Search in sources :

Example 1 with Artifact

use of org.apache.maven.artifact.Artifact in project che by eclipse.

the class TypeScriptDTOGeneratorMojoProjectStub method getArtifact.

/**
     * Use of mockito artifact
     */
@Override
public Artifact getArtifact() {
    Artifact artifact = Mockito.mock(Artifact.class);
    when(artifact.getArtifactId()).thenReturn(getModel().getArtifactId());
    when(artifact.getGroupId()).thenReturn(getModel().getGroupId());
    when(artifact.getVersion()).thenReturn(getModel().getVersion());
    when(artifact.getVersionRange()).thenReturn(VersionRange.createFromVersion(getModel().getVersion()));
    return artifact;
}
Also used : Artifact(org.apache.maven.artifact.Artifact)

Example 2 with Artifact

use of org.apache.maven.artifact.Artifact in project che by eclipse.

the class MavenModelUtil method convertModel.

public static MavenModel convertModel(Model model, List<String> sources, List<String> testSources, Collection<Artifact> dependencies, Collection<Artifact> extensions, File localRepo) {
    MavenModel result = new MavenModel();
    result.setMavenKey(new MavenKey(model.getGroupId(), model.getArtifactId(), model.getVersion()));
    Parent parent = model.getParent();
    if (parent != null) {
        result.setParent(new MavenParent(new MavenKey(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()), parent.getRelativePath()));
    }
    result.setName(model.getName());
    result.setPackaging(model.getPackaging());
    result.setProperties(model.getProperties() != null ? model.getProperties() : new Properties());
    result.setModules(model.getModules());
    result.setPlugins(convertPlugins(model));
    Map<Artifact, MavenArtifact> convertedArtifacts = new HashMap<>();
    result.setExtensions(convertArtifacts(extensions, convertedArtifacts, localRepo));
    result.setDependencies(convertArtifacts(dependencies, convertedArtifacts, localRepo));
    result.setRemoteRepositories(convertRepositories(model.getRepositories()));
    result.setProfiles(convertProfiles(model.getProfiles()));
    convertBuild(result.getBuild(), model.getBuild(), sources, testSources);
    return result;
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey) MavenModel(org.eclipse.che.maven.data.MavenModel) Parent(org.apache.maven.model.Parent) MavenParent(org.eclipse.che.maven.data.MavenParent) HashMap(java.util.HashMap) MavenParent(org.eclipse.che.maven.data.MavenParent) Properties(java.util.Properties) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Artifact(org.apache.maven.artifact.Artifact)

Example 3 with Artifact

use of org.apache.maven.artifact.Artifact in project che by eclipse.

the class CheArtifactResolver method resolve.

