Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Add support for Gradle 8 #42

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ group = "dev.galasa"

// Note: The following line is changed by the set-version.sh script.
// It is also read by other build scrips as required.
version = "0.33.0"
version = "0.36.0"

signing {
def signingKeyId = findProperty("signingKeyId")
Expand Down
8 changes: 4 additions & 4 deletions dev.galasa.gradle.impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "dev.galasa"
version = "0.33.0"
version = "0.36.0"

repositories {
mavenLocal()
Expand Down Expand Up @@ -33,9 +33,9 @@ tasks.withType(Javadoc) {
}

task gitHash(dependsOn : 'classes') {
def dir = file("${buildDir}/githash")
def meta = file("${buildDir}/githash/META-INF")
def result = file("${buildDir}/githash/META-INF/git.hash")
def dir = layout.buildDirectory.dir("githash").get().asFile
def meta = layout.buildDirectory.dir("githash/META-INF").get().asFile
def result = layout.buildDirectory.file("githash/META-INF/git.hash").get().asFile

outputs.dir meta
tasks.jar.dependsOn('gitHash')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package dev.galasa.gradle.common;

import org.gradle.util.GradleVersion;

public class GradleCompatibilityService implements ICompatibilityService {

public static final GradleVersion CURRENT_GRADLE_VERSION = GradleVersion.current();

public boolean isCurrentVersionLaterThanGradle8() {
return CURRENT_GRADLE_VERSION.compareTo(GradleVersion.version("8.0")) >= 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package dev.galasa.gradle.common;

public interface ICompatibilityService {
boolean isCurrentVersionLaterThanGradle8();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.gradle.api.DefaultTask;
import org.gradle.api.Task;
import org.gradle.api.file.Directory;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskAction;
Expand Down Expand Up @@ -57,17 +58,15 @@ public void apply() {
Jar jarTask = (Jar) getProject().getTasks().getByName("jar");
jarTask.getDependsOn().add(this);

//*** Create the directories so Gradle does not moan
File dirGenTestCatalog = new File(getProject().getBuildDir(),"hashes");
File dirGenTestCatalogMeta = new File(dirGenTestCatalog,"META-INF");
//*** dont need to create the file here, just indicate where it will be on the outputs
this.gitHash = new File(dirGenTestCatalogMeta,"git.hash");
//*** Create the directories so Gradle does not moan)
Directory dirHashes = getProject().getLayout().getBuildDirectory().dir("hashes").get();
Directory dirHashesMeta = dirHashes.dir("META-INF");

//*** Tell the JAR task we want to it to include the meta-inf and json file
jarTask.from(dirGenTestCatalog);
this.gitHash = dirHashesMeta.file("git.hash").getAsFile();

//*** Tell the JAR task we want to it to include the meta-inf and json file
jarTask.from(dirHashes);
//*** Mark the meta-inf file as output for caching purposes
getOutputs().dir(dirGenTestCatalog);
getOutputs().dir(dirHashes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
Expand All @@ -31,7 +30,9 @@
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.ResolvedDependency;
import org.gradle.api.file.RegularFile;
import org.gradle.api.logging.Logger;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.TaskAction;

public class ObrBuildTask extends DefaultTask {
Expand Down Expand Up @@ -200,8 +201,8 @@ private void processObr(DataModelHelper obrDataModelHelper, RepositoryImpl newRe

public void apply() {
// Run during apply phase, need to decide on the output file name
Path buildDirectory = Paths.get(project.getBuildDir().toURI());
this.pathObr = buildDirectory.resolve("galasa.obr");
Provider<RegularFile> obrFile = project.getLayout().getBuildDirectory().file("galasa.obr");
this.pathObr = obrFile.get().getAsFile().toPath();
getOutputs().file(pathObr);

ConfigurationContainer configurations = project.getConfigurations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,34 @@
import javax.inject.Inject;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.component.AdhocComponentWithVariants;
import org.gradle.api.component.SoftwareComponentFactory;
import org.gradle.api.internal.artifacts.ArtifactAttributes;
import org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact;
import org.gradle.api.internal.file.FileResolver;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.api.internal.tasks.TaskDependencyFactory;
import org.gradle.api.provider.Provider;

import dev.galasa.gradle.common.GradleCompatibilityService;
import dev.galasa.gradle.common.ICompatibilityService;

/**
* Generate an OBR
*/
public class ObrPlugin implements Plugin<Project> {

private final SoftwareComponentFactory softwareComponentFactory;
private final TaskDependencyFactory taskDependencyFactory;
private final ICompatibilityService compatibilityService = new GradleCompatibilityService();

@Inject
public ObrPlugin(SoftwareComponentFactory softwareComponentFactory) {
public ObrPlugin(SoftwareComponentFactory softwareComponentFactory, TaskDependencyFactory taskDependencyFactory) {
this.softwareComponentFactory = softwareComponentFactory;
this.taskDependencyFactory = taskDependencyFactory;
}

public void apply(Project project) {
Expand Down Expand Up @@ -58,11 +67,24 @@ private void createObrBuildTask(Project project) {
Provider<ObrBuildTask> provider = project.getTasks().register("genobr", ObrBuildTask.class, obrTask -> {
obrTask.apply();
});

// Create the Publish Artifact that the task will be creating and add it the
// configuration outbound list
LazyPublishArtifact artifact = new LazyPublishArtifact(provider);
project.getConfigurations().getByName("galasagenobr").getOutgoing().artifact(artifact);
try {
LazyPublishArtifact artifact;
if (compatibilityService.isCurrentVersionLaterThanGradle8()) {
// Create the artifact using the Gradle 8.x constructor
artifact = LazyPublishArtifact.class
.getConstructor(Provider.class, FileResolver.class, TaskDependencyFactory.class)
.newInstance(provider, ((ProjectInternal) project).getFileResolver(), taskDependencyFactory);
} else {
// Create the artifact using the Gradle 6.x/7.x constructor
artifact = LazyPublishArtifact.class.getConstructor(Provider.class).newInstance(provider);
}
project.getConfigurations().getByName("galasagenobr").getOutgoing().artifact(artifact);
} catch (ReflectiveOperationException err) {
throw new IllegalArgumentException("Incompatible LazyPublishArtifact constructor for Gradle version " + project.getGradle().getGradleVersion());
}
}

private void createSoftwareComponents(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.ResolvedDependency;
import org.gradle.api.file.RegularFile;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.TaskAction;

import com.google.gson.Gson;
Expand Down Expand Up @@ -201,7 +203,8 @@ private void processBundle(ResolvedDependency dependency) throws TestCatalogExce

public void apply() {
// Run during apply phase, need to decide on the output file name
this.testCatalog = new File(getProject().getBuildDir(),"testcatalog.json");
Provider<RegularFile> testCatalogFile = getProject().getLayout().getBuildDirectory().file("testcatalog.json");
this.testCatalog = testCatalogFile.get().getAsFile();
getOutputs().file(testCatalog);

ConfigurationContainer configurations = getProject().getConfigurations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,28 @@
import org.gradle.api.component.SoftwareComponentFactory;
import org.gradle.api.internal.artifacts.ArtifactAttributes;
import org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact;
import org.gradle.api.internal.file.FileResolver;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.api.internal.tasks.TaskDependencyFactory;
import org.gradle.api.provider.Provider;
import org.gradle.api.publish.plugins.PublishingPlugin;

import dev.galasa.gradle.common.GradleCompatibilityService;
import dev.galasa.gradle.common.ICompatibilityService;

/**
* Build testcatalog artifact
*/
public class TestCatalogPlugin implements Plugin<Project> {

private final SoftwareComponentFactory softwareComponentFactory;
private final TaskDependencyFactory taskDependencyFactory;
private final ICompatibilityService compatibilityService = new GradleCompatibilityService();

@Inject
public TestCatalogPlugin(SoftwareComponentFactory softwareComponentFactory) {
public TestCatalogPlugin(SoftwareComponentFactory softwareComponentFactory, TaskDependencyFactory taskDependencyFactory) {
this.softwareComponentFactory = softwareComponentFactory;
this.taskDependencyFactory = taskDependencyFactory;
}

public void apply(Project project) {
Expand Down Expand Up @@ -65,8 +74,21 @@ private void createTestcatBuildTask(Project project) {

// Create the Publish Artifact that the task will be creating and add it the
// configuration outbound list
LazyPublishArtifact artifact = new LazyPublishArtifact(provider);
project.getConfigurations().getByName("galasamergetestcat").getOutgoing().artifact(artifact);
try {
LazyPublishArtifact artifact;
if (compatibilityService.isCurrentVersionLaterThanGradle8()) {
// Create the artifact using the Gradle 8.x constructor
artifact = LazyPublishArtifact.class
.getConstructor(Provider.class, FileResolver.class, TaskDependencyFactory.class)
.newInstance(provider, ((ProjectInternal) project).getFileResolver(), taskDependencyFactory);
} else {
// Create the artifact using the Gradle 6.x/7.x constructor
artifact = LazyPublishArtifact.class.getConstructor(Provider.class).newInstance(provider);
}
project.getConfigurations().getByName("galasamergetestcat").getOutgoing().artifact(artifact);
} catch (ReflectiveOperationException err) {
throw new IllegalArgumentException("Incompatible LazyPublishArtifact constructor for Gradle version " + project.getGradle().getGradleVersion());
}
}

private void createTestcatDeployTask(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.gradle.api.DefaultTask;
import org.gradle.api.Task;
import org.gradle.api.file.Directory;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskAction;
Expand Down Expand Up @@ -252,10 +253,10 @@ public void apply() {
jarTask.getDependsOn().add(this);

//*** Create the directories so Gradle does not moan
File dirGenTestCatalog = new File(getProject().getBuildDir(),"gentestcatalog");
File dirGenTestCatalogMeta = new File(dirGenTestCatalog,"META-INF");
Directory dirGenTestCatalog = getProject().getLayout().getBuildDirectory().dir("gentestcatalog").get();
Directory dirGenTestCatalogMeta = dirGenTestCatalog.dir("META-INF");
//*** dont need to create the file here, just indicate where it will be on the outputs
this.testCatalog = new File(dirGenTestCatalogMeta,"testcatalog.json");
this.testCatalog = dirGenTestCatalogMeta.file("testcatalog.json").getAsFile();

//*** Tell the JAR task we want to it to include the meta-inf and json file
jarTask.from(dirGenTestCatalog);
Expand Down
2 changes: 1 addition & 1 deletion dev.galasa.plugin.common.impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "dev.galasa"
version = "0.33.0"
version = "0.36.0"

repositories {
maven {
Expand Down
2 changes: 1 addition & 1 deletion dev.galasa.plugin.common.test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "dev.galasa"
version = "0.33.0"
version = "0.36.0"

repositories {
maven {
Expand Down
8 changes: 4 additions & 4 deletions dev.galasa.plugin.common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "dev.galasa"
version = "0.33.0"
version = "0.36.0"

repositories {
maven {
Expand All @@ -31,9 +31,9 @@ tasks.withType(Javadoc) {
}

task gitHash(dependsOn : 'classes') {
def dir = file("${buildDir}/githash")
def meta = file("${buildDir}/githash/META-INF")
def result = file("${buildDir}/githash/META-INF/git.hash")
def dir = layout.buildDirectory.dir("githash").get().asFile
def meta = layout.buildDirectory.dir("githash/META-INF").get().asFile
def result = layout.buildDirectory.file("githash/META-INF/git.hash").get().asFile

outputs.dir meta
tasks.jar.dependsOn('gitHash')
Expand Down
Loading