Eclipse p2 and OSGi-r5 to Maven publisher library

A who helps with publishing p2 and OSGi-R5 repositories to a maven repository

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

at.bestsolution
ArtifactId

ArtifactId

at.bestsolution.maven.publisher
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

Eclipse p2 and OSGi-r5 to Maven publisher library
A who helps with publishing p2 and OSGi-R5 repositories to a maven repository
Project URL

Project URL

https://github.com/BestSolution-at/osgi-to-maven-publisher
Source Code Management

Source Code Management

https://github.com/BestSolution-at/osgi-to-maven-publisher

Download at.bestsolution.maven.publisher

How to add to project

<!-- https://jarcasting.com/artifacts/at.bestsolution/at.bestsolution.maven.publisher/ -->
<dependency>
    <groupId>at.bestsolution</groupId>
    <artifactId>at.bestsolution.maven.publisher</artifactId>
    <version>1.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/at.bestsolution/at.bestsolution.maven.publisher/
implementation 'at.bestsolution:at.bestsolution.maven.publisher:1.1.1'
// https://jarcasting.com/artifacts/at.bestsolution/at.bestsolution.maven.publisher/
implementation ("at.bestsolution:at.bestsolution.maven.publisher:1.1.1")
'at.bestsolution:at.bestsolution.maven.publisher:jar:1.1.1'
<dependency org="at.bestsolution" name="at.bestsolution.maven.publisher" rev="1.1.1">
  <artifact name="at.bestsolution.maven.publisher" type="jar" />
</dependency>
@Grapes(
@Grab(group='at.bestsolution', module='at.bestsolution.maven.publisher', version='1.1.1')
)
libraryDependencies += "at.bestsolution" % "at.bestsolution.maven.publisher" % "1.1.1"
[at.bestsolution/at.bestsolution.maven.publisher "1.1.1"]

Dependencies

compile (6)

Group / Artifact Type Version
org.apache.commons : commons-compress jar 1.12
commons-io : commons-io jar 2.5
org.apache.maven.indexer : indexer-core jar 5.1.2-816025a
org.apache.maven.wagon : wagon-http-lightweight jar 2.3
org.eclipse.sisu : org.eclipse.sisu.plexus jar 0.3.3
org.sonatype.sisu : sisu-guice jar 3.2.6

Project Modules

There are no modules declared in this project.

osgi-to-maven-publisher

Library to publish Eclipse p2 and OSGi r5 repositories to a maven repository

Usage

This is a library so you can not use it directly to publish artifacts but you have to create your own application to customize the publishing process.

An example useage is the publishing process used by e(fx)clipse to publish the runtime build artefacts.

