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

Use MIMA #218

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 13 additions & 11 deletions layrry-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,21 @@
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<groupId>eu.maveniverse.maven.mima</groupId>
<artifactId>context</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api-maven</artifactId>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
</dependency>
<dependency>
<groupId>eu.maveniverse.maven.mima.runtime</groupId>
<artifactId>standalone-static-uber</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.methvin</groupId>
Expand All @@ -71,12 +80,5 @@
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-depchain</artifactId>
<version>1.2.6</version>
<scope>test</scope>
<type>pom</type>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

import java.nio.file.Path;

import org.jboss.shrinkwrap.resolver.api.InvalidConfigurationFileException;

/**
* Configures remote artifact resolution.
*/
Expand All @@ -38,8 +36,6 @@ public interface RemoteResolve {
* @return Modified instance of {@code RemoteMaven}
* @throws IllegalArgumentException
* If the file is not specified, is a directory, or does not exist
* @throws InvalidConfigurationFileException
* If the file is not in correct format
*/
RemoteResolve fromFile(Path file);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.moditect.layrry.Layers;
import org.moditect.layrry.LocalResolve;
import org.moditect.layrry.RemoteResolve;
Expand Down Expand Up @@ -218,7 +219,12 @@ private ModuleLayer createModuleLayer(List<ModuleLayer> parentLayers, List<Path>

private List<Path> getModulePathEntries(Layer layer) {
List<String> moduleGavs = layer.getModuleGavs();
return Arrays.asList(resolve.resolve(moduleGavs).asPath());
try {
return Arrays.asList(resolve.resolve(moduleGavs).asPath());
}
catch (ArtifactResolutionException e) {
throw new IllegalStateException(e);
}
}

private Class<?> getMainClass(String main) throws ClassNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.nio.file.Path;

import org.jboss.shrinkwrap.resolver.api.InvalidConfigurationFileException;
import org.moditect.layrry.RemoteResolve;

public class RemoteResolveImpl implements RemoteResolve {
Expand Down Expand Up @@ -63,7 +62,7 @@ public RemoteResolveImpl enabled(boolean enabled) {
}

@Override
public RemoteResolveImpl fromFile(Path file) throws IllegalArgumentException, InvalidConfigurationFileException {
public RemoteResolveImpl fromFile(Path file) throws IllegalArgumentException {
this.fromFile = file;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

import java.util.Collection;

import org.jboss.shrinkwrap.resolver.api.CoordinateParseException;
import org.jboss.shrinkwrap.resolver.api.ResolutionException;
import org.eclipse.aether.resolution.ArtifactResolutionException;

/**
* Resolves artifacts using local and remote repositories.
Expand All @@ -30,10 +29,10 @@ public interface ArtifactResolver {
* @return The {@link CompositeFormatStage} for the user to define the artifact format to use.
* @throws IllegalStateException
* If no dependencies have yet been added
* @throws ResolutionException
* @throws ArtifactResolutionException
* If an error occurred in resolution
*/
CompositeFormatStage resolve() throws IllegalStateException, ResolutionException;
CompositeFormatStage resolve() throws IllegalStateException, ArtifactResolutionException;

/**
* Begins resolution by defining the single desired dependency (in canonical form).
Expand All @@ -43,12 +42,10 @@ public interface ArtifactResolver {
* @return The {@link CompositeFormatStage} for the user to define the artifact format to use.
* @throws IllegalArgumentException
* If no coordinate is supplied
* @throws ResolutionException
* @throws ArtifactResolutionException
* If an error occurred in resolution
* @throws CoordinateParseException
* If the specified canonical form is invalid
*/
CompositeFormatStage resolve(String canonicalForm) throws IllegalArgumentException, ResolutionException, CoordinateParseException;
CompositeFormatStage resolve(String canonicalForm) throws IllegalArgumentException, ArtifactResolutionException;

/**
* Begins resolution by defining a set of desired dependencies (in canonical form).
Expand All @@ -58,12 +55,10 @@ public interface ArtifactResolver {
* @return The {@link CompositeFormatStage} for the user to define the artifact format to use.
* @throws IllegalArgumentException
* If no coordinates are supplied
* @throws ResolutionException
* @throws ArtifactResolutionException
* If an error occurred in resolution
* @throws CoordinateParseException
* If one or more of the specified canonical forms is invalid
*/
CompositeFormatStage resolve(String... canonicalForms) throws IllegalArgumentException, ResolutionException, CoordinateParseException;
CompositeFormatStage resolve(String... canonicalForms) throws IllegalArgumentException, ArtifactResolutionException;

/**
* Begins resolution by defining a set of desired dependencies (in canonical form).
Expand All @@ -73,10 +68,8 @@ public interface ArtifactResolver {
* @return The {@link CompositeFormatStage} for the user to define the artifact format to use.
* @throws IllegalArgumentException
* If no coordinates are supplied
* @throws ResolutionException
* @throws ArtifactResolutionException
* If an error occurred in resolution
* @throws CoordinateParseException
* If one or more of the specified canonical forms is invalid
*/
CompositeFormatStage resolve(Collection<String> canonicalForms) throws IllegalArgumentException, ResolutionException, CoordinateParseException;
CompositeFormatStage resolve(Collection<String> canonicalForms) throws IllegalArgumentException, ArtifactResolutionException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jboss.shrinkwrap.resolver.api.maven.PackagingType;
import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate;
import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinates;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;

class ArtifactUtils {
private static final Pattern ARTIFACT_PATTERN = Pattern.compile("(.*?)\\-(\\d[\\d+\\.]*?)\\.jar");
private static final Pattern ARTIFACT_PATTERN2 = Pattern.compile("(.*?)\\-(\\d[\\d+\\-_A-Za-z\\.]*?)\\.jar");

static Artifact fromCanonical(String canonicalForm) {
return new DefaultArtifact(canonicalForm); // unsure what "canonical form" is, so change here if needed
}

static LocalResolvedArtifact fromPaths(Path basedir, Path file) {
String version = file.getParent().toFile().getName();
String artifactId = file.getParent().getParent().toFile().getName();
Expand All @@ -57,7 +60,7 @@ static LocalResolvedArtifact fromPaths(Path basedir, Path file) {
classifier = matcher.group(1);
}

MavenCoordinate mavenCoordinate = MavenCoordinates.createCoordinate(groupId, artifactId, version, PackagingType.JAR, classifier);
Artifact mavenCoordinate = new DefaultArtifact(groupId, artifactId, classifier, "jar", version);
return new LocalResolvedArtifactImpl(mavenCoordinate, file.toFile());
}

Expand All @@ -67,7 +70,7 @@ static LocalResolvedArtifact fromFile(File file) {
String artifactId = matcher.group(1);
String version = matcher.group(2);

MavenCoordinate mavenCoordinate = MavenCoordinates.createCoordinate("*", artifactId, version, PackagingType.JAR, null);
Artifact mavenCoordinate = new DefaultArtifact("*", artifactId, null, "jar", version);
return new LocalResolvedArtifactImpl(mavenCoordinate, file);
}

Expand All @@ -85,7 +88,7 @@ static LocalResolvedArtifact fromFile(File file) {
}

// can't tell if version has classifier or not
MavenCoordinate mavenCoordinate = MavenCoordinates.createCoordinate("*", artifactId, version, PackagingType.JAR, null);
Artifact mavenCoordinate = new DefaultArtifact("*", artifactId, null, "jar", version);
return new LocalResolvedArtifactImpl(mavenCoordinate, file);
}

Expand Down Expand Up @@ -117,7 +120,7 @@ private static LocalResolvedArtifact resolveFromPomProperties(File file, String
}
}

MavenCoordinate mavenCoordinate = MavenCoordinates.createCoordinate(props.getProperty("groupId"), artifactId, v, PackagingType.JAR, classifier);
Artifact mavenCoordinate = new DefaultArtifact(props.getProperty("groupId"), artifactId, classifier, "jar", v);
return new LocalResolvedArtifactImpl(mavenCoordinate, file);
}
}
Expand All @@ -128,15 +131,15 @@ private static LocalResolvedArtifact resolveFromPomProperties(File file, String
return null;
}

static boolean coordinatesMatch(MavenCoordinate a, MavenCoordinate b) {
static boolean coordinatesMatch(Artifact a, Artifact b) {
// Do we have an exact match?
if (a.equals(b) && a.getVersion().equals(b.getVersion()))
return true;

// Is the group missing?
if ("*".equals(a.getGroupId()) || "*".equals(b.getGroupId())) {
a = MavenCoordinates.createCoordinate("*", a.getArtifactId(), a.getVersion(), a.getPackaging(), a.getClassifier());
b = MavenCoordinates.createCoordinate("*", b.getArtifactId(), b.getVersion(), b.getPackaging(), b.getClassifier());
a = new DefaultArtifact("*", a.getArtifactId(), a.getClassifier(), a.getExtension(), a.getVersion());
b = new DefaultArtifact("*", b.getArtifactId(), b.getClassifier(), b.getExtension(), b.getVersion());
}
if (a.equals(b) && a.getVersion().equals(b.getVersion()))
return true;
Expand All @@ -148,7 +151,7 @@ static boolean coordinatesMatch(MavenCoordinate a, MavenCoordinate b) {
if (!isBlank(bc) && isBlank(ac)) {
// let b.version += " " + b.classifier
// b.classifier = null
b = MavenCoordinates.createCoordinate(b.getGroupId(), b.getArtifactId(), b.getVersion() + "-" + bc, b.getPackaging(), null);
b = new DefaultArtifact(b.getGroupId(), b.getArtifactId(), b.getClassifier(), null, b.getVersion() + "-" + bc);
}

return a.equals(b) && a.getVersion().equals(b.getVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,39 @@
*/
package org.moditect.layrry.internal.resolver;

import java.io.File;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.stream.Collectors;

import org.jboss.shrinkwrap.resolver.api.maven.MavenFormatStage;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.resolution.ArtifactResult;

public class CompositeFormatStageImpl implements CompositeFormatStage {
private final LocalFormatStage local;
private final MavenFormatStage remote;
private final Collection<ArtifactResult> remote;

public CompositeFormatStageImpl(LocalFormatStage local, MavenFormatStage remote) {
public CompositeFormatStageImpl(LocalFormatStage local, Collection<ArtifactResult> remote) {
this.local = local != null ? local : new EmptyLocalFormatStage();
this.remote = remote != null ? remote : new EmptyFormatStage();
this.remote = remote != null ? remote : Collections.emptyList();
}

private Path[] remoteAsPathArray() {
return remote.stream()
.map(ArtifactResult::getArtifact)
.map(Artifact::getFile)
.filter(Objects::nonNull)
.map(File::toPath)
.collect(Collectors.toSet())
.toArray(new Path[remote.size()]);
}

@Override
public Path[] asPath() {
Path[] a = local.asPath();
Path[] b = remote.as(Path.class);
Path[] b = remoteAsPathArray();
Path[] c = new Path[a.length + b.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(b, 0, c, a.length, b.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import java.util.LinkedHashMap;
import java.util.Map;

import org.jboss.shrinkwrap.resolver.api.CoordinateParseException;
import org.jboss.shrinkwrap.resolver.api.ResolutionException;
import org.eclipse.aether.resolution.ArtifactResolutionException;

public class ConfigurableLocalArtifactResolverSystemImpl implements ConfigurableLocalArtifactResolverSystem {
private final Map<String, LocalRepository> localRepositories = new LinkedHashMap<>();
Expand Down Expand Up @@ -60,7 +59,7 @@ public ConfigurableLocalArtifactResolverSystem withLocalRepo(LocalRepository rep
}

@Override
public LocalFormatStage resolve() throws IllegalStateException, ResolutionException {
public LocalFormatStage resolve() throws IllegalStateException, ArtifactResolutionException {
Collection<LocalResolvedArtifact> artifacts = new ArrayList<>();

for (LocalRepository repository : localRepositories.values()) {
Expand All @@ -71,7 +70,7 @@ public LocalFormatStage resolve() throws IllegalStateException, ResolutionExcept
}

@Override
public LocalFormatStage resolve(String canonicalForm) throws IllegalArgumentException, ResolutionException, CoordinateParseException {
public LocalFormatStage resolve(String canonicalForm) throws IllegalArgumentException, ArtifactResolutionException {
Collection<LocalResolvedArtifact> artifacts = new ArrayList<>();

for (LocalRepository repository : localRepositories.values()) {
Expand All @@ -82,7 +81,7 @@ public LocalFormatStage resolve(String canonicalForm) throws IllegalArgumentExce
}

@Override
public LocalFormatStage resolve(String... canonicalForms) throws IllegalArgumentException, ResolutionException, CoordinateParseException {
public LocalFormatStage resolve(String... canonicalForms) throws IllegalArgumentException, ArtifactResolutionException {
Collection<LocalResolvedArtifact> artifacts = new ArrayList<>();

for (LocalRepository repository : localRepositories.values()) {
Expand All @@ -93,7 +92,7 @@ public LocalFormatStage resolve(String... canonicalForms) throws IllegalArgument
}

@Override
public LocalFormatStage resolve(Collection<String> canonicalForms) throws IllegalArgumentException, ResolutionException, CoordinateParseException {
public LocalFormatStage resolve(Collection<String> canonicalForms) throws IllegalArgumentException, ArtifactResolutionException {
Collection<LocalResolvedArtifact> artifacts = new ArrayList<>();

for (LocalRepository repository : localRepositories.values()) {
Expand Down
Loading