List of usage examples for org.apache.maven.artifact Artifact setVersion
void setVersion(String version);
From source file:com.linkedin.oneclick.hadoop.LauncherPlugin.java
License:Apache License
static void convert(LauncherConfig.Artifact src, Artifact dest) { dest.setGroupId(src.getGroupId());//from w ww.j av a 2 s.com dest.setArtifactId(src.getArtifactId()); dest.setVersion(src.getVersion()); dest.setFile(src.getFile()); dest.setScope(src.getScope()); }
From source file:com.opoopress.maven.plugins.plugin.downloader.DefaultArtifactDownloader.java
License:Apache License
@Override public File download(String groupId, String artifactId, String version, String classifier, String type) throws MojoFailureException { // if (theme != null) { // String[] tokens = StringUtils.split(theme, ":"); // if (tokens.length < 3 || tokens.length > 5) { // throw new MojoFailureException( // "Invalid theme artifact, you must specify groupId:artifactId:version[:packaging][:classifier] " // + theme); // } // groupId = tokens[0]; // artifactId = tokens[1]; // version = tokens[2]; // if (tokens.length >= 4) { // type = tokens[3]; // } // if (tokens.length == 5) { // classifier = tokens[4]; // } else { // classifier = null; // } // }/*from w ww. j ava2 s . com*/ // // if (artifactId == null) { // throw new MojoFailureException("theme'' or 'name' property is required."); // } String dummyVersion = version; if (version == null) { dummyVersion = "1.0"; } Artifact toDownload = classifier == null ? artifactFactory.createBuildArtifact(groupId, artifactId, dummyVersion, type) : artifactFactory.createArtifactWithClassifier(groupId, artifactId, dummyVersion, type, classifier); List<ArtifactRepository> remoteRepositoryList = getRemoteRepositoryList(); if (version == null) { List<ArtifactVersion> versions = null; try { versions = artifactMetadataSource.retrieveAvailableVersions(toDownload, localRepository, remoteRepositoryList); } catch (ArtifactMetadataRetrievalException e) { throw new MojoFailureException("Retrieve theme artifact versions failed: " + e.getMessage(), e); } if (versions.isEmpty()) { throw new MojoFailureException("Theme artifact versions not found."); } getLog().info("Found versions: " + versions.toString()); Collections.sort(versions); version = versions.get(versions.size() - 1).toString(); toDownload.setVersion(version); getLog().info("Choose version: " + version); } try { artifactResolver.resolve(toDownload, remoteRepositoryList, localRepository); } catch (ArtifactResolutionException e) { throw new MojoFailureException("Download theme artifact failed: " + e.getMessage(), e); } catch (ArtifactNotFoundException e) { throw new MojoFailureException("Theme artifact not found: " + e.getMessage()); } return toDownload.getFile(); }
From source file:fr.in2p3.maven.plugin.DependencyXmlMojo.java
private void dump(DependencyNode current, PrintStream out) throws MojoExecutionException, MojoFailureException { String artifactId = current.getArtifact().getArtifactId(); boolean hasClassifier = (current.getArtifact().getClassifier() != null); if ((artifactId.startsWith("jsaga-") || artifactId.startsWith("saga-")) && !hasClassifier) { MavenProject module = this.getMavenProject(current.getArtifact()); if (module != null) { // Filter does NOT work // AndArtifactFilter scopeFilter = new AndArtifactFilter(); // scopeFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_COMPILE)); // scopeFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME)); try { current = dependencyTreeBuilder.buildDependencyTree(module, localRepository, factory, artifactMetadataSource, null, collector); } catch (DependencyTreeBuilderException e) { throw new MojoExecutionException("Unable to build dependency tree", e); }//from w w w . j ava 2s .co m } } // dump (part 1) indent(current, out); out.print("<artifact"); Artifact artifact = current.getArtifact(); addAttribute(out, "id", artifact.getArtifactId()); addAttribute(out, "group", artifact.getGroupId()); // Get version from HashMap String v = includedArtifacts.get(artifact.getArtifactId()); if (v != null) { artifact.setVersion(v); } addAttribute(out, "version", artifact.getVersion()); addAttribute(out, "type", artifact.getType()); addAttribute(out, "scope", artifact.getScope()); addAttribute(out, "classifier", artifact.getClassifier()); try { addAttribute(out, "file", this.getJarFile(artifact).toString()); } catch (Exception e) { getLog().debug(artifact.getArtifactId() + "Could not find JAR"); } MavenProject proj = this.getMavenProject(artifact); if (proj != null) { if (!proj.getName().startsWith("Unnamed - ")) { addAttribute(out, "name", proj.getName()); } addAttribute(out, "description", proj.getDescription()); addAttribute(out, "url", proj.getUrl()); if (proj.getOrganization() != null) { addAttribute(out, "organization", proj.getOrganization().getName()); addAttribute(out, "organizationUrl", proj.getOrganization().getUrl()); } if (proj.getLicenses().size() > 0) { License license = (License) proj.getLicenses().get(0); addAttribute(out, "license", license.getName()); addAttribute(out, "licenseUrl", license.getUrl()); } } out.println(">"); // recurse for (Iterator it = current.getChildren().iterator(); it.hasNext();) { DependencyNode child = (DependencyNode) it.next(); // filter dependencies with scope "test", except those with classifier "tests" (i.e. adaptor integration tests) if ("test".equals(child.getArtifact().getScope()) && !"tests".equals(child.getArtifact().getClassifier())) { Artifact c = child.getArtifact(); getLog().debug(artifact.getArtifactId() + ": ignoring dependency " + c.getGroupId() + ":" + c.getArtifactId()); } else { this.dump(child, out); } } // dump (part 2) indent(current, out); out.println("</artifact>"); }
From source file:org.apache.archiva.converter.artifact.LegacyToDefaultConverter.java
License:Apache License
private boolean doRelocation(Artifact artifact, org.apache.maven.model.v3_0_0.Model v3Model, ArtifactRepository repository, FileTransaction transaction) throws IOException { Properties properties = v3Model.getProperties(); if (properties.containsKey("relocated.groupId") || properties.containsKey("relocated.artifactId") //$NON-NLS-1$ //$NON-NLS-2$ || properties.containsKey("relocated.version")) //$NON-NLS-1$ {//w w w . ja v a 2s . c om String newGroupId = properties.getProperty("relocated.groupId", v3Model.getGroupId()); //$NON-NLS-1$ properties.remove("relocated.groupId"); //$NON-NLS-1$ String newArtifactId = properties.getProperty("relocated.artifactId", v3Model.getArtifactId()); //$NON-NLS-1$ properties.remove("relocated.artifactId"); //$NON-NLS-1$ String newVersion = properties.getProperty("relocated.version", v3Model.getVersion()); //$NON-NLS-1$ properties.remove("relocated.version"); //$NON-NLS-1$ String message = properties.getProperty("relocated.message", ""); //$NON-NLS-1$ //$NON-NLS-2$ properties.remove("relocated.message"); //$NON-NLS-1$ if (properties.isEmpty()) { v3Model.setProperties(null); } writeRelocationPom(v3Model.getGroupId(), v3Model.getArtifactId(), v3Model.getVersion(), newGroupId, newArtifactId, newVersion, message, repository, transaction); v3Model.setGroupId(newGroupId); v3Model.setArtifactId(newArtifactId); v3Model.setVersion(newVersion); artifact.setGroupId(newGroupId); artifact.setArtifactId(newArtifactId); artifact.setVersion(newVersion); return true; } else { return false; } }
From source file:org.apache.aries.plugin.eba.stubs.EbaMavenProjectStub.java
License:Apache License
public Artifact getArtifact() { Artifact artifact = new EbaArtifactStub(); artifact.setGroupId(getGroupId());/* www. ja v a 2 s.c o m*/ artifact.setArtifactId(getArtifactId()); artifact.setVersion(getVersion()); return artifact; }
From source file:org.apache.aries.plugin.eba.stubs.EbaMavenProjectStub.java
License:Apache License
protected Artifact createArtifact(String groupId, String artifactId, String version, boolean optional) { Artifact artifact = new EbaArtifactStub(); artifact.setGroupId(groupId);//from w w w .ja v a 2 s. co m artifact.setArtifactId(artifactId); artifact.setVersion(version); artifact.setOptional(optional); artifact.setFile(new File(getBasedir() + "/src/test/remote-repo/" + artifact.getGroupId().replace('.', '/') + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + ".jar")); return artifact; }
From source file:org.apache.aries.plugin.esa.stubs.EsaMavenProjectStub.java
License:Apache License
public Artifact getArtifact() { Artifact artifact = new EsaArtifactStub(); artifact.setGroupId(getGroupId());/*from w w w. j a v a 2 s .c om*/ artifact.setArtifactId(getArtifactId()); artifact.setVersion(getVersion()); return artifact; }
From source file:org.apache.aries.plugin.esa.stubs.EsaMavenProjectStub.java
License:Apache License
protected Artifact createArtifact(String groupId, String artifactId, String version, String type, boolean optional) { Artifact artifact = new EsaArtifactStub(); artifact.setGroupId(groupId);/* w w w . j a va 2s .c om*/ artifact.setArtifactId(artifactId); artifact.setVersion(version); artifact.setOptional(optional); artifact.setFile(new File(getBasedir() + "/src/test/remote-repo/" + artifact.getGroupId().replace('.', '/') + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + type)); return artifact; }
From source file:org.apache.karaf.tooling.features.CreateKarMojo.java
License:Apache License
/** * Generates the configuration archive.//from ww w .j a va 2 s. c o m * * @param bundles */ @SuppressWarnings("deprecation") private File createArchive(List<Artifact> bundles, File featuresFile, String groupId, String artifactId, String version) throws MojoExecutionException { ArtifactRepositoryLayout layout = new DefaultRepositoryLayout(); File archiveFile = getArchiveFile(outputDirectory, finalName, classifier); MavenArchiver archiver = new MavenArchiver(); archiver.setArchiver(jarArchiver); archiver.setOutputFile(archiveFile); try { //TODO should .kar be a bundle? // archive.addManifestEntry(Constants.BUNDLE_NAME, project.getName()); // archive.addManifestEntry(Constants.BUNDLE_VENDOR, project.getOrganization().getName()); // ArtifactVersion version = project.getArtifact().getSelectedVersion(); // String versionString = "" + version.getMajorVersion() + "." + version.getMinorVersion() + "." + version.getIncrementalVersion(); // if (version.getQualifier() != null) { // versionString += "." + version.getQualifier(); // } // archive.addManifestEntry(Constants.BUNDLE_VERSION, versionString); // archive.addManifestEntry(Constants.BUNDLE_MANIFESTVERSION, "2"); // archive.addManifestEntry(Constants.BUNDLE_DESCRIPTION, project.getDescription()); // // NB, no constant for this one // archive.addManifestEntry("Bundle-License", ((License) project.getLicenses().get(0)).getUrl()); // archive.addManifestEntry(Constants.BUNDLE_DOCURL, project.getUrl()); // //TODO this might need some help // archive.addManifestEntry(Constants.BUNDLE_SYMBOLICNAME, project.getArtifactId()); //include the feature.xml Artifact featureArtifact = factory.createArtifactWithClassifier(groupId, artifactId, version, "xml", KarArtifactInstaller.FEATURE_CLASSIFIER); jarArchiver.addFile(featuresFile, repositoryPath + layout.pathOf(featureArtifact)); if (featureArtifact.isSnapshot()) { // the artifact is a snapshot, create the maven-metadata-local.xml getLog().debug("Feature artifact is a SNAPSHOT, handling the maven-metadata-local.xml"); File metadataTarget = new File(featuresFile.getParentFile(), "maven-metadata-local.xml"); getLog().debug("Looking for " + metadataTarget.getAbsolutePath()); if (!metadataTarget.exists()) { // the maven-metadata-local.xml doesn't exist, create it getLog().debug(metadataTarget.getAbsolutePath() + " doesn't exist, create it"); Metadata metadata = new Metadata(); metadata.setGroupId(featureArtifact.getGroupId()); metadata.setArtifactId(featureArtifact.getArtifactId()); metadata.setVersion(featureArtifact.getVersion()); metadata.setModelVersion("1.1.0"); Versioning versioning = new Versioning(); versioning.setLastUpdatedTimestamp(new Date(System.currentTimeMillis())); Snapshot snapshot = new Snapshot(); snapshot.setLocalCopy(true); versioning.setSnapshot(snapshot); SnapshotVersion snapshotVersion = new SnapshotVersion(); snapshotVersion.setClassifier(featureArtifact.getClassifier()); snapshotVersion.setVersion(featureArtifact.getVersion()); snapshotVersion.setExtension(featureArtifact.getType()); snapshotVersion.setUpdated(versioning.getLastUpdated()); versioning.addSnapshotVersion(snapshotVersion); metadata.setVersioning(versioning); MetadataXpp3Writer metadataWriter = new MetadataXpp3Writer(); try { Writer writer = new FileWriter(metadataTarget); metadataWriter.write(writer, metadata); } catch (Exception e) { getLog().warn("Could not create maven-metadata-local.xml", e); getLog().warn( "It means that this SNAPSHOT could be overwritten by an older one present on remote repositories"); } } getLog().debug( "Adding file " + metadataTarget.getAbsolutePath() + " in the jar path " + repositoryPath + layout.pathOf(featureArtifact).substring(0, layout.pathOf(featureArtifact).lastIndexOf('/')) + "/maven-metadata-local.xml"); jarArchiver.addFile(metadataTarget, repositoryPath + layout.pathOf(featureArtifact).substring(0, layout.pathOf(featureArtifact).lastIndexOf('/')) + "/maven-metadata-local.xml"); } for (Artifact artifact : bundles) { resolver.resolve(artifact, remoteRepos, localRepo); File localFile = artifact.getFile(); if (artifact.isSnapshot()) { // the artifact is a snapshot, create the maven-metadata-local.xml File metadataTarget = new File(localFile.getParentFile(), "maven-metadata-local.xml"); if (!metadataTarget.exists()) { // the maven-metadata-local.xml doesn't exist, create it try { MavenUtil.generateMavenMetadata(artifact, metadataTarget); } catch (Exception e) { getLog().warn("Could not create maven-metadata-local.xml", e); getLog().warn( "It means that this SNAPSHOT could be overwritten by an older one present on remote repositories"); } } jarArchiver.addFile(metadataTarget, repositoryPath + layout.pathOf(artifact).substring(0, layout.pathOf(artifact).lastIndexOf('/')) + "/maven-metadata-local.xml"); } //TODO this may not be reasonable, but... resolved snapshot artifacts have timestamped versions //which do not work in startup.properties. artifact.setVersion(artifact.getBaseVersion()); String targetFileName = repositoryPath + layout.pathOf(artifact); jarArchiver.addFile(localFile, targetFileName); } if (resourcesDir.isDirectory()) { archiver.getArchiver().addDirectory(resourcesDir); } archiver.createArchive(project, archive); return archiveFile; } catch (Exception e) { throw new MojoExecutionException("Failed to create archive", e); } }
From source file:org.apache.karaf.tooling.KarMojo.java
License:Apache License
/** * Generates the configuration archive./*from w ww. ja va2 s .co m*/ * * @param bundles */ @SuppressWarnings("deprecation") private File createArchive(List<Artifact> bundles, File featuresFile, String groupId, String artifactId, String version) throws MojoExecutionException { ArtifactRepositoryLayout layout = new DefaultRepositoryLayout(); File archiveFile = getArchiveFile(outputDirectory, finalName, classifier); MavenArchiver archiver = new MavenArchiver(); archiver.setArchiver(jarArchiver); archiver.setOutputFile(archiveFile); try { //TODO should .kar be a bundle? // archive.addManifestEntry(Constants.BUNDLE_NAME, project.getName()); // archive.addManifestEntry(Constants.BUNDLE_VENDOR, project.getOrganization().getName()); // ArtifactVersion version = project.getArtifact().getSelectedVersion(); // String versionString = "" + version.getMajorVersion() + "." + version.getMinorVersion() + "." + version.getIncrementalVersion(); // if (version.getQualifier() != null) { // versionString += "." + version.getQualifier(); // } // archive.addManifestEntry(Constants.BUNDLE_VERSION, versionString); // archive.addManifestEntry(Constants.BUNDLE_MANIFESTVERSION, "2"); // archive.addManifestEntry(Constants.BUNDLE_DESCRIPTION, project.getDescription()); // // NB, no constant for this one // archive.addManifestEntry("Bundle-License", ((License) project.getLicenses().get(0)).getUrl()); // archive.addManifestEntry(Constants.BUNDLE_DOCURL, project.getUrl()); // //TODO this might need some help // archive.addManifestEntry(Constants.BUNDLE_SYMBOLICNAME, project.getArtifactId()); //include the feature.xml Artifact featureArtifact = factory.createArtifactWithClassifier(groupId, artifactId, version, "xml", KarArtifactInstaller.FEATURE_CLASSIFIER); jarArchiver.addFile(featuresFile, repositoryPath + layout.pathOf(featureArtifact)); if (featureArtifact.isSnapshot()) { // the artifact is a snapshot, create the maven-metadata-local.xml getLog().debug("Feature artifact is a SNAPSHOT, handling the maven-metadata-local.xml"); File metadataTarget = new File(featuresFile.getParentFile(), "maven-metadata-local.xml"); getLog().debug("Looking for " + metadataTarget.getAbsolutePath()); if (!metadataTarget.exists()) { // the maven-metadata-local.xml doesn't exist, create it getLog().debug(metadataTarget.getAbsolutePath() + " doesn't exist, create it"); Metadata metadata = new Metadata(); metadata.setGroupId(featureArtifact.getGroupId()); metadata.setArtifactId(featureArtifact.getArtifactId()); metadata.setVersion(featureArtifact.getVersion()); metadata.setModelVersion("1.1.0"); Versioning versioning = new Versioning(); versioning.setLastUpdatedTimestamp(new Date(System.currentTimeMillis())); Snapshot snapshot = new Snapshot(); snapshot.setLocalCopy(true); versioning.setSnapshot(snapshot); SnapshotVersion snapshotVersion = new SnapshotVersion(); snapshotVersion.setClassifier(featureArtifact.getClassifier()); snapshotVersion.setVersion(featureArtifact.getVersion()); snapshotVersion.setExtension(featureArtifact.getType()); snapshotVersion.setUpdated(versioning.getLastUpdated()); versioning.addSnapshotVersion(snapshotVersion); metadata.setVersioning(versioning); MetadataXpp3Writer metadataWriter = new MetadataXpp3Writer(); try { Writer writer = new FileWriter(metadataTarget); metadataWriter.write(writer, metadata); } catch (Exception e) { getLog().warn("Could not create maven-metadata-local.xml", e); getLog().warn( "It means that this SNAPSHOT could be overwritten by an older one present on remote repositories"); } } getLog().debug( "Adding file " + metadataTarget.getAbsolutePath() + " in the jar path " + repositoryPath + layout.pathOf(featureArtifact).substring(0, layout.pathOf(featureArtifact).lastIndexOf('/')) + "/maven-metadata-local.xml"); jarArchiver.addFile(metadataTarget, repositoryPath + layout.pathOf(featureArtifact).substring(0, layout.pathOf(featureArtifact).lastIndexOf('/')) + "/maven-metadata-local.xml"); } for (Artifact artifact : bundles) { artifactResolver.resolve(artifact, remoteRepos, localRepo); File localFile = artifact.getFile(); if (artifact.isSnapshot()) { // the artifact is a snapshot, create the maven-metadata-local.xml File metadataTarget = new File(localFile.getParentFile(), "maven-metadata-local.xml"); if (!metadataTarget.exists()) { // the maven-metadata-local.xml doesn't exist, create it try { MavenUtil.generateMavenMetadata(artifact, metadataTarget); } catch (Exception e) { getLog().warn("Could not create maven-metadata-local.xml", e); getLog().warn( "It means that this SNAPSHOT could be overwritten by an older one present on remote repositories"); } } jarArchiver.addFile(metadataTarget, repositoryPath + layout.pathOf(artifact).substring(0, layout.pathOf(artifact).lastIndexOf('/')) + "/maven-metadata-local.xml"); } //TODO this may not be reasonable, but... resolved snapshot artifacts have timestamped versions //which do not work in startup.properties. artifact.setVersion(artifact.getBaseVersion()); String targetFileName = repositoryPath + layout.pathOf(artifact); jarArchiver.addFile(localFile, targetFileName); } if (resourcesDir.isDirectory()) { archiver.getArchiver().addDirectory(resourcesDir); } archiver.createArchive(project, archive); return archiveFile; } catch (Exception e) { throw new MojoExecutionException("Failed to create archive", e); } }