Java Code Examples for org.apache.maven.project.MavenProject#getArtifact()

The following examples show how to use org.apache.maven.project.MavenProject#getArtifact() . 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: Analyzer.java    From revapi with Apache License 2.0 6 votes vote down vote up
public static String getProjectArtifactCoordinates(MavenProject project, String versionOverride) {

        org.apache.maven.artifact.Artifact artifact = project.getArtifact();

        String extension = artifact.getArtifactHandler().getExtension();

        String version = versionOverride == null ? project.getVersion() : versionOverride;

        if (artifact.hasClassifier()) {
            return project.getGroupId() + ":" + project.getArtifactId() + ":" + extension + ":" +
                    artifact.getClassifier() + ":" + version;
        } else {
            return project.getGroupId() + ":" + project.getArtifactId() + ":" + extension + ":" +
                    version;
        }
    }
 
Example 2
Source File: DockerAssemblyManager.java    From docker-maven-plugin with Apache License 2.0 6 votes vote down vote up
private File ensureThatArtifactFileIsSet(MavenProject project) {
    Artifact artifact = project.getArtifact();
    if (artifact == null) {
        return null;
    }
    File oldFile = artifact.getFile();
    if (oldFile != null) {
        return oldFile;
    }
    Build build = project.getBuild();
    if (build == null) {
        return null;
    }
    String finalName = build.getFinalName();
    String target = build.getDirectory();
    if (finalName == null || target == null) {
        return null;
    }
    File artifactFile = new File(target, finalName + "." + project.getPackaging());
    if (artifactFile.exists() && artifactFile.isFile()) {
        setArtifactFile(project, artifactFile);
    }
    return null;
}
 
Example 3
Source File: PluginDescriptorMojoTest.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testSourcepathDependency() throws Exception {
  // assert that MojoAnnotationProcessorMojo honours sourcepath=reactorDependencies

  File basedir = resources.getBasedir("plugin-descriptor/sourcepath-dependency");
  File dependency = new File(basedir, "dependency");
  File plugin = new File(basedir, "plugin");

  MavenProject dependencyProject = mojos.readMavenProject(dependency);
  MavenProject pluginProject = mojos.readMavenProject(plugin);
  addDependencies(pluginProject, "apache-plugin-annotations-jar", "maven-plugin-api-jar");
  mojos.newDependency(new File(dependencyProject.getBuild().getOutputDirectory())) //
      .setGroupId(dependencyProject.getGroupId()) //
      .setArtifactId(dependencyProject.getArtifactId()) //
      .setVersion(dependencyProject.getVersion()) //
      .addTo(pluginProject);
  Artifact dependencyArtifact = dependencyProject.getArtifact();
  dependencyArtifact.setScope(Artifact.SCOPE_COMPILE);
  pluginProject.getArtifacts().add(dependencyArtifact);
  MavenSession session = mojos.newMavenSession(pluginProject);
  session.setProjects(ImmutableList.of(dependencyProject, pluginProject));
  session.setCurrentProject(pluginProject);
  mojos.executeMojo(session, pluginProject, "mojo-annotation-processor", newParameter("sourcepath", "reactorDependencies"));
  mojos.executeMojo(session, pluginProject, "plugin-descriptor");
  mojos.assertBuildOutputs(plugin, "target/classes/META-INF/maven/plugin.xml", "target/classes/META-INF/m2e/lifecycle-mapping-metadata.xml");
}
 
Example 4
Source File: ArtifactMultiViewFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override @CheckForNull public Lookup createLookup(@NonNull Project prj) {
    NbMavenProject mvPrj = prj.getLookup().lookup(NbMavenProject.class);
    MavenProject mvn = mvPrj.getMavenProject();
    Artifact artifact = mvn.getArtifact();
    //artifact null with unloadable projects??
    return artifact != null ? createPomEditorLookup(prj, artifact) : null;
}
 
Example 5
Source File: LockSnapshotsMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
private void lockParentSnapshot( ModifiedPomXMLEventReader pom, MavenProject parent )
    throws XMLStreamException, MojoExecutionException
{
    if ( parent == null )
    {
        getLog().info( "Project does not have a parent" );
        return;
    }

    if ( reactorProjects.contains( parent ) )
    {
        getLog().info( "Project's parent is part of the reactor" );
        return;
    }

    Artifact parentArtifact = parent.getArtifact();
    String parentVersion = parentArtifact.getVersion();

    Matcher versionMatcher = matchSnapshotRegex.matcher( parentVersion );
    if ( versionMatcher.find() && versionMatcher.end() == parentVersion.length() )
    {
        String lockedParentVersion = resolveSnapshotVersion( parentArtifact );
        if ( !parentVersion.equals( lockedParentVersion ) )
        {
            if ( PomHelper.setProjectParentVersion( pom, lockedParentVersion ) )
            {
                getLog().info( "Locked parent " + parentArtifact.toString() + " to version "
                    + lockedParentVersion );
            }
        }
    }
}
 
