Java Code Examples for org.eclipse.aether.artifact.Artifact#getExtension()

The following examples show how to use org.eclipse.aether.artifact.Artifact#getExtension() . 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: Publisher.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * @param descriptor an {@link Artifact}, holding the maven coordinates for the published files
 *     less the extension that is to be derived from the files. The {@code descriptor} itself will
 *     not be published as is, and the {@link File} attached to it (if any) will be ignored.
 * @param toPublish {@link File}(s) to be published using the given coordinates. The filename
 *     extension of each given file will be used as a maven "extension" coordinate
 */
public DeployResult publish(Artifact descriptor, List<File> toPublish)
    throws DeploymentException {
  String providedExtension = descriptor.getExtension();
  if (!providedExtension.isEmpty()) {
    LOG.warn(
        "Provided extension %s of artifact %s to be published will be ignored. The extensions "
            + "of the provided file(s) will be used",
        providedExtension, descriptor);
  }
  List<Artifact> artifacts = new ArrayList<>(toPublish.size());
  for (File file : toPublish) {
    artifacts.add(
        new SubArtifact(
            descriptor,
            descriptor.getClassifier(),
            Files.getFileExtension(file.getAbsolutePath()),
            file));
  }
  return publish(artifacts);
}
 
Example 2
Source File: SerializeGraph.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private String ScopeConflict( DependencyNode node )
{
    Artifact artifact = node.getArtifact();
    List<String> scopes = Arrays.asList( "compile", "provided", "runtime", "test", "system" );

    for( String scope:scopes )
    {
        String coordinate = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" +
                artifact.getExtension() + ":" + artifact.getVersion() + ":" + scope;
        if( coordinateStrings.contains( coordinate ) )
        {
            return scope;
        }
    }
    // check for scopeless, this probably can't happen
    return null;
}
 
Example 3
Source File: ArtifactRetriever.java    From maven-repository-tools with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Iterate through the provided artifact coordinates to retrieve and pull additional artifact such as
 * jar for bundle packaging, jar for aar packaging and so on as required. And get them even if not specified.
 * @param artifactCoordinates
 */
private void getAdditionalArtifactsForRequest( List<String> artifactCoordinates )
{
  List<Artifact> artifacts = new ArrayList<Artifact>();
  for ( String artifactCoordinate : artifactCoordinates )
  {
      artifacts.add( new DefaultArtifact( artifactCoordinate ) );
  }
  for ( Artifact artifact : artifacts )
  {
    String extension = artifact.getExtension();
    if ( MavenConstants.packagingUsesJar( extension ) )
    {
      Gav gav = new Gav( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
          artifact.getExtension() );
      getJar( gav );
    }
  }
}
 
Example 4
Source File: MavenUtils.java    From syndesis with Apache License 2.0 5 votes vote down vote up
static String toGav(final Artifact artifact) {
    // <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>
    return artifact.getGroupId()
        + ":" + artifact.getArtifactId()
        + (artifact.getExtension() == null ? "" : ":" + artifact.getExtension())
        + (artifact.getClassifier() == null ? "" : ":" + artifact.getClassifier())
        + ":" + artifact.getVersion();
}
 
Example 5
Source File: Resolver.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Construct a key to identify the artifact, less its version */
private String buildKey(Artifact artifact) {
  return artifact.getGroupId()
      + ':'
      + artifact.getArtifactId()
      + ':'
      + artifact.getExtension()
      + ':'
      + artifact.getClassifier();
}
 
Example 6
Source File: AutoDiscoverDeployService.java    From vertx-deploy-tools with Apache License 2.0 5 votes vote down vote up
private Artifact checkWithModel(Model model, Artifact artifact, Map<String, String> properties) {
    Optional<org.apache.maven.model.Dependency> result = model.getDependencies().stream()
            .filter(d -> d.getGroupId().equals(artifact.getGroupId()))
            .filter(d -> d.getArtifactId().equals(artifact.getArtifactId()))
            .filter(d -> d.getClassifier() != null && properties.containsKey(d.getClassifier().substring(2, d.getClassifier().length() - 1)))
            .findFirst();
    return result.isPresent() ?
            new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), properties.get(result.get().getClassifier().substring(2, result.get().getClassifier().length() - 1)), artifact.getExtension(), artifact.getVersion(), artifact.getProperties(), artifact.getFile())
            : artifact;
}
 
