Java Code Examples for org.apache.maven.artifact.Artifact#getArtifactId()
The following examples show how to use
org.apache.maven.artifact.Artifact#getArtifactId() .
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: MojoUtil.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public static Set<URL> getProjectFiles(final MavenProject mavenProject, final List<InternalKieModule> kmoduleDeps) throws DependencyResolutionRequiredException, IOException { final Set<URL> urls = new HashSet<>(); for (final String element : mavenProject.getCompileClasspathElements()) { urls.add(new File(element).toURI().toURL()); } mavenProject.setArtifactFilter(new CumulativeScopeArtifactFilter(Arrays.asList("compile", "runtime"))); for (final Artifact artifact : mavenProject.getArtifacts()) { final File file = artifact.getFile(); if (file != null && file.isFile()) { urls.add(file.toURI().toURL()); final KieModuleModel depModel = getDependencyKieModel(file); if (kmoduleDeps != null && depModel != null) { final ReleaseId releaseId = new ReleaseIdImpl(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); kmoduleDeps.add(new ZipKieModule(releaseId, depModel, file)); } } } return urls; }
Example 2
Source File: LibertyRuntime.java From boost with Eclipse Public License 1.0 | 6 votes |
/** * Assumes a non-WAR packaging type (like JAR) has a WAR dependency. We assume * there's only 1 but don't check, just return the first one. * * @return * @throws BoostException */ private String getWarName() throws BoostException { String retVal = null; if (project.getPackaging().equals(ConfigConstants.WAR_PKG_TYPE)) { retVal = project.getBuild().getFinalName(); } else { // JAR package "release", get WAR from dependency for (Artifact artifact : project.getArtifacts()) { // first WAR if (artifact.getType().equals("war")) { retVal = artifact.getArtifactId() + "-" + artifact.getVersion(); break; } } if (retVal == null) { BoostLogger log = BoostLogger.getSystemStreamLogger(); String msg = "With non-WAR packaging type, we require a WAR dependency"; log.error(msg); throw new BoostException(msg); } } return retVal; }
Example 3
Source File: ProGuardMojo.java From code-hidding-plugin with GNU Lesser General Public License v2.1 | 6 votes |
private static File getClasspathElement(Artifact artifact, MavenProject mavenProject) throws MojoExecutionException { if (artifact.getClassifier() != null) { return artifact.getFile(); } String refId = artifact.getGroupId() + ":" + artifact.getArtifactId(); MavenProject project = (MavenProject) mavenProject.getProjectReferences().get(refId); if (project != null) { return new File(project.getBuild().getOutputDirectory()); } else { File file = artifact.getFile(); if ((file == null) || (!file.exists())) { throw new MojoExecutionException("Dependency Resolution Required " + artifact); } return file; } }
Example 4
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 5
Source File: ExcludeDependencyPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void setReferenceTree(CheckNode mtb) { Artifact art = (Artifact) mtb.getUserObject(); if (modelCache.containsKey(art)) { trRef.setModel(modelCache.get(art)); } else { if (rootnode == null) { trRef.setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); } else { DependencyExcludeNodeVisitor nv = new DependencyExcludeNodeVisitor(art.getGroupId(), art.getArtifactId(), art.getType()); rootnode.accept(nv); Set<DependencyNode> nds = nv.getDirectDependencies(); DefaultTreeModel dtm = new DefaultTreeModel(createReferenceModel(nds, mtb)); trRef.setModel(dtm); modelCache.put(art, dtm); } } }
Example 6
Source File: SearchClassDependencyInRepo.java From netbeans with Apache License 2.0 | 6 votes |
private Artifact getArtifact(NbMavenProject mavProj, List<NBVersionInfo> nbvis, boolean isTestSource) { MavenProject mp = mavProj.getMavenProject(); List<Artifact> arts = new LinkedList<Artifact>(isTestSource ? mp.getTestArtifacts() : mp.getCompileArtifacts()); for (NBVersionInfo info : nbvis) { for (Artifact a : arts) { if (a.getGroupId() != null && a.getGroupId().equals(info.getGroupId())) { if (a.getArtifactId() != null && a.getArtifactId().equals(info.getArtifactId())) { String scope = a.getScope(); if ("compile".equals(scope) || "test".equals(scope)) { // NOI18N return a; } } } } } return null; }
Example 7
Source File: AbstractSwarmMojo.java From wildfly-swarm with Apache License 2.0 | 5 votes |
protected ArtifactSpec artifactToArtifactSpec(Artifact dep) { return new ArtifactSpec(dep.getScope(), dep.getGroupId(), dep.getArtifactId(), dep.getBaseVersion(), dep.getType(), dep.getClassifier(), dep.getFile()); }
Example 8
Source File: NativeUnZipIncMojo.java From maven-native with MIT License | 5 votes |
private boolean unpackIncZipDepenedencies() throws MojoExecutionException { List<Artifact> files = getIncZipDependencies(); Iterator<Artifact> iter = files.iterator(); for ( int i = 0; i < files.size(); ++i ) { Artifact artifact = iter.next(); File incZipFile = artifact.getFile(); File marker = new File( this.dependencyIncZipMarkerDirectory, artifact.getGroupId() + "." + artifact.getArtifactId() ); if ( !marker.exists() || marker.lastModified() < incZipFile.lastModified() ) { try { unpackZipFile( incZipFile ); marker.delete(); if ( !dependencyIncZipMarkerDirectory.exists() ) { dependencyIncZipMarkerDirectory.mkdirs(); } marker.createNewFile(); } catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } } return files.size() != 0; }
Example 9
Source File: DependencyNodeUtil.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 10
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 11
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 12
Source File: DependenciesRenderer.java From maven-confluence-plugin with Apache License 2.0 | 5 votes |
private String[] getArtifactRow( Artifact artifact ) { return new String[] { artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier(), artifact.getType(), artifact.isOptional() ? "(optional)" : " " }; }
Example 13
Source File: OpenSourceLicenseCheckMojo.java From license-check with MIT License | 5 votes |
String recurseForLicenseName(final Artifact artifact, final int currentDepth) throws IOException { final File artifactDirectory = artifact.getFile().getParentFile(); String directoryPath = artifactDirectory.getAbsolutePath(); directoryPath += "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + ".pom"; final String pom = readPomContents(directoryPath); // first, look for a license String licenseName = extractLicenseName(pom); if (licenseName == null) { final String parentArtifactCoords = extractParentCoords(pom); if (parentArtifactCoords != null) { // search for the artifact final Artifact parent = retrieveArtifact(parentArtifactCoords); if (parent != null) { // check the recursion depth if (currentDepth >= maxSearchDepth) { return null; // TODO throw an exception } licenseName = recurseForLicenseName(parent, currentDepth + 1); } else { return null; } } else { return null; } } return licenseName; }
Example 14
Source File: BootRecommendedTemplates.java From nb-springboot with Apache License 2.0 | 4 votes |
@Override public String[] getRecommendedTypes() { NbMavenProject project = prj.getLookup().lookup(NbMavenProject.class); EnumSet<SpringDeps> deps = EnumSet.noneOf(SpringDeps.class); List compileArtifacts = project.getMavenProject().getCompileArtifacts(); for (Object obj : compileArtifacts) { if (obj instanceof Artifact) { Artifact artifact = (Artifact) obj; if (artifact.getScope().equals(Artifact.SCOPE_COMPILE)) { final String artifactId = artifact.getArtifactId(); if (artifactId.contains("spring-data")) { deps.add(SpringDeps.DATA); } switch (artifactId) { case "spring-context": deps.add(SpringDeps.CONTEXT); break; case "spring-web": deps.add(SpringDeps.WEB); break; case "spring-webflux": deps.add(SpringDeps.WEBFLUX); break; case "spring-boot": deps.add(SpringDeps.BOOT); break; case "spring-boot-actuator": deps.add(SpringDeps.ACTUATOR); break; } } } } Set<String> recomTypes = new HashSet<>(); if (deps.contains(SpringDeps.BOOT)) { recomTypes.add(CATEGORY_SPRING_BOOT); } if (deps.contains(SpringDeps.DATA)) { recomTypes.add(CATEGORY_SPRING_DATA); } if (deps.contains(SpringDeps.CONTEXT)) { recomTypes.add(CATEGORY_SPRING_FRAMEWORK); } if (deps.contains(SpringDeps.CONTEXT) && deps.contains(SpringDeps.WEB)) { recomTypes.add(CATEGORY_SPRING_MVC); } if (deps.contains(SpringDeps.CONTEXT) && deps.contains(SpringDeps.WEBFLUX)) { recomTypes.add(CATEGORY_SPRING_REACT); } if (deps.contains(SpringDeps.ACTUATOR)) { recomTypes.add(CATEGORY_SPRING_BOOT_ACTUATOR); } return recomTypes.toArray(new String[0]); }
Example 15
Source File: DependencyResolverVisitor.java From dependency-mediator with Apache License 2.0 | 4 votes |
/** * Returns the qualified name for an Artifact. */ private String getQualifiedName(Artifact artifact) { return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType(); }
Example 16
Source File: OpenSourceLicenseCheckMojo.java From license-check with MIT License | 4 votes |
String toCoordinates(Artifact artifact) { return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(); }
Example 17
Source File: JApiCmpMojo.java From japicmp with Apache License 2.0 | 4 votes |
private String toDescriptor(Artifact artifact) { return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(); }
Example 18
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 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: AbstractScanMojo.java From LicenseScout with Apache License 2.0 | 2 votes |
/** * Obtains an artifact description for use in an attach operation. * * <p>The returned object has group ID, artifact ID, version and type set from the current project. * The classifier is set from the Maven parameter {@link #attachReportsClassifier}.</p> * @return an artifact description to attach */ private LSArtifact getAttachArtifact() { final Artifact artifact = mavenProject.getArtifact(); return new LSArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), attachReportsClassifier); }