Skip to content

Commit

Permalink
Create tycho-repository-plugin to generate standard OSGi repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jul 5, 2023
1 parent edc419c commit 1daa6ea
Show file tree
Hide file tree
Showing 17 changed files with 444 additions and 7 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This page describes the noteworthy improvements provided by each release of Ecli

## 5.0.0 (under development)

### new tycho-repository-plugin

Tycho now contains a new `tycho-repository-plugin` that can be used to package OSGi repositories.


## 4.0.0

Expand Down
13 changes: 13 additions & 0 deletions demo/osgi-repository/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Publish bundles as an OSGi Repository to maven repository

This Demo shows how to publish a set of bundles as an OSGi Repository and deploy it to a maven repository (simulated by a folder here),
with this approach it is possible to deploy a whole project consumable by OSGi and maven users with only using the maven repository as the backing store.

This example uses a single bundle build with bnd-maven-plugin, but actually any jar project that produces a bundle (including Tycho ones) would work!

As a result of building the project with `mvn clean deploy -DaltDeploymentRepository=snapshot-repo::default::file:maven-repository` you can inspect the following items:

- find the produced site in `site/target/repository`
- see the deployed artifacts in the file base maven repository under `maven-repository`

**Currently there is no support in Eclipse/Tycho for consuming such repository!**
1 change: 1 addition & 0 deletions demo/osgi-repository/maven-repository/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/org/
39 changes: 39 additions & 0 deletions demo/osgi-repository/my-bundle/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.tycho.demo</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>my-bundle</artifactId>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.bundle</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>6.4.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>jar</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package hello.world;

public interface GreetingService {

void sayHello();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@org.osgi.annotation.bundle.Export
@org.osgi.annotation.versioning.Version("1.0")
package hello.world;
15 changes: 15 additions & 0 deletions demo/osgi-repository/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.tycho.demo</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>repository</module>
<module>my-bundle</module>
</modules>
<properties>
<tycho-version>5.0.0-SNAPSHOT</tycho-version>
</properties>

</project>
23 changes: 23 additions & 0 deletions demo/osgi-repository/repository/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.tycho.demo</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>repository</artifactId>
<packaging>repository</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-repository-plugin</artifactId>
<version>${tycho-version}</version>
<!-- Extensions must be enabled for this mojo to work reliable and for using the custom package type-->
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@
<maven-version>3.9.3</maven-version>
<minimal-maven-version>3.9.0</minimal-maven-version>
<!-- When updating surefire version, double-check Import-Package statements generated by bnd-maven-plugin and possibly adapt instructions in various bnd.bnd files -->
<!-- Stick to 3.0.0-M5 because of https://github.com/eclipse-tycho/tycho/issues/879 / https://issues.apache.org/jira/projects/SUREFIRE/issues/SUREFIRE-2072 -->
<surefire-version>3.1.2</surefire-version>
<equinoxVersion>3.18.400</equinoxVersion>
<ecjVersion>3.34.0</ecjVersion>
<bnd.version>6.4.0</bnd.version>
<!-- these are referenced from src/main/resources/META-INF/plexus/components.xml -->
<resources-plugin.version>2.4.3</resources-plugin.version>
<install-plugin.version>2.3.1</install-plugin.version>
<deploy-plugin.version>2.5</deploy-plugin.version>
<clean-plugin.version>2.4.1</clean-plugin.version>
<surefire-plugin.version>${surefire-version}</surefire-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -544,6 +549,7 @@
<module>tycho-apitools-plugin</module>
<module>tycho-targetplatform</module>
<module>tycho-bnd-plugin</module>
<module>tycho-repository-plugin</module>
</modules>
<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2023 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;

public class MavenArtifactNamespace {

/**
* Namespace name for maven artifact capabilities and requirements.
*/
public static final String MAVEN_ARTIFACT_NAMESPACE = "apache.maven.artifact";

/**
* The capability attribute identifying the group id.
*/
public static final String CAPABILITY_GROUP_ATTRIBUTE = "group";

/**
* The capability attribute identifying the {@code Version} of the artifact.
*/
public static final String CAPABILITY_VERSION_ATTRIBUTE = "version";
}
5 changes: 5 additions & 0 deletions tycho-its/src/test/java/org/eclipse/tycho/test/DemoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public void testP2MavenRepositoryDemo() throws Exception {
runDemo("p2-maven-site", "deploy", "-DaltDeploymentRepository=snapshot-repo::default::file:maven-repository");
}

@Test
public void testOsgiMavenRepositoryDemo() throws Exception {
runDemo("osgi-repository", "deploy", "-DaltDeploymentRepository=snapshot-repo::default::file:maven-repository");
}

protected Verifier runDemo(String test, String... xargs) throws Exception {
Verifier verifier = super.getVerifier("../../demo/" + test, true, true);
for (String xarg : xargs) {
Expand Down
6 changes: 0 additions & 6 deletions tycho-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
</dependencies>

<properties>
<!-- these are referenced from src/main/resources/META-INF/plexus/components.xml -->
<resources-plugin.version>2.4.3</resources-plugin.version>
<install-plugin.version>2.3.1</install-plugin.version>
<deploy-plugin.version>2.5</deploy-plugin.version>
<clean-plugin.version>2.4.1</clean-plugin.version>
<surefire-plugin.version>${surefire-version}</surefire-plugin.version>
</properties>

<build>
Expand Down
8 changes: 8 additions & 0 deletions tycho-repository-plugin/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=17
71 changes: 71 additions & 0 deletions tycho-repository-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho</artifactId>
<version>5.0.0-SNAPSHOT</version>
</parent>
<artifactId>tycho-repository-plugin</artifactId>
<name>Tycho Repository Plugin</name>
<description>Mojos dedicated to creating OSGi Repositories</description>
<packaging>maven-plugin</packaging>
<prerequisites>
<maven>${minimal-maven-version}</maven>
</prerequisites>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.repository</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.util.function</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.util.promise</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<configuration>
<staticMetadataDirectory>${project.build.directory}/filtered/META-INF/plexus/</staticMetadataDirectory>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<targetPath>${project.build.directory}/filtered</targetPath>
</resource>
</resources>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2023 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.repository.plugin;

import java.util.List;

import org.apache.maven.AbstractMavenLifecycleParticipant;
import org.apache.maven.MavenExecutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;

@Component(role = AbstractMavenLifecycleParticipant.class)
public class PackageMavenLifecycleParticipant extends AbstractMavenLifecycleParticipant {

@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
List<MavenProject> projects = session.getProjects();
for (MavenProject project : projects) {
if ("repository".equals(project.getPackaging()) && project.getPlugin("org.eclipse.tycho:tycho-repository-plugin") != null) {
addInterestingProjects(project, projects);
}
}
}

private void addInterestingProjects(MavenProject project, List<MavenProject> projects) {
for (MavenProject other : projects) {
if (other == project) {
continue;
}
if (PackageMavenRepositoryMojo.isInteresting(other)) {
Dependency dependency = new Dependency();
dependency.setGroupId(other.getGroupId());
dependency.setArtifactId(other.getArtifactId());
dependency.setVersion(other.getVersion());
project.getModel().addDependency(dependency);
}
}
}

}
Loading

0 comments on commit 1daa6ea

Please sign in to comment.