Java Code Examples for org.apache.maven.artifact.Artifact

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project build-info, under directory /build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/.

Source file: BuildInfoRecorder.java

  22 
vote

private void extractModuleArtifact(MavenProject project,Set<Artifact> artifacts){
  Artifact artifact=project.getArtifact();
  if (artifact == null) {
    logger.warn("Skipping Artifactory Build-Info project artifact extraction: Null artifact.");
    return;
  }
  artifacts.add(artifact);
}
 

Example 2

From project cargo-maven2-plugin-db, under directory /src/test/java/org/codehaus/cargo/maven2/configuration/.

Source file: DeployableTest.java

  22 
vote

public void testCreateCustomDeployable() throws Exception {
  Deployable deployableElement=createCustomDeployableElement();
  String deployableFile="testCreateCustomDeployable.custom";
  Artifact artifact=createCustomArtifact(deployableFile);
  Set artifacts=new HashSet();
  artifacts.add(artifact);
  org.codehaus.cargo.container.deployable.Deployable deployable=deployableElement.createDeployable("whateverId",createDefaultProject("war",artifacts));
  assertEquals(CustomType.class.getName(),deployable.getClass().getName());
}
 

Example 3

From project cdk, under directory /maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/.

Source file: AbstractCDKMojo.java

  22 
vote

private String createTaglibVersionFromProjectVersion(){
  Artifact artifact=project.getArtifact();
  String version=artifact.getVersion();
  Matcher matcher=Pattern.compile("^(\\d+(?:\\.\\d+)*)").matcher(version);
  if (matcher.find()) {
    return matcher.group(1);
  }
  return "1.2";
}
 

Example 4

From project clirr-maven-plugin, under directory /src/main/java/org/codehaus/mojo/clirr/.

Source file: AbstractClirrMojo.java

  22 
vote

protected List getTransitiveDependencies(final Set previousArtifacts) throws ProjectBuildingException, InvalidDependencyVersionException, ArtifactResolutionException, ArtifactNotFoundException {
  final List dependencies=new ArrayList();
  for (Iterator iter=previousArtifacts.iterator(); iter.hasNext(); ) {
    final Artifact a=(Artifact)iter.next();
    final Artifact pomArtifact=factory.createArtifact(a.getGroupId(),a.getArtifactId(),a.getVersion(),a.getScope(),"pom");
    final MavenProject pomProject=mavenProjectBuilder.buildFromRepository(pomArtifact,project.getRemoteArtifactRepositories(),localRepository);
    final Set pomProjectArtifacts=pomProject.createArtifacts(factory,null,null);
    final ArtifactResolutionResult result=resolver.resolveTransitively(pomProjectArtifacts,pomArtifact,localRepository,project.getRemoteArtifactRepositories(),metadataSource,null);
    dependencies.addAll(result.getArtifacts());
  }
  return dependencies;
}
 

Example 5

From project cpp-maven-plugins, under directory /cpp-compiler-maven-plugin/src/main/java/com/ericsson/tools/cpp/compiler/.

Source file: TargetCurrencyVerifier.java

  22 
vote

private void addMutableAncestorModelFiles(final Collection<File> collection,final MavenProject parent){
  if (parent == null)   return;
  final Artifact parentPomArtifact=artifactManager.createProjectArtifact(parent);
  if (!parentPomArtifact.isSnapshot()) {
    log.debug("Parent " + parent + " isn't a SNAPSHOT. Ancenstry will not be searched for further mutable configurations.");
    return;
  }
  final File parentPomFile=artifactManager.getPomOfArtifact(parentPomArtifact);
  log.debug("Found mutable parent file " + parentPomFile);
  collection.add(parentPomFile);
  addMutableAncestorModelFiles(collection,parent.getParent());
}
 

Example 6

From project flexmojos, under directory /flexmojos-maven-plugin/src/main/java/net/flexmojos/oss/plugin/.

Source file: AbstractMavenMojo.java

  22 
vote

