|
|
|
|
|
import org.fusesource.jansi.AnsiColors; |
|
import org.fusesource.jansi.AnsiMode; |
|
import org.fusesource.jansi.AnsiType; |
|
import org.fusesource.jansi.io.AnsiOutputStream; |
|
import org.fusesource.jansi.io.AnsiProcessor; |
|
import org.junit.Test; |
|
|
|
import javax.annotation.Nullable; |
|
import java.io.BufferedReader; |
|
import java.io.ByteArrayOutputStream; |
|
import java.io.IOException; |
|
import java.io.StringReader; |
|
import java.nio.charset.Charset; |
|
import java.nio.charset.StandardCharsets; |
|
import java.util.ArrayList; |
|
import java.util.Collections; |
|
import java.util.LinkedHashMap; |
|
import java.util.List; |
|
import java.util.Map; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
public class MavenDependencyTest { |
|
|
|
@Test |
|
public void parse_noModule() throws Exception { |
|
String line = " org.elasticmq:elasticmq-core_2.12:jar:0.15.6:compile"; |
|
assertNotNull(MavenDependency.parse(line)); |
|
} |
|
|
|
@Test |
|
public void parse() throws Exception { |
|
String line = " com.github.scribejava:scribejava-httpclient-apache:jar:6.9.0:compile -- module scribejava.httpclient.apache (auto)"; |
|
MavenDependency d = MavenDependency.parse(line); |
|
assertNotNull(d); |
|
assertEquals("com.github.scribejava", d.coordinates.groupId); |
|
assertEquals("scribejava-httpclient-apache", d.coordinates.artifactId); |
|
assertNull(d.coordinates.classifier); |
|
assertEquals("jar", d.coordinates.type); |
|
assertEquals("6.9.0", d.coordinates.version); |
|
assertEquals("compile", d.scope); |
|
} |
|
|
|
@Test |
|
public void parse_classifier() throws Exception { |
|
String line = " io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.53.Final:runtime -- module io.netty.transport.epoll [auto]"; |
|
MavenDependency d = MavenDependency.parse(line); |
|
assertNotNull(d); |
|
assertEquals("io.netty", d.coordinates.groupId); |
|
assertEquals("netty-transport-native-epoll", d.coordinates.artifactId); |
|
assertEquals("4.1.53.Final", d.coordinates.version); |
|
assertEquals("jar", d.coordinates.type); |
|
assertEquals("linux-x86_64", d.coordinates.classifier); |
|
} |
|
|
|
@Test |
|
public void parse_many() throws IOException { |
|
BufferedReader reader = new BufferedReader(new StringReader(dependenciesListTxt)); |
|
String line; |
|
List<String> nulls = new ArrayList<>(); |
|
List<String> nonjars = new ArrayList<>(); |
|
Map<String, MavenDependency> deps = new LinkedHashMap<>(); |
|
while ((line = reader.readLine()) != null) { |
|
if (line.startsWith(" ")) { |
|
@Nullable |
|
MavenDependency dependency = MavenDependency.parse(line); |
|
if (dependency != null) { |
|
if ("jar".equals(dependency.coordinates.type)) { |
|
deps.put(line, dependency); |
|
} else { |
|
nonjars.add(line); |
|
} |
|
} else { |
|
nulls.add(line); |
|
} |
|
} |
|
} |
|
assertEquals("nulls", Collections.emptyList(), nulls); |
|
assertEquals("nonjars", Collections.emptyList(), nonjars); |
|
deps.forEach((line_, dep) -> { |
|
assertFalse("groupId of " + line_, dep.coordinates.groupId.isBlank()); |
|
assertFalse("artifactId of " + line_, dep.coordinates.artifactId.isBlank()); |
|
assertFalse("version of " + line_, dep.coordinates.version.isBlank()); |
|
assertFalse("type of " + line_, dep.coordinates.type.isBlank()); |
|
assertFalse("scope of " + line_, dep.scope.isBlank()); |
|
}); |
|
} |
|
|
|
private static final String dependenciesListTxt = "\n" + |
|
"The following files have been resolved:\n" + |
|
" org.eclipse:yasson:jar:1.0.6:compile -- module org.eclipse.yasson\n" + |
|
" com.j256.ormlite:ormlite-core:jar:5.1:compile -- module ormlite.core (auto)\n" + |
|
" org.glassfish.hk2:hk2-locator:jar:2.6.1:compile -- module hk2.locator (auto)\n" + |
|
" org.glassfish.hk2.external:jakarta.inject:jar:2.6.1:compile -- module jakarta.inject (auto)\n" + |
|
" org.glassfish.hk2:hk2-utils:jar:2.6.1:compile -- module hk2.utils (auto)\n" + |
|
" jakarta.ws.rs:jakarta.ws.rs-api:jar:2.1.6:compile -- module java.ws.rs\n" + |
|
" org.apache.httpcomponents:httpcore-nio:jar:4.4.10:compile\n" + |
|
" org.elasticmq:elasticmq-rest-sqs_2.12:jar:0.15.6:compile\n" + |
|
" io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.53.Final:runtime -- module io.netty.transport.epoll [auto]\n" + |
|
" org.glassfish.jersey.containers:jersey-container-servlet:jar:2.33:compile -- module jersey.container.servlet (auto)\n" + |
|
" io.netty:netty-common:jar:4.1.53.Final:runtime -- module io.netty.common [auto]\n" + |
|
" org.joda:joda-convert:jar:2.2.1:compile -- module org.joda.convert\n" + |
|
"\n"; |
|
|
|
|
|
} |