Java Code Examples for com.android.utils.FileUtils

The following examples show how to use com.android.utils.FileUtils. These examples are extracted from open source projects. 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 Project: atlas   Source File: AtlasDexArchiveBuilderTransform.java    License: Apache License 2.0 6 votes vote down vote up
private List<File> convertAwbJarToDexArchive(
        @NonNull Context context,
        @NonNull JarInput toConvert,
        @NonNull File transformOutputProvider)
        throws Exception {

    File cachedVersion = cacheHandler.getCachedVersionIfPresent(toConvert);
    if (cachedVersion == null) {
        logger.info("AtlasDexArchiveBuilder miss cache:"+toConvert.getFile().getAbsolutePath()+"-> null");

        return convertAwbToDexArchive(context, toConvert, transformOutputProvider, false,true);
    } else {
        logger.info("AtlasDexArchiveBuilder hit cache:"+toConvert.getFile().getAbsolutePath()+"->"+cachedVersion.getAbsolutePath());
        File outputFile = getAwbPreDexJar(transformOutputProvider, toConvert, null);

        FileUtils.copyFile(cachedVersion,outputFile);

        // no need to try to cache an already cached version.
        return ImmutableList.of();
    }
}
 
Example 2
Source Project: atlas   Source File: TransformReplacer.java    License: Apache License 2.0 6 votes vote down vote up
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 3
Source Project: atlas   Source File: AtlasMergeJavaResourcesTransform.java    License: Apache License 2.0 6 votes vote down vote up
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 4
Source Project: atlas   Source File: ProcessAwbAndroidResources.java    License: Apache License 2.0 6 votes vote down vote up
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 5
Source Project: atlas   Source File: AwbApkPackageTask.java    License: Apache License 2.0 6 votes vote down vote up
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 6
Source Project: atlas   Source File: TaobaoInstantRunTransform.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: atlas   Source File: TaobaoInstantRunTransform.java    License: Apache License 2.0 6 votes vote down vote up
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 8
Source Project: atlas   Source File: AwbAndroidJavaCompile.java    License: Apache License 2.0 6 votes vote down vote up
@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 9
Source Project: atlas   Source File: InjectTransformManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 10
Source Project: javaide   Source File: Dex.java    License: GNU General Public License v3.0 6 votes vote down vote up
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 11
Source Project: javaide   Source File: LibraryCache.java    License: GNU General Public License v3.0 6 votes vote down vote up
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 Project: javaide   Source File: Packager.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 Project: NBANDROID-V2   Source File: AvdManager.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: NBANDROID-V2   Source File: ProjectTemplateLoader.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: EasyRouter   Source File: CollectHandler.java    License: Apache License 2.0 6 votes vote down vote up
@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 16
private File getGeneratedResourcesDirectory(String name) {
    return FileUtils.join(
            getGeneratedDirectory(),
            StringHelper.toStrings(
                    "res",
                    name,
                    Collections.singletonList("android")));
}
 
Example 17
Source Project: atlas   Source File: AtlasDexArchiveBuilderTransform.java    License: Apache License 2.0 5 votes vote down vote up
@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 18
Source Project: atlas   Source File: AtlasMainDexMerger.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void merge(TransformInvocation transformInvocation) {

    if (dexMerger == DexMergerTool.D8) {
        logger.info("D8 is used to merge dex.");
    }

    TransformOutputProvider outputProvider = transformInvocation.getOutputProvider();
    Collection<TransformInput> transformInputs = transformInvocation.getInputs();

    List<File> mainDexFiles = new ArrayList<>();

    final File[][] mergeDexs = {new File[0]};

    File outputDir =
            getDexOutputLocation(outputProvider, "main", TransformManager.SCOPE_FULL_PROJECT);
    // this deletes and creates the dir for the output
    try {
        FileUtils.cleanOutputDir(outputDir);
    } catch (IOException e) {
        e.printStackTrace();
    }

    variantOutputContext.setDexMergeFolder(outputDir);

    transformInputs.forEach((TransformInput transformInput) -> {
        File file = (File) ReflectUtils.getField(transformInput, "optionalRootLocation");
        if (file != null && file.exists()) {
            mainDexFiles.addAll(org.apache.commons.io.FileUtils.listFiles(file, new String[]{"jar", "dex"}, true));
            mergeDexs[0] = file.listFiles(pathname -> pathname.getName().endsWith(".jar") || pathname.isDirectory());
        }
    });


    merge(mainDexFiles,outputDir,mergeDexs);

}
 
Example 19
Source Project: atlas   Source File: AwbDexsMerger.java    License: Apache License 2.0 5 votes vote down vote up
public AwbDexsMerger(DexingType dexingType, FileCollection mainDexListFile, ErrorReporter errorReporter, DexMergerTool dexMerger, int minSdkVersion, boolean isDebuggable, AppVariantOutputContext appVariantOutputContext) {
    super(dexingType, mainDexListFile, errorReporter, dexMerger, minSdkVersion, isDebuggable, appVariantOutputContext);
        cacheHandler = new CacheHandler() {
        @Override
        public void handleMissActionResult(File outputDir, File in) throws IOException {
            File[] dexs = outputDir.listFiles((dir, name) -> name.endsWith(".dex"));
            if (dexs != null && dexs.length > 1) {
                for (File file : dexs) {
                    org.apache.commons.io.FileUtils.copyFileToDirectory(file, in.getParentFile());
                }

            } else if (dexs.length == 1) {

                Files.copy(dexs[0].toPath(), in.toPath());
            } else {
                throw new IOException("no dex file merge out");
            }
        }

        @Override
        public void handleQueryResult(FileCache.QueryResult result, File outDir, String bundleName) throws IOException {

            if (result.getQueryEvent().equals(FileCache.QueryEvent.HIT)) {
                logger.info("hit dexmerge cache " + bundleName + "->" + result.getCachedFile().getAbsolutePath());
                if (result.getCachedFile().exists()) {
                    org.apache.commons.io.FileUtils.copyFile(result.getCachedFile(), new File(outDir, CLASSES_DEX));
                }
            } else {
                logger.info("miss dexmerge cache " + bundleName + "-> null");

            }
        }
    };
}
 
