Skip to content

Commit

Permalink
Propagate configured folders from bnd to maven model
Browse files Browse the repository at this point in the history
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 9330061)
  • Loading branch information
laeubi committed Feb 1, 2025
1 parent f3d3b5d commit 929a089
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,6 +71,7 @@ public class BndMavenLifecycleParticipant extends AbstractMavenLifecycleParticip

@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
Workspace.setDriver(TychoConstants.DRIVER_NAME);
Map<MavenProject, Project> bndProjects = getProjects(session);
Map<String, BndMavenProject> manifestFirstProjects = getManifestFirstProjects(session, bndProjects.keySet());
Map<String, BndMavenProject> bndWorkspaceProjects = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,34 @@
*******************************************************************************/
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;

@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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -76,7 +74,6 @@ public class BndInitMojo extends AbstractMojo {

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Workspace.setDriver("tycho-maven-build");
fixupPolyglot();
writeConsumerPom();
}
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

}

0 comments on commit 929a089

Please sign in to comment.