Skip to content

Commit

Permalink
Use Builder to evaluate the bsn and version of the project
Browse files Browse the repository at this point in the history
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 04710cf)
  • Loading branch information
laeubi committed Feb 12, 2025
1 parent 11b3f65 commit e96fcff
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()));
Expand All @@ -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());
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e96fcff

Please sign in to comment.