Java源码示例:org.gradle.language.base.plugins.LifecycleBasePlugin
示例1
private void logWarningIfCheckTaskOnTaskGraph(Project project, TaskExecutionGraph graph) {
if (logger.isWarnEnabled()) {
Optional<Task> lastCheckTask = graph.getAllTasks().stream().sorted(reverseOrder())
.filter(t -> t.getName().endsWith(LifecycleBasePlugin.CHECK_TASK_NAME)).findFirst();
if (lastCheckTask.isPresent()) { // it is possible to just execute a task before "check", e.g. "compileJava"
Task task = lastCheckTask.get();
String message = "\n" +
"WARNING: Due to the absence of '" + LifecycleBasePlugin.class.getSimpleName() +
"' on " + project + " the task ':" + TASK_NAME_CPD_CHECK +
"' could not be added to task graph. Therefore CPD will not be executed. To prevent this, manually add a task dependency of ':" +
TASK_NAME_CPD_CHECK + "' to a '" + LifecycleBasePlugin.CHECK_TASK_NAME +
"' task of a subproject.\n" +
"1) Directly to " + task.getProject() + ":\n" +
" " + task.getName() + ".dependsOn(':" + TASK_NAME_CPD_CHECK + "')\n" +
"2) Indirectly, e.g. via " + project + ":\n" +
" project('" + task.getProject().getPath() + "') {\n" +
" plugins.withType(LifecycleBasePlugin) { // <- just required if 'java' plugin is applied within subproject\n" +
" " + task.getName() + ".dependsOn(" + TASK_NAME_CPD_CHECK + ")\n" +
" }\n" +
" }\n";
logger.warn(message);
}
}
}
示例2
public void apply(Project project) {
project.getPlugins().apply(LifecycleBasePlugin.class);
BasePluginConvention convention = new BasePluginConvention(project);
project.getConvention().getPlugins().put("base", convention);
configureBuildConfigurationRule(project);
configureUploadRules(project);
configureUploadArchivesTask();
configureArchiveDefaults(project, convention);
configureConfigurations(project);
configureAssemble(project);
}
示例3
/**
* Configures SourceSets, dependencies and tasks related to each Transport UDF platform
*/
private void configurePlatform(Project project, Platform platform, SourceSet mainSourceSet, SourceSet testSourceSet,
File baseOutputDir) {
SourceSet sourceSet = configureSourceSet(project, platform, mainSourceSet, baseOutputDir);
configureGenerateWrappersTask(project, platform, mainSourceSet, sourceSet);
List<TaskProvider<? extends Task>> packagingTasks =
configurePackagingTasks(project, platform, sourceSet, mainSourceSet);
// Add Transport tasks to build task dependencies
project.getTasks().named(LifecycleBasePlugin.BUILD_TASK_NAME).configure(task -> task.dependsOn(packagingTasks));
TaskProvider<Test> testTask = configureTestTask(project, platform, mainSourceSet, testSourceSet);
project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME).configure(task -> task.dependsOn(testTask));
}
示例4
public void apply(Project project) {
project.getPluginManager().apply(LifecycleBasePlugin.class);
BasePluginConvention convention = new BasePluginConvention(project);
project.getConvention().getPlugins().put("base", convention);
configureBuildConfigurationRule(project);
configureUploadRules(project);
configureUploadArchivesTask();
configureArchiveDefaults(project, convention);
configureConfigurations(project);
configureAssemble((ProjectInternal) project);
}
示例5
private void createBinaryLifecycleTask(SourceSet sourceSet, Project target) {
sourceSet.compiledBy(sourceSet.getClassesTaskName());
Task binaryLifecycleTask = target.task(sourceSet.getClassesTaskName());
binaryLifecycleTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
binaryLifecycleTask.setDescription("Assembles " + sourceSet.getOutput() + ".");
binaryLifecycleTask.dependsOn(sourceSet.getOutput().getDirs());
binaryLifecycleTask.dependsOn(sourceSet.getCompileJavaTaskName());
binaryLifecycleTask.dependsOn(sourceSet.getProcessResourcesTaskName());
}
示例6
@Override
public void apply(Project project) {
project.getPlugins().apply(JacocoPlugin.class);
project.getTasks().register("aggregateJacocoReport", JacocoReport.class, reportTask -> {
reportTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
reportTask.setDescription(String.format("Generates aggregated code coverage report for the %s project.", project.getPath()));
project.allprojects(subproject -> {
subproject.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
SourceSetContainer sourceSets = subproject.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
reportTask.sourceSets(main);
});
subproject.getTasks()
.withType(Test.class)
.forEach(reportTask::executionData);
});
JacocoPluginExtension reportingExtension = project.getExtensions().getByType(JacocoPluginExtension.class);
reportTask.getReports().getHtml().setEnabled(true);
reportTask.getReports().all(report -> {
if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) {
report.setDestination(project.provider(() -> new File(reportingExtension.getReportsDir(), reportTask.getName() + "/" + report.getName())));
}
else {
report.setDestination(project.provider(() -> new File(reportingExtension.getReportsDir(), reportTask.getName() + "/" + reportTask.getName() + "." + report.getName())));
}
});
});
}
示例7
@Override
public void apply(Project project) {
project.getPlugins().apply(JacocoPlugin.class);
project.getTasks().register("aggregateJacocoReport", JacocoReport.class, reportTask -> {
reportTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
reportTask.setDescription(String.format("Generates aggregated code coverage report for the %s project.", project.getPath()));
project.allprojects(subproject -> {
subproject.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
SourceSetContainer sourceSets = subproject.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
reportTask.sourceSets(main);
});
subproject.getTasks()
.withType(Test.class)
.forEach(reportTask::executionData);
});
JacocoPluginExtension reportingExtension = project.getExtensions().getByType(JacocoPluginExtension.class);
reportTask.getReports().getHtml().setEnabled(true);
reportTask.getReports().all(report -> {
if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) {
report.setDestination(project.provider(() -> new File(reportingExtension.getReportsDir(), reportTask.getName() + "/" + report.getName())));
}
else {
report.setDestination(project.provider(() -> new File(reportingExtension.getReportsDir(), reportTask.getName() + "/" + reportTask.getName() + "." + report.getName())));
}
});
});
}
示例8
public void apply(Project project) {
project.getPlugins().apply(LifecycleBasePlugin.class);
BasePluginConvention convention = new BasePluginConvention(project);
project.getConvention().getPlugins().put("base", convention);
configureBuildConfigurationRule(project);
configureUploadRules(project);
configureUploadArchivesTask();
configureArchiveDefaults(project, convention);
configureConfigurations(project);
configureAssemble(project);
}
示例9
private void createTask(Project project) {
TaskProvider<Cpd> taskProvider = project.getTasks().register(TASK_NAME_CPD_CHECK, Cpd.class, task -> {
task.setDescription("Run CPD analysis for all sources");
project.getAllprojects().forEach(p ->
p.getPlugins().withType(JavaBasePlugin.class, plugin ->
p.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet ->
sourceSet.getAllJava().getSrcDirs().forEach(task::source)
)
)
);
});
project.getPlugins().withType(LifecycleBasePlugin.class, plugin ->
project.getTasks().findByName(LifecycleBasePlugin.CHECK_TASK_NAME).dependsOn(taskProvider));
}
示例10
static Stream<Class<? extends Plugin>> CpdPlugin_shouldAddCpdCheckTaskAsDependencyOfCheckLifecycleTaskIfPluginIsApplied() {
return Stream.of(
LifecycleBasePlugin.class,
BasePlugin.class,
LanguageBasePlugin.class,
JavaBasePlugin.class,
JavaPlugin.class,
GroovyPlugin.class,
CppPlugin.class
);
}
示例11
private void createBinaryLifecycleTask(ClassDirectoryBinarySpecInternal binary, Project target) {
Task binaryLifecycleTask = target.task(binary.getNamingScheme().getLifecycleTaskName());
binaryLifecycleTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
binaryLifecycleTask.setDescription(String.format("Assembles %s.", binary));
binary.setBuildTask(binaryLifecycleTask);
}
示例12
/**
* Creates and configures a task to run tests written using the Unified Testing Framework against a given platform
*/
private TaskProvider<Test> configureTestTask(Project project, Platform platform, SourceSet mainSourceSet,
SourceSet testSourceSet) {
/*
Configures the classpath configuration to run platform-specific tests. E.g. For the Presto platform,
configurations {
prestoTestClasspath {
extendsFrom testImplementation
}
}
dependencies {
prestoTestClasspath sourceSets.main.output, sourceSets.test.output
prestoTestClasspath 'com.linkedin.transport:transportable-udfs-test-presto'
}
*/
Configuration testClasspath = project.getConfigurations()
.create(platform.getName() + "TestClasspath",
config -> config.extendsFrom(getConfigurationForSourceSet(project, testSourceSet, IMPLEMENTATION)));
addDependencyToConfiguration(project, testClasspath, mainSourceSet.getOutput());
addDependencyToConfiguration(project, testClasspath, testSourceSet.getOutput());
platform.getDefaultTestDependencyConfigurations()
.forEach(dependencyConfiguration -> addDependencyToConfiguration(project, testClasspath,
dependencyConfiguration.getDependencyString()));
/*
Creates the test task for a given platform. E.g. For the Presto platform,
task prestoTest(type: Test, dependsOn: test) {
group 'Verification'
description 'Runs the Presto tests.'
testClassesDirs = sourceSets.test.output.classesDirs
classpath = configurations.prestoTestClasspath
useTestNG()
}
*/
return project.getTasks().register(testTaskName(platform), Test.class, task -> {
task.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
task.setDescription("Runs Transport UDF tests on " + platform.getName());
task.setTestClassesDirs(testSourceSet.getOutput().getClassesDirs());
task.setClasspath(testClasspath);
task.useTestNG();
task.mustRunAfter(project.getTasks().named("test"));
});
}
示例13
@Override
public void apply(Project project) {
project.getPlugins().apply(NodePlugin.class);
var config = StaticSiteExtension.create(project);
var mergeSite =
project
.getTasks()
.register(
"mergeSite",
Copy.class,
t -> {
t.from("src");
t.into("build/site");
for (SiteProject site : config.getSites().get()) {
site.getProject()
.getPlugins()
.withType(
LifecycleBasePlugin.class,
unused ->
t.dependsOn(
site.getProject()
.getTasks()
.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)));
t.from(site.getBuildDir(), copy -> copy.into(site.getOutputSubDir()));
}
});
var assemble = project.getTasks().named("assemble");
assemble.configure(t -> t.dependsOn(mergeSite));
var yarn = project.getRootProject().getTasks().named("yarn");
var deployAlpha =
project
.getTasks()
.register(
"deployAlpha",
GcloudTask.class,
t -> {
t.dependsOn(assemble);
// TODO(choko): Remove this major hack - the command line has two --project flags
// and we're just lucky the later is used.
t.args(
config
.getAppEngineProject()
.map(
appEngineProject ->
ImmutableList.of(
"app", "deploy", "--project=" + appEngineProject)));
});
var deployProd =
project
.getTasks()
.register(
"deployProd",
NodeTask.class,
t -> {
t.dependsOn(yarn, assemble);
t.args(
config
.getFirebaseProject()
.map(
firebaseProject ->
ImmutableList.of(
"run", "firebase", "--project", firebaseProject, "deploy")));
});
project
.getTasks()
.register(
"preview",
NodeTask.class,
t -> {
t.dependsOn(yarn, assemble);
t.args("run", "superstatic", "--port=8080");
});
CurioGenericCiPlugin.addToReleaseBuild(project, deployProd);
project.afterEvaluate(
unused -> {
if (config.getAutoDeployAlpha().get()) {
CurioGenericCiPlugin.addToMasterBuild(project, deployAlpha);
}
});
}
示例14
private void createBinaryLifecycleTask(ClassDirectoryBinarySpecInternal binary, Project target) {
Task binaryLifecycleTask = target.task(binary.getNamingScheme().getLifecycleTaskName());
binaryLifecycleTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
binaryLifecycleTask.setDescription(String.format("Assembles %s.", binary));
binary.setBuildTask(binaryLifecycleTask);
}