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();  }
@Test public void nonIncWithJarInputInOriginalStream() throws IOException, TransformException, InterruptedException { OriginalStream projectClass = OriginalStream.builder() .addContentType(QualifiedContent.DefaultContentType.CLASSES) .addScope(Scope.PROJECT) .setJar(new File("input file")) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TestTransform t = TestTransform.builder() .setInputTypes(QualifiedContent.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); transformTask.transform(inputBuilder().build()); assertThat(t.isIncremental()).isFalse(); assertThat(t.getReferencedInputs()).isEmpty(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(1); Collection<DirectoryInput> directoryInputs = input.getDirectoryInputs(); assertThat(directoryInputs).isNotNull(); assertThat(directoryInputs).isEmpty(); JarInput singleJarInput = Iterables.getOnlyElement(jarInputs); assertThat(singleJarInput.getFile()).isEqualTo( Iterables.getOnlyElement(projectClass.getJarFiles().get())); assertThat(singleJarInput.getContentTypes()).containsExactlyElementsIn( projectClass.getContentTypes()); assertThat(singleJarInput.getScopes()).containsExactlyElementsIn(projectClass.getScopes()); assertThat(singleJarInput.getStatus()).isSameAs(Status.NOTCHANGED); }
@Test public void nonIncWithJarInputInIntermediateStream() throws IOException, TransformException, InterruptedException { File rootFolder = temporaryFolder.newFolder(); IntermediateStream projectClass = IntermediateStream.builder() .addContentTypes(QualifiedContent.DefaultContentType.CLASSES.CLASSES) .addScopes(Scope.PROJECT) .setRootLocation(rootFolder) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TransformOutputProvider output = projectClass.asOutput(); File jarFile = output.getContentLocation("foo", projectClass.getContentTypes(), projectClass.getScopes(), Format.JAR); mkdirs(jarFile.getParentFile()); Files.write("foo", jarFile, Charsets.UTF_8); TestTransform t = TestTransform.builder() .setInputTypes(QualifiedContent.DefaultContentType.CLASSES.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); transformTask.transform(inputBuilder().build()); assertThat(t.isIncremental()).isFalse(); assertThat(t.getReferencedInputs()).isEmpty(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(1); Collection<DirectoryInput> directoryInputs = input.getDirectoryInputs(); assertThat(directoryInputs).isNotNull(); assertThat(directoryInputs).isEmpty(); JarInput singleJarInput = Iterables.getOnlyElement(jarInputs); assertThat(singleJarInput.getFile()).isEqualTo(jarFile); assertThat(singleJarInput.getContentTypes()).containsExactlyElementsIn( projectClass.getContentTypes()); assertThat(singleJarInput.getScopes()).containsExactlyElementsIn(projectClass.getScopes()); assertThat(singleJarInput.getStatus()).isSameAs(Status.NOTCHANGED); }
@Test public void nonIncWithReferencedJarInputInOriginalStream() throws IOException, TransformException, InterruptedException { OriginalStream projectClass = OriginalStream.builder() .addContentType(QualifiedContent.DefaultContentType.CLASSES.CLASSES) .addScope(Scope.PROJECT) .setJar(new File("input file")) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TestTransform t = TestTransform.builder() .setInputTypes(QualifiedContent.DefaultContentType.CLASSES.CLASSES) .setReferencedScopes(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); transformTask.transform(inputBuilder().build()); assertThat(t.isIncremental()).isFalse(); assertThat(t.getInputs()).isEmpty(); Collection<TransformInput> inputs = t.getReferencedInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(1); Collection<DirectoryInput> directoryInputs = input.getDirectoryInputs(); assertThat(directoryInputs).isNotNull(); assertThat(directoryInputs).isEmpty(); JarInput singleJarInput = Iterables.getOnlyElement(jarInputs); assertThat(singleJarInput.getFile()).isEqualTo( Iterables.getOnlyElement(projectClass.getJarFiles().get())); assertThat(singleJarInput.getContentTypes()).containsExactlyElementsIn( projectClass.getContentTypes()); assertThat(singleJarInput.getScopes()).containsExactlyElementsIn(projectClass.getScopes()); assertThat(singleJarInput.getStatus()).isSameAs(Status.NOTCHANGED); }
@Test public void nonIncWithReferencedJarInputInIntermediateStream() throws IOException, TransformException, InterruptedException { File rootFolder = temporaryFolder.newFolder(); IntermediateStream projectClass = IntermediateStream.builder() .addContentTypes(QualifiedContent.DefaultContentType.CLASSES) .addScopes(Scope.PROJECT) .setRootLocation(rootFolder) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TransformOutputProvider output = projectClass.asOutput(); File jarFile = output.getContentLocation("foo", projectClass.getContentTypes(), projectClass.getScopes(), Format.JAR); mkdirs(jarFile.getParentFile()); Files.write("foo", jarFile, Charsets.UTF_8); TestTransform t = TestTransform.builder() .setInputTypes(QualifiedContent.DefaultContentType.CLASSES) .setReferencedScopes(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); transformTask.transform(inputBuilder().build()); assertThat(t.isIncremental()).isFalse(); assertThat(t.getInputs()).isEmpty(); Collection<TransformInput> inputs = t.getReferencedInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(1); Collection<DirectoryInput> directoryInputs = input.getDirectoryInputs(); assertThat(directoryInputs).isNotNull(); assertThat(directoryInputs).isEmpty(); JarInput singleJarInput = Iterables.getOnlyElement(jarInputs); assertThat(singleJarInput.getFile()).isEqualTo(jarFile); assertThat(singleJarInput.getContentTypes()).containsExactlyElementsIn( projectClass.getContentTypes()); assertThat(singleJarInput.getScopes()).containsExactlyElementsIn(projectClass.getScopes()); assertThat(singleJarInput.getStatus()).isSameAs(Status.NOTCHANGED); }
@Test public void nonIncWithFolderInputInOriginalStream() throws IOException, TransformException, InterruptedException { OriginalStream projectClass = OriginalStream.builder() .addContentType(DefaultContentType.CLASSES) .addScope(Scope.PROJECT) .setFolder(new File("input file")) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TestTransform t = TestTransform.builder() .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); transformTask.transform(inputBuilder().build()); assertThat(t.isIncremental()).isFalse(); assertThat(t.getReferencedInputs()).isEmpty(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).isEmpty(); Collection<DirectoryInput> directoryInputs = input.getDirectoryInputs(); assertThat(directoryInputs).isNotNull(); assertThat(directoryInputs).hasSize(1); DirectoryInput singleDirectoryInput = Iterables.getOnlyElement(directoryInputs); assertThat(singleDirectoryInput.getFile()).isEqualTo( Iterables.getOnlyElement(projectClass.getFolders().get())); assertThat(singleDirectoryInput.getContentTypes()).containsExactlyElementsIn( projectClass.getContentTypes()); assertThat(singleDirectoryInput.getScopes()).containsExactlyElementsIn(projectClass.getScopes()); assertThat(singleDirectoryInput.getChangedFiles()).isEmpty(); }
@Test public void nonIncWithFolderInputInIntermediateStream() throws IOException, TransformException, InterruptedException { 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); TestTransform t = TestTransform.builder() .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); transformTask.transform(inputBuilder().build()); assertThat(t.isIncremental()).isFalse(); assertThat(t.getReferencedInputs()).isEmpty(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).isEmpty(); Collection<DirectoryInput> directoryInputs = input.getDirectoryInputs(); assertThat(directoryInputs).isNotNull(); assertThat(directoryInputs).hasSize(1); DirectoryInput singleDirectoryInput = Iterables.getOnlyElement(directoryInputs); assertThat(singleDirectoryInput.getFile()).isEqualTo(outputFolder); assertThat(singleDirectoryInput.getContentTypes()).containsExactlyElementsIn( projectClass.getContentTypes()); assertThat(singleDirectoryInput.getScopes()).containsExactlyElementsIn(projectClass.getScopes()); assertThat(singleDirectoryInput.getChangedFiles()).isEmpty(); }
@Test public void nonIncWithReferencedFolderInputInOriginalStream() throws IOException, TransformException, InterruptedException { OriginalStream projectClass = OriginalStream.builder() .addContentType(DefaultContentType.CLASSES) .addScope(Scope.PROJECT) .setFolder(new File("input file")) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TestTransform t = TestTransform.builder() .setInputTypes(DefaultContentType.CLASSES) .setReferencedScopes(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); transformTask.transform(inputBuilder().build()); assertThat(t.isIncremental()).isFalse(); assertThat(t.getInputs()).isEmpty(); Collection<TransformInput> inputs = t.getReferencedInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).isEmpty(); Collection<DirectoryInput> directoryInputs = input.getDirectoryInputs(); assertThat(directoryInputs).isNotNull(); assertThat(directoryInputs).hasSize(1); DirectoryInput singleDirectoryInput = Iterables.getOnlyElement(directoryInputs); assertThat(singleDirectoryInput.getFile()).isEqualTo( Iterables.getOnlyElement(projectClass.getFolders().get())); assertThat(singleDirectoryInput.getContentTypes()).containsExactlyElementsIn( projectClass.getContentTypes()); assertThat(singleDirectoryInput.getScopes()).containsExactlyElementsIn(projectClass.getScopes()); assertThat(singleDirectoryInput.getChangedFiles()).isEmpty(); }
@Test public void nonIncWithReferencedFolderInputInIntermediateStream() throws IOException, TransformException, InterruptedException { 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); TestTransform t = TestTransform.builder() .setInputTypes(DefaultContentType.CLASSES) .setReferencedScopes(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); transformTask.transform(inputBuilder().build()); assertThat(t.isIncremental()).isFalse(); assertThat(t.getInputs()).isEmpty(); Collection<TransformInput> inputs = t.getReferencedInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).isEmpty(); Collection<DirectoryInput> directoryInputs = input.getDirectoryInputs(); assertThat(directoryInputs).isNotNull(); assertThat(directoryInputs).hasSize(1); DirectoryInput singleDirectoryInput = Iterables.getOnlyElement(directoryInputs); assertThat(singleDirectoryInput.getFile()).isEqualTo(outputFolder); assertThat(singleDirectoryInput.getContentTypes()).containsExactlyElementsIn( projectClass.getContentTypes()); assertThat(singleDirectoryInput.getScopes()).containsExactlyElementsIn(projectClass.getScopes()); assertThat(singleDirectoryInput.getChangedFiles()).isEmpty(); }
@Test public void incTaskWithNonIncTransformWithJarInputInOriginalStream() throws TransformException, InterruptedException, IOException { File jarFile = new File("input file"); OriginalStream projectClass = OriginalStream.builder() .addContentType(DefaultContentType.CLASSES) .addScope(Scope.PROJECT) .setJar(jarFile) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TestTransform t = TestTransform.builder() .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); transformTask.transform(inputBuilder() .incremental() .addedFile(jarFile) .build()); assertThat(t.isIncrementalInputs()).isFalse(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(1); JarInput singleJarInput = Iterables.getOnlyElement(jarInputs); assertThat(singleJarInput.getFile()).isEqualTo(jarFile); assertThat(singleJarInput.getStatus()).isSameAs(Status.NOTCHANGED); }
@Test public void incTaskWithNonIncTransformWithJarInputInIntermediateStream() 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 jarFile = output.getContentLocation("foo", projectClass.getContentTypes(), projectClass.getScopes(), Format.JAR); mkdirs(jarFile.getParentFile()); Files.write("foo", jarFile, Charsets.UTF_8); TestTransform t = TestTransform.builder() .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); transformTask.transform(inputBuilder() .incremental() .addedFile(jarFile) .build()); assertThat(t.isIncrementalInputs()).isFalse(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(1); JarInput singleJarInput = Iterables.getOnlyElement(jarInputs); assertThat(singleJarInput.getFile()).isEqualTo(jarFile); assertThat(singleJarInput.getStatus()).isSameAs(Status.NOTCHANGED); }
@Test public void incTaskWithNonIncTransformWithFolderInputInOriginalStream() throws TransformException, InterruptedException, IOException { File rootFolder = new File("input file"); OriginalStream projectClass = OriginalStream.builder() .addContentType(DefaultContentType.CLASSES) .addScope(Scope.PROJECT) .setFolder(rootFolder) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TestTransform t = TestTransform.builder() .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 addedFile = new File(rootFolder, "added"); transformTask.transform(inputBuilder() .incremental() .addedFile(addedFile) .build()); assertThat(t.isIncrementalInputs()).isFalse(); 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(1); DirectoryInput singleDirectoryInput = Iterables.getOnlyElement(directoryInputs); assertThat(singleDirectoryInput.getFile()).isEqualTo(rootFolder); assertThat(singleDirectoryInput.getChangedFiles()).isEmpty(); }
@Test public void incTaskWithNonIncTransformWithFolderInputInIntermediateStream() 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); TestTransform t = TestTransform.builder() .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 addedFile = new File(rootFolder, "added"); transformTask.transform(inputBuilder() .incremental() .addedFile(addedFile) .build()); assertThat(t.isIncrementalInputs()).isFalse(); 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(1); DirectoryInput singleDirectoryInput = Iterables.getOnlyElement(directoryInputs); assertThat(singleDirectoryInput.getFile()).isEqualTo(outputFolder); assertThat(singleDirectoryInput.getChangedFiles()).isEmpty(); }
@Test public void incrementalJarInputInOriginalStream() throws TransformException, InterruptedException, IOException { final File addedFile = new File("jar file1"); final File changedFile = new File("jar file2"); final ImmutableMap<File, Status> jarMap = ImmutableMap.of( addedFile, Status.ADDED, changedFile, Status.CHANGED); OriginalStream projectClass = OriginalStream.builder() .addContentType(DefaultContentType.CLASSES) .addScope(Scope.PROJECT) .setJars(new Supplier<Collection<File>>() { @Override public Collection<File> get() { return ImmutableList.of(addedFile, changedFile); } }) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); 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); transformTask.transform(inputBuilder() .incremental() .addedFile(addedFile) .modifiedFile(changedFile) .build()); assertThat(t.isIncrementalInputs()).isTrue(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(jarMap.size()); for (JarInput jarInput : jarInputs) { File file = jarInput.getFile(); assertThat(file).isIn(jarMap.keySet()); assertThat(jarInput.getStatus()).isSameAs(jarMap.get(file)); } }
@Test public void incrementalJarInputInIntermediateStream() 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 addedJar = output.getContentLocation("added", projectClass.getContentTypes(), projectClass.getScopes(), Format.JAR); mkdirs(addedJar.getParentFile()); Files.write("foo", addedJar, Charsets.UTF_8); File changedJar = output.getContentLocation("changed", projectClass.getContentTypes(), projectClass.getScopes(), Format.JAR); mkdirs(changedJar.getParentFile()); Files.write("foo", changedJar, Charsets.UTF_8); final ImmutableMap<File, Status> jarMap = ImmutableMap.of( addedJar, Status.ADDED, changedJar, Status.CHANGED); 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); transformTask.transform(inputBuilder() .incremental() .addedFile(addedJar) .modifiedFile(changedJar) .build()); assertThat(t.isIncrementalInputs()).isTrue(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(jarMap.size()); for (JarInput jarInput : jarInputs) { File file = jarInput.getFile(); assertThat(file).isIn(jarMap.keySet()); assertThat(jarInput.getStatus()).isSameAs(jarMap.get(file)); } }
@Test public void incrementalComplexTypeJarInputInIntermediateStream() throws TransformException, InterruptedException, IOException { File rootFolder = temporaryFolder.newFolder(); IntermediateStream projectClass = IntermediateStream.builder() .addContentTypes(DefaultContentType.CLASSES) .addContentTypes(ExtendedContentType.CLASSES_ENHANCED) .addScopes(Scope.PROJECT) .setRootLocation(rootFolder) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TransformOutputProvider output = projectClass.asOutput(); File addedJar = output.getContentLocation("added", ImmutableSet.of(DefaultContentType.CLASSES), projectClass.getScopes(), Format.JAR); mkdirs(addedJar.getParentFile()); Files.write("foo", addedJar, Charsets.UTF_8); File changedJar = output.getContentLocation("changed", ImmutableSet.of(DefaultContentType.CLASSES), projectClass.getScopes(), Format.JAR); mkdirs(changedJar.getParentFile()); Files.write("foo", changedJar, Charsets.UTF_8); File enhancedAddedJar = output.getContentLocation("added", ImmutableSet.of(ExtendedContentType.CLASSES_ENHANCED), projectClass.getScopes(), Format.JAR); mkdirs(addedJar.getParentFile()); Files.write("foo", addedJar, Charsets.UTF_8); File enhancedChangedJar = output.getContentLocation("changed", ImmutableSet.of(ExtendedContentType.CLASSES_ENHANCED), projectClass.getScopes(), Format.JAR); mkdirs(changedJar.getParentFile()); Files.write("foo", changedJar, Charsets.UTF_8); File enhancedRemovedJar = output.getContentLocation("removed", ImmutableSet.of(ExtendedContentType.CLASSES_ENHANCED), projectClass.getScopes(), Format.JAR); final ImmutableMap<File, Status> jarMap = ImmutableMap.of( addedJar, Status.ADDED, changedJar, Status.CHANGED); TestTransform classesTransform = TestTransform.builder() .setIncremental(true) .setInputTypes(DefaultContentType.CLASSES) .setScopes(Scope.PROJECT) .build(); AndroidTask<TransformTask> classesTask = transformManager .addTransform(taskFactory, scope, classesTransform); TransformTask transformTask = (TransformTask) taskFactory.named(classesTask.getName()); assertThat(transformTask).isNotNull(); List<TransformStream> streams = transformManager.getStreams(); assertThat(streams).hasSize(2); transformTask.transform(inputBuilder() .incremental() .addedFile(addedJar) .addedFile(enhancedAddedJar) .modifiedFile(changedJar) .modifiedFile(enhancedChangedJar) .removedFile(enhancedRemovedJar) .build()); assertThat(classesTransform.isIncrementalInputs()).isTrue(); Collection<TransformInput> inputs = classesTransform.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(jarMap.size()); for (JarInput jarInput : jarInputs) { File file = jarInput.getFile(); assertThat(file).isIn(jarMap.keySet()); assertThat(jarInput.getStatus()).isSameAs(jarMap.get(file)); } }
@Test public void incrementalComplexScopeJarInputInIntermediateStream() throws TransformException, InterruptedException, IOException { File rootFolder = temporaryFolder.newFolder(); IntermediateStream projectClass = IntermediateStream.builder() .addContentTypes(DefaultContentType.CLASSES) .addScopes(Scope.PROJECT, Scope.SUB_PROJECTS) .setRootLocation(rootFolder) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TransformOutputProvider output = projectClass.asOutput(); File addedJar = output.getContentLocation("added", ImmutableSet.of(DefaultContentType.CLASSES), ImmutableSet.of(Scope.PROJECT), Format.JAR); mkdirs(addedJar.getParentFile()); Files.write("foo", addedJar, Charsets.UTF_8); File changedJar = output.getContentLocation("changed", ImmutableSet.of(DefaultContentType.CLASSES), ImmutableSet.of(Scope.PROJECT), Format.JAR); mkdirs(changedJar.getParentFile()); Files.write("foo", changedJar, Charsets.UTF_8); File enhancedAddedJar = output.getContentLocation("added", ImmutableSet.of(DefaultContentType.CLASSES), ImmutableSet.of(Scope.SUB_PROJECTS), Format.JAR); mkdirs(addedJar.getParentFile()); Files.write("foo", addedJar, Charsets.UTF_8); File enhancedChangedJar = output.getContentLocation("changed", ImmutableSet.of(DefaultContentType.CLASSES), ImmutableSet.of(Scope.SUB_PROJECTS), Format.JAR); mkdirs(changedJar.getParentFile()); Files.write("foo", changedJar, Charsets.UTF_8); File enhancedRemovedJar = output.getContentLocation("removed", ImmutableSet.of(DefaultContentType.CLASSES), ImmutableSet.of(Scope.SUB_PROJECTS), Format.JAR); final ImmutableMap<File, Status> jarMap = ImmutableMap.of( addedJar, Status.ADDED, changedJar, Status.CHANGED); TestTransform classesTransform = TestTransform.builder() .setIncremental(true) .setInputTypes(DefaultContentType.CLASSES) .setScopes(Scope.PROJECT) .build(); AndroidTask<TransformTask> classesTask = transformManager .addTransform(taskFactory, scope, classesTransform); TransformTask transformTask = (TransformTask) taskFactory.named(classesTask.getName()); assertThat(transformTask).isNotNull(); List<TransformStream> streams = transformManager.getStreams(); assertThat(streams).hasSize(2); transformTask.transform(inputBuilder() .incremental() .addedFile(addedJar) .addedFile(enhancedAddedJar) .modifiedFile(changedJar) .modifiedFile(enhancedChangedJar) .removedFile(enhancedRemovedJar) .build()); assertThat(classesTransform.isIncrementalInputs()).isTrue(); Collection<TransformInput> inputs = classesTransform.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(jarMap.size()); for (JarInput jarInput : jarInputs) { File file = jarInput.getFile(); assertThat(file).isIn(jarMap.keySet()); assertThat(jarInput.getStatus()).isSameAs(jarMap.get(file)); } }
@Test public void incrementalFolderInputInOriginalStream() throws TransformException, InterruptedException, IOException { File rootFolder = temporaryFolder.newFolder(); OriginalStream projectClass = OriginalStream.builder() .addContentType(DefaultContentType.CLASSES) .addScope(Scope.PROJECT) .setFolder(rootFolder) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); 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 addedFile = new File(rootFolder, "added"); File modifiedFile = new File(rootFolder, "modified"); File removedFile = new File(rootFolder, "removed"); transformTask.transform(inputBuilder() .incremental() .addedFile(addedFile) .modifiedFile(modifiedFile) .removedFile(removedFile) .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(1); DirectoryInput singleDirectoryInput = Iterables.getOnlyElement(directoryInputs); assertThat(singleDirectoryInput.getFile()).isEqualTo(rootFolder); Map<File, Status> changedFiles = singleDirectoryInput.getChangedFiles(); assertThat(changedFiles).hasSize(3); assertThat(changedFiles).containsEntry(addedFile, Status.ADDED); assertThat(changedFiles).containsEntry(modifiedFile, Status.CHANGED); assertThat(changedFiles).containsEntry(removedFile, Status.REMOVED); }
@Test public void incrementalFolderInputInIntermediateStream() 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); 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 addedFile = new File(outputFolder, "added"); File modifiedFile = new File(outputFolder, "modified"); File removedFile = new File(outputFolder, "removed"); transformTask.transform(inputBuilder() .incremental() .addedFile(addedFile) .modifiedFile(modifiedFile) .removedFile(removedFile) .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(1); DirectoryInput singleDirectoryInput = Iterables.getOnlyElement(directoryInputs); assertThat(singleDirectoryInput.getFile()).isEqualTo(outputFolder); Map<File, Status> changedFiles = singleDirectoryInput.getChangedFiles(); assertThat(changedFiles).hasSize(3); assertThat(changedFiles).containsEntry(addedFile, Status.ADDED); assertThat(changedFiles).containsEntry(modifiedFile, Status.CHANGED); assertThat(changedFiles).containsEntry(removedFile, Status.REMOVED); }
@Test public void incrementalComplexTypesFolderInputInIntermediateStream() throws TransformException, InterruptedException, IOException { File rootFolder = temporaryFolder.newFolder(); IntermediateStream projectClass = IntermediateStream.builder() .addContentTypes(DefaultContentType.CLASSES, ExtendedContentType.CLASSES_ENHANCED) .addScopes(Scope.PROJECT) .setRootLocation(rootFolder) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TransformOutputProvider output = projectClass.asOutput(); File classesOutput = output.getContentLocation("classes", ImmutableSet.of(DefaultContentType.CLASSES), projectClass.getScopes(), Format.DIRECTORY); mkdirs(classesOutput); File enhancedClassesOutput = output.getContentLocation("enhanced", ImmutableSet.of(ExtendedContentType.CLASSES_ENHANCED), 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(2); File addedFile = new File(classesOutput, "added"); File modifiedFile = new File(classesOutput, "modified"); File removedFile = new File(classesOutput, "removed"); File enhancedRemoved = new File(enhancedClassesOutput, "removed"); File enhancedAdded = new File(enhancedClassesOutput, "added"); File enhancedModified = new File(enhancedClassesOutput, "modified"); transformTask.transform(inputBuilder() .incremental() .addedFile(addedFile) .addedFile(enhancedAdded) .modifiedFile(modifiedFile) .modifiedFile(enhancedModified) .removedFile(removedFile) .removedFile(enhancedRemoved) .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(1); DirectoryInput singleDirectoryInput = Iterables.getOnlyElement(directoryInputs); assertThat(singleDirectoryInput.getFile()).isEqualTo(classesOutput); Map<File, Status> changedFiles = singleDirectoryInput.getChangedFiles(); assertThat(changedFiles).hasSize(3); assertThat(changedFiles).containsEntry(addedFile, Status.ADDED); assertThat(changedFiles).containsEntry(modifiedFile, Status.CHANGED); assertThat(changedFiles).containsEntry(removedFile, Status.REMOVED); }
@Test public void incrementalComplexScopeFolderInputInIntermediateStream() throws TransformException, InterruptedException, IOException { File rootFolder = temporaryFolder.newFolder(); IntermediateStream projectClass = IntermediateStream.builder() .addContentTypes(DefaultContentType.CLASSES) .addScopes(Scope.PROJECT) .addScopes(Scope.SUB_PROJECTS) .setRootLocation(rootFolder) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); TransformOutputProvider output = projectClass.asOutput(); File classesOutput = output.getContentLocation("classes", ImmutableSet.of(DefaultContentType.CLASSES), ImmutableSet.of(Scope.PROJECT), Format.DIRECTORY); mkdirs(classesOutput); File subProjectOutput = output.getContentLocation("enhanced", ImmutableSet.of(DefaultContentType.CLASSES), ImmutableSet.of(Scope.SUB_PROJECTS), 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(2); File addedFile = new File(classesOutput, "added"); File modifiedFile = new File(classesOutput, "modified"); File removedFile = new File(classesOutput, "removed"); File subProjectRemoved = new File(subProjectOutput, "removed"); transformTask.transform(inputBuilder() .incremental() .addedFile(addedFile) .modifiedFile(modifiedFile) .removedFile(removedFile) .removedFile(subProjectRemoved) .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(1); DirectoryInput singleDirectoryInput = Iterables.getOnlyElement(directoryInputs); assertThat(singleDirectoryInput.getFile()).isEqualTo(classesOutput); Map<File, Status> changedFiles = singleDirectoryInput.getChangedFiles(); assertThat(changedFiles).hasSize(3); assertThat(changedFiles).containsEntry(addedFile, Status.ADDED); assertThat(changedFiles).containsEntry(modifiedFile, Status.CHANGED); assertThat(changedFiles).containsEntry(removedFile, Status.REMOVED); }
@Test public void deletedJarInputInOriginalStream() throws TransformException, InterruptedException, IOException { File jarFile = new File("jar file"); OriginalStream projectClass = OriginalStream.builder() .addContentType(DefaultContentType.CLASSES) .addScope(Scope.PROJECT) .setJar(jarFile) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); 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 deletedJar = new File("deleted jar"); transformTask.transform(inputBuilder() .incremental() .removedFile(deletedJar) .build()); assertThat(t.isIncrementalInputs()).isFalse(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(1); JarInput jarInput = Iterables.getOnlyElement(jarInputs); assertThat(jarInput.getFile()).isEqualTo(jarFile); assertThat(jarInput.getStatus()).isSameAs(Status.NOTCHANGED); }
@Test public void deletedJarInputInIntermediateStream() 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 jarFile = output.getContentLocation("foo", projectClass.getContentTypes(), projectClass.getScopes(), Format.JAR); mkdirs(jarFile.getParentFile()); Files.write("foo", jarFile, Charsets.UTF_8); File deletedJarFile = output.getContentLocation("deleted", projectClass.getContentTypes(), projectClass.getScopes(), Format.JAR); 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); transformTask.transform(inputBuilder() .incremental() .removedFile(deletedJarFile) .build()); assertThat(t.isIncrementalInputs()).isTrue(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(2); List<File> jarLocations = ImmutableList.of(jarFile, deletedJarFile); for (JarInput jarInput : jarInputs) { File file = jarInput.getFile(); assertThat(file).isIn(jarLocations); if (file.equals(jarFile)) { assertThat(jarInput.getStatus()).isSameAs(Status.NOTCHANGED); } else { assertThat(jarInput.getStatus()).isSameAs(Status.REMOVED); } } }
@Test public void deletedFolderInputInOriginalStream() throws TransformException, InterruptedException, IOException { File rootFolder = temporaryFolder.newFolder(); OriginalStream projectClass = OriginalStream.builder() .addContentType(DefaultContentType.CLASSES) .addScope(Scope.PROJECT) .setFolder(rootFolder) .setDependency("my dependency") .build(); transformManager.addStream(projectClass); 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 deletedFolder = new File("deleted"); File removedFile = new File(deletedFolder, "removed"); transformTask.transform(inputBuilder() .incremental() .removedFile(removedFile) .build()); assertThat(t.isIncrementalInputs()).isFalse(); 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(1); DirectoryInput directoryInput = Iterables.getOnlyElement(directoryInputs); assertThat(directoryInput.getFile()).isEqualTo(rootFolder); assertThat(directoryInput.getChangedFiles()).isEmpty(); }
@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); } } }
@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); } } }
@Test public void secondaryFileAddedWithJarInputInOriginalStream() throws TransformException, InterruptedException, IOException { File jarFile = temporaryFolder.newFolder(); 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); File addedFile = new File(jarFile, "added"); transformTask.transform(inputBuilder() .incremental() .addedFile(addedFile) .addedFile(secondaryFile) .build()); assertThat(t.isIncrementalInputs()).isFalse(); Collection<TransformInput> inputs = t.getInputs(); assertThat(inputs).hasSize(1); TransformInput input = Iterables.getOnlyElement(inputs); Collection<JarInput> jarInputs = input.getJarInputs(); assertThat(jarInputs).isNotNull(); assertThat(jarInputs).hasSize(1); JarInput singleJarInput = Iterables.getOnlyElement(jarInputs); assertThat(singleJarInput.getFile()).isEqualTo(jarFile); assertThat(singleJarInput.getStatus()).isSameAs(Status.NOTCHANGED); }
@Test public void secondaryFileAddedWithFolderInputInOriginalStream() throws TransformException, InterruptedException, IOException { File rootFolder = temporaryFolder.newFolder(); TransformStream projectClass = OriginalStream.builder() .addContentType(DefaultContentType.CLASSES) .addScope(Scope.PROJECT) .setFolder(rootFolder) .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); File addedFile = new File(rootFolder, "added"); transformTask.transform(inputBuilder() .incremental() .addedFile(addedFile) .addedFile(secondaryFile) .build()); assertThat(t.isIncrementalInputs()).isFalse(); 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(1); DirectoryInput singleDirectoryInput = Iterables.getOnlyElement(directoryInputs); assertThat(singleDirectoryInput.getFile()).isEqualTo(rootFolder); assertThat(singleDirectoryInput.getChangedFiles()).isEmpty(); }
@Test public void secondaryFileModified() 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) .modifiedFile(secondaryFile) .build()); assertThat(t.isIncrementalInputs()).isFalse(); }
@Test public void secondaryFileModifiedWithIncrementalCapabilities() 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) .setSecondaryInput(SecondaryFile.incremental(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) .modifiedFile(secondaryFile) .build()); assertThat(t.isIncrementalInputs()).isTrue(); assertThat(t.getSecondaryInputs()).hasSize(1); SecondaryInput change = Iterables.getOnlyElement(t.getSecondaryInputs()); assertThat(change.getStatus()).isEqualTo(Status.CHANGED); assertThat(change.getSecondaryInput().getFile()).isEqualTo(secondaryFile); transformTask.transform(inputBuilder() .incremental() .removedFile(secondaryFile) .build()); assertThat(t.isIncrementalInputs()).isTrue(); assertThat(t.getSecondaryInputs()).hasSize(1); change = Iterables.getOnlyElement(t.getSecondaryInputs()); assertThat(change.getStatus()).isEqualTo(Status.REMOVED); assertThat(change.getSecondaryInput().getFile()).isEqualTo(secondaryFile); transformTask.transform(inputBuilder() .incremental() .addedFile(secondaryFile) .build()); assertThat(t.isIncrementalInputs()).isTrue(); assertThat(t.getSecondaryInputs()).hasSize(1); change = Iterables.getOnlyElement(t.getSecondaryInputs()); assertThat(change.getStatus()).isEqualTo(Status.ADDED); assertThat(change.getSecondaryInput().getFile()).isEqualTo(secondaryFile); }
@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(); }
@Test public void streamWithTooManyScopes() throws IOException, TransformException, InterruptedException { File rootFolder = temporaryFolder.newFolder(); IntermediateStream stream = IntermediateStream.builder() .addContentTypes(DefaultContentType.CLASSES) .addScopes(Scope.PROJECT, Scope.EXTERNAL_LIBRARIES) .setRootLocation(rootFolder) .setDependency("my dependency") .build(); transformManager.addStream(stream); TransformOutputProvider output = stream.asOutput(); File outputFolder = output.getContentLocation("foo", stream.getContentTypes(), stream.getScopes(), Format.DIRECTORY); mkdirs(outputFolder); TestTransform t = TestTransform.builder() .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(2); exception.expect(RuntimeException.class); exception.expectMessage("error"); transformTask.transform(inputBuilder().build()); }