Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Maven 4 #4219

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<plexusCompilerVersion>2.15.0</plexusCompilerVersion>
<pluginToolsVersion>3.15.0</pluginToolsVersion>
<jgit-version>7.0.0.202409031743-r</jgit-version>
<maven-version>3.9.9</maven-version>
<maven-version>4.0.0-beta-4</maven-version>
<sisu-version>0.9.0.M3</sisu-version>
<minimal-maven-version>3.9.6</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 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.tycho.ArtifactDescriptor;
import org.eclipse.tycho.ArtifactKey;
Expand Down Expand Up @@ -155,6 +155,7 @@ public static void injectMavenDependencies(MavenProject project, DependencyArtif
.flatMap(definition -> definition.getLocations().stream()).filter(MavenGAVLocation.class::isInstance)
.map(MavenGAVLocation.class::cast).flatMap(location -> location.getRepositoryReferences().stream())
.toList();
//FIXME this should be injected in the model building phase so maven can figure it out directly!
if (repositoryReferences != null && !repositoryReferences.isEmpty()) {
Map<String, ArtifactRepository> repositoryMap = project.getRemoteArtifactRepositories().stream()
.collect(Collectors.toMap(MavenDependencyInjector::getId, Function.identity(), (a, b) -> a,
Expand All @@ -163,19 +164,19 @@ public static void injectMavenDependencies(MavenProject project, DependencyArtif
String id = getId(reference);
ArtifactRepository artifactRepository = repositoryMap.get(id);
if (artifactRepository == null) {
repositoryMap.put(id,
repositorySystem.createArtifactRepository(id, reference.getUrl(), null, null, null));
// repositoryMap.put(id,
// repositorySystem.createArtifactRepository(id, reference.getUrl(), null, null, null));
} else if (!artifactRepository.getUrl().equals(reference.getUrl())) {
logger.warn("Target defines an artifact repository with the ID " + id
+ " but there is already a repository for that ID mapped to a different URL! (target URL = "
+ reference.getUrl() + ", existing URL = " + artifactRepository.getUrl());
}
}
List<ArtifactRepository> artifactRepositories = new ArrayList<>(repositoryMap.values());
repositorySystem.injectMirror(artifactRepositories, settings.getMirrors());
repositorySystem.injectProxy(artifactRepositories, settings.getProxies());
repositorySystem.injectAuthentication(artifactRepositories, settings.getServers());
project.setRemoteArtifactRepositories(artifactRepositories);
// List<ArtifactRepository> artifactRepositories = new ArrayList<>(repositoryMap.values());
// repositorySystem.injectMirror(artifactRepositories, settings.getMirrors());
// repositorySystem.injectProxy(artifactRepositories, settings.getProxies());
// repositorySystem.injectAuthentication(artifactRepositories, settings.getServers());
// project.setRemoteArtifactRepositories(artifactRepositories);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.apache.commons.io.FilenameUtils;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.repository.RepositorySystem;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.graph.DependencyNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
package org.eclipse.tycho.core.resolver;

import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.spi.synccontext.SyncContextFactory;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.tycho.core.MavenDependenciesResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,28 @@
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.tycho.MavenArtifactRepositoryReference;
import org.eclipse.tycho.core.DependencyResolutionException;
import org.eclipse.tycho.core.MavenDependenciesResolver;
import org.eclipse.tycho.core.MavenModelFacade;
import org.eclipse.tycho.core.maven.MavenArtifactFacade;

@Component(role = MavenDependenciesResolver.class)
public class MavenDependenciesResolverConfigurer implements MavenDependenciesResolver {
Expand All @@ -62,68 +55,70 @@ public class MavenDependenciesResolverConfigurer implements MavenDependenciesRes
public Collection<?> resolve(String groupId, String artifactId, String version, String packaging, String classifier,
Collection<String> scopes, int depth, Collection<MavenArtifactRepositoryReference> additionalRepositories,
Object session) throws DependencyResolutionException {
Artifact artifact;
if (classifier != null && !classifier.isEmpty()) {
artifact = repositorySystem.createArtifactWithClassifier(groupId, artifactId, version, packaging,
classifier);
} else {
artifact = repositorySystem.createArtifact(groupId, artifactId, version, null, packaging);
}
logger.debug("Resolving " + artifact);
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
MavenSession mavenSession = getMavenSession(session);
request.setResolveRoot(true);
request.setOffline(mavenSession.isOffline());
request.setCollectionFilter(a -> isValidScope(a, scopes));
request.setResolutionFilter(new ArtifactFilter() {
@Override
public boolean include(Artifact a) {
List<String> trail = a.getDependencyTrail();
if (logger.isDebugEnabled()) {
logger.debug("[depth=" + trail.size() + ", scope matches =" + isValidScope(a, scopes) + "][" + a
+ "][" + trail.stream().collect(Collectors.joining(" >> ")) + "]");
}
return trail.size() <= depth && isValidScope(a, scopes);
}
});
request.setLocalRepository(mavenSession.getLocalRepository());
request.setResolveTransitively(depth > 0);
request.setRemoteRepositories(
getEffectiveRepositories(mavenSession.getCurrentProject(), additionalRepositories, repositorySystem));
repositorySystem.injectMirror(request.getRemoteRepositories(), mavenSession.getSettings().getMirrors());
repositorySystem.injectProxy(request.getRemoteRepositories(), mavenSession.getSettings().getProxies());
repositorySystem.injectAuthentication(request.getRemoteRepositories(), mavenSession.getSettings().getServers());
ArtifactResolutionResult result = repositorySystem.resolve(request);
if (result.hasExceptions()) {
throw new DependencyResolutionException("resolving " + artifact + " failed!", result.getExceptions());
}
return result.getArtifacts().stream().filter(a -> a.getFile() != null).map(MavenArtifactFacade::new).toList();
// Artifact artifact;
// if (classifier != null && !classifier.isEmpty()) {
// artifact = repositorySystem.createArtifactWithClassifier(groupId, artifactId, version, packaging,
// classifier);
// } else {
// artifact = repositorySystem.createArtifact(groupId, artifactId, version, null, packaging);
// }
// logger.debug("Resolving " + artifact);
// ArtifactResolutionRequest request = new ArtifactResolutionRequest();
// request.setArtifact(artifact);
// MavenSession mavenSession = getMavenSession(session);
// request.setResolveRoot(true);
// request.setOffline(mavenSession.isOffline());
// request.setCollectionFilter(a -> isValidScope(a, scopes));
// request.setResolutionFilter(new ArtifactFilter() {
// @Override
// public boolean include(Artifact a) {
// List<String> trail = a.getDependencyTrail();
// if (logger.isDebugEnabled()) {
// logger.debug("[depth=" + trail.size() + ", scope matches =" + isValidScope(a, scopes) + "][" + a
// + "][" + trail.stream().collect(Collectors.joining(" >> ")) + "]");
// }
// return trail.size() <= depth && isValidScope(a, scopes);
// }
// });
// request.setLocalRepository(mavenSession.getLocalRepository());
// request.setResolveTransitively(depth > 0);
// request.setRemoteRepositories(
// getEffectiveRepositories(mavenSession.getCurrentProject(), additionalRepositories, repositorySystem));
// repositorySystem.injectMirror(request.getRemoteRepositories(), mavenSession.getSettings().getMirrors());
// repositorySystem.injectProxy(request.getRemoteRepositories(), mavenSession.getSettings().getProxies());
// repositorySystem.injectAuthentication(request.getRemoteRepositories(), mavenSession.getSettings().getServers());
// ArtifactResolutionResult result = repositorySystem.resolve(request);
// if (result.hasExceptions()) {
// throw new DependencyResolutionException("resolving " + artifact + " failed!", result.getExceptions());
// }
// return result.getArtifacts().stream().filter(a -> a.getFile() != null).map(MavenArtifactFacade::new).toList();
return null;
}

@SuppressWarnings("deprecation")
public static List<ArtifactRepository> getEffectiveRepositories(MavenProject project,
Collection<MavenArtifactRepositoryReference> additionalRepositories, RepositorySystem repositorySystem) {
List<ArtifactRepository> projectRepositories;
if (project == null) {
try {
projectRepositories = List.of(repositorySystem.createDefaultRemoteRepository());
} catch (InvalidRepositoryException e) {
projectRepositories = List.of();
}
} else {
projectRepositories = project.getRemoteArtifactRepositories();
}

if (additionalRepositories != null && !additionalRepositories.isEmpty()) {
List<ArtifactRepository> repositories = new ArrayList<>(projectRepositories);
for (MavenArtifactRepositoryReference reference : additionalRepositories) {
repositories.add(repositorySystem.createArtifactRepository(reference.getId(), reference.getUrl(), null,
null, null));
}
return repositorySystem.getEffectiveRepositories(repositories);
}
return projectRepositories;
// if (project == null) {
// try {
// projectRepositories = List.of(repositorySystem.createDefaultRemoteRepository());
// } catch (InvalidRepositoryException e) {
// projectRepositories = List.of();
// }
// } else {
// projectRepositories = project.getRemoteArtifactRepositories();
// }
//
// if (additionalRepositories != null && !additionalRepositories.isEmpty()) {
// List<ArtifactRepository> repositories = new ArrayList<>(projectRepositories);
// for (MavenArtifactRepositoryReference reference : additionalRepositories) {
// repositories.add(repositorySystem.createArtifactRepository(reference.getId(), reference.getUrl(), null,
// null, null));
// }
// return repositorySystem.getEffectiveRepositories(repositories);
// }
// return projectRepositories;
return null;
}

protected boolean isValidScope(Artifact artifact, Collection<String> scopes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.building.FileModelSource;
import org.apache.maven.model.building.ModelProcessor;
import org.apache.maven.model.io.ModelParseException;
import org.apache.maven.model.io.ModelReader;
import org.apache.maven.model.io.ModelWriter;
import org.codehaus.plexus.PlexusContainer;
Expand Down Expand Up @@ -150,6 +151,11 @@ public Model read(Reader input, Map<String, ?> options) throws IOException {
return read(input, file, options);
}

@Override
public Model read(Path input, Map<String, ?> options) throws IOException, ModelParseException {
return read(input.toFile(), options);
}

private Model read(Reader artifactReader, Path artifactFile, Map<String, ?> options) throws IOException {
Model model = new Model();
model.setModelVersion("4.0.0");
Expand Down

This file was deleted.

7 changes: 7 additions & 0 deletions tycho-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
<artifactId>tycho-api</artifactId>
<version>${project.version}</version>
</dependency>

<!-- legacy replace -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
8 changes: 7 additions & 1 deletion tycho-testing-harness/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
- Sonatype Inc. - initial API and implementation
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -68,6 +69,11 @@
<artifactId>sisu-osgi-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>7.0.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Loading