@SuppressWarnings("unchecked") protected Artifact getFrameworkConfig(){
  Artifact frmkCfg=getDependency(groupId(FRAMEWORK_GROUP_ID),artifactId("framework"),classifier("configs"),type("zip"));
  if (frmkCfg == null) {
    frmkCfg=resolve(FRAMEWORK_GROUP_ID,"framework",getFrameworkVersion(),"configs","zip");
  }
  return frmkCfg;
}
 

Example 7

From project fools-errands, under directory /jboss-tools/eclipse/plugins/org.jboss.tools.m2e.extras/src/org/jboss/tools/m2e/extras/.

Source file: DependencyCopyProjectConfigurator.java

  22 
vote

private String getArtifactFileName(Xpp3Dom artifactItemDom,ProjectConfigurationRequest request,MojoExecution execution,IProgressMonitor monitor) throws CoreException {
  String groupId=getMojoParameterValue("groupId",String.class,artifactItemDom,request,execution);
  String artifactId=getMojoParameterValue("artifactId",String.class,artifactItemDom,request,execution);
  String version=getMojoParameterValue("version",String.class,artifactItemDom,request,execution);
  String type=getMojoParameterValue("type",String.class,artifactItemDom,request,execution);
  String classifier=getMojoParameterValue("classifier",String.class,artifactItemDom,request,execution);
  IMaven maven=MavenPlugin.getMaven();
  Artifact artifact=maven.resolve(groupId,artifactId,version,type,classifier,maven.getArtifactRepositories(),monitor);
  if (artifact == null || artifact.getFile() == null) {
    return null;
  }
  return artifact.getFile().getName();
}
 

Example 8

From project grails-maven, under directory /src/main/java/org/grails/maven/plugin/.

Source file: AbstractGrailsMojo.java

  22 
vote

private Artifact findGrailsDependency(MavenProject project){
  Set dependencyArtifacts=project.getDependencyArtifacts();
  for (  Object o : dependencyArtifacts) {
    Artifact artifact=(Artifact)o;
    if (artifact.getArtifactId().equals("grails-dependencies")) {
      return artifact;
    }
  }
  return null;
}
 

Example 9

From project gwt-maven-plugin, under directory /src/main/java/org/codehaus/mojo/gwt/.

Source file: AbstractGwtMojo.java

  22 
vote

/** 
 * TODO remove ! Check that gwt-dev is not define in dependencies : this can produce version conflicts with other dependencies, as gwt-dev is a "uber-jar" with some commons-* and jetty libs inside.
 */
private void checkGwtDevAsDependency(){
  for (Iterator iterator=getProject().getArtifacts().iterator(); iterator.hasNext(); ) {
    Artifact artifact=(Artifact)iterator.next();
    if (GWT_GROUP_ID.equals(artifact.getGroupId()) && "gwt-dev".equals(artifact.getArtifactId()) && !SCOPE_TEST.equals(artifact.getScope())) {
      getLog().warn("Don't declare gwt-dev as a project dependency. This may introduce complex dependency conflicts");
    }
  }
}
 

Example 10

From project hbc-maven-core, under directory /src/main/java/org/hardisonbrewing/maven/core/.

Source file: DependencyService.java

  22 
vote

/** 
 * Copy all  {@link Dependency} {@link Artifact}s to the specified destination directory.
 * @param dest The destination directory.
 * @throws Exception
 */
public static final void copyDependencies(File dest) throws Exception {
  MavenProject mavenProject=ProjectService.getProject();
  Set<Artifact> artifacts=mavenProject.getDependencyArtifacts();
  Iterator<Artifact> iterator=artifacts.iterator();
  while (iterator.hasNext()) {
    Artifact artifact=iterator.next();
    FileUtils.copyFileToDirectory(artifact.getFile(),dest);
  }
}
 

Example 11

From project jetty-maven-plugin, under directory /src/main/java/org/mortbay/jetty/plugin/.

Source file: RuntimeDependencyResolver.java

  22 
vote

public void removeDependency(Set artifacts,String groupId,String artifactId,String versionId,String type){
  if ((artifacts == null) || artifacts.isEmpty())   return;
  Iterator itor=artifacts.iterator();
  while (itor.hasNext()) {
    Artifact a=(Artifact)itor.next();
    if (a.getGroupId().equals(groupId) && a.getArtifactId().equals(artifactId) && a.getType().equals(type)) {
      if (versionId == null)       itor.remove();
 else       if (a.getVersion().equals(versionId))       itor.remove();
    }
  }
}
 

