use of org.gradle.api.Task 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.api.Task in project gradle by gradle.
the class NativeBasePlugin method addLifecycleTasks.
private void addLifecycleTasks(final TaskContainer tasks, final SoftwareComponentContainer components) {
components.withType(ComponentWithBinaries.class, new Action<ComponentWithBinaries>() {
@Override
public void execute(final ComponentWithBinaries component) {
// Register each child of each component
component.getBinaries().whenElementKnown(new Action<SoftwareComponent>() {
@Override
public void execute(SoftwareComponent binary) {
components.add(binary);
}
});
if (component instanceof ProductionComponent) {
// Add an assemble task for each binary and also wire the development binary in to the `assemble` task
component.getBinaries().whenElementFinalized(ComponentWithOutputs.class, new Action<ComponentWithOutputs>() {
@Override
public void execute(ComponentWithOutputs binary) {
// Determine which output to produce at development time.
FileCollection outputs = binary.getOutputs();
Names names = ((ComponentWithNames) binary).getNames();
Task lifecycleTask = tasks.create(names.getTaskName("assemble"));
lifecycleTask.dependsOn(outputs);
if (binary == ((ProductionComponent) component).getDevelopmentBinary().get()) {
tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(outputs);
}
}
});
}
}
});
}
use of org.gradle.api.Task in project gradle by gradle.
the class PlayDistributionPlugin method createDistributionContentTasks.
@Mutate
void createDistributionContentTasks(ModelMap<Task> tasks, @Path("buildDir") final File buildDir, @Path("distributions") final PlayDistributionContainer distributions, final PlayPluginConfigurations configurations) {
for (final PlayDistribution distribution : distributions.withType(PlayDistribution.class)) {
final PlayApplicationBinarySpec binary = distribution.getBinary();
if (binary == null) {
throw new InvalidUserCodeException(String.format("Play Distribution '%s' does not have a configured Play binary.", distribution.getName()));
}
final File distJarDir = new File(buildDir, "distributionJars/" + distribution.getName());
final String jarTaskName = "create" + StringUtils.capitalize(distribution.getName()) + "DistributionJar";
tasks.create(jarTaskName, Jar.class, new Action<Jar>() {
@Override
public void execute(Jar jar) {
jar.setDescription("Assembles an application jar suitable for deployment for the " + binary + ".");
jar.dependsOn(binary.getTasks().withType(Jar.class));
jar.from(jar.getProject().zipTree(binary.getJarFile()));
jar.setDestinationDir(distJarDir);
jar.setArchiveName(binary.getJarFile().getName());
Map<String, Object> classpath = Maps.newHashMap();
classpath.put("Class-Path", new PlayManifestClasspath(configurations.getPlayRun(), binary.getAssetsJarFile()));
jar.getManifest().attributes(classpath);
}
});
final Task distributionJar = tasks.get(jarTaskName);
final File scriptsDir = new File(buildDir, "scripts/" + distribution.getName());
String createStartScriptsTaskName = "create" + StringUtils.capitalize(distribution.getName() + "StartScripts");
tasks.create(createStartScriptsTaskName, CreateStartScripts.class, new Action<CreateStartScripts>() {
@Override
public void execute(CreateStartScripts createStartScripts) {
createStartScripts.setDescription("Creates OS specific scripts to run the " + binary + ".");
createStartScripts.setClasspath(distributionJar.getOutputs().getFiles());
createStartScripts.setMainClassName(getMainClass(distribution));
createStartScripts.setApplicationName(distribution.getName());
createStartScripts.setOutputDir(scriptsDir);
}
});
Task createStartScripts = tasks.get(createStartScriptsTaskName);
CopySpecInternal distSpec = (CopySpecInternal) distribution.getContents();
CopySpec libSpec = distSpec.addChild().into("lib");
libSpec.from(distributionJar);
libSpec.from(binary.getAssetsJarFile());
libSpec.from(configurations.getPlayRun().getAllArtifacts());
libSpec.eachFile(new PrefixArtifactFileNames(configurations.getPlayRun()));
CopySpec binSpec = distSpec.addChild().into("bin");
binSpec.from(createStartScripts);
binSpec.setFileMode(0755);
CopySpec confSpec = distSpec.addChild().into("conf");
confSpec.from("conf").exclude("routes");
distSpec.from("README");
}
}
use of org.gradle.api.Task in project gradle by gradle.
the class ApplicationPlugin method configureDistSpec.
private CopySpec configureDistSpec(CopySpec distSpec) {
Task jar = project.getTasks().getAt(JavaPlugin.JAR_TASK_NAME);
Task startScripts = project.getTasks().getAt(TASK_START_SCRIPTS_NAME);
CopySpec libChildSpec = project.copySpec();
libChildSpec.into("lib");
libChildSpec.from(jar);
libChildSpec.from(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
CopySpec binChildSpec = project.copySpec();
binChildSpec.into(new Callable<Object>() {
@Override
public Object call() throws Exception {
return pluginConvention.getExecutableDir();
}
});
binChildSpec.from(startScripts);
binChildSpec.setFileMode(0755);
CopySpec childSpec = project.copySpec();
childSpec.from(project.file("src/dist"));
childSpec.with(libChildSpec);
childSpec.with(binChildSpec);
distSpec.with(childSpec);
distSpec.with(pluginConvention.getApplicationDistribution());
return distSpec;
}
use of org.gradle.api.Task in project gradle by gradle.
the class JavaBasePlugin method configureBasedOnSingleProperty.
private void configureBasedOnSingleProperty(final Test test) {
String singleTest = getTaskPrefixedProperty(test, "single");
if (singleTest == null) {
// configure inputs so that the test task is skipped when there are no source files.
// unfortunately, this only applies when 'test.single' is *not* applied
// We should fix this distinction, the behavior with 'test.single' or without it should be the same
test.getInputs().files(test.getCandidateClassFiles()).withPropertyName("nonEmptyCandidateClassFiles").withPathSensitivity(PathSensitivity.RELATIVE).skipWhenEmpty();
return;
}
test.prependParallelSafeAction(new Action<Task>() {
public void execute(Task task) {
test.getLogger().info("Running single tests with pattern: {}", test.getIncludes());
}
});
test.setIncludes(WrapUtil.toSet("**/" + singleTest + "*.class"));
test.addTestListener(new NoMatchingTestsReporter("Could not find matching test for pattern: " + singleTest));
}
Aggregations