List of usage examples for org.apache.maven.execution MavenSession getExecutionRootDirectory
public String getExecutionRootDirectory()
From source file:io.takari.maven.timeline.BuildEventsExtension.java
License:Apache License
private File mavenTimelineFile(MavenSession session) { return new File(session.getExecutionRootDirectory(), "target/timeline/maven-timeline.js"); }
From source file:io.takari.maven.timeline.BuildEventsExtension.java
License:Apache License
private File logFile(MavenSession session) { String path = session.getUserProperties().getProperty(OUTPUT_FILE, DEFAULT_FILE_DESTINATION); if (new File(path).isAbsolute()) { return new File(path); }/*from ww w . ja v a 2 s. c o m*/ String buildDir = session.getExecutionRootDirectory(); return new File(buildDir, path); }
From source file:net.gageot.maven.BuildEventsExtension.java
License:Apache License
private File logFile(MavenSession session) { String path = session.getUserProperties().getProperty(OUTPUT_FILE, DEFAULT_FILE_DESTINATION); if (new File(path).isAbsolute()) { return new File(path); }/*ww w .j a v a2 s . c o m*/ String buildDir = session.getExecutionRootDirectory(); return new File(buildDir, path); }
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 w w . j a v a 2 s. co m 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.JavaEncondingChecker.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 {/*from w w w .j a v a2 s. c o m*/ if (configurationProvider.getQuickstartsRules(project.getGroupId()).isCheckerIgnored(this.getClass())) { checkerMessage = "This checker is ignored for this groupId in config file."; } else { // get all files to process List<File> sourceFiles = FileUtils.getFiles(project.getBasedir(), "**/*.java", ""); for (File source : sourceFiles) { FileInputStream fis = null; try { // Read file content as byte array (no encoding) fis = new FileInputStream(source); byte[] buf = new byte[4096]; int nread; while ((nread = fis.read(buf)) > 0 && !encodingDetector.isDone()) { encodingDetector.handleData(buf, 0, nread); } encodingDetector.dataEnd(); // report if not utf-8 String encoding = encodingDetector.getDetectedCharset(); if (encoding != null && !encoding.equalsIgnoreCase("UTF-8")) { // Get relative path based on maven work dir String rootDirectory = (mavenSession.getExecutionRootDirectory() + File.separator) .replace("\\", "\\\\"); String fileAsString = source.getAbsolutePath().replace(rootDirectory, ""); if (results.get(fileAsString) == null) { results.put(fileAsString, new ArrayList<Violation>()); } results.get(fileAsString).add(new Violation(getClass(), 0, "This file contains a non UTF-8 characters. It was detected as " + encoding)); violationsQtd++; } } finally { encodingDetector.reset(); if (fis != null) { fis.close(); } } } if (getCheckerMessage() != null) { log.info("--> Checker Message: " + getCheckerMessage()); } if (violationsQtd > 0) { log.info("There are " + violationsQtd + " checkers violations"); } } } catch (Exception e) { throw new QSToolsException(e); } return results; }
From source file:org.jboss.maven.plugins.qstools.checkers.SamePropertyValueChecker.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>>(); Rules rules = configurationProvider.getQuickstartsRules(project.getGroupId()); try {/*from w w w .java2s . c o m*/ if (rules.isCheckerIgnored(this.getClass())) { checkerMessage = "This checker is ignored for this groupId in config file."; } else { // iterate over all reactor projects to iterate on all declared properties for (MavenProject mavenProject : reactorProjects) { Document doc = PositionalXMLReader.readXML(new FileInputStream(mavenProject.getFile())); NodeList propertiesNodes = (NodeList) xPath.evaluate("/project/properties/*", doc, XPathConstants.NODESET); // find all declared properties for (int x = 0; x < propertiesNodes.getLength(); x++) { Node property = propertiesNodes.item(x); String propertyName = property.getNodeName(); String propertyValue = property.getTextContent(); // skip ignored property if (rules.getIgnoredDifferentValuesProperties().contains(propertyName)) { continue; } if (projectProperties.get(propertyName) == null) { projectProperties.put(propertyName, propertyValue); } else if (projectProperties.get(propertyName) != null && !projectProperties.get(propertyName).equals(propertyValue)) { // The property was used but with an different value int lineNumber = (Integer) property .getUserData(PositionalXMLReader.BEGIN_LINE_NUMBER_KEY_NAME); String rootDirectory = (mavenSession.getExecutionRootDirectory() + File.separator) .replace("\\", "\\\\"); String fileAsString = mavenProject.getFile().getAbsolutePath().replace(rootDirectory, ""); if (results.get(fileAsString) == null) { results.put(fileAsString, new ArrayList<Violation>()); } String msg = "Property [%s] was declared with a value [%s] that differ from previous value [%s]"; results.get(fileAsString).add(new Violation(getClass(), lineNumber, String.format(msg, propertyName, propertyValue, projectProperties.get(propertyName)))); violationsQtd++; } } } if (getCheckerMessage() != null) { log.info("--> Checker Message: " + getCheckerMessage()); } if (violationsQtd > 0) { log.info("There are " + violationsQtd + " checkers violations"); } } } catch (Exception e) { throw new QSToolsException(e); } return results; }
From source file:org.jboss.maven.plugins.qstools.checkers.UnusedPropertiesChecker.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>>(); Rules rules = configurationProvider.getQuickstartsRules(project.getGroupId()); if (rules.isCheckerIgnored(this.getClass())) { checkerMessage = "This checker is ignored for this groupId in config file."; } else {/*ww w . ja va 2 s. c o m*/ try { List<UnusedPropertiesUtil.PomInformation> unusedPropertyInfo = unusedPropertiesUtil .findUnusedProperties(reactorProjects, rules); // Construct a violation for each unused property for (UnusedPropertiesUtil.PomInformation pi : unusedPropertyInfo) { // Get relative path based on maven work dir 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 = "Property [%s] was declared but was never used"; results.get(fileAsString) .add(new Violation(getClass(), pi.getLine(), String.format(msg, pi.getProperty()))); violationsQtd++; } if (getCheckerMessage() != null) { log.info("--> Checker Message: " + getCheckerMessage()); } if (violationsQtd > 0) { log.info("There are " + violationsQtd + " checkers violations"); } } catch (Exception e) { throw new QSToolsException(e); } } return results; }
From source file:org.jboss.maven.plugins.qstools.checkers.ValidXMLSchemaChecker.java
License:Apache License
@Override public Map<String, List<Violation>> check(MavenProject project, MavenSession mavenSession, List<MavenProject> reactorProjects, Log log) throws QSToolsException { log.info("--> This Checker can take several minutes to run"); this.log = log; Map<String, List<Violation>> results = new TreeMap<String, List<Violation>>(); Rules rules = configurationProvider.getQuickstartsRules(project.getGroupId()); try {//from w w w . j a v a2s.c o m if (rules.isCheckerIgnored(this.getClass())) { checkerMessage = "This checker is ignored for this groupId in config file."; } else { // get all xml to process but excludes hidden files and /target and /bin folders List<File> xmlFiles = FileUtils.getFiles(project.getBasedir(), "**/*.xml", rules.getExcludes()); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(); for (File xml : xmlFiles) { // Get relative path based on maven work dir String rootDirectory = (mavenSession.getExecutionRootDirectory() + File.separator).replace("\\", "\\\\"); String fileAsString = xml.getAbsolutePath().replace(rootDirectory, ""); Validator validator = schema.newValidator(); validator.setResourceResolver(new URLBasedResourceResolver(xml)); validator.setErrorHandler(new XMLErrorHandler(fileAsString, results)); log.info("Validating " + fileAsString); try { validator.validate(new StreamSource(new BufferedInputStream(new FileInputStream(xml)))); } catch (SAXException e) { // validator.validate can throw a SAXException coming from the ErrorHandler addViolation(fileAsString, 0, e.getMessage(), results); } } if (getCheckerMessage() != null) { log.info("--> Checker Message: " + getCheckerMessage()); } if (violationsQtd > 0) { log.info("There are " + violationsQtd + " checkers violations"); } } } catch (Exception e) { throw new QSToolsException(e); } return results; }
From source file:org.sonatype.maven.mojo.execution.MojoExecution.java
License:Open Source License
/** * Returns true if the current project is located at the Execution Root Directory (from where mvn was launched). * * @param mavenSession the MavenSession/*from ww w . j a v a 2s .c om*/ * @param basedir the basedir * @return true if execution root equals to the passed in basedir. */ public static boolean isThisTheExecutionRoot(final MavenSession mavenSession, final String basedir) { return mavenSession.getExecutionRootDirectory().equalsIgnoreCase(basedir); }