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

The following examples show how to use com.android.build.api.transform.TransformInvocation. 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: DataLoaderTransform.java    From DataLoader with Apache License 2.0 6 votes vote down vote up
private void process(TransformInvocation transformInvocation) throws IOException {
    List<LoaderInfo> loaderInfoList = new ArrayList<>();
    for (TransformInput input : transformInvocation.getInputs()) {
        for (JarInput jarInput : input.getJarInputs()) {
            File file = jarInput.getFile();
            JarFile jarFile = new JarFile(file);
            Enumeration<JarEntry> entries = jarFile.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                if (isLoaderInfoEntry(entry)) {
                    System.out.println(TAG + "entry name: " + entry.getName());
                    String content = GradleUtils.getContent(jarFile, entry);
                    System.out.println(TAG + "content: " + content);
                    Type type = new TypeToken<List<LoaderInfo>>() {
                    }.getType();
                    List<LoaderInfo> loaderInfos = gson.fromJson(content, type);
                    if (loaderInfos != null) {
                        loaderInfoList.addAll(loaderInfos);
                    }
                }
            }
        }
    }
    String json = gson.toJson(loaderInfoList);
    generateInitClass(transformInvocation, json);
}
 
Example #2
Source File: DataLoaderTransform.java    From DataLoader with Apache License 2.0 6 votes vote down vote up
private void testModifyClass(TransformInvocation transformInvocation) {
    try {
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
        cw.visit(Opcodes.V1_7, Opcodes.ACC_PUBLIC,
                "com.jeremyliao.dataloader.core.utils.GenericsUtils".replace('.', '/'),
                null, "java/lang/Object", null);
        {
            MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC,
                    Const.INIT_METHOD, "()Ljava/lang/String;", null, null);
            mv.visitCode();
            mv.visitInsn(Opcodes.ARETURN);
            mv.visitMaxs(1, 0);
            mv.visitEnd();
        }
        cw.visitEnd();
        System.out.println(TAG + "code");
        System.out.println(TAG + "code: " + new String(cw.toByteArray()));
    } catch (Exception e) {

    }
}
 
Example #3
Source File: AtlasTransformUtils.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static Collection<File> getTransformInputs(AppVariantContext appVariantContext,
        TransformInvocation invocation) {
    ImmutableSet.Builder<File> builder = ImmutableSet.builder();
    Collection<File> transformInputs = TransformInputUtil.getAllFiles(invocation.getInputs());
    builder.addAll(transformInputs);
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(
            appVariantContext.getVariantConfiguration().getFullName());

    if (atlasDependencyTree.getAwbBundles().size() > 0) {

        BaseVariantOutput vod =
                (BaseVariantOutput) appVariantContext.getVariantOutputData().iterator().next();
        AppVariantOutputContext appVariantOutputContext =
                appVariantContext.getAppVariantOutputContext(ApkDataUtils.get(vod));
        Collection<AwbTransform> awbTransforms =
                appVariantOutputContext.getAwbTransformMap().values();
        awbTransforms.forEach(awbTransform -> {
            builder.addAll(awbTransform.getInputLibraries());
        });
    }
    return builder.build();
}
 
Example #4
Source File: AtlasIntermediateStreamHelper.java    From atlas with Apache License 2.0 6 votes vote down vote up
public void replaceProvider(TransformInvocation transformInvocation){
    try {
        Field field = intermediateStream.getClass().getDeclaredField("folderUtils");
        field.setAccessible(true);
        IntermediateFolderUtils intermediateFolderUtils = (IntermediateFolderUtils) field.get(intermediateStream);
        Set<QualifiedContent.ContentType> types = (Set<QualifiedContent.ContentType>) ReflectUtils.getField(intermediateFolderUtils,"types");
        Set<? super QualifiedContent.Scope> scopes = (Set<? super QualifiedContent.Scope>) ReflectUtils.getField(intermediateFolderUtils,"scopes");
        AtlasIntermediateFolderUtils atlasIntermediateFolderUtils = new AtlasIntermediateFolderUtils(intermediateFolderUtils.getRootFolder(),types,scopes);
        field.set(intermediateStream,atlasIntermediateFolderUtils);
        TransformOutputProvider transformOutputProvider = transformInvocation.getOutputProvider();
        ReflectUtils.updateField(transformOutputProvider,"folderUtils",atlasIntermediateFolderUtils);

    }catch (Exception e){

    }


}
 
