From 929a089d2a73250458841c3f263be663311309e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 1 Feb 2025 15:36:35 +0100 Subject: [PATCH] Propagate configured folders from bnd to maven model the user can define custom folders for output and sources, these are now propagated from the bnd config to the maven model. (cherry picked from commit 9330061417e71eaddd4f7f99c8165cf6839d5b16) --- .../java/org/eclipse/tycho/TychoConstants.java | 1 + .../maven/BndMavenLifecycleParticipant.java | 2 ++ .../eclipse/tycho/bnd/mojos/BndCleanMojo.java | 17 +++++++++++++++++ .../eclipse/tycho/bnd/mojos/BndInitMojo.java | 5 ++--- .../tycho/build/bnd/BndProjectMapping.java | 18 +++++++++++++++++- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java b/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java index 5c35162b60..d4afa345dc 100644 --- a/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java +++ b/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java @@ -149,4 +149,5 @@ public interface TychoConstants { String SUFFIX_SNAPSHOT = "-SNAPSHOT"; String PROP_DOWNLOAD_CHECKSUM_PREFIX = IArtifactDescriptor.DOWNLOAD_CHECKSUM + "."; + public String DRIVER_NAME = "tycho-maven-build"; } diff --git a/tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/maven/BndMavenLifecycleParticipant.java b/tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/maven/BndMavenLifecycleParticipant.java index e7bfd7084d..c4eaf26971 100644 --- a/tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/maven/BndMavenLifecycleParticipant.java +++ b/tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/maven/BndMavenLifecycleParticipant.java @@ -34,6 +34,7 @@ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; +import org.eclipse.tycho.TychoConstants; import org.eclipse.tycho.core.bnd.BndPluginManager; import aQute.bnd.build.Project; @@ -70,6 +71,7 @@ public class BndMavenLifecycleParticipant extends AbstractMavenLifecycleParticip @Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { + Workspace.setDriver(TychoConstants.DRIVER_NAME); Map bndProjects = getProjects(session); Map manifestFirstProjects = getManifestFirstProjects(session, bndProjects.keySet()); Map bndWorkspaceProjects = new HashMap<>(); diff --git a/tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/mojos/BndCleanMojo.java b/tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/mojos/BndCleanMojo.java index 51a39a4a23..c51eb0c4c0 100644 --- a/tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/mojos/BndCleanMojo.java +++ b/tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/mojos/BndCleanMojo.java @@ -12,8 +12,11 @@ *******************************************************************************/ package org.eclipse.tycho.bnd.mojos; +import java.io.File; + import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import aQute.bnd.build.Project; @@ -21,8 +24,22 @@ @Mojo(name = "clean", defaultPhase = LifecyclePhase.CLEAN, requiresDependencyResolution = ResolutionScope.NONE, threadSafe = true) public class BndCleanMojo extends AbstractBndProjectMojo { + /** + * The filename of the tycho generated POM file. + */ + @Parameter(defaultValue = ".tycho-consumer-pom.xml", property = "tycho.bnd.consumerpom.file") + protected String tychoPomFilename; + + /** + * The directory where the tycho generated POM file will be written to. + */ + @Parameter(defaultValue = "${project.basedir}", property = "tycho.bnd.consumerpom.directory") + protected File outputDirectory; + @Override protected void execute(Project project) throws Exception { + File consumerPom = new File(outputDirectory, tychoPomFilename); + consumerPom.delete(); project.clean(); } diff --git a/tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/mojos/BndInitMojo.java b/tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/mojos/BndInitMojo.java index 73a74a3519..b3217c8604 100644 --- a/tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/mojos/BndInitMojo.java +++ b/tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/mojos/BndInitMojo.java @@ -33,8 +33,6 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import aQute.bnd.build.Workspace; - @Mojo(name = "initialize", defaultPhase = LifecyclePhase.INITIALIZE) public class BndInitMojo extends AbstractMojo { @@ -76,7 +74,6 @@ public class BndInitMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { - Workspace.setDriver("tycho-maven-build"); fixupPolyglot(); writeConsumerPom(); } @@ -91,6 +88,7 @@ private void writeConsumerPom() throws MojoExecutionException { } catch (IOException e) { throw new MojoExecutionException("reading the model failed!", e); } + projectModel.setBuild(null); projectModel.setVersion(mavenProject.getVersion()); projectModel.setGroupId(mavenProject.getGroupId()); projectModel.setParent(null); @@ -131,6 +129,7 @@ public boolean accept(File pathname) { File moved = new File(file.getParentFile(), ".polyglot.xml"); if (file.renameTo(moved)) { mavenProject.setFile(moved); + moved.deleteOnExit(); } } } diff --git a/tycho-build/src/main/java/org/eclipse/tycho/build/bnd/BndProjectMapping.java b/tycho-build/src/main/java/org/eclipse/tycho/build/bnd/BndProjectMapping.java index 25ca5462fc..ae4c8de2b7 100644 --- a/tycho-build/src/main/java/org/eclipse/tycho/build/bnd/BndProjectMapping.java +++ b/tycho-build/src/main/java/org/eclipse/tycho/build/bnd/BndProjectMapping.java @@ -19,6 +19,7 @@ import java.util.Map; import org.apache.maven.lifecycle.Lifecycle; +import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.codehaus.plexus.component.annotations.Component; @@ -79,6 +80,7 @@ public String getFlavour() { @Override protected void initModel(Model model, Reader artifactReader, Path artifactFile) throws IOException { try { + Workspace.setDriver(TychoConstants.DRIVER_NAME); Project project = Workspace.getProject(artifactFile.getParent().toFile()); if (project.getSubProjects().isEmpty()) { model.setPackaging(getPackaging()); @@ -101,7 +103,14 @@ protected void initModel(Model model, Reader artifactReader, Path artifactFile) } else { model.setVersion(v); } - + Build build = getBuild(model); + build.setDirectory(path(project.getTarget())); + build.setOutputDirectory(path(project.getSrcOutput())); + build.setTestOutputDirectory(path(project.getTestOutput())); + @SuppressWarnings("deprecation") + File src = project.getSrc(); + build.setSourceDirectory(path(src)); + build.setTestSourceDirectory(path(project.getTestSrc())); model.setVersion(project.getBundleVersion()); Plugin bndPlugin = getPlugin(model, TYCHO_GROUP_ID, TYCHO_BND_PLUGIN); bndPlugin.setExtensions(true); @@ -142,4 +151,11 @@ protected void initModel(Model model, Reader artifactReader, Path artifactFile) } + private static String path(File file) throws Exception { + if (file != null) { + return file.getAbsolutePath(); + } + return null; + } + }