Search in sources :

Example 1 with AndroidBuilder

use of com.android.builder.core.AndroidBuilder in project atlas by alibaba.

the class AtlasConfigurationHelper method createBuilderAfterEvaluate.

public void createBuilderAfterEvaluate() throws Exception {
    AndroidBuilder androidBuilder = appPluginHook.getAndroidBuilder();
    if (null == androidBuilder) {
        return;
    }
    AndroidBuilder atlasBuilder = new AtlasBuilder(project.equals(project.getRootProject()) ? project.getName() : project.getPath(), creator, new GradleProcessExecutor(project), new GradleJavaProcessExecutor(project), DefaultGroovyMethods.asType(ReflectUtils.getField(androidBuilder, "mErrorReporter"), ErrorReporter.class), LoggerWrapper.getLogger(AtlasBuilder.class), DefaultGroovyMethods.asType(ReflectUtils.getField(androidBuilder, "mVerboseExec"), Boolean.class));
    ((AtlasBuilder) atlasBuilder).setDefaultBuilder(androidBuilder);
    ((AtlasBuilder) atlasBuilder).setAtlasExtension(atlasExtension);
    AtlasBuildContext.androidBuilderMap.put(project, (AtlasBuilder) (atlasBuilder));
}
Also used : ErrorReporter(com.android.builder.core.ErrorReporter) GradleProcessExecutor(com.android.build.gradle.internal.process.GradleProcessExecutor) AndroidBuilder(com.android.builder.core.AndroidBuilder) AtlasBuilder(com.android.builder.core.AtlasBuilder) GradleJavaProcessExecutor(com.android.build.gradle.internal.process.GradleJavaProcessExecutor)

Example 2 with AndroidBuilder

use of com.android.builder.core.AndroidBuilder in project atlas by alibaba.

the class AppPluginHook method getAndroidBuilder.

// public void replaceTaskManager() throws Exception {
// 
// AppPlugin appPlugin = project.getPlugins().findPlugin(AppPlugin.class);
// 
// if (null == appPlugin) {
// return;
// }
// 
// TaskManager taskManager =
// (TaskManager)ReflectUtils.getField(BasePlugin.class, appPlugin, "taskManager");
// 
// DependencyManager dependencyManager = (DependencyManager)ReflectUtils.getField(TaskManager.class, taskManager,
// "dependencyManager");
// 
// AtlasDependencyManager atlasDependencyManager = new AtlasDependencyManager(project,
// (ExtraModelInfo)ReflectUtils
// .getField(dependencyManager,
// "extraModelInfo"),
// (SdkHandler)ReflectUtils
// .getField(dependencyManager,
// "sdkHandler"));
// 
// ReflectUtils.updateField(TaskManager.class, taskManager, "dependencyManager", atlasDependencyManager);
// 
// }
public AndroidBuilder getAndroidBuilder() throws Exception {
    BasePlugin basePlugin = project.getPlugins().findPlugin(AppPlugin.class);
    if (null == basePlugin) {
        basePlugin = project.getPlugins().findPlugin(LibraryPlugin.class);
    }
    if (null == basePlugin) {
        return null;
    }
    AndroidBuilder androidBuilder = (AndroidBuilder) ReflectUtils.getField(BasePlugin.class, basePlugin, "androidBuilder");
    return androidBuilder;
}
Also used : BasePlugin(com.android.build.gradle.BasePlugin) AndroidBuilder(com.android.builder.core.AndroidBuilder) LibraryPlugin(com.android.build.gradle.LibraryPlugin)

Example 3 with AndroidBuilder

use of com.android.builder.core.AndroidBuilder in project atlas by alibaba.

the class ProcessAwbAndroidResources method makeAapt.

private Aapt makeAapt() throws IOException {
    AndroidBuilder builder = getBuilder();
    MergingLog mergingLog = new MergingLog(getMergeBlameLogFolder());
    FileCache fileCache = appVariantContext.getScope().getGlobalScope().getBuildCache();
    ProcessOutputHandler processOutputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(aaptGeneration == AaptGeneration.AAPT_V1 ? new AaptOutputParser() : new Aapt2OutputParser(), getILogger()), new MergingLogRewriter(mergingLog::find, builder.getErrorReporter()));
    return AaptGradleFactory.make(aaptGeneration, builder, processOutputHandler, fileCache, true, FileUtils.mkdirs(new File(getIncrementalFolder(), "awb-aapt-temp/" + awbBundle.getName())), aaptOptions.getCruncherProcesses());
}
Also used : MergingLogRewriter(com.android.ide.common.blame.MergingLogRewriter) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) LoggedProcessOutputHandler(com.android.ide.common.process.LoggedProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) ToolOutputParser(com.android.ide.common.blame.parser.ToolOutputParser) MergingLog(com.android.ide.common.blame.MergingLog) AndroidBuilder(com.android.builder.core.AndroidBuilder) Aapt2OutputParser(com.android.ide.common.blame.parser.aapt.Aapt2OutputParser) AaptOutputParser(com.android.ide.common.blame.parser.aapt.AaptOutputParser) JarFile(java.util.jar.JarFile) File(java.io.File) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) FileCache(com.android.builder.utils.FileCache)

