List of usage examples for org.apache.maven.plugin.logging Log warn
void warn(Throwable error);
From source file:net.radai.easyavro.maven.CodegenMojo.java
License:Open Source License
public void execute() throws MojoExecutionException, MojoFailureException { Log log = getLog(); //check parameters supplementDefaultConfiguration();/* w w w . j av a 2s .co m*/ //find source files Set<Path> files = findIncludedFiles(); if (files.isEmpty()) { log.warn("found no avro files"); return; } log.info("using " + inputEncoding + " to parse " + files.size() + " avro file(s) and " + outputEncoding + " to generate java files"); //generate java code from source files AvroCodeGenerator generator = new AvroCodeGenerator(); generator.setInputEncoding(inputEncoding); generator.setOutputEncoding(outputEncoding); try { generator.generateSpecificClasses(files, outputPath.toPath()); } catch (IOException e) { throw new MojoFailureException("unable to generate java classes from avro files", e); } //add generated java code to the current maven project project.addCompileSourceRoot(outputPath.toString()); }
From source file:net.revelc.code.formatter.FormatterMojo.java
License:Apache License
/** * Read file hash cache file.// w w w . jav a 2s . c o m * * @return the properties */ private Properties readFileHashCacheFile() { Properties props = new Properties(); Log log = getLog(); if (!this.targetDirectory.exists()) { this.targetDirectory.mkdirs(); } else if (!this.targetDirectory.isDirectory()) { log.warn("Something strange here as the " + "supposedly target directory is not a directory."); return props; } File cacheFile = new File(this.targetDirectory, CACHE_PROPERTIES_FILENAME); if (!cacheFile.exists()) { return props; } try (final BufferedInputStream stream = new BufferedInputStream(new FileInputStream(cacheFile))) { props.load(stream); } catch (FileNotFoundException e) { log.warn("Cannot load file hash cache properties file", e); } catch (IOException e) { log.warn("Cannot load file hash cache properties file", e); } return props; }
From source file:net.roboconf.maven.MavenPluginUtils.java
License:Apache License
/** * Formats a Roboconf errors and outputs it in the logs. * @param error an error//from ww w . j a v a 2 s . com * @param log the Maven logger * @return a string builder with the output */ public static StringBuilder formatErrors(Collection<? extends RoboconfError> errors, Log log) { StringBuilder result = new StringBuilder(); for (Map.Entry<RoboconfError, String> entry : RoboconfErrorHelpers.formatErrors(errors, null, true) .entrySet()) { if (entry.getKey().getErrorCode().getLevel() == ErrorLevel.WARNING) log.warn(entry.getValue()); else log.error(entry.getValue()); result.append(entry.getValue()); result.append("\n"); } return result; }
From source file:net.roboconf.maven.MavenUtils.java
License:Apache License
/** * Formats a Roboconf errors and outputs it in the logs. * @param error an error/* www. ja v a 2 s . c om*/ * @param log the Maven logger * @return a string builder with the output */ public static StringBuilder formatError(RoboconfError error, Log log) { StringBuilder sb = new StringBuilder(); sb.append("[ "); sb.append(error.getErrorCode().getCategory().toString().toLowerCase()); sb.append(" ] "); sb.append(error.getErrorCode().getMsg()); if (!Utils.isEmptyOrWhitespaces(error.getDetails())) sb.append(" " + error.getDetails()); if (!sb.toString().endsWith(".")) sb.append("."); if (error instanceof ParsingError) { sb.append(" See "); sb.append(((ParsingError) error).getFile().getName()); sb.append(", line "); sb.append(((ParsingError) error).getLine()); sb.append("."); } if (error.getErrorCode().getLevel() == ErrorLevel.WARNING) log.warn(sb.toString()); else log.error(sb.toString()); return sb; }
From source file:net.sourceforge.mavenhippo.FileManager.java
License:Apache License
public FileManager(File sourceRoot, Log log, boolean deleteIfExits) throws FileManagerException { if (sourceRoot.exists()) { if (!sourceRoot.isDirectory()) { throw new IllegalArgumentException("sourceRoot is required to be a directory."); } else if (deleteIfExits) { if (forcefulDeletion(sourceRoot)) { log.info("source root folder was deleted."); createSourceRootFolder(sourceRoot, log); } else { if (sourceRoot.exists()) { log.warn("source root folder could not be cleaned."); } else { createSourceRootFolder(sourceRoot, log); }/*from w w w. j a v a 2 s . c om*/ } } } else { createSourceRootFolder(sourceRoot, log); } this.log = log; this.sourceRoot = sourceRoot; }
From source file:nl.geodienstencentrum.maven.plugin.sass.AbstractSassMojo.java
License:Apache License
/** * Builds the basic sass script./*from ww w . j a va 2 s. c om*/ * * @param sassScript * the sass script * @throws MojoExecutionException * the mojo execution exception */ protected void buildBasicSassScript(final StringBuilder sassScript) throws MojoExecutionException { final Log log = this.getLog(); sassScript.append("require 'rubygems'\n"); if (this.gemPaths.length > 0) { sassScript.append("env = { 'GEM_PATH' => [\n"); for (final String gemPath : this.gemPaths) { sassScript.append(" '").append(gemPath).append("',\n"); } final String gemPath = System.getenv("GEM_PATH"); if (gemPath != null) { for (final String p : gemPath.split(File.pathSeparator)) { sassScript.append(" '").append(p).append("',\n"); } } /* remove trailing comma+\n */ sassScript.setLength(sassScript.length() - 2); sassScript.append("\n] }\n"); sassScript.append("Gem.paths = env\n"); } for (final String gem : this.gems) { sassScript.append("require '").append(gem).append("'\n"); } sassScript.append("require 'sass/plugin'\n"); sassScript.append("require 'java'\n"); if (this.useCompass) { log.info("Running with Compass enabled."); log.warn( "Compass support is deprecated, it will be removed in version 3.0, see https://github.com/GeoDienstenCentrum/sass-maven-plugin/issues/77"); sassScript.append("require 'compass'\n"); sassScript.append("require 'compass/exec'\n"); sassScript.append("require 'compass/core'\n"); sassScript.append("require 'compass/import-once'\n"); if (compassConfigFile != null) { sassScript.append("Compass.add_project_configuration '").append(compassConfigFile.getAbsolutePath()) .append("'\n"); } else { sassScript.append("Compass.add_project_configuration \n"); } this.sassOptions.put("load_paths", "Compass.configuration.sass_load_paths"); } // Get all template locations from resources and set option // 'template_location' and // 'css_location' (to override default "./public/stylesheets/sass", // "./public/stylesheets") // remaining locations are added later with 'add_template_location' final Iterator<Entry<String, String>> templateLocations = this.getTemplateLocations(); if (templateLocations.hasNext()) { final Entry<String, String> location = templateLocations.next(); this.sassOptions.put("template_location", "'" + location.getKey() + "'"); this.sassOptions.put("css_location", "'" + location.getValue() + "'"); } // If not explicitly set place the cache location in the target dir if (!this.sassOptions.containsKey("cache_location")) { final File sassCacheDir = new File(this.buildDirectory, "sass_cache"); final String sassCacheDirStr = sassCacheDir.toString(); this.sassOptions.put("cache_location", "'" + FilenameUtils.separatorsToUnix(sassCacheDirStr) + "'"); } // Add the plugin configuration options sassScript.append("Sass::Plugin.options.merge!(\n"); for (final Iterator<Entry<String, String>> entryItr = this.sassOptions.entrySet().iterator(); entryItr .hasNext();) { final Entry<String, String> optEntry = entryItr.next(); final String opt = optEntry.getKey(); final String value = optEntry.getValue(); sassScript.append(" :").append(opt).append(" => ").append(value); if (entryItr.hasNext()) { sassScript.append(","); } sassScript.append('\n'); } sassScript.append(")\n"); // add remaining template locations with 'add_template_location' (need // to be done after options.merge) while (templateLocations.hasNext()) { final Entry<String, String> location = templateLocations.next(); sassScript.append("Sass::Plugin.add_template_location('").append(location.getKey()).append("', '") .append(location.getValue()).append("')\n"); } if (this.useBourbon) { log.info("Running with Bourbon enabled."); final String bDest = this.buildDirectory + "/bourbon"; this.extractBourbonResources(bDest); // sassScript.append("require 'bourbon'\n"); sassScript.append("Sass::Plugin.add_template_location('").append(bDest) .append("/app/assets/stylesheets', '").append(destination).append("')\n"); } // set up sass compiler callback for reporting sassScript.append( "Sass::Plugin.on_compilation_error {|error, template, css| $compiler_callback.compilationError(error.message, template, css) }\n"); sassScript.append( "Sass::Plugin.on_updated_stylesheet {|template, css| $compiler_callback.updatedStylesheeet(template, css) }\n"); sassScript.append( "Sass::Plugin.on_template_modified {|template| $compiler_callback.templateModified(template) }\n"); sassScript.append( "Sass::Plugin.on_template_created {|template| $compiler_callback.templateCreated(template) }\n"); sassScript.append( "Sass::Plugin.on_template_deleted {|template| $compiler_callback.templateDeleted(template) }\n"); // make ruby give use some debugging info when requested if (log.isDebugEnabled()) { sassScript.append("require 'pp'\n"); sassScript.append("pp Sass::Plugin.options\n"); if (this.useCompass) { sassScript.append("pp Compass.base_directory\n"); sassScript.append("pp Compass::Core.base_directory\n"); sassScript.append("pp Compass::configuration\n"); } } }
From source file:nl.geodienstencentrum.maven.plugin.sass.report.SCSSLintMojo.java
License:Apache License
/** * Execute the lint script./*from ww w . j a v a 2s. c o m*/ * * @see org.apache.maven.plugin.Mojo#execute() * @throws MojoExecutionException when the execution of the plugin * errored * @throws MojoFailureException when the Sass compilation fails * */ @Override public void execute() throws MojoExecutionException, MojoFailureException { if (this.isSkip()) { return; } final Log log = this.getLog(); // create directory this.outputFile.getParentFile().mkdirs(); log.info("Linting Sass sources in: " + this.getSassSourceDirectory()); final StringBuilder sassScript = new StringBuilder(); this.buildBasicSassScript(sassScript); log.debug("scss-lint ruby script:\n" + sassScript); System.setProperty("org.jruby.embed.localcontext.scope", "threadsafe"); final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); final ScriptEngine jruby = scriptEngineManager.getEngineByName("jruby"); ScriptContext context = jruby.getContext(); ArrayList<String> argv = new ArrayList<>(); argv.add("--format=Checkstyle"); argv.add("-o" + this.outputFile); // argv.add("--config " + get config from some params,); argv.addAll(this.getSourceDirs()); // this.getSassSourceDirectory().getPath() context.setAttribute(ScriptEngine.ARGV, argv.toArray(new String[argv.size()]), ScriptContext.GLOBAL_SCOPE); try { log.info("Reporting scss lint in: " + this.outputFile.getAbsolutePath()); ExitCode result = ExitCode .getExitCode(Ints.checkedCast((Long) jruby.eval(sassScript.toString(), context))); log.debug("scss-lint result: " + result.toString()); switch (result) { case CODE_0: log.info(result.msg()); break; case CODE_1: log.warn(result.msg()); break; case CODE_2: log.error(result.toString()); if (this.failOnError) { throw new MojoFailureException(result.toString()); } case CODE_64: // fall through case CODE_66: // fall through case CODE_70: // fall through case CODE_78: // fall through default: log.error(result.toString()); throw new MojoExecutionException(result.toString()); } } catch (final ScriptException e) { throw new MojoExecutionException("Failed to execute scss-lint Ruby script:\n" + sassScript, e); } }
From source file:npanday.vendor.SettingsUtil.java
License:Apache License
/** * Replaces npanday settings from the given path or file. * * @param failIfFileNotFound//w w w .ja va 2 s.c o m * If <code>true</code>, fails, if the file can't be found. Else, * just leaves the settings untouched. * @return The new Settings Repository. * @throws MojoExecutionException If anything goes wrong reading or initializing the settings */ private static boolean overrideDefaultSettings(Log log, RepositoryRegistry repositoryRegistry, String settingsPathOrFile, boolean failIfFileNotFound) throws MojoExecutionException { File settingsFile = PathUtil.buildSettingsFilePath(settingsPathOrFile); if (!settingsFile.exists()) { if (failIfFileNotFound) { throw new MojoExecutionException( "NPANDAY-108-005: Configured settings file does not exist: " + settingsFile); } else { log.warn("NPANDAY-108-006: Settings file does not exist: " + settingsFile + "; current Mojo will adhere to configured defaults."); return false; } } SettingsRepository settingsRepository = findSettingsFromRegistry(repositoryRegistry); try { settingsRepository.clearAll(); } catch (OperationNotSupportedException e) { throw new MojoExecutionException("NPANDAY-108-006: Error clearing settings repository.", e); } try { settingsRepository.load(settingsFile.toURI().toURL()); log.debug("NPANDAY-108-007: Replaced default npanday-settings with contents from '" + settingsFile + "'."); return true; } catch (IOException e) { throw new MojoExecutionException("NPANDAY-108-003: Error loading " + settingsFile.getAbsolutePath(), e); } catch (NPandayRepositoryException e) { throw new MojoExecutionException("NPANDAY-108-004: Error loading settings repository.", e); } }
From source file:org.acmsl.dockerfile.maven.DockerfileMojo.java
License:Open Source License
/** * Executes Dockerfile Maven Plugin./* w ww .j a v a 2 s .c o m*/ * @param log the Maven log. * @param version the Dockerfile Maven Plugin version. * @throws MojoExecutionException if the process fails. */ protected void execute(@NotNull final Log log, final String version) throws MojoExecutionException { boolean running = false; @Nullable final File outputDirPath = getOutputDir(); if (outputDirPath != null) { //initialize directories @NotNull final File outputDir = outputDirPath.getAbsoluteFile(); if ((!outputDir.exists()) && (!outputDir.mkdirs())) { log.warn("Cannot create output folder: " + outputDir); } log.info("Running Dockerfile Maven Plugin " + version); running = true; } else { log.error("outputDir is null"); } if (!running) { log.error("NOT running Dockerfile Maven Plugin " + version); throw new MojoExecutionException("Dockerfile Maven Plugin could not start"); } }
From source file:org.acmsl.queryj.tools.maven.AntProjectAdapter.java
License:Open Source License
/** * See {@link Project#log(String)}./*from w w w.ja v a 2s. c o m*/ * @param message the message. * @param msgLevel either {@link Project#MSG_ERR}, {@link Project#MSG_WARN}, * {@link Project#MSG_INFO}, {@link Project#MSG_VERBOSE}, or {@link Project#MSG_DEBUG}. * @param log the {@link Log} instance. */ protected void log(@NotNull final String message, final int msgLevel, @NotNull final Log log) { switch (msgLevel) { case MSG_ERR: log.error(message); break; case MSG_WARN: log.warn(message); break; case MSG_VERBOSE: case MSG_DEBUG: log.debug(message); break; default: log.info(message); break; } }