List of usage examples for org.apache.maven.project MavenProject getBasedir
public File getBasedir()
From source file:org.sonar.batch.ProjectTree.java
License:Open Source License
public void start() throws IOException { projects = Lists.newArrayList();// ww w.j a v a 2 s . c o m Map<String, Project> paths = Maps.newHashMap(); // projects by canonical path for (MavenProject pom : poms) { Project project = projectBuilder.create(pom); projects.add(project); paths.put(pom.getBasedir().getCanonicalPath(), project); } for (Map.Entry<String, Project> entry : paths.entrySet()) { Project project = entry.getValue(); MavenProject pom = project.getPom(); for (Object moduleId : pom.getModules()) { File modulePath = new File(pom.getBasedir(), (String) moduleId); Project module = paths.get(modulePath.getCanonicalPath()); if (module != null) { module.setParent(project); } } } configureProjects(); applyModuleExclusions(); }
From source file:org.sonar.batch.scan.maven.MavenProjectConverter.java
License:Open Source License
public static ProjectDefinition convert(List<MavenProject> poms, MavenProject root) { // projects by canonical path to pom.xml Map<String, MavenProject> paths = Maps.newHashMap(); Map<MavenProject, ProjectDefinition> defs = Maps.newHashMap(); try {/*from w w w. j a va 2s. c om*/ for (MavenProject pom : poms) { paths.put(pom.getFile().getCanonicalPath(), pom); defs.put(pom, convert(pom)); } for (Map.Entry<String, MavenProject> entry : paths.entrySet()) { MavenProject pom = entry.getValue(); for (Object m : pom.getModules()) { String moduleId = (String) m; File modulePath = new File(pom.getBasedir(), moduleId); MavenProject module = findMavenProject(modulePath, paths); ProjectDefinition parentProject = defs.get(pom); if (parentProject == null) { throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); } ProjectDefinition subProject = defs.get(module); if (subProject == null) { throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); } parentProject.addSubProject(subProject); } } } catch (IOException e) { throw new SonarException(e); } ProjectDefinition rootProject = defs.get(root); if (rootProject == null) { throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); } return rootProject; }
From source file:org.sonar.batch.scan.maven.MavenProjectConverter.java
License:Open Source License
public static void synchronizeFileSystem(MavenProject pom, ProjectDefinition into) { into.setBaseDir(pom.getBasedir()); File buildDir = resolvePath(pom.getBuild().getDirectory(), pom.getBasedir()); if (buildDir != null) { into.setBuildDir(buildDir);/*from w w w. ja v a 2 s.c o m*/ into.setWorkDir(new File(buildDir, "sonar")); } into.setSourceDirs( (String[]) pom.getCompileSourceRoots().toArray(new String[pom.getCompileSourceRoots().size()])); into.setTestDirs((String[]) pom.getTestCompileSourceRoots() .toArray(new String[pom.getTestCompileSourceRoots().size()])); File binaryDir = resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir()); if (binaryDir != null) { into.addBinaryDir(binaryDir); } }
From source file:org.sonar.batch.scan.maven.MavenProjectConverter.java
License:Open Source License
public static void synchronizeFileSystem(MavenProject pom, DefaultModuleFileSystem into) { into.resetDirs(pom.getBasedir(), resolvePath(pom.getBuild().getDirectory(), pom.getBasedir()), resolvePaths((List<String>) pom.getCompileSourceRoots(), pom.getBasedir()), resolvePaths((List<String>) pom.getTestCompileSourceRoots(), pom.getBasedir()), Arrays.asList(resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir()))); }
From source file:org.sonar.plugins.maven.MavenProjectConverter.java
License:Open Source License
public static void synchronizeFileSystem(MavenProject pom, ProjectDefinition into) { into.setBaseDir(pom.getBasedir()); File buildDir = getBuildDir(pom); if (buildDir != null) { into.setBuildDir(buildDir);/*ww w .ja v a2s. c o m*/ into.setWorkDir(getSonarWorkDir(pom)); } List<String> filteredCompileSourceRoots = filterExisting(pom.getCompileSourceRoots(), pom.getBasedir()); List<String> filteredTestCompileSourceRoots = filterExisting(pom.getTestCompileSourceRoots(), pom.getBasedir()); into.setSourceDirs( (String[]) filteredCompileSourceRoots.toArray(new String[filteredCompileSourceRoots.size()])); into.setTestDirs((String[]) filteredTestCompileSourceRoots .toArray(new String[filteredTestCompileSourceRoots.size()])); File binaryDir = resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir()); if (binaryDir != null) { into.addBinaryDir(binaryDir); } }
From source file:org.sonar.plugins.maven.MavenProjectConverter.java
License:Open Source License
public static void synchronizeFileSystem(MavenProject pom, DefaultModuleFileSystem into) { into.resetDirs(pom.getBasedir(), getBuildDir(pom), resolvePaths(pom.getCompileSourceRoots(), pom.getBasedir()), resolvePaths(pom.getTestCompileSourceRoots(), pom.getBasedir()), Arrays.asList(resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir()))); }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
private static void rebuildModuleHierarchy(Properties properties, Map<MavenProject, Properties> propsByModule, MavenProject current, String prefix) throws IOException { Properties currentProps = propsByModule.get(current); if (currentProps == null) { throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); }//from w w w.j a va 2 s. c om for (Map.Entry<Object, Object> prop : currentProps.entrySet()) { properties.put(prefix + prop.getKey(), prop.getValue()); } propsByModule.remove(current); List<String> moduleIds = new ArrayList<>(); for (String modulePathStr : current.getModules()) { File modulePath = new File(current.getBasedir(), modulePathStr); MavenProject module = findMavenProject(modulePath, propsByModule.keySet()); if (module != null) { String moduleId = module.getGroupId() + ":" + module.getArtifactId(); rebuildModuleHierarchy(properties, propsByModule, module, prefix + moduleId + "."); moduleIds.add(moduleId); } } if (!moduleIds.isEmpty()) { properties.put(prefix + "sonar.modules", StringUtils.join(moduleIds, SEPARATOR)); } }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
private static MavenProject findMavenProject(final File modulePath, Collection<MavenProject> modules) throws IOException { File canonical = modulePath.getCanonicalFile(); for (MavenProject module : modules) { if (module.getBasedir().getCanonicalFile().equals(canonical) || module.getFile().getCanonicalFile().equals(canonical)) { return module; }/* w w w. j ava 2s. c o m*/ } return null; }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
private static void findBugsExcludeFileMaven(MavenProject pom, Properties props) { String excludeFilterFile = MavenUtils.getPluginSetting(pom, MavenUtils.GROUP_ID_CODEHAUS_MOJO, ARTIFACTID_FINDBUGS_MAVEN_PLUGIN, "excludeFilterFile", null); File path = resolvePath(excludeFilterFile, pom.getBasedir()); if (path != null && path.exists()) { props.put(FINDBUGS_EXCLUDE_FILTERS, path.getAbsolutePath()); }// ww w . ja v a2 s . c o m }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
private void synchronizeFileSystemAndOtherProps(MavenProject pom, Properties props) throws MojoExecutionException { props.setProperty(ScanProperties.PROJECT_BASEDIR, pom.getBasedir().getAbsolutePath()); File buildDir = getBuildDir(pom); if (buildDir != null) { props.setProperty(PROPERTY_PROJECT_BUILDDIR, buildDir.getAbsolutePath()); props.setProperty(ScannerProperties.WORK_DIR, getSonarWorkDir(pom).getAbsolutePath()); }// ww w.j a va 2 s . c om populateBinaries(pom, props); populateLibraries(pom, props, false); populateLibraries(pom, props, true); populateSurefireReportsPath(pom, props); // IMPORTANT NOTE : reference on properties from POM model must not be saved, // instead they should be copied explicitly - see SONAR-2896 for (String k : pom.getModel().getProperties().stringPropertyNames()) { props.put(k, pom.getModel().getProperties().getProperty(k)); } props.putAll(envProperties); // Add user properties (ie command line arguments -Dsonar.xxx=yyyy) in last position to // override all other props.putAll(userProperties); List<File> mainDirs = mainSources(pom); props.setProperty(ScanProperties.PROJECT_SOURCE_DIRS, StringUtils.join(toPaths(mainDirs), SEPARATOR)); List<File> testDirs = testSources(pom); if (!testDirs.isEmpty()) { props.setProperty(ScanProperties.PROJECT_TEST_DIRS, StringUtils.join(toPaths(testDirs), SEPARATOR)); } else { props.remove(ScanProperties.PROJECT_TEST_DIRS); } }