use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class ConnectorTestUtils method createTransfers.
/**
* Creates transfer objects according to the given class. If the file parameter is {@code null}, a new temporary
* file will be created for downloads. Uploads will just use the parameter as it is.
*/
public static <T extends Transfer> List<T> createTransfers(Class<T> cls, int count, File file) {
ArrayList<T> ret = new ArrayList<T>();
Object item;
if (ArtifactTransfer.class.isAssignableFrom(cls)) {
item = new StubArtifact("testGroup", "testArtifact", "sources", "jar", "will be replaced");
} else {
item = new StubMetadata("testGroup", "testArtifact", "will be replaced", "jar", Metadata.Nature.RELEASE_OR_SNAPSHOT, file);
}
for (int i = 0; i < count; i++) {
String context = null;
String checksumPolicy = RepositoryPolicy.CHECKSUM_POLICY_IGNORE;
Object obj = null;
if (cls.isAssignableFrom(ArtifactUpload.class)) {
Artifact artifact = ((Artifact) item).setVersion((i + 1) + "-test");
obj = new ArtifactUpload(artifact, file);
} else if (cls.isAssignableFrom(ArtifactDownload.class)) {
try {
Artifact artifact = ((Artifact) item).setVersion((i + 1) + "-test");
obj = new ArtifactDownload(artifact, context, safeFile(file), checksumPolicy);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
} else if (cls.isAssignableFrom(MetadataUpload.class)) {
Metadata metadata = ((StubMetadata) item).setVersion((i + 1) + "-test");
obj = new MetadataUpload(metadata, file);
} else if (cls.isAssignableFrom(MetadataDownload.class)) {
try {
Metadata metadata = ((StubMetadata) item).setVersion((i + 1) + "-test");
obj = new MetadataDownload(metadata, context, safeFile(file), checksumPolicy);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
ret.add(cls.cast(obj));
}
return ret;
}
use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class DependencyGraphParserTest method testOnlyRoot.
@Test
public void testOnlyRoot() throws IOException {
String def = "gid:aid:jar:1:scope";
DependencyNode node = parser.parseLiteral(def);
assertNotNull(node);
assertEquals(0, node.getChildren().size());
Dependency dependency = node.getDependency();
assertNotNull(dependency);
assertEquals("scope", dependency.getScope());
Artifact artifact = dependency.getArtifact();
assertNotNull(artifact);
assertEquals("gid", artifact.getGroupId());
assertEquals("aid", artifact.getArtifactId());
assertEquals("jar", artifact.getExtension());
assertEquals("1", artifact.getVersion());
}
use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class IniArtifactDataReaderTest method testRelocations.
@Test
public void testRelocations() throws IOException {
String def = "[relocations]\ngid:aid:ext:ver\ngid2:aid2:ext2:ver2";
ArtifactDescription description = parser.parseLiteral(def);
List<Artifact> relocations = description.getRelocations();
assertNotNull(relocations);
assertEquals(2, relocations.size());
Artifact artifact = relocations.get(0);
assertEquals("aid", artifact.getArtifactId());
assertEquals("gid", artifact.getGroupId());
assertEquals("ver", artifact.getVersion());
assertEquals("ext", artifact.getExtension());
artifact = relocations.get(1);
assertEquals("aid2", artifact.getArtifactId());
assertEquals("gid2", artifact.getGroupId());
assertEquals("ver2", artifact.getVersion());
assertEquals("ext2", artifact.getExtension());
}
use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class DependencyGraphParser method addNode.
private void addNode(DependencyNode root, int level, List<NodeEntry> entries) {
NodeEntry entry = new NodeEntry();
Dependency dependency = root.getDependency();
StringBuilder defBuilder = new StringBuilder();
if (dependency == null) {
defBuilder.append("(null)");
} else {
Artifact artifact = dependency.getArtifact();
defBuilder.append(artifact.getGroupId()).append(":").append(artifact.getArtifactId()).append(":").append(artifact.getExtension()).append(":").append(artifact.getVersion());
if (dependency.getScope() != null && (!"".equals(dependency.getScope()))) {
defBuilder.append(":").append(dependency.getScope());
}
Map<String, String> properties = artifact.getProperties();
if (!(properties == null || properties.isEmpty())) {
for (Map.Entry<String, String> prop : properties.entrySet()) {
defBuilder.append(";").append(prop.getKey()).append("=").append(prop.getValue());
}
}
}
entry.setDefinition(defBuilder.toString());
entry.setLevel(level++);
entries.add(entry);
for (DependencyNode node : root.getChildren()) {
addNode(node, level, entries);
}
}
use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class IniArtifactDescriptorReaderTest method assertDependencies.
private void assertDependencies(List<Dependency> deps) {
assertEquals(4, deps.size());
Dependency dep = deps.get(0);
assertEquals("scope", dep.getScope());
assertEquals(false, dep.isOptional());
assertEquals(2, dep.getExclusions().size());
Iterator<Exclusion> it = dep.getExclusions().iterator();
Exclusion excl = it.next();
assertEquals("gid3", excl.getGroupId());
assertEquals("aid", excl.getArtifactId());
excl = it.next();
assertEquals("gid2", excl.getGroupId());
assertEquals("aid2", excl.getArtifactId());
Artifact art = dep.getArtifact();
assertEquals("gid", art.getGroupId());
assertEquals("aid", art.getArtifactId());
assertEquals("ver", art.getVersion());
assertEquals("ext", art.getExtension());
dep = deps.get(1);
assertEquals("scope", dep.getScope());
assertEquals(true, dep.isOptional());
assertEquals(0, dep.getExclusions().size());
art = dep.getArtifact();
assertEquals("gid", art.getGroupId());
assertEquals("aid2", art.getArtifactId());
assertEquals("ver", art.getVersion());
assertEquals("ext", art.getExtension());
dep = deps.get(2);
assertEquals("scope", dep.getScope());
assertEquals(true, dep.isOptional());
assertEquals(0, dep.getExclusions().size());
art = dep.getArtifact();
assertEquals("gid", art.getGroupId());
assertEquals("aid", art.getArtifactId());
assertEquals("ver3", art.getVersion());
assertEquals("ext", art.getExtension());
dep = deps.get(3);
assertEquals("scope5", dep.getScope());
assertEquals(true, dep.isOptional());
assertEquals(0, dep.getExclusions().size());
art = dep.getArtifact();
assertEquals("gid1", art.getGroupId());
assertEquals("aid", art.getArtifactId());
assertEquals("ver", art.getVersion());
assertEquals("ext", art.getExtension());
}
Aggregations