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

The following examples show how to use com.android.build.api.transform.QualifiedContent. 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 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 #2
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 #3
Source File: InjectTransformManager.java    From atlas with Apache License 2.0 6 votes vote down vote up
@NonNull
private static String getTaskNamePrefix(@NonNull Transform transform) {
    StringBuilder sb = new StringBuilder(100);
    sb.append("transform");

    Iterator<QualifiedContent.ContentType> iterator = transform.getInputTypes().iterator();
    // there's always at least one
    sb.append(capitalize(iterator.next().name().toLowerCase(Locale.getDefault())));
    while (iterator.hasNext()) {
        sb.append("And")
                .append(capitalize(iterator.next().name().toLowerCase(Locale.getDefault())));
    }

    sb.append("With").append(capitalize(transform.getName())).append("For");

    return sb.toString();
}
 
Example #4
Source File: TransformReplacer.java    From atlas with Apache License 2.0 6 votes vote down vote up
public void replaceMergeJavaResourcesTransform(AppVariantContext appVariantContext, BaseVariantOutput vod) {
    List<TransformTask> baseTransforms = TransformManager.findTransformTaskByTransformType(
            variantContext, MergeJavaResourcesTransform.class);
    for (TransformTask transformTask : baseTransforms) {
        MergeJavaResourcesTransform transform = (MergeJavaResourcesTransform) transformTask.getTransform();
        PackagingOptions packagingOptions = (PackagingOptions) ReflectUtils.getField(transform, "packagingOptions");
        packagingOptions.exclude("**.aidl");
        packagingOptions.exclude("**.cfg");
        Set<? super QualifiedContent.Scope> mergeScopes = (Set<? super QualifiedContent.Scope>) ReflectUtils.getField(transform, "mergeScopes");
        Set<QualifiedContent.ContentType> mergedType = (Set<QualifiedContent.ContentType>) ReflectUtils.getField(transform, "mergedType");
        String name = (String) ReflectUtils.getField(transform, "name");
        AtlasMergeJavaResourcesTransform atlasMergeJavaResourcesTransform = new AtlasMergeJavaResourcesTransform(appVariantContext.getAppVariantOutputContext(ApkDataUtils.get(vod)), packagingOptions, mergeScopes, mergedType.iterator().next(), name, appVariantContext.getScope());
        ReflectUtils.updateField(transformTask, "transform",
                atlasMergeJavaResourcesTransform);
    }

}
 
Example #5
Source File: DirectoryContentProvider.java    From EasyRouter with Apache License 2.0 6 votes vote down vote up
@Override
public void forEach(QualifiedContent content, ClassHandler processor) throws IOException {
    if (processor.onStart(content)) {
        Log.i("start trans dir "+content.getName());

        File root = content.getFile();
        URI base = root.toURI();
        for (File f : Files.fileTreeTraverser().preOrderTraversal(root)) {
            if (f.isFile()) {
                byte[] data = Files.toByteArray(f);
                String relativePath = base.relativize(f.toURI()).toString();
                processor.onClassFetch(content, Status.ADDED, relativePath, data);
            }
        }
    }
    processor.onComplete(content);
}
 
Example #6
Source File: DesugarTask.java    From javafxmobile-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void processSingle(
        @NonNull Path input, @NonNull Path output, @NonNull Set<? super QualifiedContent.Scope> scopes)
        throws Exception {
    waitableExecutor.execute(
            () -> {
                if (output.toString().endsWith(SdkConstants.DOT_JAR)) {
                    Files.createDirectories(output.getParent());
                } else {
                    Files.createDirectories(output);
                }

                FileCache cacheToUse;
                if (Files.isRegularFile(input)
                        && Objects.equals(
                        scopes, Collections.singleton(QualifiedContent.Scope.EXTERNAL_LIBRARIES))) {
                    cacheToUse = userCache;
                } else {
                    cacheToUse = null;
                }

                processUsingCache(input, output, cacheToUse);
                return null;
            });
}
 
Example #7
Source File: RenameHandler.java    From EasyRouter with Apache License 2.0 6 votes vote down vote up
@Override
public void onClassFetch(QualifiedContent content, Status status, String relativePath, byte[] bytes) throws IOException {
    File outputFile = context.getRelativeFile(content);
    byte[] finalBytes = bytes;
    if (relativePath.endsWith(".class") && relativePath.contains("com/zane/easyrouter_generated")) {
        ClassReader classReader = new ClassReader(finalBytes);
        ClassWriter classWriter = new ClassWriter(0);
        RenameClassVisistor classVisistor = new RenameClassVisistor(classWriter);
        classReader.accept(classVisistor, 0);

        if (classVisistor.isFindTarget()) {
            relativePath = classVisistor.getFinalName() + ".class";
            finalBytes = classWriter.toByteArray();
        }
    }

    directoryWriter.write(outputFile, relativePath, finalBytes);
}
 
