Skip to content

Commit

Permalink
Merge pull request #5341 from bjhargrave/gradle-task-group
Browse files Browse the repository at this point in the history
Gradle set task group in task type constructor
  • Loading branch information
bjhargrave committed Aug 18, 2022
2 parents a878029 + 91c2be0 commit 836a39a
Show file tree
Hide file tree
Showing 20 changed files with 16 additions and 29 deletions.
Expand Up @@ -49,6 +49,7 @@
import aQute.bnd.version.Version;
import aQute.lib.io.IO;
import aQute.lib.strings.Strings;
import org.gradle.language.base.plugins.LifecycleBasePlugin;

/**
* Baseline task type for Gradle.
Expand Down Expand Up @@ -216,6 +217,7 @@ public RegularFileProperty getReportFile() {
*/
public Baseline() {
super();
setGroup(LifecycleBasePlugin.BUILD_GROUP);
org.gradle.api.Project project = getProject();
this.layout = project.getLayout();
this.providers = project.getProviders();
Expand Down
Expand Up @@ -98,7 +98,6 @@ public void apply(Project project) {

TaskProvider<Baseline> baselineTask = tasks.register("baseline", Baseline.class, t -> {
t.setDescription("Baseline the project bundle.");
t.setGroup(LifecycleBasePlugin.BUILD_GROUP);
t.setBundle(jar);
t.setBaseline(baseline);
});
Expand Down
Expand Up @@ -672,7 +672,6 @@ public void execute(Task tt) {
TaskProvider<TestOSGi> testOSGi = tasks.register("testOSGi", TestOSGi.class, t -> {
t.setDescription(
"Runs the OSGi JUnit tests by launching a framework and running the tests in the launched framework.");
t.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
t.setEnabled(
!bndProject.is(Constants.NOJUNITOSGI) && !bndProject.getUnprocessedProperty(Constants.TESTCASES, "")
.isEmpty());
Expand Down Expand Up @@ -737,7 +736,6 @@ public void execute(Task tt) {
List<TaskProvider<Export>> exportTasks = MapStream.of(bndruns)
.mapToObj((name, runFile) -> tasks.register("export.".concat(name), Export.class, t -> {
t.setDescription(String.format("Export the %s file.", runFile.getName()));
t.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
t.dependsOn(assemble);
t.getBndrun()
.fileValue(runFile);
Expand All @@ -756,7 +754,6 @@ public void execute(Task tt) {
.mapToObj((name, runFile) -> tasks.register("runbundles.".concat(name), Export.class, t -> {
t.setDescription(
String.format("Create a distribution of the runbundles in the %s file.", runFile.getName()));
t.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
t.dependsOn(assemble);
t.getBndrun()
.fileValue(runFile);
Expand All @@ -774,7 +771,6 @@ public void execute(Task tt) {
List<TaskProvider<Resolve>> resolveTasks = MapStream.of(bndruns)
.mapToObj((name, runFile) -> tasks.register("resolve.".concat(name), Resolve.class, t -> {
t.setDescription(String.format("Resolve the runbundles required for %s file.", runFile.getName()));
t.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
t.dependsOn(assemble);
t.getBndrun()
.fileValue(runFile);
Expand All @@ -783,14 +779,13 @@ public void execute(Task tt) {

TaskProvider<Task> resolve = tasks.register("resolve", t -> {
t.setDescription("Resolve the runbundles required for each of the bndrun files.");
t.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
t.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
t.dependsOn(resolveTasks);
});

bndruns.forEach((name, runFile) -> {
tasks.register("run.".concat(name), Bndrun.class, t -> {
t.setDescription(String.format("Run the bndrun file %s.", runFile.getName()));
t.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
t.dependsOn(assemble);
t.getBndrun()
.fileValue(runFile);
Expand All @@ -801,7 +796,6 @@ public void execute(Task tt) {
tasks.register("testrun.".concat(name), TestOSGi.class, t -> {
t.setDescription(
String.format("Runs the OSGi JUnit tests in the bndrun file %s.", runFile.getName()));
t.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
t.dependsOn(assemble);
t.getBndrun()
.fileValue(runFile);
Expand Down
Expand Up @@ -13,6 +13,7 @@
import org.gradle.api.GradleException;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.publish.plugins.PublishingPlugin;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.UntrackedTask;
Expand Down Expand Up @@ -81,6 +82,7 @@ public Property<JavaLauncher> getJavaLauncher() {
*/
public Bndrun() {
super();
setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
org.gradle.api.Project project = getProject();
ObjectFactory objects = project.getObjects();
javaLauncher = objects.property(JavaLauncher.class)
Expand Down
@@ -1,6 +1,7 @@
package aQute.bnd.gradle;

import org.gradle.api.tasks.bundling.Jar;
import org.gradle.language.base.plugins.LifecycleBasePlugin;

/**
* Bundle task type for Gradle.
Expand Down Expand Up @@ -34,6 +35,7 @@ public class Bundle extends Jar {
@SuppressWarnings("deprecation")
public Bundle() {
super();
setGroup(LifecycleBasePlugin.BUILD_GROUP);
BundleTaskExtension extension = getExtensions().create(BundleTaskExtension.NAME, BundleTaskExtension.class,
this);
getConvention().getPlugins()
Expand Down
Expand Up @@ -19,6 +19,7 @@
import org.gradle.api.model.ReplacedBy;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.publish.plugins.PublishingPlugin;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputDirectory;
Expand Down Expand Up @@ -146,6 +147,7 @@ public Property<String> getExporter() {
*/
public Export() {
super();
setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
org.gradle.api.Project project = getProject();
ObjectFactory objects = project.getObjects();
exporter = objects.property(String.class)
Expand Down
Expand Up @@ -20,6 +20,7 @@
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.publish.plugins.PublishingPlugin;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
Expand Down Expand Up @@ -203,6 +204,7 @@ public RegularFileProperty getIndexCompressed() {
*/
public Index() {
super();
setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
org.gradle.api.Project project = getProject();
ObjectFactory objects = project.getObjects();
indexName = objects.property(String.class)
Expand Down
Expand Up @@ -9,6 +9,7 @@

import org.gradle.api.GradleException;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputFile;
Expand Down Expand Up @@ -203,6 +204,7 @@ public void setWriteOnChanges(boolean writeOnChanges) {
*/
public Resolve() {
super();
setGroup(JavaBasePlugin.VERIFICATION_GROUP);
org.gradle.api.Project project = getProject();
outputBndrun = project.getObjects()
.fileProperty()
Expand Down
Expand Up @@ -14,6 +14,7 @@
import org.gradle.api.file.Directory;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
Expand Down Expand Up @@ -131,6 +132,7 @@ public Property<JavaLauncher> getJavaLauncher() {
*/
public TestOSGi() {
super();
setGroup(JavaBasePlugin.VERIFICATION_GROUP);
org.gradle.api.Project project = getProject();
ObjectFactory objects = project.getObjects();
Provider<Directory> testResultsDir = testResultsDir(project);
Expand Down
Expand Up @@ -43,7 +43,6 @@ baseline {

task baselineDiffpackages(type: Baseline) {
description = 'Baseline diffpackages'
group = 'build'
bundle = jar
baseline = configurations.baseline
diffpackages = ['!doubler']
Expand All @@ -53,7 +52,6 @@ task baselineDiffpackages(type: Baseline) {

task baselineDiffignore(type: Baseline) {
description = 'Baseline diffignore'
group = 'build'
bundle jar
baseline configurations.baseline
diffignore 'foo.txt'
Expand All @@ -63,7 +61,6 @@ task baselineDiffignore(type: Baseline) {

task baselineSelf(type: Baseline) {
description = 'Baseline Self'
group = 'build'
bundle jar
baseline jar.archiveFile
ignoreFailures = false
Expand Down
Expand Up @@ -37,7 +37,6 @@ jar {

task bundle(type: Bundle) {
description = 'Bundle'
group = 'build'
from sourceSets.test.output
archiveClassifier = 'bundle'
bundle {
Expand Down
Expand Up @@ -32,7 +32,6 @@ def jarTask = tasks.named('jar', Jar) {

task bundle(type: Bundle) {
description = 'Bundle'
group = 'build'
from jarTask.map { zipTree(it.archiveFile) }
archiveClassifier = 'bundle'
manifest {
Expand Down
Expand Up @@ -27,22 +27,19 @@ ext {

task export(type: Export) {
description = "Export ${name}.bndrun"
group = 'export'
bndrun = layout.projectDirectory.file("${name}.bndrun")
bundles = configurations.bundles
}

task exporter(type: Export) {
description = "Exporter for ${name}.bndrun"
group = 'export'
bndrun = objects.fileProperty().value(layout.projectDirectory.file("${name}.bndrun"))
bundles = configurations.bundles
exporter = 'bnd.runbundles'
}

task runbundles(type: Export) {
description = "Export ${name}.bndrun"
group = 'export'
bndrun = file("${name}.bndrun")
exporter = 'bnd.runbundles'
bundles = configurations.bundles
Expand Down
Expand Up @@ -37,7 +37,6 @@ jar {

task bundle(type: Bundle) {
description = 'Bundle'
group = 'build'
from sourceSets.test.output
archiveBaseName = "${project.archivesBaseName}_bundle"
bundle {
Expand Down Expand Up @@ -69,7 +68,6 @@ artifacts {

task indexer(type: Index) {
description = 'Indexer'
group = 'build'
repositoryName = project.name
bundles fileTree(destinationDirectory.dir(libsDirName)) {
include '**/*.jar'
Expand All @@ -89,7 +87,6 @@ task copybundles(type: Copy) {

task indexer2(type: Index) {
description = 'Indexer'
group = 'build'
indexName = 'index2.xml'
gzip = true
destinationDirectory = indexDir
Expand Down
Expand Up @@ -27,15 +27,13 @@ ext {

task create(type: Resolve) {
description = "Resolve ${name}.bndrun"
group = 'export'
bndrun = file("${name}.bndrun")
outputBndrun = file("${buildDir}/${name}.bndrun")
bundles = configurations.bundles
}

task same(type: Resolve) {
description = "Resolve ${name}.bndrun"
group = 'export'
bndrun = file("${name}.bndrun")
failOnChanges = true
bundles = configurations.bundles
Expand All @@ -44,15 +42,13 @@ task same(type: Resolve) {

task changefail(type: Resolve) {
description = "Resolve ${name}.bndrun"
group = 'export'
bndrun = file("${name}.bndrun")
failOnChanges = true
bundles = configurations.bundles
}

task resolvefail(type: Resolve) {
description = "Resolve ${name}.bndrun"
group = 'export'
bndrun = file("${name}.bndrun")
bundles = configurations.bundles
}
Expand Up @@ -21,7 +21,6 @@ dependencies {

task run(type: Bndrun) {
description = "OSGi Bndrun ${name}.bndrun"
group = 'export'
inputs.files jar
bndrun = file("${name}.bndrun")
javaLauncher = javaToolchains.launcherFor {
Expand Down
Expand Up @@ -26,7 +26,6 @@ dependencies {

task testosgi(type: TestOSGi) {
description = "OSGi Test ${name}.bndrun"
group = 'test'
inputs.files jar
bndrun = file("${name}.bndrun")
bundles configurations.framework
Expand Down
Expand Up @@ -27,7 +27,6 @@ dependencies {

task testosgi(type: TestOSGi) {
description = "OSGi Test ${name}.bndrun"
group = 'test'
inputs.files jar
bndrun = file("${name}.bndrun")
bundles = [
Expand Down
Expand Up @@ -23,15 +23,13 @@ dependencies {

task testosgiIgnoreFail(type: TestOSGi) {
description = "OSGi Test ${name}.bndrun"
group = 'test'
inputs.files jar
bndrun = file("${name}.bndrun")
ignoreFailures = true
}

task testosgiFail(type: TestOSGi) {
description = "OSGi Test ${name}.bndrun"
group = 'test'
inputs.files jar
bndrun = file("${name}.bndrun")
ignoreFailures = false
Expand Down
2 changes: 1 addition & 1 deletion maven/bnd-plugin-parent/pom.xml
Expand Up @@ -451,7 +451,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.7</version>
<version>1.3.0</version>
<configuration>
<flattenMode>oss</flattenMode>
</configuration>
Expand Down

0 comments on commit 836a39a

Please sign in to comment.