Example 6
Source File: UnlockSnapshotsMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
private void unlockParentSnapshot( ModifiedPomXMLEventReader pom, MavenProject parent )
    throws XMLStreamException, MojoExecutionException
{
    if ( parent == null )
    {
        getLog().info( "Project does not have a parent" );
        return;
    }

    if ( reactorProjects.contains( parent ) )
    {
        getLog().info( "Project's parent is part of the reactor" );
        return;
    }

    Artifact parentArtifact = parent.getArtifact();
    String parentVersion = parentArtifact.getVersion();

    Matcher versionMatcher = matchSnapshotRegex.matcher( parentVersion );
    if ( versionMatcher.find() && versionMatcher.end() == parentVersion.length() )
    {
        String unlockedParentVersion = versionMatcher.replaceFirst( "-SNAPSHOT" );
        if ( PomHelper.setProjectParentVersion( pom, unlockedParentVersion ) )
        {
            getLog().info( "Unlocked parent " + parentArtifact.toString() + " to version "
                + unlockedParentVersion );
        }
    }
}
 
Example 7
Source File: AggregatingGraphFactory.java    From depgraph-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public String createGraph(MavenProject parent) {
  this.graphBuilder.graphName(parent.getArtifactId());

  if (this.includeParentProjects) {
    buildModuleTree(parent, this.graphBuilder);
  }

  Collection<MavenProject> collectedProjects = this.subProjectSupplier.get();
  for (MavenProject collectedProject : collectedProjects) {
    // Process project only if its artifact is not filtered
    if (isPartOfGraph(collectedProject)) {
      this.mavenGraphAdapter.buildDependencyGraph(collectedProject, this.globalFilter, this.graphBuilder);
    }
  }

  // Add the project as single node if the graph is empty
  Artifact artifact = parent.getArtifact();
  if (this.graphBuilder.isEmpty() && this.globalFilter.include(artifact)) {
    this.graphBuilder.addNode(new DependencyNode(artifact));
  }

  if (this.reduceEdges) {
    this.graphBuilder.reduceEdges();
  }

  return this.graphBuilder.toString();
}
 
Example 8
Source File: AggregatingGraphFactory.java    From depgraph-maven-plugin with Apache License 2.0 5 votes vote down vote up
private DependencyNode filterProject(MavenProject project) {
  Artifact artifact = project.getArtifact();
  if (this.globalFilter.include(artifact)) {
    return new DependencyNode(artifact);
  }

  return null;
}
 
Example 9
Source File: SimpleGraphFactory.java    From depgraph-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public String createGraph(MavenProject project) {
  this.graphBuilder.graphName(project.getArtifactId());
  this.mavenGraphAdapter.buildDependencyGraph(project, this.globalFilter, this.graphBuilder);

  // Add the project as single node if the graph is empty
  Artifact artifact = project.getArtifact();
  if (this.graphBuilder.isEmpty() && this.globalFilter.include(artifact)) {
    this.graphBuilder.addNode(new DependencyNode(artifact));
  }

  return this.graphBuilder.toString();
}
 
Example 10
Source File: DockerAssemblyManager.java    From docker-maven-plugin with Apache License 2.0 4 votes vote down vote up
private void setArtifactFile(MavenProject project, File artifactFile) {
    Artifact artifact = project.getArtifact();
    if (artifact != null) {
        artifact.setFile(artifactFile);
    }
}
 
Example 11
Source File: ReactorDependencySkipper.java    From pgpverify-maven-plugin with Apache License 2.0 3 votes vote down vote up
/**
 * Check whether the specified artifact belongs to the specified Maven project.
 *
 * @param artifact
 *   The artifact being checked.
 * @param project
 *   The project to which the artifact will be compared.
 *
 * @return
 *   {@code true} if the artifact was produced by the specified project; or
 *   {@code false} if it is not.
 */
private static boolean artifactMatchesProject(final Artifact artifact,
                                       final MavenProject project) {
    final Artifact projectArtifact = project.getArtifact();

    return projectArtifact != null
           && artifactsMatch(projectArtifact, artifact);
}