-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for exporting bndruns in bndworkspace projects
This adds support for "building" bndrun files by exporting them into a runnable jar. (cherry picked from commit 9511187)
- Loading branch information
1 parent
1a4ce42
commit 6c0287c
Showing
8 changed files
with
389 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/MavenReactorRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Christoph Läubrich and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.bnd; | ||
|
||
import java.io.File; | ||
import java.io.InputStream; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.SortedSet; | ||
|
||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.component.annotations.Component; | ||
|
||
import aQute.bnd.osgi.repository.ResourcesRepository; | ||
import aQute.bnd.osgi.resource.ResourceBuilder; | ||
import aQute.bnd.service.RepositoryPlugin; | ||
import aQute.bnd.service.resource.SupportingResource; | ||
import aQute.bnd.version.Version; | ||
|
||
@Component(role = MavenReactorRepository.class) | ||
public class MavenReactorRepository extends ResourcesRepository implements RepositoryPlugin { | ||
|
||
@Override | ||
public PutResult put(InputStream stream, PutOptions options) throws Exception { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) | ||
throws Exception { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean canWrite() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public List<String> list(String pattern) throws Exception { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public SortedSet<Version> versions(String bsn) throws Exception { | ||
return Collections.emptySortedSet(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Maven Reactor"; | ||
} | ||
|
||
@Override | ||
public String getLocation() { | ||
return "reactor"; | ||
} | ||
|
||
public void addProject(MavenProject project) { | ||
addArtifact(project.getArtifact()); | ||
project.getAttachedArtifacts().forEach(this::addArtifact); | ||
} | ||
|
||
private void addArtifact(Artifact artifact) { | ||
File file = artifact.getFile(); | ||
if (file == null || !file.getName().endsWith(".jar") || !file.isFile()) { | ||
return; | ||
} | ||
try { | ||
SupportingResource resource = ResourceBuilder.parse(file, file.toURI()); | ||
add(resource); | ||
} catch (RuntimeException e) { | ||
|
||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tycho-bnd-plugin/src/main/java/org/eclipse/tycho/bnd/mojos/AbstractBndMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Christoph Läubrich and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.bnd.mojos; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.Component; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.project.MavenProject; | ||
import org.eclipse.tycho.bnd.MavenReactorRepository; | ||
|
||
import aQute.bnd.build.Workspace; | ||
import aQute.service.reporter.Report; | ||
|
||
public abstract class AbstractBndMojo extends AbstractMojo { | ||
|
||
@Parameter(property = "project", readonly = true) | ||
protected MavenProject mavenProject; | ||
|
||
@Parameter(property = "session", readonly = true) | ||
protected MavenSession session; | ||
|
||
@Component | ||
protected MavenReactorRepository mavenReactorRepository; | ||
|
||
protected Workspace getWorkspace() throws MojoFailureException { | ||
try { | ||
Workspace workspace = Workspace.getWorkspace(mavenProject.getBasedir().getParentFile()); | ||
if (workspace.getPlugins().stream().noneMatch(plugin -> plugin instanceof MavenReactorRepository)) { | ||
workspace.addBasicPlugin(mavenReactorRepository); | ||
workspace.refresh(); | ||
} | ||
checkResult(workspace, workspace.isFailOk()); | ||
return workspace; | ||
} catch (Exception e) { | ||
throw new MojoFailureException("error while locating workspace!", e); | ||
} | ||
} | ||
|
||
protected void checkResult(Report report, boolean errorOk) throws MojoFailureException { | ||
List<String> warnings = report.getWarnings(); | ||
for (String warning : warnings) { | ||
getLog().warn(warning); | ||
} | ||
warnings.clear(); | ||
List<String> errors = report.getErrors(); | ||
for (String error : errors) { | ||
getLog().error(error); | ||
} | ||
if (errorOk) { | ||
errors.clear(); | ||
return; | ||
} | ||
if (errors.size() > 0) { | ||
throw new MojoFailureException(errors.stream().collect(Collectors.joining(System.lineSeparator()))); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.