Skip to content

Commit

Permalink
Support custom properties from bnd files and enhance the documentation
Browse files Browse the repository at this point in the history
This now makes the bnd.bnd file available as plain properties to the
build so one is able to define the magic pomless properties to further
customize the pomless build.

Additionally the workspace cnf folder is now searched for a pom.xml file
as the parent of the aggregator to allow further customization and the
documentation is enhanced to describe these options.

(cherry picked from commit 29904bc)
  • Loading branch information
laeubi authored and eclipse-tycho-bot committed Feb 2, 2025
1 parent 6c0287c commit f7cef38
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/site/markdown/BndBuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ In contrast to a traditional maven build where each module has to contain a `pom
</extensions>
```

- create a file called `maven.config` in the `.mvn` folder with the following content (adjust the version accordingly!):
- create a file called `maven.config` in the `.mvn` folder with the following content (adjust the Tycho version accordingly to the [latest release](https://github.com/eclipse-tycho/tycho/releases)!):
```properties
-Dtycho-version=4.0.10
```
Expand All @@ -43,6 +43,14 @@ In contrast to a traditional maven build where each module has to contain a `pom

You can check more details in a [demo project](https://github.com/eclipse-tycho/tycho/tree/master/demo/bnd-workspace).

### Configure the pomless build

If you want to further configure the build can be done in these ways:

1. You can specify additional global properties in the `.mvn/maven.config`.
2. You can define properties per project properties in the `bnd.bnd` file `pom.model.property.<some property>: true`, see [the wiki](https://github.com/eclipse-tycho/tycho/wiki/Tycho-Pomless#overwrite-group-and-artifact-ids) for more details.
3. You can place a `pom.xml` in your `cnf` folder this will then be used as a parent for the aggregator, here you can add additional mojos, profiles and so on. If you want to enable certain things only for some of the projects you can use properties as described in (2) to skip the execution of mojos not relevant for other projects.

## Mixed Builds

You can even combine a BND Workspace and PDE bundles in a build, see [demo](https://github.com/eclipse-tycho/tycho/tree/master/demo/bnd-pde-workspace).
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
package org.eclipse.tycho.bnd.mojos;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.jar.JarOutputStream;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugins.annotations.Component;
Expand Down Expand Up @@ -56,7 +60,24 @@ protected void execute(Project project) throws Exception {
helper.attachArtifact(mavenProject, "jar", name, file);
}
}
ensureArtifactIsSet();
}

private void ensureArtifactIsSet() throws IOException, FileNotFoundException {
if ("pom".equals(mavenProject.getPackaging())) {
// pom packaging is allowed to have no main artifact...
return;
}
Artifact artifact = mavenProject.getArtifact();
if (artifact.getFile() == null) {
artifact.setFile(new File(mavenProject.getBuild().getDirectory(), mavenProject.getArtifactId() + ".jar"));
}
if (!artifact.getFile().exists()) {
try (JarOutputStream jarOutputStream = new JarOutputStream(
new FileOutputStream(artifact.getFile()))) {
// create a dummy result as otherwise maven is not happy
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.Properties;

import org.apache.maven.lifecycle.Lifecycle;
import org.apache.maven.model.Build;
Expand Down Expand Up @@ -77,6 +80,15 @@ public String getFlavour() {
return "bnd";
}

@Override
protected Properties getEnhancementProperties(Path file) throws IOException {
Properties bnd = new Properties();
try (InputStream stream = Files.newInputStream(file)) {
bnd.load(stream);
return bnd;
}
}

@Override
protected void initModel(Model model, Reader artifactReader, Path artifactFile) throws IOException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ protected void initModel(Model model, Reader artifactReader, Path cnfFolder) thr

@Override
protected ParentModel findParent(Path projectRoot, Map<String, ?> projectOptions) throws IOException {
try {
Workspace workspace = Workspace.findWorkspace(projectRoot.toFile());
File base = workspace.getBase();
if (Files.isSameFile(projectRoot, base.toPath())) {
File buildDir = workspace.getBuildDir();
return loadParent(projectRoot, buildDir.toPath());
}
} catch (Exception e) {
}
try {
return super.findParent(projectRoot, projectOptions);
} catch (NoParentPomFound e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ protected synchronized ParentModel findParent(Path projectRootIn, Map<String, ?>
// assumption parent pom must be physically located in parent directory if not given by build.properties
String parentRef = buildProperties.getProperty(TYCHO_POMLESS_PARENT_PROPERTY, PARENT_POM_DEFAULT_VALUE);
Path fileOrFolder = projectRoot.resolve(parentRef).toRealPath();
return loadParent(projectRoot, fileOrFolder);
}

protected ParentModel loadParent(Path projectRoot, Path fileOrFolder) throws NoParentPomFound, IOException {
PomReference parentPom;
if (Files.isRegularFile(fileOrFolder)) {
parentPom = locatePomReference(fileOrFolder.getParent(), getFileName(fileOrFolder));
Expand Down

0 comments on commit f7cef38

Please sign in to comment.