Java Code Examples for org.apache.maven.artifact.Artifact#getClassifier()

The following examples show how to use org.apache.maven.artifact.Artifact#getClassifier() . 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: InitializeMojo.java    From vertx-maven-plugin with Apache License 2.0 6 votes vote down vote up
private void copyJavascriptDependency(Artifact artifact, File file) throws MojoExecutionException {
    try {
        if (stripJavaScriptDependencyVersion) {
            String name = artifact.getArtifactId();
            if (artifact.getClassifier() != null) {
                name += "-" + artifact.getClassifier();
            }
            name += ".js";
            File output = new File(createWebRootDirIfNeeded(), name);
            FileUtils.copyFile(file, output);
        } else {
            FileUtils.copyFileToDirectory(file, createWebRootDirIfNeeded());
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to copy '"
            + artifact.toString() + "'", e);
    }
}
 
Example 2
Source File: InstallPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages("TXT_InstallTask=Install artifact")
public static void runInstallGoal(NbMavenProjectImpl project, File fil, Artifact art) {
    BeanRunConfig brc = new BeanRunConfig();
    brc.setExecutionDirectory(project.getPOMFile().getParentFile());
    brc.setProject(project);
    brc.setGoals(Collections.singletonList(MavenCommandSettings.getDefault().getCommand(MavenCommandSettings.COMMAND_INSTALL_FILE))); //NOI18N
    brc.setExecutionName("install-artifact"); //NOI18N
    brc.setProperty("artifactId", art.getArtifactId()); //NOI18N
    brc.setProperty("groupId", art.getGroupId()); //NOI18N
    brc.setProperty("version", art.getVersion()); //NOI18N
    brc.setProperty("packaging", art.getType()); //NOI18N
    if (art.getClassifier() != null) {
        brc.setProperty("classifier", art.getClassifier()); //NOI18N
    }
    brc.setProperty("file", fil.getAbsolutePath()); //NOI18N
    brc.setProperty("generatePom", "false"); //NOI18N
    brc.setActivatedProfiles(Collections.<String>emptyList());
    brc.setTaskDisplayName(TXT_InstallTask());
    RunUtils.executeMaven(brc); //NOI18N
    //TODO how to handle errors
    
}
 
Example 3
Source File: EarImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 4
Source File: BaseCycloneDxMojo.java    From cyclonedx-maven-plugin with Apache License 2.0 6 votes vote down vote up
private String generatePackageUrl(final Artifact artifact) {
    try {
        TreeMap<String, String> qualifiers = null;
        if (artifact.getType() != null || artifact.getClassifier() != null) {
            qualifiers = new TreeMap<>();
            if (artifact.getType() != null) {
                qualifiers.put("type", artifact.getType());
            }
            if (artifact.getClassifier() != null) {
                qualifiers.put("classifier", artifact.getClassifier());
            }
        }
        return new PackageURL(PackageURL.StandardTypes.MAVEN,
                artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), qualifiers, null).canonicalize();
    } catch (MalformedPackageURLException e) {
        getLog().warn("An unexpected issue occurred attempting to create a PackageURL for "
                + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(), e);
    }
    return null;
}
 
Example 5
Source File: ProGuardMojo.java    From code-hidding-plugin with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 6
Source File: AbstractCodegenMojo.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean isArtifactMatched(Artifact targetArtifact, Artifact pArtifact) {
    return targetArtifact.getGroupId().equals(pArtifact.getGroupId())
            && targetArtifact.getArtifactId().equals(pArtifact.getArtifactId())
            && targetArtifact.getVersion().equals(pArtifact.getVersion())
            && ("wsdl".equals(pArtifact.getType())
            || (
                    targetArtifact.getClassifier() != null
                            && pArtifact.getType() != null
                            && (targetArtifact.getClassifier() + ".wsdl").equals(pArtifact.getType())
            ));
}
 
