本文整理汇总了Java中org.apache.maven.RepositoryUtils类的典型用法代码示例。如果您正苦于以下问题:Java RepositoryUtils类的具体用法?Java RepositoryUtils怎么用?Java RepositoryUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RepositoryUtils类属于org.apache.maven包,在下文中一共展示了RepositoryUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMirror
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
private Mirror getMirror( RepositorySystemSession session, ArtifactRepository repository )
{
if ( session != null )
{
org.sonatype.aether.repository.MirrorSelector selector = session.getMirrorSelector();
if ( selector != null )
{
RemoteRepository repo = selector.getMirror( RepositoryUtils.toRepo( repository ) );
if ( repo != null )
{
Mirror mirror = new Mirror();
mirror.setId( repo.getId() );
mirror.setUrl( repo.getUrl() );
mirror.setLayout( repo.getContentType() );
return mirror;
}
}
}
return null;
}
示例2: getAuthentication
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
private Authentication getAuthentication( RepositorySystemSession session, ArtifactRepository repository )
{
if ( session != null )
{
AuthenticationSelector selector = session.getAuthenticationSelector();
if ( selector != null )
{
org.sonatype.aether.repository.Authentication auth =
selector.getAuthentication( RepositoryUtils.toRepo( repository ) );
if ( auth != null )
{
Authentication result = new Authentication( auth.getUsername(), auth.getPassword() );
result.setPrivateKey( auth.getPrivateKeyFile() );
result.setPassphrase( auth.getPassphrase() );
return result;
}
}
}
return null;
}
示例3: getProxy
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
private Proxy getProxy( RepositorySystemSession session, ArtifactRepository repository )
{
if ( session != null )
{
ProxySelector selector = session.getProxySelector();
if ( selector != null )
{
org.sonatype.aether.repository.Proxy proxy = selector.getProxy( RepositoryUtils.toRepo( repository ) );
if ( proxy != null )
{
Proxy p = new Proxy();
p.setHost( proxy.getHost() );
p.setProtocol( proxy.getType() );
p.setPort( proxy.getPort() );
if ( proxy.getAuthentication() != null )
{
p.setUserName( proxy.getAuthentication().getUsername() );
p.setPassword( proxy.getAuthentication().getPassword() );
}
return p;
}
}
}
return null;
}
示例4: retrieveArtifact
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
/**
* Uses Aether to retrieve an artifact from the repository.
*
* @param coordinates as in groupId:artifactId:version
* @return the located artifact
*/
Artifact retrieveArtifact(final String coordinates)
{
final ArtifactRequest request = new ArtifactRequest();
request.setArtifact(new DefaultArtifact(coordinates));
request.setRepositories(remoteRepos);
ArtifactResult result = null;
try {
result = repoSystem.resolveArtifact(repoSession, request);
} catch (final ArtifactResolutionException e) {
getLog().error("Could not resolve parent artifact (" + coordinates + "): " + e.getMessage());
}
if (result != null) {
return RepositoryUtils.toArtifact(result.getArtifact());
}
return null;
}
示例5: init
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
@PostConstruct
public void init() {
// setting the artifact version to a release version temporarily since the dist repository checks for a snapshot
// version of the artifact. Maybe this can be implemented in a different manner but then we would have to setup the
// repository manually
org.apache.maven.artifact.Artifact projectArtifact = this.project.getArtifact();
String oldVersion = projectArtifact.getVersion();
projectArtifact.setVersion("1");
// getting the remote repo
this.deploymentRepository = RepositoryUtils.toRepo(this.project.getDistributionManagementArtifactRepository());
// resetting the artifact version
projectArtifact.setVersion(oldVersion);
for (MavenProject p : this.reactorProjects) {
// puts the initial module artifact coordinates into the cache
addArtifactCoordinates(ProjectToCoordinates.POM.apply(p), ReleasePhase.PRE_RELEASE);
// caching of SCM settings of every POM in order to go back to it before setting next dev version
this.cachedScmSettings.put(ProjectToCoordinates.EMPTY_VERSION.apply(p), p.getModel().getScm());
Optional<Document> parsedPOM = PomUtil.parsePOM(p);
if (parsedPOM.isPresent()) {
this.originalPOMs.put(ProjectToCoordinates.EMPTY_VERSION.apply(p), parsedPOM.get());
}
}
}
示例6: ScmRepositoryIndex
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
private ScmRepositoryIndex(MavenSession session, RepositorySystemSession repoSession,
ArtifactFactory repositorySystem, ProjectBuilder projectBuilder, Set<org.srcdeps.core.Scm> scms) {
super();
this.session = session;
this.repoSession = repoSession;
this.repositorySystem = repositorySystem;
this.projectBuilder = projectBuilder;
this.remoteRepos = RepositoryUtils.toRepos(session.getProjectBuildingRequest().getRemoteRepositories());
this.scms = scms;
}
示例7: convertAetherDependencyNodes
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
public static List<MavenArtifactNode> convertAetherDependencyNodes(MavenArtifactNode parent,
Collection<DependencyNode> nodes,
Map<Artifact, MavenArtifact> nativeToConvertedMap,
File localRepository) {
List<MavenArtifactNode> result = new ArrayList<MavenArtifactNode>(nodes.size());
for (DependencyNode each : nodes) {
Artifact a = RepositoryUtils.toArtifact(each.getDependency().getArtifact());
MavenArtifact ma = convertArtifact(a, nativeToConvertedMap, localRepository);
Map<?, ?> data = each.getData();
//String premanagedVersion = DependencyManagerUtils.getPremanagedVersion(each);
//String premanagedScope = DependencyManagerUtils.getPremanagedScope(each);
//Object winner = data.get(ConflictResolver.NODE_DATA_WINNER);
//if(winner instanceof DependencyNode) {
// DependencyNode winnerNode = (DependencyNode)winner;
// if(!StringUtil.equals(each.getVersion().toString(), winnerNode.getVersion().toString())) {
// state = MavenArtifactState.CONFLICT;
// Artifact winnerArtifact = RepositoryUtils.toArtifact(winnerNode.getDependency().getArtifact());
// relatedArtifact = convertArtifact(winnerArtifact, nativeToConvertedMap, localRepository);
// }
//}
//
MavenArtifactNode newNode = new MavenArtifactNode(
parent, ma, MavenArtifactState.ADDED, null, each.getDependency().getScope(),
each.getPremanagedVersion(), each.getPremanagedScope());
newNode.setDependencies(convertAetherDependencyNodes(newNode, each.getChildren(), nativeToConvertedMap, localRepository));
result.add(newNode);
}
return result;
}
示例8: convertAetherDependencyNodes
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
public static List<MavenArtifactNode> convertAetherDependencyNodes(MavenArtifactNode parent,
Collection<DependencyNode> nodes,
Map<Artifact, MavenArtifact> nativeToConvertedMap,
File localRepository) {
List<MavenArtifactNode> result = new ArrayList<MavenArtifactNode>(nodes.size());
for (DependencyNode each : nodes) {
Artifact a = RepositoryUtils.toArtifact(each.getDependency().getArtifact());
MavenArtifact ma = convertArtifact(a, nativeToConvertedMap, localRepository);
Map<?, ?> data = each.getData();
String premanagedVersion = DependencyManagerUtils.getPremanagedVersion(each);
String premanagedScope = DependencyManagerUtils.getPremanagedScope(each);
MavenArtifactState state = MavenArtifactState.ADDED;
MavenArtifact relatedArtifact = null;
Object winner = data.get(ConflictResolver.NODE_DATA_WINNER);
if(winner instanceof DependencyNode) {
DependencyNode winnerNode = (DependencyNode)winner;
if(!StringUtil.equals(each.getVersion().toString(), winnerNode.getVersion().toString())) {
state = MavenArtifactState.CONFLICT;
Artifact winnerArtifact = RepositoryUtils.toArtifact(winnerNode.getDependency().getArtifact());
relatedArtifact = convertArtifact(winnerArtifact, nativeToConvertedMap, localRepository);
}
}
MavenArtifactNode newNode = new MavenArtifactNode(
parent, ma, state, relatedArtifact, each.getDependency().getScope(),
premanagedVersion, premanagedScope);
newNode.setDependencies(convertAetherDependencyNodes(newNode, each.getChildren(), nativeToConvertedMap, localRepository));
result.add(newNode);
}
return result;
}
示例9: getBundleArtifacts
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
public Set<BundleArtifact> getBundleArtifacts(List<DependencyNode> nodes) {
Set<BundleArtifact> bundleArtifacts = new HashSet<BundleArtifact>();
for (DependencyNode node : nodes) {
Artifact artifact = RepositoryUtils.toArtifact(node.getDependency().getArtifact());
String symbolicName = getManifestAttribute(artifact, Constants.BUNDLE_SYMBOLICNAME);
if (symbolicName != null) {
String version = getManifestAttribute(artifact, Constants.BUNDLE_VERSION);
bundleArtifacts.add(new BundleArtifact(artifact, symbolicName, version));
bundleArtifacts.addAll(getBundleArtifacts(node.getChildren()));
} else {
log.warn("Not an OSGi bundle : " + artifact.getId());
}
}
return bundleArtifacts;
}
示例10: getAllArtifacts
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
public Set<Artifact> getAllArtifacts(List<DependencyNode> nodes) {
Set<Artifact> artifacts = new HashSet<Artifact>();
for (DependencyNode node : nodes) {
Artifact artifact = RepositoryUtils.toArtifact(node.getDependency().getArtifact());
if (isBundle(artifact)) {
artifacts.add(artifact);
artifacts.addAll(getAllArtifacts(node.getChildren()));
}
}
return artifacts;
}
示例11: getArtifacts
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
public Set<Artifact> getArtifacts(List<DependencyNode> nodes) {
Set<Artifact> artifacts = new HashSet<Artifact>();
for (DependencyNode node : nodes) {
Artifact artifact = RepositoryUtils.toArtifact(node.getDependency().getArtifact());
if (isBundle(artifact)) {
artifacts.add(artifact);
}
}
return artifacts;
}
示例12: testSensibleSession
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
public void testSensibleSession(MavenSession s) throws Exception {
MavenSession ms = newMavenSession(); //((LicenseAuditMojo)mojo).mavenSession;
assertNotNull( ms );
assertNotNull( ms.getLocalRepository().getBasedir() );
System.out.println("Basedir: "+ms.getLocalRepository().getBasedir());
// The following artifacts could not be resolved: org.apache.maven:maven-core:jar:2.0.7
RepositorySystem rs = lookup(RepositorySystem.class);
assertNotNull( rs );
// check we can access stuff in remote repos
// (fails if we don't have proper aether connectors + transforms,
// or if we've not "populated" with default remote repos)
ArtifactResult art;
art = resolveArtifact(rs, ms, "org.apache.maven:maven-core:jar:2.0.7");
System.out.println(art);
assertNotNull(art.getArtifact());
// check we avoid this:
// [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14
art = resolveArtifact(rs, ms, "org.apache.commons:commons-lang3:3.1");
System.out.println(art);
assertNotNull(art.getArtifact());
ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
ProjectBuildingResult res = projectBuilder.build(RepositoryUtils.toArtifact(art.getArtifact()), true, ms.getProjectBuildingRequest());
System.out.println(res);
if (!res.getProblems().isEmpty()) fail("Problems: "+res.getProblems());
}
示例13: resolveArtifact
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
static ArtifactResult resolveArtifact(RepositorySystem rs, MavenSession ms, String coords) throws ArtifactResolutionException {
return rs.resolveArtifact(
ms.getRepositorySession(),
new ArtifactRequest(new DefaultArtifact(coords),
RepositoryUtils.toRepos(ms.getRequest().getRemoteRepositories()),
null));
}
示例14: findProjectArtifact
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
private static Artifact findProjectArtifact(MavenProject project) {
String extension = project.getArtifact().getArtifactHandler().getExtension();
String fileName = project.getModel().getBuild().getFinalName() + "." + extension;
File f = new File(new File(project.getBasedir(), "target"), fileName);
if (f.exists()) {
Artifact ret = RepositoryUtils.toArtifact(project.getArtifact());
return ret.setFile(f);
} else {
return null;
}
}
示例15: resolveDependencies
import org.apache.maven.RepositoryUtils; //导入依赖的package包/类
private DependencyResolutionResult resolveDependencies( MavenProject project, RepositorySystemSession session )
{
DependencyResolutionResult resolutionResult = null;
try
{
DefaultDependencyResolutionRequest resolution = new DefaultDependencyResolutionRequest( project, session );
resolutionResult = dependencyResolver.resolve( resolution );
}
catch ( DependencyResolutionException e )
{
resolutionResult = e.getResult();
}
Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
if ( resolutionResult.getDependencyGraph() != null )
{
RepositoryUtils.toArtifacts( artifacts, resolutionResult.getDependencyGraph().getChildren(),
Collections.singletonList( project.getArtifact().getId() ), null );
// Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
for ( Artifact artifact : artifacts )
{
if ( !artifact.isResolved() )
{
String path = lrm.getPathForLocalArtifact( RepositoryUtils.toArtifact( artifact ) );
artifact.setFile( new File( lrm.getRepository().getBasedir(), path ) );
}
}
}
project.setResolvedArtifacts( artifacts );
project.setArtifacts( artifacts );
return resolutionResult;
}