@Test public void secondaryFileRemoved() throws TransformException, InterruptedException, IOException { File jarFile = new File("jar file"); TransformStream projectClass = OriginalStream.builder() .addContentType(DefaultContentType.CLASSES) .addScope(Scope.PROJECT) .setJar(jarFile) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); File secondaryFile = new File("secondary file"); TestTransform t = TestTransform.builder() .setIncremental(true) .setInputTypes(DefaultContentType.CLASSES) .setScopes(Scope.PROJECT) .setSecondaryFile(secondaryFile) .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); transformTask.transform(inputBuilder() .incremental() .addedFile(jarFile) .removedFile(secondaryFile) .build()); assertThat(t.isIncrementalInputs()).isFalse(); }
@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();  }