Skip to content

Commit

Permalink
feat: Switch from Maven resolver to MIMA
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas authored May 3, 2024
1 parent f5f19a9 commit 96676f9
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 315 deletions.
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.1/apache-maven-3.9.1-bin.zip
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
34 changes: 17 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@
<maven.compiler.release>8</maven.compiler.release>
<!-- value comes from property git.commit.author.time -->
<project.build.outputTimestamp>${git.commit.author.time}</project.build.outputTimestamp>
<slf4j.version>2.0.12</slf4j.version>
<slf4j.version>2.0.13</slf4j.version>
<picocli.version>4.7.5</picocli.version>
<sisu.version>0.9.0.M1</sisu.version>
<maven.version>3.9.1</maven.version>
<maven.resolver.version>1.9.18</maven.resolver.version>
<sisu.version>0.9.0.M2</sisu.version>
<maven.version>3.9.6</maven.version>
<mima.version>2.4.12</mima.version>
<maven.resolver.version>1.9.20</maven.resolver.version>
<commons.lang3.version>3.14.0</commons.lang3.version>
<version.compiler.plugin>3.13.0</version.compiler.plugin>
<version.dependency.plugin>3.6.1</version.dependency.plugin>
Expand Down Expand Up @@ -106,12 +107,12 @@
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>5.1.0</version>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
<version>33.2.0-jre</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down Expand Up @@ -149,17 +150,6 @@
<artifactId>maven-model-builder</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
Expand Down Expand Up @@ -235,6 +225,16 @@
<artifactId>plexus-utils</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>eu.maveniverse.maven.mima</groupId>
<artifactId>context</artifactId>
<version>${mima.version}</version>
</dependency>
<dependency>
<groupId>eu.maveniverse.maven.mima.runtime</groupId>
<artifactId>standalone-sisu</artifactId>
<version>${mima.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
23 changes: 9 additions & 14 deletions pomchecker-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.sonatype.plexus</groupId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-cipher</artifactId>
<version>1.7</version>
<version>2.0</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand All @@ -71,8 +71,12 @@
<artifactId>maven-model-builder</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<groupId>eu.maveniverse.maven.mima</groupId>
<artifactId>context</artifactId>
</dependency>
<dependency>
<groupId>eu.maveniverse.maven.mima.runtime</groupId>
<artifactId>standalone-sisu</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -221,13 +225,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.kordamp.shade</groupId>
<artifactId>maven-shade-ext-transformers</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
Expand All @@ -245,10 +242,8 @@
</manifestEntries>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.kordamp.shade.resources.ServicesResourceTransformer">
<path>META-INF/sisu</path>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.SisuIndexResourceTransformer"/>
</transformers>
<filters>
<filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@

import com.google.common.base.CharMatcher;
import com.google.common.collect.ImmutableMap;
import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.mima.context.ContextOverrides;
import eu.maveniverse.maven.mima.context.Runtimes;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingResult;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
Expand All @@ -35,25 +37,13 @@
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
import org.eclipse.aether.impl.DefaultServiceLocator;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
import org.eclipse.aether.spi.connector.transport.TransporterFactory;
import org.eclipse.aether.transport.file.FileTransporterFactory;
import org.eclipse.aether.transport.http.HttpTransporterFactory;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;
import java.util.Properties;

import static java.util.Objects.requireNonNull;

/**
* @author Andres Almiray
* @since 1.1.0
Expand All @@ -63,29 +53,36 @@ public class PomParser {
CharMatcher.inRange('a', 'z').or(CharMatcher.inRange('0', '9'));

public static MavenProject createMavenProject(File pomFile) {
return createMavenProject(pomFile, createDefaultRepositorySystemSession(newRepositorySystem()));
}

private static MavenProject createMavenProject(File pomFile, RepositorySystemSession session) {
// MavenCli's way to instantiate PlexusContainer
// HACK: MIMA provides sisu runtime, but we need Maven components as well,
// that are Plexus still. Hence, we "wrap" and boot Plexus around MIMA, and this
// awakens MIMA eager singleton activator.
ClassWorld classWorld =
new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader());
new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader());
ContainerConfiguration containerConfiguration =
new DefaultContainerConfiguration()
.setClassWorld(classWorld)
.setRealm(classWorld.getClassRealm("plexus.core"))
.setClassPathScanning(PlexusConstants.SCANNING_INDEX)
.setAutoWiring(true)
.setJSR250Lifecycle(true)
.setName("pom-reader");
new DefaultContainerConfiguration()
.setClassWorld(classWorld)
.setRealm(classWorld.getClassRealm("plexus.core"))
.setClassPathScanning(PlexusConstants.SCANNING_INDEX)
.setAutoWiring(true)
.setJSR250Lifecycle(true)
.setName("pom-reader");
try {
PlexusContainer container = new DefaultPlexusContainer(containerConfiguration);
try (Context context = Runtimes.INSTANCE.getRuntime().create(ContextOverrides.create().withUserSettings(true).build())) {
return createMavenProject(pomFile, context, container);
}
} catch (PlexusContainerException ex) {
throw new IllegalStateException(ex);
}
}

private static MavenProject createMavenProject(File pomFile, Context context, PlexusContainer plexusContainer) {
try {
MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();
ProjectBuildingRequest projectBuildingRequest =
mavenExecutionRequest.getProjectBuildingRequest();

projectBuildingRequest.setRepositorySession(session);
projectBuildingRequest.setRepositorySession(context.repositorySystemSession());

// Profile activation needs properties such as JDK version
Properties properties = new Properties(); // allowing duplicate entries
Expand All @@ -94,51 +91,15 @@ private static MavenProject createMavenProject(File pomFile, RepositorySystemSes
properties.putAll(System.getProperties());
projectBuildingRequest.setSystemProperties(properties);

ProjectBuilder projectBuilder = container.lookup(ProjectBuilder.class);
ProjectBuilder projectBuilder = plexusContainer.lookup(ProjectBuilder.class);
ProjectBuildingResult projectBuildingResult =
projectBuilder.build(pomFile, projectBuildingRequest);
return projectBuildingResult.getProject();
} catch (PlexusContainerException | ComponentLookupException | ProjectBuildingException ex) {
} catch (ComponentLookupException | ProjectBuildingException ex) {
throw new IllegalStateException(ex);
}
}

private static RepositorySystem newRepositorySystem() {
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
locator.addService(TransporterFactory.class, FileTransporterFactory.class);
locator.addService(TransporterFactory.class, HttpTransporterFactory.class);

return locator.getService(RepositorySystem.class);
}

private static DefaultRepositorySystemSession createDefaultRepositorySystemSession(RepositorySystem system) {
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
LocalRepository localRepository = new LocalRepository(findLocalRepository());
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepository));
return session;
}

private static String findLocalRepository() {
Path home = Paths.get(System.getProperty("user.home"));
Path localRepo = home.resolve(".m2").resolve("repository");
if (Files.isDirectory(localRepo)) {
return localRepo.toAbsolutePath().toString();
} else {
return makeTemporaryLocalRepository();
}
}

private static String makeTemporaryLocalRepository() {
try {
File temporaryDirectory = Files.createTempDirectory("m2").toFile();
temporaryDirectory.deleteOnExit();
return temporaryDirectory.getAbsolutePath();
} catch (IOException ex) {
return null;
}
}

public static ImmutableMap<String, String> detectOsProperties() {
return ImmutableMap.of(
"os.detected.name",
Expand Down
3 changes: 2 additions & 1 deletion pomchecker-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ dependencies {
api "org.apache.maven.resolver:maven-resolver-transport-file:$mavenResolverVersion"
api "org.apache.maven.resolver:maven-resolver-transport-classpath:$mavenResolverVersion"
api "org.apache.maven.resolver:maven-resolver-connector-basic:$mavenResolverVersion"
api "org.apache.maven:maven-project:$mavenProjectVersion"
api "eu.maveniverse.maven.mima:context:$mimaVersion"
api "eu.maveniverse.maven.mima.runtime:standalone-sisu:$mimaVersion"
api "org.kordamp.gradle:base-gradle-plugin:$kordampPluginVersion"
api "org.eclipse.sisu:org.eclipse.sisu.inject:$sisuVersion"
api "org.eclipse.sisu:org.eclipse.sisu.plexus:$sisuVersion"
Expand Down
22 changes: 11 additions & 11 deletions pomchecker-gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@

group = org.kordamp.gradle
version = 0.0.0-SNAPSHOT
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 11
targetCompatibility = 11

kordampPluginVersion = 0.46.10
kordampBuildVersion = 2.9.1
kordampPluginVersion = 0.54.0
kordampBuildVersion = 3.4.0
commonsCollectionsVersion = 3.2.2
commonsLangVersion = 2.6
commonsLang3Version = 3.14.0
commonsLoggingVersion = 1.2
groovyVersion = 2.5.12
guavaVersion = 31.1-jre
guiceVersion = 5.1.0
guavaVersion = 33.2.0-jre
guiceVersion = 6.0.0
httpVersion = 4.5.10
mavenProjectVersion = 2.2.1
mavenVersion = 3.9.1
mavenResolverVersion = 1.9.18
mavenVersion = 3.9.6
mimaVersion = 2.4.12
mavenResolverVersion = 1.9.20
plexus2Version = 1.26
plexusVersion = 3.5.1
sisuVersion = 0.9.0.M1
slf4jVersion = 2.0.12
sisuVersion = 0.9.0.M2
slf4jVersion = 2.0.13

org.gradle.daemon = true
org.gradle.caching = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 96676f9

Please sign in to comment.