org.apache.maven.artifact.handler.ArtifactHandler类的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中org.apache.maven.artifact.handler.ArtifactHandler类的一些代码示例,展示了ArtifactHandler类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ArtifactHandler类的具体详情如下:
包路径:org.apache.maven.artifact.handler.ArtifactHandler
类名称:ArtifactHandler

ArtifactHandler介绍

[英]An artifact handler defines for a dependency type, defined as Plexus role:

  • extension and classifier, to be able to download the file,
  • information on how to use the artifact: whether to add it to the classpath, or to take into account its dependencies.
    [中]工件处理程序为依赖项类型(定义为Plexus角色)定义:
    *扩展名和分类器,以便能够下载文件,
    *关于如何使用工件的信息:是将其添加到类路径,还是考虑其依赖性。

代码示例

代码示例来源:origin: apache/maven

public static Artifact toArtifact( org.apache.maven.artifact.Artifact artifact )
{
  if ( artifact == null )
  {
    return null;
  }
  String version = artifact.getVersion();
  if ( version == null && artifact.getVersionRange() != null )
  {
    version = artifact.getVersionRange().toString();
  }
  Map<String, String> props = null;
  if ( org.apache.maven.artifact.Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
  {
    String localPath = ( artifact.getFile() != null ) ? artifact.getFile().getPath() : "";
    props = Collections.singletonMap( ArtifactProperties.LOCAL_PATH, localPath );
  }
  Artifact result =
    new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(),
               artifact.getArtifactHandler().getExtension(), version, props,
               newArtifactType( artifact.getType(), artifact.getArtifactHandler() ) );
  result = result.setFile( artifact.getFile() );
  return result;
}

代码示例来源:origin: org.apache.maven/maven-project

public List getSystemArtifacts()
{
  List list = new ArrayList( getArtifacts().size() );
  for ( Iterator i = getArtifacts().iterator(); i.hasNext(); )
  {
    Artifact a = (Artifact) i.next();
    // TODO: classpath check doesn't belong here - that's the other method
    if ( a.getArtifactHandler().isAddedToClasspath() )
    {
      // TODO: let the scope handler deal with this
      if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
      {
        list.add( a );
      }
    }
  }
  return list;
}

代码示例来源:origin: apache/maven

public static ArtifactType newArtifactType( String id, ArtifactHandler handler )
{
  return new DefaultArtifactType( id, handler.getExtension(), handler.getClassifier(), handler.getLanguage(),
                  handler.isAddedToClasspath(), handler.isIncludesDependencies() );
}

代码示例来源:origin: org.apache.continuum/continuum-buildagent-core

Artifact artifact = project.getArtifact();
String projectPackaging = project.getPackaging();
  artifact.setFile( project.getFile() );
  ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, project.getFile() );
  artifact.addMetadata( metadata );
  String finalName = project.getBuild().getFinalName();
  String filename = finalName + "." + artifact.getArtifactHandler().getExtension();
  String buildDirectory = project.getBuild().getDirectory();