// ------------------------------------------------------------------------
//
// ------------------------------------------------------------------------
public ArtifactResolutionResult resolve(ArtifactResolutionRequest request) {
    Artifact rootArtifact = request.getArtifact();
    Set<Artifact> artifacts = request.getArtifactDependencies();
    Map<String, Artifact> managedVersions = request.getManagedVersionMap();
    List<ResolutionListener> listeners = request.getListeners();
    ArtifactFilter collectionFilter = request.getCollectionFilter();
    ArtifactFilter resolutionFilter = request.getResolutionFilter();
    RepositorySystemSession session = getSession(request.getLocalRepository());
    //TODO: hack because metadata isn't generated in m2e correctly and i want to run the maven i have in the workspace
    if (source == null) {
        try {
            source = container.lookup(ArtifactMetadataSource.class);
        } catch (ComponentLookupException e) {
        // won't happen
        }
    }
    if (listeners == null) {
        listeners = new ArrayList<ResolutionListener>();
        if (logger.isDebugEnabled()) {
            listeners.add(new DebugResolutionListener(logger));
        }
        listeners.add(new WarningResolutionListener(logger));
    }
    ArtifactResolutionResult result = new ArtifactResolutionResult();
    if (request.isResolveRoot()) /* && rootArtifact.getFile() == null */
    {
        try {
            resolve(rootArtifact, request.getRemoteRepositories(), session);
        } catch (ArtifactResolutionException e) {
            result.addErrorArtifactException(e);
            return result;
        } catch (ArtifactNotFoundException e) {
            result.addMissingArtifact(request.getArtifact());
            return result;
        }
    }
    ArtifactResolutionRequest collectionRequest = request;
    if (request.isResolveTransitively()) {
        MetadataResolutionRequest metadataRequest = new DefaultMetadataResolutionRequest(request);
        metadataRequest.setArtifact(rootArtifact);
        metadataRequest.setResolveManagedVersions(managedVersions == null);
        try {
            ResolutionGroup resolutionGroup = source.retrieve(metadataRequest);
            if (managedVersions == null) {
                managedVersions = resolutionGroup.getManagedVersions();
            }
            Set<Artifact> directArtifacts = resolutionGroup.getArtifacts();
            if (artifacts == null || artifacts.isEmpty()) {
                artifacts = directArtifacts;
            } else {
                List<Artifact> allArtifacts = new ArrayList<Artifact>();
                allArtifacts.addAll(artifacts);
                allArtifacts.addAll(directArtifacts);
                Map<String, Artifact> mergedArtifacts = new LinkedHashMap<String, Artifact>();
                for (Artifact artifact : allArtifacts) {
                    String conflictId = artifact.getDependencyConflictId();
                    if (!mergedArtifacts.containsKey(conflictId)) {
                        mergedArtifacts.put(conflictId, artifact);
                    }
                }
                artifacts = new LinkedHashSet<Artifact>(mergedArtifacts.values());
            }
            collectionRequest = new ArtifactResolutionRequest(request);
            collectionRequest.setServers(request.getServers());
            collectionRequest.setMirrors(request.getMirrors());
            collectionRequest.setProxies(request.getProxies());
            collectionRequest.setRemoteRepositories(resolutionGroup.getResolutionRepositories());
        } catch (ArtifactMetadataRetrievalException e) {
            ArtifactResolutionException are = new ArtifactResolutionException("Unable to get dependency information for " + rootArtifact.getId() + ": " + e.getMessage(), rootArtifact, metadataRequest.getRemoteRepositories(), e);
            result.addMetadataResolutionException(are);
            return result;
        }
    }
    if (artifacts == null || artifacts.isEmpty()) {
        if (request.isResolveRoot()) {
            result.addArtifact(rootArtifact);
        }
        return result;
    }
    // After the collection we will have the artifact object in the result but they will not be resolved yet.
    result = artifactCollector.collect(artifacts, rootArtifact, managedVersions, collectionRequest, source, collectionFilter, listeners, null);
    if (result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() || result.hasCircularDependencyExceptions()) {
        return result;
    }
    if (result.getArtifactResolutionNodes() != null) {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        CountDownLatch latch = new CountDownLatch(result.getArtifactResolutionNodes().size());
        for (ResolutionNode node : result.getArtifactResolutionNodes()) {
            Artifact artifact = node.getArtifact();
            if (resolutionFilter == null || resolutionFilter.include(artifact)) {
                executor.execute(new ResolveTask(classLoader, latch, artifact, session, node.getRemoteRepositories(), result));
            } else {
                latch.countDown();
            }
        }
        try {
            latch.await();
        } catch (InterruptedException e) {
            result.addErrorArtifactException(new ArtifactResolutionException("Resolution interrupted", rootArtifact, e));
        }
    }
    // have been resolved.
    if (request.isResolveRoot()) {
        // Add the root artifact (as the first artifact to retain logical order of class path!)
        Set<Artifact> allArtifacts = new LinkedHashSet<Artifact>();
        allArtifacts.add(rootArtifact);
        allArtifacts.addAll(result.getArtifacts());
        result.setArtifacts(allArtifacts);
    }
    return result;
}
Also used : DefaultMetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest) MetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest) LinkedHashSet(java.util.LinkedHashSet) ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException) ArrayList(java.util.ArrayList) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) LinkedHashMap(java.util.LinkedHashMap) DefaultMetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) DebugResolutionListener(org.apache.maven.artifact.resolver.DebugResolutionListener) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ResolutionListener(org.apache.maven.artifact.resolver.ResolutionListener) DebugResolutionListener(org.apache.maven.artifact.resolver.DebugResolutionListener) WarningResolutionListener(org.apache.maven.artifact.resolver.WarningResolutionListener) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ResolutionNode(org.apache.maven.artifact.resolver.ResolutionNode) ResolutionGroup(org.apache.maven.artifact.metadata.ResolutionGroup) CountDownLatch(java.util.concurrent.CountDownLatch) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) WarningResolutionListener(org.apache.maven.artifact.resolver.WarningResolutionListener) ArtifactMetadataSource(org.apache.maven.artifact.metadata.ArtifactMetadataSource)

