Example usage for org.apache.maven.plugin.logging Log warn

List of usage examples for org.apache.maven.plugin.logging Log warn

Introduction

In this page you can find the example usage for org.apache.maven.plugin.logging Log warn.

Prototype

void warn(Throwable error);

Source Link

Document

Send an exception to the user in the warn error level.
The stack trace for this exception will be output when this error level is enabled.

Usage

From source file:com.github.lucapino.jira.helpers.IssuesReportHelper.java

License:Apache License

/**
 * Get a list of id:s for the columns that are to be included in the report.
 * This method also handles deprecated column names, which will still work.
 * If deprecated column names are used they generate a warning, indicating
 * the replacement column name./*from  www . j a va 2  s  .  c om*/
 *
 * @param columnNames The names of the columns
 * @param allColumns A mapping from column name to column id
 * @param deprecatedColumns A mapping from deprecated column name to column
 * id
 * @param log A log
 * @return A List of column id:s
 */
public static List<Integer> getColumnIds(String columnNames, Map<String, Integer> allColumns,
        Map<String, Integer> deprecatedColumns, Log log) {
    DualHashBidiMap bidiColumns = null;
    List<Integer> columnIds = new ArrayList<>();
    String[] columnNamesArray = columnNames.split(",");

    if (deprecatedColumns != null) {
        bidiColumns = new DualHashBidiMap(allColumns);
    }

    // Loop through the names of the columns, to validate each of them and add their id to the list
    for (String columnNamesNotTrimmed : columnNamesArray) {
        String columnName = columnNamesNotTrimmed.trim();
        if (allColumns.containsKey(columnName)) {
            columnIds.add(allColumns.get(columnName));
        } else if (deprecatedColumns != null && deprecatedColumns.containsKey(columnName)) {
            Integer columnId = deprecatedColumns.get(columnName);
            columnIds.add(columnId);
            if (log != null && bidiColumns != null) {
                log.warn("The columnName '" + columnName + "' has been deprecated." + " Please use "
                        + "the columnName '" + bidiColumns.getKey(columnId) + "' instead.");
            }
        }
    }
    return columnIds;
}

From source file:com.github.maven_nar.NarUtil.java

License:Apache License

public static int runCommand(final String cmd, final String[] args, final File workingDirectory,
        final String[] env, final TextStream out, final TextStream err, final TextStream dbg, final Log log,
        final boolean expectFailure) throws MojoExecutionException, MojoFailureException {
    final Commandline cmdLine = new Commandline();

    try {//from  w  ww .j a  v  a  2  s  .c om
        dbg.println("RunCommand: " + cmd);
        cmdLine.setExecutable(cmd);
        if (args != null) {
            for (final String arg : args) {
                dbg.println("  '" + arg + "'");
            }
            cmdLine.addArguments(args);
        }
        if (workingDirectory != null) {
            dbg.println("in: " + workingDirectory.getPath());
            cmdLine.setWorkingDirectory(workingDirectory);
        }

        if (env != null) {
            dbg.println("with Env:");
            for (final String element : env) {
                final String[] nameValue = element.split("=", 2);
                if (nameValue.length < 2) {
                    throw new MojoFailureException("   Misformed env: '" + element + "'");
                }
                dbg.println("   '" + nameValue[0] + "=" + nameValue[1] + "'");
                cmdLine.addEnvironment(nameValue[0], nameValue[1]);
            }
        }

        final Process process = cmdLine.execute();
        final StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), err);
        final StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), out);

        errorGobbler.start();
        outputGobbler.start();
        process.waitFor();
        final int exitValue = process.exitValue();
        dbg.println("ExitValue: " + exitValue);
        final int timeout = 5000;
        errorGobbler.join(timeout);
        outputGobbler.join(timeout);
        if (exitValue != 0 ^ expectFailure) {
            if (log == null) {
                System.err.println(err.toString());
                System.err.println(out.toString());
                System.err.println(dbg.toString());
            } else {
                log.warn(err.toString());
                log.warn(out.toString());
                log.warn(dbg.toString());
            }
            throw new MojoExecutionException("exit code: " + exitValue);
        }
        return exitValue;
    } catch (final MojoExecutionException e) {
        throw e;
    } catch (final Exception e) {
        throw new MojoExecutionException("Could not launch " + cmdLine, e);
    }
}

From source file:com.github.paulmoloney.maven.plugins.enforcer.AbstractToolChainAwareRule.java

License:Apache License

