Example usage for org.apache.maven.artifact.resolver AbstractArtifactResolutionException getArtifactId

List of usage examples for org.apache.maven.artifact.resolver AbstractArtifactResolutionException getArtifactId

Introduction

In this page you can find the example usage for org.apache.maven.artifact.resolver AbstractArtifactResolutionException getArtifactId.

Prototype

public String getArtifactId() 

Source Link

Usage

From source file:org.eclipse.m2e.core.internal.markers.MavenMarkerManager.java

License:Open Source License

private String getArtifactId(AbstractArtifactResolutionException rex) {
    String id = rex.getGroupId() + ":" + rex.getArtifactId() + ":" + rex.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$
    if (rex.getClassifier() != null) {
        id += ":" + rex.getClassifier(); //$NON-NLS-1$
    }//w  ww  .  jav  a2s  .  c om
    if (rex.getType() != null) {
        id += ":" + rex.getType(); //$NON-NLS-1$
    }
    return id;
}

From source file:org.seasar.kvasir.plust.KvasirPlugin.java

@SuppressWarnings("unchecked")
public void resolveClasspathEntries(Set<IClasspathEntry> libraryEntries, Set<String> moduleArtifacts,
        IFile pomFile, boolean recursive, boolean downloadSources, IProgressMonitor monitor) {
    monitor.beginTask("Reading " + pomFile.getLocation(), IProgressMonitor.UNKNOWN);
    try {//w  w w.  j  a  v  a  2 s.  c  o  m
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }

        final MavenProject mavenProject = getMavenProject(pomFile, new SubProgressMonitor(monitor, 1));
        if (mavenProject == null) {
            return;
        }

        deleteMarkers(pomFile);
        // TODO use version?
        moduleArtifacts.add(mavenProject.getGroupId() + ":" + mavenProject.getArtifactId());

        Set artifacts = mavenProject.getArtifacts();
        for (Iterator it = artifacts.iterator(); it.hasNext();) {
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }

            final Artifact a = (Artifact) it.next();

            monitor.subTask("Processing " + a.getId());

            if (!"jar".equals(a.getType())) {
                continue;
            }
            // TODO use version?
            if (!moduleArtifacts.contains(a.getGroupId() + ":" + a.getArtifactId()) &&
            // TODO verify if there is an Eclipse API to check that archive is acceptable
                    ("jar".equals(a.getType()) || "zip".equals(a.getType()))) {
                String artifactLocation = a.getFile().getAbsolutePath();

                // TODO add a lookup through workspace projects

                Path srcPath = null;
                File srcFile = new File(
                        artifactLocation.substring(0, artifactLocation.length() - 4) + "-sources.jar");
                if (srcFile.exists()) {
                    // XXX ugly hack to do not download any sources
                    srcPath = new Path(srcFile.getAbsolutePath());
                } else if (downloadSources && !isSourceChecked(a)) {
                    srcPath = (Path) executeInEmbedder(new MavenEmbedderCallback() {
                        public Object run(MavenEmbedder mavenEmbedder, IProgressMonitor monitor) {
                            monitor.beginTask("Resolve sources " + a.getId(), IProgressMonitor.UNKNOWN);
                            try {
                                Artifact src = mavenEmbedder.createArtifactWithClassifier(a.getGroupId(),
                                        a.getArtifactId(), a.getVersion(), "java-source", "sources");
                                if (src != null) {
                                    mavenEmbedder.resolve(src, mavenProject.getRemoteArtifactRepositories(),
                                            mavenEmbedder.getLocalRepository());
                                    return new Path(src.getFile().getAbsolutePath());
                                }
                            } catch (AbstractArtifactResolutionException ex) {
                                String name = ex.getGroupId() + ":" + ex.getArtifactId() + "-" + ex.getVersion()
                                        + "." + ex.getType();
                                getConsole().logMessage(ex.getOriginalMessage() + " " + name);
                            } finally {
                                monitor.done();
                            }
                            return null;
                        }
                    }, new SubProgressMonitor(monitor, 1));
                    setSourceChecked(a);
                }

                libraryEntries.add(JavaCore.newLibraryEntry(new Path(artifactLocation), srcPath, null));
            }
        }

        if (recursive) {
            IContainer parent = pomFile.getParent();

            List modules = mavenProject.getModules();
            for (Iterator it = modules.iterator(); it.hasNext() && !monitor.isCanceled();) {
                if (monitor.isCanceled()) {
                    throw new OperationCanceledException();
                }

                String module = (String) it.next();
                IResource memberPom = parent.findMember(module + "/" + IKvasirProject.POM_FILE_NAME);
                if (memberPom != null && memberPom.getType() == IResource.FILE) {
                    resolveClasspathEntries(libraryEntries, moduleArtifacts, (IFile) memberPom, true,
                            downloadSources, new SubProgressMonitor(monitor, 1));
                }
            }
        }
    } catch (OperationCanceledException ex) {
        throw ex;
    } catch (InvalidArtifactRTException ex) {
        addMarker(pomFile, ex.getBaseMessage(), 1, IMarker.SEVERITY_ERROR);
    } catch (Throwable ex) {
        addMarker(pomFile, ex.toString(), 1, IMarker.SEVERITY_ERROR);
    } finally {
        monitor.done();
    }
}