input.getJarInputs().parallelStream().forEach(jarInput -> { File src = jarInput.getFile(); File dst = invocation.getOutputProvider().getContentLocation( jarInput.getName(), jarInput.getContentTypes(), jarInput.getScopes(), Format.JAR); input.getDirectoryInputs().parallelStream().forEach(directoryInput -> { File src = directoryInput.getFile(); File dst = invocation.getOutputProvider().getContentLocation( directoryInput.getName(), directoryInput.getContentTypes(), directoryInput.getScopes(), Format.DIRECTORY); File dest = invocation.getOutputProvider().getContentLocation( "WMRouter", TransformManager.CONTENT_CLASS, ImmutableSet.of(QualifiedContent.Scope.PROJECT), Format.DIRECTORY);
transformInvocation .getOutputProvider() .getContentLocation(TRANSFORM_OUTPUT, getOutputTypes(), getScopes(), Format.DIRECTORY); transformInvocation .getOutputProvider() .getContentLocation(inputJar.getName(), getOutputTypes(), getScopes(), Format.JAR); outputJar.getParentFile().mkdirs();
private File classRootFor(String id) { return invocation.getOutputProvider().getContentLocation("capt-generated-by:" + id, Collections.singleton(QualifiedContent.DefaultContentType.CLASSES), Collections.singleton(QualifiedContent.Scope.EXTERNAL_LIBRARIES), Format.DIRECTORY); }
private void writeTo(@NonNull TransformOutputProvider outputProvider) throws IOException { File sliceOutputLocation = outputProvider.getContentLocation(name, TransformManager.CONTENT_CLASS, Sets.immutableEnumSet(Scope.PROJECT, Scope.SUB_PROJECTS), Format.DIRECTORY); FileUtils.cleanOutputDir(sliceOutputLocation); // always write our dummy guard class, nobody will ever delete this file which mean // the slice will continue existing even it there is no other .class file in it. createGuardClass(name, sliceOutputLocation); // now copy all the files into its new location. for (Slice.SlicedElement slicedElement : slicedElements) { File outputFile = new File(sliceOutputLocation, new File(slicedElement.packagePath, slicedElement.slicedFile.getName()).getPath()); Files.createParentDirs(outputFile); Files.copy(slicedElement.slicedFile, outputFile); } } }
File dest = outputProvider.getContentLocation(directoryInput.getName(),directoryInput.getContentTypes(),directoryInput.getScopes(), Format.DIRECTORY); FileUtils.copyDirectory(directoryInput.getFile(),dest); name = name.substring(0,name.length()-4); File dest = outputProvider.getContentLocation(name + md5Name,jarInput.getContentTypes(),jarInput.getScopes(),Format.JAR); FileUtils.copyFile(jarInput.getFile(),dest);
Util.deleteIFExists(invocation.getOutputProvider().getContentLocation( jar.getName(), jar.getContentTypes(), jar.getScopes(), Format.JAR)); File output = invocation.getOutputProvider().getContentLocation( jar.getName(), jar.getContentTypes(), jar.getScopes(), Format.JAR); zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(output)));
File dest = outputProvider.getContentLocation(input.getName(), input.getContentTypes(), input.getScopes(), Format.DIRECTORY); FileUtils.copyDirectory(input.getFile(), dest); } else { File dest = outputProvider.getContentLocation(jarName + md5Name, jarInput.getContentTypes(), jarInput.getScopes(), Format.JAR); FileUtils.copyFile(jarInput.getFile(), dest);
/** * Tries to determine the output class file, for rewriting the given class file. * * <p>This will return {@link Optional#absent()} if the class is not part of the program to * shrink (e.g. comes from a platform JAR). */ @NonNull protected Optional<File> chooseOutputFile( @NonNull T klass, @NonNull File classFile, @NonNull Iterable<TransformInput> inputs, @NonNull TransformOutputProvider output) { String classFilePath = classFile.getAbsolutePath(); for (TransformInput input : inputs) { Iterable<QualifiedContent> directoriesAndJars = Iterables.concat(input.getDirectoryInputs(), input.getJarInputs()); for (QualifiedContent directoryOrJar : directoriesAndJars) { File file = directoryOrJar.getFile(); if (classFilePath.startsWith(file.getAbsolutePath())) { File outputDir = output.getContentLocation( FileUtils.getDirectoryNameForJar(file), directoryOrJar.getContentTypes(), directoryOrJar.getScopes(), Format.DIRECTORY); return Optional.of(new File(outputDir, mGraph.getClassName(klass) + ".class")); } } } return Optional.absent(); }
Path outDir = transformInvocation.getOutputProvider().getContentLocation( directoryInput.getName(), directoryInput.getContentTypes(),
private static File getOutputStreamForFile( @NonNull TransformOutputProvider transformOutputProvider, @NonNull DirectoryInput input, @NonNull File file, @NonNull Slices slices) { String relativePackagePath = FileUtils.relativePossiblyNonExistingPath(file.getParentFile(), input.getFile()); Slice slice = slices.getSliceFor(new Slice.SlicedElement(relativePackagePath, file)); return transformOutputProvider.getContentLocation(slice.name, TransformManager.CONTENT_CLASS, Sets.immutableEnumSet(Scope.PROJECT, Scope.SUB_PROJECTS), Format.DIRECTORY); }
TransformOutputProvider outputProvider = transformInvocation.getOutputProvider(); File styleables = outputProvider.getContentLocation("styleables", this.getInputTypes(), this.getScopes(), Format.DIRECTORY); String buildType = styleables.getParentFile().getName(); outputProvider.deleteAll(); throw new UnsupportedOperationException("Unknown format readAll input " + input); File f = outputProvider.getContentLocation(input.getName(), input.getContentTypes(), input.getScopes(), format); if (!f.getParentFile().exists()) f.getParentFile().mkdirs(); File destFolder = outputProvider.getContentLocation(dir.getName(), dir.getContentTypes(), dir.getScopes(), Format.DIRECTORY); try { File dest = outputProvider.getContentLocation(jarInput.getName(), jarInput.getContentTypes(), jarInput.getScopes(), Format.JAR); if (dest.exists()) {
File output = outputProvider.getContentLocation( directoryInput.getName(), directoryInput.getContentTypes(), File output = outputProvider.getContentLocation( jarInput.getName(), jarInput.getContentTypes(), } else { classpathFiles.add(jarInput.getFile()); File output = outputProvider.getContentLocation( jarInput.getName(), jarInput.getContentTypes(), File output = outputProvider.getContentLocation(NAME, getOutputTypes(), Sets.immutableEnumSet(QualifiedContent.Scope.PROJECT), Format.DIRECTORY);
@NonNull private File getOutputLocation( @NonNull TransformOutputProvider output, @NonNull QualifiedContent qualifiedContent, @NonNull File file) { // In InstantRun mode, all files are guaranteed to have a unique name due to the slicer // transform. adding sha1 to the name can lead to cleaning issues in device, it's much // easier if the slices always have the same names, irrespective of the current variant, // last version wins. String name = instantRunBuildContext.isInInstantRunMode() && (qualifiedContent.getScopes().contains(Scope.PROJECT) || qualifiedContent.getScopes().contains(Scope.SUB_PROJECTS)) ? getInstantRunFileName(file) : getFilename(file); File contentLocation = output.getContentLocation(name, TransformManager.CONTENT_DEX, qualifiedContent.getScopes(), multiDex ? Format.DIRECTORY : Format.JAR); if (multiDex) { FileUtils.mkdirs(contentLocation); } else { FileUtils.mkdirs(contentLocation.getParentFile()); } return contentLocation; }
@Override public void transform(@NonNull TransformInvocation invocation) throws IOException, TransformException, InterruptedException { checkNotNull(invocation.getOutputProvider(), "Missing output object for transform " + getName()); File outputDir = invocation.getOutputProvider().getContentLocation( "main", getOutputTypes(), getScopes(), Format.DIRECTORY); FileUtils.mkdirs(outputDir); TransformInput input = Iterables.getOnlyElement(invocation.getInputs()); // we don't want jar inputs. Preconditions.checkState(input.getJarInputs().isEmpty()); DirectoryInput directoryInput = Iterables.getOnlyElement(input.getDirectoryInputs()); File inputDir = directoryInput.getFile(); Instrumenter instrumenter = new Instrumenter(new OfflineInstrumentationAccessGenerator()); if (invocation.isIncremental()) { instrumentFilesIncremental(instrumenter, inputDir, outputDir, directoryInput.getChangedFiles()); } else { instrumentFilesFullRun(instrumenter, inputDir, outputDir); } }
File inputJar = jarInput.getFile(); File outputJar = outputProvider.getContentLocation( jarInput.getName(), jarInput.getContentTypes(), File inputDir = di.getFile(); File outputDir = outputProvider.getContentLocation( di.getName(), di.getContentTypes(),
Set<ContentType> outputTypes = getOutputTypes(); Set<Scope> scopes = getScopes(); File outFile = output.getContentLocation("main", outputTypes, scopes, asJar ? Format.JAR : Format.DIRECTORY); if (asJar) { for (File jarFile : jars) { String jarFileName = jarFile.getName(); File to = output.getContentLocation( jarFileName.substring(0, jarFileName.length() - DOT_JAR.length()), outputTypes, scopes, Format.JAR);
File dirOutput = outputProvider.getContentLocation(dirInput.getName() + "-" + dirInput.getFile().getAbsolutePath().hashCode(), dirInput.getContentTypes(), final File outJarFolder = outputProvider.getContentLocation( jarFile.getName() + "-" + jarFile.getPath().hashCode(), jarInput.getContentTypes(),
File outFile = outputProvider.getContentLocation( getJackFileName(file), getOutputTypes(),
File jarFile = outputProvider.getContentLocation("combined", getOutputTypes(), getScopes(), Format.JAR); FileUtils.mkdirs(jarFile.getParentFile());
private void runJack(@NonNull TransformInvocation transformInvocation) throws ProcessException, IOException, JackToolchain.ToolchainException, ClassNotFoundException { TransformOutputProvider outputProvider = transformInvocation.getOutputProvider(); checkNotNull(outputProvider); final File outDirectory = outputProvider.getContentLocation( "main", getOutputTypes(), getScopes(), Format.DIRECTORY); options.setDexOutputDirectory(outDirectory); options.setClasspaths( TransformInputUtil.getAllFiles(transformInvocation.getReferencedInputs())); options.setImportFiles(TransformInputUtil.getAllFiles(transformInvocation.getInputs())); options.setInputFiles(getSourceFiles()); JackToolchain toolchain = new JackToolchain( androidBuilder.getTargetInfo().getBuildTools(), androidBuilder.getLogger(), androidBuilder.getErrorReporter()); toolchain.convert(options, androidBuilder.getJavaProcessExecutor(), jackInProcess); }