From 4bf187e98dcc9ec2666a666a073b620ba72e1316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Wed, 7 Jun 2023 10:02:43 +0200 Subject: [PATCH] Add a packaging for maven site Fix eclipse-tycho#436 --- RELEASE_NOTES.md | 9 +++ demo/p2-maven-site/.mvn/extensions.xml | 8 +++ demo/p2-maven-site/.mvn/maven.config | 1 + demo/p2-maven-site/README.MD | 10 +++ .../bundles/bundle1/META-INF/MANIFEST.MF | 6 ++ .../bundles/bundle1/build.properties | 4 ++ .../bundles/bundle2/META-INF/MANIFEST.MF | 6 ++ .../bundles/bundle2/build.properties | 4 ++ .../p2-maven-site/maven-repository/.gitignore | 1 + demo/p2-maven-site/pom.xml | 21 ++++++ demo/p2-maven-site/site/pom.xml | 14 ++++ .../java/org/eclipse/tycho/ArtifactType.java | 1 + .../java/org/eclipse/tycho/PackagingType.java | 4 +- .../tycho/core/osgitools/P2SiteProject.java | 69 +++++++++++++++++++ .../tycho/p2resolver/P2GeneratorImpl.java | 2 + .../java/org/eclipse/tycho/test/DemoTest.java | 5 ++ .../resources/META-INF/plexus/components.xml | 34 +++++++++ 17 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 demo/p2-maven-site/.mvn/extensions.xml create mode 100644 demo/p2-maven-site/.mvn/maven.config create mode 100644 demo/p2-maven-site/README.MD create mode 100644 demo/p2-maven-site/bundles/bundle1/META-INF/MANIFEST.MF create mode 100644 demo/p2-maven-site/bundles/bundle1/build.properties create mode 100644 demo/p2-maven-site/bundles/bundle2/META-INF/MANIFEST.MF create mode 100644 demo/p2-maven-site/bundles/bundle2/build.properties create mode 100644 demo/p2-maven-site/maven-repository/.gitignore create mode 100644 demo/p2-maven-site/pom.xml create mode 100644 demo/p2-maven-site/site/pom.xml create mode 100644 tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/P2SiteProject.java diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 93985ee59a..a7e830cc21 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -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: diff --git a/demo/p2-maven-site/.mvn/extensions.xml b/demo/p2-maven-site/.mvn/extensions.xml new file mode 100644 index 0000000000..ff2889110d --- /dev/null +++ b/demo/p2-maven-site/.mvn/extensions.xml @@ -0,0 +1,8 @@ + + + + org.eclipse.tycho + tycho-build + ${tycho-version} + + diff --git a/demo/p2-maven-site/.mvn/maven.config b/demo/p2-maven-site/.mvn/maven.config new file mode 100644 index 0000000000..7084d8ecd9 --- /dev/null +++ b/demo/p2-maven-site/.mvn/maven.config @@ -0,0 +1 @@ +-Dtycho-version=4.0.0-SNAPSHOT \ No newline at end of file diff --git a/demo/p2-maven-site/README.MD b/demo/p2-maven-site/README.MD new file mode 100644 index 0000000000..dbe4d4d084 --- /dev/null +++ b/demo/p2-maven-site/README.MD @@ -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` \ No newline at end of file diff --git a/demo/p2-maven-site/bundles/bundle1/META-INF/MANIFEST.MF b/demo/p2-maven-site/bundles/bundle1/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..ca53834902 --- /dev/null +++ b/demo/p2-maven-site/bundles/bundle1/META-INF/MANIFEST.MF @@ -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 diff --git a/demo/p2-maven-site/bundles/bundle1/build.properties b/demo/p2-maven-site/bundles/bundle1/build.properties new file mode 100644 index 0000000000..34d2e4d2da --- /dev/null +++ b/demo/p2-maven-site/bundles/bundle1/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/demo/p2-maven-site/bundles/bundle2/META-INF/MANIFEST.MF b/demo/p2-maven-site/bundles/bundle2/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..113f8158f5 --- /dev/null +++ b/demo/p2-maven-site/bundles/bundle2/META-INF/MANIFEST.MF @@ -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 diff --git a/demo/p2-maven-site/bundles/bundle2/build.properties b/demo/p2-maven-site/bundles/bundle2/build.properties new file mode 100644 index 0000000000..34d2e4d2da --- /dev/null +++ b/demo/p2-maven-site/bundles/bundle2/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/demo/p2-maven-site/maven-repository/.gitignore b/demo/p2-maven-site/maven-repository/.gitignore new file mode 100644 index 0000000000..cf1db2eed3 --- /dev/null +++ b/demo/p2-maven-site/maven-repository/.gitignore @@ -0,0 +1 @@ +/org/ diff --git a/demo/p2-maven-site/pom.xml b/demo/p2-maven-site/pom.xml new file mode 100644 index 0000000000..b6374fff01 --- /dev/null +++ b/demo/p2-maven-site/pom.xml @@ -0,0 +1,21 @@ + + 4.0.0 + org.eclipse.tycho.demo + parent + 1.0.0 + pom + + bundles + site + + + + + org.eclipse.tycho + tycho-maven-plugin + ${tycho-version} + true + + + + diff --git a/demo/p2-maven-site/site/pom.xml b/demo/p2-maven-site/site/pom.xml new file mode 100644 index 0000000000..468ac34030 --- /dev/null +++ b/demo/p2-maven-site/site/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + + org.eclipse.tycho.demo + parent + 1.0.0 + + + p2-maven-site + p2-maven-repository + diff --git a/tycho-api/src/main/java/org/eclipse/tycho/ArtifactType.java b/tycho-api/src/main/java/org/eclipse/tycho/ArtifactType.java index c58b2c3784..1dc3e26975 100644 --- a/tycho-api/src/main/java/org/eclipse/tycho/ArtifactType.java +++ b/tycho-api/src/main/java/org/eclipse/tycho/ArtifactType.java @@ -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"; } diff --git a/tycho-api/src/main/java/org/eclipse/tycho/PackagingType.java b/tycho-api/src/main/java/org/eclipse/tycho/PackagingType.java index 5f823e6d3a..73f2be240a 100644 --- a/tycho-api/src/main/java/org/eclipse/tycho/PackagingType.java +++ b/tycho-api/src/main/java/org/eclipse/tycho/PackagingType.java @@ -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 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); } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/P2SiteProject.java b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/P2SiteProject.java new file mode 100644 index 0000000000..221d0aed48 --- /dev/null +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/P2SiteProject.java @@ -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); + } + +} diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/P2GeneratorImpl.java b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/P2GeneratorImpl.java index 82828ea04c..a491521ebc 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/P2GeneratorImpl.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/P2GeneratorImpl.java @@ -289,6 +289,8 @@ protected List 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")) { diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/DemoTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/DemoTest.java index ecd1be154a..f12bbaa5ce 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/DemoTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/DemoTest.java @@ -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) { diff --git a/tycho-maven-plugin/src/main/resources/META-INF/plexus/components.xml b/tycho-maven-plugin/src/main/resources/META-INF/plexus/components.xml index 990cfa295a..c8b238f511 100644 --- a/tycho-maven-plugin/src/main/resources/META-INF/plexus/components.xml +++ b/tycho-maven-plugin/src/main/resources/META-INF/plexus/components.xml @@ -209,6 +209,40 @@ + + org.apache.maven.lifecycle.mapping.LifecycleMapping + p2-maven-repository + + org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping + + + + + default + + + + org.apache.maven.plugins:maven-clean-plugin:${clean-plugin.version}:clean + + + + + + + org.eclipse.tycho:tycho-p2-repository-plugin:${project.version}:assemble-maven-repository + + + org.apache.maven.plugins:maven-install-plugin:${install-plugin.version}:install + + + org.apache.maven.plugins:maven-deploy-plugin:${deploy-plugin.version}:deploy + + + + + + + org.apache.maven.lifecycle.mapping.LifecycleMapping eclipse-target-definition