@SuppressWarnings("unchecked") public void execute() throws MojoExecutionException, MojoFailureException { try { if (failOnWarning) { jswarn = true; } jsErrorReporter_ = new ErrorReporter4Mojo(getLog(), jswarn); beforeProcess(); processDir(sourceDirectory, outputDirectory, null, null, true); for (Resource resource : resources) { File destRoot = outputDirectory; if (resource.getTargetPath() != null) { destRoot = new File(outputDirectory, resource.getTargetPath()); } processDir( new File(resource.getDirectory()), destRoot, resource.getIncludes(), resource.getExcludes(), true); } processDir(warSourceDirectory, webappDirectory, null, null, false); afterProcess(); getLog() .info( String.format( "nb warnings: %d, nb errors: %d", jsErrorReporter_.getWarningCnt(), jsErrorReporter_.getErrorCnt())); if (failOnWarning && (jsErrorReporter_.getWarningCnt() > 0)) { throw new MojoFailureException( "warnings on " + this.getClass().getSimpleName() + "=> failure ! (see log)"); } } catch (RuntimeException exc) { throw exc; } catch (MojoFailureException exc) { throw exc; } catch (MojoExecutionException exc) { throw exc; } catch (Exception exc) { throw new MojoExecutionException("wrap: " + exc.getMessage(), exc); } }
protected void processDir( File srcRoot, File destRoot, List<String> srcIncludes, List<String> srcExcludes, boolean destAsSource) throws Exception { if ((srcRoot == null) || (!srcRoot.exists())) { return; } if (destRoot == null) { throw new MojoFailureException("destination directory for " + srcRoot + " is null"); } DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(srcRoot); if ((srcIncludes != null) && !srcIncludes.isEmpty()) { scanner.setIncludes(srcIncludes.toArray(EMPTY_STRING_ARRAY)); } if ((includes != null) && !includes.isEmpty()) { scanner.setIncludes(includes.toArray(EMPTY_STRING_ARRAY)); } else { scanner.setIncludes(getDefaultIncludes()); } if ((srcExcludes != null) && !srcExcludes.isEmpty()) { scanner.setExcludes(srcExcludes.toArray(EMPTY_STRING_ARRAY)); } if ((excludes != null) && !excludes.isEmpty()) { scanner.setExcludes(excludes.toArray(EMPTY_STRING_ARRAY)); } scanner.addDefaultExcludes(); scanner.scan(); for (String name : scanner.getIncludedFiles()) { SourceFile src = new SourceFile(srcRoot, destRoot, name, destAsSource); jsErrorReporter_.setDefaultFileName( "..." + src.toFile() .getAbsolutePath() .substring(project.getBasedir().getAbsolutePath().length())); processFile(src); } }