Search in sources :

Example 1 with BuildAdapter

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

the class IdePlugin method postProcess.

/**
     * Executes the provided Action after all projects have been evaluated.
     * Action will only be added once per provided key. Any subsequent calls for the same key will be ignored.
     * This permits the plugin to be applied in multiple subprojects, with the postprocess action executed once only.
     */
protected void postProcess(String key, final Action<? super Gradle> action) {
    Project rootProject = project.getRootProject();
    ExtraPropertiesExtension rootExtraProperties = rootProject.getExtensions().getByType(ExtraPropertiesExtension.class);
    String extraPropertyName = "org.gradle." + key + ".postprocess.applied";
    if (!rootExtraProperties.has(extraPropertyName)) {
        project.getGradle().addBuildListener(new BuildAdapter() {

            @Override
            public void projectsEvaluated(Gradle gradle) {
                action.execute(gradle);
            }
        });
        rootExtraProperties.set(extraPropertyName, true);
    }
}
Also used : Project(org.gradle.api.Project) ExtraPropertiesExtension(org.gradle.api.plugins.ExtraPropertiesExtension) BuildAdapter(org.gradle.BuildAdapter) Gradle(org.gradle.api.invocation.Gradle)

Example 2 with BuildAdapter

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

the class ScalaBasePlugin method configureScalaCompile.

private static void configureScalaCompile(final Project project, final SourceSet sourceSet) {
    String taskName = sourceSet.getCompileTaskName("scala");
    final ScalaCompile scalaCompile = project.getTasks().create(taskName, ScalaCompile.class);
    scalaCompile.dependsOn(sourceSet.getCompileJavaTaskName());
    Convention scalaConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
    ScalaSourceSet scalaSourceSet = scalaConvention.findPlugin(ScalaSourceSet.class);
    SourceSetUtil.configureForSourceSet(sourceSet, scalaSourceSet.getScala(), scalaCompile, scalaCompile.getOptions(), project);
    scalaCompile.setDescription("Compiles the " + scalaSourceSet.getScala() + ".");
    scalaCompile.setSource(scalaSourceSet.getScala());
    project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(taskName);
    // cannot use convention mapping because the resulting object won't be serializable
    // cannot compute at task execution time because we need association with source set
    project.getGradle().addBuildListener(new BuildAdapter() {

        @Override
        public void projectsEvaluated(Gradle gradle) {
            IncrementalCompileOptions incrementalOptions = scalaCompile.getScalaCompileOptions().getIncrementalOptions();
            if (incrementalOptions.getAnalysisFile() == null) {
                String analysisFilePath = project.getBuildDir().getPath() + "/tmp/scala/compilerAnalysis/" + scalaCompile.getName() + ".analysis";
                incrementalOptions.setAnalysisFile(new File(analysisFilePath));
            }
            if (incrementalOptions.getPublishedCode() == null) {
                Jar jarTask = (Jar) project.getTasks().findByName(sourceSet.getJarTaskName());
                incrementalOptions.setPublishedCode(jarTask == null ? null : jarTask.getArchivePath());
            }
        }
    });
}
Also used : IncrementalCompileOptions(org.gradle.api.tasks.scala.IncrementalCompileOptions) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Convention(org.gradle.api.plugins.Convention) ScalaCompile(org.gradle.api.tasks.scala.ScalaCompile) ScalaSourceSet(org.gradle.api.tasks.ScalaSourceSet) DefaultScalaSourceSet(org.gradle.api.internal.tasks.DefaultScalaSourceSet) BuildAdapter(org.gradle.BuildAdapter) Jar(org.gradle.jvm.tasks.Jar) Gradle(org.gradle.api.invocation.Gradle) File(java.io.File)

Example 3 with BuildAdapter

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

the class DefaultGradleLauncherFactory method newInstance.

@Override
public GradleLauncher newInstance(StartParameter startParameter, BuildRequestContext requestContext, ServiceRegistry parentRegistry) {
    // This should only be used for top-level builds
    if (rootBuild != null) {
        throw new IllegalStateException("Cannot have a current build");
    }
    if (!(parentRegistry instanceof BuildTreeScopeServices)) {
        throw new IllegalArgumentException("Service registry must be of build-tree scope");
    }
    BuildTreeScopeServices buildTreeScopeServices = (BuildTreeScopeServices) parentRegistry;
    // TODO: Push this up more so we can inject plugins into the root build as well.
    BuildDefinition buildDefinition = BuildDefinition.fromStartParameter(startParameter);
    DefaultGradleLauncher launcher = doNewInstance(buildDefinition, null, requestContext.getCancellationToken(), requestContext, requestContext.getEventConsumer(), buildTreeScopeServices, ImmutableList.of(new Stoppable() {

        @Override
        public void stop() {
            rootBuild = null;
        }
    }));
    rootBuild = launcher;
    final DefaultDeploymentRegistry deploymentRegistry = parentRegistry.get(DefaultDeploymentRegistry.class);
    launcher.getGradle().addBuildListener(new BuildAdapter() {

        @Override
        public void buildFinished(BuildResult result) {
            deploymentRegistry.buildFinished(result);
        }
    });
    return launcher;
}
Also used : BuildResult(org.gradle.BuildResult) DefaultDeploymentRegistry(org.gradle.deployment.internal.DefaultDeploymentRegistry) BuildTreeScopeServices(org.gradle.internal.service.scopes.BuildTreeScopeServices) Stoppable(org.gradle.internal.concurrent.Stoppable) BuildAdapter(org.gradle.BuildAdapter) BuildDefinition(org.gradle.api.internal.BuildDefinition)

Example 4 with BuildAdapter

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