Example 12

From project jetty-project, under directory /jetty-maven-plugin/src/main/java/org/mortbay/jetty/plugin/.

Source file: AbstractJettyMojo.java

  22 
vote

public boolean isPluginArtifact(Artifact artifact){
  if (pluginArtifacts == null || pluginArtifacts.isEmpty())   return false;
  boolean isPluginArtifact=false;
  for (Iterator<Artifact> iter=pluginArtifacts.iterator(); iter.hasNext() && !isPluginArtifact; ) {
    Artifact pluginArtifact=iter.next();
    if (getLog().isDebugEnabled()) {
      getLog().debug("Checking " + pluginArtifact);
    }
    if (pluginArtifact.getGroupId().equals(artifact.getGroupId()) && pluginArtifact.getArtifactId().equals(artifact.getArtifactId()))     isPluginArtifact=true;
  }
  return isPluginArtifact;
}
 

Example 13

From project karaf, under directory /tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/.

Source file: MavenUtil.java

  22 
vote

static Artifact mvnToArtifact(String name){
  name=mvnToAether(name);
  DefaultArtifact artifact=new DefaultArtifact(name);
  Artifact mavenArtifact=RepositoryUtils.toArtifact(artifact);
  return mavenArtifact;
}
 

Example 14

From project adt-maven-plugin, under directory /src/main/java/com/yelbota/plugins/adt/.

Source file: DependencyAdtMojo.java

  21 
vote

public Artifact getAirSdkArtifact() throws MojoFailureException {
  DependencyHelper dependencyHelper=new DependencyHelper(){
    @Override protected String getDefaultArtifactId() throws MojoFailureException {
      return "air-sdk";
    }
    @Override protected String getDefaultGroupId() throws MojoFailureException {
      return "com.adobe.air";
    }
    @Override protected String getDefaultVersion() throws MojoFailureException {
      return sdkVersion;
    }
    @Override protected String getDefaultPackaging() throws MojoFailureException {
      return getSDKArtifactPackaging(sdkVersion,getDefaultClassifier());
    }
  }
;
  Artifact artifact=dependencyHelper.resolve(pluginArtifacts,repositorySystem,localRepository,remoteRepositories);
  getLog().debug("No plugin dependency defined.");
  if (artifact == null && sdkVersion == null) {
    throw failWith("sdkVersion or plugin dependency must be defined");
  }
  return artifact;
}
 

Example 15

From project flatpack-java, under directory /apidoc-plugin/src/main/java/com/getperka/flatpack/apidoc/.

Source file: ApidocMojo.java

  21 
vote

@SuppressWarnings({"restriction","unchecked"}) private void extractDocStrings() throws MojoFailureException {
  Artifact jar=factory.createArtifact(project.getGroupId(),project.getArtifactId(),project.getVersion(),"compile","jar");
  Set<Artifact> artifacts;
  try {
    ArtifactResolutionResult res=artifactResolver.resolveTransitively(project.getDependencyArtifacts(),jar,remoteRepositories,localRepository,source);
    artifacts=res.getArtifacts();
  }
 catch (  ArtifactNotFoundException e) {
    throw new MojoFailureException("Could not resolve jar",e);
  }
catch (  ArtifactResolutionException e) {
    throw new MojoFailureException("Could not resolve jar",e);
  }
  getLog().debug("Resolved " + artifacts.toString());
  List<String> args=new ArrayList<String>();
  StringBuilder sb=new StringBuilder();
  for (  Artifact a : artifacts) {
    sb.append(File.pathSeparatorChar).append(a.getFile().getAbsolutePath());
  }
  args.add("-classpath");
  args.add(sb.substring(1));
  args.add("-doclet");
  args.add(docletClass);
  args.add("-sourcepath");
  args.add(sourceDirectory.getAbsolutePath());
  args.add("-subpackages");
  args.add(subpackages);
  args.add("-d");
  args.add(outputDirectory.getAbsolutePath());
  int ret=com.sun.tools.javadoc.Main.execute(args.toArray(new String[args.size()]));
  if (ret != 0) {
    throw new MojoFailureException("Javadoc tool returned status code " + ret);
  }
  Resource resource=new Resource();
  resource.setDirectory(outputDirectory.getPath());
  project.addResource(resource);
  buildContext.refresh(outputDirectory);
}
 

