gate.util.maven.SimpleModelResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gate-core Show documentation
Show all versions of gate-core Show documentation
GATE - general achitecture for text engineering - is open source
software capable of solving almost any text processing problem. This
artifact enables you to embed the core GATE Embedded with its essential
dependencies. You will able to use the GATE Embedded API and load and
store GATE XML documents. This artifact is the perfect dependency for
CREOLE plugins or for applications that need to customize the GATE
dependencies due to confict with their own dependencies or for lower
footprint.
The newest version!
package gate.util.maven;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Parent;
import org.apache.maven.model.building.FileModelSource;
import org.apache.maven.model.building.ModelSource;
import org.apache.maven.model.resolution.InvalidRepositoryException;
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.model.resolution.UnresolvableModelException;
import org.apache.maven.repository.internal.ArtifactDescriptorUtils;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactRequest;
@SuppressWarnings("deprecation")
public class SimpleModelResolver implements ModelResolver {
private final RepositorySystem system;
private final RepositorySystemSession session;
private final Set repositoryIds;
private List repositories;
/**
* Creates a model resolver to assist building of dependency POMs.
*
* @param system a {@link RepositorySystem}
* @param session a {@link RepositorySystemSession}
* @param remoteRepositories remote repositories to use for resolution.
*/
public SimpleModelResolver(RepositorySystem system, RepositorySystemSession session,
List remoteRepositories) {
this.system = system;
this.session = session;
this.repositories = new ArrayList(remoteRepositories);
this.repositoryIds = new HashSet(
remoteRepositories.size() < 3 ? 3 : remoteRepositories.size());
for(RemoteRepository repository : remoteRepositories) {
repositoryIds.add(repository.getId());
}
}
/**
* Clone Constructor.
*
* @param original a SimpleModelResolver.
*/
private SimpleModelResolver(SimpleModelResolver original) {
this.session = original.session;
this.system = original.system;
this.repositoryIds = new HashSet(original.repositoryIds);
}
@Override
public void addRepository(org.apache.maven.model.Repository repository) throws InvalidRepositoryException {
if (!repositoryIds.add(repository.getId())) {
return;
}
this.repositories.add(ArtifactDescriptorUtils.toRemoteRepository(repository));
}
@Override
public ModelResolver newCopy() {
return new SimpleModelResolver(this);
}
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version)
throws UnresolvableModelException {
Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version);
try {
ArtifactRequest request = new ArtifactRequest(pomArtifact, repositories, null);
pomArtifact = system.resolveArtifact(session, request).getArtifact();
} catch (org.eclipse.aether.resolution.ArtifactResolutionException ex) {
throw new UnresolvableModelException(ex.getMessage(), groupId, artifactId, version, ex);
}
File pomFile = pomArtifact.getFile();
return new FileModelSource(pomFile);
}
@Override
public ModelSource resolveModel(Parent parent)
throws UnresolvableModelException {
return resolveModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion());
}
@Override
public void addRepository(org.apache.maven.model.Repository repository,
boolean replace) throws InvalidRepositoryException {
// TODO Auto-generated method stub
}
public ModelSource resolveModel(Dependency dependency)
throws UnresolvableModelException {
return resolveModel(dependency.getGroupId(), dependency.getArtifactId(),
dependency.getVersion());
}
}