Example 7
Source File: FullDependencyFilenameStrategy.java    From webstart with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public String getDependencyFileBasename( Artifact artifact, Boolean outputJarVersion, Boolean useUniqueVersions )
{
    String filename = artifact.getGroupId() + "-" + artifact.getArtifactId();

    if ( outputJarVersion != null )
    {

        if ( outputJarVersion )
        {
            filename += "__V";
        }
        else
        {
            filename += "-";
        }

        filename += getDependencyFileVersion( artifact, useUniqueVersions );
    }

    if ( StringUtils.isNotEmpty( artifact.getClassifier() ) )
    {
        filename += "-" + artifact.getClassifier();
    }

    return filename;
}
 
Example 8
Source File: CompareDependenciesMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a key that is similar to what {@link Dependency#getManagementKey()} generates for a dependency.
 */
private static String generateId( Artifact artifact )
{
    StringBuilder sb = new StringBuilder();
    sb.append( artifact.getGroupId() ).append( ":" ).append( artifact.getArtifactId() ).append( ":" ).append( artifact.getType() );
    if ( artifact.getClassifier() != null )
    {
        sb.append( ":" ).append( artifact.getClassifier() );
    }
    return sb.toString();
}
 
Example 9
Source File: DependenciesRenderer.java    From maven-confluence-plugin with Apache License 2.0 5 votes vote down vote up
private String[] getArtifactRow( Artifact artifact )
{
    return new String[] {
      		artifact.getGroupId(), 
      		artifact.getArtifactId(), 
      		artifact.getVersion(),
      		artifact.getClassifier(), 
      		artifact.getType(), 
      		artifact.isOptional() ? "(optional)" : " "
    			};
}
 
Example 10
Source File: AbstractMavenEventHandler.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
public Xpp3Dom newElement(@Nonnull String name, @Nullable Artifact artifact) {
    Xpp3Dom element = new Xpp3Dom(name);
    if (artifact == null) {
        return element;
    }

    element.setAttribute("groupId", artifact.getGroupId());
    element.setAttribute("artifactId", artifact.getArtifactId());
    element.setAttribute("baseVersion", artifact.getBaseVersion());
    element.setAttribute("version", artifact.getVersion());
    element.setAttribute("snapshot", String.valueOf(artifact.isSnapshot()));
    if (artifact.getClassifier() != null) {
        element.setAttribute("classifier", artifact.getClassifier());
    }
    element.setAttribute("type", artifact.getType());
    element.setAttribute("id", artifact.getId());

    ArtifactHandler artifactHandler = artifact.getArtifactHandler();
    String extension;
    if (artifactHandler == null) {
        extension = artifact.getType();
    } else {
        extension = artifactHandler.getExtension();
    }
    element.setAttribute("extension", extension);

    return element;
}
 
Example 11
Source File: ExampleGraphMojo.java    From depgraph-maven-plugin with Apache License 2.0 5 votes vote down vote up
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 12
Source File: AbstractSwarmMojo.java    From thorntail with Apache License 2.0 5 votes vote down vote up
protected ArtifactSpec artifactToArtifactSpec(Artifact dep) {
    return new ArtifactSpec(dep.getScope(),
                            dep.getGroupId(),
                            dep.getArtifactId(),
                            dep.getBaseVersion(),
                            dep.getType(),
                            dep.getClassifier(),
                            dep.getFile());
}
 
Example 13
Source File: AbstractSwarmMojo.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
protected ArtifactSpec artifactToArtifactSpec(Artifact dep) {
    return new ArtifactSpec(dep.getScope(),
                            dep.getGroupId(),
                            dep.getArtifactId(),
                            dep.getBaseVersion(),
                            dep.getType(),
                            dep.getClassifier(),
                            dep.getFile());
}
 
Example 14
Source File: ArtifactFilter.java    From code-hidding-plugin with GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean match(Artifact artifact) {
    boolean artifactMatch = WILDCARD.equals(artifactId) || artifact.getArtifactId().equals(this.artifactId) ||
            (artifactId != null && getMatcher(artifact).matches());
    boolean groupMatch = artifact.getGroupId().equals(this.groupId);
    boolean classifierMatch = ((this.classifier == null) && (artifact.getClassifier() == null)) || ((this.classifier != null) && this.classifier.equals(artifact.getClassifier()));
    return artifactMatch && groupMatch && classifierMatch;
}
 
Example 15
Source File: InitializeMojo.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private void copyJSDependencies(Set<Artifact> dependencies) throws MojoExecutionException {
    for (Artifact artifact : dependencies) {
        if (artifact.getType().equalsIgnoreCase("js")) {
            Optional<File> file = getArtifactFile(artifact);
            if (file.isPresent()) {
                try {
                    if (stripJavaScriptDependencyVersion) {
                        String name = artifact.getArtifactId();
                        if (artifact.getClassifier() != null) {
                            name += "-" + artifact.getClassifier();
                        }
                        name += ".js";
                        File output = new File(createWebRootDirIfNeeded(), name);
                        FileUtils.copyFile(file.get(), output);
                    } else {
                        FileUtils.copyFileToDirectory(file.get(), createWebRootDirIfNeeded());
                    }
                } catch (IOException e) {
                    throw new MojoExecutionException("Unable to copy '"
                        + artifact.toString() + "'", e);
                }
            } else {
                getLog().warn("Skipped the copy of '"
                    + artifact.toString() + "' - The artifact file does not exist");
            }
        }
    }
}
 
Example 16
Source File: BotsingMojo.java    From botsing with Apache License 2.0 5 votes vote down vote up
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 17
Source File: DependenciesMojo.java    From mangooio with Apache License 2.0 5 votes vote down vote up
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 18
Source File: MavenWhiteListQueryImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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 19
Source File: DependencyNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
    final Collection<? extends Artifact> artifacts = lkp.lookupAll(Artifact.class);
    if (artifacts.isEmpty()) {
        return;
    }
    Collection<? extends NbMavenProjectImpl> res = lkp.lookupAll(NbMavenProjectImpl.class);
    Set<NbMavenProjectImpl> prjs = new HashSet<NbMavenProjectImpl>(res);
    if (prjs.size() != 1) {
        return;
    }
    final NbMavenProjectImpl project = prjs.iterator().next();

    final ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
        @Override
        public void performOperation(POMModel model) {
            for (Artifact art : artifacts) {
                org.netbeans.modules.maven.model.pom.Dependency dep = model.getProject().findDependencyById(art.getGroupId(), art.getArtifactId(), null);
                if (dep == null) {
                    // now check the active profiles for the dependency..
                    List<String> profileNames = new ArrayList<String>();
                    Iterator it = project.getOriginalMavenProject().getActiveProfiles().iterator();
                    while (it.hasNext()) {
                        Profile prof = (Profile) it.next();
                        profileNames.add(prof.getId());
                    }
                    for (String profileId : profileNames) {
                        org.netbeans.modules.maven.model.pom.Profile modProf = model.getProject().findProfileById(profileId);
                        if (modProf != null) {
                            dep = modProf.findDependencyById(art.getGroupId(), art.getArtifactId(), null);
                            if (dep != null) {
                                break;
                            }
                        }
                    }
                }
                if (dep == null) {
                    dep = model.getFactory().createDependency();
                    dep.setGroupId(art.getGroupId());
                    dep.setArtifactId(art.getArtifactId());
                    dep.setVersion(art.getVersion());
                    if (!"jar".equals(art.getType())) {
                        dep.setType(art.getType());
                    }
                    if (!Artifact.SCOPE_COMPILE.equals(art.getScope())) {
                        dep.setScope(art.getScope());
                    }
                    if (art.getClassifier() != null) {
                        dep.setClassifier(art.getClassifier());
                    }
                    model.getProject().addDependency(dep);
                }
            }
        }
    };
    RP.post(new Runnable() {
        @Override
        public void run() {
            FileObject fo = FileUtil.toFileObject(project.getPOMFile());
            org.netbeans.modules.maven.model.Utilities.performPOMModelOperations(fo, Collections.singletonList(operation));
        }
    });
}
 
Example 20
Source File: ScopeFilter.java    From sundrio with Apache License 2.0 4 votes vote down vote up
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());
}