List of usage examples for org.apache.maven.project MavenProject getVersion
public String getVersion()
From source file:ms.dew.devops.kernel.plugin.deploy.maven.MavenDeployPlugin.java
License:Apache License
@Override public Resp<String> deployAble(FinalProjectConfig projectConfig) { MavenProject mavenProject = projectConfig.getMavenProject(); String version = mavenProject.getVersion(); if (version.trim().toLowerCase().endsWith("snapshot")) { // /*from ww w.j a v a2s .c o m*/ if (mavenProject.getDistributionManagement() == null || mavenProject.getDistributionManagement().getSnapshotRepository() == null || mavenProject.getDistributionManagement().getSnapshotRepository().getUrl() == null || mavenProject.getDistributionManagement().getSnapshotRepository().getUrl().trim().isEmpty()) { return Resp.forbidden("Maven distribution snapshot repository not found"); } } else if (mavenProject.getDistributionManagement() == null || mavenProject.getDistributionManagement().getRepository() == null || mavenProject.getDistributionManagement().getRepository().getUrl() == null || mavenProject.getDistributionManagement().getRepository().getUrl().trim().isEmpty()) { // ?? return Resp.forbidden("Maven distribution repository not found"); } String repoUrl = mavenProject.getDistributionManagement().getRepository().getUrl().trim(); // TBD auth repoUrl = repoUrl.endsWith("/") ? repoUrl : repoUrl + "/"; repoUrl += mavenProject.getGroupId().replaceAll("\\.", "/") + "/" + mavenProject.getArtifactId() + "/" + version; try { if ($.http.getWrap(repoUrl).statusCode == 200) { return Resp.forbidden("The current version already exists"); } } catch (IOException e) { throw new ProjectProcessException(e.getMessage(), e); } return Resp.success(""); }
From source file:net.dynamic_tools.maven.plugin.javascript.util.JavaScriptArchiver.java
License:Apache License
public void createDefaultManifest(MavenProject project) throws ManifestException, IOException, ArchiverException { Manifest manifest = new Manifest(); Manifest.Attribute attr = new Manifest.Attribute("Created-By", "Apache Maven"); manifest.addConfiguredAttribute(attr); attr = new Manifest.Attribute("Implementation-Title", project.getName()); manifest.addConfiguredAttribute(attr); attr = new Manifest.Attribute("Implementation-Version", project.getVersion()); manifest.addConfiguredAttribute(attr); attr = new Manifest.Attribute("Implementation-Vendor-Id", project.getGroupId()); manifest.addConfiguredAttribute(attr); if (project.getOrganization() != null) { String vendor = project.getOrganization().getName(); attr = new Manifest.Attribute("Implementation-Vendor", vendor); manifest.addConfiguredAttribute(attr); }/*from ww w. j av a 2s .c o m*/ attr = new Manifest.Attribute("Built-By", System.getProperty("user.name")); manifest.addConfiguredAttribute(attr); File mf = File.createTempFile("maven", ".mf"); mf.deleteOnExit(); PrintWriter writer = new PrintWriter(new FileWriter(mf)); manifest.write(writer); writer.close(); setManifest(mf); }
From source file:net.erdfelt.maven.graphing.MultimoduleGraphMojo.java
License:Apache License
private boolean isMultiModuleDependency(Dependency dep) { boolean ret = false; Iterator it = projects.iterator(); while (it.hasNext()) { MavenProject project = (MavenProject) it.next(); if (StringUtils.equals(project.getGroupId(), dep.getGroupId()) && StringUtils.equals(project.getArtifactId(), dep.getArtifactId()) && StringUtils.equals(project.getPackaging(), dep.getType())) { // Found dep that matches on groupId / artifactId / type only. if (ignoreVersions) { // No test of version. ret = true;//from w w w .j a v a 2 s.c o m break; } else if (StringUtils.equals(project.getVersion(), dep.getVersion())) { // Found dep that matches on version too. ret = true; break; } } } return ret; }
From source file:net.erdfelt.maven.graphing.MultimoduleGraphMojo.java
License:Apache License
private Node toNode(MavenProject project) { return toNode(project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging()); }
From source file:net.flexmojos.oss.plugin.war.CopyMojo.java
License:Open Source License
private List<Artifact> getRuntimeLocalesDependencies(MavenProject artifactProject) { String[] runtimeLocales = CompileConfigurationLoader.getCompilerPluginSettings(artifactProject, "runtimeLocales"); if (runtimeLocales == null || runtimeLocales.length == 0) { return Collections.emptyList(); }// w ww .ja v a 2s. c om List<Artifact> artifacts = new ArrayList<Artifact>(); for (String locale : runtimeLocales) { artifacts.add(repositorySystem.createArtifactWithClassifier(artifactProject.getGroupId(), artifactProject.getArtifactId(), artifactProject.getVersion(), SWF, locale)); } return artifacts; }
From source file:net.java.jpatch.maven.common.AbstractPatchMojo.java
License:Apache License
/** * Check the SCM status of the project./*from ww w . j ava 2 s . c o m*/ * * @param project the MAVEN project. * @param begin the SCM ID. * @param end the SCM ID. * * @return * * @throws MojoExecutionException if the method fails. */ private boolean checkSCM(MavenProject project, String revision, File diffDirectory) throws MojoExecutionException { getLog().info("Check SCM for the project " + project.getId()); boolean result = false; boolean ignoreUnknown = true; DiffScmResult scmResult = null; try { ScmRepository repository = scmManager.makeScmRepository(project.getScm().getConnection()); scmResult = scmManager.diff(repository, new ScmFileSet(project.getBasedir()), new ScmRevision(revision), null); } catch (Exception e) { getLog().error("Error check SCM status for project " + project.getId()); throw new MojoExecutionException("Couldn't configure SCM repository: " + e.getLocalizedMessage(), e); } if (scmResult != null && scmResult.getChangedFiles() != null) { List<ScmFile> changedFiles = scmResult.getChangedFiles(); for (ScmFile changedScmFile : changedFiles) { ScmFileStatus status = changedScmFile.getStatus(); if (!status.isStatus()) { getLog().debug("Not a diff: " + status); continue; } if (ignoreUnknown && ScmFileStatus.UNKNOWN.equals(status)) { getLog().debug("Ignoring unknown"); continue; } getLog().info(changedScmFile.getStatus().toString() + " " + changedScmFile.getPath()); result = true; } if (result) { File diffFile = new File(diffDirectory, project.getArtifactId() + project.getVersion() + ".diff"); try { getLog().info("Create new diff file: " + diffFile.getAbsolutePath()); diffFile.createNewFile(); FileUtils.fileWrite(diffFile.getAbsolutePath(), scmResult.getPatch()); } catch (IOException ex) { Logger.getLogger(AbstractPatchMojo.class.getName()).log(Level.SEVERE, null, ex); } } } getLog().info(""); return result; }
From source file:net.kozelka.contentcheck.mojo.LicenseShowMojo.java
License:Open Source License
/** * Artifact resolving and the rest of Maven repo magic taken from <a href="http://maven.apache.org/plugins/maven-project-info-reports-plugin/index.html">Maven Project Info Reports Plugin</a>. *///from w w w . j av a2 s. c o m public void execute() throws MojoExecutionException, MojoFailureException { final File src = sourceFile.exists() ? sourceFile : defaultBundleForPOMPacking; if (!src.exists()) { getLog().warn("Skipping project since there is no archive to check."); return; } final List<MavenProject> mavenProjectForDependencies = getMavenProjectForDependencies(); try { final ContentIntrospector introspector = VendorFilter.createIntrospector( new MyIntrospectionListener(getLog()), ignoreVendorArchives, vendorId, manifestVendorEntry, checkFilesPattern); final Set<ActualEntry> archiveEntries = new LinkedHashSet<ActualEntry>(); introspector.setSourceFile(src); //TODO: instead of collecting, put the dependency comparison right inside final ContentCollector collector = new ContentCollector(archiveEntries); introspector.getEvents().addListener(collector); introspector.walk(); introspector.getEvents().removeListener(collector); final Map<String, List<License>> entries = new LinkedHashMap<String, List<License>>(); final Map<String, List<License>> additionalLicenseInformation = new LinkedHashMap<String, List<License>>(); if (licenseMappingFile != null && licenseMappingFile.exists()) { //read additional license information getLog().info( String.format("Reading license mapping file %s", licenseMappingFile.getAbsolutePath())); try { additionalLicenseInformation.putAll(LicenseShow.parseLicenseMappingFile(licenseMappingFile)); } catch (JsonParseException e) { throw new MojoFailureException(String.format( "Cannot parse JSON from file %s the content of the file is not well formed JSON.", licenseMappingFile), e); } catch (JsonMappingException e) { throw new MojoFailureException( String.format("Cannot deserialize JSON from file %s", licenseMappingFile), e); } catch (IOException e) { throw new MojoFailureException(e.getMessage(), e); } } getLog().info("Comparing the archive content with Maven project artifacts"); for (ActualEntry archiveEntry : archiveEntries) { List<License> licenses = null; //these licenses will be associated with the given archive entry for (MavenProject mavenProject : mavenProjectForDependencies) { mavenProject.getGroupId(); final String artifactId = mavenProject.getArtifactId(); final String version = mavenProject.getVersion(); final String jarName = artifactId + "-" + version + ".jar"; //guess jar name if (archiveEntry.getUri().endsWith(jarName)) { @SuppressWarnings("unchecked") final List<License> _licenses = mavenProject.getLicenses(); licenses = _licenses == null || _licenses.size() == 0 ? null : _licenses; break; } } final List<License> licensesMappingFile = additionalLicenseInformation .get(FileUtils.filename(archiveEntry.getUri())); if (licenses == null && licensesMappingFile == null) {//misising license information getLog().debug(String.format( "Cannot resolve license information for archive entry %s neither from the POM file nor the file for license mapping", archiveEntry)); //archive entry must be present even if there is no a matching Maven Project entries.put(archiveEntry.getUri(), Collections.<License>emptyList()); } else if (licenses != null && licensesMappingFile != null) {//licenses specified in both - POM and license mapping file getLog().warn(String.format( "The license information for file %s are defined in the POM file and also in the file for license mapping. Using license information from the the file for license mapping.", archiveEntry)); entries.put(archiveEntry.getUri(), licensesMappingFile); //mapping manually specified licenses precedes licenses from POM } else if (licenses != null) {//license information in POM entries.put(archiveEntry.getUri(), licenses);//license } else { //license information in mapping file //put additional license information to the object that holds this information entries.put(archiveEntry.getUri(), licensesMappingFile); } } final LicenseShow.LicenseOutput logOutput = new MavenLogOutput(getLog()); logOutput.output(entries); if (csvOutput) { final LicenseShow.CsvOutput csvOutput = new LicenseShow.CsvOutput(csvOutputFile); getLog().info(String.format("Creating license output to CSV file %s", csvOutputFile.getPath())); csvOutput.output(entries); } } catch (IOException e) { throw new MojoFailureException(e.getMessage(), e); } }
From source file:net.oneandone.maven.plugins.billofmaterials.CreateBillOfMaterialsMojo.java
License:Apache License
/** * Adds the hash entry for the POM./* w w w .j a v a2s .c o m*/ * @param hashBaseNames to add the entry to. * @throws IOException when the POM could not be read. */ void addHashEntryForPom(final List<String> hashBaseNames) throws IOException { final MavenProject project = getProject(); final HashCode sha1OfPom = Files.hash(project.getFile(), sha1); final String pomLine = String.format(Locale.ENGLISH, "%s %s-%s.pom", sha1OfPom, project.getArtifactId(), project.getVersion()); hashBaseNames.add(pomLine); }
From source file:net.oneandone.maven.plugins.billofmaterials.CreateBillOfMaterialsMojo.java
License:Apache License
/** * Returns a string representation for the comment. * * @param userName current user/*from ww w .j a va2s . c o m*/ * @return string representation for the comment. */ String projectCommentToString(final String userName) { final MavenProject project = getProject(); return String.format(Locale.ENGLISH, "# %s:%s:%s user=%s\n", project.getGroupId(), project.getArtifactId(), project.getVersion(), userName); }
From source file:net.oneandone.maven.plugins.prerelease.core.Descriptor.java
License:Apache License
public static Descriptor create(String prerelease, MavenProject mavenProject, long revision) throws MissingScmTag, MissingDeveloperConnection, CannotBumpVersion, CannotDeterminTagBase { Project project;/*from www. j av a 2 s. com*/ String svnOrig; String svnTag; DeploymentRepository repo; svnOrig = getSvnUrl(mavenProject); svnTag = tagurl(svnOrig, mavenProject); project = Project.forMavenProject(mavenProject, releaseVersion(mavenProject)); repo = mavenProject.getDistributionManagement().getRepository(); return new Descriptor(prerelease, revision, svnOrig, svnTag, project, repo.getId() + "::" + repo.getUrl(), "maven-plugin".equals(mavenProject.getPackaging()), mavenProject.getVersion(), next(project.version), new HashMap<String, String>()); }