Skip to content
Merged
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
33 changes: 0 additions & 33 deletions classpath-replacer/src/main/java/cr/Action.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cr;

import cr.util.ModifiedClassLoaderCache;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Optional;
Expand Down
89 changes: 0 additions & 89 deletions classpath-replacer/src/main/java/cr/ClasspathReplacer.java

This file was deleted.

176 changes: 0 additions & 176 deletions classpath-replacer/src/main/java/cr/ClasspathReplacerExtension.java

This file was deleted.

51 changes: 51 additions & 0 deletions classpath-replacer/src/main/java/cr/MavenUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cr;

import cr.util.Const;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;

/**
* @author Freeman
*/
final class MavenUtils {
private static final int MAX_RESOLUTION_ATTEMPTS = 3;

private MavenUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/**
* Resolves Maven coordinate to a list of URLs.
*
* @param coordinate Maven coordinates of the form groupId:artifactId:version
* @return list of URLs to the resolved artifacts
*/
public static List<URL> resolveCoordinate(String coordinate) {
if (coordinate == null || coordinate.isEmpty()) {
throw new IllegalArgumentException("Coordinate cannot be null or empty");
}
if (!Pattern.matches(Const.MAVEN_COORDINATE_PATTERN, coordinate)) {
throw new IllegalArgumentException("Invalid Maven coordinate: " + coordinate);
}
Exception latestFailure = null;
for (int i = 0; i < MAX_RESOLUTION_ATTEMPTS; i++) {
try {
File[] dependencies =
Maven.resolver().resolve(coordinate).withTransitivity().asFile();
List<URL> result = new ArrayList<>();
for (File dependency : dependencies) {
result.add(dependency.toURI().toURL());
}
return result;
} catch (Exception ex) {
latestFailure = ex;
}
}
throw new IllegalStateException(
"Resolution failed after " + MAX_RESOLUTION_ATTEMPTS + " attempts", latestFailure);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cr.util;
package cr;

import cr.ModifiedClassPathClassLoader;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Supplier;
Expand All @@ -12,7 +11,7 @@ public final class ModifiedClassLoaderCache {

private static final ConcurrentMap<Class<?>, ModifiedClassPathClassLoader> cache = new ConcurrentHashMap<>();

public static ModifiedClassPathClassLoader get(Class<?> testClass) {
/*private*/ static ModifiedClassPathClassLoader get(Class<?> testClass) {
return cache.get(testClass);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cr.action.Add;
import cr.action.Exclude;
import cr.util.Const;
import cr.util.MavenUtils;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.net.URISyntaxException;
Expand Down
Loading