Skip to content

Commit 83dac29

Browse files
Remove deprecated code (#11)
1 parent d223631 commit 83dac29

17 files changed

+58
-1016
lines changed

classpath-replacer/src/main/java/cr/Action.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

classpath-replacer/src/main/java/cr/ClasspathExtension.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package cr;
22

3-
import cr.util.ModifiedClassLoaderCache;
43
import java.lang.reflect.Method;
54
import java.util.List;
65
import java.util.Optional;

classpath-replacer/src/main/java/cr/ClasspathReplacer.java

Lines changed: 0 additions & 89 deletions
This file was deleted.

classpath-replacer/src/main/java/cr/ClasspathReplacerExtension.java

Lines changed: 0 additions & 176 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package cr;
2+
3+
import cr.util.Const;
4+
import java.io.File;
5+
import java.net.URL;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.regex.Pattern;
9+
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
10+
11+
/**
12+
* @author Freeman
13+
*/
14+
final class MavenUtils {
15+
private static final int MAX_RESOLUTION_ATTEMPTS = 3;
16+
17+
private MavenUtils() {
18+
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
19+
}
20+
21+
/**
22+
* Resolves Maven coordinate to a list of URLs.
23+
*
24+
* @param coordinate Maven coordinates of the form groupId:artifactId:version
25+
* @return list of URLs to the resolved artifacts
26+
*/
27+
public static List<URL> resolveCoordinate(String coordinate) {
28+
if (coordinate == null || coordinate.isEmpty()) {
29+
throw new IllegalArgumentException("Coordinate cannot be null or empty");
30+
}
31+
if (!Pattern.matches(Const.MAVEN_COORDINATE_PATTERN, coordinate)) {
32+
throw new IllegalArgumentException("Invalid Maven coordinate: " + coordinate);
33+
}
34+
Exception latestFailure = null;
35+
for (int i = 0; i < MAX_RESOLUTION_ATTEMPTS; i++) {
36+
try {
37+
File[] dependencies =
38+
Maven.resolver().resolve(coordinate).withTransitivity().asFile();
39+
List<URL> result = new ArrayList<>();
40+
for (File dependency : dependencies) {
41+
result.add(dependency.toURI().toURL());
42+
}
43+
return result;
44+
} catch (Exception ex) {
45+
latestFailure = ex;
46+
}
47+
}
48+
throw new IllegalStateException(
49+
"Resolution failed after " + MAX_RESOLUTION_ATTEMPTS + " attempts", latestFailure);
50+
}
51+
}

classpath-replacer/src/main/java/cr/util/ModifiedClassLoaderCache.java renamed to classpath-replacer/src/main/java/cr/ModifiedClassLoaderCache.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package cr.util;
1+
package cr;
22

3-
import cr.ModifiedClassPathClassLoader;
43
import java.util.concurrent.ConcurrentHashMap;
54
import java.util.concurrent.ConcurrentMap;
65
import java.util.function.Supplier;
@@ -12,7 +11,7 @@ public final class ModifiedClassLoaderCache {
1211

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

15-
public static ModifiedClassPathClassLoader get(Class<?> testClass) {
14+
/*private*/ static ModifiedClassPathClassLoader get(Class<?> testClass) {
1615
return cache.get(testClass);
1716
}
1817

classpath-replacer/src/main/java/cr/ModifiedClassPathClassLoaderBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import cr.action.Add;
44
import cr.action.Exclude;
55
import cr.util.Const;
6-
import cr.util.MavenUtils;
76
import java.io.File;
87
import java.lang.management.ManagementFactory;
98
import java.net.URISyntaxException;

0 commit comments

Comments
 (0)