@Test public void deletedFolderInputInIntermediateStream() throws TransformException, InterruptedException, IOException { File rootFolder = temporaryFolder.newFolder(); IntermediateStream projectClass = IntermediateStream.builder() .addContentTypes(DefaultContentType.CLASSES) .addScopes(Scope.PROJECT) .setRootLocation(rootFolder) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TransformOutputProvider output = projectClass.asOutput(); File outputFolder = output.getContentLocation("foo", projectClass.getContentTypes(), projectClass.getScopes(), Format.DIRECTORY); mkdirs(outputFolder); File deletedOutputFolder = output.getContentLocation("foo2", projectClass.getContentTypes(), projectClass.getScopes(), Format.DIRECTORY); TestTransform t = TestTransform.builder() .setIncremental(true) .setInputTypes(DefaultContentType.CLASSES) .setScopes(Scope.PROJECT) .build(); AndroidTask<TransformTask> task = transformManager.addTransform( taskFactory, scope, t); TransformTask transformTask = (TransformTask) taskFactory.named(task.getName()); assertThat(transformTask).isNotNull(); List<TransformStream> streams = transformManager.getStreams(); assertThat(streams).hasSize(1); File removedFile = new File(deletedOutputFolder, "removed"); File removedFile2 = new File(deletedOutputFolder, "removed2"); transformTask.transform(inputBuilder() .incremental() .removedFile(removedFile) .removedFile(removedFile2) .build()); assertThat(t.isIncrementalInputs()).isTrue(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<DirectoryInput> directoryInputs = input.getDirectoryInputs(); assertThat(directoryInputs).isNotNull(); assertThat(directoryInputs).hasSize(2); List<File> folderLocations = ImmutableList.of(outputFolder, deletedOutputFolder); for (DirectoryInput directoryInput : directoryInputs) { File file = directoryInput.getFile(); assertThat(file).isIn(folderLocations); Map<File, Status> changedFiles = directoryInput.getChangedFiles(); if (file.equals(outputFolder)) { assertThat(changedFiles).isEmpty(); } else { assertThat(changedFiles).hasSize(2); assertThat(changedFiles).containsEntry(removedFile, Status.REMOVED); assertThat(changedFiles).containsEntry(removedFile2, Status.REMOVED); } } }
@TaskAction void transform(final IncrementalTaskInputs incrementalTaskInputs) throws IOException, TransformException, InterruptedException { final ReferenceHolder<List<TransformInput>> consumedInputs = ReferenceHolder.empty(); final ReferenceHolder<List<TransformInput>> referencedInputs = ReferenceHolder.empty(); final ReferenceHolder<Boolean> isIncremental = ReferenceHolder.empty(); final ReferenceHolder<Collection<SecondaryInput>> changedSecondaryInputs = ReferenceHolder.empty(); isIncremental.setValue(transform.isIncremental() && incrementalTaskInputs.isIncremental()); AndroidStudioStats.GradleTransformExecution preExecutionInfo = AndroidStudioStats.GradleTransformExecution.newBuilder() .setType(getTransformType(transform.getClass())) .setIsIncremental(isIncremental.getValue()) .build(); ThreadRecorder.get().record(ExecutionType.TASK_TRANSFORM_PREPARATION, preExecutionInfo, getProject().getPath(), getVariantName(), new Recorder.Block<Void>() { @Override public Void call() throws Exception { Map<File, Status> changedMap = Maps.newHashMap(); Set<File> removedFiles = Sets.newHashSet(); if (isIncremental.getValue()) { gatherChangedFiles(getLogger(), incrementalTaskInputs, changedMap, removedFiles); isIncremental.setValue(checkSecondaryFiles(changedMap, removedFiles)); } if (isIncremental.getValue()) { List<IncrementalTransformInput> incInputs = createIncrementalInputs(consumedInputStreams); List<IncrementalTransformInput> incReferencedInputs = createIncrementalInputs(referencedInputStreams); if (isIncremental.setValue(updateIncrementalInputsWithChangedFiles( incInputs, incReferencedInputs, changedMap, removedFiles))) { consumedInputs.setValue(convertToImmutable(incInputs)); referencedInputs.setValue(convertToImmutable(incReferencedInputs)); } } if (!isIncremental.getValue()) { consumedInputs.setValue( computeNonIncTransformInput(consumedInputStreams)); referencedInputs.setValue( computeNonIncTransformInput(referencedInputStreams)); changedSecondaryInputs.setValue( ImmutableList.<SecondaryInput>of()); } else { changedSecondaryInputs.setValue( gatherSecondaryInputChanges(changedMap, removedFiles)); } return null; } }); AndroidStudioStats.GradleTransformExecution executionInfo = preExecutionInfo.toBuilder().setIsIncremental(isIncremental.getValue()).build(); ThreadRecorder.get().record(ExecutionType.TASK_TRANSFORM, executionInfo, getProject().getPath(), getVariantName(), new Recorder.Block<Void>() { @Override public Void call() throws Exception { transform.transform(new TransformInvocationBuilder(TransformTask.this) .addInputs(consumedInputs.getValue()) .addReferencedInputs(referencedInputs.getValue()) .addSecondaryInputs(changedSecondaryInputs.getValue()) .addOutputProvider(outputStream != null ? outputStream.asOutput() : null) .setIncrementalMode(isIncremental.getValue()) .build()); return null; } }); }
TransformTask extends StreamBasedTask implements Context { @TaskAction void transform(final IncrementalTaskInputs incrementalTaskInputs) throws IOException, TransformException, InterruptedException { final ReferenceHolder<List<TransformInput>> consumedInputs = ReferenceHolder.empty(); final ReferenceHolder<List<TransformInput>> referencedInputs = ReferenceHolder.empty(); final ReferenceHolder<Boolean> isIncremental = ReferenceHolder.empty(); final ReferenceHolder<Collection<SecondaryInput>> changedSecondaryInputs = ReferenceHolder.empty(); isIncremental.setValue(transform.isIncremental() && incrementalTaskInputs.isIncremental()); AndroidStudioStats.GradleTransformExecution preExecutionInfo = AndroidStudioStats.GradleTransformExecution.newBuilder() .setType(getTransformType(transform.getClass())) .setIsIncremental(isIncremental.getValue()) .build(); ThreadRecorder.get().record(ExecutionType.TASK_TRANSFORM_PREPARATION, preExecutionInfo, getProject().getPath(), getVariantName(), new Recorder.Block<Void>() { @Override public Void call() throws Exception { Map<File, Status> changedMap = Maps.newHashMap(); Set<File> removedFiles = Sets.newHashSet(); if (isIncremental.getValue()) { gatherChangedFiles(getLogger(), incrementalTaskInputs, changedMap, removedFiles); isIncremental.setValue(checkSecondaryFiles(changedMap, removedFiles)); } if (isIncremental.getValue()) { List<IncrementalTransformInput> incInputs = createIncrementalInputs(consumedInputStreams); List<IncrementalTransformInput> incReferencedInputs = createIncrementalInputs(referencedInputStreams); if (isIncremental.setValue(updateIncrementalInputsWithChangedFiles( incInputs, incReferencedInputs, changedMap, removedFiles))) { consumedInputs.setValue(convertToImmutable(incInputs)); referencedInputs.setValue(convertToImmutable(incReferencedInputs)); } } if (!isIncremental.getValue()) { consumedInputs.setValue( computeNonIncTransformInput(consumedInputStreams)); referencedInputs.setValue( computeNonIncTransformInput(referencedInputStreams)); changedSecondaryInputs.setValue( ImmutableList.<SecondaryInput>of()); } else { changedSecondaryInputs.setValue( gatherSecondaryInputChanges(changedMap, removedFiles)); } return null; } }); AndroidStudioStats.GradleTransformExecution executionInfo = preExecutionInfo.toBuilder().setIsIncremental(isIncremental.getValue()).build(); ThreadRecorder.get().record(ExecutionType.TASK_TRANSFORM, executionInfo, getProject().getPath(), getVariantName(), new Recorder.Block<Void>() { @Override public Void call() throws Exception { transform.transform(new TransformInvocationBuilder(TransformTask.this) .addInputs(consumedInputs.getValue()) .addReferencedInputs(referencedInputs.getValue()) .addSecondaryInputs(changedSecondaryInputs.getValue()) .addOutputProvider(outputStream != null ? outputStream.asOutput() : null) .setIncrementalMode(isIncremental.getValue()) .build()); return null; } }); } }
TransformTask extends StreamBasedTask implements Context { @TaskAction void transform(final IncrementalTaskInputs incrementalTaskInputs) throws IOException, TransformException, InterruptedException { final ReferenceHolder<List<TransformInput>> consumedInputs = ReferenceHolder.empty(); final ReferenceHolder<List<TransformInput>> referencedInputs = ReferenceHolder.empty(); final ReferenceHolder<Boolean> isIncremental = ReferenceHolder.empty(); final ReferenceHolder<Collection<SecondaryInput>> changedSecondaryInputs = ReferenceHolder.empty(); isIncremental.setValue(transform.isIncremental() && incrementalTaskInputs.isIncremental()); AndroidStudioStats.GradleTransformExecution preExecutionInfo = AndroidStudioStats.GradleTransformExecution.newBuilder() .setType(getTransformType(transform.getClass())) .setIsIncremental(isIncremental.getValue()) .build(); ThreadRecorder.get().record(ExecutionType.TASK_TRANSFORM_PREPARATION, preExecutionInfo, getProject().getPath(), getVariantName(), new Recorder.Block<Void>() { @Override public Void call() throws Exception { Map<File, Status> changedMap = Maps.newHashMap(); Set<File> removedFiles = Sets.newHashSet(); if (isIncremental.getValue()) { gatherChangedFiles(getLogger(), incrementalTaskInputs, changedMap, removedFiles); isIncremental.setValue(checkSecondaryFiles(changedMap, removedFiles)); } if (isIncremental.getValue()) { List<IncrementalTransformInput> incInputs = createIncrementalInputs(consumedInputStreams); List<IncrementalTransformInput> incReferencedInputs = createIncrementalInputs(referencedInputStreams); if (isIncremental.setValue(updateIncrementalInputsWithChangedFiles( incInputs, incReferencedInputs, changedMap, removedFiles))) { consumedInputs.setValue(convertToImmutable(incInputs)); referencedInputs.setValue(convertToImmutable(incReferencedInputs)); } } if (!isIncremental.getValue()) { consumedInputs.setValue( computeNonIncTransformInput(consumedInputStreams)); referencedInputs.setValue( computeNonIncTransformInput(referencedInputStreams)); changedSecondaryInputs.setValue( ImmutableList.<SecondaryInput>of()); } else { changedSecondaryInputs.setValue( gatherSecondaryInputChanges(changedMap, removedFiles)); } return null; } }); AndroidStudioStats.GradleTransformExecution executionInfo = preExecutionInfo.toBuilder().setIsIncremental(isIncremental.getValue()).build(); ThreadRecorder.get().record(ExecutionType.TASK_TRANSFORM, executionInfo, getProject().getPath(), getVariantName(), new Recorder.Block<Void>() { @Override public Void call() throws Exception { transform.transform(new TransformInvocationBuilder(TransformTask.this) .addInputs(consumedInputs.getValue()) .addReferencedInputs(referencedInputs.getValue()) .addSecondaryInputs(changedSecondaryInputs.getValue()) .addOutputProvider(outputStream != null ? outputStream.asOutput() : null) .setIncrementalMode(isIncremental.getValue()) .build()); return null; } }); }  }
TransformTask extends StreamBasedTask implements Context { @TaskAction void transform(final IncrementalTaskInputs incrementalTaskInputs) throws IOException, TransformException, InterruptedException { final ReferenceHolder<List<TransformInput>> consumedInputs = ReferenceHolder.empty(); final ReferenceHolder<List<TransformInput>> referencedInputs = ReferenceHolder.empty(); final ReferenceHolder<Boolean> isIncremental = ReferenceHolder.empty(); final ReferenceHolder<Collection<SecondaryInput>> changedSecondaryInputs = ReferenceHolder.empty(); isIncremental.setValue(transform.isIncremental() && incrementalTaskInputs.isIncremental()); AndroidStudioStats.GradleTransformExecution preExecutionInfo = AndroidStudioStats.GradleTransformExecution.newBuilder() .setType(getTransformType(transform.getClass())) .setIsIncremental(isIncremental.getValue()) .build(); ThreadRecorder.get().record(ExecutionType.TASK_TRANSFORM_PREPARATION, preExecutionInfo, getProject().getPath(), getVariantName(), new Recorder.Block<Void>() { @Override public Void call() throws Exception { Map<File, Status> changedMap = Maps.newHashMap(); Set<File> removedFiles = Sets.newHashSet(); if (isIncremental.getValue()) { gatherChangedFiles(getLogger(), incrementalTaskInputs, changedMap, removedFiles); isIncremental.setValue(checkSecondaryFiles(changedMap, removedFiles)); } if (isIncremental.getValue()) { List<IncrementalTransformInput> incInputs = createIncrementalInputs(consumedInputStreams); List<IncrementalTransformInput> incReferencedInputs = createIncrementalInputs(referencedInputStreams); if (isIncremental.setValue(updateIncrementalInputsWithChangedFiles( incInputs, incReferencedInputs, changedMap, removedFiles))) { consumedInputs.setValue(convertToImmutable(incInputs)); referencedInputs.setValue(convertToImmutable(incReferencedInputs)); } } if (!isIncremental.getValue()) { consumedInputs.setValue( computeNonIncTransformInput(consumedInputStreams)); referencedInputs.setValue( computeNonIncTransformInput(referencedInputStreams)); changedSecondaryInputs.setValue( ImmutableList.<SecondaryInput>of()); } else { changedSecondaryInputs.setValue( gatherSecondaryInputChanges(changedMap, removedFiles)); } return null; } }); AndroidStudioStats.GradleTransformExecution executionInfo = preExecutionInfo.toBuilder().setIsIncremental(isIncremental.getValue()).build(); ThreadRecorder.get().record(ExecutionType.TASK_TRANSFORM, executionInfo, getProject().getPath(), getVariantName(), new Recorder.Block<Void>() { @Override public Void call() throws Exception { transform.transform(new TransformInvocationBuilder(TransformTask.this) .addInputs(consumedInputs.getValue()) .addReferencedInputs(referencedInputs.getValue()) .addSecondaryInputs(changedSecondaryInputs.getValue()) .addOutputProvider(outputStream != null ? outputStream.asOutput() : null) .setIncrementalMode(isIncremental.getValue()) .build()); return null; } }); }  Transform getTransform(); @InputFiles Collection<File> getOtherFileInputs(); @OutputFiles Collection<File> getOtherFileOutputs(); @OutputDirectories Collection<File> getOtherFolderOutputs(); }
TransformTask extends StreamBasedTask implements Context { @TaskAction void transform(final IncrementalTaskInputs incrementalTaskInputs) throws IOException, TransformException, InterruptedException { final ReferenceHolder<List<TransformInput>> consumedInputs = ReferenceHolder.empty(); final ReferenceHolder<List<TransformInput>> referencedInputs = ReferenceHolder.empty(); final ReferenceHolder<Boolean> isIncremental = ReferenceHolder.empty(); final ReferenceHolder<Collection<SecondaryInput>> changedSecondaryInputs = ReferenceHolder.empty(); isIncremental.setValue(transform.isIncremental() && incrementalTaskInputs.isIncremental()); AndroidStudioStats.GradleTransformExecution preExecutionInfo = AndroidStudioStats.GradleTransformExecution.newBuilder() .setType(getTransformType(transform.getClass())) .setIsIncremental(isIncremental.getValue()) .build(); ThreadRecorder.get().record(ExecutionType.TASK_TRANSFORM_PREPARATION, preExecutionInfo, getProject().getPath(), getVariantName(), new Recorder.Block<Void>() { @Override public Void call() throws Exception { Map<File, Status> changedMap = Maps.newHashMap(); Set<File> removedFiles = Sets.newHashSet(); if (isIncremental.getValue()) { gatherChangedFiles(getLogger(), incrementalTaskInputs, changedMap, removedFiles); isIncremental.setValue(checkSecondaryFiles(changedMap, removedFiles)); } if (isIncremental.getValue()) { List<IncrementalTransformInput> incInputs = createIncrementalInputs(consumedInputStreams); List<IncrementalTransformInput> incReferencedInputs = createIncrementalInputs(referencedInputStreams); if (isIncremental.setValue(updateIncrementalInputsWithChangedFiles( incInputs, incReferencedInputs, changedMap, removedFiles))) { consumedInputs.setValue(convertToImmutable(incInputs)); referencedInputs.setValue(convertToImmutable(incReferencedInputs)); } } if (!isIncremental.getValue()) { consumedInputs.setValue( computeNonIncTransformInput(consumedInputStreams)); referencedInputs.setValue( computeNonIncTransformInput(referencedInputStreams)); changedSecondaryInputs.setValue( ImmutableList.<SecondaryInput>of()); } else { changedSecondaryInputs.setValue( gatherSecondaryInputChanges(changedMap, removedFiles)); } return null; } }); AndroidStudioStats.GradleTransformExecution executionInfo = preExecutionInfo.toBuilder().setIsIncremental(isIncremental.getValue()).build(); ThreadRecorder.get().record(ExecutionType.TASK_TRANSFORM, executionInfo, getProject().getPath(), getVariantName(), new Recorder.Block<Void>() { @Override public Void call() throws Exception { transform.transform(new TransformInvocationBuilder(TransformTask.this) .addInputs(consumedInputs.getValue()) .addReferencedInputs(referencedInputs.getValue()) .addSecondaryInputs(changedSecondaryInputs.getValue()) .addOutputProvider(outputStream != null ? outputStream.asOutput() : null) .setIncrementalMode(isIncremental.getValue()) .build()); return null; } }); }  Transform getTransform(); @InputFiles Collection<File> getOtherFileInputs(); @OutputFiles Collection<File> getOtherFileOutputs(); @OutputDirectories Collection<File> getOtherFolderOutputs();  }