Example 16

From project jboss-as-maven-plugin, under directory /src/main/java/org/jboss/as/plugin/deployment/.

Source file: DeployArtifact.java

  21 
vote

@Override @SuppressWarnings("unchecked") public void validate() throws DeploymentFailureException {
  super.validate();
  if (artifactId == null) {
    throw new DeploymentFailureException("deploy-artifact must specify the artifactId");
  }
  if (groupId == null) {
    throw new DeploymentFailureException("deploy-artifact must specify the groupId");
  }
  final Set<Artifact> dependencies=project.getArtifacts();
  dependencies.addAll(project.getDependencyArtifacts());
  Artifact artifact=null;
  for (  final Artifact a : dependencies) {
    if (a.getArtifactId().equals(artifactId) && a.getGroupId().equals(groupId)) {
      artifact=a;
      break;
    }
  }
  if (artifact == null) {
    throw new DeploymentFailureException("Could not resolve artifact to deploy " + groupId + ":"+ artifactId);
  }
  file=artifact.getFile();
}
 

Example 17

From project artifactory-plugin, under directory /src/main/java/org/jfrog/hudson/maven2/.

Source file: MavenDependenciesRecorder.java

  19 
vote

private void recordMavenDependencies(Set<Artifact> artifacts){
  if (artifacts != null) {
    for (    Artifact dependency : artifacts) {
      if (dependency.isResolved() && dependency.getFile() != null) {
        MavenDependency mavenDependency=new MavenDependency();
        mavenDependency.id=dependency.getId();
        mavenDependency.groupId=dependency.getGroupId();
        mavenDependency.artifactId=dependency.getArtifactId();
        mavenDependency.version=dependency.getVersion();
        mavenDependency.classifier=dependency.getClassifier();
        mavenDependency.scope=dependency.getScope();
        mavenDependency.fileName=dependency.getFile().getName();
        mavenDependency.type=dependency.getType();
        dependencies.add(mavenDependency);
      }
    }
  }
}
 

Example 18

From project backend-update-center2, under directory /src/main/java/org/jvnet/hudson/update_center/.

Source file: DefaultArtifactTransformationManager.java

  19 
vote

public void transformForResolve(Artifact artifact,List remoteRepositories,ArtifactRepository localRepository) throws ArtifactResolutionException, ArtifactNotFoundException {
  for (Iterator i=artifactTransformations.iterator(); i.hasNext(); ) {
    ArtifactTransformation transform=(ArtifactTransformation)i.next();
    transform.transformForResolve(artifact,remoteRepositories,localRepository);
  }
}
 

Example 19

From project clojure-maven-plugin, under directory /src/main/java/com/theoryinpractise/clojure/.

Source file: AbstractClojureCompilerMojo.java

  19 
vote

public List<String> getRunWithClasspathElements(){
  Set<String> classPathElements=new HashSet<String>();
  if (includePluginDependencies) {
    for (    Artifact artifact : pluginArtifacts) {
      classPathElements.add(artifact.getFile().getPath());
    }
  }
  classPathElements.addAll(runWithTests ? testClasspathElements : classPathElements);
  return new ArrayList<String>(classPathElements);
}
 

Example 20

From project cloudbees-deployer-plugin, under directory /src/main/java/org/jenkins/plugins/cloudbees/.

Source file: MavenArtifactFilePathSaver.java

  19 
vote

