use of org.apache.maven.wagon.Wagon in project archiva by apache.
the class Maven2RepositoryMetadataResolverMRM1411Test method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
c = new Configuration();
testRepo = new ManagedRepositoryConfiguration();
testRepo.setId(TEST_REPO_ID);
testRepo.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
testRepo.setReleases(true);
testRepo.setSnapshots(true);
c.addManagedRepository(testRepo);
RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
testRemoteRepo.setId(TEST_REMOTE_REPO_ID);
testRemoteRepo.setLayout("default");
testRemoteRepo.setName("Central Repository");
testRemoteRepo.setUrl("http://central.repo.com/maven2");
testRemoteRepo.setTimeout(10);
c.addRemoteRepository(testRemoteRepo);
ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
proxyConnector.setSourceRepoId(TEST_REPO_ID);
proxyConnector.setTargetRepoId(TEST_REMOTE_REPO_ID);
proxyConnector.setDisabled(false);
c.addProxyConnector(proxyConnector);
configuration.save(c);
repositoryRegistry.reload();
assertTrue(c.getManagedRepositories().get(0).isSnapshots());
assertTrue(c.getManagedRepositories().get(0).isReleases());
wagonFactory = mock(WagonFactory.class);
storage.setWagonFactory(wagonFactory);
Wagon wagon = new MockWagon();
when(wagonFactory.getWagon(new WagonFactoryRequest("wagon#http", new HashMap<String, String>()))).thenReturn(wagon);
}
use of org.apache.maven.wagon.Wagon in project archiva by apache.
the class Maven2RepositoryMetadataResolverTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
c = new Configuration();
c.setVersion("2.0");
testRepo = new ManagedRepositoryConfiguration();
testRepo.setId(TEST_REPO_ID);
testRepo.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
testRepo.setReleases(true);
testRepo.setSnapshots(true);
c.addManagedRepository(testRepo);
RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
testRemoteRepo.setId(TEST_REMOTE_REPO_ID);
testRemoteRepo.setLayout("default");
testRemoteRepo.setName("Central Repository");
testRemoteRepo.setUrl("http://central.repo.com/maven2");
testRemoteRepo.setTimeout(10);
c.addRemoteRepository(testRemoteRepo);
ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
proxyConnector.setSourceRepoId(TEST_REPO_ID);
proxyConnector.setTargetRepoId(TEST_REMOTE_REPO_ID);
proxyConnector.setDisabled(false);
c.addProxyConnector(proxyConnector);
RepositoryScanningConfiguration scCfg = new RepositoryScanningConfiguration();
c.setRepositoryScanning(scCfg);
configuration.save(c);
assertFalse(configuration.isDefaulted());
repositoryRegistry.reload();
assertTrue(c.getManagedRepositories().get(0).isSnapshots());
assertTrue(c.getManagedRepositories().get(0).isReleases());
wagonFactory = mock(WagonFactory.class);
storage.setWagonFactory(wagonFactory);
Wagon wagon = new MockWagon();
when(wagonFactory.getWagon(new WagonFactoryRequest().protocol("wagon#http"))).thenReturn(wagon);
}
use of org.apache.maven.wagon.Wagon in project archiva by apache.
the class RepositoryModelResolver method getModelFromProxy.
// FIXME: we need to do some refactoring, we cannot re-use the proxy components of archiva-proxy in maven2-repository
// because it's causing a cyclic dependency
private boolean getModelFromProxy(RemoteRepository remoteRepository, String groupId, String artifactId, String version, String filename) throws AuthorizationException, TransferFailedException, ResourceDoesNotExistException, WagonFactoryException, XMLException, IOException {
boolean success = false;
Path tmpMd5 = null;
Path tmpSha1 = null;
Path tmpResource = null;
String artifactPath = pathTranslator.toPath(groupId, artifactId, version, filename);
Path resource = Paths.get(targetRepository.getLocation()).resolve(artifactPath);
Path workingDirectory = createWorkingDirectory(targetRepository.getLocation().toString());
try {
Wagon wagon = null;
try {
String protocol = getProtocol(remoteRepository.getLocation().toString());
final NetworkProxy networkProxy = this.networkProxyMap.get(remoteRepository.getId());
wagon = wagonFactory.getWagon(new WagonFactoryRequest("wagon#" + protocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
if (wagon == null) {
throw new RuntimeException("Unsupported remote repository protocol: " + protocol);
}
boolean connected = connectToRepository(wagon, remoteRepository);
if (connected) {
tmpResource = workingDirectory.resolve(filename);
if (VersionUtil.isSnapshot(version)) {
// get the metadata first!
Path tmpMetadataResource = workingDirectory.resolve(METADATA_FILENAME);
String metadataPath = StringUtils.substringBeforeLast(artifactPath, "/") + "/" + METADATA_FILENAME;
wagon.get(addParameters(metadataPath, remoteRepository), tmpMetadataResource.toFile());
log.debug("Successfully downloaded metadata.");
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read(tmpMetadataResource);
// re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename
SnapshotVersion snapshotVersion = metadata.getSnapshotVersion();
String timestampVersion = version;
if (snapshotVersion != null) {
timestampVersion = timestampVersion.substring(0, timestampVersion.length() - // remove SNAPSHOT from end
8);
timestampVersion = timestampVersion + snapshotVersion.getTimestamp() + "-" + snapshotVersion.getBuildNumber();
filename = artifactId + "-" + timestampVersion + ".pom";
artifactPath = pathTranslator.toPath(groupId, artifactId, version, filename);
log.debug("New artifactPath :{}", artifactPath);
}
}
log.info("Retrieving {} from {}", artifactPath, remoteRepository.getName());
wagon.get(addParameters(artifactPath, remoteRepository), tmpResource.toFile());
log.debug("Downloaded successfully.");
tmpSha1 = transferChecksum(wagon, remoteRepository, artifactPath, tmpResource, workingDirectory, ".sha1");
tmpMd5 = transferChecksum(wagon, remoteRepository, artifactPath, tmpResource, workingDirectory, ".md5");
}
} finally {
if (wagon != null) {
try {
wagon.disconnect();
} catch (ConnectionException e) {
log.warn("Unable to disconnect wagon.", e);
}
}
}
if (resource != null) {
synchronized (resource.toAbsolutePath().toString().intern()) {
Path directory = resource.getParent();
moveFileIfExists(tmpMd5, directory);
moveFileIfExists(tmpSha1, directory);
moveFileIfExists(tmpResource, directory);
success = true;
}
}
} finally {
org.apache.archiva.common.utils.FileUtils.deleteQuietly(workingDirectory);
}
return success;
}
use of org.apache.maven.wagon.Wagon in project archiva by apache.
the class DefaultRepositoryProxyConnectors method transferResources.
/**
* @param connector
* @param remoteRepository
* @param tmpMd5
* @param tmpSha1
* @param tmpResource
* @param url
* @param remotePath
* @param resource
* @param workingDirectory
* @param repository
* @throws ProxyException
* @throws NotModifiedException
* @throws org.apache.archiva.admin.model.RepositoryAdminException
*/
protected void transferResources(ProxyConnector connector, RemoteRepositoryContent remoteRepository, Path tmpMd5, Path tmpSha1, Path tmpResource, String url, String remotePath, Path resource, Path workingDirectory, ManagedRepositoryContent repository) throws ProxyException, NotModifiedException, RepositoryAdminException {
Wagon wagon = null;
try {
RepositoryURL repoUrl = remoteRepository.getURL();
String protocol = repoUrl.getProtocol();
NetworkProxy networkProxy = null;
if (StringUtils.isNotBlank(connector.getProxyId())) {
networkProxy = networkProxyAdmin.getNetworkProxy(connector.getProxyId());
}
WagonFactoryRequest wagonFactoryRequest = new WagonFactoryRequest("wagon#" + protocol, remoteRepository.getRepository().getExtraHeaders()).networkProxy(networkProxy);
wagon = wagonFactory.getWagon(wagonFactoryRequest);
if (wagon == null) {
throw new ProxyException("Unsupported target repository protocol: " + protocol);
}
if (wagon == null) {
throw new ProxyException("Unsupported target repository protocol: " + protocol);
}
boolean connected = connectToRepository(connector, wagon, remoteRepository);
if (connected) {
transferArtifact(wagon, remoteRepository, remotePath, repository, resource, workingDirectory, tmpResource);
// TODO: these should be used to validate the download based on the policies, not always downloaded
// to
// save on connections since md5 is rarely used
transferChecksum(wagon, remoteRepository, remotePath, repository, resource, workingDirectory, ".sha1", tmpSha1);
transferChecksum(wagon, remoteRepository, remotePath, repository, resource, workingDirectory, ".md5", tmpMd5);
}
} catch (NotFoundException e) {
urlFailureCache.cacheFailure(url);
throw e;
} catch (NotModifiedException e) {
// Do not cache url here.
throw e;
} catch (ProxyException e) {
urlFailureCache.cacheFailure(url);
throw e;
} catch (WagonFactoryException e) {
throw new ProxyException(e.getMessage(), e);
} finally {
if (wagon != null) {
try {
wagon.disconnect();
} catch (ConnectionException e) {
log.warn("Unable to disconnect wagon.", e);
}
}
}
}
use of org.apache.maven.wagon.Wagon in project archiva by apache.
the class DefaultRemoteRepositoriesService method checkRemoteConnectivity.
@Override
public Boolean checkRemoteConnectivity(String repositoryId) throws ArchivaRestServiceException {
try {
RemoteRepository remoteRepository = remoteRepositoryAdmin.getRemoteRepository(repositoryId);
if (remoteRepository == null) {
log.warn("ignore scheduleDownloadRemote for repo with id {} as not exists", repositoryId);
return Boolean.FALSE;
}
NetworkProxy networkProxy = null;
if (StringUtils.isNotBlank(remoteRepository.getRemoteDownloadNetworkProxyId())) {
networkProxy = networkProxyAdmin.getNetworkProxy(remoteRepository.getRemoteDownloadNetworkProxyId());
if (networkProxy == null) {
log.warn("your remote repository is configured to download remote index trought a proxy we cannot find id:{}", remoteRepository.getRemoteDownloadNetworkProxyId());
}
}
String wagonProtocol = new URL(remoteRepository.getUrl()).getProtocol();
final Wagon wagon = wagonFactory.getWagon(//
new WagonFactoryRequest(wagonProtocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
// hardcoded value as it's a check of the remote repo connectivity
wagon.setReadTimeout(checkReadTimeout);
wagon.setTimeout(checkTimeout);
if (wagon instanceof AbstractHttpClientWagon) {
HttpMethodConfiguration httpMethodConfiguration = //
new HttpMethodConfiguration().setUsePreemptive(//
true).setReadTimeout(checkReadTimeout);
HttpConfiguration httpConfiguration = new HttpConfiguration().setGet(httpMethodConfiguration);
AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
}
ProxyInfo proxyInfo = null;
if (networkProxy != null) {
proxyInfo = new ProxyInfo();
proxyInfo.setType(networkProxy.getProtocol());
proxyInfo.setHost(networkProxy.getHost());
proxyInfo.setPort(networkProxy.getPort());
proxyInfo.setUserName(networkProxy.getUsername());
proxyInfo.setPassword(networkProxy.getPassword());
}
String url = StringUtils.stripEnd(remoteRepository.getUrl(), "/");
wagon.connect(new Repository(remoteRepository.getId(), url), proxyInfo);
// MRM-1933, there are certain servers that do not allow browsing
if (!(StringUtils.isEmpty(remoteRepository.getCheckPath()) || "/".equals(remoteRepository.getCheckPath()))) {
return wagon.resourceExists(remoteRepository.getCheckPath());
} else {
// we only check connectivity as remote repo can be empty
// MRM-1909: Wagon implementation appends a slash already
wagon.getFileList("");
}
return Boolean.TRUE;
} catch (TransferFailedException e) {
log.info("TransferFailedException :{}", e.getMessage());
return Boolean.FALSE;
} catch (Exception e) {
// This service returns either true or false, Exception cannot be handled by the clients
log.debug("Exception occured on connectivity test.", e);
log.info("Connection exception: {}", e.getMessage());
return Boolean.FALSE;
}
}
Aggregations