Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to skip creation of aggregated output if input set is empty #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public interface AggregatorBuildContext {

public InputSet newInputSet();

public InputSet newInputSet(boolean createOutputIfEmpty);

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ public DefaultAggregatorBuildContext(Workspace workspace, File stateFile,

@Override
public DefaultInputSet newInputSet() {
return new DefaultInputSet(this);
return newInputSet(true);
}

@Override
public DefaultInputSet newInputSet(boolean createOutputIfEmpty) {
return new DefaultInputSet(this, createOutputIfEmpty);
}

private File registerOutput(File outputFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public class DefaultInputSet implements InputSet {
private final DefaultAggregatorBuildContext context;

private final Set<File> inputs = new LinkedHashSet<>();
private final boolean createOutputIfEmpty;

DefaultInputSet(DefaultAggregatorBuildContext context) {
DefaultInputSet(DefaultAggregatorBuildContext context, boolean createOutputIfEmpty) {
this.context = context;
this.createOutputIfEmpty = createOutputIfEmpty;
}

@Override
Expand All @@ -44,12 +46,18 @@ public Iterable<File> addInputs(File basedir, Collection<String> includes,
@Override
public boolean aggregateIfNecessary(File outputFile, InputAggregator aggregator)
throws IOException {
if (inputs.isEmpty() && !createOutputIfEmpty) {
return false;
}
return context.aggregateIfNecessary(inputs, outputFile, aggregator);
}

@Override
public <T extends Serializable> boolean aggregateIfNecessary(File outputFile,
MetadataAggregator<T> aggregator) throws IOException {
if (inputs.isEmpty() && !createOutputIfEmpty) {
return false;
}
return context.aggregateIfNecessary(inputs, outputFile, aggregator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public InputSet newInputSet() {
return provider.get().newInputSet();
}

@Override
public InputSet newInputSet(boolean createOutputIfEmpty) {
return provider.get().newInputSet(createOutputIfEmpty);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,18 @@ public void testEmpty() throws Exception {
Assert.assertEquals(1, indexer.outputs.size());
}

@Test
public void testEmptyNoCreate() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for incremental delete of an aggregate output created during a prior build.

File outputFile = new File(temp.getRoot(), "output");
File basedir = temp.newFolder();

FileIndexer indexer = new FileIndexer();
DefaultAggregatorBuildContext actx = newContext();
DefaultInputSet output = actx.newInputSet(false);
output.addInputs(basedir, null, null);
output.aggregateIfNecessary(outputFile, indexer);
actx.commit(null);
Assert.assertFalse(outputFile.exists());
Assert.assertEquals(0, indexer.outputs.size());
}
}