List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:net.sf.buildbox.maven.contentcheck.LicenseShowMojo.java
License:Open Source License
/** * @see net.sf.buildbox.maven.contentcheck.AbstractArchiveContentMojo#doExecute() *//*from w w w . j a va2 s .c o m*/ @Override protected void doExecute() throws IOException, MojoExecutionException, MojoFailureException { List<MavenProject> mavenProjectForDependencies = getMavenProjectForDependencies(); DefaultIntrospector introspector = new DefaultIntrospector(getLog(), isIgnoreVendorArchives(), getVendorId(), getManifestVendorEntry(), getCheckFilesPattern()); introspector.readArchive(getArchive()); Set<String> archiveEntries = new LinkedHashSet<String>(introspector.getArchiveEntries()); Map<String, List<License>> entries = new LinkedHashMap<String, List<License>>(); Map<String, List<License>> additionalLicenseInformation = new LinkedHashMap<String, List<License>>(); if (licenseMappingFile != null && licenseMappingFile.exists()) { //read additional license information LicenseMappingParser licenseMappingParser = new LicenseMappingParser(getLog(), licenseMappingFile); additionalLicenseInformation.putAll(licenseMappingParser.parseLicenseMappingFile()); } getLog().info("Comparing the archive content with Maven project artifacts"); for (String archiveEntry : archiveEntries) { List<License> licenses = null; //these licenses will be associated with the given archive entry for (MavenProject mavenProject : mavenProjectForDependencies) { mavenProject.getGroupId(); String artifactId = mavenProject.getArtifactId(); String version = mavenProject.getVersion(); String jarName = artifactId + "-" + version + ".jar"; //guess jar name if (archiveEntry.endsWith(jarName)) { @SuppressWarnings("unchecked") List<License> _licenses = mavenProject.getLicenses(); licenses = _licenses == null || _licenses.size() == 0 ? null : _licenses; break; } } List<License> licensesMappingFile = additionalLicenseInformation .get(stripJARNameFromPath(archiveEntry)); 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, 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, licensesMappingFile); //mapping manually specified licenses precedes licenses from POM } else if (licenses != null) {//license information in POM entries.put(archiveEntry, licenses);//license } else { //license information in mapping file //put additional license information to the object that holds this information entries.put(archiveEntry, licensesMappingFile); } } LicenseOutput logOutput = new LogOutput(getLog()); logOutput.output(entries); if (csvOutput) { CsvOutput csvOutput = new CsvOutput(getLog(), csvOutputFile); csvOutput.output(entries); } }
From source file:net.sourceforge.vulcan.maven.integration.MavenProjectConfiguratorImpl.java
License:Open Source License
@SuppressWarnings("unchecked") private String[] findVulcanProjectDependencies(List<String> existingProjectNames) { final Set<String> vulcanDeps = new HashSet<String>(); final List<Dependency> deps = project.getDependencies(); for (Dependency dep : deps) { if (existingProjectNames.contains(dep.getArtifactId())) { vulcanDeps.add(dep.getArtifactId()); }/*w w w .j a v a 2 s . c o m*/ } final Set<Artifact> plugins = project.getPluginArtifacts(); for (Artifact artifact : plugins) { if (existingProjectNames.contains(artifact.getArtifactId())) { vulcanDeps.add(artifact.getArtifactId()); } } MavenProject parent = project.getParent(); while (parent != null) { if (existingProjectNames.contains(parent.getArtifactId())) { vulcanDeps.add(parent.getArtifactId()); } parent = parent.getParent(); } return vulcanDeps.toArray(new String[vulcanDeps.size()]); }
From source file:net.ubos.tools.pacmanpkgmavenplugin.PacmanPkgMavenPlugin.java
License:Open Source License
/** * {@inheritDoc}// w ww . j a va2 s .c o m * * @throws MojoExecutionException */ @Override public void execute() throws MojoExecutionException { MavenProject project = (MavenProject) getPluginContext().get("project"); String packaging = project.getPackaging(); if (!"jar".equals(packaging) && !"ear".equals(packaging) && !"war".equals(packaging)) { return; } getLog().info("Generating PKGBUILD @ " + project.getName()); // pull stuff out of MavenProject String artifactId = project.getArtifactId(); String version = project.getVersion(); String url = project.getUrl(); String description = project.getDescription(); Set<Artifact> dependencies = project.getDependencyArtifacts(); File artifactFile = project.getArtifact().getFile(); if (artifactFile == null || !artifactFile.exists()) { throw new MojoExecutionException("pacmanpkg must be executed as part of a build, not standalone," + " otherwise it can't find the main JAR file"); } // translate to PKGBUILD fields String pkgname = artifactId; String pkgver = version.replaceAll("-SNAPSHOT", "a"); // alpha String pkgdesc = "A Java package available on UBOS"; if (description != null) { if (description.length() > 64) { pkgdesc = description.substring(0, 64) + "..."; } else { pkgdesc = description; } } ArrayList<String> depends = new ArrayList<>(dependencies.size()); for (Artifact a : dependencies) { if (!"test".equals(a.getScope())) { depends.add(a.getArtifactId()); } } // write to PKGBUILD try { File baseDir = project.getBasedir(); File pkgBuild = new File(baseDir, "target/PKGBUILD"); PrintWriter out = new PrintWriter(pkgBuild); getLog().debug("Writing PKGBUILD to " + pkgBuild.getAbsolutePath()); out.println("#"); out.println(" * Automatically generated by pacman-pkg-maven-plugin; do not modify."); out.println("#"); out.println(); out.println("pkgname=" + pkgname); out.println("pkgver=" + pkgver); out.println("pkgrel=" + pkgrel); out.println("pkgdesc='" + pkgdesc + "'"); out.println("arch=('any')"); out.println("url='" + url + "'"); out.println("license=('" + license + "')"); out.print("depends=("); String sep = ""; for (String d : depends) { out.print(sep); sep = ","; out.print("'"); out.print(d); out.print("'"); } out.println(")"); out.println(); out.println("package() ("); out.println(" mkdir -p ${pkgdir}/usr/share/java"); out.println(" install -m644 ${startdir}/" + artifactFile.getName() + " ${pkgdir}/usr/share/java/"); out.println(")"); out.close(); } catch (IOException ex) { throw new MojoExecutionException("Failed to write target/PKGBUILD", ex); } }
From source file:nl.mpi.tla.version.controller.VersionControlCheck.java
License:Open Source License
@Override public void execute() throws MojoExecutionException { final VcsVersionChecker versionChecker; try {/*from ww w .j a v a 2s . c o m*/ switch (VcsType.valueOf(vcsType)) { case git: versionChecker = new GitVersionChecker(new CommandRunnerImpl()); break; case svn: versionChecker = new SvnVersionChecker(new CommandRunnerImpl()); break; default: throw new MojoExecutionException("Unknown version control system: " + vcsType); } } catch (IllegalArgumentException exception) { throw new MojoExecutionException("Unknown version control system: " + vcsType + "\nValid options are: " + VcsType.git.name() + " or " + VcsType.svn.name()); } if (verbose) { logger.info("VersionControlCheck"); logger.info("project: " + project); logger.info("majorVersion: " + majorVersion); logger.info("minorVersion: " + minorVersion); logger.info("buildType: " + buildType); logger.info("outputDirectory: " + outputDirectory); logger.info("projectDirectory :" + projectDirectory); } for (MavenProject reactorProject : mavenProjects) { final String artifactId = reactorProject.getArtifactId(); final String moduleVersion = reactorProject.getVersion(); final String groupId = reactorProject.getGroupId(); logger.info("Checking version numbers for " + artifactId); if (verbose) { logger.info("artifactId: " + artifactId); logger.info("moduleVersion: " + moduleVersion); logger.info("moduleDir :" + reactorProject.getBasedir()); } // for (MavenProject dependencyProject : reactorProject.getDependencies()) { // logger.info("dependencyProject:" + dependencyProject.getArtifactId()); // } final String expectedVersion; final String buildVersionString; final File moduleDirectory = reactorProject.getBasedir(); if (allowSnapshots && moduleVersion.contains("SNAPSHOT")) { expectedVersion = majorVersion + "." + minorVersion + "-" + buildType + "-SNAPSHOT"; buildVersionString = "-1"; //"SNAPSHOT"; it will be nice to have snapshot here but we need to update some of the unit tests first } else if ((modulesWithShortVersion != null && modulesWithShortVersion.contains(artifactId)) || (moduleWithShortVersion != null && moduleWithShortVersion.equals(artifactId))) { expectedVersion = majorVersion + "." + minorVersion; buildVersionString = "-1"; } else { logger.info("getting build number"); int buildVersion = versionChecker.getBuildNumber(verbose, moduleDirectory, "."); logger.info(artifactId + ".buildVersion: " + Integer.toString(buildVersion)); expectedVersion = majorVersion + "." + minorVersion + "." + buildVersion + "-" + buildType; buildVersionString = Integer.toString(buildVersion); } if (!expectedVersion.equals(moduleVersion)) { logger.error("Expecting version number: " + expectedVersion); logger.error("But found: " + moduleVersion); logger.error("Artifact: " + artifactId); throw new MojoExecutionException("The build numbers to not match for '" + artifactId + "': '" + expectedVersion + "' vs '" + moduleVersion + "'"); } // get the last commit date logger.info("getting lastCommitDate"); final String lastCommitDate = versionChecker.getLastCommitDate(verbose, moduleDirectory, "."); logger.info(".lastCommitDate:" + lastCommitDate); // construct the compile date DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); Date date = new Date(); final String buildDate = dateFormat.format(date); // setting the maven properties final String versionPropertyName = groupId + "." + artifactId + ".moduleVersion"; logger.info("Setting property '" + versionPropertyName + "' to '" + expectedVersion + "'"); reactorProject.getProperties().setProperty(versionPropertyName, expectedVersion); reactorProject.getProperties().setProperty(propertiesPrefix + ".majorVersion", majorVersion); reactorProject.getProperties().setProperty(propertiesPrefix + ".minorVersion", minorVersion); reactorProject.getProperties().setProperty(propertiesPrefix + ".buildVersion", buildVersionString); reactorProject.getProperties().setProperty(propertiesPrefix + ".lastCommitDate", lastCommitDate); reactorProject.getProperties().setProperty(propertiesPrefix + ".buildDate", buildDate); } }
From source file:npanday.PathUtil.java
License:Apache License
public static File getPreparedPackageFolder(MavenProject project) { String folderName = project.getArtifactId(); return new File(new File(project.getBuild().getDirectory(), "packages"), folderName); }
From source file:NPanday.Plugin.Msbuild.MsbuildMojo.java
License:Apache License
private void copyDependencies(Collection<Artifact> requiredArtifacts) throws MojoExecutionException { Map<String, MavenProject> projects = new HashMap<String, MavenProject>(); for (MavenProject p : reactorProjects) { projects.put(ArtifactUtils.versionlessKey(p.getGroupId(), p.getArtifactId()), p); }/*from ww w . j ava 2 s. c o m*/ getLog().info("projects = " + projects.keySet()); for (Object artifact : requiredArtifacts) { Artifact a = (Artifact) artifact; File targetDir; String vKey = ArtifactUtils.versionlessKey(a); if (!projects.containsKey(vKey)) { String path = a.getGroupId() + "/" + a.getArtifactId() + "-" + a.getBaseVersion(); targetDir = new File(referencesDirectory, path); } else { // Likely a project reference in MSBuild. // If the other project was not built with MSBuild, make sure the artifact is present where it will look for it // Note: deliberately limited for now - will only work with reactor projects and doesn't test what are references and what are not File binDir = new File(projects.get(vKey).getBasedir(), "bin"); targetDir = new File(binDir, configuration); } File targetFile = new File(targetDir, a.getArtifactId() + "." + a.getArtifactHandler().getExtension()); getLog().info("Copying reference " + vKey + " to " + targetFile); if (!targetFile.exists()) { targetFile.getParentFile().mkdirs(); try { FileUtils.copyFile(a.getFile(), targetFile); } catch (IOException e) { throw new MojoExecutionException( "Error copying reference from the local repository to .references: " + e.getMessage(), e); } } } }
From source file:npanday.plugin.msdeploy.create.Package.java
License:Apache License
public Package(MavenProject project) { this.classifier = null; this.packageSource = PathUtil.getPreparedPackageFolder(project); this.packageFile = new File(project.getBuild().getDirectory(), project.getArtifactId() + "." + ArtifactType.MSDEPLOY_PACKAGE.getExtension()); }
From source file:npanday.plugin.resolver.CopyDependenciesMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { String skipReason = ""; if (!skip) {//from w ww .ja v a 2 s . co m ArtifactType knownType = ArtifactType.getArtifactTypeForPackagingName(project.getPackaging()); if (knownType.equals(ArtifactType.NULL)) { skip = true; skipReason = ", because the current project (type:" + project.getPackaging() + ") is not built with NPanday"; } } if (skip) { getLog().info("NPANDAY-158-001: Mojo for copying dependencies was intentionally skipped" + skipReason); return; } SettingsUtil.applyCustomSettings(getLog(), repositoryRegistry, settingsPath); AndArtifactFilter includeFilter = new AndArtifactFilter(); OrArtifactFilter typeIncludes = new OrArtifactFilter(); typeIncludes.add(new DotnetExecutableArtifactFilter()); typeIncludes.add(new DotnetLibraryArtifactFilter()); if (includePdbs) { typeIncludes.add(new DotnetSymbolsArtifactFilter()); } includeFilter.add(typeIncludes); if (!Strings.isNullOrEmpty(includeScope)) { includeFilter.add(new ScopeArtifactFilter(includeScope)); } Set<Artifact> artifacts; try { artifacts = dependencyResolution.require(project, LocalRepositoryUtil.create(localRepository), includeFilter); } catch (ArtifactResolutionException e) { throw new MojoExecutionException( "NPANDAY-158-003: dependency resolution for scope " + includeScope + " failed!", e); } /** * Should be resolved, but then not copied */ if (!Strings.isNullOrEmpty(excludeScope)) { includeFilter.add(new InversionArtifactFilter(new ScopeArtifactFilter(excludeScope))); } if (skipReactorArtifacts) { getLog().info("NPANDAY-158-008: " + reactorProjects); includeFilter.add(new InversionArtifactFilter(new ArtifactFilter() { public boolean include(Artifact artifact) { for (MavenProject project : reactorProjects) { // we don't care about the type and the classifier here if (project.getGroupId().equals(artifact.getGroupId()) && project.getArtifactId().equals(artifact.getArtifactId()) && project.getVersion().equals(artifact.getVersion())) { return true; } } return false; } })); } for (Artifact dependency : artifacts) { if (!includeFilter.include(dependency)) { getLog().debug("NPANDAY-158-006: dependency " + dependency + " was excluded"); continue; } try { File targetFile = new File(outputDirectory, PathUtil.getPlainArtifactFileName(dependency)); if (!targetFile.exists() || targetFile.lastModified() != dependency.getFile().lastModified() || targetFile.length() != dependency.getFile().length()) { getLog().info("NPANDAY-158-004: copy " + dependency.getFile() + " to " + targetFile); FileUtils.copyFile(dependency.getFile(), targetFile); } else { getLog().debug("NPANDAY-158-007: dependency " + dependency + " is yet up to date"); } } catch (IOException ioe) { throw new MojoExecutionException("NPANDAY-158-005: Error copying dependency " + dependency, ioe); } } }
From source file:npanday.plugin.resolver.ListDependenciesMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { String skipReason = ""; if (skip) {//from w w w . j a va 2 s . c o m getLog().info("NPANDAY-161-001: Mojo for listing dependencies was intentionally skipped" + skipReason); return; } SettingsUtil.applyCustomSettings(getLog(), repositoryRegistry, settingsPath); AndArtifactFilter includeFilter = new AndArtifactFilter(); if (!Strings.isNullOrEmpty(includeScope)) { includeFilter.add(new ScopeArtifactFilter(includeScope)); } Set<Artifact> artifacts; try { // TODO: Workarround. Somehow in the first run, PDBs wont be part of the result! dependencyResolution.require(project, LocalRepositoryUtil.create(localRepository), includeFilter); artifacts = dependencyResolution.require(project, LocalRepositoryUtil.create(localRepository), includeFilter); } catch (ArtifactResolutionException e) { throw new MojoExecutionException( "NPANDAY-161-003: dependency resolution for scope " + includeScope + " failed!", e); } /** * Should be resolved, but then not shown */ if (!Strings.isNullOrEmpty(excludeScope)) { includeFilter.add(new InversionArtifactFilter(new ScopeArtifactFilter(excludeScope))); } if (skipReactorArtifacts) { getLog().info("NPANDAY-161-008: " + reactorProjects); includeFilter.add(new InversionArtifactFilter(new ArtifactFilter() { public boolean include(Artifact artifact) { for (MavenProject project : reactorProjects) { // we don't care about the type and the classifier here if (project.getGroupId().equals(artifact.getGroupId()) && project.getArtifactId().equals(artifact.getArtifactId()) && project.getVersion().equals(artifact.getVersion())) { return true; } } return false; } })); } getLog().info("The following files have been resolved:"); for (Artifact dependency : artifacts) { if (!includeFilter.include(dependency)) { getLog().debug("NPANDAY-161-006: dependency " + dependency + " was excluded"); continue; } getLog().info(" " + dependency.getId() + ":" + dependency.getScope() + " -> " + dependency.getFile()); } }
From source file:org.ajax4jsf.builder.mojo.AssemblyAttachedLibraryMojo.java
License:Open Source License
public void execute() throws MojoExecutionException, MojoFailureException { if (null != reactorProjects) { getLog().info("Reactor projects"); for (Iterator iterator = reactorProjects.iterator(); iterator.hasNext();) { MavenProject reactor = (MavenProject) iterator.next(); getLog().info("Project " + reactor.getGroupId() + ":" + reactor.getArtifactId()); }/*ww w. ja v a 2s . co m*/ } // assemblyProjects(); }