/**
 * Determines a path to a tool based on environment variables and subdirectory searches
 * @param tool//from   w ww .  j  av  a2s . c o  m
 * @param log
 * @param sysProperty
 * @param subDirs1
 * @param envArgs
 * @param subDirs2
 * @return The path to a tool or null if one is not found
 */
protected String findToolExecutable(String tool, Log log, String sysProperty, String[] subDirs1,
        String[] envArgs, String[] subDirs2) {
    log.warn("Falling back to env lookup for specified tool");

    String command = tool;
    try {
        Properties env = new Properties();
        env.putAll(getSession().getSystemProperties());
        env.putAll(getSession().getUserProperties());
        int envLen = null != env ? envArgs.length : 0;
        command = findExecutable(tool, env.getProperty(sysProperty), subDirs1);

        if (command == null) {
            if (null != envArgs) {
                for (int i = 0; i < envLen && executable == null; i++) {
                    command = findExecutable(tool, env.getProperty(envArgs[i]), subDirs2);
                    if (command != null) {
                        break;
                    }
                }
            }
        }
        log.warn("Using executable: " + command);
    } catch (IOException e) {
        log.error("Unable to find executable", e);
    }

    return command;
}

From source file:com.github.randomcodeorg.netmaven.netmaven.NetMavenSetupMojo.java

protected void printLicenseAndDisclaimerInfo(Log log, String path) {
    log.warn(
            "\nThe IKVM library is an external tool that can be used to access Java dependencies from the .NET-Framework."
                    + String.format(
                            "Please refer to the license file at '%s' to get more information about the terms and conditions",
                            PathBuilder.create(path).sub("LICENSE").build())
                    + " regarding the IKVM library and its dependencies."
                    + " The transformations which are applied by IKVM, might be a forbidden manipulation of third party property."
                    + " Please check the license descriptions of all (Java) dependencies that will or might be transformed by IKVM.\n\n"
                    + "DO NOT USE IKVM OR ANY JAVA DEPENDENCY IF YOU DON'T AGREE WITH THE REFERED LICENSES OR RESTRICTIONS.");
}