private static final String SNAPSHOT_URL = "https://oss.sonatype.org/content/repositories/snapshots/";
	private static final String RELEASE_URL = "https://oss.sonatype.org/service/local/staging/deploy/maven2/";
	private static final String REPOSITORY_ID = "sonatype";

	public static void main(String[] args) throws Throwable {
		Options options = new Options();
		options.addOption("snapshots", false, "Publish snapshots");
		options.addOption("mavenrepository",true, "Maven repository to publish the build to");
		options.addOption("mavenrepositoryid",true,"Id of the maven repository to publish to");
		options.addOption("p2repository", true, "P2 repository url");
		options.addOption("publishSubset", true, "Publishing subset allowed values ALL, PLATFORM, EFX");


		CommandLineParser parser = new DefaultParser();
	private static final String SNAPSHOT_URL = "https://oss.sonatype.org/content/repositories/snapshots/";
	private static final String RELEASE_URL = "https://oss.sonatype.org/service/local/staging/deploy/maven2/";
	private static final String REPOSITORY_ID = "sonatype";

	public static void main(String[] args) throws Throwable {
		Options options = new Options();
		options.addOption("snapshots", false, "Publish snapshots");
		options.addOption("mavenrepository",true, "Maven repository to publish the build to");
		options.addOption("mavenrepositoryid",true,"Id of the maven repository to publish to");
		options.addOption("p2repository", true, "P2 repository url");
		options.addOption("publishSubset", true, "Publishing subset allowed values ALL, PLATFORM, EFX");
		options.addOption("validateonly",false,"Validate if the content of the repository is mirrored and resolved correctly");

		CommandLineParser parser = new DefaultParser();
		CommandLine cmd = parser.parse(options, args);

		String repository = cmd.hasOption("snapshots") ? "http://download.eclipse.org/efxclipse/runtime-nightly/site_assembly.zip" : null;
		if( cmd.hasOption("p2repository") ) {
			repository = cmd.getOptionValue("p2repository");
		}

		Path file = null;

		if( repository != null ) {
			URL url = new URL(repository);
			file = Files.createTempFile("p2-repository", ".zip");
			try ( InputStream in = url.openStream();
					OutputStream out = Files.newOutputStream(file) ) {
				byte[] buf = new byte[1024 * 500];
				int l;
				int total = 0;
				while( (l = in.read(buf)) != -1 ) {
					out.write(buf, 0, l);
					total += l;
					System.out.println("Loaded bytes " + new DecimalFormat("#,##0.00").format(total / 1024.0 / 1024.0) + " MB");
				}
			}
		} else {
			System.exit(1);
		}

		String mavenRepoUrl = cmd.hasOption("snapshots") ? SNAPSHOT_URL : RELEASE_URL;
		if( cmd.hasOption("mavenrepository") ) {
			mavenRepoUrl = cmd.getOptionValue("mavenrepository");
		}
		String mavenrepositoryId = REPOSITORY_ID;
		if( cmd.hasOption("mavenrepositoryid") ) {
			mavenrepositoryId = cmd.getOptionValue("mavenrepositoryid");
		}

		P2ToMavenSax p = new P2ToMavenSax( file.toAbsolutePath().toString(), mavenRepoUrl, mavenrepositoryId);
		p.setMavenReplacementLookup( b -> {
			if( b.getBundleId().equals("org.sat4j.core") ) {
				return Optional.of(new OsgiToMaven.MavenDep("org.ow2.sat4j","org.ow2.sat4j.core"));
			} else if( b.getBundleId().equals("org.sat4j.pb") ) {
				return Optional.of(new OsgiToMaven.MavenDep("org.ow2.sat4j","org.ow2.sat4j.pb"));
			}
			return Optional.empty();
		});
		p.setSourceEnforced( b -> ! b.getBundleId().equals("org.antlr.runtime"));
		p.setBundleFilter( b -> { return ! (b.getBundleId().startsWith("org.eclipse.emf.codegen")
				|| b.getBundleId().startsWith("org.eclipse.emf.mwe")
				|| b.getBundleId().startsWith("org.eclipse.fx.ui.workbench3")
				|| b.getBundleId().equals("org.eclipse.xtext.generator")
				|| b.getBundleId().startsWith("org.eclipse.xtext")); });
		p.setGroupIdResolver( b -> {
			if( b.getBundleId().startsWith("org.eclipse.fx") ) {
				return "at.bestsolution.efxclipse.rt";
			}
			return "at.bestsolution.efxclipse.eclipse";
		});

		if( cmd.hasOption("publishSubset") && "PLATFORM".equals(cmd.getOptionValue("publishSubset")) ) {
			p.setPublishFilter( b -> ! b.getBundleId().startsWith("org.eclipse.fx") );
		} else if( cmd.hasOption("publishSubset") && "EFX".equals(cmd.getOptionValue("publishSubset")) ) {
			p.setPublishFilter( b -> b.getBundleId().startsWith("org.eclipse.fx") );
		}

		if( cmd.hasOption("validateonly") ) {
			p.validate();
		} else {
			p.publish();
			p.validate();
		}

		Files.delete(file);
	}
at.bestsolution

BestSolution.at EDV Systemhaus GmbH

Versions

Version
1.1.1
1.1.0
1.0.0