com.android.utils.FileUtils Java Examples
The following examples show how to use
com.android.utils.FileUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CollectHandler.java From EasyRouter with Apache License 2.0 | 6 votes |
@Override public boolean onStart(QualifiedContent content) throws IOException { if (content instanceof JarInput) { JarInput jarInput = (JarInput) content; File targetFile = context.getRelativeFile(content); switch (jarInput.getStatus()) { case REMOVED: FileUtils.deleteIfExists(targetFile); return false; case CHANGED: FileUtils.deleteIfExists(targetFile); default: Files.createParentDirs(targetFile); map.put(content, new JarWriter(targetFile)); } return true; } return false; }
Example #2
Source File: AtlasMergeJavaResourcesTransform.java From atlas with Apache License 2.0 | 6 votes |
private void processAtlasNativeSo(String path) { appVariantOutputContext.getVariantContext().getProject().getLogger().info("processAtlasNativeSo soFile path:" + path); Set<String> removedNativeSos = appVariantOutputContext.getVariantContext().getAtlasExtension().getTBuildConfig().getOutOfApkNativeSos(); if (removedNativeSos.size() > 0) { if (removedNativeSos.contains(path)) { File soFile = outputLocation.toPath().resolve(path).toFile(); appVariantOutputContext.getVariantContext().getProject().getLogger().info("remove soFile path:" + soFile.getAbsolutePath()); String url = AtlasBuildContext.atlasApkProcessor.uploadNativeSo(appVariantOutputContext.getVariantContext().getProject(), soFile, appVariantOutputContext.getVariantContext().getBuildType()); NativeInfo nativeInfo = new NativeInfo(); nativeInfo.bundleName = "mainBundle"; nativeInfo.md5 = MD5Util.getFileMD5(soFile); nativeInfo.url = url; nativeInfo.path = path; appVariantOutputContext.getSoMap().put(path, nativeInfo); try { org.apache.commons.io.FileUtils.moveFileToDirectory(soFile, appVariantOutputContext.getRemoteNativeSoFolder(nativeInfo.bundleName), true); } catch (IOException e) { e.printStackTrace(); } } } }
Example #3
Source File: TransformReplacer.java From atlas with Apache License 2.0 | 6 votes |
public void replaceShrinkResourcesTransform() { File shrinkerOutput = FileUtils.join( variantContext.getScope().getGlobalScope().getIntermediatesDir(), "res_stripped", variantContext.getScope().getVariantConfiguration().getDirName()); List<TransformTask> baseTransforms = TransformManager.findTransformTaskByTransformType( variantContext, ShrinkResourcesTransform.class); for (TransformTask transform : baseTransforms) { ShrinkResourcesTransform oldTransform = (ShrinkResourcesTransform) transform.getTransform(); ResourcesShrinker resourcesShrinker = new ResourcesShrinker(oldTransform, variantContext.getVariantData(), variantContext.getScope().getOutput(TaskOutputHolder.TaskOutputType.PROCESSED_RES), shrinkerOutput, AaptGeneration.fromProjectOptions(variantContext.getScope().getGlobalScope().getProjectOptions()), variantContext.getScope().getOutput(TaskOutputHolder.TaskOutputType.SPLIT_LIST), variantContext.getProject().getLogger(), variantContext); ReflectUtils.updateField(transform, "transform", resourcesShrinker); } }
Example #4
Source File: AwbAndroidJavaCompile.java From atlas with Apache License 2.0 | 6 votes |
@Override protected void compile(IncrementalTaskInputs inputs) { getLogger().info( "Compiling with source level {} and target level {}.", getSourceCompatibility(), getTargetCompatibility()); if (isPostN()) { if (!JavaVersion.current().isJava8Compatible()) { throw new RuntimeException("compileSdkVersion '" + compileSdkVersion + "' requires " + "JDK 1.8 or later to compile."); } } if (awbBundle.isDataBindEnabled() && !analyticsed) { processAnalytics(); analyticsed = true; } // Create directory for output of annotation processor. FileUtils.mkdirs(annotationProcessorOutputFolder); mInstantRunBuildContext.startRecording(InstantRunBuildContext.TaskType.JAVAC); compile(); mInstantRunBuildContext.stopRecording(InstantRunBuildContext.TaskType.JAVAC); }
Example #5
Source File: TaobaoInstantRunTransform.java From atlas with Apache License 2.0 | 6 votes |
protected void wrapUpOutputs(File classes2Folder, File classes3Folder) throws IOException { // the transform can set the verifier status to failure in some corner cases, in that // case, make sure we delete our classes.3 // if (!transformScope.getInstantRunBuildContext().hasPassedVerification()) { // FileUtils.cleanOutputDir(classes3Folder); // return; // } // otherwise, generate the patch file and add it to the list of files to process next. ImmutableList<String> generatedClassNames = generatedClasses3Names.build(); if (!generatedClassNames.isEmpty()) { File patchClassInfo = new File(variantContext.getProject().getBuildDir(), "outputs/patchClassInfo.json"); org.apache.commons.io.FileUtils.writeStringToFile(patchClassInfo, JSON.toJSONString(modifyClasses)); modifyClasses.entrySet().forEach(stringStringEntry -> LOGGER.warning(stringStringEntry.getKey() + ":" + stringStringEntry.getValue())); writePatchFileContents( generatedClassNames, classes3Folder, transformScope.getInstantRunBuildContext().getBuildId()); } }
Example #6
Source File: TaobaoInstantRunTransform.java From atlas with Apache License 2.0 | 6 votes |
private static void deleteOutputFile( @NonNull IncrementalVisitor.VisitorBuilder visitorBuilder, @NonNull File inputDir, @NonNull File inputFile, @NonNull File outputDir) { String inputPath = FileUtils.relativePossiblyNonExistingPath(inputFile, inputDir); String outputPath = visitorBuilder.getMangledRelativeClassFilePath(inputPath); File outputFile = new File(outputDir, outputPath); if (outputFile.exists()) { try { FileUtils.delete(outputFile); } catch (IOException e) { // it's not a big deal if the file cannot be deleted, hopefully // no code is still referencing it, yet we should notify. LOGGER.warning("Cannot delete %1$s file.\nCause: %2$s", outputFile, Throwables.getStackTraceAsString(e)); } } }
Example #7
Source File: InjectTransformManager.java From atlas with Apache License 2.0 | 6 votes |
/** * Get the task outputStream * * @param injectTransform * @param scope * @param taskName * @param <T> * @return */ @NotNull private <T extends Transform> IntermediateStream getOutputStream(T injectTransform, @NonNull VariantScope scope, String taskName) { File outRootFolder = FileUtils.join(project.getBuildDir(), StringHelper.toStrings(AndroidProject.FD_INTERMEDIATES, FD_TRANSFORMS, injectTransform.getName(), scope.getDirectorySegments())); Set<? super Scope> requestedScopes = injectTransform.getScopes(); // create the output return IntermediateStream.builder(project,injectTransform.getName()) .addContentTypes(injectTransform.getOutputTypes()) .addScopes(requestedScopes) .setTaskName(taskName) .setRootLocation(outRootFolder).build(); }
Example #8
Source File: ProcessAwbAndroidResources.java From atlas with Apache License 2.0 | 6 votes |
private Aapt makeAapt() throws IOException { AndroidBuilder builder = getBuilder(); MergingLog mergingLog = new MergingLog(getMergeBlameLogFolder()); FileCache fileCache = appVariantContext.getScope().getGlobalScope().getBuildCache(); ProcessOutputHandler processOutputHandler = new ParsingProcessOutputHandler( new ToolOutputParser( aaptGeneration == AaptGeneration.AAPT_V1 ? new AaptOutputParser() : new Aapt2OutputParser(), getILogger()), new MergingLogRewriter(mergingLog::find, builder.getErrorReporter())); return AaptGradleFactory.make( aaptGeneration, builder, processOutputHandler, fileCache, true, FileUtils.mkdirs(new File(getIncrementalFolder(), "awb-aapt-temp/"+awbBundle.getName())), aaptOptions.getCruncherProcesses()); }
Example #9
Source File: Dex.java From javaide with GNU General Public License v3.0 | 6 votes |
private void doTaskAction(@Nullable Collection<File> inputFiles, @Nullable File inputDir) throws IOException, ProcessException, InterruptedException { File outFolder = getOutputFolder(); FileUtils.emptyFolder(outFolder); File tmpFolder = getTmpFolder(); tmpFolder.mkdirs(); // if some of our .jar input files exist, just reset the inputDir to null for (File inputFile : inputFiles) { if (inputFile.exists()) { inputDir = null; } } if (inputDir != null) { inputFiles = getProject().files(inputDir).getFiles(); } getBuilder().convertByteCode(inputFiles, getLibraries(), outFolder, getMultiDexEnabled(), getMainDexListFile(), getDexOptions(), getAdditionalParameters(), tmpFolder, false, getOptimize(), new LoggedProcessOutputHandler(getILogger())); }
Example #10
Source File: AwbApkPackageTask.java From atlas with Apache License 2.0 | 6 votes |
static File copyJavaResourcesOnly(File destinationFolder, File zip64File) throws IOException { File cacheDir = new File(destinationFolder, ZIP_64_COPY_DIR); File copiedZip = new File(cacheDir, zip64File.getName()); FileUtils.mkdirs(copiedZip.getParentFile()); try (ZipFile inFile = new ZipFile(zip64File); ZipOutputStream outFile = new ZipOutputStream( new BufferedOutputStream(new FileOutputStream(copiedZip)))) { Enumeration<? extends ZipEntry> entries = inFile.entries(); while (entries.hasMoreElements()) { ZipEntry zipEntry = entries.nextElement(); if (!zipEntry.getName().endsWith(SdkConstants.DOT_CLASS)) { outFile.putNextEntry(new ZipEntry(zipEntry.getName())); try { ByteStreams.copy( new BufferedInputStream(inFile.getInputStream(zipEntry)), outFile); } finally { outFile.closeEntry(); } } } } return copiedZip; }
Example #11
Source File: LibraryCache.java From javaide with GNU General Public License v3.0 | 6 votes |
public static void unzipAar(final File bundle, final File folderOut, final Project project) throws IOException { FileUtils.deleteFolder(folderOut); folderOut.mkdirs(); project.copy(new Action<CopySpec>() { @Override public void execute(CopySpec copySpec) { copySpec.from(project.zipTree(bundle)); copySpec.into(new Object[]{folderOut}); copySpec.filesMatching("**/*.jar", new Action<FileCopyDetails>() { @Override public void execute(FileCopyDetails details) { setRelativePath(details, new RelativePath(false, FD_JARS).plus(details.getRelativePath())); } }); } }); }
Example #12
Source File: Packager.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Checks the merger folder is: * - a directory. * - if the folder exists, that it can be modified. * - if it doesn't exists, that a new folder can be created. * @param file the File to check * @throws PackagerException If the check fails */ private static void checkMergingFolder(File file) throws PackagerException { if (file.isFile()) { throw new PackagerException("%s is a file!", file); } if (file.exists()) { // will be a directory in this case. if (!file.canWrite()) { throw new PackagerException("Cannot write %s", file); } } try { FileUtils.emptyFolder(file); } catch (IOException e) { throw new PackagerException(e); } }
Example #13
Source File: AvdManager.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
private static void checkSkinsFolder(AndroidSdk defaultSdk) { String sdkPath = defaultSdk.getSdkPath(); File skinsFolder = new File(sdkPath+File.separator+"skins"); if(!skinsFolder.exists()){ NotifyDescriptor nd = new NotifyDescriptor.Confirmation("<html>The skins subdirectory was not found in your default SDK directory. <br/>" + "To make AVD Manager work properly, you need to install this directory.<br/>" + "Do you want to automatically create and install the necessary files?</html>", "Creating a skins Directory", NotifyDescriptor.YES_NO_OPTION,NotifyDescriptor.WARNING_MESSAGE); Object notify = DialogDisplayer.getDefault().notify(nd); if(NotifyDescriptor.YES_OPTION.equals(notify)){ skinsFolder.mkdirs(); final File skinsSourceFolder = InstalledFileLocator.getDefault().locate("modules/ext/skins", "sk-arsi-netbeans-gradle-android-Gradle-Android-support-ext-libs-android", false); if(skinsSourceFolder.exists()){ try { FileUtils.copyDirectory(skinsSourceFolder, skinsFolder); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } } } }
Example #14
Source File: ProjectTemplateLoader.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
@Override public void instantiate(File from, File to) throws TemplateProcessingException { if ("build.gradle".equals(to.getName()) && buildGradleLocation == null) { buildGradleLocation = to; } String process = process(templatePath + from.getPath(), parameters); if (process == null) { NotifyDescriptor nd = new NotifyDescriptor.Message("Unable to instantiate template " + from.getPath(), NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notifyLater(nd); } else { try { FileUtils.writeToFile(to, process); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } }
Example #15
Source File: AtlasBundleInstantApp.java From atlas with Apache License 2.0 | 5 votes |
@TaskAction public void taskAction() throws IOException { FileUtils.mkdirs(bundleDirectory); File bundleFile = new File(bundleDirectory, bundleName); FileUtils.deleteIfExists(bundleFile); File baseFeatureApk = new File(bundleDirectory, "baseFeature.apk"); if (!apkFile.exists()){ File[]apkFiles = apkFile.getParentFile().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(".apk"); } }); if (apkFiles != null){ apkFile = apkFiles[0]; } } if (apkFile.exists()) { try { make(baseFeatureApk, apkFile, bundleFile, scope.getVariantConfiguration().getSigningConfig()); } catch (SigningException e) { e.printStackTrace(); } }else { getLogger().error(apkFile.getAbsolutePath()+" is not exist!"); } }
Example #16
Source File: DirDexArchiveHook.java From atlas with Apache License 2.0 | 5 votes |
@Override public void removeFile(@NonNull String relativePath) throws IOException { Path finalPath = rootDir.resolve(relativePath); if (Files.isDirectory(finalPath)) { FileUtils.deleteDirectoryContents(finalPath.toFile()); } Files.deleteIfExists(finalPath); }
Example #17
Source File: JarMergerWithOverride.java From atlas with Apache License 2.0 | 5 votes |
private void init() throws IOException { if (closer == null) { FileUtils.mkdirs(jarFile.getParentFile()); closer = Closer.create(); FileOutputStream fos = closer.register(new FileOutputStream(jarFile)); jarOutputStream = closer.register(new JarOutputStream(fos)); } }
Example #18
Source File: VariantContext.java From atlas with Apache License 2.0 | 5 votes |
public File getAwbResourceBlameLogDir(AwbBundle awbBundle) { return FileUtils.join( scope.getGlobalScope().getIntermediatesDir(), StringHelper.toStrings( "awb-blame", "res", scope.getDirectorySegments(),awbBundle.getName())); }
Example #19
Source File: VariantContext.java From atlas with Apache License 2.0 | 5 votes |
public File getAwbShadersOutputDir(AwbBundle awbBundle) { return FileUtils.join(new File( scope.getGlobalScope().getGeneratedDir().getParentFile(),"/awb-generated/"), StringHelper.toStrings( "assets", "shaders", scope.getDirectorySegments(),awbBundle.getName())); }
Example #20
Source File: AtlasDexArchiveBuilderTransform.java From atlas with Apache License 2.0 | 5 votes |
@NonNull private static File getPreDexFolder( @NonNull TransformOutputProvider output, @NonNull DirectoryInput directoryInput) { return FileUtils.mkdirs( output.getContentLocation( directoryInput.getName(), ImmutableSet.of(ExtendedContentType.DEX_ARCHIVE), directoryInput.getScopes(), Format.DIRECTORY)); }
Example #21
Source File: AppVariantContext.java From atlas with Apache License 2.0 | 5 votes |
public Map<String, String> getBaseUnitTagMap() throws IOException { Map<String, String> tagMap = new HashMap<>(); if (null != this.apContext.getApExploredFolder() && this.apContext.getApExploredFolder().exists()) { File file = new File(this.apContext.getApExploredFolder(), "atlasFrameworkProperties.json"); if (file.exists()) { JSONObject jsonObject = (JSONObject) JSON.parse(org.apache.commons.io.FileUtils.readFileToString(file)); JSONArray jsonArray = jsonObject.getJSONArray("bundleInfo"); for (JSONObject obj : jsonArray.toArray(new JSONObject[0])) { tagMap.put(obj.getString("pkgName"), obj.getString("unique_tag")); } } } return tagMap; }
Example #22
Source File: ApContext.java From atlas with Apache License 2.0 | 5 votes |
public void setApExploredFolder(File apExploredFolder) { this.apExploredFolder = apExploredFolder; this.baseManifest = new File(apExploredFolder, ANDROID_MANIFEST_XML); this.baseModifyManifest = FileUtils.join(apExploredFolder, "manifest-modify", ANDROID_MANIFEST_XML); this.baseApk = new File(apExploredFolder, AP_INLINE_APK_FILENAME); this.baseApkDirectory = new File(apExploredFolder, AP_INLINE_APK_EXTRACT_DIRECTORY); this.baseAwbDirectory = new File(apExploredFolder, AP_INLINE_AWB_EXTRACT_DIRECTORY); this.baseUnzipBundleDirectory = new File(apExploredFolder,SO_LOCATION_PREFIX); this.baseExplodedAwbDirectory = new File(apExploredFolder, AP_INLINE_AWB_EXPLODED_DIRECTORY); this.basePackageIdFile = new File(apExploredFolder, PACKAGE_ID_PROPERTIES_FILENAME); this.baseAtlasFrameworkPropertiesFile = new File(apExploredFolder, ATLAS_FRAMEWORK_PROPERTIES_FILENAME); this.baseDependenciesFile = new File(apExploredFolder, DEPENDENCIES_FILENAME); this.baseStableIdsFile = new File(apExploredFolder, STABLE_IDS_FILENAME); }
Example #23
Source File: ApContext.java From atlas with Apache License 2.0 | 5 votes |
public File getBaseAwb(String soFileName) { File file = FileUtils.join(baseAwbDirectory, soFileName); if (!file.exists()) { return null; } return file; }
Example #24
Source File: ApContext.java From atlas with Apache License 2.0 | 5 votes |
public File getBaseExplodedAwb(String soFileName) { File file = FileUtils.join(baseExplodedAwbDirectory, FilenameUtils.getBaseName(soFileName)); if (!file.exists()) { return null; } return file; }
Example #25
Source File: ApContext.java From atlas with Apache License 2.0 | 5 votes |
public File getBaseSo(String soFileName){ File file = FileUtils.join(baseUnzipBundleDirectory,soFileName); if (file.exists()){ return file; } return null; }
Example #26
Source File: AtlasDependencyGraph.java From atlas with Apache License 2.0 | 5 votes |
@NonNull private static List<File> findLocalJarsAsFiles(@NonNull File folder) { File localJarRoot = FileUtils.join(folder, FD_JARS, FD_AAR_LIBS); if (!localJarRoot.isDirectory()) { return ImmutableList.of(); } File[] jarFiles = localJarRoot.listFiles((dir, name) -> name.endsWith(DOT_JAR)); if (jarFiles != null && jarFiles.length > 0) { return ImmutableList.copyOf(jarFiles); } return ImmutableList.of(); }
Example #27
Source File: LibraryCache.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Extract to local repository */ public boolean extractAar(File bundle, File folderOut) { if (!bundle.isFile() || !bundle.getName().toLowerCase().endsWith(".aar")) { return false; } try { FileUtils.deleteFolder(folderOut); folderOut.mkdirs(); Zip.unpackZip(bundle, folderOut); File[] jarsFile = folderOut.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isFile() && pathname.getName().endsWith(".jar"); } }); File jarFolder = new File(folderOut, FD_JARS); jarFolder.mkdirs(); for (File file : jarsFile) { file.renameTo(new File(jarFolder, file.getName())); } return true; } catch (Exception e) { return false; } }
Example #28
Source File: MergeResources.java From javaide with GNU General Public License v3.0 | 5 votes |
@Override protected void doFullTaskAction() throws IOException { // this is full run, clean the previous output File destinationDir = getOutputDir(); FileUtils.emptyFolder(destinationDir); List<ResourceSet> resourceSets = getConfiguredResourceSets(); // create a new merger and populate it with the sets. ResourceMerger merger = new ResourceMerger(); try { for (ResourceSet resourceSet : resourceSets) { resourceSet.loadFromFiles(getILogger()); merger.addDataSet(resourceSet); } // get the merged set and write it down. MergedResourceWriter writer = new MergedResourceWriter( destinationDir, getCruncher(), getCrunchPng(), getProcess9Patch(), getPublicFile(), preprocessor); writer.setInsertSourceMarkers(getInsertSourceMarkers()); merger.mergeData(writer, false /*doCleanUp*/); // No exception? Write the known state. merger.writeBlobTo(getIncrementalFolder(), writer); throw new StopExecutionException("Stop for now."); } catch (MergingException e) { System.out.println(e.getMessage()); merger.cleanBlob(getIncrementalFolder()); throw new ResourceException(e.getMessage(), e); } }
Example #29
Source File: GenerateResValues.java From javaide with GNU General Public License v3.0 | 5 votes |
@TaskAction public void generate() throws IOException, ParserConfigurationException { File folder = getResOutputDir(); List<Object> resolvedItems = getItems(); if (resolvedItems.isEmpty()) { FileUtils.deleteFolder(folder); } else { ResValueGenerator generator = new ResValueGenerator(folder); generator.addItems(getItems()); generator.generate(); } }
Example #30
Source File: VariantScope.java From javaide with GNU General Public License v3.0 | 5 votes |
@NonNull public File getGeneratedResourcesDir(String name) { return FileUtils.join( globalScope.getGeneratedDir(), "res", name, getVariantConfiguration().getDirName()); }