List of usage examples for org.apache.maven.project MavenProject getGroupId
public String getGroupId()
From source file:org.jboss.maven.extension.dependency.DependencyManagementLifecycleParticipant.java
License:Apache License
@Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { // The dependency management overrider needs to know which projects // are in the reactor, and therefore should not be overridden. StringBuilder reactorProjects = new StringBuilder(); for (MavenProject project : session.getProjects()) { reactorProjects.append(project.getGroupId() + ":" + project.getArtifactId() + ","); }/*from w w w. j a v a2s .c o m*/ System.setProperty("reactorProjectGAs", reactorProjects.toString()); // Apply model modifiers to the projects' models for (MavenProject project : session.getProjects()) { logger.debug("Checking project '" + project.getId() + "'"); int modelChangeCount = 0; Model currModel = project.getModel(); // Run the modifiers against the built model for (ModelModifier currModifier : afterProjectsReadModifierList) { boolean modelChanged = currModifier.updateModel(currModel); if (modelChanged) { modelChangeCount++; } } // If something changed, then it will be useful to output extra info if (sessionChangeCount >= 1 || modelChangeCount >= 1) { logger.debug("Session/Model changed at least once, writing informational files"); try { MetaInfWriter.writeResource(currModel, new EffectivePomGenerator()); } catch (IOException e) { logger.error( "Could not write the effective POM of model '" + currModel.getId() + "' due to " + e); } } } }
From source file:org.jboss.maven.plugins.qstools.AbstractProjectWalker.java
License:Apache License
@SuppressWarnings("unchecked") public void walk(WalkType walkType, MavenProject project, MavenSession mavenSession, List<MavenProject> reactorProjects, Log log, Map<String, List<Violation>> results) throws QSToolsException { this.mavenSession = mavenSession; this.log = log; try {/*w w w .j a v a 2 s . c om*/ List<String> ignoredQuickstarts = (List<String>) context.get(Constants.IGNORED_QUICKSTARTS_CONTEXT); if (configurationProvider.getQuickstartsRules(project.getGroupId()).isCheckerIgnored(this.getClass())) { setCheckerMessage("This checker is ignored for this groupId in config file."); } else { for (MavenProject mavenProject : reactorProjects) { if (!ignoredQuickstarts.contains(mavenProject.getBasedir().getName())) { Document doc = PositionalXMLReader.readXML(new FileInputStream(mavenProject.getFile())); switch (walkType) { case CHECK: checkProject(mavenProject, doc, results); break; case FIX: fixProject(mavenProject, doc); break; default: break; } } else { log.warn("Ignoring " + mavenProject.getBasedir().getName() + ". It is listed on .quickstarts_ignore file"); } } } } catch (Exception e) { // Any other exception is a problem. throw new QSToolsException(e); } }
From source file:org.jboss.maven.plugins.qstools.BomUpdaterMojo.java
License:Apache License
/** * @param project//from w w w. j a v a 2 s . c om * @throws Exception */ private void processProject(MavenProject project) throws Exception { pomModified = false; Rules rules = configurationProvider.getQuickstartsRules(project.getGroupId()); getLog().debug("Processing " + project.getArtifactId()); Document doc = PositionalXMLReader.readXML(new FileInputStream(project.getFile())); NodeList dependencies = (NodeList) xPath.evaluate("/project/dependencyManagement/dependencies/dependency", doc, XPathConstants.NODESET); replaceBOMsIfNeeded(project, dependencies, rules); updateBomsVersionIfNeeded(project, dependencies, rules, doc); if (pomModified) { getLog().info("*** Saving changes to " + project.getFile() + "\n"); updatedProjects++; XMLUtil.writeXML(doc, project.getFile()); } }
From source file:org.jboss.maven.plugins.qstools.checkers.AbstractCheckstyleChecker.java
License:Apache License
@Override public Map<String, List<Violation>> check(MavenProject project, MavenSession mavenSession, List<MavenProject> reactorProjects, Log log) throws QSToolsException { Map<String, List<Violation>> results = new TreeMap<String, List<Violation>>(); if (configurationProvider.getQuickstartsRules(project.getGroupId()).isCheckerIgnored(this.getClass())) { checkerMessage = "This checker is ignored for this groupId in config file."; } else {/*from w ww . jav a 2s. c om*/ CheckstyleExecutorRequest executorRequest = new CheckstyleExecutorRequest(); Rules rules = configurationProvider.getQuickstartsRules(project.getGroupId()); try { executorRequest.setReactorProjects(reactorProjects).setSourceDirectory(project.getBasedir()) .setTestSourceDirectory(project.getBasedir()).setFailsOnError(false).setProject(project) .setConfigLocation(getCheckstyleConfig()).setLog(log).setEncoding("UTF-8") .setHeaderLocation(rules.getHeaderLocation()).setIncludes(getIncludes()) .setExcludes(rules.getExcludes() + ", " + rules.getCheckerSpecificExcludes(this)); CheckstyleResults checkstyleResults = checkstyleExecutor.executeCheckstyle(executorRequest); Map<String, List<AuditEvent>> files = checkstyleResults.getFiles(); for (String file : files.keySet()) { List<AuditEvent> events = files.get(file); // If file has events/violations if (events.size() > 0) { List<Violation> violations = new ArrayList<Violation>(); for (AuditEvent event : events) { // Add each checktyle AuditEvent as a new Violation violations.add(new Violation(this.getClass(), event.getLine(), event.getMessage())); violationsQtd++; } results.put(file, violations); } } } catch (Exception e) { throw new QSToolsException(e); } } if (getCheckerMessage() != null) { log.info("--> Checker Message: " + getCheckerMessage()); } return results; }
From source file:org.jboss.maven.plugins.qstools.checkers.AbstractProjectChecker.java
License:Apache License
@Override @SuppressWarnings("unchecked") public Map<String, List<Violation>> check(MavenProject project, MavenSession mavenSession, List<MavenProject> reactorProjects, Log log) throws QSCheckerException { this.mavenSession = mavenSession; this.log = log; Map<String, List<Violation>> results = new TreeMap<String, List<Violation>>(); try {/* www .jav a 2 s . c o m*/ List<String> ignoredQuickstarts = (List<String>) context.get(Constants.IGNORED_QUICKSTARTS_CONTEXT); for (MavenProject mavenProject : reactorProjects) { if (!ignoredQuickstarts.contains(mavenProject.getBasedir().getName())) { Document doc = PositionalXMLReader.readXML(new FileInputStream(mavenProject.getFile())); if (configurationProvider.getQuickstartsRules(project.getGroupId()).isCheckerIgnored(this)) { String msg = "Skiping %s for %s:%s"; log.warn(String.format(msg, this.getClass().getSimpleName(), project.getGroupId(), project.getArtifactId())); } else { processProject(mavenProject, doc, results); } } else { log.debug("Ignoring " + mavenProject.getBasedir().getName() + ". It is listed on .quickstarts_ignore file"); } } if (violationsQtd > 0) { log.info("There are " + violationsQtd + " checkers errors"); } } catch (Exception e) { // Any other exception is a problem. throw new QSCheckerException(e); } return results; }
From source file:org.jboss.maven.plugins.qstools.checkers.ArtifactIdNameChecker.java
License:Apache License
@Override public Map<String, List<Violation>> check(MavenProject project, MavenSession mavenSession, List<MavenProject> reactorProjects, Log log) throws QSToolsException { Map<String, List<Violation>> results = new TreeMap<String, List<Violation>>(); try {/*w ww . j a v a 2 s. c om*/ if (configurationProvider.getQuickstartsRules(project.getGroupId()).isCheckerIgnored(this.getClass())) { checkerMessage = "This checker is ignored for this groupId in config file."; } else { Rules rules = configurationProvider.getQuickstartsRules(project.getGroupId()); List<ArtifactIdNameUtil.PomInformation> pomsWithInvalidArtifactIds = artifactIdNameUtil .findAllIncorrectArtifactIdNames(reactorProjects, rules); for (ArtifactIdNameUtil.PomInformation pi : pomsWithInvalidArtifactIds) { String rootDirectory = (mavenSession.getExecutionRootDirectory() + File.separator).replace("\\", "\\\\"); String fileAsString = pi.getProject().getFile().getAbsolutePath().replace(rootDirectory, ""); if (results.get(fileAsString) == null) { results.put(fileAsString, new ArrayList<Violation>()); } String msg = "Project with the following artifactId [%s] doesn't match the required format. It should be: [%s]"; results.get(fileAsString).add(new Violation(getClass(), pi.getLine(), String.format(msg, pi.getActualArtifactId(), pi.getExpectedArtifactId()))); violationsQtd++; } if (getCheckerMessage() != null) { log.info("--> Checker Message: " + getCheckerMessage()); } if (violationsQtd > 0) { log.info("There are " + violationsQtd + " checkers violations"); } } return results; } catch (Exception e) { throw new QSToolsException(e); } }
From source file:org.jboss.maven.plugins.qstools.checkers.ArtifactIdPrefixChecker.java
License:Apache License
@Override public void processProject(MavenProject project, Document doc, Map<String, List<Violation>> results) throws Exception { Rules rules = getConfigurationProvider().getQuickstartsRules(project.getGroupId()); String artifarIdPrefix = rules.getArtifactIdPrefix(); if (!project.getArtifactId().startsWith(artifarIdPrefix)) { Node artifacId = (Node) getxPath().evaluate("/project/artifactId", doc, XPathConstants.NODE); int lineNumber = artifacId == null ? 0 : getLineNumberFromNode(artifacId); String msg = "Project with the following artifactId [%s] isn't doesn't start with [%s]"; addViolation(project.getFile(), results, lineNumber, String.format(msg, project.getArtifactId(), artifarIdPrefix)); }//w w w .j a va 2s. c om }
From source file:org.jboss.maven.plugins.qstools.checkers.BomVersionChecker.java
License:Apache License
@Override public void checkProject(MavenProject project, Document doc, Map<String, List<Violation>> results) throws Exception { Properties expectedBomVersions = getConfigurationProvider().getQuickstartsRules(project.getGroupId()) .getExpectedBomVersion();/*from w w w. j av a 2 s. c o m*/ NodeList dependencies = (NodeList) getxPath() .evaluate("/project/dependencyManagement/dependencies/dependency", doc, XPathConstants.NODESET); // Iterate over all Declared Managed Dependencies for (int x = 0; x < dependencies.getLength(); x++) { Node dependency = dependencies.item(x); MavenDependency mavenDependency = getDependencyProvider().getDependencyFromNode(project, dependency); // use stacks to find if the project is using a jboss-developer bom Bom bomUsed = null; Stacks stacks = (Stacks) getContext().get(Constants.STACKS_CONTEXT); for (Bom bom : stacks.getAvailableBoms()) { if (bom.getGroupId().equals(mavenDependency.getGroupId()) && bom.getArtifactId().equals(mavenDependency.getArtifactId())) { bomUsed = bom; } } int lineNumber = XMLUtil.getLineNumberFromNode(dependency); if (bomUsed == null // No JDF Bom used && !mavenDependency.getGroupId().startsWith("org.jboss") // Escape jboss boms && !mavenDependency.getGroupId().startsWith(project.getGroupId()) // Escape projects with same groupId (subprojects) && "pom".equals(mavenDependency.getType()) && "import".equals(mavenDependency.getScope()) // Only consider BOMs ) { addViolation(project.getFile(), results, lineNumber, mavenDependency + " isn't a JBoss Developer BOM"); } else if (bomUsed != null) { String expectedBomVersion = expectedBomVersions.getProperty(bomUsed.getGroupId()); if (expectedBomVersion != null && !mavenDependency.getInterpoledVersion().equals(expectedBomVersion)) { String violationMsg = String.format("BOM %s isn't using the expected version %s", mavenDependency, expectedBomVersion); addViolation(project.getFile(), results, lineNumber, violationMsg); } } } }
From source file:org.jboss.maven.plugins.qstools.checkers.FinalNameChecker.java
License:Apache License
@Override public void checkProject(MavenProject project, Document doc, Map<String, List<Violation>> results) throws Exception { String packaging = project.getPackaging(); String expectedFinalName = getConfigurationProvider().getQuickstartsRules(project.getGroupId()) .getFinalNamePatterns().get(packaging); Node finalNameNode = (Node) getxPath().evaluate("//finalName", doc, XPathConstants.NODE); String declaredFinalName = finalNameNode == null ? project.getBuild().getFinalName() : finalNameNode.getTextContent(); if (expectedFinalName != null && !expectedFinalName.equals(declaredFinalName)) { int lineNumber = finalNameNode == null ? 0 : XMLUtil.getLineNumberFromNode(finalNameNode); addViolation(project.getFile(), results, lineNumber, ("File doesn't contain <finalName>" + expectedFinalName + "</finalName>")); }// w w w . j a v a 2 s . com }
From source file:org.jboss.maven.plugins.qstools.checkers.GroupIdChecker.java
License:Apache License
@Override public void checkProject(MavenProject project, Document doc, Map<String, List<Violation>> results) throws Exception { groupId = getConfigurationProvider().getQuickstartsRules(project.getGroupId()).getGroupId(); Node node = (Node) getxPath().evaluate("/project/groupId", doc, XPathConstants.NODE); if (node != null && !project.getGroupId().equals(groupId)) { int lineNumber = XMLUtil.getLineNumberFromNode(node); addViolation(project.getFile(), results, lineNumber, "The project doesn't use groupId '" + groupId + "'"); }/*from w w w . j av a 2 s. c o m*/ }