Example 4 with AndroidBuilder

use of com.android.builder.core.AndroidBuilder in project atlas by alibaba.

the class BasePlugin method configureProject.

protected void configureProject() {
    extraModelInfo = new ExtraModelInfo(project, isLibrary());
    checkGradleVersion();
    sdkHandler = new SdkHandler(project, getLogger());
    project.afterEvaluate(p -> {
        if (!p.getGradle().getStartParameter().isOffline() && AndroidGradleOptions.getUseSdkDownload(p)) {
            SdkLibData sdkLibData = SdkLibData.download(getDownloader(), getSettingsController());
            dependencyManager.setSdkLibData(sdkLibData);
            sdkHandler.setSdkLibData(sdkLibData);
        }
    });
    androidBuilder = new AndroidBuilder(project == project.getRootProject() ? project.getName() : project.getPath(), creator, new GradleProcessExecutor(project), new GradleJavaProcessExecutor(project), extraModelInfo, getLogger(), isVerbose());
    dataBindingBuilder = new DataBindingBuilder();
    dataBindingBuilder.setPrintMachineReadableOutput(extraModelInfo.getErrorFormatMode() == ExtraModelInfo.ErrorFormatMode.MACHINE_PARSABLE);
    project.getPlugins().apply(JavaBasePlugin.class);
    jacocoPlugin = project.getPlugins().apply(JacocoPlugin.class);
    project.getTasks().getByName("assemble").setDescription("Assembles all variants of all applications and secondary packages.");
    // call back on execution. This is called after the whole build is done (not
    // after the current project is done).
    // This is will be called for each (android) projects though, so this should support
    // being called 2+ times.
    project.getGradle().addBuildListener(new BuildListener() {

        private final LibraryCache libraryCache = LibraryCache.getCache();

        @Override
        public void buildStarted(Gradle gradle) {
        }

        @Override
        public void settingsEvaluated(Settings settings) {
        }

        @Override
        public void projectsLoaded(Gradle gradle) {
        }

        @Override
        public void projectsEvaluated(Gradle gradle) {
        }

        @Override
        public void buildFinished(BuildResult buildResult) {
            ExecutorSingleton.shutdown();
            sdkHandler.unload();
            ThreadRecorder.get().record(ExecutionType.BASE_PLUGIN_BUILD_FINISHED, project.getPath(), null, new Recorder.Block() {

                @Override
                public Void call() throws Exception {
                    PreDexCache.getCache().clear(new File(project.getRootProject().getBuildDir(), FD_INTERMEDIATES + "/dex-cache/cache.xml"), getLogger());
                    JackConversionCache.getCache().clear(new File(project.getRootProject().getBuildDir(), FD_INTERMEDIATES + "/jack-cache/cache.xml"), getLogger());
                    libraryCache.unload();
                    Main.clearInternTables();
                    return null;
                }
            });
        }
    });
    project.getGradle().getTaskGraph().addTaskExecutionGraphListener(new TaskExecutionGraphListener() {

        @Override
        public void graphPopulated(TaskExecutionGraph taskGraph) {
            for (Task task : taskGraph.getAllTasks()) {
                if (task instanceof TransformTask) {
                    Transform transform = ((TransformTask) task).getTransform();
                    if (transform instanceof DexTransform) {
                        PreDexCache.getCache().load(new File(project.getRootProject().getBuildDir(), FD_INTERMEDIATES + "/dex-cache/cache.xml"));
                        break;
                    } else if (transform instanceof JackPreDexTransform) {
                        JackConversionCache.getCache().load(new File(project.getRootProject().getBuildDir(), FD_INTERMEDIATES + "/jack-cache/cache.xml"));
                        break;
                    }
                }
            }
        }
    });
}
Also used : TaskExecutionGraphListener(org.gradle.api.execution.TaskExecutionGraphListener) SdkLibData(com.android.builder.sdk.SdkLibData) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) Task(org.gradle.api.Task) JackPreDexTransform(com.android.build.gradle.tasks.JackPreDexTransform) JacocoPlugin(com.android.build.gradle.internal.coverage.JacocoPlugin) DataBindingBuilder(android.databinding.tool.DataBindingBuilder) BuildListener(org.gradle.BuildListener) BuildResult(org.gradle.BuildResult) ExtraModelInfo(com.android.build.gradle.internal.ExtraModelInfo) GradleProcessExecutor(com.android.build.gradle.internal.process.GradleProcessExecutor) LibraryCache(com.android.build.gradle.internal.LibraryCache) AndroidBuilder(com.android.builder.core.AndroidBuilder) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) Gradle(org.gradle.api.invocation.Gradle) SdkHandler(com.android.build.gradle.internal.SdkHandler) Transform(com.android.build.api.transform.Transform) DexTransform(com.android.build.gradle.internal.transforms.DexTransform) JackPreDexTransform(com.android.build.gradle.tasks.JackPreDexTransform) File(java.io.File) TaskExecutionGraph(org.gradle.api.execution.TaskExecutionGraph) DexTransform(com.android.build.gradle.internal.transforms.DexTransform) JackPreDexTransform(com.android.build.gradle.tasks.JackPreDexTransform) Settings(org.gradle.api.initialization.Settings) GradleJavaProcessExecutor(com.android.build.gradle.internal.process.GradleJavaProcessExecutor)

