@TaskAction public void preCompile() { // Create directory for output of annotation processor. FileUtils.mkdirs(annotationProcessorOutputFolder); }
private void init() throws IOException { if (closer == null) { FileUtils.mkdirs(jarFile.getParentFile()); closer = Closer.create(); FileOutputStream fos = closer.register(new FileOutputStream(jarFile)); BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos)); jarOutputStream = closer.register(new JarOutputStream(bos)); } }
@TaskAction public void compile() { // TODO FileUtils.mkdirs(getOutputDirectory()); }
/** * Obtains the temporary directory for {@code aapt} to use. * * @return the temporary directory */ private File getAaptTempDir() { return FileUtils.mkdirs(new File(getIncrementalFolder(), "aapt-temp")); }
private static void deleteDirectoryContents(@NonNull File directory) throws IOException { if (!directory.exists()) { FileUtils.mkdirs(directory); } else if (!directory.isDirectory()) { FileUtils.delete(directory); FileUtils.mkdirs(directory); } else { FileUtils.deleteDirectoryContents(directory); } }
/** * Adds a file to the cache, replacing any file that had the exact same absolute path. * * @param f the file to add * @throws IOException failed to copy the file into the cache */ public void add(@NonNull File f) throws IOException { Preconditions.checkArgument(f.isFile(), "!f.isFile()"); if (!directory.isDirectory()) { FileUtils.mkdirs(directory); } String k = key(f); Files.copy(f, new File(directory, k)); }
private void copyFromJar(@NonNull File jarFile) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try (ZipFile zipFile = new ZipFile(jarFile)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String entryPath = entry.getName(); if (!pattern.matcher(entryPath).matches()) { continue; } // read the content. buffer.reset(); ByteStreams.copy(zipFile.getInputStream(entry), buffer); // get the output file and write to it. final File to = computeFile(jniLibsFolder, entryPath); FileUtils.mkdirs(to.getParentFile()); Files.write(buffer.toByteArray(), to); } } }
private void createEcjOptionFile() throws IOException { checkNotNull(options.getEcjOptionFile()); StringBuilder sb = new StringBuilder(); for (File sourceFile : options.getInputFiles()) { sb.append('\"') .append(FileUtils.toSystemIndependentPath(sourceFile.getAbsolutePath())) .append('\"') .append("\n"); } FileUtils.mkdirs(options.getEcjOptionFile().getParentFile()); Files.write(sb.toString(), options.getEcjOptionFile(), Charsets.UTF_8); }
/** * Obtains the temporary directory for {@code aapt} to use. * * @return the temporary directory */ @NonNull private File getAaptTempDir() { return FileUtils.mkdirs(new File(getIncrementalFolder(), "aapt-temp")); }
public void generateUnbundledWearApkData( @NonNull File outResFolder, @NonNull String mainPkgName) throws ProcessException, IOException { String content = String.format( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<wearableApp package=\"%1$s\">\n" + " <unbundled />\n" + "</wearableApp>", mainPkgName); // xml folder File resXmlFile = new File(outResFolder, FD_RES_XML); FileUtils.mkdirs(resXmlFile); Files.write( content, new File(resXmlFile, ANDROID_WEAR_MICRO_APK + DOT_XML), Charsets.UTF_8); }
private static void copy(@NonNull File inputFile, @NonNull File outputDir, @NonNull String archivePath) throws IOException { File outputFile = new File(outputDir, archivePath); mkdirs(outputFile.getParentFile()); Files.copy(inputFile, outputFile); }
/** * Obtains the file that will receive the compilation output of a given file. This method * will return a unique file in the output directory for each input file. * * <p>This method will also create any parent directories needed to hold the output file. * * @param file the file * @param output the output directory * @return the output file */ @NonNull private static File compileOutputFor(@NonNull File file, @NonNull File output) { Preconditions.checkArgument(file.isFile(), "!file.isFile()"); Preconditions.checkArgument(output.isDirectory(), "!output.isDirectory()"); File parentDir = new File(output, file.getParentFile().getName()); FileUtils.mkdirs(parentDir); return new File(parentDir, file.getName()); }
private void mergeAll(@NonNull File outputDir, @NonNull String archivePath) throws IOException { File outputFile = new File(outputDir, archivePath); deleteIfExists(outputFile); mkdirs(outputFile.getParentFile()); List<File> allFiles = getAllFiles(archivePath); if (!allFiles.isEmpty()) { OutputStream os = null; try { os = new BufferedOutputStream(new FileOutputStream(outputFile)); // take each file in order and merge them. for (File file : allFiles) { Files.copy(file, os); } } finally { if (os != null) { os.close(); } } } }
@Override public void execute(@NonNull Task task) { task.doLast(t -> { FileUtils.mkdirs(variantScope.getAssetsDir()); }); } });
private void copyFromFolder( @NonNull File fromFolder, @NonNull File toFolder, @NonNull String path) throws IOException { File from = computeFile(fromFolder, validator.keyToFolderPath(path)); File to = computeFile(toFolder, path); mkdirs(to.getParentFile()); Files.copy(from, to); }
@TaskAction void generate() throws IOException, ProcessException, LoggedErrorException, InterruptedException { AndroidBuilder builder = getBuilder(); // always empty output dir. File outDir = getResOutputDir(); FileUtils.cleanOutputDir(outDir); File apk = getApkFile(); if (apk != null) { // copy the file into the destination, by sanitizing the name first. File rawDir = new File(outDir, FD_RES_RAW); FileUtils.mkdirs(rawDir); File to = new File(rawDir, ANDROID_WEAR_MICRO_APK + DOT_ANDROID_PACKAGE); Files.copy(apk, to); builder.generateApkData(apk, outDir, getMainPkgName(), ANDROID_WEAR_MICRO_APK); } else { builder.generateUnbundledWearApkData(outDir, getMainPkgName()); } AndroidBuilder.generateApkDataEntryInManifest(getMinSdkVersion(), getTargetSdkVersion(), getManifestFile()); }
@Override public void processFile(@NonNull File sourceFolder, @NonNull File sourceFile) throws ProcessException, IOException { ProcessInfoBuilder builder = new ProcessInfoBuilder(); builder.setExecutable(mGlslcLocation); // working dir for the includes builder.addArgs("-I", mSourceFolder.getPath()); // compute the output file path String relativePath = FileUtils.relativePath(sourceFile, sourceFolder); File destFile = new File(mOutputDir, relativePath + ".spv"); // add the args builder.addArgs(getArgs(relativePath)); // the source file builder.addArgs(sourceFile.getPath()); // add the output file builder.addArgs("-o", destFile.getPath()); // make sure the output file's parent folder is created. FileUtils.mkdirs(destFile.getParentFile()); ProcessResult result = mProcessExecutor.execute( builder.createProcess(), mProcessOutputHandler); result.rethrowFailure().assertNormalExitValue(); }
@NonNull public static Aapt makeAapt(@NonNull AndroidBuilder androidBuilder, @NonNull PackagingScope packagingScope, @NonNull String incrementalDirName) { return AaptGradleFactory.make( androidBuilder, true, packagingScope.getProject(), packagingScope.getVariantType(), FileUtils.mkdirs(new File( packagingScope.getIncrementalDir("instantRunDependenciesApkBuilder"), "aapt-temp")), 0); } }
private void doTransform(@NonNull Collection<TransformInput> inputs, boolean isIncremental) throws IOException, TransformException, InterruptedException { if (!isIncremental && outputDir.exists()) { FileUtils.cleanOutputDir(outputDir); } else { FileUtils.mkdirs(outputDir); } InstantRunVerifierStatus resultSoFar = InstantRunVerifierStatus.COMPATIBLE; for (TransformInput transformInput : inputs) { resultSoFar = processFolderInputs(resultSoFar, isIncremental, transformInput); resultSoFar = processJarInputs(resultSoFar, transformInput); } // if we are being asked to produce the RESTART artifacts, there is no need to set the // verifier result, however the transform needed to run to backup the .class files. if (!variantScope.getGlobalScope().isActive(OptionalCompilationStep.RESTART_ONLY)) { variantScope.getInstantRunBuildContext().setVerifierStatus(resultSoFar); } }
@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); } }