From e96fcffdba2e2f3ef6834129c62f00e357f90647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Wed, 12 Feb 2025 06:02:08 +0100 Subject: [PATCH] Use Builder to evaluate the bsn and version of the project Currently if the version contains an evaluated expression this is used as is and maven complains about that. This now use the ProjectBuilder to evaluate the actual version and bsn. (cherry picked from commit 04710cfea029e0c628c9640adc28d9e3a11709f8) --- .../tycho/build/bnd/BndProjectMapping.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) 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 754efca3a0..a3449fe1cb 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 @@ -35,6 +35,7 @@ import org.sonatype.maven.polyglot.mapping.Mapping; import aQute.bnd.build.Project; +import aQute.bnd.build.ProjectBuilder; import aQute.bnd.build.Workspace; @Component(role = Mapping.class, hint = "bnd") @@ -106,16 +107,18 @@ protected void initModel(Model model, Reader artifactReader, Path artifactFile) if (g != null) { model.setGroupId(g); } - if (a == null) { - model.setArtifactId(project.getName()); - } else { - model.setArtifactId(a); - } - if (v == null) { - model.setVersion(project.getBundleVersion()); - } else { - model.setVersion(v); + if (a == null || v == null) { + try (ProjectBuilder builder = createBuilder(project)) { + if (a == null) { + a = builder.getBsn(); + } + if (v == null) { + v = builder.getVersion(); + } + } } + model.setArtifactId(a); + model.setVersion(v); Build build = getBuild(model); build.setDirectory(path(project.getTarget())); build.setOutputDirectory(path(project.getSrcOutput())); @@ -124,7 +127,6 @@ protected void initModel(Model model, Reader artifactReader, Path artifactFile) 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); bndPlugin.setVersion(TychoVersion.getTychoVersion()); @@ -165,6 +167,14 @@ protected void initModel(Model model, Reader artifactReader, Path artifactFile) } + private static ProjectBuilder createBuilder(Project project) throws Exception { + ProjectBuilder builder = new ProjectBuilder(project); + builder.setBase(project.getBase()); + builder.use(project); + builder.setFailOk(true); + return builder; + } + private static String path(File file) throws Exception { if (file != null) { return file.getAbsolutePath();