/** * Adds multiple jar inputs for this transform input. * * @param filePaths the paths of the jars. * @return this instance of the builder. */ TransformInputBuilder addJarInput(List<String> filePaths) { for (String filePath : filePaths) { addJarInput(new File(filePath)); } return this; }
/** * Adds a jar input folder for this transform input. All the jars found will be added to the class * path. * * @param folder the folder of the jars input. * @return this instance of the builder. */ TransformInputBuilder addJarInputFolder(File folder) { File[] listFiles = folder.listFiles(); if (listFiles != null) { for (File file : listFiles) { if (file.isDirectory()) { addJarInputFolder(file); } else { if (!file.getAbsolutePath().endsWith(DOT_JAR)) { continue; } addJarInput(file); } } } return this; }
private void runTransform(Transform transform, TransformOutputProvider outputProvider) throws Exception { // Cleaning output directory. FileUtil.deleteDirectory(outputJarsDir); outputJarsDir.mkdirs(); // Preparing Transform invocation. TransformInput input = new TransformInputBuilder().addJarInputFolder(inputJarsDir).build(); TransformInput referencedInput = new TransformInputBuilder().addJarInput(androidClassPath).build(); TransformInvocation invocation = new TransformInvocationBuilder() .addInput(input) .addReferencedInput(referencedInput) .setOutputProvider(outputProvider) .build(); // Running the transform invocation. transform.transform(invocation); } }
/** * Adds multiple jar inputs for this transform input. * * @param filePaths the paths of the jars. * @return this instance of the builder. */ TransformInputBuilder addJarInput(String... filePaths) { return addJarInput(Arrays.asList(filePaths)); }
@Test public void addJarInput_whenAddPaths_builtShouldReturnCorrectPaths() throws Exception { File file1 = getTmpFile("tmp1"); File file2 = getTmpFile("tmp2"); TransformInput input = builder.addJarInput(file1.getAbsolutePath(), file2.getAbsolutePath()).build(); assertThat(input.getJarInputs()).hasSize(2); JarInput[] jarInputs = input.getJarInputs().toArray(new JarInput[2]); assertThat(jarInputs[0].getFile().getAbsolutePath()).isEqualTo(file1.getAbsolutePath()); assertThat(jarInputs[1].getFile().getAbsolutePath()).isEqualTo(file2.getAbsolutePath()); }
@Test public void addJarInput_whenAddFile_builtShouldReturnFile() throws Exception { File file = getTmpFile("tmp"); TransformInput input = builder.addJarInput(file).build(); assertThat(input.getJarInputs()).hasSize(1); assertThat(input.getJarInputs().toArray(new JarInput[1])[0].getFile()).isEqualTo(file); }