Search in sources :

Example 6 with BuildResult

use of org.gradle.BuildResult in project gradle by gradle.

the class DefaultGradleLauncher method doBuild.

private BuildResult doBuild(final Stage upTo) {
    Throwable failure = null;
    try {
        buildListener.buildStarted(gradle);
        doBuildStages(upTo);
    } catch (Throwable t) {
        failure = exceptionAnalyser.transform(t);
    }
    BuildResult buildResult = new BuildResult(upTo.name(), gradle, failure);
    buildListener.buildFinished(buildResult);
    if (failure != null) {
        throw new ReportedException(failure);
    }
    return buildResult;
}
Also used : BuildResult(org.gradle.BuildResult)

Example 7 with BuildResult

use of org.gradle.BuildResult in project gradle by gradle.

the class ClientProvidedBuildActionRunner method run.

@Override
public void run(BuildAction action, final BuildController buildController) {
    if (!(action instanceof ClientProvidedBuildAction)) {
        return;
    }
    final GradleInternal gradle = buildController.getGradle();
    ClientProvidedBuildAction clientProvidedBuildAction = (ClientProvidedBuildAction) action;
    PayloadSerializer payloadSerializer = getPayloadSerializer(gradle);
    final InternalBuildAction<?> clientAction = (InternalBuildAction<?>) payloadSerializer.deserialize(clientProvidedBuildAction.getAction());
    final boolean isRunTasks = clientProvidedBuildAction.isRunTasks();
    gradle.addBuildListener(new BuildAdapter() {

        @Override
        public void buildFinished(BuildResult result) {
            if (result.getFailure() == null) {
                buildController.setResult(buildResult(clientAction, gradle, isRunTasks));
            }
        }
    });
    if (isRunTasks) {
        buildController.run();
    } else {
        buildController.configure();
    }
}
Also used : GradleInternal(org.gradle.api.internal.GradleInternal) BuildResult(org.gradle.BuildResult) PayloadSerializer(org.gradle.tooling.internal.provider.serialization.PayloadSerializer) ClientProvidedBuildAction(org.gradle.tooling.internal.provider.ClientProvidedBuildAction) InternalBuildAction(org.gradle.tooling.internal.protocol.InternalBuildAction) BuildAdapter(org.gradle.BuildAdapter)

Example 8 with BuildResult

use of org.gradle.BuildResult in project gradle by gradle.

the class InProcessGradleExecuter method executeBuild.

private BuildResult executeBuild(GradleInvocation invocation, StandardOutputListener outputListener, StandardOutputListener errorListener, BuildListenerImpl listener) {
    // Augment the environment for the execution
    System.setIn(connectStdIn());
    processEnvironment.maybeSetProcessDir(getWorkingDir());
    for (Map.Entry<String, String> entry : invocation.environmentVars.entrySet()) {
        processEnvironment.maybeSetEnvironmentVariable(entry.getKey(), entry.getValue());
    }
    Map<String, String> implicitJvmSystemProperties = getImplicitJvmSystemProperties();
    System.getProperties().putAll(implicitJvmSystemProperties);
    resetTempDirLocation();
    // TODO: Fix tests that rely on this being set before we process arguments like this...
    StartParameter startParameter = new StartParameter();
    startParameter.setCurrentDir(getWorkingDir());
    startParameter.setShowStacktrace(ShowStacktrace.ALWAYS);
    CommandLineParser parser = new CommandLineParser();
    ParametersConverter parametersConverter = new ParametersConverter();
    parametersConverter.configure(parser);
    final Parameters parameters = new Parameters(startParameter);
    parametersConverter.convert(parser.parse(getAllArgs()), parameters);
    BuildActionExecuter<BuildActionParameters> actionExecuter = GLOBAL_SERVICES.get(BuildActionExecuter.class);
    ListenerManager listenerManager = GLOBAL_SERVICES.get(ListenerManager.class);
    listenerManager.addListener(listener);
    try {
        // TODO: Reuse more of BuildActionsFactory
        BuildAction action = new ExecuteBuildAction(startParameter);
        BuildActionParameters buildActionParameters = createBuildActionParameters(startParameter);
        BuildRequestContext buildRequestContext = createBuildRequestContext(outputListener, errorListener);
        startMeasurement();
        actionExecuter.execute(action, buildRequestContext, buildActionParameters, GLOBAL_SERVICES);
        return new BuildResult(null, null);
    } catch (ReportedException e) {
        return new BuildResult(null, e.getCause());
    } finally {
        stopMeasurement();
        listenerManager.removeListener(listener);
    }
}
Also used : StartParameter(org.gradle.StartParameter) Parameters(org.gradle.launcher.cli.Parameters) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) ExecuteBuildAction(org.gradle.launcher.cli.ExecuteBuildAction) DefaultBuildRequestContext(org.gradle.initialization.DefaultBuildRequestContext) BuildRequestContext(org.gradle.initialization.BuildRequestContext) BuildResult(org.gradle.BuildResult) ParametersConverter(org.gradle.launcher.cli.ParametersConverter) CommandLineParser(org.gradle.cli.CommandLineParser) Map(java.util.Map) HashMap(java.util.HashMap) ExecuteBuildAction(org.gradle.launcher.cli.ExecuteBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction) ListenerManager(org.gradle.internal.event.ListenerManager) ReportedException(org.gradle.initialization.ReportedException)

Example 9 with BuildResult

use of org.gradle.BuildResult 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)

Aggregations

BuildResult (org.gradle.BuildResult)9 BuildAdapter (org.gradle.BuildAdapter)2 BuildListener (org.gradle.BuildListener)2 Settings (org.gradle.api.initialization.Settings)2 Gradle (org.gradle.api.invocation.Gradle)2 ReportedException (org.gradle.initialization.ReportedException)2 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2 DataBindingBuilder (android.databinding.tool.DataBindingBuilder)1 Transform (com.android.build.api.transform.Transform)1 AndroidConfig (com.android.build.gradle.AndroidConfig)1 ExtraModelInfo (com.android.build.gradle.internal.ExtraModelInfo)1 LibraryCache (com.android.build.gradle.internal.LibraryCache)1 SdkHandler (com.android.build.gradle.internal.SdkHandler)1 JacocoPlugin (com.android.build.gradle.internal.coverage.JacocoPlugin)1 TransformTask (com.android.build.gradle.internal.pipeline.TransformTask)1 GradleJavaProcessExecutor (com.android.build.gradle.internal.process.GradleJavaProcessExecutor)1 GradleProcessExecutor (com.android.build.gradle.internal.process.GradleProcessExecutor)1 DexTransform (com.android.build.gradle.internal.transforms.DexTransform)1 JackPreDexTransform (com.android.build.gradle.tasks.JackPreDexTransform)1