Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for maven and gradle plugins #5311

Merged
merged 2 commits into from Jul 7, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -44,6 +44,7 @@
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFileProperty;
Expand All @@ -60,6 +61,7 @@
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskInputFilePropertyBuilder;
import org.gradle.api.tasks.compile.AbstractCompile;
import org.gradle.work.NormalizeLineEndings;

/**
Expand Down Expand Up @@ -185,6 +187,7 @@ public MapProperty<String, Object> getProperties() {
private final ProjectLayout layout;
private final File buildFile;
private final ListProperty<CharSequence> instructions;
private final DirectoryProperty outputDirectory;

/**
* Create a BundleTaskExtension for the specified Jar task.
Expand All @@ -206,6 +209,7 @@ public BundleTaskExtension(org.gradle.api.tasks.bundling.Jar task) {
bnd = instructions.map(list -> Strings.join("\n", list));
classpath = objects.fileCollection();
allSource = objects.fileCollection();
outputDirectory = objects.directoryProperty();
SourceSet mainSourceSet = sourceSets(project).getByName(SourceSet.MAIN_SOURCE_SET_NAME);
setSourceSet(mainSourceSet);
classpath(mainSourceSet.getCompileClasspath());
Expand Down Expand Up @@ -331,6 +335,11 @@ public void setClasspath(Object path) {
public void setSourceSet(SourceSet sourceSet) {
getAllSource().setFrom(sourceSet.getAllSource()
.getSourceDirectories());
getOutputDirectory().value(getTask().getProject()
.getTasks()
.named(sourceSet.getCompileJavaTaskName(), AbstractCompile.class)
.flatMap(AbstractCompile::getDestinationDirectory));

jarLibraryElements(getTask(), sourceSet.getCompileClasspathConfigurationName());
}

Expand All @@ -342,6 +351,10 @@ File getBuildFile() {
return buildFile;
}

DirectoryProperty getOutputDirectory() {
return outputDirectory;
}

/**
* The default value for the Bundle-SymbolicName manifest header.
* <p>
Expand Down Expand Up @@ -388,9 +401,9 @@ private class BuildAction implements Action<Task> {
public void execute(Task t) {
try {
File projectDir = unwrapFile(getLayout().getProjectDirectory());
File buildDir = unwrapFile(getLayout().getBuildDirectory());
File outputDir = unwrapFile(getOutputDirectory());
File buildFile = getBuildFile();
FileCollection sourcepath = getAllSource().filter(file -> file.exists());
FileCollection sourcepath = getAllSource().filter(File::exists);
Optional<org.gradle.api.java.archives.Manifest> taskManifest = Optional
.ofNullable(getTask().getManifest());
// create Builder
Expand Down Expand Up @@ -436,7 +449,7 @@ public void execute(Task t) {
}
// this will cause project.dir property to be set
builder.setProperties(temporaryBndFile, projectDir);
builder.setProperty("project.output", buildDir.getCanonicalPath());
builder.setProperty("project.output", outputDir.getCanonicalPath());
// If no bundle to be built, we have nothing to do
if (builder.is(Constants.NOBUNDLES)) {
return;
Expand Down
Expand Up @@ -57,7 +57,7 @@ class TestBundlePlugin extends Specification {
jartask_manifest.getValue("Bundle-Name") == "test.bnd.gradle:${testProject}"
jartask_manifest.getValue("Project-Name") == "${testProject}"
new File(jartask_manifest.getValue("Project-Dir")).canonicalFile == testProjectDir
new File(jartask_manifest.getValue("Project-Output")).canonicalFile == testProjectBuildDir
new File(jartask_manifest.getValue("Project-Output")).canonicalFile == new File(testProjectBuildDir, "classes/java/main").canonicalFile
jartask_manifest.getValue("Project-Sourcepath")
jartask_manifest.getValue("Project-Buildpath")
jartask_manifest.getValue("Bundle-ClassPath") =~ /commons-lang-2\.6\.jar/
Expand Down Expand Up @@ -95,7 +95,7 @@ class TestBundlePlugin extends Specification {
bundletask_manifest.getValue("Bundle-Name") == "test.bnd.gradle:${testProject}-bundle"
bundletask_manifest.getValue("Project-Name") == "${testProject}"
new File(bundletask_manifest.getValue("Project-Dir")).canonicalFile == testProjectDir
new File(bundletask_manifest.getValue("Project-Output")).canonicalFile == testProjectBuildDir
new File(bundletask_manifest.getValue("Project-Output")).canonicalFile == new File(testProjectBuildDir, "classes/java/test").canonicalFile
bundletask_manifest.getValue("Project-Sourcepath")
bundletask_manifest.getValue("Project-Buildpath")
bundletask_manifest.getValue("Bundle-ClassPath") =~ /commons-lang-2\.6\.jar/
Expand Down Expand Up @@ -207,7 +207,7 @@ class TestBundlePlugin extends Specification {
jartask_manifest.getValue("Bundle-Name") == "test.bnd.gradle:${testProject}"
jartask_manifest.getValue("Project-Name") == "${testProject}"
new File(jartask_manifest.getValue("Project-Dir")).canonicalFile == testProjectDir
new File(jartask_manifest.getValue("Project-Output")).canonicalFile == testProjectBuildDir
new File(jartask_manifest.getValue("Project-Output")).canonicalFile == new File(testProjectBuildDir, "classes/java/main").canonicalFile
jartask_manifest.getValue("Project-Sourcepath")
jartask_manifest.getValue("Project-Buildpath")
jartask_manifest.getValue("Bundle-ClassPath") =~ /commons-lang-2\.6\.jar/
Expand Down Expand Up @@ -244,7 +244,7 @@ class TestBundlePlugin extends Specification {
bundletask_manifest.getValue("Bundle-Name") == "test.bnd.gradle:${testProject}-bundle"
bundletask_manifest.getValue("Project-Name") == "${testProject}"
new File(bundletask_manifest.getValue("Project-Dir")).canonicalFile == testProjectDir
new File(bundletask_manifest.getValue("Project-Output")).canonicalFile == testProjectBuildDir
new File(bundletask_manifest.getValue("Project-Output")).canonicalFile == new File(testProjectBuildDir, "classes/java/test").canonicalFile
bundletask_manifest.getValue("Project-Sourcepath")
bundletask_manifest.getValue("Project-Buildpath")
bundletask_manifest.getValue("Bundle-ClassPath") =~ /commons-lang-2\.6\.jar/
Expand Down Expand Up @@ -316,7 +316,7 @@ class TestBundlePlugin extends Specification {
jartask_manifest.getValue("Bundle-Name") == "test.bnd.gradle:${testProject}"
jartask_manifest.getValue("Project-Name") == "${testProject}"
new File(jartask_manifest.getValue("Project-Dir")).canonicalFile == testProjectDir
new File(jartask_manifest.getValue("Project-Output")).canonicalFile == testProjectBuildDir
new File(jartask_manifest.getValue("Project-Output")).canonicalFile == new File(testProjectBuildDir, "classes/java/main").canonicalFile
jartask_manifest.getValue("Project-Sourcepath")
jartask_manifest.getValue("Project-Buildpath")
jartask_manifest.getValue("Gradle-Project-Prop") == "prop.project"
Expand Down Expand Up @@ -353,7 +353,7 @@ class TestBundlePlugin extends Specification {
bundletask_manifest.getValue("Bundle-Name") == "test.bnd.gradle:${testProject}-overridden"
bundletask_manifest.getValue("Project-Name") == "${testProject}"
new File(bundletask_manifest.getValue("Project-Dir")).canonicalFile == testProjectDir
new File(bundletask_manifest.getValue("Project-Output")).canonicalFile == testProjectBuildDir
new File(bundletask_manifest.getValue("Project-Output")).canonicalFile == new File(testProjectBuildDir, "classes/java/test").canonicalFile
bundletask_manifest.getValue("Project-Sourcepath")
bundletask_manifest.getValue("Project-Buildpath")
bundletask_manifest.getValue("Here") == testProjectDir.absolutePath.replace(File.separatorChar, (char)'/')
Expand Down