use of org.eclipse.aether.RepositorySystemSession in project spf4j by zolyfarkas.
the class MavenRepositoryUtils method resolveArtifactAndDependencies.
public static Set<File> resolveArtifactAndDependencies(final List<RemoteRepository> repos, final File localRepo, final String scope, final String groupId, final String artifactId, final String classifier, final String extension, final String versionExpr) throws DependencyResolutionException {
RepositorySystem repositorySystem = getRepositorySystem();
RepositorySystemSession session = getRepositorySystemSession(repositorySystem, localRepo);
return resolveArtifactAndDependencies(scope, groupId, artifactId, classifier, extension, versionExpr, repos, repositorySystem, session);
}
use of org.eclipse.aether.RepositorySystemSession in project liferay-ide by liferay.
the class LiferayMavenProjectProvider method getData.
@Override
public <T> List<T> getData(String key, Class<T> type, Object... params) {
List<T> retval = null;
if ("profileIds".equals(key)) {
List<T> profileIds = new ArrayList<>();
try {
IMaven maven = MavenPlugin.getMaven();
List<Profile> profiles = maven.getSettings().getProfiles();
for (Profile profile : profiles) {
if (profile.getActivation() != null) {
if (profile.getActivation().isActiveByDefault()) {
continue;
}
}
profileIds.add(type.cast(profile.getId()));
}
if ((params[0] != null) && params[0] instanceof File) {
File locationDir = (File) params[0];
File pomFile = new File(locationDir, IMavenConstants.POM_FILE_NAME);
if (FileUtil.notExists(pomFile) && FileUtil.exists(locationDir.getParentFile())) {
// try one level up for when user is adding new module
pomFile = new File(locationDir.getParentFile(), IMavenConstants.POM_FILE_NAME);
}
if (FileUtil.exists(pomFile)) {
Model model = maven.readModel(pomFile);
File parentDir = pomFile.getParentFile();
while (model != null) {
for (org.apache.maven.model.Profile p : model.getProfiles()) {
profileIds.add(type.cast(p.getId()));
}
parentDir = parentDir.getParentFile();
if (FileUtil.exists(parentDir)) {
try {
model = maven.readModel(new File(parentDir, IMavenConstants.POM_FILE_NAME));
} catch (Exception e) {
model = null;
}
}
}
}
}
} catch (CoreException ce) {
LiferayMavenCore.logError(ce);
}
retval = profileIds;
} else if ("liferayVersions".equals(key)) {
List<T> possibleVersions = new ArrayList<>();
RepositorySystem system = AetherUtil.newRepositorySystem();
RepositorySystemSession session = AetherUtil.newRepositorySystemSession(system);
String groupId = params[0].toString();
String artifactId = params[1].toString();
String coords = groupId + ":" + artifactId + ":[6,)";
Artifact artifact = new DefaultArtifact(coords);
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.addRepository(AetherUtil.newCentralRepository());
rangeRequest.addRepository(AetherUtil.newLiferayRepository());
try {
VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
List<Version> versions = rangeResult.getVersions();
for (Version version : versions) {
String val = version.toString();
if (!"6.2.0".equals(val) && !val.contains("7.0.0")) {
possibleVersions.add(type.cast(val));
}
}
retval = possibleVersions;
} catch (VersionRangeResolutionException vrre) {
}
} else if ("parentVersion".equals(key)) {
List<T> version = new ArrayList<>();
File locationDir = (File) params[0];
File parentPom = new File(locationDir, IMavenConstants.POM_FILE_NAME);
if (FileUtil.exists(parentPom)) {
try {
IMaven maven = MavenPlugin.getMaven();
Model model = maven.readModel(parentPom);
version.add(type.cast(model.getVersion()));
retval = version;
} catch (CoreException ce) {
LiferayMavenCore.logError("unable to get parent version", ce);
}
}
} else if ("parentGroupId".equals(key)) {
List<T> groupId = new ArrayList<>();
File locationDir = (File) params[0];
File parentPom = new File(locationDir, IMavenConstants.POM_FILE_NAME);
if (FileUtil.exists(parentPom)) {
try {
IMaven maven = MavenPlugin.getMaven();
Model model = maven.readModel(parentPom);
groupId.add(type.cast(model.getGroupId()));
retval = groupId;
} catch (CoreException ce) {
LiferayMavenCore.logError("unable to get parent groupId", ce);
}
}
} else if ("archetypeGAV".equals(key)) {
String frameworkType = (String) params[0];
String value = LiferayMavenCore.getPreferenceString("archetype-gav-" + frameworkType, "");
retval = Collections.singletonList(type.cast(value));
}
return retval;
}
use of org.eclipse.aether.RepositorySystemSession in project spring-cloud-deployer by spring-cloud.
the class MavenArtifactResolver method resolve.
/**
* Resolve an artifact and return its location in the local repository. Aether performs the normal
* Maven resolution process ensuring that the latest update is cached to the local repository.
* In addition, if the {@link MavenProperties#resolvePom} flag is <code>true</code>,
* the POM is also resolved and cached.
* @param resource the {@link MavenResource} representing the artifact
* @return a {@link FileSystemResource} representing the resolved artifact in the local repository
* @throws IllegalStateException if the artifact does not exist or the resolution fails
*/
Resource resolve(MavenResource resource) {
Assert.notNull(resource, "MavenResource must not be null");
validateCoordinates(resource);
RepositorySystemSession session = newRepositorySystemSession(this.repositorySystem, this.properties.getLocalRepository());
ArtifactResult resolvedArtifact;
try {
List<ArtifactRequest> artifactRequests = new ArrayList<>(2);
if (properties.isResolvePom()) {
artifactRequests.add(new ArtifactRequest(toPomArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME));
}
artifactRequests.add(new ArtifactRequest(toJarArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME));
List<ArtifactResult> results = this.repositorySystem.resolveArtifacts(session, artifactRequests);
resolvedArtifact = results.get(results.size() - 1);
} catch (ArtifactResolutionException e) {
ChoiceFormat pluralizer = new ChoiceFormat(new double[] { 0d, 1d, ChoiceFormat.nextDouble(1d) }, new String[] { "repositories: ", "repository: ", "repositories: " });
MessageFormat messageFormat = new MessageFormat("Failed to resolve MavenResource: {0}. Configured remote {1}: {2}");
messageFormat.setFormat(1, pluralizer);
String repos = properties.getRemoteRepositories().isEmpty() ? "none" : StringUtils.collectionToDelimitedString(properties.getRemoteRepositories().keySet(), ",", "[", "]");
throw new IllegalStateException(messageFormat.format(new Object[] { resource, properties.getRemoteRepositories().size(), repos }), e);
}
return toResource(resolvedArtifact);
}
use of org.eclipse.aether.RepositorySystemSession in project launcher by runelite.
the class ArtifactResolver method resolveArtifacts.
public List<ArtifactResult> resolveArtifacts(Artifact artifact) throws DependencyResolutionException {
RepositorySystem system = newRepositorySystem();
RepositorySystemSession session = newRepositorySystemSession(system);
DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE, JavaScopes.RUNTIME);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
collectRequest.setRepositories(repositories);
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
List<ArtifactResult> results = system.resolveDependencies(session, dependencyRequest).getArtifactResults();
// check to see if they're from the right repository
validate(results);
return results;
}
use of org.eclipse.aether.RepositorySystemSession in project wildfly-swarm by wildfly-swarm.
the class MavenArtifactResolvingHelperTest method propagateRepositoryPolicies.
@Test
public // SWARM-1173: swarm-plugin trying to download SNAPSHOTs from Maven Central
void propagateRepositoryPolicies() {
RepositorySystemSession sessionMock = Mockito.mock(RepositorySystemSession.class);
MirrorSelector mirrorSelectorMock = Mockito.mock(MirrorSelector.class);
Mockito.when(sessionMock.getMirrorSelector()).thenReturn(mirrorSelectorMock);
ProxySelector proxySelectorMock = Mockito.mock(ProxySelector.class);
Mockito.when(sessionMock.getProxySelector()).thenReturn(proxySelectorMock);
MavenArtifactResolvingHelper artifactResolverHelper = new MavenArtifactResolvingHelper(null, null, sessionMock, null);
ArtifactRepositoryPolicy testSnapshotPolicy = new ArtifactRepositoryPolicy(false, "hourly", "warn");
ArtifactRepositoryPolicy testReleasesPolicy = new ArtifactRepositoryPolicy(true, "never", "warn");
ArtifactRepository testingRepo = new MavenArtifactRepository("testing-repo", "http://testing-repo.org", new DefaultRepositoryLayout(), testSnapshotPolicy, testReleasesPolicy);
artifactResolverHelper.remoteRepository(testingRepo);
List<RemoteRepository> remoteRepos = artifactResolverHelper.getRemoteRepositories();
Assert.assertTrue("Remote repositories " + remoteRepos + " do not contain expected testing repo " + testingRepo, remoteRepos.stream().anyMatch(remoteRepo -> {
RepositoryPolicy snapshotsPolicy = remoteRepo.getPolicy(true);
RepositoryPolicy releasesPolicy = remoteRepo.getPolicy(false);
return remoteRepo.getId().equals(testingRepo.getId()) && !snapshotsPolicy.isEnabled() && snapshotsPolicy.getUpdatePolicy().equals(testSnapshotPolicy.getUpdatePolicy()) && snapshotsPolicy.getChecksumPolicy().equals(testSnapshotPolicy.getChecksumPolicy()) && releasesPolicy.isEnabled() && releasesPolicy.getUpdatePolicy().equals(testReleasesPolicy.getUpdatePolicy()) && releasesPolicy.getChecksumPolicy().equals(testReleasesPolicy.getChecksumPolicy());
}));
}
Aggregations