Example 7
Source File: AetherUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private Set<Dependency> parseDependencies(Collection<Dependency> unchagedDeps) {
    Set<Dependency> changedDeps = Sets.newHashSet();
    for (Dependency dependency : unchagedDeps) {
        Artifact artifact = dependency.getArtifact();
        String extension = artifact.getExtension();
        if (!extension.equals(JAR_EXTENSION)) {
            dependency = getChangedDependency(artifact);
            changedDeps.add(dependency);
        } else changedDeps.add(dependency);

    }
    return changedDeps;
}
 
Example 8
Source File: StackResolution.java    From vertx-stack with Apache License 2.0 5 votes vote down vote up
private String getManagementKey(Artifact artifact) {
  return artifact.getGroupId()
    + ":" + artifact.getArtifactId()
    + ":" + artifact.getExtension()
    + (artifact.getClassifier() != null && artifact.getClassifier().length() > 0
    ? ":" + artifact.getClassifier() : "");
}
 
Example 9
Source File: AetherImporter.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
private static DefaultArtifact makeOtherClassifier ( final Artifact main, final String classifier )
{
    if ( main.getClassifier () != null && !main.getClassifier ().isEmpty () )
    {
        // we only change main artifacts
        return null;
    }

    return new DefaultArtifact ( main.getGroupId (), main.getArtifactId (), classifier, main.getExtension (), main.getVersion () );
}
 
Example 10
Source File: SerializeGraph.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private static String getDependencyCoordinate( DependencyNode node )
{
    Artifact artifact = node.getArtifact();
    String scope = node.getDependency().getScope();
    String coords = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" +
            artifact.getExtension() + ":" + artifact.getVersion();

    if( scope != null && !scope.isEmpty() )
    {
        coords = coords.concat( ":" + scope );
    }
    return coords;
}
 
Example 11
Source File: BootstrapAppModelResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static AppArtifact toAppArtifact(Artifact artifact) {
    final AppArtifact appArtifact = new AppArtifact(artifact.getGroupId(), artifact.getArtifactId(),
            artifact.getClassifier(), artifact.getExtension(), artifact.getVersion());
    final File file = artifact.getFile();
    if (file != null) {
        appArtifact.setPaths(PathsCollection.of(file.toPath()));
    }
    return appArtifact;
}
 
Example 12
Source File: SerializeGraph.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private static String getVersionlessCoordinate( DependencyNode node )
{
    Artifact artifact = node.getArtifact();

    // scope not included because we check for scope conflicts separately
    return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getExtension();
}
 
