Java Code Examples for org.apache.maven.artifact.Artifact#getGroupId()
The following examples show how to use
org.apache.maven.artifact.Artifact#getGroupId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UseLatestReleasesMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
private ArtifactVersion[] filterVersionsWithIncludes( ArtifactVersion[] newer, Artifact artifact ) { List<ArtifactVersion> filteredNewer = new ArrayList<>( newer.length ); for ( int j = 0; j < newer.length; j++ ) { ArtifactVersion artifactVersion = newer[j]; Artifact artefactWithNewVersion = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), VersionRange.createFromVersion( artifactVersion.toString() ), artifact.getScope(), artifact.getType(), null, new DefaultArtifactHandler(), false ); if ( isIncluded( artefactWithNewVersion ) ) { filteredNewer.add( artifactVersion ); } } return filteredNewer.toArray( new ArtifactVersion[filteredNewer.size()] ); }
Example 2
Source File: EarImpl.java From netbeans with Apache License 2.0 | 6 votes |
private EarImpl.MavenModule findMavenModule(Artifact art, EarImpl.MavenModule[] mm) { EarImpl.MavenModule toRet = null; for (EarImpl.MavenModule m : mm) { if (art.getGroupId().equals(m.groupId) && art.getArtifactId().equals(m.artifactId)) { m.artifact = art; toRet = m; break; } } if (toRet == null) { toRet = new EarImpl.MavenModule(); toRet.artifact = art; toRet.groupId = art.getGroupId(); toRet.artifactId = art.getArtifactId(); toRet.classifier = art.getClassifier(); //add type as well? } return toRet; }
Example 3
Source File: DependenciesMojo.java From mangooio with Apache License 2.0 | 5 votes |
private String coordinates(Artifact artifact) { String classifier = artifact.getClassifier(); String extension = artifact.getType(); String version = snapshotStyle == SnapshotStyle.SNAPSHOT ? artifact.getBaseVersion() : artifact.getVersion(); return artifact.getGroupId() + ":" + artifact.getArtifactId() + (hasText(extension) && (!"jar".equals(extension) || hasText(classifier)) ? ":" + extension : "") + (hasText(classifier) ? ":" + classifier : "") + ":" + version; }
Example 4
Source File: ExampleGraphMojo.java From depgraph-maven-plugin with Apache License 2.0 | 5 votes |
private static DependencyNode createConflict(Artifact artifact, String winningVersion) { org.eclipse.aether.artifact.DefaultArtifact aetherArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType(), artifact.getVersion()); org.eclipse.aether.artifact.DefaultArtifact winnerArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType(), winningVersion); DefaultDependencyNode dependencyNode = new DefaultDependencyNode(new Dependency(aetherArtifact, artifact.getScope())); dependencyNode.setData(NODE_DATA_WINNER, new DefaultDependencyNode(new Dependency(winnerArtifact, "compile"))); return new DependencyNode(dependencyNode); }
Example 5
Source File: MavenUtils.java From mvn-golang with Apache License 2.0 | 5 votes |
/** * Make artifact record from a maven artifact * * @param artifact artifact to be converted into string, must not be null * @return string representation of artifact, must not be null * @see #parseArtifactRecord(java.lang.String, * org.apache.maven.artifact.handler.ArtifactHandler) */ @Nonnull public static String makeArtifactRecord(@Nonnull final Artifact artifact) { return artifact.getGroupId() + "::" + artifact.getArtifactId() + "::" + artifact.getVersionRange().toString() + "::" + GetUtils.ensureNonNull(artifact.getScope(), "compile") + "::" + GetUtils.ensureNonNull(artifact.getType(), "zip") + "::" + GetUtils.ensureNonNull(artifact.getClassifier(), ""); }
Example 6
Source File: BotsingMojo.java From botsing with Apache License 2.0 | 5 votes |
private File getArtifactFile(Artifact artifact) throws MojoExecutionException { /** * Taken from https://gist.github.com/vincent-zurczak/282775f56d27e12a70d3 */ DefaultArtifact aetherArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType(), artifact.getVersion()); return getArtifactFile(aetherArtifact); }
Example 7
Source File: AgentDependencies.java From promagent with Apache License 2.0 | 5 votes |
private static void failOnVersionConflict(Artifact artifact, List<Artifact> knownArtifacts, String pluginArtifactId) throws MojoExecutionException { Optional<String> conflictingVersion = knownArtifacts.stream() .filter(artifactMatcherWithoutVersion(artifact)) .filter(artifactMatcherWithVersion(artifact).negate()) // same version -> not conflicting .findFirst() .map(Artifact::getVersion); if (conflictingVersion.isPresent()) { String artifactName = artifact.getGroupId() + artifact.getArtifactId(); throw new MojoExecutionException("version conflict in " + pluginArtifactId + ": " + artifactName + " found in version " + artifact.getVersion() + " and version " + conflictingVersion.get()); } }
Example 8
Source File: NarMojo.java From nifi-maven with Apache License 2.0 | 5 votes |
private NarDependency getNarDependency() throws MojoExecutionException { NarDependency narDependency = null; // get nar dependencies FilterArtifacts filter = new FilterArtifacts(); filter.addFilter(new TypeFilter("nar", "")); // start with all artifacts. Set artifacts = project.getArtifacts(); // perform filtering try { artifacts = filter.filter(artifacts); } catch (ArtifactFilterException e) { throw new MojoExecutionException(e.getMessage(), e); } // ensure there is a single nar dependency if (artifacts.size() > 1) { throw new MojoExecutionException("Each NAR represents a ClassLoader. A NAR dependency allows that NAR's ClassLoader to be " + "used as the parent of this NAR's ClassLoader. As a result, only a single NAR dependency is allowed."); } else if (artifacts.size() == 1) { final Artifact artifact = (Artifact) artifacts.iterator().next(); narDependency = new NarDependency(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); } return narDependency; }
Example 9
Source File: ExcludeDependencyPanel.java From netbeans with Apache License 2.0 | 5 votes |
private TreeNode createTransitiveDependenciesList() { DefaultMutableTreeNode root = new DefaultMutableTreeNode(null, true); Set<Artifact> artifacts = project.getArtifacts(); Icon icn = ImageUtilities.image2Icon(ImageUtilities.loadImage(IconResources.TRANSITIVE_DEPENDENCY_ICON, true)); //NOI18N for (Artifact a : artifacts) { if (a.getDependencyTrail().size() > 2) { String label = a.getGroupId() + ":" + a.getArtifactId(); root.add(new CheckNode(a, label, icn)); } } return root; }
Example 10
Source File: AbstractSwarmMojo.java From thorntail with Apache License 2.0 | 5 votes |
private static ArtifactSpec asBucketKey(Artifact artifact) { return new ArtifactSpec( artifact.getScope(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getType(), artifact.getClassifier(), artifact.getFile() ); }
Example 11
Source File: DependencyFilter.java From pitest with Apache License 2.0 | 4 votes |
@Override public boolean test(final Artifact a) { final GroupIdPair p = new GroupIdPair(a.getGroupId(), a.getArtifactId()); return this.groups.contains(p); }
Example 12
Source File: MavenProjectUtil.java From microprofile-sandbox with Apache License 2.0 | 4 votes |
public static Map<String, String> getAllDependencies(MavenProject project, RepositorySystem repoSystem, RepositorySystemSession repoSession, List<RemoteRepository> remoteRepos, BoostLogger logger) throws ArtifactDescriptorException { logger.debug("Processing project for dependencies."); Map<String, String> dependencies = new HashMap<String, String>(); for (Artifact artifact : project.getArtifacts()) { logger.debug("Found dependency while processing project: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + ":" + artifact.getType() + ":" + artifact.getScope()); if (artifact.getType().equals("war")) { logger.debug("Resolving transitive booster dependencies for war"); org.eclipse.aether.artifact.Artifact pomArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion()); List<org.eclipse.aether.artifact.Artifact> warArtifacts = getWarArtifacts(pomArtifact, repoSystem, repoSession, remoteRepos); for (org.eclipse.aether.artifact.Artifact warArtifact : warArtifacts) { // Only add booster dependencies for this war. Anything else // like datasource // dependencies must be explicitly defined by this project. // This is to allow the // current project to have full control over those optional // dependencies. if (warArtifact.getGroupId().equals(AbstractBoosterConfig.BOOSTERS_GROUP_ID)) { logger.debug("Found booster dependency: " + warArtifact.getGroupId() + ":" + warArtifact.getArtifactId() + ":" + warArtifact.getVersion()); dependencies.put(warArtifact.getGroupId() + ":" + warArtifact.getArtifactId(), warArtifact.getVersion()); } } } else { dependencies.put(artifact.getGroupId() + ":" + artifact.getArtifactId(), artifact.getVersion()); } } return dependencies; }
Example 13
Source File: MavenWhiteListQueryImpl.java From netbeans with Apache License 2.0 | 4 votes |
boolean hasOnClassPath(Artifact art) { //construct ID as we do in NetbeansManifestUpdateMojo String id = art.getGroupId() + ":" + art.getArtifactId() + ":" + art.getBaseVersion() + (art.getClassifier() != null ? ":" + art.getClassifier() : ""); return mavenCP.contains(id); }
Example 14
Source File: PackageMojo.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 4 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { initProperties(false); final BuildTool tool = new BuildTool(); tool.projectArtifact( this.project.getArtifact().getGroupId(), this.project.getArtifact().getArtifactId(), this.project.getArtifact().getBaseVersion(), this.project.getArtifact().getType(), this.project.getArtifact().getFile()); this.project.getArtifacts() .forEach(dep -> tool.dependency(dep.getScope(), dep.getGroupId(), dep.getArtifactId(), dep.getBaseVersion(), dep.getType(), dep.getClassifier(), dep.getFile(), dep.getDependencyTrail().size() == 2)); List<Resource> resources = this.project.getResources(); for (Resource each : resources) { tool.resourceDirectory(each.getDirectory()); } for (String additionalModule : additionalModules) { File source = new File(this.project.getBuild().getOutputDirectory(), additionalModule); if (source.exists()) { tool.additionalModule(source.getAbsolutePath()); } } tool .properties(this.properties) .mainClass(this.mainClass) .bundleDependencies(this.bundleDependencies); MavenArtifactResolvingHelper resolvingHelper = new MavenArtifactResolvingHelper(this.resolver, this.repositorySystem, this.repositorySystemSession); this.remoteRepositories.forEach(resolvingHelper::remoteRepository); tool.artifactResolvingHelper(resolvingHelper); try { File jar = tool.build(this.project.getBuild().getFinalName(), Paths.get(this.projectBuildDir)); Artifact primaryArtifact = this.project.getArtifact(); ArtifactHandler handler = new DefaultArtifactHandler("jar"); Artifact swarmJarArtifact = new DefaultArtifact( primaryArtifact.getGroupId(), primaryArtifact.getArtifactId(), primaryArtifact.getBaseVersion(), primaryArtifact.getScope(), "jar", "swarm", handler ); swarmJarArtifact.setFile(jar); this.project.addAttachedArtifact(swarmJarArtifact); } catch (Exception e) { throw new MojoFailureException("Unable to create -swarm.jar", e); } }
Example 15
Source File: ArtifactMultiViewFactory.java From netbeans with Apache License 2.0 | 4 votes |
private static String getTcId(Artifact artifact) { return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(); }
Example 16
Source File: ScopeFilter.java From sundrio with Apache License 2.0 | 4 votes |
public Artifact apply(Artifact artifact) { return artifact == null ? null : new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() != null ? artifact.getScope() : Artifact.SCOPE_COMPILE, artifact.getType(), artifact.getClassifier(), artifact.getArtifactHandler()); }
Example 17
Source File: ArkPluginMojoTest.java From sofa-ark with Apache License 2.0 | 4 votes |
@Test public void testShadeJar(@Mocked final MavenProject projectOne, @Mocked final MavenProject projectTwo, @Mocked final Artifact artifact) { ArkPluginMojo arkPluginMojo = new ArkPluginMojo(); arkPluginMojo.setShades(new LinkedHashSet<>(Collections .singleton("com.alipay.sofa:test-demo:1.0.0"))); new Expectations() { { projectOne.getGroupId(); result = "com.alipay.sofa"; minTimes = 0; projectOne.getArtifactId(); result = "test-demo"; minTimes = 0; projectTwo.getGroupId(); result = "com.alipay.sofa"; minTimes = 0; projectTwo.getArtifactId(); result = ""; minTimes = 0; artifact.getGroupId(); result = "com.alipay.sofa"; minTimes = 0; artifact.getArtifactId(); result = "test-demo"; artifact.getVersion(); result = "1.0.0"; minTimes = 0; } }; arkPluginMojo.setProject(projectOne); try { arkPluginMojo.isShadeJar(artifact); } catch (Exception ex) { Assert.assertTrue(ex.getMessage().equals("Can't shade jar-self.")); } arkPluginMojo.setProject(projectTwo); Assert.assertTrue(arkPluginMojo.isShadeJar(artifact)); }
Example 18
Source File: DeployMojoSupport.java From ci.maven with Apache License 2.0 | 4 votes |
protected void installLooseConfigEar(MavenProject proj, LooseConfigData config) throws Exception { LooseEarApplication looseEar = new LooseEarApplication(proj, config); looseEar.addSourceDir(); looseEar.addApplicationXmlFile(); Set<Artifact> artifacts = proj.getArtifacts(); log.debug("Number of compile dependencies for " + proj.getArtifactId() + " : " + artifacts.size()); for (Artifact artifact : artifacts) { if ("compile".equals(artifact.getScope()) || "runtime".equals(artifact.getScope())) { if (!isReactorMavenProject(artifact)) { if (looseEar.isEarSkinnyWars() && "war".equals(artifact.getType())) { throw new MojoExecutionException( "Unable to create loose configuration for the EAR application with skinnyWars package from " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + ". Please set the looseApplication configuration parameter to false and try again."); } looseEar.addModuleFromM2(resolveArtifact(artifact)); } else { MavenProject dependencyProject = getReactorMavenProject(artifact); switch (artifact.getType()) { case "jar": looseEar.addJarModule(dependencyProject); break; case "ejb": looseEar.addEjbModule(dependencyProject); break; case "war": Element warArchive = looseEar.addWarModule(dependencyProject, getWarSourceDirectory(dependencyProject)); if (looseEar.isEarSkinnyWars()) { // add embedded lib only if they are not a compile dependency in the ear // project. addSkinnyWarLib(warArchive, dependencyProject, looseEar); } else { addEmbeddedLib(warArchive, dependencyProject, looseEar, "/WEB-INF/lib/"); } break; case "rar": Element rarArchive = looseEar.addRarModule(dependencyProject); addEmbeddedLib(rarArchive, dependencyProject, looseEar, "/"); break; default: // use the artifact from local .m2 repo looseEar.addModuleFromM2(resolveArtifact(artifact)); break; } } } } // add Manifest file File manifestFile = MavenProjectUtil.getManifestFile(proj, "maven-ear-plugin"); looseEar.addManifestFile(manifestFile); }
Example 19
Source File: MavenProjectUtil.java From boost with Eclipse Public License 1.0 | 4 votes |
public static Map<String, String> getAllDependencies(MavenProject project, RepositorySystem repoSystem, RepositorySystemSession repoSession, List<RemoteRepository> remoteRepos, BoostLogger logger) throws ArtifactDescriptorException { logger.debug("Processing project for dependencies."); Map<String, String> dependencies = new HashMap<String, String>(); for (Artifact artifact : project.getArtifacts()) { logger.debug("Found dependency while processing project: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + ":" + artifact.getType() + ":" + artifact.getScope()); if (artifact.getType().equals("war")) { logger.debug("Resolving transitive booster dependencies for war"); org.eclipse.aether.artifact.Artifact pomArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion()); List<org.eclipse.aether.artifact.Artifact> warArtifacts = getWarArtifacts(pomArtifact, repoSystem, repoSession, remoteRepos); for (org.eclipse.aether.artifact.Artifact warArtifact : warArtifacts) { // Only add booster dependencies for this war. Anything else // like datasource // dependencies must be explicitly defined by this project. // This is to allow the // current project to have full control over those optional // dependencies. if (warArtifact.getGroupId().equals(AbstractBoosterConfig.BOOSTERS_GROUP_ID)) { logger.debug("Found booster dependency: " + warArtifact.getGroupId() + ":" + warArtifact.getArtifactId() + ":" + warArtifact.getVersion()); dependencies.put(warArtifact.getGroupId() + ":" + warArtifact.getArtifactId(), warArtifact.getVersion()); } } } else { dependencies.put(artifact.getGroupId() + ":" + artifact.getArtifactId(), artifact.getVersion()); } } return dependencies; }
Example 20
Source File: TestProvidedArtifacts.java From vespa with Apache License 2.0 | votes |
private static String toArtifactStringId(Artifact artifact) { return artifact.getGroupId() + ":" + artifact.getArtifactId(); }