List of usage examples for org.apache.maven.project MavenProject getPackaging
public String getPackaging()
From source file:org.codehaus.mojo.pom.DependencyPatternMatcher.java
License:Apache License
/** * @param project/*from w w w .ja va 2s .co m*/ */ public DependencyPatternMatcher(MavenProject project) { this(project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging(), null, null); }
From source file:org.codehaus.mojo.pom.ProjectId.java
License:Apache License
/** * @see #equals(Object)/*from www. j a v a 2s .c o m*/ */ public final boolean isMatching(MavenProject dependency) { return isMatching(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getPackaging(), null, null); }
From source file:org.codehaus.mojo.versions.DisplayPluginUpdatesMojo.java
License:Apache License
/** * Gets the plugins that are bound to the defined phases. This does not find plugins bound in the pom to a phase * later than the plugin is executing./*from w w w.j a v a2 s. c o m*/ * * @param project the project * @param thePhases the the phases * @return the bound plugins * @throws org.apache.maven.plugin.PluginNotFoundException * the plugin not found exception * @throws LifecycleExecutionException the lifecycle execution exception * @throws IllegalAccessException the illegal access exception */ // pilfered this from enforcer-rules // TODO coordinate with Brian Fox to remove the duplicate code private Set<Plugin> getBoundPlugins(MavenProject project, String thePhases) throws PluginNotFoundException, LifecycleExecutionException, IllegalAccessException { if (new DefaultArtifactVersion("3.0").compareTo(runtimeInformation.getApplicationVersion()) <= 0) { getLog().debug("Using Maven 3.0+ strategy to determine lifecycle defined plugins"); try { Method getPluginsBoundByDefaultToAllLifecycles = LifecycleExecutor.class .getMethod("getPluginsBoundByDefaultToAllLifecycles", new Class[] { String.class }); Set<Plugin> plugins = (Set<Plugin>) getPluginsBoundByDefaultToAllLifecycles.invoke( lifecycleExecutor, new Object[] { project.getPackaging() == null ? "jar" : project.getPackaging() }); // we need to provide a copy with the version blanked out so that inferring from super-pom // works as for 2.x as 3.x fills in the version on us! Set<Plugin> result = new LinkedHashSet<Plugin>(plugins.size()); for (Plugin plugin : plugins) { Plugin dup = new Plugin(); dup.setGroupId(plugin.getGroupId()); dup.setArtifactId(plugin.getArtifactId()); result.add(dup); } return result; } catch (NoSuchMethodException e1) { // no much we can do here } catch (InvocationTargetException e1) { // no much we can do here } catch (IllegalAccessException e1) { // no much we can do here } } List lifecycles = null; getLog().debug("Using Maven 2.0.10+ strategy to determine lifecycle defined plugins"); try { Method getLifecycles = LifecycleExecutor.class.getMethod("getLifecycles", new Class[0]); lifecycles = (List) getLifecycles.invoke(lifecycleExecutor, new Object[0]); } catch (NoSuchMethodException e1) { // no much we can do here } catch (InvocationTargetException e1) { // no much we can do here } catch (IllegalAccessException e1) { // no much we can do here } Set<Plugin> allPlugins = new HashSet<Plugin>(); // lookup the bindings for all the passed in phases for (String lifecyclePhase : thePhases.split(",")) { if (StringUtils.isNotEmpty(lifecyclePhase)) { try { Lifecycle lifecycle = getLifecycleForPhase(lifecycles, lifecyclePhase); allPlugins.addAll(getAllPlugins(project, lifecycle)); } catch (BuildFailureException e) { // i'm going to swallow this because the // user may have declared a phase that // doesn't exist for every module. } } } return allPlugins; }
From source file:org.codehaus.mojo.versions.DisplayPluginUpdatesMojo.java
License:Apache License
/** * Find mappings for lifecycle.//from w w w . ja v a2 s . c om * * @param project the project * @param lifecycle the lifecycle * @return the map * @throws LifecycleExecutionException the lifecycle execution exception * @throws PluginNotFoundException the plugin not found exception */ private Map findMappingsForLifecycle(MavenProject project, Lifecycle lifecycle) throws LifecycleExecutionException, PluginNotFoundException { String packaging = project.getPackaging(); Map mappings = null; LifecycleMapping m = (LifecycleMapping) findExtension(project, LifecycleMapping.ROLE, packaging, session.getSettings(), session.getLocalRepository()); if (m != null) { mappings = m.getPhases(lifecycle.getId()); } Map defaultMappings = lifecycle.getDefaultPhases(); if (mappings == null) { try { m = (LifecycleMapping) session.lookup(LifecycleMapping.ROLE, packaging); mappings = m.getPhases(lifecycle.getId()); } catch (ComponentLookupException e) { if (defaultMappings == null) { throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging + "\'.", e); } } } if (mappings == null) { if (defaultMappings == null) { throw new LifecycleExecutionException("Cannot find lifecycle mapping for packaging: \'" + packaging + "\', and there is no default"); } else { mappings = defaultMappings; } } return mappings; }
From source file:org.codehaus.mojo.versions.DisplayPluginUpdatesMojo.java
License:Apache License
/** * Find optional mojos for lifecycle.//from w w w .j ava2 s . co m * * @param project the project * @param lifecycle the lifecycle * @return the list * @throws LifecycleExecutionException the lifecycle execution exception * @throws PluginNotFoundException the plugin not found exception */ private List<String> findOptionalMojosForLifecycle(MavenProject project, Lifecycle lifecycle) throws LifecycleExecutionException, PluginNotFoundException { String packaging = project.getPackaging(); List<String> optionalMojos = null; LifecycleMapping m = (LifecycleMapping) findExtension(project, LifecycleMapping.ROLE, packaging, session.getSettings(), session.getLocalRepository()); if (m != null) { optionalMojos = m.getOptionalMojos(lifecycle.getId()); } if (optionalMojos == null) { try { m = (LifecycleMapping) session.lookup(LifecycleMapping.ROLE, packaging); optionalMojos = m.getOptionalMojos(lifecycle.getId()); } catch (ComponentLookupException e) { getLog().debug("Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " + lifecycle.getId() + ". Error: " + e.getMessage(), e); } } if (optionalMojos == null) { optionalMojos = Collections.emptyList(); } return optionalMojos; }
From source file:org.codehaus.tycho.source.AbstractSourceJarMojo.java
License:Apache License
/** * @param p//from w ww. jav a2s . co m * @return true to package the sources of the given project. false to skip. * @throws MojoExecutionException */ protected boolean doPackageSources(MavenProject p) throws MojoExecutionException { return !"pom".equals(p.getPackaging()); }
From source file:org.debian.maven.packager.GenerateDebianFilesMojo.java
License:Apache License
public void execute() throws MojoExecutionException { File f = outputDirectory;/* www .jav a2s . c o m*/ if (!f.exists()) { f.mkdirs(); } String controlTemplate = "control.vm"; String rulesTemplate = "rules.vm"; if ("cdbs".equals(helper)) { rulesTemplate = "rules.cdbs.vm"; } if ("ant".equals(packageType)) { controlTemplate = "control.ant.vm"; rulesTemplate = "rules.ant.vm"; } // #638788: clean up email if (email != null && email.indexOf('<') >= 0 && email.indexOf('>') >= 0) { email = email.substring(email.indexOf('<') + 1, email.indexOf('>') - 1); } try { Properties velocityProperties = new Properties(); velocityProperties.put("resource.loader", "class"); velocityProperties.put("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); Velocity.init(velocityProperties); VelocityContext context = new VelocityContext(); context.put("package", packageName); context.put("packageType", packageType); context.put("binPackage", binPackageName); context.put("helper", helper); context.put("packager", packager); context.put("packagerEmail", email); context.put("project", project); context.put("collectedProjects", wrapMavenProjects(collectedProjects)); context.put("runTests", Boolean.valueOf(runTests)); context.put("generateJavadoc", Boolean.valueOf(generateJavadoc)); if (project.getName() == null || project.getName().isEmpty()) { project.setName(new SimpleQuestion( "POM does not contain the project name. Please enter the name of the project:").ask()); } if (project.getUrl() == null || project.getUrl().isEmpty()) { project.setUrl(new SimpleQuestion( "POM does not contain the project URL. Please enter the URL of the project:").ask()); } Set<String> licenses = licensesScanner.discoverLicenses(project.getLicenses()); context.put("licenses", licenses); if (licenses.size() == 1) { packagerLicense = licenses.iterator().next(); } if (packagerLicense == null) { String q = "Packager license for the debian/ files was not found, please enter a license name preferably in one of:\n" + "Apache Artistic BSD FreeBSD ISC CC-BY CC-BY-SA CC-BY-ND CC-BY-NC CC-BY-NC-SA CC-BY-NC-ND CC0 CDDL CPL Eiffel" + "Expat GPL LGPL GFDL GFDL-NIV LPPL MPL Perl PSF QPL W3C-Software ZLIB Zope"; String s = new SimpleQuestion(q).ask(); if (s.length() > 0) { packagerLicense = s; } } context.put("packagerLicense", packagerLicense); String copyrightOwner = ""; String projectTeam = ""; if (project.getOrganization() != null) { copyrightOwner = project.getOrganization().getName(); projectTeam = project.getOrganization().getName() + " developers"; } if (copyrightOwner == null || copyrightOwner.isEmpty()) { Iterator<Developer> devs = project.getDevelopers().iterator(); if (devs.hasNext()) { Developer dev = devs.next(); copyrightOwner = dev.getName(); if (dev.getEmail() != null && !dev.getEmail().isEmpty()) { copyrightOwner += " <" + dev.getEmail() + ">"; } } } if (copyrightOwner == null || copyrightOwner.isEmpty()) { copyrightOwner = new SimpleQuestion( "Could not find who owns the copyright for the upstream sources, please enter his name:") .ask(); } context.put("copyrightOwner", copyrightOwner); if (projectTeam == null || projectTeam.isEmpty()) { projectTeam = project.getName() + " developers"; } context.put("projectTeam", projectTeam); String copyrightYear; int currentYear = new GregorianCalendar().get(Calendar.YEAR); if (project.getInceptionYear() != null) { copyrightYear = project.getInceptionYear(); if (Integer.parseInt(copyrightYear) < currentYear) { copyrightYear += "-" + currentYear; } } else { copyrightYear = String.valueOf(currentYear); } context.put("copyrightYear", copyrightYear); context.put("currentYear", new Integer(currentYear)); if (project.getDescription() == null || project.getDescription().trim().isEmpty()) { project.setDescription(new MultilineQuestion( "Please enter a short description of the project, press Enter twice to stop.").ask()); } context.put("description", formatDescription(project.getDescription())); File substvarsFile = new File(outputDirectory, binPackageName + ".substvars"); if (substvarsFile.exists()) { Properties substvars = new Properties(); substvars.load(new FileReader(substvarsFile)); List<String> compileDepends = new ArrayList<String>(); compileDepends.addAll(split(substvars.getProperty("maven.CompileDepends"))); compileDepends.addAll(split(substvars.getProperty("maven.Depends"))); List<String> buildDepends = new ArrayList<String>(compileDepends); List<String> testDepends = new ArrayList<String>(split(substvars.getProperty("maven.TestDepends"))); if (runTests) { buildDepends.addAll(testDepends); } if (generateJavadoc) { buildDepends.addAll(split(substvars.getProperty("maven.DocDepends"))); buildDepends.addAll(split(substvars.getProperty("maven.DocOptionalDepends"))); } if ("maven".equals(packageType)) { boolean seenJavadocPlugin = false; // Remove dependencies that are implied by maven-debian-helper for (Iterator<String> i = buildDepends.iterator(); i.hasNext();) { String dependency = i.next(); if (dependency.startsWith("libmaven-clean-plugin-java") || dependency.startsWith("libmaven-resources-plugin-java") || dependency.startsWith("libmaven-compiler-plugin-java") || dependency.startsWith("libmaven-jar-plugin-java") || dependency.startsWith("libmaven-site-plugin-java") || dependency.startsWith("libsurefire-java") || dependency.startsWith("velocity") || dependency.startsWith("libplexus-velocity-java")) { i.remove(); } else if (dependency.startsWith("libmaven-javadoc-plugin-java")) { seenJavadocPlugin = true; } } if (generateJavadoc && !seenJavadocPlugin) { buildDepends.add("libmaven-javadoc-plugin-java"); } } else if ("ant".equals(packageType)) { // Remove dependencies that are implied by ant packaging for (Iterator<String> i = buildDepends.iterator(); i.hasNext();) { String dependency = i.next(); if (dependency.equals("ant") || dependency.startsWith("ant ") || dependency.startsWith("ant-optional")) { i.remove(); } } buildDepends.remove("ant"); buildDepends.remove("ant-optional"); } context.put("buildDependencies", buildDepends); context.put("runtimeDependencies", split(substvars.getProperty("maven.Depends"))); context.put("testDependencies", split(substvars.getProperty("maven.TestDepends"))); context.put("optionalDependencies", split(substvars.getProperty("maven.OptionalDepends"))); context.put("javadocDependencies", split(substvars.getProperty("maven.DocDepends"))); context.put("javadocOptionalDependencies", split(substvars.getProperty("maven.DocOptionalDepends"))); if ("ant".equals(packageType)) { Set<String> compileJars = new TreeSet<String>(); for (String library : compileDepends) { compileJars.addAll(scanner.listSharedJars(library)); } context.put("compileJars", compileJars); Set<String> testJars = new TreeSet<String>(); for (String library : testDepends) { testJars.addAll(scanner.listSharedJars(library)); } context.put("testJars", testJars); } } else { System.err.println("Cannot find file " + substvarsFile); } if ("ant".equals(packageType)) { ListOfPOMs listOfPOMs = new ListOfPOMs(new File(outputDirectory, binPackageName + ".poms")); ListOfPOMs listOfJavadocPOMs = null; if (generateJavadoc && "ant".equals(packageType)) { listOfJavadocPOMs = new ListOfPOMs(new File(outputDirectory, binPackageName + "-doc.poms")); } setupArtifactLocation(listOfPOMs, listOfJavadocPOMs, project); for (MavenProject mavenProject : collectedProjects) { setupArtifactLocation(listOfPOMs, listOfJavadocPOMs, mavenProject); } listOfPOMs.save(); if (listOfJavadocPOMs != null) { listOfJavadocPOMs.save(); } } String projectVersion = project.getVersion(); int downloadType = DownloadType.UNKNOWN; if (downloadUrl == null) { if (project.getScm() != null) { downloadUrl = project.getScm().getConnection(); } } if (downloadUrl != null && downloadUrl.startsWith("scm:svn:")) { downloadType = DownloadType.SVN; downloadUrl = downloadUrl.substring("scm:svn:".length()); String tag = projectVersion; int tagPos = downloadUrl.indexOf(tag); String baseUrl = null; String suffixUrl = null; String tagMarker = null; if (tagPos >= 0) { baseUrl = downloadUrl.substring(0, tagPos); suffixUrl = downloadUrl.substring(tagPos + tag.length()); if (!suffixUrl.endsWith("/")) { suffixUrl += "/"; } int slashPos = baseUrl.lastIndexOf("/"); tagMarker = baseUrl.substring(slashPos + 1); baseUrl = baseUrl.substring(0, slashPos); } if (tagPos < 0 && downloadUrl.contains("/trunk")) { System.out.println("Download URL does not include a tagged revision but /trunk found,"); System.out.println("Trying to guess the address of the tagged revision."); tag = "trunk"; tagPos = downloadUrl.indexOf(tag); baseUrl = downloadUrl.substring(0, tagPos); baseUrl += "tags"; tagMarker = packageName + "-"; suffixUrl = ""; } if (tagPos >= 0) { context.put("baseUrl", baseUrl); context.put("tagMarker", tagMarker); context.put("suffixUrl", suffixUrl); generateFile(context, "watch.svn.vm", outputDirectory, "watch"); generateFile(context, "orig-tar.svn.vm", outputDirectory, "orig-tar.sh"); new File("debian/orig-tar.sh").setExecutable(true); } else { System.err.println("Cannot locate the version in the download url (" + downloadUrl + ")."); System.err.println( "Please run again and provide the download location with an explicit version tag, e.g."); System.err.println( "-DdownloadUrl=scm:svn:http://svn.codehaus.org/modello/tags/modello-1.0-alpha-21/"); } } if (downloadUrl != null && downloadUrl.startsWith("scm:git:") && downloadUrl.contains("github")) { Pattern pattern = Pattern.compile("github\\.com/([^/]+)/([^/\\.]+)"); Matcher matcher = pattern.matcher(downloadUrl); if (matcher.find()) { downloadType = DownloadType.GITHUB; downloadUrl = downloadUrl.substring("scm:git:".length()); context.put("userId", matcher.group(1)); context.put("repository", matcher.group(2)); generateFile(context, "watch.github.vm", outputDirectory, "watch"); } } if (downloadType == DownloadType.UNKNOWN) { System.err.println("Cannot recognize the download url (" + downloadUrl + ")."); } generateFile(context, "README.source.vm", outputDirectory, "README.source"); generateFile(context, "copyright.vm", outputDirectory, "copyright"); generateFile(context, "compat.vm", outputDirectory, "compat"); generateFile(context, rulesTemplate, outputDirectory, "rules"); new File("debian/rules").setExecutable(true); String debianVersion = projectVersion.replace("-alpha-", "~alpha"); debianVersion = debianVersion.replace("-beta-", "~beta"); debianVersion = debianVersion.replace("-rc-", "~rc"); debianVersion += "-1"; context.put("version.vm", debianVersion); generateFile(context, rulesTemplate, new File("."), ".debianVersion"); if (generateJavadoc) { if (project.getPackaging().equals("pom") && collectedProjects.size() > 1) { generateFile(context, "java-doc.doc-base.api.multi.vm", outputDirectory, binPackageName + "-doc.doc-base.api"); generateFile(context, "java-doc.install.multi.vm", outputDirectory, binPackageName + "-doc.install"); } else { generateFile(context, "java-doc.doc-base.api.vm", outputDirectory, binPackageName + "-doc.doc-base.api"); generateFile(context, "java-doc.install.vm", outputDirectory, binPackageName + "-doc.install"); } } if ("ant".equals(packageType)) { boolean containsJars = false; boolean containsPlugins = false; if (project.getPackaging().equals("pom") && project.getModules().size() > 0) { for (MavenProject module : collectedProjects) { if (module.getPackaging().equals("maven-plugin")) { containsPlugins = true; } else if (!module.getPackaging().equals("pom")) { containsJars = true; } } } else if (!project.getPackaging().equals("pom")) { if (project.getPackaging().equals("maven-plugin")) { containsPlugins = true; } else if (!project.getPackaging().equals("pom")) { containsJars = true; } } context.put("containsJars", Boolean.valueOf(containsJars)); context.put("containsPlugins", Boolean.valueOf(containsPlugins)); if (project.getPackaging().equals("pom") && project.getModules().size() > 0) { generateFile(context, "build.xml.vm", outputDirectory, "build.xml"); } generateFile(context, "build.properties.ant.vm", outputDirectory, "build.properties"); generateFile(context, "build-classpath.vm", outputDirectory, "build-classpath"); } else { generateFile(context, "maven.properties.vm", outputDirectory, "maven.properties"); } generateFile(context, controlTemplate, outputDirectory, "control"); generateFile(context, "format.vm", new File(outputDirectory, "source"), "format"); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.debian.maven.packager.GenerateDebianFilesMojo.java
License:Apache License
private void setupArtifactLocation(ListOfPOMs listOfPOMs, ListOfPOMs listOfJavadocPOMs, MavenProject mavenProject) { String dirRelPath = new WrappedProject(project, mavenProject).getBaseDir(); if (!"pom".equals(mavenProject.getPackaging())) { String pomFile = dirRelPath + "pom.xml"; listOfPOMs.getOrCreatePOMOptions(pomFile).setJavaLib(true); String extension = mavenProject.getPackaging(); if (extension.equals("bundle")) { extension = "jar"; }/*from w w w. java 2s . c om*/ if (extension.equals("webapp")) { extension = "war"; } if (mavenProject.getArtifact() != null && mavenProject.getArtifact().getFile() != null) { extension = mavenProject.getArtifact().getFile().toString(); extension = extension.substring(extension.lastIndexOf('.') + 1); } POMOptions pomOptions = listOfPOMs.getOrCreatePOMOptions(pomFile); pomOptions.setArtifact(dirRelPath + "target/" + mavenProject.getArtifactId() + "-*." + extension); if ("jar".equals(extension) && generateJavadoc && "ant".equals(packageType) && listOfJavadocPOMs != null) { String artifactId = mavenProject.getArtifact().getArtifactId(); POMOptions javadocPomOptions = listOfJavadocPOMs.getOrCreatePOMOptions(pomFile); javadocPomOptions.setIgnorePOM(true); javadocPomOptions.setArtifact(dirRelPath + "target/" + artifactId + ".javadoc.jar"); javadocPomOptions.setClassifier("javadoc"); javadocPomOptions.setHasPackageVersion(pomOptions.getHasPackageVersion()); } pomOptions.setJavaLib(true); if (mavenProject.getArtifactId().matches(packageName + "\\d")) { pomOptions.setUsjName(packageName); } } }
From source file:org.deegree.maven.EclipseWorkingSetMojo.java
License:Open Source License
private Map<String, String> findModules() { List<MavenProject> modules = project.getCollectedProjects(); List<String> modList = new ArrayList<String>(); for (MavenProject p : modules) { if (p.getPackaging().equals("pom")) { continue; }//from www.ja v a2 s . com modList.add(p.getArtifactId()); } Collections.sort(modList); List<String> workingsets = new ArrayList<String>(); Map<String, String> moduleToWorkingSet = new HashMap<String, String>(); for (String mod : modList) { int idx1 = mod.indexOf("-"); if (idx1 == -1) { continue; } int idx2 = mod.indexOf("-", idx1 + 1); if (idx2 != -1) { String ws = mod.substring(idx1 + 1, idx2); if (!workingsets.contains(ws)) { workingsets.add(ws); } moduleToWorkingSet.put(mod, ws); } } return moduleToWorkingSet; }
From source file:org.deegree.maven.ModuleListRenderer.java
License:Open Source License
@Override protected void renderBody() { List<MavenProject> modules = project.getCollectedProjects(); SortedMap<String, String> byModuleName = new TreeMap<String, String>(); HashSet<String> status = new HashSet<String>(); for (MavenProject p : modules) { if (p.getPackaging().equals("pom")) { continue; }//from www.ja v a 2 s. com String st = getModuleStatus(p); status.add(st); byModuleName.put(p.getArtifactId(), st); } generateReport(byModuleName, status); }