List of usage examples for org.apache.maven.project MavenProject getBasedir
public File getBasedir()
From source file:org.seasar.uruma.eclipath.ProjectRefresher.java
License:Apache License
public void refresh(MavenProject project, String host, int port) { EclipseProject eclipseProject = new EclipseProject(project.getBasedir().getAbsolutePath()); String projectName = eclipseProject.getProjectName(); URL url = getRefleshRequestURL(host, port, projectName); Logger.info("Refreshing project : " + projectName); sendRequest(url);// ww w.j a va2s . co m }
From source file:org.smallmind.license.SourceNoticeMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { MavenProject rootProject = project; Stencil[] mergedStencils;/* w w w . ja v a 2s . c om*/ char[] buffer = new char[8192]; while ((root == null) ? !(rootProject.getParent() == null) : !(root.getGroupId().equals(rootProject.getGroupId()) && root.getArtifactId().equals(rootProject.getArtifactId()))) { rootProject = rootProject.getParent(); } mergedStencils = new Stencil[(stencils != null) ? stencils.length + DEFAULT_STENCILS.length : DEFAULT_STENCILS.length]; System.arraycopy(DEFAULT_STENCILS, 0, mergedStencils, 0, DEFAULT_STENCILS.length); if (stencils != null) { System.arraycopy(stencils, 0, mergedStencils, DEFAULT_STENCILS.length, stencils.length); } for (Rule rule : rules) { FileFilter[] fileFilters; String[] noticeArray; boolean noticed; boolean stenciled; if (verbose) { getLog().info(String.format("Processing rule(%s)...", rule.getId())); } noticed = true; if (rule.getNotice() == null) { if (!allowNoticeRemoval) { throw new MojoExecutionException("No notice was provided for rule(" + rule.getId() + "), but notice removal has not been enabled(allowNoticeRemoval = false)"); } noticeArray = null; } else { File noticeFile; noticeFile = new File(rule.getNotice()); if ((noticeArray = getFileAsLineArray(noticeFile.isAbsolute() ? noticeFile.getAbsolutePath() : rootProject.getBasedir() + System.getProperty("file.separator") + noticeFile.getPath())) == null) { noticed = false; } } if (!noticed) { getLog().warn(String.format("Unable to acquire the notice file(%s), skipping notice updating...", rule.getNotice())); } else { if ((rule.getFileTypes() == null) || (rule.getFileTypes().length == 0)) { throw new MojoExecutionException("No file types were specified for rule(" + rule.getId() + ")"); } fileFilters = new FileFilter[rule.getFileTypes().length]; for (int count = 0; count < fileFilters.length; count++) { fileFilters[count] = new FileTypeFilenameFilter(rule.getFileTypes()[count]); } stenciled = false; for (Stencil stencil : mergedStencils) { if (stencil.getId().equals(rule.getStencilId())) { stenciled = true; updateNotice(stencil, noticeArray, buffer, project.getBuild().getSourceDirectory(), fileFilters); updateNotice(stencil, noticeArray, buffer, project.getBuild().getScriptSourceDirectory(), fileFilters); if (includeResources) { for (Resource resource : project.getBuild().getResources()) { updateNotice(stencil, noticeArray, buffer, resource.getDirectory(), fileFilters); } } if (includeTests) { updateNotice(stencil, noticeArray, buffer, project.getBuild().getTestSourceDirectory(), fileFilters); if (includeResources) { for (Resource testResource : project.getBuild().getTestResources()) { updateNotice(stencil, noticeArray, buffer, testResource.getDirectory(), fileFilters); } } } break; } } if (!stenciled) { throw new MojoExecutionException( "No stencil found with id(" + rule.getStencilId() + ") for rule(" + rule.getId() + ")"); } } } }
From source file:org.smallmind.license.TargetLicenseMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { if ((new File(project.getBuild().getOutputDirectory())).exists()) { MavenProject rootProject = project; byte[] buffer = new byte[8192]; while ((root == null) ? !(rootProject.getParent() == null) : !(root.getGroupId().equals(rootProject.getGroupId()) && root.getArtifactId().equals(rootProject.getArtifactId()))) { rootProject = rootProject.getParent(); }/*from www . j a va 2 s . c o m*/ for (String license : licenses) { File licenseFile; File copyFile; FileInputStream inputStream; FileOutputStream outputStream; int bytesRead; if (!(licenseFile = new File(license)).isAbsolute()) { licenseFile = new File(rootProject.getBasedir() + System.getProperty("file.separator") + licenseFile.getPath()); } if (!licenseFile.exists()) { getLog().warn( String.format("Unable to acquire the license file(%s), skipping license copying...", licenseFile.getAbsolutePath())); } else { if (verbose) { getLog().info(String.format("Copying license(%s)...", licenseFile.getName())); } copyFile = new File(project.getBuild().getOutputDirectory() + System.getProperty("file.separator") + licenseFile.getName()); try { outputStream = new FileOutputStream(copyFile); } catch (IOException ioException) { throw new MojoExecutionException( "Unable to create output license file (" + copyFile.getAbsolutePath() + ")", ioException); } try { inputStream = new FileInputStream(licenseFile); while ((bytesRead = inputStream.read(buffer)) >= 0) { outputStream.write(buffer, 0, bytesRead); } inputStream.close(); } catch (IOException ioException) { copyFile.delete(); throw new MojoExecutionException( "Problem in copying output license file (" + copyFile.getAbsolutePath() + ")", ioException); } try { outputStream.close(); } catch (IOException ioException) { throw new MojoExecutionException( "Problem in closing license file (" + licenseFile.getAbsolutePath() + ")", ioException); } } } } }
From source file:org.sonar.batch.maven.MavenProjectConverter.java
License:Open Source License
private void rebuildModuleHierarchy(Map<String, MavenProject> paths, Map<MavenProject, ProjectDefinition> defs) throws IOException { 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); }// w ww . j a v a2 s.com ProjectDefinition subProject = defs.get(module); if (subProject == null) { throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); } parentProject.addSubProject(subProject); } } }
From source file:org.sonar.batch.maven.MavenProjectConverter.java
License:Open Source License
public void synchronizeFileSystem(MavenProject pom, ProjectDefinition into) { into.setBaseDir(pom.getBasedir()); File buildDir = getBuildDir(pom); if (buildDir != null) { into.setBuildDir(buildDir);//from w ww . java2 s. c om into.setWorkDir(getSonarWorkDir(pom)); } into.setSourceDirs(toPaths(mainDirs(pom))); into.setTestDirs(toPaths(testDirs(pom))); File binaryDir = resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir()); if (binaryDir != null) { into.addBinaryDir(binaryDir); } }
From source file:org.sonar.batch.maven.MavenProjectConverter.java
License:Open Source License
private static File getBuildDir(MavenProject pom) { return resolvePath(pom.getBuild().getDirectory(), pom.getBasedir()); }
From source file:org.sonar.batch.maven.MavenProjectConverter.java
License:Open Source License
public void synchronizeFileSystem(MavenProject pom, DefaultModuleFileSystem into) { into.resetDirs(pom.getBasedir(), getBuildDir(pom), mainDirs(pom), testDirs(pom), Arrays.asList(resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir()))); }
From source file:org.sonar.batch.maven.MavenProjectConverter.java
License:Open Source License
private List<File> sourceDirs(MavenProject pom, String propertyKey, List mavenDirs) { List<String> paths; String prop = pom.getProperties().getProperty(propertyKey); if (prop != null) { paths = Arrays.asList(StringUtils.split(prop, ",")); // do not remove dirs that do not exist. They must be kept in order to // notify users that value of sonar.sources has a typo. return existingDirsOrFail(resolvePaths(paths, pom.getBasedir()), pom, propertyKey); }//from w w w. j ava2s.c om List<File> dirs = resolvePaths(mavenDirs, pom.getBasedir()); // Maven provides some directories that do not exist. They // should be removed return keepExistingDirs(dirs); }
From source file:org.sonar.batch.MavenProjectConverter.java
License:Open Source License
public static ProjectDefinition convert(List<MavenProject> poms, MavenProject root) { Map<String, MavenProject> paths = Maps.newHashMap(); // projects by canonical path Map<MavenProject, ProjectDefinition> defs = Maps.newHashMap(); try {/* w ww . j a v a 2 s .co m*/ for (MavenProject pom : poms) { String basedir = pom.getBasedir().getCanonicalPath(); paths.put(basedir, pom); defs.put(pom, convert(pom)); } for (Map.Entry<String, MavenProject> entry : paths.entrySet()) { MavenProject pom = entry.getValue(); for (Object moduleId : pom.getModules()) { File modulePath = new File(pom.getBasedir(), (String) moduleId); MavenProject module = paths.get(modulePath.getCanonicalPath()); defs.get(pom).addSubProject(defs.get(module)); } } } catch (IOException e) { throw new SonarException(e); } return defs.get(root); }
From source file:org.sonar.batch.MavenProjectConverter.java
License:Open Source License
public static void synchronizeFileSystem(MavenProject pom, ProjectDefinition into) { into.setBaseDir(pom.getBasedir()); into.setWorkDir(new File(resolvePath(pom.getBuild().getDirectory(), pom.getBasedir()), "sonar")); into.setSourceDirs(//w w w . j av a2 s.com (String[]) pom.getCompileSourceRoots().toArray(new String[pom.getCompileSourceRoots().size()])); into.setTestDirs((String[]) pom.getTestCompileSourceRoots() .toArray(new String[pom.getTestCompileSourceRoots().size()])); }