Example 4 with Artifact

use of org.apache.maven.artifact.Artifact in project jetty.project by eclipse.

the class JspcMojo method setUpWebAppClassPath.

/**
     * Set up the execution classpath for Jasper.
     * 
     * Put everything in the classesDirectory and all of the dependencies on the
     * classpath.
     * 
     * @returns a list of the urls of the dependencies
     * @throws Exception
     */
private List<URL> setUpWebAppClassPath() throws Exception {
    //add any classes from the webapp
    List<URL> urls = new ArrayList<URL>();
    String classesDir = classesDirectory.getCanonicalPath();
    classesDir = classesDir + (classesDir.endsWith(File.pathSeparator) ? "" : File.separator);
    urls.add(Resource.toURL(new File(classesDir)));
    if (getLog().isDebugEnabled())
        getLog().debug("Adding to classpath classes dir: " + classesDir);
    //add the dependencies of the webapp (which will form WEB-INF/lib)
    for (Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); ) {
        Artifact artifact = (Artifact) iter.next();
        // Include runtime and compile time libraries
        if (!Artifact.SCOPE_TEST.equals(artifact.getScope()) && !Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
            String filePath = artifact.getFile().getCanonicalPath();
            if (getLog().isDebugEnabled())
                getLog().debug("Adding to classpath dependency file: " + filePath);
            urls.add(Resource.toURL(artifact.getFile()));
        }
    }
    return urls;
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with Artifact

use of org.apache.maven.artifact.Artifact in project jetty.project by eclipse.

the class JettyRunForkedMojo method getContainerClassPath.

public String getContainerClassPath() throws Exception {
    StringBuilder classPath = new StringBuilder();
    for (Object obj : pluginArtifacts) {
        Artifact artifact = (Artifact) obj;
        if ("jar".equals(artifact.getType())) {
            if (classPath.length() > 0) {
                classPath.append(File.pathSeparator);
            }
            classPath.append(artifact.getFile().getAbsolutePath());
        }
    }
    //Any jars that we need from the plugin environment (like the ones containing Starter class)
    Set<Artifact> extraJars = getExtraJars();
    for (Artifact a : extraJars) {
        classPath.append(File.pathSeparator);
        classPath.append(a.getFile().getAbsolutePath());
    }
    //Any jars that we need from the project's dependencies because we're useProvided
    List<String> providedJars = getProvidedJars();
    if (providedJars != null && !providedJars.isEmpty()) {
        for (String jar : providedJars) {
            classPath.append(File.pathSeparator);
            classPath.append(jar);
            if (getLog().isDebugEnabled())
                getLog().debug("Adding provided jar: " + jar);
        }
    }
    return classPath.toString();
}
Also used : Artifact(org.apache.maven.artifact.Artifact)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)450 File (java.io.File)175 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)92 ArrayList (java.util.ArrayList)91 MavenProject (org.apache.maven.project.MavenProject)63 IOException (java.io.IOException)50 HashSet (java.util.HashSet)42 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)32 LinkedHashSet (java.util.LinkedHashSet)29 MojoFailureException (org.apache.maven.plugin.MojoFailureException)24 HashMap (java.util.HashMap)22 Set (java.util.Set)22 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)22 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)21 URL (java.net.URL)20 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)20 Test (org.junit.Test)20 MalformedURLException (java.net.MalformedURLException)18 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)17 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)16