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.
  • Loading branch information
laeubi committed Feb 12, 2025
1 parent 6d105c6 commit 850801f
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import org.sonatype.maven.polyglot.mapping.Mapping;

import aQute.bnd.build.Project;
import aQute.bnd.build.ProjectBuilder;
import aQute.bnd.build.Workspace;
import aQute.bnd.osgi.Analyzer;

@Component(role = Mapping.class, hint = "bnd")
public class BndProjectMapping extends AbstractTychoMapping {
Expand Down Expand Up @@ -106,16 +108,19 @@ 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) {
String version = builder.getVersion();
v = Analyzer.cleanupVersion(version);
}
}
}
model.setArtifactId(a);
model.setVersion(v);
Build build = getBuild(model);
build.setDirectory(path(project.getTarget()));
build.setOutputDirectory(path(project.getSrcOutput()));
Expand Down Expand Up @@ -165,6 +170,10 @@ protected void initModel(Model model, Reader artifactReader, Path artifactFile)

}

private static ProjectBuilder createBuilder(Project project) throws Exception {
return project.getBuilder(null);
}

private static String path(File file) throws Exception {
if (file != null) {
return file.getAbsolutePath();
Expand Down

0 comments on commit 850801f

Please sign in to comment.