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

The following examples show how to use com.android.build.api.transform.TransformInput. 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: 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 #3
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 #4
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();
}