Example #8
Source File: InlineRTransform.java    From shrinker with Apache License 2.0 5 votes vote down vote up
@Override
public Set<? super QualifiedContent.Scope> getScopes() {
    if (!config.inlineR) // empty scope
        return ImmutableSet.of();
    // full
    return Sets.immutableEnumSet(
            QualifiedContent.Scope.PROJECT,
            QualifiedContent.Scope.SUB_PROJECTS,
            QualifiedContent.Scope.EXTERNAL_LIBRARIES);
}
 
Example #9
Source File: InlineRProcessor.java    From shrinker with Apache License 2.0 5 votes vote down vote up
InlineRProcessor(Collection<TransformInput> inputs,
                 Function<byte[], byte[]> transform,
                 Function<QualifiedContent, Path> getTargetPath) {
    this.inputs = inputs;
    this.getTargetPath = getTargetPath;
    this.transform = transform;
}
 
Example #10
Source File: InlineRProcessor.java    From shrinker with Apache License 2.0 5 votes vote down vote up
private static <T extends QualifiedContent> Stream<T> streamOf(
        Collection<TransformInput> inputs,
        Function<TransformInput, Collection<T>> mapping) {
    Collection<T> list = inputs.stream()
            .map(mapping)
            .flatMap(Collection::stream)
            .collect(Collectors.toList());
    if (list.size() >= Runtime.getRuntime().availableProcessors())
        return list.parallelStream();
    else
        return list.stream();
}
 
Example #11
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 #12
Source File: AtlasDexArchiveBuilderCacheHander.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Returns if the qualified content is an external jar.
 */
private static boolean isExternalLib(@NonNull QualifiedContent content) {
    return content.getFile().isFile()
            && content.getScopes()
            .equals(Collections.singleton(QualifiedContent.Scope.EXTERNAL_LIBRARIES))
            && content.getContentTypes()
            .equals(Collections.singleton(QualifiedContent.DefaultContentType.CLASSES))
            && !content.getName().startsWith(OriginalStream.LOCAL_JAR_GROUPID);
}
 
Example #13
Source File: AtlasDexArchiveBuilderCacheHander.java    From atlas with Apache License 2.0 5 votes vote down vote up
void populateCache(Multimap<QualifiedContent, File> cacheableItems)
        throws Exception {

    for (QualifiedContent input : cacheableItems.keys()) {
        FileCache cache =
                getBuildCache(
                        input.getFile(), isExternalLib(input), userLevelCache);
        if (cache != null) {
            FileCache.Inputs buildCacheInputs =
                    AtlasDexArchiveBuilderCacheHander.getBuildCacheInputs(
                            input.getFile(), dexOptions, dexer, minSdkVersion, isDebuggable);
            FileCache.QueryResult result =
                    cache.createFileInCacheIfAbsent(
                            buildCacheInputs,
                            in -> {
                                Collection<File> dexArchives = cacheableItems.get(input);
                                logger.verbose(
                                        "Merging %1$s into %2$s",
                                        Joiner.on(',').join(dexArchives), in.getAbsolutePath());
                                mergeJars(in, cacheableItems.get(input));
                            });
            if (result.getQueryEvent().equals(FileCache.QueryEvent.CORRUPTED)) {
                Verify.verifyNotNull(result.getCauseOfCorruption());
                logger.info(
                        "The build cache at '%1$s' contained an invalid cache entry.\n"
                                + "Cause: %2$s\n"
                                + "We have recreated the cache entry.\n"
                                + "%3$s",
                        cache.getCacheDirectory().getAbsolutePath(),
                        Throwables.getStackTraceAsString(result.getCauseOfCorruption()),
                        BuildCacheUtils.BUILD_CACHE_TROUBLESHOOTING_MESSAGE);
            }
        }
    }
}
 
Example #14
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 #15
Source File: TransformInputUtils.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static DirectoryInput makeDirectoryInput(File file, AppVariantContext variantContext) {
    return new DirectoryInput() {
        @Override
        public Map<File, Status> getChangedFiles() {
            return ImmutableMap.of(file, Status.CHANGED);
        }

        @Override
        public String getName() {
            return "folder";
        }

        @Override
        public File getFile() {
            return file;
        }

        @Override
        public Set<QualifiedContent.ContentType> getContentTypes() {
            return ImmutableSet.of(QualifiedContent.DefaultContentType.CLASSES);
        }

        @Override
        public Set<? super QualifiedContent.Scope> getScopes() {
            return ImmutableSet.of(Scope.EXTERNAL_LIBRARIES);
        }
    };

}
 
