@Test public void incrementalTestComplexOriginalStreamOnly() throws TransformException, InterruptedException, IOException { File scope1Jar = new File("jar file1"); File scope3Jar = new File("jar file2"); File scope1RootFolder = new File("folder file1"); File scope3RootFolder = new File("folder file2"); OriginalStream scope1 = OriginalStream.builder() .addContentType(DefaultContentType.CLASSES) .addScope(Scope.PROJECT) .setJar(scope1Jar) .setFolder(scope1RootFolder) .setDependency("my dependency") .build(); File scope2Root = temporaryFolder.newFolder(); IntermediateStream scope2 = IntermediateStream.builder() .addContentTypes(DefaultContentType.CLASSES) .addScopes(Scope.PROJECT_LOCAL_DEPS) .setRootLocation(scope2Root) .setDependency("my dependency") .build(); TransformOutputProvider output2 = scope2.asOutput(); File scope2RootFolder = output2.getContentLocation("foo", scope2.getContentTypes(), scope2.getScopes(), Format.DIRECTORY); mkdirs(scope2RootFolder); File scope2Jar = output2.getContentLocation("foo2", scope2.getContentTypes(), scope2.getScopes(), Format.JAR); OriginalStream scope3 = OriginalStream.builder() .addContentType(DefaultContentType.CLASSES) .addScope(Scope.SUB_PROJECTS) .setJar(scope3Jar) .setFolder(scope3RootFolder) .setDependency("my dependency") .build(); File scope4Root = temporaryFolder.newFolder(); IntermediateStream scope4 = IntermediateStream.builder() .addContentTypes(DefaultContentType.CLASSES) .addScopes(Scope.EXTERNAL_LIBRARIES) .setRootLocation(scope4Root) .setDependency("my dependency") .build(); TransformOutputProvider output4 = scope4.asOutput(); File scope4RootFolder = output4.getContentLocation("foo", scope4.getContentTypes(), scope4.getScopes(), Format.DIRECTORY); mkdirs(scope4RootFolder); File scope4Jar = output4.getContentLocation("foo2", scope4.getContentTypes(), scope4.getScopes(), Format.JAR); final ImmutableMap<File, Status> inputJarMap1 = ImmutableMap.of( scope1Jar, Status.ADDED, scope2Jar, Status.REMOVED); final ImmutableMap<File, Status> inputJarMap2 = ImmutableMap.of( scope3Jar, Status.ADDED, scope4Jar, Status.REMOVED); transformManager.addStream(scope1); transformManager.addStream(scope2); transformManager.addStream(scope3); transformManager.addStream(scope4); TestTransform t = TestTransform.builder() .setIncremental(true) .setInputTypes(DefaultContentType.CLASSES) .setScopes(Scope.PROJECT, Scope.PROJECT_LOCAL_DEPS) .setReferencedScopes(Scope.EXTERNAL_LIBRARIES, Scope.SUB_PROJECTS) .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(3); File addedFile1 = new File(scope1RootFolder, "added"); File removedFile2 = new File(scope2RootFolder, "removed"); File addedFile3 = new File(scope3RootFolder, "added"); File removedFile4 = new File(scope4RootFolder, "removed"); transformTask.transform(inputBuilder() .incremental() .addedFile(scope1Jar) .removedFile(scope2Jar) .addedFile(scope3Jar) .removedFile(scope4Jar) .addedFile(addedFile1) .addedFile(addedFile3) .removedFile(removedFile2) .removedFile(removedFile4) .build()); assertThat(t.isIncrementalInputs()).isTrue(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(2); List<JarInput> jarInputs = Lists.newArrayListWithCapacity(2); List<DirectoryInput> directoryInputs = Lists.newArrayListWithCapacity(2); for (TransformInput input : inputs) { jarInputs.addAll(input.getJarInputs()); directoryInputs.addAll(input.getDirectoryInputs()); } assertThat(jarInputs).hasSize(2); for (JarInput jarInput : jarInputs) { File file = jarInput.getFile(); assertThat(file).isIn(inputJarMap1.keySet()); assertThat(jarInput.getStatus()).isSameAs(inputJarMap1.get(file)); } assertThat(directoryInputs).hasSize(2); for (DirectoryInput directoryInput : directoryInputs) { Map<File, Status> changedFiles = directoryInput.getChangedFiles(); assertThat(changedFiles).hasSize(1); File file = directoryInput.getFile(); assertThat(file).isAnyOf(scope1RootFolder, scope2RootFolder); if (file.equals(scope1RootFolder)) { assertThat(changedFiles).containsEntry(addedFile1, Status.ADDED); } else if (file.equals(scope2RootFolder)) { assertThat(changedFiles).containsEntry(removedFile2, Status.REMOVED); } } Collection<TransformInput> referencedInputs = t.getReferencedInputs(); assertThat(referencedInputs).hasSize(2); jarInputs = Lists.newArrayListWithCapacity(2); directoryInputs = Lists.newArrayListWithCapacity(2); for (TransformInput input : referencedInputs) { jarInputs.addAll(input.getJarInputs()); directoryInputs.addAll(input.getDirectoryInputs()); } assertThat(jarInputs).hasSize(2); for (JarInput jarInput : jarInputs) { File file = jarInput.getFile(); assertThat(file).isIn(inputJarMap2.keySet()); assertThat(jarInput.getStatus()).isSameAs(inputJarMap2.get(file)); } assertThat(directoryInputs).hasSize(2); for (DirectoryInput directoryInput : directoryInputs) { Map<File, Status> changedFiles = directoryInput.getChangedFiles(); assertThat(changedFiles).hasSize(1); File file = directoryInput.getFile(); assertThat(file).isAnyOf(scope3RootFolder, scope4RootFolder); if (file.equals(scope3RootFolder)) { assertThat(changedFiles).containsEntry(addedFile3, Status.ADDED); } else if (file.equals(scope4RootFolder)) { assertThat(changedFiles).containsEntry(removedFile4, 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();  }