Example 20
Source Project: atlas   Source File: AwbDexsMerger.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void merge(TransformInvocation transformInvocation) {

    mainDexOut = getDexOutputLocation(transformInvocation.getOutputProvider(),"main", TransformManager.SCOPE_FULL_PROJECT);
    if (!mainDexOut.exists() || !mainDexOut.isDirectory()){
        return;
    }
    atomicInteger.set(org.apache.commons.io.FileUtils.listFiles(mainDexOut,new String[]{"dex"},true).size());
    for (AwbTransform awbTransform : variantOutputContext.getAwbTransformMap().values()) {
       merge(awbTransform.getAwbBundle());
    }

}
 
Example 21
Source Project: atlas   Source File: AtlasMergeJavaResourcesTransform.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Save the incremental merge state.
 *
 * @param state the state
 * @throws IOException failed to save the state
 */
private void saveMergeState(@NonNull IncrementalFileMergerState state) throws IOException {
    File incrementalFile = incrementalStateFile();

    FileUtils.mkdirs(incrementalFile.getParentFile());
    try (ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(incrementalFile))) {
        o.writeObject(state);
    }
}
 
Example 22
Source Project: atlas   Source File: AtlasMergeJavaResourcesTransform.java    License: Apache License 2.0 5 votes vote down vote up
private void saveAwbMergeState(@NonNull IncrementalFileMergerState state, AwbBundle awbBundle) throws IOException {
    File incrementalFile = incrementalAwbStateFile(awbBundle);

    FileUtils.mkdirs(incrementalFile.getParentFile());
    try (ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(incrementalFile))) {
        o.writeObject(state);
    }
}
 
Example 23
Source Project: atlas   Source File: AwbDataBindingMergeArtifactsTask.java    License: Apache License 2.0 5 votes vote down vote up
private void extractBinFilesFromJar(File outFolder, File jarFile) throws IOException {
    File jarOutFolder = getOutFolderForJarFile(outFolder, jarFile);
    if (jarOutFolder.exists()) {
        FileUtils.deleteDirectoryContents(jarOutFolder);
    }else {
        FileUtils.mkdirs(jarOutFolder);
    }

    try (Closer localCloser = Closer.create()) {
        FileInputStream fis = localCloser.register(new FileInputStream(jarFile));
        ZipInputStream zis = localCloser.register(new ZipInputStream(fis));
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                continue;
            }

            String name = entry.getName();

            if (!isResource(name)) {
                continue;
            }
            // get rid of the path. We don't need it since the file name includes the domain
            name = new File(name).getName();
            File out = new File(jarOutFolder, name);
            //noinspection ResultOfMethodCallIgnored
            FileOutputStream fos = localCloser.register(new FileOutputStream(out));
            ByteStreams.copy(zis, fos);
            zis.closeEntry();
        }
    }
}
 
Example 24
Source Project: atlas   Source File: MergeAwbAssets.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    protected void doFullTaskAction() throws IOException {
        if (awbBundle.isMBundle){
            return;
        }
        // this is full run, clean the previous output
        File destinationDir = getOutputDir();
        FileUtils.cleanOutputDir(destinationDir);

        List<AssetSet> assetSets = computeAssetSetList();

        // create a new merger and populate it with the sets.
        AssetMerger merger = new AssetMerger();

        try {
            for (AssetSet assetSet : assetSets) {
                // set needs to be loaded.
                assetSet.loadFromFiles(getILogger());
                merger.addDataSet(assetSet);
            }

            // get the merged set and write it down.
            MergedAssetWriter writer = new MergedAssetWriter(destinationDir, workerExecutor);

            merger.mergeData(writer, false /*doCleanUp*/);

            // No exception? Write the known state.
            merger.writeBlobTo(getIncrementalFolder(), writer, false);
        } catch (MergingException e) {
            getLogger().error("Could not merge source set folders: ", e);
            merger.cleanBlob(getIncrementalFolder());
            throw new ResourceException(e.getMessage(), e);
        }
//        if (awbBundle.mBundle){
//            org.apache.commons.io.FileUtils.moveDirectoryToDirectory(destinationDir,variantContext.getVariantData().mergeAssetsTask.getOutputDir(),true);
//        }
    }
 
Example 25
Source Project: atlas   Source File: AtlasBundleInstantApp.java    License: Apache License 2.0 5 votes vote down vote up
@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 26
Source Project: atlas   Source File: DirDexArchiveHook.java    License: Apache License 2.0 5 votes vote down vote up
@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 27
Source Project: atlas   Source File: JarMergerWithOverride.java    License: Apache License 2.0 5 votes vote down vote up
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 28
Source Project: atlas   Source File: VariantContext.java    License: Apache License 2.0 5 votes vote down vote up
public File getAwbResourceBlameLogDir(AwbBundle awbBundle) {
    return FileUtils.join(
            scope.getGlobalScope().getIntermediatesDir(),
            StringHelper.toStrings(
                    "awb-blame", "res", scope.getDirectorySegments(),awbBundle.getName()));

}
 
Example 29
Source Project: atlas   Source File: VariantContext.java    License: Apache License 2.0 5 votes vote down vote up
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 30
Source Project: atlas   Source File: AppVariantContext.java    License: Apache License 2.0 5 votes vote down vote up
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;
}