Skip to content

Commit

Permalink
Make setCreateParent(boolean) as an InstrumentationOutput interfa…
Browse files Browse the repository at this point in the history
…ce level method.

PiperOrigin-RevId: 712738035
Change-Id: I9a3996395c91fe016522fb64707e3c45acec5c69
  • Loading branch information
yuyue730 authored and copybara-github committed Jan 7, 2025
1 parent 5eb0254 commit de4ba2f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public Builder setUploader(BuildEventArtifactUploader uploader) {
return this;
}

/**
* {@inheritDoc}
*
* <p>This is a no-op for {@link BuildEventArtifactInstrumentationOutput} since it will never be
* written to a local path.
*/
@CanIgnoreReturnValue
@Override
public Builder setCreateParent(boolean createParent) {
return this;
}

@Override
public BuildEventArtifactInstrumentationOutput build() {
return new BuildEventArtifactInstrumentationOutput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ default InstrumentationOutputBuilder setOptions(OptionsProvider options) {
return this;
}

/** Specifies whether output parent directory should be created. */
@CanIgnoreReturnValue
InstrumentationOutputBuilder setCreateParent(boolean createParent);

/** Builds the {@link InstrumentationOutput} object. */
InstrumentationOutput build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public InstrumentationOutput createInstrumentationOutput(
.setDestination(destination)
.setDestinationRelatedToType(destinationRelativeTo)
.setOptions(env.getOptions())
.setCreateParent(createParent)
.build();
}
eventHandler.handle(
Expand All @@ -166,17 +167,14 @@ public InstrumentationOutput createInstrumentationOutput(
env.getRuntime().getFileSystem().getPath(localTempLoggingDirPathStr);
})
.getRelative(destination);
LocalInstrumentationOutput.Builder localOutputBuilder =
localInstrumentationOutputBuilderSupplier.get();
localOutputBuilder
return localInstrumentationOutputBuilderSupplier
.get()
.setName(name)
.setPath(localOutputPath)
.setAppend(append)
.setInternal(internal);
if (createParent) {
localOutputBuilder.enableCreateParent();
}
return localOutputBuilder.build();
.setInternal(internal)
.setCreateParent(createParent)
.build();
}

public BuildEventArtifactInstrumentationOutput createBuildEventArtifactInstrumentationOutput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static class Builder implements InstrumentationOutputBuilder {
@Nullable private String convenienceName;
@Nullable private Boolean append;
@Nullable private Boolean internal;
private boolean createParent = false;
private boolean createParent;

@CanIgnoreReturnValue
@Override
Expand Down Expand Up @@ -126,8 +126,9 @@ public Builder setInternal(@Nullable Boolean internal) {
}

@CanIgnoreReturnValue
public Builder enableCreateParent() {
this.createParent = true;
@Override
public Builder setCreateParent(boolean createParent) {
this.createParent = createParent;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ public InstrumentationOutputBuilder setName(String name) {
return this;
}

@Override
@CanIgnoreReturnValue
public InstrumentationOutputBuilder setCreateParent(boolean createParent) {
return this;
}

@Override
public InstrumentationOutput build() {
return fakeRedirectInstrumentationOutput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testLocalInstrumentation_recursiveCreateParentDirectory(
localInstrumentationOutputBuilder.setName("recursive-dir-output").setPath(path);
if (enableRecursiveCreateDirectory) {
InstrumentationOutput localInstrumentationOutput =
localInstrumentationOutputBuilder.enableCreateParent().build();
localInstrumentationOutputBuilder.setCreateParent(/* createParent= */ true).build();
var unused = localInstrumentationOutput.createOutputStream();
assertThat(path.exists()).isTrue();
} else {
Expand Down

0 comments on commit de4ba2f

Please sign in to comment.