List of usage examples for org.apache.maven.project MavenProject getBasedir
public File getBasedir()
From source file:org.universAAL.support.directives.checks.LicenseFileCheckFix.java
License:Apache License
/** {@inheritDoc} */ public boolean check(MavenProject mavenproject, Log log) throws MojoExecutionException, MojoFailureException { String message = ""; if (mavenproject.getPackaging().equals("pom")) { return true; }/*w ww. j av a 2s .c o m*/ for (int i = 0; i < files.length; i++) { if (!new File(mavenproject.getBasedir(), files[i]).exists()) { message += NOT_FOUND + files[i] + "\n"; } } for (int i = 0; i < exFiles.length; i++) { if (new File(mavenproject.getBasedir(), exFiles[i]).exists()) { message += FOUND + exFiles[i] + "\n"; } } if (!message.isEmpty()) { throw new MojoFailureException(message); } return true; }
From source file:org.universAAL.support.directives.checks.LicenseFileCheckFix.java
License:Apache License
/** {@inheritDoc} */ public void fix(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException { // does not try NOTICE.txt! for (int i = 0; i < files.length - 1; i++) { File lf = new File(mavenProject.getBasedir(), files[i]); if (!lf.exists()) { try { copyFile(files[i], lf);//ww w .ja v a2 s .c o m } catch (IOException e) { } } } if (!new File(mavenProject.getBasedir(), files[files.length - 1]).exists()) { generateNoticeFile(mavenProject); } for (int i = 0; i < exFiles.length; i++) { File lf = new File(mavenProject.getBasedir(), exFiles[i]); if (lf.exists()) { lf.delete(); } } }
From source file:org.universAAL.support.directives.checks.LicenseFileCheckFix.java
License:Apache License
/** * @param mavenProject/*from www . j a va2 s . c om*/ */ private void generateNoticeFile(MavenProject mavenProject) { File notice = new File(mavenProject.getBasedir(), files[files.length - 1]); // TODO use mavenProject.getDependencies() to generate notice. }
From source file:org.universAAL.support.directives.checks.LicenseHeaderCheckFix.java
License:Apache License
/** {@inheritDoc} */ public boolean check(MavenProject mavenproject, Log log) throws MojoExecutionException, MojoFailureException { SourceExplorer se = new SourceExplorer(this); ArrayList<File> conflicted = se.walk(mavenproject.getBasedir().getAbsolutePath() + "/src/main/java/"); if (conflicted.size() > 0) { String m = "The following Files seem not to have a proper License Header:\n"; for (File f : conflicted) { m += "\t" + f.getAbsolutePath() + "\n"; }//ww w . j av a 2 s . c om m += "Make sure all your classes have an Apache Software Licence Header\n" + " see license at http://www.apache.org/licenses/LICENSE-2.0"; throw new MojoFailureException(m); } return true; }
From source file:org.universAAL.support.directives.checks.MainMethodCheck.java
License:Apache License
/** {@ inheritDoc} */ public boolean check(MavenProject mavenproject, Log log) throws MojoExecutionException, MojoFailureException { SourceExplorer se = new SourceExplorer(this); ArrayList<File> conflicted = se.walk(mavenproject.getBasedir() + "/src/main/java/"); if (conflicted.size() > 0) { String m = "The following Files contain a main method:\n"; for (java.util.Iterator<File> iterator = conflicted.iterator(); iterator.hasNext();) { m += "\t" + iterator.next().getAbsolutePath() + "\n"; }/* w w w .j a v a 2s. c o m*/ m += "There should not be any main method in a Library. Consider moving this code to a Junit Test."; throw new MojoFailureException(m); } return true; }
From source file:org.universAAL.support.directives.checks.ModulesCheckFix.java
License:Apache License
/** * Checks the project is a POM and a parent POM (ie it has no source). * @param mavenProject2/*w ww .j a v a2 s. com*/ * @param log log element to output log info. * @return */ private boolean isAparentPOM(MavenProject mavenProject2, Log log) { boolean isAPOM = mavenProject2.getPackaging().equals("pom"); boolean containsSRC = false; for (File f : mavenProject2.getBasedir().listFiles()) { if (f.isDirectory()) { containsSRC |= f.getName().contains("src"); log.debug(f.getName()); log.debug(Boolean.toString(containsSRC)); } } return isAPOM & !containsSRC; }
From source file:org.universAAL.support.directives.checks.ModulesCheckFix.java
License:Apache License
/** * Check whether the pom modules are in the following disposition: * <br>//from ww w. j a v a2 s.co m * <pre> * parentFolder * L pom.xml * L Module1 * L pom.xml * : * L ModuleN * L pom.xml * </pre> * ie: all of the modules of the pom are children. * @param mavenProject2 * @param log * @return */ private boolean isOfCommonType(MavenProject mp, Log log) { List<String> listed = (List<String>) mp.getModules(); boolean common = true; for (String m : listed) { File mDir = new File(mp.getBasedir(), m); log.debug("checking \n -" + mp.getBasedir().getAbsolutePath() + "\n -" + mDir.getAbsolutePath()); try { /* * for all of the modules: * the parent folder of the module is the same as the parent POMs folder */ common &= mp.getBasedir().equals(mDir.getCanonicalFile().getParentFile()); } catch (IOException e) { log.error(e); } log.debug(Boolean.toString(common)); } return listed.size() > 0 && common; }
From source file:org.universAAL.support.directives.checks.ModulesCheckFix.java
License:Apache License
private boolean passRootCheckCommonType(MavenProject mavenProject2, Log log) { List<String> mods = (List<String>) mavenProject2.getModules(); List<File> listed = new ArrayList<File>(); for (String m : mods) { try {// www.j av a 2 s .com listed.add(new File(mavenProject2.getBasedir(), m).getCanonicalFile()); } catch (IOException e) { log.error(e); } } //gather the existent modules File dir = mavenProject2.getBasedir(); for (File f : dir.listFiles()) { String rel = f.getName(); if (f.isDirectory() && directoryContains(f, "pom.xml") && !listed.contains(f) // it is not already listed && !rel.contains(SVN_FOLDER) // it is not the svn folder ) { toBeFixed.add(rel); log.debug("Found not listed module : " + rel); } } return toBeFixed.isEmpty(); }
From source file:org.universAAL.support.directives.checks.ModulesCheckFix.java
License:Apache License
private boolean passRootCheckSiblingType(MavenProject mavenProject2, Log log) { List<String> listed = (List<String>) mavenProject2.getModules(); //gather the existent modules File dir = mavenProject2.getBasedir().getParentFile(); for (File f : dir.listFiles()) { String rel = "../" + f.getName(); if (f.isDirectory() && directoryContains(f, "pom.xml") && !listed.contains(rel) // it is not already listed && !rel.endsWith(mavenProject2.getBasedir().getName()) // it is not the parent project && !rel.contains(SVN_FOLDER) // it is not the svn folder ) {/*from w w w . ja va 2s .com*/ toBeFixed.add(rel); log.debug("Found not listed module : " + rel); } } return toBeFixed.isEmpty(); }
From source file:org.universAAL.support.directives.checks.ParentGForgePropertyCheck.java
License:Apache License
private String getCorrectPropValue(MavenProject mavenProject, Log log) throws SVNException, MalformedURLException, Exception { String correctValue = getSVNURL(mavenProject.getBasedir()); URL u = new URL(correctValue); correctValue = u.getPath().split("/")[1]; log.debug("Determined Correct Value for " + PROP + ": " + correctValue); return correctValue; }