use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository.
@Test
public void testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository() throws ArtifactResolutionException {
session.setLocalRepositoryManager(new LocalRepositoryManager() {
public LocalRepository getRepository() {
return null;
}
public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
return null;
}
public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
return null;
}
public String getPathForLocalMetadata(Metadata metadata) {
return null;
}
public String getPathForLocalArtifact(Artifact artifact) {
return null;
}
public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
LocalArtifactResult result = new LocalArtifactResult(request);
result.setAvailable(false);
try {
result.setFile(TestFileUtils.createTempFile(""));
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
}
public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
LocalMetadataResult result = new LocalMetadataResult(request);
return result;
}
public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
}
});
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
request.addRepository(new RemoteRepository("id", "default", "file:///"));
resolver.setVersionResolver(new VersionResolver() {
public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
return new VersionResult(request).setRepository(new LocalRepository("id")).setVersion(request.getArtifact().getVersion());
}
});
ArtifactResult result = resolver.resolveArtifact(session, request);
assertTrue(result.getExceptions().isEmpty());
Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());
resolved = resolved.setFile(null);
assertEquals(artifact, resolved);
}
use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testFindInLocalRepositoryWhenVersionRangeWasResolvedFromLocalRepository.
@Test
public void testFindInLocalRepositoryWhenVersionRangeWasResolvedFromLocalRepository() throws ArtifactResolutionException {
session.setLocalRepositoryManager(new LocalRepositoryManager() {
public LocalRepository getRepository() {
return null;
}
public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
return null;
}
public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
return null;
}
public String getPathForLocalMetadata(Metadata metadata) {
return null;
}
public String getPathForLocalArtifact(Artifact artifact) {
return null;
}
public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
LocalArtifactResult result = new LocalArtifactResult(request);
result.setAvailable(false);
try {
result.setFile(TestFileUtils.createTempFile(""));
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
}
public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
LocalMetadataResult result = new LocalMetadataResult(request);
return result;
}
public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
}
});
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
resolver.setVersionResolver(new VersionResolver() {
public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
return new VersionResult(request).setVersion(request.getArtifact().getVersion());
}
});
ArtifactResult result = resolver.resolveArtifact(session, request);
assertTrue(result.getExceptions().isEmpty());
Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());
resolved = resolved.setFile(null);
assertEquals(artifact, resolved);
}
use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class DefaultMetadataResolverTest method testResolve.
@Test
public void testResolve() throws IOException {
connector.setExpectGet(metadata);
// prepare "download"
File file = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, repository, ""));
TestFileUtils.write(file.getAbsolutePath(), file);
MetadataRequest request = new MetadataRequest(metadata, repository, "");
List<MetadataResult> results = resolver.resolveMetadata(session, Arrays.asList(request));
assertEquals(1, results.size());
MetadataResult result = results.get(0);
assertSame(request, result.getRequest());
assertNull(result.getException());
assertNotNull(result.getMetadata());
assertNotNull(result.getMetadata().getFile());
assertEquals(file, result.getMetadata().getFile());
assertEquals(metadata, result.getMetadata().setFile(null));
connector.assertSeenExpected();
Set<Metadata> metadataRegistration = ((TestLocalRepositoryManager) session.getLocalRepositoryManager()).getMetadataRegistration();
assertTrue(metadataRegistration.contains(metadata));
assertEquals(1, metadataRegistration.size());
}
use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class DefaultDeployer method deploy.
private DeployResult deploy(SyncContext syncContext, RepositorySystemSession session, DeployRequest request) throws DeploymentException {
DeployResult result = new DeployResult(request);
RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
RemoteRepository repository = request.getRepository();
RepositoryConnector connector;
try {
connector = remoteRepositoryManager.getRepositoryConnector(session, repository);
} catch (NoRepositoryConnectorException e) {
throw new DeploymentException("Failed to deploy artifacts/metadata: " + e.getMessage(), e);
}
List<MetadataGenerator> generators = getMetadataGenerators(session, request);
try {
List<ArtifactUpload> artifactUploads = new ArrayList<ArtifactUpload>();
List<MetadataUpload> metadataUploads = new ArrayList<MetadataUpload>();
IdentityHashMap<Metadata, Object> processedMetadata = new IdentityHashMap<Metadata, Object>();
EventCatapult catapult = new EventCatapult(session, trace, repository, repositoryEventDispatcher);
List<Artifact> artifacts = new ArrayList<Artifact>(request.getArtifacts());
List<Metadata> metadatas = Utils.prepareMetadata(generators, artifacts);
syncContext.acquire(artifacts, Utils.combine(request.getMetadata(), metadatas));
for (Metadata metadata : metadatas) {
upload(metadataUploads, session, metadata, repository, connector, catapult);
processedMetadata.put(metadata, null);
}
for (int i = 0; i < artifacts.size(); i++) {
Artifact artifact = artifacts.get(i);
for (MetadataGenerator generator : generators) {
artifact = generator.transformArtifact(artifact);
}
artifacts.set(i, artifact);
artifactUploads.add(new ArtifactUploadEx(artifact, artifact.getFile(), catapult));
}
connector.put(artifactUploads, null);
for (ArtifactUpload upload : artifactUploads) {
if (upload.getException() != null) {
throw new DeploymentException("Failed to deploy artifacts: " + upload.getException().getMessage(), upload.getException());
}
result.addArtifact(upload.getArtifact());
}
metadatas = Utils.finishMetadata(generators, artifacts);
syncContext.acquire(null, metadatas);
for (Metadata metadata : metadatas) {
upload(metadataUploads, session, metadata, repository, connector, catapult);
processedMetadata.put(metadata, null);
}
for (Metadata metadata : request.getMetadata()) {
if (!processedMetadata.containsKey(metadata)) {
upload(metadataUploads, session, metadata, repository, connector, catapult);
processedMetadata.put(metadata, null);
}
}
connector.put(null, metadataUploads);
for (MetadataUpload upload : metadataUploads) {
if (upload.getException() != null) {
throw new DeploymentException("Failed to deploy metadata: " + upload.getException().getMessage(), upload.getException());
}
result.addMetadata(upload.getMetadata());
}
} finally {
connector.close();
}
return result;
}
use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class DefaultUpdateCheckManagerTest method testCheckMetadataNotFoundInRepoCachingDisabled.
@Test
public void testCheckMetadataNotFoundInRepoCachingDisabled() throws Exception {
metadata.getFile().delete();
session.setNotFoundCachingEnabled(false);
UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
check.setException(new MetadataNotFoundException(metadata, repository, ""));
manager.touchMetadata(session, check);
resetSessionData(session);
// ! file.exists && ! updateRequired -> artifact not found in remote repo
// ignore NotFoundCaching-setting, don't check if update policy does not say so for metadata
check.setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
manager.checkMetadata(session, check);
assertEquals(false, check.isRequired());
assertTrue(check.getException() instanceof MetadataNotFoundException);
}
Aggregations