Skip to content

Commit

Permalink
Add support for the new plexus-build-api artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Mar 9, 2023
1 parent 3d0b6ac commit d97aa83
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 11 deletions.
13 changes: 9 additions & 4 deletions m2e-maven-runtime/org.eclipse.m2e.maven.runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</parent>

<artifactId>org.eclipse.m2e.maven.runtime</artifactId>
<version>3.8.701-SNAPSHOT</version>
<version>3.8.702-SNAPSHOT</version>
<packaging>jar</packaging>

<name>M2E Embedded Maven Runtime (includes Incubating components)</name>
Expand All @@ -32,8 +32,6 @@
bundle. So make sure the following variable has the value of the maven-resolver-* jars
https://bugs.eclipse.org/bugs/show_bug.cgi?id=529540 -->
<maven-resolver.version>1.6.3</maven-resolver.version>
<!-- below are m2e-specific addons -->
<plexus-build-api.version>0.0.7</plexus-build-api.version>
<okhttp-connector.version>0.17.8</okhttp-connector.version>
</properties>

Expand Down Expand Up @@ -76,10 +74,17 @@
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
</dependency>
<!-- the legacy plexus build API (old group/packages) -->
<dependency>
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
<version>${plexus-build-api.version}</version>
<version>0.0.7</version>
</dependency>
<!-- the release v1 plexus build API (new group/packages) only -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>io.takari.aether</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class EclipseClassRealmManagerDelegate implements ClassRealmManagerDelega

private final PlexusContainer plexus;

private static final ArtifactVersion currentBuildApiVersion;
private static final ArtifactVersion legacytBuildApiVersion;

static {
Properties props = new Properties();
Expand All @@ -55,7 +55,7 @@ public class EclipseClassRealmManagerDelegate implements ClassRealmManagerDelega
} catch(IOException e) {
// TODO log
}
currentBuildApiVersion = new DefaultArtifactVersion(props.getProperty("api.version", "0.0.5")); //$NON-NLS-1$ //$NON-NLS-2$
legacytBuildApiVersion = new DefaultArtifactVersion(props.getProperty("api.version", "0.0.5")); //$NON-NLS-1$ //$NON-NLS-2$
}

@Inject
Expand All @@ -73,24 +73,37 @@ public void setupRealm(ClassRealm realm, ClassRealmRequest request) {
realm.importFrom(coreRealm, "org.codehaus.plexus.util.Scanner"); //$NON-NLS-1$

realm.importFrom(coreRealm, "org.sonatype.plexus.build.incremental"); //$NON-NLS-1$
realm.importFrom(coreRealm, "org.codehaus.plexus.build"); //$NON-NLS-1$
}
}

private boolean supportsBuildApi(List<ClassRealmConstituent> constituents) {
boolean hasBuildApi = false;
for(Iterator<ClassRealmConstituent> it = constituents.iterator(); it.hasNext();) {
ClassRealmConstituent constituent = it.next();
if("org.sonatype.plexus".equals(constituent.getGroupId()) //$NON-NLS-1$
&& "plexus-build-api".equals(constituent.getArtifactId())) { //$NON-NLS-1$
ArtifactVersion version = new DefaultArtifactVersion(constituent.getVersion());
boolean compatible = currentBuildApiVersion.compareTo(version) >= 0;
if(compatible) {
if(legacytBuildApiVersion.compareTo(version) >= 0) {
// removing the JAR from the plugin realm to prevent discovery of the DefaultBuildContext
it.remove();
hasBuildApi = true;
}
}
if("org.codehaus.plexus.build".equals(constituent.getGroupId()) //$NON-NLS-1$
&& "plexus-build-api".equals(constituent.getArtifactId())) { //$NON-NLS-1$
ArtifactVersion version = new DefaultArtifactVersion(constituent.getVersion());
// currently we support only version 1, we want to design the API that it is always backward compatible for the client
// so even if we implements Version X and the client Version < X it can be used!
// for incompatible changes we need to use a different package then
if(version.getMajorVersion() >= 1 && version.getMajorVersion() <= 2) {
// removing the JAR from the plugin realm to prevent discovery of the default components
it.remove();
hasBuildApi = true;
}
return compatible;
}
}
return false;
return hasBuildApi;
}

}
65 changes: 65 additions & 0 deletions org.eclipse.m2e.tests.plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<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.m2e</groupId>
<artifactId>m2e-core</artifactId>
<version>2.1.0-SNAPSHOT</version>
</parent>

<groupId>org.eclipse.m2e.tests.plugin</groupId>
<artifactId>org.eclipse.m2e.tests.plugin</artifactId>
<version>1.0.0</version>

<packaging>maven-plugin</packaging>
<name>M2Eclipse Test Maven Plugin</name>
<description>This is a mavenplugin that implements some mojos used in m2e tests to test certain mojo behaviour.</description>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.8.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.8.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
<version>0.0.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>force-install</id>
<phase>verify</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2023 Christoph Läubrich
* All rights reserved. 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.m2e.tests.plugin;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.sonatype.plexus.build.incremental.BuildContext;

/**
* This mojo test that we can use the V1 API
*/
@Mojo(name = "m2e-test-buildapi-v0")
public class PlexusBuildApiV0Mojo extends AbstractMojo {

@Component
BuildContext buildContext;

@Parameter(property = "project", readonly = true)
MavenProject mavenProject;

public void execute() throws MojoExecutionException, MojoFailureException {
String msg = "The buildContext is: " + buildContext.getClass().getName();
getLog().info(msg);
buildContext.addMessage(mavenProject.getBasedir(), 1, 0, msg, BuildContext.SEVERITY_WARNING, null);
// TODO we should have mojo parameter to do some usefull things for test...
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2023 Christoph Läubrich
* All rights reserved. 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.m2e.tests.plugin;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.build.BuildContext;

/**
* This mojo test that we can use the V1 API
*/
@Mojo(name = "m2e-test-buildapi-v1")
public class PlexusBuildApiV1Mojo extends AbstractMojo {

@Component
BuildContext buildContext;

@Parameter(property = "project", readonly = true)
MavenProject mavenProject;

public void execute() throws MojoExecutionException, MojoFailureException {
String msg = "The buildContext is: " + buildContext.getClass().getName();
getLog().info(msg);
buildContext.addMessage(mavenProject.getBasedir(), 1, 0, msg, BuildContext.SEVERITY_WARNING, null);
// TODO we should have mojo parameter to do some usefull things for test...
}

}
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<modules>
<module>target-platform</module>

<module>org.eclipse.m2e.tests.plugin</module>
<module>m2e-maven-runtime</module>

<module>org.eclipse.m2e.model.edit</module>
Expand Down Expand Up @@ -106,7 +107,7 @@
<dependency>
<groupId>org.eclipse.m2e</groupId>
<artifactId>org.eclipse.m2e.maven.runtime</artifactId>
<version>3.8.701-SNAPSHOT</version>
<version>3.8.702-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down

0 comments on commit d97aa83

Please sign in to comment.