public boolean postBuild(MavenBuildProxy build,MavenProject pom,final BuildListener listener) throws InterruptedException, IOException {
  listener.getLogger().println("post build " + (pom.getArtifact() != null) + ":"+ (pom.getAttachedArtifacts() != null));
  if (pom != null && pom.getArtifact() != null || pom.getAttachedArtifacts() != null) {
    final Set<MavenArtifactWithFilePath> mavenArtifacts=new HashSet<MavenArtifactWithFilePath>();
    if (pom.getArtifact() != null) {
      final MavenArtifact mainArtifact=MavenArtifact.create(pom.getArtifact());
      if (mainArtifact != null && pom.getArtifact() != null && pom.getArtifact().getFile() != null) {
        mavenArtifacts.add(new MavenArtifactWithFilePath(pom.getGroupId(),pom.getArtifactId(),pom.getVersion(),pom.getArtifact().getFile().getPath(),pom.getArtifact().getType()));
      }
    }
    if (pom.getAttachedArtifacts() != null) {
      final List<MavenArtifact> attachedArtifacts=new ArrayList<MavenArtifact>();
      for (      Artifact a : pom.getAttachedArtifacts()) {
        MavenArtifact ma=MavenArtifact.create(a);
        if (ma != null && pom.getArtifact() != null && pom.getArtifact().getFile() != null) {
          mavenArtifacts.add(new MavenArtifactWithFilePath(pom.getGroupId(),pom.getArtifactId(),pom.getVersion(),pom.getArtifact().getFile().getPath(),pom.getArtifact().getType()));
        }
      }
    }
    build.execute(new MavenBuildProxy.BuildCallable<Void,IOException>(){
      public Void call(      MavenBuild build) throws IOException, InterruptedException {
        ArtifactFilePathSaveAction artifactFilePathSaveAction=build.getAction(ArtifactFilePathSaveAction.class);
        if (artifactFilePathSaveAction == null) {
          artifactFilePathSaveAction=new ArtifactFilePathSaveAction(mavenArtifacts);
        }
 else {
          artifactFilePathSaveAction.mavenArtifactWithFilePaths.addAll(mavenArtifacts);
        }
        build.addAction(artifactFilePathSaveAction);
        build.save();
        return null;
      }
    }
);
  }
  return true;
}
 

Example 21

From project geronimo-xbean, under directory /maven-xbean-plugin/src/main/java/org/apache/xbean/maven/.

Source file: XBeanMojo.java

  19 
vote

protected URLClassLoader getClassLoader() throws MojoExecutionException {
  try {
    Set<URL> urls=new HashSet<URL>();
    URL mainClasses=new File(project.getBuild().getOutputDirectory()).toURL();
    getLog().debug("Adding to classpath : " + mainClasses);
    urls.add(mainClasses);
    URL testClasses=new File(project.getBuild().getTestOutputDirectory()).toURL();
    getLog().debug("Adding to classpath : " + testClasses);
    urls.add(testClasses);
    Set<Artifact> dependencies=project.getArtifacts();
    Iterator iter=dependencies.iterator();
    for (    Artifact classPathElement : dependencies) {
      getLog().debug("Adding artifact: " + classPathElement.getFile() + " to classpath");
      urls.add(classPathElement.getFile().toURL());
    }
    if (classPathIncludes != null) {
      for (      String include : classPathIncludes) {
        final URL url=new File(include).toURL();
        getLog().debug("Adding to classpath : " + url);
        urls.add(url);
      }
    }
    URLClassLoader appClassloader=new URLClassLoader(urls.toArray(new URL[urls.size()]),this.getClass().getClassLoader());
    return appClassloader;
  }
 catch (  MalformedURLException e) {
    throw new MojoExecutionException("Error during setting up classpath",e);
  }
}
 

Example 22

From project hawtjni, under directory /maven-hawtjni-plugin/src/main/java/org/fusesource/hawtjni/maven/.

Source file: GenerateMojo.java

  19 
vote

@SuppressWarnings("unchecked") private ArrayList<String> getClasspath() throws MojoExecutionException {
  ArrayList<String> artifacts=new ArrayList<String>();
  try {
    artifacts.add(classesDirectory.getCanonicalPath());
    for (    Artifact artifact : (Set<Artifact>)project.getArtifacts()) {
      File file=artifact.getFile();
      getLog().debug("Including: " + file);
      artifacts.add(file.getCanonicalPath());
    }
  }
 catch (  IOException e) {
    throw new MojoExecutionException("Could not determine project classath.",e);
  }
  return artifacts;
}
 

