use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class DependencyGraphParserTest method assertNodeProperties.
private void assertNodeProperties(DependencyNode node, String suffix) {
assertNotNull(node);
Dependency dependency = node.getDependency();
assertNotNull(dependency);
if (!"".equals(dependency.getScope())) {
assertEquals("scope" + suffix, dependency.getScope());
}
Artifact artifact = dependency.getArtifact();
assertNotNull(artifact);
assertEquals("gid" + suffix, artifact.getGroupId());
assertEquals("aid" + suffix, artifact.getArtifactId());
assertEquals("ext" + suffix, artifact.getExtension());
assertEquals("ver" + suffix, artifact.getVersion());
}
use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class DependencyGraphParserTest method testSubstitutions.
@Test
public void testSubstitutions() throws IOException {
parser.setSubstitutions(Arrays.asList("subst1", "subst2"));
String def = "%s:%s:ext:ver";
DependencyNode root = parser.parseLiteral(def);
Artifact artifact = root.getDependency().getArtifact();
assertEquals("subst2", artifact.getArtifactId());
assertEquals("subst1", artifact.getGroupId());
def = "%s:aid:ext:ver\n\\- %s:aid:ext:ver";
root = parser.parseLiteral(def);
assertEquals("subst1", root.getDependency().getArtifact().getGroupId());
assertEquals("subst2", root.getChildren().get(0).getDependency().getArtifact().getGroupId());
}
use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class ConnectorTestSuite method testProgressEventsDataBuffer.
@Test
public void testProgressEventsDataBuffer() throws UnsupportedEncodingException, IOException, NoSuchAlgorithmException, NoRepositoryConnectorException {
byte[] bytes = "These are the test contents.\n".getBytes("UTF-8");
int count = 120000;
MessageDigest digest = MessageDigest.getInstance("SHA-1");
for (int i = 0; i < count; i++) {
digest.update(bytes);
}
byte[] hash = digest.digest();
File file = TestFileUtils.createTempFile(bytes, count);
Artifact artifact = new StubArtifact("gid:aid:ext:ver");
ArtifactUpload upA = new ArtifactUpload(artifact, file);
File dir = TestFileUtils.createTempDir("con-test");
File downAFile = new File(dir, "downA.file");
downAFile.deleteOnExit();
ArtifactDownload downA = new ArtifactDownload(artifact, "", downAFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
Metadata metadata = new StubMetadata("gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
MetadataUpload upM = new MetadataUpload(metadata, file);
File downMFile = new File(dir, "downM.file");
downMFile.deleteOnExit();
MetadataDownload downM = new MetadataDownload(metadata, "", downMFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
DigestingTransferListener listener = new DigestingTransferListener();
session.setTransferListener(listener);
RepositoryConnector connector = factory().newInstance(session, repository);
connector.put(Arrays.asList(upA), null);
assertArrayEquals(hash, listener.getHash());
listener.rewind();
connector.put(null, Arrays.asList(upM));
assertArrayEquals(hash, listener.getHash());
listener.rewind();
connector.get(Arrays.asList(downA), null);
assertArrayEquals(hash, listener.getHash());
listener.rewind();
connector.get(null, Arrays.asList(downM));
assertArrayEquals(hash, listener.getHash());
listener.rewind();
connector.close();
}
use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class ClassicDependencyManager method deriveChildManager.
public DependencyManager deriveChildManager(DependencyCollectionContext context) {
if (depth >= 2) {
return this;
} else if (depth == 1) {
return new ClassicDependencyManager(depth + 1, managedVersions, managedScopes, managedLocalPaths, managedExclusions);
}
Map<Object, String> managedVersions = this.managedVersions;
Map<Object, String> managedScopes = this.managedScopes;
Map<Object, String> managedLocalPaths = this.managedLocalPaths;
Map<Object, Collection<Exclusion>> managedExclusions = this.managedExclusions;
for (Dependency managedDependency : context.getManagedDependencies()) {
Artifact artifact = managedDependency.getArtifact();
Object key = getKey(artifact);
String version = artifact.getVersion();
if (version.length() > 0 && !managedVersions.containsKey(key)) {
if (managedVersions == this.managedVersions) {
managedVersions = new HashMap<Object, String>(this.managedVersions);
}
managedVersions.put(key, version);
}
String scope = managedDependency.getScope();
if (scope.length() > 0 && !managedScopes.containsKey(key)) {
if (managedScopes == this.managedScopes) {
managedScopes = new HashMap<Object, String>(this.managedScopes);
}
managedScopes.put(key, scope);
}
String localPath = managedDependency.getArtifact().getProperty(ArtifactProperties.LOCAL_PATH, null);
if (localPath != null && !managedLocalPaths.containsKey(key)) {
if (managedLocalPaths == this.managedLocalPaths) {
managedLocalPaths = new HashMap<Object, String>(this.managedLocalPaths);
}
managedLocalPaths.put(key, localPath);
}
Collection<Exclusion> exclusions = managedDependency.getExclusions();
if (!exclusions.isEmpty()) {
if (managedExclusions == this.managedExclusions) {
managedExclusions = new HashMap<Object, Collection<Exclusion>>(this.managedExclusions);
}
Collection<Exclusion> managed = managedExclusions.get(key);
if (managed == null) {
managed = new LinkedHashSet<Exclusion>();
managedExclusions.put(key, managed);
}
managed.addAll(exclusions);
}
}
return new ClassicDependencyManager(depth + 1, managedVersions, managedScopes, managedLocalPaths, managedExclusions);
}
use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.
the class IniArtifactDataReaderTest 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