Example 13
Source File: NbArtifactFixer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public @Override File resolve(Artifact artifact) {
    if (!artifact.getExtension().equals(NbMavenProject.TYPE_POM)) {
        return null;
    }
    if (!artifact.getClassifier().isEmpty()) {
        return null;
    }
    ArtifactRepository local = EmbedderFactory.getProjectEmbedder().getLocalRepository();
    if (local.getLayout() != null) { // #189807: for unknown reasons, there is no layout when running inside MavenCommandLineExecutor.run
        
        //the special snapshot handling is important in case of SNAPSHOT or x-SNAPSHOT versions, for some reason aether has slightly different
        //handling of baseversion compared to maven artifact. we need to manually set the baseversion here..
        boolean isSnapshot = artifact.isSnapshot();
        DefaultArtifact art = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), null, artifact.getExtension(), artifact.getClassifier(), new DefaultArtifactHandler(artifact.getExtension()));
        if (isSnapshot) {
            art.setBaseVersion(artifact.getBaseVersion());
        }
        String path = local.pathOf(art);
        if (new File(local.getBasedir(), path).exists()) {
            return null; // for now, we prefer the repository version when available
        }
    }
    //#234586
    Set<String> gavSet = gav.get();
    if (gavSet == null) {
        gavSet = new HashSet<String>();
        gav.set(gavSet);
    }
    String id = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();

    if (!gavSet.contains(id)) {
        try {
            gavSet.add(id); //#234586
            File pom = MavenFileOwnerQueryImpl.getInstance().getOwnerPOM(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
            if (pom != null) {
                //instead of workarounds down the road, we set the artifact's file here.
                // some stacktraces to maven/aether do set it after querying our code, but some don't for reasons unknown to me.
                artifact.setFile(pom);
                return pom;
            }
        } finally {
            gavSet.remove(id); //#234586
            if (gavSet.isEmpty()) {
                gav.remove();
            }
        }
    } else {
        LOG.log(Level.INFO, "Cycle in NbArtifactFixer resolution (issue #234586): {0}", Arrays.toString(gavSet.toArray()));
    }
    
    try {
        File f = createFallbackPOM(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
        //instead of workarounds down the road, we set the artifact's file here.
        // some stacktraces to maven/aether do set it after querying our code, but some don't for reasons unknown to me.
        artifact.setFile(f);
        return f;
    } catch (IOException x) {
        Exceptions.printStackTrace(x);
        return null;
    }
}
 
Example 14
Source File: ArtifactRetriever.java    From maven-repository-tools with Eclipse Public License 1.0 4 votes vote down vote up
private List<ArtifactResult> getArtifactResults( List<String> artifactCoordinates, boolean
        includeProvidedScope, boolean includeTestScope, boolean includeRuntimeScope )
{

    List<Artifact> artifacts = new ArrayList<Artifact>();
    for ( String artifactCoordinate : artifactCoordinates )
    {
        artifacts.add( new DefaultArtifact( artifactCoordinate ) );
    }

    List<ArtifactResult> artifactResults = new ArrayList<ArtifactResult>();
    DependencyFilter depFilter = 
        DependencyFilterUtils.classpathFilter( JavaScopes.TEST );
    
    Collection<String> includes = new ArrayList<String>();
    // we always include compile scope, not doing that makes no sense
    includes.add( JavaScopes.COMPILE );
    
    Collection<String> excludes = new ArrayList<String>();
    // always exclude system scope since it is machine specific and wont work in 99% of cases
    excludes.add( JavaScopes.SYSTEM );

    if ( includeProvidedScope )
    {
        includes.add( JavaScopes.PROVIDED );
    }
    else 
    {
        excludes.add( JavaScopes.PROVIDED ); 
    }
    
    if ( includeTestScope ) 
    {
        includes.add( JavaScopes.TEST );
    }
    else
    {
        excludes.add( JavaScopes.TEST );
    }

    if ( includeRuntimeScope )
    {
        includes.add( JavaScopes.RUNTIME );
    }
    
    DependencySelector selector =
        new AndDependencySelector(
        new ScopeDependencySelector( includes, excludes ),
        new OptionalDependencySelector(),
        new ExclusionDependencySelector()
    );
    session.setDependencySelector( selector );

    for ( Artifact artifact : artifacts )
    {
        CollectRequest collectRequest = new CollectRequest();
        collectRequest.setRoot( new Dependency( artifact, JavaScopes.COMPILE ) );
        collectRequest.addRepository( sourceRepository );

        DependencyRequest dependencyRequest = new DependencyRequest( collectRequest, depFilter );

        try
        {
            DependencyResult resolvedDependencies = system.resolveDependencies( session, dependencyRequest );
            artifactResults.addAll( resolvedDependencies.getArtifactResults() );
            for ( ArtifactResult result : resolvedDependencies.getArtifactResults() )
            {
                successfulRetrievals.add( result.toString() );
            }
        }
        catch ( DependencyResolutionException e )
        {
            String extension = artifact.getExtension();
            if ( MavenConstants.packagingUsesJarOnly( extension ) )
            {
                logger.info( "Not reporting as failure due to " + artifact.getExtension() + " extension." );
            }
            else
            {
              logger.info( "DependencyResolutionException ", e );
              failedRetrievals.add( e.getMessage() );
            }
        }
        catch ( NullPointerException npe )
        {
            logger.info( "NullPointerException resolving dependencies for " + artifact + ":" + npe );
            if ( npe.getMessage() != null )
            {
                failedRetrievals.add( npe.getMessage() );
            }
            else
            {
                failedRetrievals.add( "NPE retrieving " + artifact );
            }
        }
    }

    return artifactResults;
}
 
Example 15
Source File: IDEWorkspaceReader2.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public File findArtifact(Artifact artifact) {
    return super.findArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getExtension(), artifact.getClassifier());
}
 
Example 16
Source File: BootstrapAppModelResolver.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private AppArtifactKey getKey(final Artifact artifact) {
    return new AppArtifactKey(artifact.getGroupId(), artifact.getArtifactId(),
            artifact.getClassifier(), artifact.getExtension());
}
 
Example 17
Source File: MavenArtifactResolver.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private static AppArtifactKey getId(Artifact a) {
    return new AppArtifactKey(a.getGroupId(), a.getArtifactId(), a.getClassifier(), a.getExtension());
}