List of usage examples for org.apache.maven.project MavenProject getGroupId
public String getGroupId()
From source file:org.wso2.maven.MavenReleasePrePrepareMojo.java
License:Open Source License
/** * set Registry artifact version in artifact.xml file * /*from w w w . j a v a 2s. c o m*/ * @param prop * properties in release.properties file * @param repoType * type of the repository * @param artifactXml * @throws FactoryConfigurationError * @throws Exception */ private void setRegArtifactVersion(Properties prop, String repoType, File artifactXml) throws FactoryConfigurationError, Exception { File pomFile = new File(artifactXml.getParent() + File.separator + POM_XML); MavenProject mavenProject = getMavenProject(pomFile); String releaseVersion = prop.getProperty( PROJECT + repoType + "." + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId()); GeneralProjectArtifact projectArtifact = new GeneralProjectArtifact(); projectArtifact.fromFile(artifactXml); for (RegistryArtifact artifact : projectArtifact.getAllESBArtifacts()) { if (artifact.getVersion() != null && artifact.getType() != null) { if (releaseVersion != null) { artifact.setVersion(releaseVersion); } } } projectArtifact.toFile(); }
From source file:org.wso2.maven.MavenReleasePrePrepareMojo.java
License:Open Source License
/** * set ESB artifact version in artifact.xml file * // ww w. j a v a 2s . co m * @param prop * properties in release.properties file * @param repoType * type of the repository * @param artifactXml * @throws FactoryConfigurationError * @throws Exception */ private void setESBArtifactVersion(Properties prop, String repoType, File artifactXml) throws FactoryConfigurationError, Exception { File pomFile = new File(artifactXml.getParent() + File.separator + POM_XML); MavenProject mavenProject = getMavenProject(pomFile); String releaseVersion = prop.getProperty( PROJECT + repoType + "." + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId()); ESBProjectArtifact projectArtifact = new ESBProjectArtifact(); projectArtifact.fromFile(artifactXml); for (ESBArtifact artifact : projectArtifact.getAllESBArtifacts()) { if (artifact.getVersion() != null && artifact.getType() != null) { if (releaseVersion != null) { artifact.setVersion(releaseVersion); } } } projectArtifact.toFile(); }
From source file:org.wso2.maven.pckg.prepare.PackagePrepareDefaultScopeMojo.java
License:Open Source License
private void filterAllCappProjects(List<MavenProject> mavenProjects) { cappMavenProjects = new ArrayList<>(); for (MavenProject mavenProject : mavenProjects) { String packaging = mavenProject.getPackaging(); if (packaging != null && packaging.equals(MavenConstants.CAPP_PACKAGING)) { if (isDebugEnabled) { log.debug("Identified the composite application project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":" + mavenProject.getVersion()); }//from w w w. j a v a2s.c om cappMavenProjects.add(mavenProject); } } }
From source file:org.wso2.maven.pckg.prepare.PackagePrepareSystemScopeMojo.java
License:Open Source License
private void aggregateDependencies(List<MavenProject> mavenProjects) { dependencySystemPathMap = new HashMap<>(); for (MavenProject mavenProject : mavenProjects) { String packaging = mavenProject.getPackaging(); // CAPP projects are ignored. if (packaging == null || !MavenConstants.CAPP_PACKAGING.equals(packaging)) { try { dependencySystemPathMap.putAll(PackagePrepareUtils.getArtifactsSystemPathMap(mavenProject)); } catch (FactoryConfigurationError | Exception e) { // Can proceed even if this is reached log.warn("Failed to retrieve dependencies from project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":" + mavenProject.getVersion(), e); }/* ww w . ja v a2 s . co m*/ } } if (isDebugEnabled) { Iterator<Entry<String, String>> dependencyIterator = dependencySystemPathMap.entrySet().iterator(); while (dependencyIterator.hasNext()) { log.debug("Identified system path of: " + dependencyIterator.next().getKey()); } } }
From source file:org.wso2.maven.pckg.prepare.util.PackagePrepareUtils.java
License:Open Source License
private static String getDependencyString(MavenProject project, ESBArtifact artifact) { String groupId;//from w w w . j a v a 2s . c o m if (StringUtils.isNotEmpty(artifact.getGroupId())) { groupId = artifact.getGroupId(); } else { groupId = project.getGroupId(); } String artifactId = artifact.getName(); String version = artifact.getVersion(); StringBuilder dependencyStringBuilder = new StringBuilder(); dependencyStringBuilder.append(groupId); dependencyStringBuilder.append(":"); dependencyStringBuilder.append(artifactId); dependencyStringBuilder.append(":"); dependencyStringBuilder.append(version); return dependencyStringBuilder.toString(); }
From source file:org.wso2.maven.PrepareReleasedArtifactsMojo.java
License:Open Source License
@Override protected String getNewVersion(File artifactXml) throws IOException, XmlPullParserException { File pomFile = new File(artifactXml.getParent() + File.separator + POM_XML); MavenProject mavenProject = getMavenProject(pomFile); String newVersion = releaseProperties.getProperty( PROJECT_PREFIX + REL + "." + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId()); return newVersion; }
From source file:org.wso2.maven.PrepareSnapshotArtifactsMojo.java
License:Open Source License
@Override protected String getNewVersion(File artifactXml) throws IOException, XmlPullParserException { File pomFile = new File(artifactXml.getParent() + File.separator + POM_XML); MavenProject mavenProject = getMavenProject(pomFile); String newVersion = releaseProperties.getProperty( PROJECT_PREFIX + DEV + "." + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId()); return newVersion; }
From source file:se.jguru.nazgul.tools.codestyle.enforcer.rules.AbstractEnforcerRule.java
License:Apache License
/** * This is the interface into the rule. This method should throw an exception * containing a reason message if the rule fails the check. The plugin will * then decide based on the fail flag if it should stop or just log the * message as a warning./*from w w w . j av a 2 s.c o m*/ * * @param helper The helper provides access to the log, MavenSession and has * helpers to get common components. It is also able to lookup components * by class name. * @throws org.apache.maven.enforcer.rule.api.EnforcerRuleException the enforcer rule exception */ @Override @SuppressWarnings("PMD.PreserveStackTrace") public final void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException { final MavenProject project; try { project = (MavenProject) helper.evaluate("${project}"); } catch (final ExpressionEvaluationException e) { // Whoops. final String msg = "Could not acquire MavenProject. (Expression lookup failure for: " + e.getLocalizedMessage() + ")"; throw new EnforcerRuleException(msg, e); } // Delegate. try { performValidation(project, helper); } catch (RuleFailureException e) { // Create a somewhat verbose failure message. String message = "\n" + "\n#" + "\n# Structure rule failure:" + "\n# " + getShortRuleDescription() + "\n# " + "\n# Message: " + e.getLocalizedMessage() + "\n# " + "\n# Offending project [" + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + "]" + "\n#"; final Artifact art = e.getOffendingArtifact(); if (art != null) { message += "\n# Offending artifact [" + art.getGroupId() + ":" + art.getArtifactId() + ":" + art.getVersion() + "]" + "\n#"; } message += "\n"; // Re-throw for pretty print throw new EnforcerRuleException(message); } }
From source file:se.jguru.nazgul.tools.codestyle.enforcer.rules.CorrectPackagingRule.java
License:Apache License
/** * Delegate method, implemented by concrete subclasses. * * @param project The active MavenProject. * @param helper The EnforcerRuleHelper instance, from which the MavenProject has been retrieved. * @throws RuleFailureException If the enforcer rule was not satisfied. *//* w ww . jav a 2 s .c o m*/ @Override @SuppressWarnings("unchecked") protected void performValidation(final MavenProject project, final EnforcerRuleHelper helper) throws RuleFailureException { // Find all java source files, and map their packages to their names. final List<String> compileSourceRoots = (List<String>) project.getCompileSourceRoots(); if (compileSourceRoots.size() == 0) { return; } final SortedMap<String, SortedSet<String>> packageName2SourceFileNameMap = new TreeMap<String, SortedSet<String>>(); for (String current : compileSourceRoots) { addPackages(new File(current), packageName2SourceFileNameMap); } // Retrieve the groupId of this project final String groupId = project.getGroupId(); if (groupId == null || groupId.equals("")) { // Don't accept empty groupIds throw new RuleFailureException("Maven groupId cannot be null or empty.", project.getArtifact()); } else { // Correct packaging everywhere? final SortedSet<String> incorrectPackages = new TreeSet<String>(); for (Map.Entry<String, SortedSet<String>> currentPackage : packageName2SourceFileNameMap.entrySet()) { final String candidate = currentPackage.getKey(); if (!candidate.startsWith(groupId)) { incorrectPackages.add(candidate); } } if (incorrectPackages.size() > 0) { final SortedMap<String, SortedSet<String>> result = new TreeMap<String, SortedSet<String>>(); for (String current : incorrectPackages) { result.put(current, packageName2SourceFileNameMap.get(current)); } throw new RuleFailureException("Incorrect packaging detected; required [" + groupId + "] but found package to file names: " + result, project.getArtifact()); } } }
From source file:se.jguru.nazgul.tools.codestyle.enforcer.rules.ProjectType.java
License:Apache License
/** * Acquires the ProjectType instance for the provided MavenProject, * or throws an IllegalArgumentException holding an exception message * if a ProjectType could not be found for the provided MavenProject. * * @param project The MavenProject to classify. * @return The corresponding ProjectType. * @throws IllegalArgumentException if the given project could not be mapped to a [single] ProjectType. * The exception message holds *//* w ww . j a v a 2 s. co m*/ public static ProjectType getProjectType(final MavenProject project) throws IllegalArgumentException { Validate.notNull(project, "Cannot handle null project argument."); final List<ProjectType> matches = findCandidates(project.getGroupId(), project.getArtifactId(), project.getPackaging(), "Incorrect project type definition for [" + project.getGroupId() + " :: " + project.getArtifactId() + " :: " + project.getVersion() + "]: "); // Validate the internal requirements for the two different pom projects. final ProjectType toReturn = matches.get(0); switch (toReturn) { case PARENT: case ASSEMBLY: // This project should not contain modules. if (project.getModules() != null && !project.getModules().isEmpty()) { throw new IllegalArgumentException( ProjectType.PARENT + " projects may not contain module definitions. " + "(Modules are reserved for reactor projects)."); } break; case REACTOR: // This project not contain dependency definitions. final List<?> dependencies = project.getDependencies(); if (dependencies != null && !dependencies.isEmpty()) { throw new IllegalArgumentException( ProjectType.REACTOR + " projects may not contain dependency definitions." + " (Dependencies should be defined within parent projects)."); } final DependencyManagement dependencyManagement = project.getDependencyManagement(); if (dependencyManagement != null) { // Dig out all dependency management-defined dependencies. final List<Dependency> templateDependencies = dependencyManagement.getDependencies(); if (templateDependencies != null && !templateDependencies.isEmpty()) { throw new IllegalArgumentException( ProjectType.REACTOR + " projects may not contain dependency [management] definitions." + " (Dependencies should be defined within parent projects)."); } } break; // No action should be taken for other project types. default: break; } // All done. return toReturn; }