From source file:com.github.rvesse.airline.maven.GenerateMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (project == null)
        throw new MojoFailureException("Maven project was not injected into Mojo");
    if (pluginDescriptor == null)
        throw new MojoFailureException("Plugin Descriptor was not injected into Mojo");

    Log log = getLog();

    // Prepare the class realm
    prepareClassRealm();/*from w ww .  j  a v a 2  s  .  c om*/

    // Discover classes and get their meta-data as appropriate
    List<PreparedSource> sources = prepareSources(this.skipBadSources);
    if (sources.size() == 0) {
        log.info("No valid sources discovered so nothing to do");
        return;
    }

    // See how many of each type of output we have
    int commandOutputs, groupOutputs, cliOutputs;
    commandOutputs = groupOutputs = cliOutputs = 0;
    for (PreparedSource source : sources) {
        if (source.shouldOutputCommandHelp()) {
            commandOutputs++;
        } else if (source.shouldOutputGroupHelp()) {
            groupOutputs++;
        } else if (source.shouldOutputGlobalHelp()) {
            cliOutputs++;
        }
    }

    // Ensure directory is created
    ensureOutputDirectory();

    // Prepare default format options
    FormatOptions defaultOptions = this.defaultOptions == null ? new FormatOptions()
            : new FormatOptions(this.defaultOptions);
    log.debug(String.format("Default format options are %s", defaultOptions));

    // Prepare format mappings
    Map<String, FormatOptions> mappedOptions = prepareFormatMappings(defaultOptions);

    for (String format : formats) {
        // Prepare the format provider and the appropriate formatting
        // options
        FormatProvider provider = FormatMappingRegistry.find(format);
        if (provider == null) {
            if (failOnUnknownFormat)
                throw new MojoFailureException(
                        String.format("Format %s does not have a format mapping defined", format));
            log.debug(String.format("Format %s is unknown and was skipped", format));
            continue;
        }
        FormatOptions options = mappedOptions.get(format);
        if (options == null)
            options = defaultOptions;
        if (options != defaultOptions)
            log.debug(String.format("Format %s format options are %s", format, options));

        if (commandOutputs > 0) {
            // Command outputs
            CommandUsageGenerator commandGenerator = provider.getCommandGenerator(this.outputDirectory,
                    options);
            if (commandGenerator == null) {
                if (failOnUnsupportedOutputMode)
                    throw new MojoFailureException(
                            String.format("Command help is not supported by format %s", format));
                log.warn("Command help is not supported by format " + format);
            } else {
                log.info(String.format("Using command help generator %s for format %s",
                        commandGenerator.getClass(), format));

                // Generate command help
                for (PreparedSource source : sources) {
                    FormatOptions sourceOptions = source.getFormatOptions(options);
                    CommandUsageGenerator sourceCommandGenerator = commandGenerator;
                    if (source.isCommand()) {
                        if (!source.shouldOutputCommandHelp()) {
                            log.debug(String.format(
                                    "Skipping command help for %s because configured output mode is %s",
                                    source.getSourceClass(), source.getOutputMode()));
                            continue;
                        }

                        if (sourceOptions != options) {
                            // Source specific options and thus potentially
                            // generator
                            sourceCommandGenerator = prepareCommandGenerator(provider, source, sourceOptions);
                        }

                        outputCommandHelp(format, provider, sourceOptions, sourceCommandGenerator, source);
                    } else if (source.isGlobal()) {
                        if (!source.shouldOutputCommandHelp()) {
                            log.debug(String.format(
                                    "Skipping command help for %s because configured output mode is %s",
                                    source.getSourceClass(), source.getOutputMode()));
                            continue;
                        }
                        log.debug(String.format("Generating command help for all commands provided by CLI %s",
                                source.getSourceClass()));

                        if (sourceOptions != options) {
                            sourceCommandGenerator = prepareCommandGenerator(provider, source, sourceOptions);
                        }

                        // Firstly dump the default commands group and then
                        // dump
                        // the command groups
                        GlobalMetadata<Object> global = source.getGlobal();
                        outputCommandsInGroup(format, provider, sourceOptions, sourceCommandGenerator, source,
                                global.getDefaultGroupCommands(), global.getParserConfiguration(),
                                global.getName(), (String[]) null);
                        for (CommandGroupMetadata group : global.getCommandGroups()) {
                            if (group.isHidden() && !sourceOptions.includeHidden())
                                continue;

                            outputGroupCommandsHelp(format, provider, sourceOptions, sourceCommandGenerator,
                                    source, group, global.getParserConfiguration(), global.getName(),
                                    (String[]) null);
                        }
                    }
                }
            }
        } else {
            log.debug(
                    "Skipping command help as no configured sources were commands or had their output mode set to COMMAND");
        }

        if (groupOutputs > 0) {
            // Group Outputs
            CommandGroupUsageGenerator<Object> groupGenerator = provider.getGroupGenerator(this.outputDirectory,
                    options);
            if (groupGenerator == null) {
                if (failOnUnsupportedOutputMode)
                    throw new MojoFailureException(
                            String.format("Group help is not supported by format %s", format));
                log.warn("Group help is not supported by format " + format);
            } else {
                log.info(String.format("Using group help generator %s for format %s", groupGenerator.getClass(),
                        format));

                // Generate group help
                for (PreparedSource source : sources) {
                    if (source.isCommand())
                        continue;

                    if (source.isGlobal()) {
                        if (!source.shouldOutputGroupHelp()) {
                            log.debug(String.format(
                                    "Skipping group help for %s because configured output mode is %s",
                                    source.getSourceClass(), source.getOutputMode()));
                            continue;
                        }
                        CommandGroupUsageGenerator<Object> sourceGroupGenerator = groupGenerator;
                        FormatOptions sourceOptions = source.getFormatOptions(options);
                        if (sourceOptions != options) {
                            sourceGroupGenerator = prepareCommandGroupUsageGenerator(provider, source,
                                    sourceOptions);
                        }

                        GlobalMetadata<Object> global = source.getGlobal();
                        for (CommandGroupMetadata group : global.getCommandGroups()) {
                            outputGroupsHelp(format, provider, sourceOptions, sourceGroupGenerator, source,
                                    new CommandGroupMetadata[] { group }, global.getParserConfiguration(),
                                    global.getName());
                        }
                    }
                }
            }
        } else {
            log.debug("Skipping group help as no configured sources had their output mode set to GROUP");
        }

        if (cliOutputs > 0) {
            // CLI outputs
            GlobalUsageGenerator<Object> globalGenerator = provider.getGlobalGenerator(this.outputDirectory,
                    options);
            if (globalGenerator == null) {
                if (failOnUnsupportedOutputMode)
                    throw new MojoFailureException(
                            String.format("CLI help is not supported by format %s", format));
                log.warn("CLI help is not supported by format " + format);
            } else {
                log.info(String.format("Using CLI help generator %s for format %s", globalGenerator.getClass(),
                        format));

                // Generate global help
                for (PreparedSource source : sources) {
                    if (!source.isGlobal())
                        continue;

                    if (!source.shouldOutputGlobalHelp()) {
                        log.debug(String.format(
                                "Skipping global help for %s because configured output mode is %s",
                                source.getSourceClass(), source.getOutputMode()));
                        continue;
                    }

                    GlobalUsageGenerator<Object> sourceGlobalGenerator = globalGenerator;
                    FormatOptions sourceOptions = source.getFormatOptions(options);
                    if (sourceOptions != options) {
                        globalGenerator = prepareGlobalUsageGenerator(provider, source, sourceOptions);
                    }

                    outputGlobalHelp(format, provider, sourceOptions, sourceGlobalGenerator, source);
                }
            }
        } else {
            log.debug("Skipping command help as no configured sources were CLIs");
        }

    }
}

