use of org.sonatype.aether.spi.connector.RepositoryConnector in project sonatype-aether by sonatype.
the class DefaultDeployerTest method testStaleLocalMetadataCopyGetsDeletedBeforeMergeWhenMetadataIsNotCurrentlyPresentInRemoteRepo.
@Test
public void testStaleLocalMetadataCopyGetsDeletedBeforeMergeWhenMetadataIsNotCurrentlyPresentInRemoteRepo() throws Exception {
MergeableMetadata metadata = new MergeableMetadata() {
public Metadata setFile(File file) {
return this;
}
public String getVersion() {
return "";
}
public String getType() {
return "test.properties";
}
public Nature getNature() {
return Nature.RELEASE;
}
public String getGroupId() {
return "org";
}
public File getFile() {
return null;
}
public String getArtifactId() {
return "aether";
}
public void merge(File current, File result) throws RepositoryException {
Properties props = new Properties();
try {
if (current.isFile()) {
TestFileUtils.read(props, current);
}
props.setProperty("new", "value");
TestFileUtils.write(props, result);
} catch (IOException e) {
throw new RepositoryException(e.getMessage(), e);
}
}
public boolean isMerged() {
return false;
}
};
manager.setConnector(new RepositoryConnector() {
public void put(Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads) {
}
public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
if (metadataDownloads != null) {
for (MetadataDownload download : metadataDownloads) {
download.setException(new MetadataNotFoundException(download.getMetadata(), null, null));
}
}
}
public void close() {
}
});
request.addMetadata(metadata);
File metadataFile = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, request.getRepository(), ""));
Properties props = new Properties();
props.setProperty("old", "value");
TestFileUtils.write(props, metadataFile);
deployer.deploy(session, request);
props = new Properties();
TestFileUtils.read(props, metadataFile);
assertNull(props.toString(), props.get("old"));
}
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 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 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 testFileHandleLeakage.
@Test
public void testFileHandleLeakage() throws IOException, NoRepositoryConnectorException {
StubArtifact artifact = new StubArtifact("testGroup", "testArtifact", "", "jar", "1-test");
StubMetadata metadata = new StubMetadata("testGroup", "testArtifact", "1-test", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
RepositoryConnector connector = factory().newInstance(session, repository);
File tmpFile = TestFileUtils.createTempFile("testFileHandleLeakage");
ArtifactUpload artUp = new ArtifactUpload(artifact, tmpFile);
connector.put(Arrays.asList(artUp), null);
assertTrue("Leaking file handle in artifact upload", tmpFile.delete());
tmpFile = TestFileUtils.createTempFile("testFileHandleLeakage");
MetadataUpload metaUp = new MetadataUpload(metadata, tmpFile);
connector.put(null, Arrays.asList(metaUp));
assertTrue("Leaking file handle in metadata upload", tmpFile.delete());
tmpFile = TestFileUtils.createTempFile("testFileHandleLeakage");
ArtifactDownload artDown = new ArtifactDownload(artifact, null, tmpFile, null);
connector.get(Arrays.asList(artDown), null);
new File(tmpFile.getAbsolutePath() + ".sha1").deleteOnExit();
assertTrue("Leaking file handle in artifact download", tmpFile.delete());
tmpFile = TestFileUtils.createTempFile("testFileHandleLeakage");
MetadataDownload metaDown = new MetadataDownload(metadata, null, tmpFile, null);
connector.get(null, Arrays.asList(metaDown));
new File(tmpFile.getAbsolutePath() + ".sha1").deleteOnExit();
assertTrue("Leaking file handle in metadata download", tmpFile.delete());
connector.close();
}
Aggregations