Example 23

From project hbase-maven-plugin, under directory /src/main/java/com/wibidata/maven/plugins/hbase/.

Source file: StartMojo.java

  19 
vote

/** 
 * Gets the runtime classpath required to run the mini clusters. <p>The maven classloading scheme is nonstandard.  They only put the "classworlds" jar on the classpath, and it takes care of ClassLoading the rest of the jars.  This a problem if we are going to start a mini MapReduce cluster.  The TaskTracker will start a child JVM with the same classpath as this process, and it won't have configured the classworlds class loader.  To work around this, we will put all of our dependencies into the java.class.path system property, which will be read by the TaskRunner's child JVM launcher to build the child JVM classpath.</p> <p>Note that when we say "all of our dependencies" we mean both the dependencies of this plugin as well as the test classes and dependencies of the project that is running the plugin.  We need to include the latter on the classpath because tests are still just .class files at integration-test-time.  There will be no jars available yet to put on the distributed cache via job.setJarByClass().  Hence, all of the test-classes in the project running this plugin need to already be on the classpath of the MapReduce cluster.<p>
 */
private String getClassPath() throws MojoExecutionException {
  Set<String> alreadyAddedComponents=new HashSet<String>();
  StringBuilder classpath=new StringBuilder();
  String existingClasspath=System.getProperty("java.class.path");
  classpath.append(existingClasspath);
  alreadyAddedComponents.addAll(Arrays.asList(existingClasspath.split(":")));
  List<?> testClasspathComponents;
  try {
    testClasspathComponents=mMavenProject.getTestClasspathElements();
  }
 catch (  DependencyResolutionRequiredException e) {
    throw new MojoExecutionException("Unable to retrieve project test classpath",e);
  }
  for (  Object testClasspathComponent : testClasspathComponents) {
    String dependency=testClasspathComponent.toString();
    if (alreadyAddedComponents.contains(dependency)) {
      continue;
    }
    classpath.append(":");
    classpath.append(dependency);
    alreadyAddedComponents.add(dependency);
  }
  for (  Artifact artifact : mPluginDependencyArtifacts) {
    String dependency=artifact.getFile().getPath();
    if (alreadyAddedComponents.contains(dependency)) {
      continue;
    }
    classpath.append(":");
    classpath.append(dependency);
    alreadyAddedComponents.add(dependency);
  }
  return classpath.toString();
}
 

Example 24

From project jangaroo-tools, under directory /jangaroo-maven/jangaroo-maven-plugin/src/main/java/net/jangaroo/jooc/mvnplugin/.

Source file: PackageApplicationMojo.java

  19 
vote

/** 
 * Linearizes the acyclic, directed graph of all dependent artifacts to a list where every item just depends on items that are contained in the list before itself.
 * @return linearized dependency list of artifacts
 */
private List<Artifact> getLinearizedDependencies() throws ProjectBuildingException {
  final Map<String,Artifact> internalId2Artifact=artifactByInternalId();
  List<String> depthFirstArtifactIds=new ArrayList<String>();
  Set<String> openArtifacts=new HashSet<String>(internalId2Artifact.keySet());
  while (!openArtifacts.isEmpty()) {
    depthFirst(internalId2Artifact,depthFirstArtifactIds,openArtifacts,openArtifacts.iterator().next());
  }
  getLog().debug("linearized dependencies: " + depthFirstArtifactIds);
  List<Artifact> depthFirstArtifacts=new ArrayList<Artifact>(depthFirstArtifactIds.size());
  for (  String depthFirstArtifactId : depthFirstArtifactIds) {
    depthFirstArtifacts.add(internalId2Artifact.get(depthFirstArtifactId));
  }
  return depthFirstArtifacts;
}
 

Example 25

From project Jenkins-Repository, under directory /jenkins-maven-plugin/src/main/java/com/nirima/jenkins/.

Source file: SimpleArtifactCopier.java

  19 
vote

public void updateAll(Artifact art) throws IOException, HttpException, URISyntaxException, ParserConfigurationException, SAXException, TransformerException {
  List<String> items=fetchFiles(art);
  for (  String item : items) {
    fetchFile(art,item);
  }
}