List of usage examples for org.apache.maven.artifact ArtifactUtils copyArtifact
public static Artifact copyArtifact(Artifact artifact)
From source file:org.codehaus.mojo.LazyDeployMojo.java
License:Apache License
private boolean unchanged(Artifact artifact) { if (alternativeRepository == null) { return false; }// w w w . j av a 2 s. c o m // try to copy the artifact from a remote repository to our local alternative repository Artifact copy = ArtifactUtils.copyArtifact(artifact); try { resolver.resolve(copy, remoteRepositories, alternativeRepository); } catch (ArtifactNotFoundException e) { // not found; force "changed" return false; } catch (ArtifactResolutionException e) { // not found; force "changed" return false; } // did we obtain a copy of a remote artifact? File file = copy.getFile(); if (file == null || !file.exists()) { return false; } return compare(file, artifact.getFile()) == 0; }
From source file:org.debian.dependency.builders.EmbeddedAntBuilder.java
License:Apache License
@Override public Set<Artifact> build(final Artifact artifact, final Source source, final File localRepository) throws ArtifactBuildException { try {/*www . j a va2 s .c om*/ List<File> buildFiles = findBuildFiles(source.getLocation()); if (buildFiles == null || buildFiles.isEmpty()) { throw new ArtifactBuildException("No build files found for " + artifact); } Project antProject = new Project(); ProjectHelper.configureProject(antProject, buildFiles.get(0)); antProject.init(); antProject.setBaseDir(buildFiles.get(0).getParentFile()); antProject.executeTarget(antProject.getDefaultTarget()); Set<Artifact> result = new HashSet<Artifact>(); Artifact builtArtifact = ArtifactUtils.copyArtifact(artifact); builtArtifact.setFile(findFile(artifact, source, "**/*.jar")); result.add(builtArtifact); Artifact pomArtifact = repositorySystem.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); pomArtifact.setFile(findProjectFile(artifact, source)); result.add(pomArtifact); return result; } catch (IOException e) { throw new ArtifactBuildException(e); } catch (BuildException e) { throw new ArtifactBuildException(e); } }
From source file:org.org.maven.plugin.dws.utils.RepositoryUtils.java
License:Apache License
/** * @param artifact not null//w ww .j a v a2 s . co m * @param repo not null * @return the artifact url in the given repo for the given artifact. If it is a snapshot artifact, the version * will be the timestamp and the build number from the metadata. Could return null if the repo is blacklisted. */ public String getDependencyUrlFromRepository(Artifact artifact, ArtifactRepository repo) { if (repo.isBlacklisted()) { return null; } Artifact copyArtifact = ArtifactUtils.copyArtifact(artifact); // Try to get the last artifact repo name depending the snapshot version if ((artifact.isSnapshot() && repo.getSnapshots().isEnabled())) { if (artifact.getBaseVersion().equals(artifact.getVersion())) { // Try to resolve it if not already done if (artifact.getMetadataList() == null || artifact.getMetadataList().isEmpty()) { try { resolve(artifact); } catch (ArtifactResolutionException e) { log.error("Artifact: " + artifact.getId() + " could not be resolved."); } catch (ArtifactNotFoundException e) { log.error("Artifact: " + artifact.getId() + " was not found."); } } for (Iterator it = artifact.getMetadataList().iterator(); it.hasNext();) { ArtifactMetadata m = (ArtifactMetadata) it.next(); if (m instanceof SnapshotArtifactRepositoryMetadata) { SnapshotArtifactRepositoryMetadata snapshotMetadata = (SnapshotArtifactRepositoryMetadata) m; // Removed not found log int oldThreshold = loggerManager.getThreshold(); loggerManager.setThreshold(RepositoryMetadataManager.class.getName(), Logger.LEVEL_DISABLED); try { repositoryMetadataManager.resolveAlways(snapshotMetadata, localRepository, repo); } catch (RepositoryMetadataResolutionException e) { loggerManager.setThreshold(RepositoryMetadataManager.class.getName(), oldThreshold); if (log.isDebugEnabled()) { log.error("Unable to connect to: " + repo.getUrl(), e); } else { log.error("Unable to connect to: " + repo.getUrl()); } return repo.getUrl() + "/" + repo.pathOf(copyArtifact); } finally { loggerManager.setThreshold(RepositoryMetadataManager.class.getName(), oldThreshold); } Metadata metadata = snapshotMetadata.getMetadata(); if (metadata.getVersioning() == null || metadata.getVersioning().getSnapshot() == null || metadata.getVersioning().getSnapshot().isLocalCopy() || metadata.getVersioning().getSnapshot().getTimestamp() == null) { continue; } // create the version according SnapshotTransformation String version = StringUtils.replace(copyArtifact.getVersion(), Artifact.SNAPSHOT_VERSION, metadata.getVersioning().getSnapshot().getTimestamp()) + "-" + metadata.getVersioning().getSnapshot().getBuildNumber(); copyArtifact.setVersion(version); } } } } return repo.getUrl() + "/" + repo.pathOf(copyArtifact); }
From source file:org.sourcepit.tools.mojo.DeployCopiedArtifactMojo.java
License:Apache License
private void deployProject(DeployRequest request) throws MojoExecutionException, MojoFailureException { Artifact artifact = ArtifactUtils.copyArtifact(request.getProject().getArtifact()); String packaging = request.getProject().getPackaging(); File pomFile = request.getProject().getFile(); @SuppressWarnings("unchecked") List<Artifact> attachedArtifacts = new ArrayList<Artifact>(); ArtifactUtils.copyArtifacts(request.getProject().getAttachedArtifacts(), attachedArtifacts); ArtifactRepository repo = getDeploymentRepository(request.getProject(), request.getAltDeploymentRepository(), request.getAltReleaseDeploymentRepository(), request.getAltSnapshotDeploymentRepository()); String protocol = repo.getProtocol(); if (protocol.equalsIgnoreCase("scp")) { File sshFile = new File(System.getProperty("user.home"), ".ssh"); if (!sshFile.exists()) { sshFile.mkdirs();/* w w w . j a v a 2 s.com*/ } } // Deploy the POM boolean isPomArtifact = "pom".equals(packaging); if (!isPomArtifact) { ArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, pomFile); artifact.addMetadata(metadata); } if (request.isUpdateReleaseInfo()) { artifact.setRelease(true); } int retryFailedDeploymentCount = request.getRetryFailedDeploymentCount(); try { if (isPomArtifact) { deploy(pomFile, artifact, repo, getLocalRepository(), retryFailedDeploymentCount); } else { File file = artifact.getFile(); if (file != null && file.isFile()) { deploy(file, artifact, repo, getLocalRepository(), retryFailedDeploymentCount); } else if (!attachedArtifacts.isEmpty()) { getLog().info("No primary artifact to deploy, deploying attached artifacts instead."); Artifact pomArtifact = artifactFactory.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); pomArtifact.setFile(pomFile); if (request.isUpdateReleaseInfo()) { pomArtifact.setRelease(true); } deploy(pomFile, pomArtifact, repo, getLocalRepository(), retryFailedDeploymentCount); // propagate the timestamped version to the main artifact for the attached artifacts to pick it up artifact.setResolvedVersion(pomArtifact.getVersion()); } else { String message = "The packaging for this project did not assign a file to the build artifact"; throw new MojoExecutionException(message); } } for (Artifact attached : attachedArtifacts) { deploy(attached.getFile(), attached, repo, getLocalRepository(), retryFailedDeploymentCount); } } catch (ArtifactDeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } }