use of org.sonatype.aether.spi.connector.RepositoryConnector in project sonatype-aether by sonatype.
the class DefaultRemoteRepositoryManager method getRepositoryConnector.
public RepositoryConnector getRepositoryConnector(RepositorySystemSession session, RemoteRepository repository) throws NoRepositoryConnectorException {
if (repository == null) {
throw new IllegalArgumentException("remote repository has not been specified");
}
List<RepositoryConnectorFactory> factories = new ArrayList<RepositoryConnectorFactory>(connectorFactories);
Collections.sort(factories, COMPARATOR);
for (RepositoryConnectorFactory factory : factories) {
try {
RepositoryConnector connector = factory.newInstance(session, repository);
if (logger.isDebugEnabled()) {
StringBuilder buffer = new StringBuilder(256);
buffer.append("Using connector ").append(connector.getClass().getSimpleName());
buffer.append(" with priority ").append(factory.getPriority());
buffer.append(" for ").append(repository.getUrl());
Authentication auth = repository.getAuthentication();
if (auth != null) {
buffer.append(" as ").append(auth.getUsername());
}
Proxy proxy = repository.getProxy();
if (proxy != null) {
buffer.append(" via ").append(proxy.getHost()).append(':').append(proxy.getPort());
auth = proxy.getAuthentication();
if (auth != null) {
buffer.append(" as ").append(auth.getUsername());
}
}
logger.debug(buffer.toString());
}
return connector;
} catch (NoRepositoryConnectorException e) {
// continue and try next factory
}
}
StringBuilder buffer = new StringBuilder(256);
buffer.append("No connector available to access repository ");
buffer.append(repository.getId());
buffer.append(" (").append(repository.getUrl());
buffer.append(") of type ").append(repository.getContentType());
buffer.append(" using the available factories ");
for (ListIterator<RepositoryConnectorFactory> it = factories.listIterator(); it.hasNext(); ) {
RepositoryConnectorFactory factory = it.next();
buffer.append(factory.getClass().getSimpleName());
if (it.hasNext()) {
buffer.append(", ");
}
}
throw new NoRepositoryConnectorException(repository, buffer.toString());
}
use of org.sonatype.aether.spi.connector.RepositoryConnector 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.spi.connector.RepositoryConnector in project sonatype-aether by sonatype.
the class ResumeGetTest method testResumeInterruptedDownloadUsingRangeRequests.
@Test
public void testResumeInterruptedDownloadUsingRangeRequests() throws Exception {
FlakyHandler flakyHandler = new FlakyHandler(4);
server.setHandler(flakyHandler);
server.start();
File file = TestFileUtils.createTempFile("");
file.delete();
ArtifactDownload download = new ArtifactDownload(artifact, "", file, RepositoryPolicy.CHECKSUM_POLICY_IGNORE);
RemoteRepository repo = new RemoteRepository("test", "default", url());
RepositoryConnector connector = factory.newInstance(session, repo);
try {
connector.get(Arrays.asList(download), null);
} finally {
connector.close();
}
assertNull(String.valueOf(download.getException()), download.getException());
assertTrue("Missing " + file.getAbsolutePath(), file.isFile());
assertEquals("Bad size of " + file.getAbsolutePath(), flakyHandler.totalSize, file.length());
assertContentPattern(file);
}
use of org.sonatype.aether.spi.connector.RepositoryConnector in project sonatype-aether by sonatype.
the class ConnectorTestSuite method testBlocking.
@Test
public void testBlocking() throws NoRepositoryConnectorException, IOException {
RepositoryConnector connector = factory().newInstance(session, repository);
int count = 10;
byte[] pattern = "tmpFile".getBytes("UTF-8");
File tmpFile = TestFileUtils.createTempFile(pattern, 100000);
List<ArtifactUpload> artUps = ConnectorTestUtils.createTransfers(ArtifactUpload.class, count, tmpFile);
List<MetadataUpload> metaUps = ConnectorTestUtils.createTransfers(MetadataUpload.class, count, tmpFile);
List<ArtifactDownload> artDowns = ConnectorTestUtils.createTransfers(ArtifactDownload.class, count, null);
List<MetadataDownload> metaDowns = ConnectorTestUtils.createTransfers(MetadataDownload.class, count, null);
// this should block until all transfers are done - racing condition, better way to test this?
connector.put(artUps, metaUps);
connector.get(artDowns, metaDowns);
for (int i = 0; i < count; i++) {
ArtifactUpload artUp = artUps.get(i);
MetadataUpload metaUp = metaUps.get(i);
ArtifactDownload artDown = artDowns.get(i);
MetadataDownload metaDown = metaDowns.get(i);
assertTrue(Transfer.State.DONE.equals(artUp.getState()));
assertTrue(Transfer.State.DONE.equals(artDown.getState()));
assertTrue(Transfer.State.DONE.equals(metaUp.getState()));
assertTrue(Transfer.State.DONE.equals(metaDown.getState()));
}
connector.close();
}
use of org.sonatype.aether.spi.connector.RepositoryConnector 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();
}
Aggregations