From source file:com.github.rvesse.airline.maven.Source.java

License:Apache License

public List<PreparedSource> prepare(Log log, boolean skipBadSources) throws MojoFailureException {
    List<PreparedSource> prepared = new ArrayList<>();
    for (String className : this.classes) {
        try {/*from   w  w  w  .  java 2  s.  c om*/
            Class<?> cls = getClass().getClassLoader().loadClass(className);
            if (cls.getAnnotation(Command.class) != null) {
                prepared.add(new PreparedSource(cls, null, MetadataLoader.loadCommand(cls), this.options,
                        this.outputMode));
            } else if (cls.getAnnotation(Cli.class) != null) {
                prepared.add(new PreparedSource(cls, MetadataLoader.loadGlobal(cls), null, this.options,
                        this.outputMode));
            } else {
                if (!skipBadSources)
                    throw new MojoFailureException(
                            String.format("Class %s is not annotated with @Cli or @Command", className));
                log.warn(String.format("Class %s is not annotated with @Cli or @Command", className));

            }
        } catch (MojoFailureException e) {
            // NB - If we get this then we aren't skipping bad sources so no need to check again
            throw e;
        } catch (ClassNotFoundException e) {
            if (!skipBadSources)
                throw new MojoFailureException(String.format("Failed to locate class %s", className), e);
            log.warn(String.format("Failed to locate class %s", className));
        } catch (Throwable e) {
            if (!skipBadSources)
                throw new MojoFailureException(String.format("Bad Airline metadata on class %s", className), e);
            log.warn(String.format("Bad Airline metadata on class %s", className));
        }
    }
    return prepared;
}

From source file:com.google.code.maven.plugin.http.client.utils.HttpEntityUtils.java

License:Apache License

public static Charset getEncoding(HttpEntity entity, Charset defaultCharset, Log log) {
    try {/* ww  w  .j  av  a 2  s  .c  om*/
        if (entity.getContentEncoding() != null) {
            return Charset.forName(entity.getContentEncoding().getName());
        } else if (entity.getContentType() != null) {
            String type = entity.getContentType().getValue();
            if (type != null) {
                Matcher charsetMatcher = CONTENT_TYPE_CHARSET_PATTERN.matcher(type);
                if (charsetMatcher.find()) {
                    Matcher delimiterMatcher = CONTENT_TYPE_CHARSET_DELIMITER_PATTERN.matcher(type);
                    String charsetName = null;
                    if (delimiterMatcher.find(charsetMatcher.end())) {
                        charsetName = type.substring(charsetMatcher.end(), delimiterMatcher.start());
                    } else {
                        charsetName = type.substring(charsetMatcher.end());
                    }
                    return Charset.forName(charsetName);
                }

            }
        } else {
            log.warn("encoding not defined in content encoding nor in content type");
        }
    } catch (IllegalCharsetNameException icne) {
        log.warn("failed to determine response encoding", icne);
    } catch (UnsupportedCharsetException uce) {
        log.warn("failed to determine response encoding", uce);
    }
    log.warn("back to default platform encoding " + DEFAULT_PLATFORM_ENCODING);
    return defaultCharset;
}

From source file:com.googlecode.t7mp.steps.resources.CreateTomcatDirectoryStep.java

License:Apache License

@Override
public void execute(Context context) {
    final Log log = context.getLog();
    final File createdDirectory = new File(context.getMojo().getCatalinaBase(), directory);
    boolean created = createdDirectory.mkdirs();
    if (created) {
        log.debug("directory " + createdDirectory.getAbsolutePath() + " created");
    } else {// w  w w. j ava 2s  .  co m
        log.warn("could not create " + createdDirectory.getAbsolutePath() + ", maybe it exist.");
    }
}

