use of org.eclipse.che.maven.data.MavenRemoteRepository in project che by eclipse.
the class MavenProject method setModel.
private MavenProjectModifications setModel(MavenModelReaderResult readerResult, boolean clearArtifacts, boolean clearProfiles) {
Info newInfo = info.clone();
newInfo.problems = readerResult.getProblems();
newInfo.activeProfiles = readerResult.getActiveProfiles();
MavenModel model = readerResult.getMavenModel();
newInfo.mavenKey = model.getMavenKey();
if (model.getParent() != null) {
newInfo.parentKey = model.getParent().getMavenKey();
}
newInfo.packaging = model.getPackaging();
newInfo.name = model.getName();
newInfo.sources = model.getBuild().getSources();
newInfo.testSources = model.getBuild().getTestSources();
newInfo.resources = model.getBuild().getResources();
newInfo.testResources = model.getBuild().getTestResources();
newInfo.properties = model.getProperties();
newInfo.filters = model.getBuild().getFilters();
Set<MavenRemoteRepository> remoteRepositories = new HashSet<>();
Set<MavenArtifact> extensions = new HashSet<>();
Set<MavenArtifact> dependencies = new HashSet<>();
Set<MavenPlugin> plugins = new HashSet<>();
Set<MavenKey> unresolvedArtifacts = new HashSet<>();
if (!clearArtifacts) {
if (info.remoteRepositories != null) {
remoteRepositories.addAll(info.remoteRepositories);
}
if (info.extensions != null) {
extensions.addAll(info.extensions);
}
if (info.dependencies != null) {
dependencies.addAll(info.dependencies);
}
if (info.plugins != null) {
plugins.addAll(info.plugins);
}
if (info.unresolvedArtifacts != null) {
unresolvedArtifacts.addAll(info.unresolvedArtifacts);
}
}
remoteRepositories.addAll(model.getRemoteRepositories());
extensions.addAll(model.getExtensions());
dependencies.addAll(model.getDependencies());
plugins.addAll(model.getPlugins());
unresolvedArtifacts.addAll(readerResult.getUnresolvedArtifacts());
newInfo.remoteRepositories = new ArrayList<>(remoteRepositories);
newInfo.extensions = new ArrayList<>(extensions);
newInfo.dependencies = new ArrayList<>(dependencies);
newInfo.plugins = new ArrayList<>(plugins);
newInfo.unresolvedArtifacts = unresolvedArtifacts;
newInfo.modulesNameToPath = collectModulesNameAndPath(model);
return setInfo(newInfo);
}
use of org.eclipse.che.maven.data.MavenRemoteRepository in project che by eclipse.
the class MavenModelUtil method convertToMavenRepository.
public static Repository convertToMavenRepository(MavenRemoteRepository repository) {
Repository result = new Repository();
result.setId(repository.getId());
result.setName(repository.getName());
result.setUrl(repository.getUrl());
if (repository.getLayout() == null) {
result.setLayout("default");
} else {
result.setLayout(repository.getLayout());
}
if (repository.getSnapshotsPolicy() != null) {
result.setSnapshots(convertToMavenPolicy(repository.getSnapshotsPolicy()));
}
if (repository.getReleasesPolicy() != null) {
result.setReleases(convertToMavenPolicy(repository.getReleasesPolicy()));
}
return result;
}
use of org.eclipse.che.maven.data.MavenRemoteRepository in project che by eclipse.
the class MavenServerImpl method resolveArtifact.
@Override
public MavenArtifact resolveArtifact(MavenArtifactKey artifactKey, List<MavenRemoteRepository> repositories) throws RemoteException {
Artifact artifact = getMavenComponent(ArtifactFactory.class).createArtifactWithClassifier(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getVersion(), artifactKey.getPackaging(), artifactKey.getClassifier());
List<ArtifactRepository> repos = new ArrayList<>();
ArtifactRepositoryFactory factory = getMavenComponent(ArtifactRepositoryFactory.class);
for (MavenRemoteRepository repository : repositories) {
try {
ArtifactRepository artifactRepository = ProjectUtils.buildArtifactRepository(MavenModelUtil.convertToMavenRepository(repository), factory, container);
repos.add(artifactRepository);
} catch (InvalidRepositoryException e) {
MavenServerContext.getLogger().error(e);
}
}
MavenExecutionRequest request = newMavenRequest(null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
repos.forEach(request::addRemoteRepository);
DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
org.eclipse.aether.impl.ArtifactResolver artifactResolver = getMavenComponent(org.eclipse.aether.impl.ArtifactResolver.class);
InternalLoggerFactory loggerFactory = new InternalLoggerFactory();
if (artifactResolver instanceof DefaultArtifactResolver) {
((DefaultArtifactResolver) artifactResolver).setLoggerFactory(loggerFactory);
}
org.eclipse.aether.RepositorySystem repositorySystem = getMavenComponent(org.eclipse.aether.RepositorySystem.class);
if (repositorySystem instanceof DefaultRepositorySystem) {
((DefaultRepositorySystem) repositorySystem).setLoggerFactory(loggerFactory);
}
List<RemoteRepository> remoteRepositories = RepositoryUtils.toRepos(request.getRemoteRepositories());
remoteRepositories = repositorySystem.newResolutionRepositories(repositorySystemSession, remoteRepositories);
try {
ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, new ArtifactRequest(RepositoryUtils.toArtifact(artifact), remoteRepositories, null));
return MavenModelUtil.convertArtifact(RepositoryUtils.toArtifact(artifactResult.getArtifact()), localRepository);
} catch (ArtifactResolutionException e) {
MavenServerContext.getLogger().info(e);
}
return MavenModelUtil.convertArtifact(artifact, localRepository);
}
Aggregations