List of usage examples for org.apache.maven.artifact Artifact getDownloadUrl
String getDownloadUrl();
From source file:net.eckenfels.mavenplugins.lockdeps.LockDependenciesMojo.java
License:Apache License
public void execute() throws MojoExecutionException { Log log = getLog();//from ww w . j ava2s . c o m log.debug("Now scanning dependencies..." + project); Set<Artifact> deps = project.getArtifacts(); for (Artifact a : deps) { ArtifactRepository rep = a.getRepository(); log.info("artifact: " + a.getId() + " (" + a.getScope() + ") from " + a.getDownloadUrl() + " " + a.getFile() + " repid=" + ((rep != null) ? rep.getId() : null)); } deps = project.getPluginArtifacts(); for (Artifact a : deps) { log.info("plugin artifact: " + a.getId() + " (" + a.getScope() + ") from " + a.getDownloadUrl() + " " + a.getFile()); } }
From source file:org.codehaus.mojo.natives.plugin.NativeLinkMojo.java
License:Open Source License
/** * //from w ww. j a v a 2 s. c o m */ private void attachPrimaryArtifact() { Artifact artifact = this.project.getArtifact(); if (null == this.classifier) { artifact.setFile(new File(this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "." + this.project.getArtifact().getArtifactHandler().getExtension())); } else { //install primary artifact as a classifier DefaultArtifact clone = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersionRange().cloneOf(), artifact.getScope(), artifact.getType(), classifier, artifact.getArtifactHandler(), artifact.isOptional()); clone.setRelease(artifact.isRelease()); clone.setResolvedVersion(artifact.getVersion()); clone.setResolved(artifact.isResolved()); clone.setFile(artifact.getFile()); if (artifact.getAvailableVersions() != null) { clone.setAvailableVersions(new ArrayList(artifact.getAvailableVersions())); } clone.setBaseVersion(artifact.getBaseVersion()); clone.setDependencyFilter(artifact.getDependencyFilter()); if (artifact.getDependencyTrail() != null) { clone.setDependencyTrail(new ArrayList(artifact.getDependencyTrail())); } clone.setDownloadUrl(artifact.getDownloadUrl()); clone.setRepository(artifact.getRepository()); clone.setFile(new File(this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "." + this.project.getArtifact().getArtifactHandler().getExtension())); project.setArtifact(clone); } }
From source file:org.codehaus.mojo.webstart.AbstractJnlpMojo.java
License:Apache License
private void processDependency(Artifact artifact) throws MojoExecutionException { // TODO: scope handler // Include runtime and compile time libraries if (!Artifact.SCOPE_SYSTEM.equals(artifact.getScope()) && !Artifact.SCOPE_PROVIDED.equals(artifact.getScope()) && !Artifact.SCOPE_TEST.equals(artifact.getScope())) { String type = artifact.getType(); if ("jar".equals(type) || "ejb-client".equals(type)) { // FIXME when signed, we should update the manifest. // see http://www.mail-archive.com/turbine-maven-dev@jakarta.apache.org/msg08081.html // and maven1: maven-plugins/jnlp/src/main/org/apache/maven/jnlp/UpdateManifest.java // or shouldn't we? See MOJO-7 comment end of October. final File toCopy = artifact.getFile(); if (toCopy == null) { getLog().error("artifact with no file: " + artifact); getLog().error("artifact download url: " + artifact.getDownloadUrl()); getLog().error("artifact repository: " + artifact.getRepository()); getLog().error("artifact repository: " + artifact.getVersion()); throw new IllegalStateException( "artifact " + artifact + " has no matching file, why? Check the logs..."); }//ww w . j a v a 2 s. c om String name = getDependencyFilenameStrategy().getDependencyFilename(artifact, outputJarVersions, isUseUniqueVersions()); boolean copied = copyJarAsUnprocessedToDirectoryIfNecessary(toCopy, getLibDirectory(), name); if (copied) { getModifiedJnlpArtifacts().add(name.substring(0, name.lastIndexOf('.'))); } packagedJnlpArtifacts.add(artifact); if (jnlp.isRequireMainClass()) { // try to find if this dependency contains the main class boolean containsMainClass = getArtifactUtil().artifactContainsClass(artifact, jnlp.getMainClass()); if (containsMainClass) { if (artifactWithMainClass == null) { artifactWithMainClass = artifact; getLog().debug("Found main jar. Artifact " + artifactWithMainClass + " contains the main class: " + jnlp.getMainClass()); } else { getLog().warn("artifact " + artifact + " also contains the main class: " + jnlp.getMainClass() + ". IGNORED."); } } } } else // FIXME how do we deal with native libs? // we should probably identify them and package inside jars that we timestamp like the native lib // to avoid repackaging every time. What are the types of the native libs? { verboseLog("Skipping artifact of type " + type + " for " + getLibDirectory().getName()); } // END COPY } else { verboseLog("Skipping artifact of scope " + artifact.getScope() + " for " + getLibDirectory().getName()); } }
From source file:org.codehaus.mojo.webstart.AbstractJnlpMojo.java
License:Apache License
private void processExtensionDependency(JnlpExtension extension, Artifact artifact) throws MojoExecutionException { // TODO: scope handler // Include runtime and compile time libraries if (!Artifact.SCOPE_SYSTEM.equals(artifact.getScope()) && !Artifact.SCOPE_PROVIDED.equals(artifact.getScope()) && !Artifact.SCOPE_TEST.equals(artifact.getScope())) { String type = artifact.getType(); if ("jar".equals(type) || "ejb-client".equals(type)) { // FIXME when signed, we should update the manifest. // see http://www.mail-archive.com/turbine-maven-dev@jakarta.apache.org/msg08081.html // and maven1: maven-plugins/jnlp/src/main/org/apache/maven/jnlp/UpdateManifest.java // or shouldn't we? See MOJO-7 comment end of October. final File toCopy = artifact.getFile(); if (toCopy == null) { getLog().error("artifact with no file: " + artifact); getLog().error("artifact download url: " + artifact.getDownloadUrl()); getLog().error("artifact repository: " + artifact.getRepository()); getLog().error("artifact repository: " + artifact.getVersion()); throw new IllegalStateException( "artifact " + artifact + " has no matching file, why? Check the logs..."); }// ww w . j a v a 2 s .c o m // check jar is signed boolean jarSigned = isJarSigned(toCopy); if (!jarSigned) { throw new IllegalStateException( "artifact " + artifact + " must be signed as part of an extension.."); } String targetFilename = getDependencyFilenameStrategy().getDependencyFilename(artifact, outputJarVersions, isUseUniqueVersions()); File targetFile = new File(getLibDirectory(), targetFilename); boolean copied = getIoUtil().shouldCopyFile(toCopy, targetFile); if (copied) { getIoUtil().copyFile(toCopy, targetFile); verboseLog("copy extension artifact " + toCopy); } else { verboseLog("already up to date artifact " + toCopy); } // save the artifact dependency for the extension List<Artifact> deps = extensionsJnlpArtifacts.get(extension); if (deps == null) { deps = new ArrayList<Artifact>(); extensionsJnlpArtifacts.put(extension, deps); } deps.add(artifact); } else // FIXME how do we deal with native libs? // we should probably identify them and package inside jars that we timestamp like the native lib // to avoid repackaging every time. What are the types of the native libs? { verboseLog("Skipping artifact of type " + type + " for " + getLibDirectory().getName()); } // END COPY } else { verboseLog("Skipping artifact of scope " + artifact.getScope() + " for " + getLibDirectory().getName()); } }
From source file:org.eclipse.che.maven.CheArtifactResolver.java
License:Apache License
private void resolveOrig(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException { if (artifact == null) { return;/* ww w . j a v a 2 s . c o m*/ } if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) { File systemFile = artifact.getFile(); if (systemFile == null) { throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact); } if (!systemFile.exists()) { throw new ArtifactNotFoundException( "System artifact: " + artifact + " not found in path: " + systemFile, artifact); } if (!systemFile.isFile()) { throw new ArtifactNotFoundException( "System artifact: " + artifact + " is not a file: " + systemFile, artifact); } artifact.setResolved(true); return; } if (!artifact.isResolved()) { ArtifactResult result; try { ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact)); artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories)); // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not LocalRepositoryManager lrm = session.getLocalRepositoryManager(); String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact()); artifact.setFile(new File(lrm.getRepository().getBasedir(), path)); result = repoSystem.resolveArtifact(session, artifactRequest); } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) { if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) { throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), e); } else { throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e); } } artifact.selectVersion(result.getArtifact().getVersion()); artifact.setFile(result.getArtifact().getFile()); artifact.setResolved(true); if (artifact.isSnapshot()) { Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion()); if (matcher.matches()) { Snapshot snapshot = new Snapshot(); snapshot.setTimestamp(matcher.group(2)); try { snapshot.setBuildNumber(Integer.parseInt(matcher.group(3))); artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot)); } catch (NumberFormatException e) { logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage()); } } } } }
From source file:org.jetbrains.idea.maven.server.embedder.CustomMaven32ArtifactResolver.java
License:Apache License
private void resolveOld(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException { if (artifact == null) { return;/*from w ww . java 2s. co m*/ } if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) { File systemFile = artifact.getFile(); if (systemFile == null) { throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact); } if (!systemFile.exists()) { throw new ArtifactNotFoundException( "System artifact: " + artifact + " not found in path: " + systemFile, artifact); } if (!systemFile.isFile()) { throw new ArtifactNotFoundException( "System artifact: " + artifact + " is not a file: " + systemFile, artifact); } artifact.setResolved(true); return; } if (!artifact.isResolved()) { ArtifactResult result; try { ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact)); artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories)); // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not LocalRepositoryManager lrm = session.getLocalRepositoryManager(); String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact()); artifact.setFile(new File(lrm.getRepository().getBasedir(), path)); result = repoSystem.resolveArtifact(session, artifactRequest); } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) { if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) { throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), e); } else { throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e); } } artifact.selectVersion(result.getArtifact().getVersion()); artifact.setFile(result.getArtifact().getFile()); artifact.setResolved(true); if (artifact.isSnapshot()) { Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion()); if (matcher.matches()) { Snapshot snapshot = new Snapshot(); snapshot.setTimestamp(matcher.group(2)); try { snapshot.setBuildNumber(Integer.parseInt(matcher.group(3))); artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot)); } catch (NumberFormatException e) { logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage()); } } } } }