Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate configured folders from bnd to maven model #4673

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,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;
}

}
Loading