Example #5
Source File: AbstractTransform.java    From SocialSdkLibrary with Apache License 2.0 6 votes vote down vote up
@Override
public void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
    super.transform(transformInvocation);
    UtilX.log("start transform");
    long startTime = System.currentTimeMillis();
    // 获取输入
    Collection<TransformInput> inputs = transformInvocation.getInputs();
    final TransformOutputProvider outputProvider = transformInvocation.getOutputProvider();
    // 删除之前的输出
    if (outputProvider != null) {
        outputProvider.deleteAll();
    }
    for (TransformInput transformInput : inputs) {
        for (DirectoryInput directoryInput : transformInput.getDirectoryInputs()) {
            onEachDirectory(directoryInput, outputProvider);
        }
        for (JarInput jarInput : transformInput.getJarInputs()) {
            onEachJar(jarInput, outputProvider);
        }
    }
    long endTime = System.currentTimeMillis();
    UtilX.log("end transform cost time " + (endTime - startTime) / 1000 + " s");
}
 
Example #6
Source File: AtlasDexMerger.java    From atlas with Apache License 2.0 5 votes vote down vote up
public void mergeAll(TransformInvocation transformInvocation) throws IOException {
    ProcessOutput output = outputHandler.createOutput();
    for (File file:allDexsArchives){
        logger.warning("mergeAll File:"+file.getAbsolutePath());
    }
    TransformOutputProvider outputProvider = transformInvocation.getOutputProvider();
    File outputDir =
            getDexOutputLocation(outputProvider, "main", TransformManager.SCOPE_FULL_PROJECT);

    File finalDexDir = new File(outputDir.getParentFile(),"temp");
    finalDexDir.mkdirs();
    List<ForkJoinTask<Void>> mergeTasks = new ArrayList();
    if (dexingType == DexingType.NATIVE_MULTIDEX) {
        mergeTasks.addAll(
                handleNativeMultiDex(
                        allDexsArchives,
                        output,
                        finalDexDir,
                         null));
    } else {
        mergeTasks.addAll(
                handleLegacyAndMonoDex(
                        allDexsArchives, output, finalDexDir, mainDexListFile == null ? null : mainDexListFile.getSingleFile()));
    }

    mergeTasks.forEach(voidForkJoinTask -> voidForkJoinTask.join());

    FileUtils.deleteDirectory(outputDir);
    FileUtils.moveDirectory(finalDexDir,outputDir);

}
 
Example #7
Source File: AwbDexsMerger.java    From atlas with 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 #8
Source File: ProGuardPercentPrinter.java    From atlas with Apache License 2.0 5 votes vote down vote up
public ProGuardPercentPrinter(AppVariantContext appVariantContext,
        TransformInvocation invocation) {
    this.appVariantContext = appVariantContext;
    this.invocation = invocation;
    transformInputs =
            AtlasTransformUtils.getTransformInputs(this.appVariantContext, invocation);
    fileLibraryMap = buildFileLibraryMap();

    injarsOutjarsMap = buildgetInjarsOutjarsMap();
}
 
Example #9
Source File: ApplicationTransform.java    From EasyRouter with Apache License 2.0 5 votes vote down vote up
@Override
public void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
    TransformContext context = new TransformContext(transformInvocation);

    CollectEngine collectEngine = new CollectEngine(context);
    MergeInfo mergeInfo = collectEngine.startCollect();

    Log.i("merinfo size: " + mergeInfo.toString());
    MergeEngine mergeEngine = new MergeEngine(context);
    mergeEngine.startMerge(mergeInfo);
}
 
Example #10
Source File: DataLoaderTransform.java    From DataLoader with Apache License 2.0 4 votes vote down vote up
@Override
public void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
    super.transform(transformInvocation);
    process(transformInvocation);
    copyInputToOutput(transformInvocation);
}
 
Example #11
Source File: ModifyUtils.java    From DataLoader with Apache License 2.0 4 votes vote down vote up
public static File replaceInJar(TransformInvocation transformInvocation, File file) throws IOException {
    if (isNeedModify(file)) {
        return modifyJar(file, transformInvocation.getContext().getTemporaryDir());
    }
    return null;
}
 
Example #12
Source File: TaobaoInstantRunDependenciesApkBuilder.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
public void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
    super.transform(transformInvocation);
}
 
Example #13
Source File: TaobaoInstantRunSlicer.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
public void transform(TransformInvocation transformInvocation) throws IOException, TransformException, InterruptedException {
    super.transform(transformInvocation);
}
 
Example #14
Source File: LibraryTransform.java    From EasyRouter with Apache License 2.0 4 votes vote down vote up
@Override
public void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
    TransformContext context = new TransformContext(transformInvocation);
    RenameEngine engine = new RenameEngine(context);
    engine.stratRename(project);
}
 
Example #15
Source File: TransformContext.java    From EasyRouter with Apache License 2.0 4 votes vote down vote up
public TransformContext(TransformInvocation invocation) {
    this.invocation = invocation;
    init();
}
 
Example #16
Source File: AtlasDexMerger.java    From atlas with Apache License 2.0 votes vote down vote up
public abstract void merge(TransformInvocation transformInvocation);