com.android.build.api.transform.TransformOutputProvider Java Examples
The following examples show how to use
com.android.build.api.transform.TransformOutputProvider.
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: AtlasIntermediateStreamHelper.java From atlas with Apache License 2.0 | 6 votes |
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 #2
Source File: AbstractTransform.java From SocialSdkLibrary with Apache License 2.0 | 6 votes |
@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 #3
Source File: AtlasDexMerger.java From atlas with Apache License 2.0 | 5 votes |
@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 #4
Source File: AtlasDexMerger.java From atlas with Apache License 2.0 | 5 votes |
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 #5
Source File: MtlInjectTransform.java From atlas with Apache License 2.0 | 5 votes |
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 #6
Source File: ProGuardPercentPrinter.java From atlas with Apache License 2.0 | 5 votes |
@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 #7
Source File: AbstractTransform.java From SocialSdkLibrary with Apache License 2.0 | 4 votes |
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(); } }