List of usage examples for org.apache.maven.plugin.logging Log warn
void warn(Throwable error);
From source file:org.primefaces.extensions.optimizerplugin.optimizer.AbstractOptimizer.java
License:Apache License
protected void deleteFilesIfNecessary(ResourcesSetAdapter rsa, Log log) { if (rsa.getAggregation().isRemoveIncluded() && rsa.getFiles().size() > 0) { for (File file : rsa.getFiles()) { if (file.exists() && !file.delete()) { log.warn("File " + file.getName() + " could not be deleted after aggregation."); }/* www . j ava 2 s.c o m*/ } } }
From source file:org.primefaces.extensions.optimizerplugin.optimizer.ClosureCompilerOptimizer.java
License:Apache License
@Override public void optimize(final ResourcesSetAdapter rsAdapter, final Log log) throws MojoExecutionException { ResourcesSetJsAdapter rsa = (ResourcesSetJsAdapter) rsAdapter; CompilationLevel compLevel = rsa.getCompilationLevel(); CompilerOptions options = new CompilerOptions(); compLevel.setOptionsForCompilationLevel(options); WarningLevel warnLevel = rsa.getWarningLevel(); warnLevel.setOptionsForWarningLevel(options); Compiler.setLoggingLevel(Level.WARNING); try {/*w w w .j a va2 s .co m*/ Charset cset = Charset.forName(rsa.getEncoding()); if (rsa.getAggregation() == null) { // no aggregation for (File file : rsa.getFiles()) { log.info("Optimize JS file " + file.getName() + " ..."); // statistic addToOriginalSize(file); // path of the original file String path = file.getCanonicalPath(); String outputFilePath = null; String outputSourceMapDir = null; File sourceMapFile = null; File sourceFile; if (rsa.getSourceMap() != null) { // setup source map outputFilePath = file.getCanonicalPath(); outputSourceMapDir = rsa.getSourceMap().getOutputDir(); sourceMapFile = setupSourceMapFile(options, rsa.getSourceMap(), outputFilePath); // create an empty file with ...source.js from the original one sourceFile = getFileWithSuffix(path, OUTPUT_FILE_SUFFIX); if (StringUtils.isNotBlank(rsa.getSuffix())) { // rename original file as ...source.js FileUtils.rename(file, sourceFile); } else { // copy content of the original file to the ...source.js FileUtils.copyFile(file, sourceFile); } } else { sourceFile = file; } // compile List<SourceFile> interns = new ArrayList<SourceFile>(); interns.add(SourceFile.fromFile(sourceFile, cset)); Compiler compiler = compile(log, interns, options, rsa.isFailOnWarning()); if (StringUtils.isNotBlank(rsa.getSuffix())) { // write compiled content into the new file File outputFile = getFileWithSuffix(path, rsa.getSuffix()); Files.write(compiler.toSource(), outputFile, cset); if (sourceMapFile != null) { // write sourceMappingURL into the minified file writeSourceMappingURL(outputFile, sourceMapFile, rsa.getSourceMap().getSourceMapRoot(), cset, log); } // statistic addToOptimizedSize(outputFile); } else { // path of temp. file String pathOptimized = FileUtils.removeExtension(path) + OPTIMIZED_FILE_EXTENSION; // create a new temp. file File outputFile = new File(pathOptimized); Files.touch(outputFile); // write compiled content into the new file and rename it (overwrite the original file) Files.write(compiler.toSource(), outputFile, cset); FileUtils.rename(outputFile, file); if (sourceMapFile != null) { // write sourceMappingURL into the minified file writeSourceMappingURL(file, sourceMapFile, rsa.getSourceMap().getSourceMapRoot(), cset, log); } // statistic addToOptimizedSize(file); } if (outputFilePath != null && sourceMapFile != null) { // write the source map Files.touch(sourceMapFile); writeSourceMap(sourceMapFile, outputFilePath, compiler.getSourceMap(), outputSourceMapDir, log); // move the source file to the source map dir moveToSourceMapDir(sourceFile, outputSourceMapDir, log); } } } else if (rsa.getAggregation().getOutputFile() != null) { // aggregation to one output file File outputFile = rsa.getAggregation().getOutputFile(); File aggrOutputFile = aggregateFiles(rsa, cset, true); // statistic long sizeBefore = addToOriginalSize(aggrOutputFile); if (!rsa.getAggregation().isWithoutCompress()) { // compressing for (File file : rsa.getFiles()) { log.info("Optimize JS file " + file.getName() + " ..."); } String outputFilePath = null; File sourceMapFile = null; if (rsa.getSourceMap() != null) { // setup source map outputFilePath = outputFile.getCanonicalPath(); sourceMapFile = setupSourceMapFile(options, rsa.getSourceMap(), outputFilePath); } // compile List<SourceFile> interns = new ArrayList<SourceFile>(); interns.add(SourceFile.fromFile(aggrOutputFile, cset)); Compiler compiler = compile(log, interns, options, rsa.isFailOnWarning()); // delete single files if necessary deleteFilesIfNecessary(rsa, log); // write the compiled content into a new file Files.touch(outputFile); Files.write(compiler.toSource(), outputFile, cset); if (outputFilePath != null && sourceMapFile != null) { // write sourceMappingURL into the minified file writeSourceMappingURL(outputFile, sourceMapFile, rsa.getSourceMap().getSourceMapRoot(), cset, log); // write the source map String outputSourceMapDir = rsa.getSourceMap().getOutputDir(); Files.touch(sourceMapFile); writeSourceMap(sourceMapFile, outputFilePath, compiler.getSourceMap(), outputSourceMapDir, log); // move the source file moveToSourceMapDir(aggrOutputFile, outputSourceMapDir, log); } else { // delete the temp. aggregated file ...source.js if (aggrOutputFile.exists() && !aggrOutputFile.delete()) { log.warn("Temporary file " + aggrOutputFile.getName() + " could not be deleted."); } } // statistic addToOptimizedSize(sizeBefore - outputFile.length()); } else { // delete single files if necessary deleteFilesIfNecessary(rsa, log); // rename aggregated file if necessary renameOutputFileIfNecessary(rsa, aggrOutputFile); // statistic addToOptimizedSize(sizeBefore); } } else { // should not happen log.error("Wrong plugin's internal state."); } } catch (Exception e) { throw new MojoExecutionException("Resources optimization failure: " + e.getLocalizedMessage(), e); } }
From source file:org.primefaces.extensions.optimizerplugin.optimizer.ClosureCompilerOptimizer.java
License:Apache License
protected void evalResult(Result result, Log log, boolean failOnWarning) throws MojoExecutionException { if (result.warnings != null) { for (JSError warning : result.warnings) { log.warn(warning.toString()); }// ww w . j a v a 2 s .c om } if (result.warnings != null && result.warnings.length > 0 && failOnWarning) { throw new MojoExecutionException("Resources optimization failure. Please fix warnings and try again."); } if (result.errors != null) { for (JSError error : result.errors) { log.error(error.toString()); } } if (result.errors != null && result.errors.length > 0) { throw new MojoExecutionException("Resources optimization failure. Please fix errors and try again."); } if (!result.success) { throw new MojoExecutionException("Resources optimization failure. Please fix errors and try again."); } }
From source file:org.pustefixframework.maven.plugins.GenerateSCodes.java
License:Open Source License
public static Result generate(String infoFile, String resDir, File genDir, String module, boolean dynamic, Log log) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); File file = new File(resDir, infoFile); Document doc = db.parse(file); String nsuri = doc.getDocumentElement().getAttribute("xmlns"); if (nsuri.isEmpty()) { log.warn("Statuscode info file '" + infoFile + "' declares no namespace."); } else if (!nsuri.equals(NS_STATUSCODEINFO)) { log.warn("Statuscode info file '" + infoFile + "' declares wrong namespace: " + nsuri); }/* w w w . j av a 2 s . co m*/ NodeList scElems = doc.getDocumentElement().getElementsByTagName("statuscodes"); List<String> genClasses = new ArrayList<String>(); List<String> allClasses = new ArrayList<String>(); for (int i = 0; i < scElems.getLength(); i++) { Element scElem = (Element) scElems.item(i); String className = scElem.getAttribute("class"); List<String> scXmlFiles = new ArrayList<String>(); NodeList fileElems = scElem.getElementsByTagName("file"); for (int j = 0; j < fileElems.getLength(); j++) { Element fileElem = (Element) fileElems.item(j); String filePath = fileElem.getTextContent(); String res = null; if (!filePath.startsWith("/")) { // try to get resource relative to info file String path = infoFile; int ind = path.lastIndexOf(File.separatorChar); if (ind > -1) { path = path.substring(0, ind); } path += File.separator + filePath; File tmp = new File(resDir, path); if (tmp.exists()) res = path; } if (res == null) { // try to get resource relative to the resource dir File tmp = new File(resDir, filePath); if (tmp.exists()) res = filePath; } if (res == null) throw new RuntimeException("Statusmessage file not found: " + filePath); if (res.startsWith(File.separator)) { res = res.substring(1); } scXmlFiles.add(res); } boolean generated = generate(scXmlFiles, resDir, genDir, className, module, dynamic); if (generated) genClasses.add(className); allClasses.add(className); } return new Result(allClasses, genClasses); }
From source file:org.pustefixframework.maven.plugins.ModuleDescriptor.java
License:Open Source License
public static ModuleDescriptor read(URL url, Log log) throws Exception { ModuleDescriptor moduleInfo;/*www . ja v a 2s. com*/ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); InputStream in = url.openStream(); Document document; try { document = builder.parse(url.openStream()); } finally { in.close(); } Element root = document.getDocumentElement(); if (root.getLocalName().equals("module-descriptor")) { String nsuri = root.getNamespaceURI(); if (nsuri == null) { log.warn("Module descriptor file '" + url.toString() + "' declares no namespace."); } else if (!nsuri.equals(NS_MODULE_DESCRIPTOR)) { log.warn("Module descriptor file '" + url.toString() + "' declares wrong namespace: " + nsuri); } Element nameElem = getSingleChildElement(root, "module-name", true); String name = nameElem.getTextContent().trim(); if (name.equals("")) throw new Exception("Text content of element 'module-name' must not be empty!"); moduleInfo = new ModuleDescriptor(url, name); Element resPathElem = getSingleChildElement(root, "resource-path", false); if (resPathElem != null) { String resPath = resPathElem.getTextContent().trim(); if (resPath.length() > 0) { if (!resPath.startsWith("/")) { resPath = "/" + resPath; } if (resPath.endsWith("/")) { resPath = resPath.substring(0, resPath.length() - 1); } moduleInfo.setResourcePath(resPath); } } Element editElem = getSingleChildElement(root, "content-editable", false); if (editElem != null) { boolean editable = Boolean.valueOf(editElem.getTextContent()); moduleInfo.setContentEditable(editable); } Element searchElem = getSingleChildElement(root, "default-search", false); if (searchElem != null) { moduleInfo.setDefaultSearchable(true); String priority = searchElem.getAttribute("priority").trim(); if (priority.length() > 0) { moduleInfo.setDefaultSearchPriority(Integer.parseInt(priority)); } List<Element> filterAttrElems = getChildElements(searchElem, "filter-attribute"); for (Element filterAttrElem : filterAttrElems) { String filterAttrName = filterAttrElem.getAttribute("name"); if (filterAttrName.equals("")) throw new Exception("Element 'filter-attribute' requires 'name' attribute!"); String filterAttrValue = filterAttrElem.getAttribute("value"); if (filterAttrValue.equals("")) throw new Exception("Element 'filter-attribute' requires 'value' attribute!"); moduleInfo.addDefaultSearchFilterAttribute(filterAttrName, filterAttrValue); } } Element overElem = getSingleChildElement(root, "override-modules", false); if (overElem != null) { List<Element> filterAttrElems = getChildElements(overElem, "filter-attribute"); for (Element filterAttrElem : filterAttrElems) { String filterAttrName = filterAttrElem.getAttribute("name"); if (filterAttrName.equals("")) throw new Exception("Element 'filter-attribute' requires 'name' attribute!"); String filterAttrValue = filterAttrElem.getAttribute("value"); if (filterAttrValue.equals("")) throw new Exception("Element 'filter-attribute' requires 'value' attribute!"); moduleInfo.addModuleOverrideFilterAttribute(filterAttrName, filterAttrValue); } List<Element> modElems = getChildElements(overElem, "module"); for (Element modElem : modElems) { String modName = modElem.getAttribute("name").trim(); if (modName.equals("")) throw new Exception("Element 'module' requires 'name' attribute!"); List<Element> resElems = getChildElements(modElem, "resource"); for (Element resElem : resElems) { String resPath = resElem.getAttribute("path").trim(); if (resPath.equals("")) throw new Exception("Element 'resource' requires 'path' attribute!"); moduleInfo.addOverridedResource(modName, resPath); } } } Element staticElem = getSingleChildElement(root, "static", false); if (staticElem != null) { List<Element> pathElems = getChildElements(staticElem, "path"); for (Element pathElem : pathElems) { String path = pathElem.getTextContent().trim(); if (!path.equals("")) { if (!path.startsWith("/")) path = "/" + path; if (path.endsWith("/")) path = path.substring(0, path.length() - 1); if (path.equals("") || path.equals(moduleInfo.getResourcePath())) path = "/"; else if (path.startsWith(moduleInfo.getResourcePath())) path = path.substring(moduleInfo.getResourcePath().length()); boolean i18n = false; String i18nAttr = pathElem.getAttribute("i18n").trim(); if (i18nAttr.length() > 0) { i18n = Boolean.parseBoolean(i18nAttr); } moduleInfo.addStaticPath(path, i18n); } } } } else throw new Exception("Illegal module descriptor"); return moduleInfo; }
From source file:org.sonarsource.scanner.maven.bootstrap.JavaVersionResolver.java
License:Open Source License
public JavaVersionResolver(MavenSession session, LifecycleExecutor lifecycleExecutor, Log log) { this.session = session; this.log = log; this.mojoExecutions = new LinkedList<>(); try {//from w w w.j a va 2 s . co m this.mojoExecutions = lifecycleExecutor.calculateExecutionPlan(session, true, COMPILE_GOAL) .getMojoExecutions(); } catch (Exception e) { log.warn( String.format("Failed to get mojo executions for goal '%s': %s", COMPILE_GOAL, e.getMessage())); } }
From source file:org.spdx.maven.MavenToSpdxLicenseMapper.java
License:Apache License
private MavenToSpdxLicenseMapper(Log log) throws LicenseMapperException { // Can not instantiate directly - singleton class InputStream is = null;//w w w. j a v a 2 s . co m try { URL listedLicenseJsonUrl = new URL(LISTED_LICENSE_JSON_URL); //TODO: Uncomment the line below once the JSON file has been uploaded to the SPDX listed license website //is = listedLicenseJsonUrl.openStream(); } catch (MalformedURLException e) { if (log != null) { log.warn("Invalid JSON URL for SPDX listed licenses. Using cached version"); } } if (is == null) { // use the cached version is = LicenseManager.class.getClassLoader().getResourceAsStream(LISTED_LICENSE_JSON_PATH); } InputStreamReader reader = new InputStreamReader(is); try { initializeUrlMap(reader, log); } finally { try { reader.close(); } catch (IOException e) { if (log != null) { log.warn("IO error closing listed license reader: " + e.getMessage()); } } } }
From source file:org.teatrove.maven.plugins.teacompiler.TeaCompilerMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { final Log logger = getLog(); // Create the Helper for the Context Class Builder ContextClassBuilderHelper helper = new DefaultContextClassBuilderHelper(session, new TeaCompilerExpressionEvaluator(session, translator, project), logger, container, this.getClass().getClassLoader(), rootPackage); // Merge the contexts final Class<?> contextClass; try {//from ww w . j av a2s . c o m if (this.context == null) { if (contextClassBuilder == null) { throw new MojoExecutionException( "Either context or contextClassBuilder parameter is required."); } contextClass = contextClassBuilder.getContextClass(helper); } else { contextClass = Class.forName(this.context); } } catch (ContextClassBuilderException e) { throw new MojoExecutionException("Unable to find or create the Context.", e); } catch (ClassNotFoundException e) { throw new MojoExecutionException("Unable to load the Context.", e); } final File realOutputDirectory = new File(outputDirectory, rootPackage.replace('.', File.separatorChar)); realOutputDirectory.mkdirs(); if (sourceDirectories == null || sourceDirectories.length == 0) { sourceDirectories = new File[] { defaultSourceDirectory }; } else { // Filter out any that don't exist List<File> existing = new ArrayList<File>(sourceDirectories.length); for (File sourceDirectory : sourceDirectories) { if (sourceDirectory.exists()) { existing.add(sourceDirectory); } else if (logger.isDebugEnabled()) { logger.debug("Removing source directory because it does not exist. [" + sourceDirectory + "]."); } } sourceDirectories = existing.toArray(new File[existing.size()]); } final Compiler compiler = new Compiler(rootPackage, realOutputDirectory, encoding, 0); for (File sourceDirectory : sourceDirectories) { compiler.addCompilationProvider(new FileCompilationProvider(sourceDirectory)); } compiler.setClassLoader(contextClass.getClassLoader()); compiler.setRuntimeContext(contextClass); compiler.setForceCompile(force); compiler.addCompileListener(new CompileListener() { public void compileError(CompileEvent e) { logger.error(e.getDetailedMessage()); } public void compileWarning(CompileEvent e) { logger.warn(e.getDetailedMessage()); } }); compiler.setExceptionGuardianEnabled(guardian); final String[] names; try { if (includes == null || includes.length == 0) { names = compiler.compileAll(true); } else { names = compiler.compile(includes); } } catch (IOException e) { throw new MojoExecutionException("I/O error while compiling templates.", e); } final int errorCount = compiler.getErrorCount(); if (errorCount > 0) { String msg = errorCount + " error" + (errorCount != 1 ? "s" : ""); if (failOnError) { throw new MojoFailureException(msg); } else if (logger.isWarnEnabled()) { logger.warn(msg); } } final int warningCount = compiler.getWarningCount(); if (warningCount > 0) { String msg = warningCount + " warning" + (warningCount != 1 ? "s" : ""); if (failOnWarning) { throw new MojoFailureException(msg); } else if (logger.isWarnEnabled()) { logger.warn(msg); } } if (logger.isInfoEnabled()) { logger.info("Compiled the following templates:"); Arrays.sort(names); for (String name : names) { logger.info(name); } } }
From source file:org.universAAL.support.directives.checks.SVNIgnoreCheck.java
License:Apache License
/** {@inheritDoc} */ public boolean check(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException { this.log = log; SVNClientManager cli = SVNClientManager.newInstance(); log.debug("checking svn ignore Rules in: " + mavenProject.getBasedir().getPath()); try {//from w ww . j av a2 s. c o m wcCli = cli.getWCClient(); SVNPropertyData pd = wcCli.doGetProperty(mavenProject.getBasedir(), SVNProperty.IGNORE, SVNRevision.WORKING, SVNRevision.WORKING); boolean changed = false; if (pd == null) { changed = true; prop = ""; for (int i = 0; i < ignores.length; i++) prop += ignores[i] + "\n"; } else { prop = pd.getValue().getString(); log.debug("Ignore Property contains: " + prop);// .split("\n")[0] for (int i = 0; i < ignores.length; i++) { if (!prop.contains(ignores[i]) && exists(mavenProject, ignores[i])) { prop += ignores[i] + "\n"; changed = true; } } } if (changed) { String err = NO_IGNORES; for (int i = 0; i < ignores.length; i++) { err += "\n\t" + ignores[i]; } throw new MojoFailureException(err); } } catch (SVNException e) { e.printStackTrace(); log.warn("SVN Error."); log.warn("directory seems not to be a local SVN working copy."); return false; } return true; }
From source file:org.yuanheng.cookcc.maven.JavacTask.java
License:Apache License
public void execute(Log log, Compiler compiler, CompilerConfiguration config, String javaSrcDir, String cookccPath) throws MojoExecutionException { File file = new File(m_src); if (!file.isFile()) { throw new MojoExecutionException("File " + m_src + " does not exist."); }//from w w w . j a v a 2 s . c om try { for (Option option : m_options) { if (option.arg == null) config.addCompilerCustomArgument("-A" + option.opt, null); else config.addCompilerCustomArgument("-A" + option.opt + "=" + option.arg, null); } HashSet<File> set = new HashSet<File>(); m_src.replace('/', File.separatorChar); log.info("CookCC is processing " + m_src); set.add(new File(m_src)); config.setSourceFiles(set); String[] args = compiler.createCommandLine(config); String msg = "javac"; for (String arg : args) msg += " " + arg; log.debug(msg); log.debug("Using compiler: " + compiler.getClass()); CompilerResult result = compiler.performCompile(config); log.debug("Success: " + result.isSuccess()); boolean hasError = false; StringBuilder errorMessages = new StringBuilder(); errorMessages.append( "CookCC reported an error. Please use mvn -X clean cookcc:run to display the full javac command to execute cookcc and reproduce the error message.\n"); log.debug("CompilerMessages: " + result.getCompilerMessages().size()); for (CompilerMessage message : result.getCompilerMessages()) { CompilerMessage.Kind kind = message.getKind(); switch (kind) { case WARNING: log.warn(message.toString()); break; case ERROR: log.error(message.toString()); errorMessages.append(message.getMessage()).append('\n'); hasError = true; break; default: log.info(kind + ": " + message.toString()); break; } } if (hasError || !result.isSuccess()) throw new MojoExecutionException(errorMessages.toString()); } catch (CompilerException ex) { throw new MojoExecutionException("Error compiling code", ex); } }