List of usage examples for org.apache.maven.artifact Artifact updateVersion
void updateVersion(String version, ArtifactRepository localRepository);
From source file:com.asual.summer.onejar.OneJarMojo.java
License:Apache License
public void execute() throws MojoExecutionException { JarOutputStream out = null;//from w w w .ja va 2 s .co m JarInputStream in = null; try { File jarFile = new File(buildDirectory, jarName); File warFile = new File(buildDirectory, warName); Manifest manifest = new Manifest(new ByteArrayInputStream("Manifest-Version: 1.0\n".getBytes("UTF-8"))); manifest.getMainAttributes().putValue("Main-Class", JAR_MAIN_CLASS); manifest.getMainAttributes().putValue("One-Jar-Main-Class", ONE_JAR_MAIN_CLASS); out = new JarOutputStream(new FileOutputStream(jarFile, false), manifest); in = new JarInputStream(getClass().getClassLoader().getResourceAsStream(ONE_JAR_DIST)); putEntry(out, new FileInputStream(warFile), new ZipEntry(JAR_CLASSPATH + warFile.getName())); for (Artifact artifact : pluginArtifacts) { if (artifact.getArtifactId().equalsIgnoreCase("summer-onejar")) { artifact.updateVersion(artifact.getVersion(), localRepository); putEntry(out, new FileInputStream(artifact.getFile()), new ZipEntry(JAR_CLASSPATH + artifact.getFile().getName())); MavenProject project = mavenProjectBuilder.buildFromRepository(artifact, remoteArtifactRepositories, localRepository); List<Dependency> dependencies = project.getDependencies(); for (Dependency dependency : dependencies) { if (!"provided".equals(dependency.getScope())) { Artifact dependencyArtifact = artifactFactory.createArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getScope(), dependency.getType()); dependencyArtifact.updateVersion(dependencyArtifact.getVersion(), localRepository); putEntry(out, new FileInputStream(dependencyArtifact.getFile()), new ZipEntry(JAR_CLASSPATH + dependencyArtifact.getFile().getName())); } } } } while (true) { ZipEntry entry = in.getNextEntry(); if (entry != null) { putEntry(out, in, entry); } else { break; } } projectHelper.attachArtifact(project, "jar", jarFile); } catch (Exception e) { getLog().error(e.getMessage(), e); throw new MojoExecutionException(e.getMessage(), e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); } }
From source file:hudson.maven.artifact.transform.SnapshotTransformation.java
License:Apache License
public void transformForResolve(Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository) throws ArtifactResolutionException { // Only select snapshots that are unresolved (eg 1.0-SNAPSHOT, not 1.0-20050607.123456) if (artifact.isSnapshot() && artifact.getBaseVersion().equals(artifact.getVersion())) { try {//from w w w . j a va 2 s. c om String version = resolveVersion(artifact, localRepository, remoteRepositories); artifact.updateVersion(version, localRepository); } catch (RepositoryMetadataResolutionException e) { throw new ArtifactResolutionException(e.getMessage(), artifact, e); } } }
From source file:org.nuxeo.build.maven.AntBuildMojo.java
License:Open Source License
/** * Try to locally resolve an artifact with its "unique" version. * * @since 1.11.1// w ww. j av a2s . c o m * @param artifact Artifact to resolve with its unique version * @param e ArtifactNotFoundException originally thrown * @throws ArtifactNotFoundException If alternate resolution failed. * @see Artifact#getBaseVersion() */ protected void tryResolutionOnLocalBaseVersion(Artifact artifact, ArtifactNotFoundException e) throws ArtifactNotFoundException { String resolvedVersion = artifact.getVersion(); artifact.updateVersion(artifact.getBaseVersion(), localRepository); File localFile = new File(localRepository.getBasedir(), localRepository.pathOf(artifact)); if (localFile.exists()) { getLog().warn(String.format("Couldn't resolve %s, fallback on local install of unique version %s.", resolvedVersion, artifact.getBaseVersion())); artifact.setResolved(true); } else { // No success, set back the previous version and raise an error artifact.updateVersion(resolvedVersion, localRepository); throw e; } }