Example #16
Source File: TransformInputUtils.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static JarInput makeJarInput(File file,AppVariantContext variantContext) {
    BuildAtlasEnvTask.FileIdentity finalFileIdentity = AtlasBuildContext.atlasMainDexHelperMap.get(variantContext.getVariantName()).get(file);
    return new JarInput() {
        @Override
        public Status getStatus() {
            return Status.ADDED;
        }

        @Override
        public String getName() {

            return MD5Util.getFileMD5(file);
        }

        @Override
        public File getFile() {
            return file;
        }

        @Override
        public Set<QualifiedContent.ContentType> getContentTypes() {
            return ImmutableSet.of(QualifiedContent.DefaultContentType.CLASSES);
        }

        @Override
        public Set<? super QualifiedContent.Scope> getScopes() {
            if (finalFileIdentity == null){
                return  ImmutableSet.of(Scope.EXTERNAL_LIBRARIES);
            }
            if (finalFileIdentity.subProject) {
                return ImmutableSet.of(Scope.SUB_PROJECTS);
            } else {
                return ImmutableSet.of(Scope.EXTERNAL_LIBRARIES);
            }
        }
    };
}
 
Example #17
Source File: MergeHandler.java    From EasyRouter with Apache License 2.0 5 votes vote down vote up
@Override
public void onClassFetch(QualifiedContent content, Status status, String relativePath, byte[] bytes) throws IOException {
    File outputFile = context.getRelativeFile(content);
    byte[] finalBytes = bytes;
    if (relativePath.endsWith(".class") && relativePath.contains("com/zane/easyrouter_generated")) {
        ClassReader classReader = new ClassReader(finalBytes);
        ClassWriter classWriter = new ClassWriter(0);
        MergeClassVisitor mergeClassVisitor = new MergeClassVisitor(classWriter, mergeInfo);
        classReader.accept(mergeClassVisitor, 0);
        finalBytes = classWriter.toByteArray();
    }

    directoryWriter.write(outputFile, relativePath, finalBytes);
}
 
Example #18
Source File: ApplicationTransform.java    From EasyRouter with Apache License 2.0 4 votes vote down vote up
@Override
public Set<QualifiedContent.ContentType> getInputTypes() {
    return TransformManager.CONTENT_CLASS;
}
 
Example #19
Source File: ApplicationTransform.java    From EasyRouter with Apache License 2.0 4 votes vote down vote up
@Override
public Set<? super QualifiedContent.Scope> getScopes() {
    return TransformManager.SCOPE_FULL_PROJECT;
}
 
Example #20
Source File: RenameHandler.java    From EasyRouter with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onStart(QualifiedContent content) throws IOException {
    return true;
}
 
Example #21
Source File: JarContentProvider.java    From EasyRouter with Apache License 2.0 4 votes vote down vote up
@Override
public void forEach(QualifiedContent content, ClassHandler processor) throws IOException {
    forActualInput((JarInput) content, processor);
}
 
Example #22
Source File: MergeHandler.java    From EasyRouter with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onStart(QualifiedContent content) throws IOException {
    return true;
}
 
Example #23
Source File: MergeHandler.java    From EasyRouter with Apache License 2.0 4 votes vote down vote up
@Override
public void onComplete(QualifiedContent content) throws IOException {
}
 
Example #24
Source File: AbstractTransform.java    From SocialSdkLibrary with Apache License 2.0 4 votes vote down vote up
@Override
public Set<? super QualifiedContent.Scope> getScopes() {
    return TransformManager.SCOPE_FULL_PROJECT;
}
 
Example #25
Source File: JarContentProvider.java    From EasyRouter with Apache License 2.0 4 votes vote down vote up
@Override
public boolean accepted(QualifiedContent qualifiedContent) {
    return qualifiedContent instanceof JarInput;
}
 
Example #26
Source File: DirectoryContentProvider.java    From EasyRouter with Apache License 2.0 4 votes vote down vote up
@Override
public boolean accepted(QualifiedContent qualifiedContent) {
    return qualifiedContent instanceof DirectoryInput;
}
 
Example #27
Source File: ContextReader.java    From EasyRouter with Apache License 2.0 4 votes vote down vote up
QualifiedContentTask(QualifiedContent content, ClassHandler fetcher) {
    this.content = content;
    this.fetcher = fetcher;
}
 
Example #28
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));
}
 
Example #29
Source File: AtlasMainDexHelper.java    From atlas with Apache License 2.0 4 votes vote down vote up
public void addMainDexAchives(Map<QualifiedContent, List<File>> cacheableItems) {
    this.mainDexAchives.putAll(cacheableItems);
}
 
Example #30
Source File: DataLoaderTransform.java    From DataLoader with Apache License 2.0 4 votes vote down vote up
@Override
public Set<? super QualifiedContent.Scope> getScopes() {
    return TransformManager.SCOPE_FULL_PROJECT;
}