use of org.eclipse.aether.repository.RemoteRepository in project fabric8 by jboss-fuse.
the class AetherBasedResolver method addRepo.
private void addRepo(List<RemoteRepository> list, MavenRepositoryURL repo) {
String releasesUpdatePolicy = repo.getReleasesUpdatePolicy();
if (releasesUpdatePolicy == null || releasesUpdatePolicy.isEmpty()) {
releasesUpdatePolicy = new RepositoryPolicy().getUpdatePolicy();
}
String releasesChecksumPolicy = repo.getReleasesChecksumPolicy();
if (releasesChecksumPolicy == null || releasesChecksumPolicy.isEmpty()) {
releasesChecksumPolicy = new RepositoryPolicy().getChecksumPolicy();
}
String snapshotsUpdatePolicy = repo.getSnapshotsUpdatePolicy();
if (snapshotsUpdatePolicy == null || snapshotsUpdatePolicy.isEmpty()) {
snapshotsUpdatePolicy = new RepositoryPolicy().getUpdatePolicy();
}
String snapshotsChecksumPolicy = repo.getSnapshotsChecksumPolicy();
if (snapshotsChecksumPolicy == null || snapshotsChecksumPolicy.isEmpty()) {
snapshotsChecksumPolicy = new RepositoryPolicy().getChecksumPolicy();
}
RemoteRepository.Builder builder = new RemoteRepository.Builder(repo.getId(), REPO_TYPE, repo.getURL().toExternalForm());
RepositoryPolicy releasePolicy = new RepositoryPolicy(repo.isReleasesEnabled(), releasesUpdatePolicy, releasesChecksumPolicy);
builder.setReleasePolicy(releasePolicy);
RepositoryPolicy snapshotPolicy = new RepositoryPolicy(repo.isSnapshotsEnabled(), snapshotsUpdatePolicy, snapshotsChecksumPolicy);
builder.setSnapshotPolicy(snapshotPolicy);
Authentication authentication = getAuthentication(repo.getId());
if (authentication != null) {
builder.setAuthentication(authentication);
}
list.add(builder.build());
}
use of org.eclipse.aether.repository.RemoteRepository in project fabric8 by jboss-fuse.
the class AetherBasedResolver method collectDependencies.
protected DependencyNode collectDependencies(Artifact root, String pomVersion, final Filter<Dependency> excludeDependencyFilter) throws RepositoryException, IOException {
final DefaultRepositorySystemSession session = newSession();
try {
List<RemoteRepository> repos = selectRepositories();
assignProxyAndMirrors(repos);
ArtifactDescriptorResult artifactDescriptorResult = m_repoSystem.readArtifactDescriptor(session, new ArtifactDescriptorRequest(root, repos, null));
repos.addAll(artifactDescriptorResult.getRepositories());
Dependency rootDependency = new Dependency(root, null);
List<Dependency> dependencies = artifactDescriptorResult.getDependencies();
final DefaultDependencyNode rootNode = new DefaultDependencyNode(rootDependency);
GenericVersionScheme versionScheme = new GenericVersionScheme();
rootNode.setVersion(versionScheme.parseVersion(pomVersion));
rootNode.setVersionConstraint(versionScheme.parseVersionConstraint(pomVersion));
DependencyNode pomNode = rootNode;
// final Filter<Dependency> shouldExclude = Filters.or(DependencyFilters.testScopeFilter, excludeDependencyFilter, new NewerVersionExistsFilter(rootNode));
final Filter<Dependency> shouldExclude = Filters.or(Arrays.asList(DependencyFilters.testScopeFilter, excludeDependencyFilter));
DependencySelector dependencySelector = new AndDependencySelector(new ScopeDependencySelector("test"), new ExclusionDependencySelector(), new DependencySelector() {
@Override
public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
return this;
}
@Override
public boolean selectDependency(Dependency dependency) {
try {
return !DependencyFilters.matches(dependency, shouldExclude);
} catch (Exception e) {
failedToMakeDependencyTree(dependency, e);
return false;
}
}
});
session.setDependencySelector(dependencySelector);
// work on the root dependency directly?
if (true) {
for (Dependency dependency : dependencies) {
DependencyNode node = resolveDependencies(session, repos, pomNode, dependency, shouldExclude);
if (node != null) {
pomNode.getChildren().add(node);
}
}
} else {
DependencyNode node = resolveDependencies(session, repos, pomNode, rootDependency, shouldExclude);
if (node != null) {
pomNode = node;
}
}
// now lets transform the dependency tree to remove different versions for the same artifact
final DependencyGraphTransformationContext tranformContext = new DependencyGraphTransformationContext() {
Map<Object, Object> map = new HashMap<>();
public RepositorySystemSession getSession() {
return session;
}
public Object get(Object key) {
return map.get(key);
}
public Object put(Object key, Object value) {
return map.put(key, value);
}
};
DependencyGraphTransformer transformer = new ReplaceConflictingVersionResolver();
pomNode = transformer.transformGraph(pomNode, tranformContext);
transformer = new DuplicateTransformer();
pomNode = transformer.transformGraph(pomNode, tranformContext);
return pomNode;
} finally {
releaseSession(session);
}
}
use of org.eclipse.aether.repository.RemoteRepository in project fabric8 by jboss-fuse.
the class MavenProxyServletSupport method download.
@Override
public File download(String path) throws InvalidMavenArtifactRequest {
if (path == null) {
throw new InvalidMavenArtifactRequest();
}
Matcher artifactMatcher = ARTIFACT_REQUEST_URL_REGEX.matcher(path);
Matcher metdataGaMatcher = ARTIFACT_GA_METADATA_URL_REGEX.matcher(path);
if (metdataGaMatcher.matches()) {
LOGGER.info("Received request for maven metadata : {}", path);
Metadata metadata = null;
try {
metadata = convertPathToMetadata(path);
// Only handle xxx/maven-metadata.xml requests
if (!"maven-metadata.xml".equals(metadata.getType()) || metdataGaMatcher.group(7) != null) {
return null;
}
if (isHostedRepository()) {
// do not resolve metadata via Aether - simply look it up in hosted storage
// This is important, because `mvn deploy` or `mvn fabric8:deploy` goals, even if they PUT
// artifacts and metadata also GET metadata (not artifacts)
File hostedMetadata = new File(uploadRepository, path);
LOGGER.debug("Getting metadata from hosted storage : {}", hostedMetadata);
if (hostedMetadata.isFile()) {
File tmpFile = Files.createTempFile(runtimeProperties.getDataPath());
Files.copy(hostedMetadata, tmpFile);
return tmpFile;
}
// never look up in io.fabric8.maven.defaultRepositories or io.fabric8.maven.repositories
return null;
}
// Try with default repositories - first metadata found is returned
VersionConstraint vc = new GenericVersionScheme().parseVersionConstraint(metadata.getVersion());
if (vc.getVersion() != null) {
for (LocalRepository repo : resolver.getDefaultRepositories()) {
if (vc.getVersion().toString().endsWith("SNAPSHOT") && !resolver.handlesSnapshot(repo)) {
continue;
}
// clone session to swap local repository manager
DefaultRepositorySystemSession localSession = new DefaultRepositorySystemSession(session);
localSession.setLocalRepositoryManager(system.newLocalRepositoryManager(localSession, repo));
LOGGER.debug("Getting metadata from default repository : {}", repo.getBasedir());
List<MetadataResult> results = system.resolveMetadata(localSession, Collections.singletonList(new MetadataRequest(metadata, null, null)));
File file = processMetadataResults(metadata, results);
if (file != null) {
return file;
}
}
}
// fallback to remote repositories - this time results are merged
List<MetadataRequest> requests = new ArrayList<>();
for (RemoteRepository repository : repositories) {
MetadataRequest request = new MetadataRequest(metadata, repository, null);
request.setFavorLocalRepository(false);
requests.add(request);
}
MetadataRequest request = new MetadataRequest(metadata, null, null);
request.setFavorLocalRepository(true);
requests.add(request);
List<MetadataResult> results = system.resolveMetadata(session, requests);
File result = processMetadataResults(metadata, results);
if (result != null) {
return result;
}
} catch (Exception e) {
LOGGER.warn(String.format("Could not find metadata : %s due to %s", metadata, e.getMessage()), e);
return null;
}
// If no matching metadata found return nothing
return null;
} else if (artifactMatcher.matches()) {
LOGGER.info("Received request for maven artifact : {}", path);
Artifact artifact = convertPathToArtifact(path);
try {
if (artifact.getExtension() != null && (artifact.getExtension().endsWith(".sha1") || artifact.getExtension().endsWith(".md5"))) {
return null;
}
File download = resolver.resolveFile(artifact);
File tmpFile = Files.createTempFile(runtimeProperties.getDataPath());
Files.copy(download, tmpFile);
return tmpFile;
} catch (Exception e) {
LOGGER.warn(String.format("Could not find artifact : %s due to %s", artifact, e.getMessage()), e);
return null;
}
}
return null;
}
use of org.eclipse.aether.repository.RemoteRepository in project drools by kiegroup.
the class MavenDeployTest method testDeploy.
@Test
public void testDeploy() throws IOException {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test-deploy", "1.0-SNAPSHOT");
Path m2Folder = Files.createTempDirectory("temp-m2");
Path settingsXmlPath = generateSettingsXml(m2Folder);
String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
try {
System.setProperty(CUSTOM_SETTINGS_PROPERTY, settingsXmlPath.toString());
MavenSettings.reinitSettings();
InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieMavenRepository repository = getKieMavenRepository();
RemoteRepository remote = createRemoteRepository(m2Folder);
repository.deployArtifact(remote, releaseId, kJar1, createKPom(m2Folder, releaseId).toFile());
// create a ksesion and check it works as expected
KieSession ksession = kieContainer.newKieSession("KSession1");
checkKSession(ksession, "rule1", "rule2");
// create a new kjar
InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
// deploy it on maven
repository.deployArtifact(remote, releaseId, kJar2, createKPom(m2Folder, releaseId).toFile());
// since I am not calling start() on the scanner it means it won't have automatic scheduled scanning
KieScanner scanner = ks.newKieScanner(kieContainer);
// scan the maven repo to get the new kjar version and deploy it on the kcontainer
scanner.scanNow();
// create a ksesion and check it works as expected
KieSession ksession2 = kieContainer.newKieSession("KSession1");
checkKSession(ksession2, "rule2", "rule3");
ks.getRepository().removeKieModule(releaseId);
} finally {
if (oldSettingsXmlPath == null) {
System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
} else {
System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
}
MavenSettings.reinitSettings();
}
}
use of org.eclipse.aether.repository.RemoteRepository in project drools by kiegroup.
the class KieMavenRepository method deployArtifact.
/**
* Deploys the kjar in the given kieModule on the remote repository defined in the
* distributionManagement tag of the provided pom file. If the pom file doesn't define
* a distributionManagement no deployment will be performed and a warning message will be logged.
*
* @param releaseId The releaseId with which the deployment will be made
* @param kieModule The kieModule containing the kjar to be deployed
* @param pomfile The pom file to be deployed together with the kjar
*/
public void deployArtifact(ReleaseId releaseId, InternalKieModule kieModule, File pomfile) {
RemoteRepository repository = getRemoteRepositoryFromDistributionManagement(pomfile);
if (repository == null) {
log.warn("No Distribution Management configured: unknown repository");
return;
}
deployArtifact(repository, releaseId, kieModule, pomfile);
}
Aggregations