the class IdeaScalaConfigurer method configure.

public void configure() {
    rootProject.getGradle().addBuildListener(new BuildAdapter() {

        public void projectsEvaluated(Gradle gradle) {
            VersionNumber ideaTargetVersion = findIdeaTargetVersion();
            final boolean useScalaSdk = ideaTargetVersion == null || IDEA_VERSION_WHEN_SCALA_SDK_WAS_INTRODUCED.compareTo(ideaTargetVersion) <= 0;
            final Collection<Project> scalaProjects = findProjectsApplyingIdeaAndScalaPlugins();
            final Map<String, ProjectLibrary> scalaCompilerLibraries = Maps.newLinkedHashMap();
            rootProject.getTasks().getByName("ideaProject").doFirst(new Action<Task>() {

                @Override
                public void execute(Task task) {
                    if (scalaProjects.size() > 0) {
                        scalaCompilerLibraries.clear();
                        scalaCompilerLibraries.putAll(resolveScalaCompilerLibraries(scalaProjects, useScalaSdk));
                        declareUniqueProjectLibraries(Sets.newLinkedHashSet(scalaCompilerLibraries.values()));
                    }
                }
            });
            rootProject.configure(scalaProjects, new Action<Project>() {

                @Override
                public void execute(final Project project) {
                    project.getExtensions().getByType(IdeaModel.class).getModule().getIml().withXml(new Action<XmlProvider>() {

                        @Override
                        public void execute(XmlProvider xmlProvider) {
                            if (useScalaSdk) {
                                declareScalaSdk(scalaCompilerLibraries.get(project.getPath()), xmlProvider.asNode());
                            } else {
                                declareScalaFacet(scalaCompilerLibraries.get(project.getPath()), xmlProvider.asNode());
                            }
                        }
                    });
                }
            });
        }
    });
}
Also used : Project(org.gradle.api.Project) Action(org.gradle.api.Action) Task(org.gradle.api.Task) IdeaModel(org.gradle.plugins.ide.idea.model.IdeaModel) XmlProvider(org.gradle.api.XmlProvider) FileCollection(org.gradle.api.file.FileCollection) Collection(java.util.Collection) BuildAdapter(org.gradle.BuildAdapter) Gradle(org.gradle.api.invocation.Gradle) Map(java.util.Map) VersionNumber(org.gradle.util.VersionNumber)

Example 5 with BuildAdapter

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

the class DefaultDaemonScanInfo method notifyOnUnhealthy.

@Override
public void notifyOnUnhealthy(final Action<? super String> listener) {
    /*
            The semantics of this method are that the given action should be notified if the
            Daemon is going to be terminated at the end of this build.
            It is not a generic outlet for “expiry events”.

            Ideally, the value given would describe the problem and not be phrased in terms of why we are shutting down,
            but this is a practical compromise born out of piggy backing on the expiration listener mechanism to implement it.
         */
    final AtomicReference<DaemonExpirationListener> daemonExpirationListenerReference = new AtomicReference<DaemonExpirationListener>();
    final DaemonExpirationListener daemonExpirationListener = new DaemonExpirationListener() {

        @Override
        public void onExpirationEvent(DaemonExpirationResult result) {
            if (result.getStatus() == DaemonExpirationStatus.GRACEFUL_EXPIRE) {
                try {
                    listener.execute(result.getReason());
                } finally {
                    // set the reference to null, which says that we're taking care of removing the listener
                    if (daemonExpirationListenerReference.getAndSet(null) != null) {
                        listenerManager.removeListener(this);
                    }
                }
            }
        }
    };
    daemonExpirationListenerReference.set(daemonExpirationListener);
    listenerManager.addListener(daemonExpirationListener);
    final BuildAdapter buildListener = new InternalBuildAdapter() {

        @Override
        public void buildFinished(BuildResult result) {
            DaemonExpirationListener daemonExpirationListener = daemonExpirationListenerReference.getAndSet(null);
            if (daemonExpirationListener != null) {
                listenerManager.removeListener(daemonExpirationListener);
            }
            listenerManager.removeListener(this);
        }
    };
    listenerManager.addListener(buildListener);
}
Also used : BuildResult(org.gradle.BuildResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) BuildAdapter(org.gradle.BuildAdapter) InternalBuildAdapter(org.gradle.internal.InternalBuildAdapter) DaemonExpirationResult(org.gradle.launcher.daemon.server.expiry.DaemonExpirationResult) InternalBuildAdapter(org.gradle.internal.InternalBuildAdapter) DaemonExpirationListener(org.gradle.launcher.daemon.server.expiry.DaemonExpirationListener)

Aggregations

BuildAdapter (org.gradle.BuildAdapter)8 BuildResult (org.gradle.BuildResult)4 Gradle (org.gradle.api.invocation.Gradle)4 File (java.io.File)2 Project (org.gradle.api.Project)2 DefaultScalaSourceSet (org.gradle.api.internal.tasks.DefaultScalaSourceSet)2 Convention (org.gradle.api.plugins.Convention)2 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)2 ScalaSourceSet (org.gradle.api.tasks.ScalaSourceSet)2 IncrementalCompileOptions (org.gradle.api.tasks.scala.IncrementalCompileOptions)2 ScalaCompile (org.gradle.api.tasks.scala.ScalaCompile)2 Jar (org.gradle.jvm.tasks.Jar)2 Collection (java.util.Collection)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Action (org.gradle.api.Action)1 Task (org.gradle.api.Task)1 XmlProvider (org.gradle.api.XmlProvider)1 FileCollection (org.gradle.api.file.FileCollection)1 BuildDefinition (org.gradle.api.internal.BuildDefinition)1