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);
}
}
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());
}
}
});
}
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;
}
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());
}
}
});
}
});
}
});
}
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);
}
Aggregations