List of usage examples for org.apache.maven.repository RepositorySystem createArtifact
Artifact createArtifact(String groupId, String artifactId, String version, String scope, String type);
From source file:hudson.maven.MavenEmbedder.java
License:Apache License
public Artifact createArtifact(String groupId, String artifactId, String version, String scope, String type) throws MavenEmbedderException { try {/*ww w. j a va 2 s.c o m*/ RepositorySystem repositorySystem = lookup(RepositorySystem.class); return repositorySystem.createArtifact(groupId, artifactId, version, scope, type); } catch (ComponentLookupException e) { throw new MavenEmbedderException(e.getMessage(), e); } }
From source file:org.ebayopensource.turmeric.eclipse.mavenapi.impl.AbstractMavenApi.java
License:Open Source License
/** * Resolve an artifact using a particular maven implementation and repository. * * @param embedder the embedded version of maven to use * @param repoSystem the repository to resolve against * @param md the artifact metadata to search * @return the resolved artifact//from www . j a v a2s. co m * @throws MavenEclipseApiException the maven eclipse api exception */ public Artifact resolveArtifact(MavenImpl embedder, RepositorySystem repoSystem, ArtifactMetadata md) throws MavenEclipseApiException { if (embedder == null) throw new MavenEclipseApiException(); try { List<ArtifactRepository> repos = _getKnownRepositories(embedder, md.getType()); if (repos == null || repos.size() < 1) { throw new MavenEclipseApiException(Messages.ERROR_NO_REPOSITORIES); } Artifact artifact = null; if (md.getClassifier() == null) artifact = repoSystem.createArtifact(md.getGroupId(), md.getArtifactId(), md.getVersion(), md.getScope(), md.getType()); else artifact = repoSystem.createArtifactWithClassifier(md.getGroupId(), md.getArtifactId(), md.getVersion(), md.getType(), md.getClassifier()); if (artifact == null) { throw new MavenEclipseApiException(Messages.ERROR_NULL_ARTIFACT); } // embedder.resolve(artifact, repos, embedder.getLocalRepository()); MavenApiUtil.resolveArtifact(repoSystem, artifact, embedder.getLocalRepository(), repos); return artifact; } catch (Exception e) { e.printStackTrace(); throw new MavenEclipseApiException(e); } }
From source file:org.ebayopensource.turmeric.eclipse.mavenapi.impl.AbstractMavenEclipseApi.java
License:Open Source License
/** * Create an artifact given the metadata. This populates it into the repository. * * @param metadata the artifact metadata to use. * @return the created artifact.// ww w .j a va2s. c o m * @throws MavenEclipseApiException the maven eclipse api exception */ public Artifact createArtifact(final ArtifactMetadata metadata) throws MavenEclipseApiException { RepositorySystem res = MavenApiHelper.getRepositorySystem(); if (metadata.getClassifier() == null) return res.createArtifact(metadata.getGroupId(), metadata.getArtifactId(), metadata.getVersion(), metadata.getScope(), metadata.getType()); return res.createArtifactWithClassifier(metadata.getGroupId(), metadata.getArtifactId(), metadata.getVersion(), metadata.getType(), metadata.getClassifier()); }
From source file:org.ebayopensource.turmeric.eclipse.mavenapi.internal.util.MavenApiUtil.java
License:Open Source License
/** * Tries to resolve the given {@code ArtifactMetadata}s in the given * local/remote repositories and returns the resolved {@code Artifact}s. * * @param embedder the embedder//from w w w .j a v a 2s . c om * @param mdCollection the md collection * @param localRepository the local repository * @param remoteRepositories the remote repositories * @return the list * @throws MavenEclipseApiException the maven eclipse api exception */ public static List<Artifact> resolveArtifacts(RepositorySystem embedder, List<ArtifactMetadata> mdCollection, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories) throws MavenEclipseApiException { if (mdCollection == null || mdCollection.isEmpty()) { return null; } List<Artifact> res = new ArrayList<Artifact>(mdCollection.size()); Artifact artifact = null; for (Iterator<ArtifactMetadata> i$ = mdCollection.iterator(); i$.hasNext(); res.add(artifact)) { ArtifactMetadata md = i$.next(); artifact = embedder.createArtifact(md.getGroupId(), md.getArtifactId(), md.getVersion(), md.getScope(), md.getType() != null ? md.getType() : "jar"); resolveArtifact(embedder, artifact, localRepository, remoteRepositories); } return res; }
From source file:org.ebayopensource.turmeric.eclipse.mavenapi.internal.util.MavenApiUtil.java
License:Open Source License
private static MetadataTreeNode resolveMetadataTree(RepositorySystem embedder, ArtifactMetadata query, MetadataTreeNode parent, ArtifactRepository localRepository, List remoteRepositories) throws MavenEclipseApiException { try {//from ww w. ja v a2 s.c om Artifact pomArtifact = embedder.createArtifact(query.getGroupId(), query.getArtifactId(), query.getVersion(), query.getScope(), query.getType() != null ? query.getType() : "jar"); //Artifact art = MavenApiHelper.getMavenEmbedder().resolve(groupId, artifactId, version, type, classifier, remoteRepositories, monitor); ArtifactResolutionResult result = resolveArtifact(embedder, pomArtifact, localRepository, remoteRepositories, false); if (pomArtifact.isResolved()) { MetadataTreeNode node = new MetadataTreeNode(query, parent, true, query.getScopeAsEnum()); Set<Artifact> artifacts = result.getArtifacts(); if (artifacts.size() > 1) { List<Artifact> dependencies = new ArrayList<Artifact>(artifacts); // remove the first one, which is the source artifact itself dependencies.remove(0); int nKids = dependencies.size(); node.setNChildren(nKids); int kidNo = 0; MetadataTreeNode kidNode; for (Artifact artifact : dependencies) { ArtifactMetadata amd = new ArtifactMetadata(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), ArtifactScopeEnum.valueOf(artifact.getScope())); // 20100514#emac: no need to resolve dependencies // recursively // kidNode = resolveMetadataTree(embedder, amd, node, // localRepository, remoteRepositories); kidNode = new MetadataTreeNode(amd, node, artifact.isResolved(), amd.getScopeAsEnum()); node.addChild(kidNo++, kidNode); } } return node; } return new MetadataTreeNode(pomArtifact, parent, false, query.getArtifactScope()); } catch (Exception anyEx) { throw new MavenEclipseApiException(anyEx); } }
From source file:org.wso2.maven.p2.utils.MavenUtils.java
License:Open Source License
/** * Returns an artifact which represented by a the given CarbonArtifact. * * @param groupId {@code String} group id of the maven artifact * @param artifactId {@code String} artifact id of the maven artifact * @param version {@code String} version of the maven artifact * @param repositorySystem {@link RepositorySystem} * @param remoteRepositories {@code List<ArtifactRepository>} * @param localRepository {@link ArtifactRepository} * @param type {@code String}/*from w w w . j a v a2s .c o m*/ * @return {@link Artifact} */ private static Artifact getResolvedArtifact(String groupId, String artifactId, String version, RepositorySystem repositorySystem, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository, String type) { Artifact artifact = repositorySystem.createArtifact(groupId, artifactId, version, Artifact.SCOPE_RUNTIME, type); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setLocalRepository(localRepository); request.setRemoteRepositories(remoteRepositories); repositorySystem.resolve(request); return artifact; }