com.android.build.api.transform.Format Java Examples

The following examples show how to use com.android.build.api.transform.Format. 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: AtlasDexMerger.java    From atlas with Apache License 2.0 5 votes vote down vote up
@NonNull
protected File getDexOutputLocation(
        @NonNull TransformOutputProvider outputProvider,
        @NonNull String name,
        @NonNull Set<? super QualifiedContent.Scope> scopes) {
    return outputProvider.getContentLocation(name, TransformManager.CONTENT_DEX, scopes, Format.DIRECTORY);
}
 
Example #2
Source File: MtlInjectTransform.java    From atlas with Apache License 2.0 5 votes vote down vote up
protected File getOutputFile(TransformOutputProvider outputProvider, JarInput jarInput) {

        if (null != logger) {
            logger.debug("[ClassInject]" + jarInput.getFile().getAbsolutePath());
        }

        return outputProvider.getContentLocation(getUniqueJarName(jarInput),
                                                 jarInput.getContentTypes(),
                                                 jarInput.getScopes(),
                                                 Format.JAR);

    }
 
Example #3
Source File: ProGuardPercentPrinter.java    From atlas with Apache License 2.0 5 votes vote down vote up
@NonNull
private static Path getOutputPath(@NonNull TransformOutputProvider outputProvider,
        @NonNull QualifiedContent content) {
    return outputProvider.getContentLocation(content.getName(),
            content.getContentTypes(),
            content.getScopes(),
            content instanceof DirectoryInput ? Format.DIRECTORY : Format.JAR).toPath();
}
 
Example #4
Source File: AbstractTransform.java    From SocialSdkLibrary with Apache License 2.0 4 votes vote down vote up
private void onEachJar(JarInput input, TransformOutputProvider provider) {
    File file = input.getFile();
    if (!file.getAbsolutePath().endsWith("jar")) {
        return;
    }
    String jarName = input.getName();
    String md5Name = DigestUtils.md5Hex(file.getAbsolutePath());
    if (jarName.endsWith(".jar")) {
        jarName = jarName.substring(0, jarName.length() - 4);
    }
    try {
        JarFile jarFile = new JarFile(file);
        Enumeration<JarEntry> entries = jarFile.entries();
        File tmpFile = new File(file.getParent() + File.separator + "classes_temp.jar");
        //避免上次的缓存被重复插入
        if (tmpFile.exists()) {
            tmpFile.delete();
        }
        JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(tmpFile));
        //用于保存
        while (entries.hasMoreElements()) {
            JarEntry jarEntry = entries.nextElement();
            String entryName = jarEntry.getName();
            ZipEntry zipEntry = new ZipEntry(entryName);
            InputStream inputStream = jarFile.getInputStream(jarEntry);
            // 插桩class
            byte[] bytes = IOUtils.toByteArray(inputStream);
            if (isAttentionFile(entryName)) {
                // class文件处理
                jarOutputStream.putNextEntry(zipEntry);
                byte[] code = TransformX.visitClass(bytes, onEachClassFile(entryName));
                jarOutputStream.write(code);
            } else {
                jarOutputStream.putNextEntry(zipEntry);
                jarOutputStream.write(bytes);
            }
            jarOutputStream.closeEntry();
        }
        // 结束
        jarOutputStream.close();
        jarFile.close();
        File dest = provider.getContentLocation(jarName + md5Name,
                input.getContentTypes(), input.getScopes(), Format.JAR);
        FileUtils.copyFile(tmpFile, dest);
        tmpFile.delete();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example #5
Source File: TransformContext.java    From EasyRouter with Apache License 2.0 4 votes vote down vote up
public File getRelativeFile(QualifiedContent content) {
    return invocation.getOutputProvider().getContentLocation(content.getName(), content.getContentTypes(), content.getScopes(),
            (content instanceof JarInput ? Format.JAR : Format.DIRECTORY));
}