代码示例来源:origin: tbroyer/gwt-maven-plugin

} else {
 for (MavenProject p : reactorProjects) {
  if (p.getPackaging().equals("gwt-app")) {
   projectList.add(p);
  ambiguousProjectIds.add(key);
 key = p.getGroupId() + key;
 if (projectMap.put(key, p) != null) {
  projectMap.remove(key);
cp.add(p.getBuild().getOutputDirectory());
for (Artifact artifact : p.getArtifacts()) {
 if (!artifact.getArtifactHandler().isAddedToClasspath()) {
  continue;
 if ("gwt-lib".equals(artifact.getArtifactHandler().getPackaging())) {
  MavenProject reference = getReferencedProject(p, artifact);
  if (reference != null && reference.getArtifact() != null && reference.getArtifact().getFile() != null) {
   artifact = reference.getArtifact();
FileUtils.forceMkdir(new File(project.getBuild().getDirectory()));
FileUtils.forceMkdir(getWorkDir());
forceMkdirs();

代码示例来源:origin: apache/axis2-java

/**
 * Converts the filename of an artifact to artifactId-version.type format.
 *
 * @param artifact
 * @return converted filename of the artifact
 */
private String getDefaultFinalName(Artifact artifact) {
  return artifact.getArtifactId() + "-" + artifact.getVersion() + "." +
      artifact.getArtifactHandler().getExtension();
}

代码示例来源:origin: org.apache.maven.plugins/maven-gpg-plugin

signer.setBuildDirectory( new File( project.getBuild().getDirectory() ) );
signer.setBaseDirectory( project.getBasedir() );
if ( !"pom".equals( project.getPackaging() ) )
  Artifact artifact = project.getArtifact();
  File file = artifact.getFile();
      signingBundles.add( new SigningBundle( artifact.getArtifactHandler().getExtension(),
                          projectArtifactSignature ) );
File pomToSign = new File( project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".pom" );
  File file = artifact.getFile();
    signingBundles.add( new SigningBundle( artifact.getArtifactHandler().getExtension(),
                        artifact.getClassifier(), signature ) );

代码示例来源:origin: org.apache.maven/maven-project

public List getSystemClasspathElements()
  throws DependencyResolutionRequiredException
{
  List list = new ArrayList( getArtifacts().size() );
  list.add( getBuild().getOutputDirectory() );
  for ( Iterator i = getArtifacts().iterator(); i.hasNext(); )
  {
    Artifact a = (Artifact) i.next();
    if ( a.getArtifactHandler().isAddedToClasspath() )
    {
      // TODO: let the scope handler deal with this
      if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
      {
        addArtifactPath( a, list );
      }
    }
  }
  return list;
}

代码示例来源:origin: org.codehaus.mojo/gwt-maven-plugin

items.add( new File( project.getBuild().getOutputDirectory() ) );
addSources( items, project.getCompileSourceRoots() );
if ( isGenerator ) {
  addResources( items, project.getResources() );
  addSources( items, project.getTestCompileSourceRoots() );
  addResources( items, project.getTestResources() );
  items.add( new File( project.getBuild().getTestOutputDirectory() ) );
    items.add( artifact.getFile() );
  for ( Artifact artifact : artifacts )
    String artifactScope = artifact.getScope();
    if ( SCOPE_COMPILE.equals( artifactScope ) || SCOPE_PROVIDED.equals( artifactScope )
      || SCOPE_SYSTEM.equals( artifactScope ) )
      items.add( artifact.getFile() );
    if ( !artifact.getScope().equals( SCOPE_TEST ) && artifact.getArtifactHandler().isAddedToClasspath() )
      items.add( artifact.getFile() );

代码示例来源:origin: org.apache.maven/maven-project

public List getRuntimeClasspathElements()
  throws DependencyResolutionRequiredException
{
  List list = new ArrayList( getArtifacts().size() + 1 );
  list.add( getBuild().getOutputDirectory() );
  for ( Iterator i = getArtifacts().iterator(); i.hasNext(); )
  {
    Artifact a = (Artifact) i.next();
    if ( a.getArtifactHandler().isAddedToClasspath() )
    {
      // TODO: let the scope handler deal with this
      if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
      {
        File file = a.getFile();
        if ( file == null )
        {
          throw new DependencyResolutionRequiredException( a );
        }
        list.add( file.getPath() );
      }
    }
  }
  return list;
}

代码示例来源:origin: apache/maven

public String pathOf( Artifact artifact )
{
  ArtifactHandler artifactHandler = artifact.getArtifactHandler();
  StringBuilder path = new StringBuilder( 128 );
  path.append( formatAsDirectory( artifact.getGroupId() ) ).append( PATH_SEPARATOR );
  path.append( artifact.getArtifactId() ).append( PATH_SEPARATOR );
  path.append( artifact.getBaseVersion() ).append( PATH_SEPARATOR );
  path.append( artifact.getArtifactId() ).append( ARTIFACT_SEPARATOR ).append( artifact.getVersion() );
  if ( artifact.hasClassifier() )
  {
    path.append( ARTIFACT_SEPARATOR ).append( artifact.getClassifier() );
  }
  if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 )
  {
    path.append( GROUP_SEPARATOR ).append( artifactHandler.getExtension() );
  }
  return path.toString();
}

代码示例来源:origin: org.apache.maven/maven-project

public List getTestClasspathElements()
  throws DependencyResolutionRequiredException
{
  List list = new ArrayList( getArtifacts().size() + 1 );
  list.add( getBuild().getTestOutputDirectory() );
  list.add( getBuild().getOutputDirectory() );
  
  for ( Iterator i = getArtifacts().iterator(); i.hasNext(); )
  {
    Artifact a = (Artifact) i.next();
    if ( a.getArtifactHandler().isAddedToClasspath() )
    {
      // TODO: let the scope handler deal with this
      // NOTE: [jc] scope == 'test' is the widest possible scope, so we don't really need to perform
      // this check...
      // if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() ) ||
      //     Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
      // {
      // }
      File file = a.getFile();
      if ( file == null )
      {
        throw new DependencyResolutionRequiredException( a );
      }
      list.add( file.getPath() );
    }
  }
  return list;
}

代码示例来源:origin: org.apache.maven/maven-project

/**
 * Gets the repository conflict id of the specified artifact. Unlike the dependency conflict id, the repository
 * conflict id uses the artifact file extension instead of the artifact type. Hence, the repository conflict id more
 * closely reflects the identity of artifacts as perceived by a repository.
 * 
 * @param artifact The artifact, must not be <code>null</code>.
 * @return The repository conflict id, never <code>null</code>.
 */
private String getRepositoryConflictId( Artifact artifact )
{
  StringBuffer buffer = new StringBuffer( 128 );
  buffer.append( artifact.getGroupId() );
  buffer.append( ':' ).append( artifact.getArtifactId() );
  if ( artifact.getArtifactHandler() != null )
  {
    buffer.append( ':' ).append( artifact.getArtifactHandler().getExtension() );
  }
  else
  {
    buffer.append( ':' ).append( artifact.getType() );
  }
  if ( artifact.hasClassifier() )
  {
    buffer.append( ':' ).append( artifact.getClassifier() );
  }
  return buffer.toString();
}

代码示例来源:origin: org.apache.maven.plugins/maven-shade-plugin

private File shadedSourcesArtifactFile()
{
  Artifact artifact = project.getArtifact();
  String shadedName;
  if ( project.getBuild().getFinalName() != null )
  {
    shadedName = project.getBuild().getFinalName() + "-sources." + artifact.getArtifactHandler().getExtension();
  }
  else
  {
    shadedName = shadedArtifactId + "-" + artifact.getVersion() + "-sources."
      + artifact.getArtifactHandler().getExtension();
  }
  return new File( outputDirectory, shadedName );
}

代码示例来源:origin: io.takari.maven.plugins/takari-lifecycle-plugin

private static void putArtifact(MutableWorkspaceState state, Artifact artifact) {
 state.putArtifact(artifact.getFile(), artifact.getGroupId(), artifact.getArtifactId(), //
   artifact.getArtifactHandler().getExtension(), artifact.getClassifier(), artifact.getBaseVersion());
}

代码示例来源:origin: org.apache.maven.plugins/maven-shade-plugin

new ArtifactSelector( project.getArtifact(), artifactSet, shadedGroupFilter );
if ( artifactSelector.isSelected( project.getArtifact() ) && !"pom".equals( project.getArtifact().getType() ) )
  artifacts.add( project.getArtifact().getFile() );
      && !finalName.equals( project.getBuild().getFinalName() ) )
      String finalFileName = finalName + "." + project.getArtifact().getArtifactHandler().getExtension();
      File finalFile = new File( outputDirectory, finalFileName );
      replaceFile( finalFile, outputJar );

代码示例来源:origin: org.codehaus.mojo/cobertura-maven-plugin

ArtifactHandler artifactHandler = getProject().getArtifact().getArtifactHandler();
if ( !"java".equals( artifactHandler.getLanguage() ) )
    new File( getProject().getBuild().getDirectory(), "generated-classes/cobertura" );
  File outputDirectory = new File( getProject().getBuild().getOutputDirectory() );
  if ( !outputDirectory.exists() )
  getProject().getBuild().setOutputDirectory( instrumentedDirectory.getPath() );
  System.setProperty( "project.build.outputDirectory", instrumentedDirectory.getPath() );
  attachCoberturaArtifactIfAppropriate();

代码示例来源:origin: org.apache.maven.plugin-testing/maven-plugin-testing-harness

if ( artifact.getFile() != null && !removeVersion )
  destFileName = artifact.getFile().getName();
  if ( !removeVersion )
    versionString = "-" + artifact.getVersion();
  destFileName = artifact.getArtifactId() + versionString + classifierString + "."
    + artifact.getArtifactHandler().getExtension();

代码示例来源:origin: apache/maven

public String pathOf( Artifact artifact )
{
  ArtifactHandler artifactHandler = artifact.getArtifactHandler();
  StringBuilder path = new StringBuilder( 128 );
  path.append( artifact.getArtifactId() ).append( ARTIFACT_SEPARATOR ).append( artifact.getVersion() );
  if ( artifact.hasClassifier() )
  {
    path.append( ARTIFACT_SEPARATOR ).append( artifact.getClassifier() );
  }
  if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 )
  {
    path.append( GROUP_SEPARATOR ).append( artifactHandler.getExtension() );
  }
  return path.toString();
}

代码示例来源:origin: revapi/revapi

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;
  }
}

相关文章