Example 5 with AndroidBuilder

use of com.android.builder.core.AndroidBuilder in project atlas by alibaba.

the class TPatchDiffResAPBuildTask method makeAapt.

private Aapt makeAapt(AaptGeneration aaptGeneration) throws IOException {
    AndroidBuilder builder = getBuilder();
    MergingLog mergingLog = new MergingLog(mergeBlameLogFolder);
    ProcessOutputHandler processOutputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(aaptGeneration == AaptGeneration.AAPT_V1 ? new AaptOutputParser() : new Aapt2OutputParser(), getILogger()), new MergingLogRewriter(mergingLog::find, builder.getErrorReporter()));
    return AaptGradleFactory.make(aaptGeneration, builder, processOutputHandler, fileCache, true, com.android.utils.FileUtils.mkdirs(new File(appVariantContext.getScope().getIncrementalDir(getName()), "aapt-temp")), aaptOptions.getCruncherProcesses());
}
Also used : MergingLogRewriter(com.android.ide.common.blame.MergingLogRewriter) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) ToolOutputParser(com.android.ide.common.blame.parser.ToolOutputParser) MergingLog(com.android.ide.common.blame.MergingLog) AndroidBuilder(com.android.builder.core.AndroidBuilder) Aapt2OutputParser(com.android.ide.common.blame.parser.aapt.Aapt2OutputParser) AaptOutputParser(com.android.ide.common.blame.parser.aapt.AaptOutputParser) File(java.io.File) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler)

Aggregations

AndroidBuilder (com.android.builder.core.AndroidBuilder)6 File (java.io.File)4 GradleJavaProcessExecutor (com.android.build.gradle.internal.process.GradleJavaProcessExecutor)2 GradleProcessExecutor (com.android.build.gradle.internal.process.GradleProcessExecutor)2 AtlasBuilder (com.android.builder.core.AtlasBuilder)2 MergingLog (com.android.ide.common.blame.MergingLog)2 MergingLogRewriter (com.android.ide.common.blame.MergingLogRewriter)2 ParsingProcessOutputHandler (com.android.ide.common.blame.ParsingProcessOutputHandler)2 ToolOutputParser (com.android.ide.common.blame.parser.ToolOutputParser)2 Aapt2OutputParser (com.android.ide.common.blame.parser.aapt.Aapt2OutputParser)2 AaptOutputParser (com.android.ide.common.blame.parser.aapt.AaptOutputParser)2 ProcessOutputHandler (com.android.ide.common.process.ProcessOutputHandler)2 JarFile (java.util.jar.JarFile)2 DataBindingBuilder (android.databinding.tool.DataBindingBuilder)1 NonNull (com.android.annotations.NonNull)1 Nullable (com.android.annotations.Nullable)1 Transform (com.android.build.api.transform.Transform)1 BasePlugin (com.android.build.gradle.BasePlugin)1 LibraryPlugin (com.android.build.gradle.LibraryPlugin)1 ExtraModelInfo (com.android.build.gradle.internal.ExtraModelInfo)1