Search in sources :

Example 6 with BuildAdapter

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

the class ScalaBasePlugin method configureScalaCompile.

private static void configureScalaCompile(final Project project, JavaBasePlugin javaPlugin, final SourceSet sourceSet) {
    String taskName = sourceSet.getCompileTaskName("scala");
    final ScalaCompile scalaCompile = project.getTasks().create(taskName, ScalaCompile.class);
    scalaCompile.dependsOn(sourceSet.getCompileJavaTaskName());
    javaPlugin.configureForSourceSet(sourceSet, scalaCompile);
    Convention scalaConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
    ScalaSourceSet scalaSourceSet = scalaConvention.findPlugin(ScalaSourceSet.class);
    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 7 with BuildAdapter

use of org.gradle.BuildAdapter 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();
    gradle.getStartParameter().setConfigureOnDemand(false);
    ClientProvidedBuildAction clientProvidedBuildAction = (ClientProvidedBuildAction) action;
    PayloadSerializer payloadSerializer = getPayloadSerializer(gradle);
    final Object clientAction = payloadSerializer.deserialize(clientProvidedBuildAction.getAction());
    gradle.addBuildListener(new BuildAdapter() {

        @Override
        public void buildFinished(BuildResult result) {
            if (result.getFailure() == null) {
                buildController.setResult(buildResult(clientAction, gradle));
            }
        }
    });
    if (clientProvidedBuildAction.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) BuildAdapter(org.gradle.BuildAdapter)

Example 8 with BuildAdapter

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

the class DependencyManagementGradleUserHomeScopeServices method createArtifactCaches.

ArtifactCachesProvider createArtifactCaches(GlobalScopedCache globalScopedCache, CacheRepository cacheRepository, DefaultArtifactCaches.WritableArtifactCacheLockingParameters parameters, ListenerManager listenerManager, DocumentationRegistry documentationRegistry) {
    DefaultArtifactCaches artifactCachesProvider = new DefaultArtifactCaches(globalScopedCache, cacheRepository, parameters, documentationRegistry);
    listenerManager.addListener(new BuildAdapter() {

        @SuppressWarnings("deprecation")
        @Override
        public void buildFinished(BuildResult result) {
            artifactCachesProvider.getWritableCacheLockingManager().useCache(() -> {
            // forces cleanup even if cache wasn't used
            });
        }
    });
    return artifactCachesProvider;
}
Also used : DefaultArtifactCaches(org.gradle.api.internal.artifacts.ivyservice.DefaultArtifactCaches) BuildResult(org.gradle.BuildResult) BuildAdapter(org.gradle.BuildAdapter)

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