From source file:com.googlecode.yaxv.mkresources.GenerateMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    boolean doAddSources = false;
    for (Resource resource : resources) {
        File dir = new File(resource.getDirectory());
        DirectoryScanner scanner = new DirectoryScanner();
        scanner.setBasedir(resource.getDirectory());
        scanner.setIncludes(includes != null ? includes : new String[] { "**/*.properties" });
        scanner.setExcludes(excludes);/*from   w w w  .  j  av a2 s  .co m*/
        scanner.scan();
        String[] includedFiles = scanner.getIncludedFiles();
        if (includedFiles.length > 0) {
            URL url;
            try {
                url = dir.toURI().toURL();
            } catch (MalformedURLException ex) {
                throw new MojoExecutionException("Unexpected exception", ex);
            }
            ClassLoader loader = new URLClassLoader(new URL[] { url });
            for (String file : includedFiles) {
                if (file.endsWith(".properties")) {
                    String[] baseNameComponents = file.substring(0, file.length() - 11).split("[/\\\\]");
                    String baseName = StringUtils.join(baseNameComponents, ".");
                    log.info("Generating constants for resource bundle " + baseName);
                    ResourceBundle messages = ResourceBundle.getBundle(baseName, Locale.ENGLISH, loader);
                    String className = baseNameComponents[baseNameComponents.length - 1];
                    className = className.substring(0, 1).toUpperCase() + className.substring(1);
                    File outputFile = outputDirectory;
                    StringBuilder packageName = new StringBuilder();
                    for (int i = 0; i < baseNameComponents.length - 1; i++) {
                        if (i > 0) {
                            packageName.append('.');
                        }
                        String component = baseNameComponents[i];
                        packageName.append(component);
                        outputFile = new File(outputFile, component);
                    }
                    outputFile.mkdirs();
                    outputFile = new File(outputFile, className + ".java");
                    try {
                        generate(baseName, messages, outputFile, packageName.toString(), className);
                    } catch (IOException ex) {
                        throw new MojoExecutionException(
                                "Failed to generate " + outputFile + ": " + ex.getMessage(), ex);
                    }
                    doAddSources = true;
                } else {
                    log.warn("Skipping file " + file + ": not a resource bundle");
                }
            }
        }
    }
    if (doAddSources) {
        project.addCompileSourceRoot(outputDirectory.getPath());
    }
}

From source file:com.igormaznitsa.jute.JuteMojo.java

License:Apache License

private static List<String> collectAllPotentialTestClassPaths(final Log log, final boolean verbose,
        final File rootFolder, final String[] includes, final String[] excludes) {
    final List<String> result = new ArrayList<String>();

    final Iterator<File> iterator = FileUtils.iterateFiles(rootFolder, new IOFileFilter() {
        private final AntPathMatcher matcher = new AntPathMatcher();

        @Override/*from   w w  w . java  2s.  co m*/
        public boolean accept(final File file) {
            if (file.isDirectory()) {
                return false;
            }

            final String path = file.getAbsolutePath();
            boolean include = false;

            if (path.endsWith(".class")) {
                if (includes.length != 0) {
                    for (final String patteen : includes) {
                        if (matcher.match(patteen, path)) {
                            include = true;
                            break;
                        }
                    }
                } else {
                    include = true;
                }

                if (include && excludes.length != 0) {
                    for (final String pattern : excludes) {
                        if (matcher.match(pattern, path)) {
                            include = false;
                            break;
                        }
                    }
                }
            }

            if (!include && verbose) {
                log.info("File " + path + " excluded");
            }

            return include;
        }

        @Override
        public boolean accept(final File dir, final String name) {
            final String path = name;
            boolean include = false;
            if (includes.length != 0) {
                for (final String pattern : includes) {
                    if (matcher.match(pattern, path)) {
                        include = true;
                        break;
                    }
                }
            } else {
                include = true;
            }

            if (include && excludes.length != 0) {
                for (final String pattern : excludes) {
                    if (matcher.match(pattern, path)) {
                        include = false;
                        break;
                    }
                }
            }

            if (!include && verbose) {
                log.info("Folder " + name + " excluded");
            }

            return include;
        }
    }, DirectoryFileFilter.DIRECTORY);

    while (iterator.hasNext()) {
        final String detectedFile = iterator.next().getAbsolutePath();
        if (verbose) {
            log.info("Found potential test class : " + detectedFile);
        }
        result.add(detectedFile);
    }

    if (result.isEmpty()) {
        log.warn("No test files found in " + rootFolder.getAbsolutePath());
    }

    return result;
}