Skip to content

Commit

Permalink
Add a packaging for maven site
Browse files Browse the repository at this point in the history
Fix #436
  • Loading branch information
laeubi committed Jun 13, 2023
1 parent 17e7db6 commit 4bf187e
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 1 deletion.
9 changes: 9 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ This page describes the noteworthy improvements provided by each release of Ecli

## 4.0.0 (under development)

### creating maven p2 sites with Tycho packaging

There is already a way to [create a p2 maven site with Tycho](https://github.com/eclipse-tycho/tycho/blob/master/RELEASE_NOTES.md#create-p2-repository-referencing-maven-artifacts) for plain jar based projects.
This support is now enhanced to being used in a Tycho based setup so it is possible to build a full maven deployed updatesite automatically with all bundles of the current build.
You can find a demo here:

https://github.com/eclipse-tycho/tycho/tree/master/demo/p2-maven-site


### New document-bundle mojo

There is now a new mojo that replaces the usual ant-based workflow to generate the help index, it can be used like this:
Expand Down
8 changes: 8 additions & 0 deletions demo/p2-maven-site/.mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-build</artifactId>
<version>${tycho-version}</version>
</extension>
</extensions>
1 change: 1 addition & 0 deletions demo/p2-maven-site/.mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Dtycho-version=4.0.0-SNAPSHOT
10 changes: 10 additions & 0 deletions demo/p2-maven-site/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Publish bundles and update-site to maven repository

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

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`
- such a repository can be used in Eclipse for example by adding the following update-site with `Help` > `Install New Software`: `mvn:org.eclipse.tycho.demo:p2-maven-site:1.0.0:zip:p2site`
6 changes: 6 additions & 0 deletions demo/p2-maven-site/bundles/bundle1/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bundle 1
Bundle-SymbolicName: bundle1;singleton:=true
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5
4 changes: 4 additions & 0 deletions demo/p2-maven-site/bundles/bundle1/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
6 changes: 6 additions & 0 deletions demo/p2-maven-site/bundles/bundle2/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bundle 2
Bundle-SymbolicName: bundle2;singleton:=true
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5
4 changes: 4 additions & 0 deletions demo/p2-maven-site/bundles/bundle2/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
1 change: 1 addition & 0 deletions demo/p2-maven-site/maven-repository/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/org/
21 changes: 21 additions & 0 deletions demo/p2-maven-site/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<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>bundles</module>
<module>site</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
14 changes: 14 additions & 0 deletions demo/p2-maven-site/site/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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>p2-maven-site</artifactId>
<packaging>p2-maven-repository</packaging>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ public final class ArtifactType {
public static final String TYPE_INSTALLABLE_UNIT = "p2-installable-unit";
public static final String TYPE_P2_ARTIFACTS = "p2-artifacts";
public static final String TYPE_P2_METADATA = "p2-metadata";
public static final String TYPE_P2_MAVEN_REPOSITORY = "p2-maven-repository";

}
4 changes: 3 additions & 1 deletion tycho-api/src/main/java/org/eclipse/tycho/PackagingType.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public final class PackagingType {
public static final String TYPE_ECLIPSE_REPOSITORY = "eclipse-repository";
public static final String TYPE_ECLIPSE_TARGET_DEFINITION = "eclipse-target-definition";
public static final String TYPE_P2_IU = ArtifactType.TYPE_INSTALLABLE_UNIT;
public static final String TYPE_P2_SITE = ArtifactType.TYPE_P2_MAVEN_REPOSITORY;

public static final Set<String> TYCHO_PACKAGING_TYPES = Set.of(PackagingType.TYPE_ECLIPSE_PLUGIN,
TYPE_ECLIPSE_TEST_PLUGIN, TYPE_ECLIPSE_FEATURE, TYPE_ECLIPSE_REPOSITORY, TYPE_ECLIPSE_TARGET_DEFINITION);
TYPE_ECLIPSE_TEST_PLUGIN, TYPE_ECLIPSE_FEATURE, TYPE_ECLIPSE_REPOSITORY, TYPE_ECLIPSE_TARGET_DEFINITION,
TYPE_P2_SITE);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*******************************************************************************
* Copyright (c) 2022 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.core.osgitools;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.DefaultArtifactKey;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.TargetEnvironment;
import org.eclipse.tycho.core.ArtifactDependencyVisitor;
import org.eclipse.tycho.core.ArtifactDependencyWalker;
import org.eclipse.tycho.core.TychoProject;

@Component(role = TychoProject.class, hint = org.eclipse.tycho.ArtifactType.TYPE_P2_MAVEN_REPOSITORY)
public class P2SiteProject extends AbstractArtifactBasedProject {
@Override
protected ArtifactDependencyWalker newDependencyWalker(ReactorProject project, TargetEnvironment environment) {
return new AbstractArtifactDependencyWalker(getDependencyArtifacts(project, environment),
getEnvironments(project, environment)) {
@Override
public void walk(ArtifactDependencyVisitor visitor) {
//Nothing to do
}
};
}

@Override
public ArtifactKey getArtifactKey(ReactorProject project) {
return new DefaultArtifactKey(org.eclipse.tycho.ArtifactType.TYPE_P2_MAVEN_REPOSITORY, project.getArtifactId(),
getOsgiVersion(project));
}

@Override
public void setupProject(MavenSession session, MavenProject project) {
for (MavenProject other : session.getProjects()) {
if (isRequirement(other)) {
Dependency dependency = new Dependency();
dependency.setGroupId(other.getGroupId());
dependency.setArtifactId(other.getArtifactId());
dependency.setVersion(other.getVersion());
project.getModel().addDependency(dependency);
}
}
}

private boolean isRequirement(MavenProject other) {
String packaging = other.getPackaging();
return "jar".equalsIgnoreCase(packaging) || "bundle".equalsIgnoreCase(packaging)
|| ArtifactType.TYPE_ECLIPSE_PLUGIN.equals(packaging)
|| ArtifactType.TYPE_ECLIPSE_FEATURE.equals(packaging)
|| ArtifactType.TYPE_BUNDLE_FRAGMENT.equals(packaging)
|| ArtifactType.TYPE_ECLIPSE_TEST_PLUGIN.equals(packaging);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ protected List<IPublisherAction> getPublisherActions(IArtifactFacade artifact, L
throw new RuntimeException("Unable to read category File", e);
}
}
} else if (PackagingType.TYPE_P2_SITE.equals(packaging)) {
//nothing to do at the moment...
} else if (PackagingType.TYPE_P2_IU.equals(packaging)) {
actions.add(new AuthoredIUAction(location));
} else if (location.isFile() && location.getName().endsWith(".jar")) {
Expand Down
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 @@ -62,6 +62,11 @@ public void testTychoPublishP2Demo() throws Exception {
runDemo("publish-p2");
}

@Test
public void testP2MavenRepositoryDemo() throws Exception {
runDemo("p2-maven-site", "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
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,40 @@
</configuration>
</component>

<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>p2-maven-repository</role-hint>
<implementation>
org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
</implementation>
<configuration>
<lifecycles>
<lifecycle>
<id>default</id>
<phases>
<validate></validate>
<initialize>
org.apache.maven.plugins:maven-clean-plugin:${clean-plugin.version}:clean
</initialize>
<process-resources>
</process-resources>
<prepare-package>
</prepare-package>
<package>
org.eclipse.tycho:tycho-p2-repository-plugin:${project.version}:assemble-maven-repository
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:${install-plugin.version}:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:${deploy-plugin.version}:deploy
</deploy>
</phases>
</lifecycle>
</lifecycles>
</configuration>
</component>

<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>eclipse-target-definition</role-hint>
Expand Down

0 comments on commit 4bf187e

Please sign in to comment.