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

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

Introduction

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

Prototype

boolean isDebugEnabled();

Source Link

Usage

From source file:org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper.java

License:Apache License

/**
 * Replaces all namespaces within generated schema files, as instructed by the configured Schema instances.
 *
 * @param resolverMap                The map relating generated schema file name to SimpleNamespaceResolver instances.
 * @param configuredTransformSchemas The Schema instances read from the configuration of this plugin.
 * @param mavenLog                   The active Log.
 * @param schemaDirectory            The directory where all generated schema files reside.
 * @throws MojoExecutionException If the namespace replacement could not be done.
 *//* ww w .  java2 s  .  co  m*/
public static void replaceNamespacePrefixes(final Map<String, SimpleNamespaceResolver> resolverMap,
        final List<TransformSchema> configuredTransformSchemas, final Log mavenLog, final File schemaDirectory)
        throws MojoExecutionException {

    if (mavenLog.isDebugEnabled()) {
        mavenLog.debug("Got resolverMap.keySet() [generated filenames]: " + resolverMap.keySet());
    }

    for (SimpleNamespaceResolver currentResolver : resolverMap.values()) {
        File generatedSchemaFile = new File(schemaDirectory, currentResolver.getSourceFilename());
        Document generatedSchemaFileDocument = null;

        for (TransformSchema currentTransformSchema : configuredTransformSchemas) {
            // Should we alter the namespace prefix as instructed by the current schema?
            final String newPrefix = currentTransformSchema.getToPrefix();
            final String currentUri = currentTransformSchema.getUri();

            if (StringUtils.isNotEmpty(newPrefix)) {
                // Find the old/current prefix of the namespace for the current schema uri.
                final String oldPrefix = currentResolver.getNamespaceURI2PrefixMap().get(currentUri);

                if (StringUtils.isNotEmpty(oldPrefix)) {
                    // Can we perform the prefix substitution?
                    validatePrefixSubstitutionIsPossible(oldPrefix, newPrefix, currentResolver);

                    if (mavenLog.isDebugEnabled()) {
                        mavenLog.debug("Subtituting namespace prefix [" + oldPrefix + "] with [" + newPrefix
                                + "] in file [" + currentResolver.getSourceFilename() + "].");
                    }

                    // Get the Document of the current schema file.
                    if (generatedSchemaFileDocument == null) {
                        generatedSchemaFileDocument = parseXmlToDocument(generatedSchemaFile);
                    }

                    // Replace all namespace prefixes within the provided document.
                    process(generatedSchemaFileDocument.getFirstChild(), true,
                            new ChangeNamespacePrefixProcessor(oldPrefix, newPrefix));
                }
            }
        }

        if (generatedSchemaFileDocument != null) {
            // Overwrite the generatedSchemaFile with the content of the generatedSchemaFileDocument.
            mavenLog.debug("Overwriting file [" + currentResolver.getSourceFilename() + "] with content ["
                    + getHumanReadableXml(generatedSchemaFileDocument) + "]");
            savePrettyPrintedDocument(generatedSchemaFileDocument, generatedSchemaFile);
        } else {
            mavenLog.debug("No namespace prefix changes to generated schema file ["
                    + generatedSchemaFile.getName() + "]");
        }
    }
}

From source file:org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper.java

License:Apache License

/**
 * Updates all schemaLocation attributes within the generated schema files to match the 'file' properties within the
 * Schemas read from the plugin configuration. After that, the files are physically renamed.
 *
 * @param resolverMap                The map relating generated schema file name to SimpleNamespaceResolver instances.
 * @param configuredTransformSchemas The Schema instances read from the configuration of this plugin.
 * @param mavenLog                   The active Log.
 * @param schemaDirectory            The directory where all generated schema files reside.
 *///from   ww  w .  ja  va 2s.com
public static void renameGeneratedSchemaFiles(final Map<String, SimpleNamespaceResolver> resolverMap,
        final List<TransformSchema> configuredTransformSchemas, final Log mavenLog,
        final File schemaDirectory) {

    // Create the map relating namespace URI to desired filenames.
    Map<String, String> namespaceUriToDesiredFilenameMap = new TreeMap<String, String>();
    for (TransformSchema current : configuredTransformSchemas) {
        if (StringUtils.isNotEmpty(current.getToFile())) {
            namespaceUriToDesiredFilenameMap.put(current.getUri(), current.getToFile());
        }
    }

    // Replace the schemaLocation values to correspond to the new filenames
    for (SimpleNamespaceResolver currentResolver : resolverMap.values()) {
        File generatedSchemaFile = new File(schemaDirectory, currentResolver.getSourceFilename());
        Document generatedSchemaFileDocument = parseXmlToDocument(generatedSchemaFile);

        // Replace all namespace prefixes within the provided document.
        process(generatedSchemaFileDocument.getFirstChild(), true,
                new ChangeFilenameProcessor(namespaceUriToDesiredFilenameMap));

        // Overwrite the generatedSchemaFile with the content of the generatedSchemaFileDocument.
        if (mavenLog.isDebugEnabled()) {
            mavenLog.debug("Changed schemaLocation entries within [" + currentResolver.getSourceFilename()
                    + "]. " + "Result: [" + getHumanReadableXml(generatedSchemaFileDocument) + "]");
        }
        savePrettyPrintedDocument(generatedSchemaFileDocument, generatedSchemaFile);
    }

    // Now, rename the actual files.
    for (SimpleNamespaceResolver currentResolver : resolverMap.values()) {
        final String localNamespaceURI = currentResolver.getLocalNamespaceURI();

        if (StringUtils.isEmpty(localNamespaceURI)) {
            mavenLog.warn("SimpleNamespaceResolver contained no localNamespaceURI; aborting rename.");
            continue;
        }

        final String newFilename = namespaceUriToDesiredFilenameMap.get(localNamespaceURI);
        final File originalFile = new File(schemaDirectory, currentResolver.getSourceFilename());

        if (StringUtils.isNotEmpty(newFilename)) {
            File renamedFile = FileUtils.resolveFile(schemaDirectory, newFilename);
            String renameResult = (originalFile.renameTo(renamedFile) ? "Success " : "Failure ");

            if (mavenLog.isDebugEnabled()) {
                String suffix = "renaming [" + originalFile.getAbsolutePath() + "] to [" + renamedFile + "]";
                mavenLog.debug(renameResult + suffix);
            }
        }
    }
}

From source file:org.codehaus.mojo.jaxb2.shared.environment.logging.MavenLogHandler.java

License:Apache License

/**
 * Retrieves the JUL Level matching the supplied Maven Log.
 *
 * @param mavenLog A non-null Maven Log.
 * @return The Corresponding JUL Level.//from   ww w.j  a v  a  2 s .com
 */
public static Level getJavaUtilLoggingLevelFor(final Log mavenLog) {

    // Check sanity
    Validate.notNull(mavenLog, "mavenLog");

    Level toReturn = Level.SEVERE;

    if (mavenLog.isDebugEnabled()) {
        toReturn = Level.FINER;
    } else if (mavenLog.isInfoEnabled()) {
        toReturn = Level.INFO;
    } else if (mavenLog.isWarnEnabled()) {
        toReturn = Level.WARNING;
    }

    // All Done.
    return toReturn;
}

From source file:org.codehaus.mojo.jaxb2.shared.FileSystemUtilities.java

License:Apache License

/**
 * Filters files found either in the sources paths (or in the standardDirectory if no explicit sources are given),
 * and retrieves a List holding those files that do not match any of the supplied Java Regular Expression
 * excludePatterns.//from  w  w w  .  j  a v  a  2s.  c  o m
 *
 * @param baseDir             The non-null basedir Directory.
 * @param sources             The sources which should be either absolute or relative (to the given baseDir)
 *                            paths to files or to directories that should be searched recursively for files.
 * @param standardDirectories If no sources are given, revert to searching all files under these standard
 *                            directories. Each path is {@code relativize()}-d to the supplied baseDir to
 *                            reach a directory path.
 * @param log                 A non-null Maven Log for logging any operations performed.
 * @param fileTypeDescription A human-readable short description of what kind of files are searched for, such as
 *                            "xsdSources" or "xjbSources".
 * @param excludePatterns     An optional List of patterns used to construct an ExclusionRegExpFileFilter used to
 *                            identify files which should be excluded from the result.
 * @return URLs to all Files under the supplied sources (or standardDirectories, if no explicit sources
 * are given) which do not match the supplied Java Regular excludePatterns.
 */
@SuppressWarnings("all")
public static List<URL> filterFiles(final File baseDir, final List<String> sources,
        final List<String> standardDirectories, final Log log, final String fileTypeDescription,
        final List<Filter<File>> excludePatterns) {

    final SortedMap<String, File> pathToResolvedSourceMap = new TreeMap<String, File>();

    for (String current : standardDirectories) {
        for (File currentResolvedSource : FileSystemUtilities.filterFiles(baseDir, sources,
                FileSystemUtilities.relativize(current, baseDir), log, fileTypeDescription, excludePatterns)) {

            // Add the source
            pathToResolvedSourceMap.put(FileSystemUtilities.getCanonicalPath(currentResolvedSource),
                    currentResolvedSource);
        }
    }

    final List<URL> toReturn = new ArrayList<URL>();

    // Extract the URLs for all resolved Java sources.
    for (Map.Entry<String, File> current : pathToResolvedSourceMap.entrySet()) {
        toReturn.add(FileSystemUtilities.getUrlFor(current.getValue()));
    }

    if (log.isDebugEnabled()) {

        final StringBuilder builder = new StringBuilder();
        builder.append("\n+=================== [Filtered " + fileTypeDescription + "]\n");

        builder.append("|\n");
        builder.append("| " + excludePatterns.size() + " Exclude patterns:\n");
        for (int i = 0; i < excludePatterns.size(); i++) {
            builder.append(
                    "| [" + (i + 1) + "/" + excludePatterns.size() + "]: " + excludePatterns.get(i) + "\n");
        }

        builder.append("|\n");
        builder.append("| " + standardDirectories.size() + " Standard Directories:\n");
        for (int i = 0; i < standardDirectories.size(); i++) {
            builder.append("| [" + (i + 1) + "/" + standardDirectories.size() + "]: "
                    + standardDirectories.get(i) + "\n");
        }

        builder.append("|\n");
        builder.append("| " + toReturn.size() + " Results:\n");
        for (int i = 0; i < toReturn.size(); i++) {
            builder.append("| [" + (i + 1) + "/" + toReturn.size() + "]: " + toReturn.get(i) + "\n");
        }
        builder.append("|\n");
        builder.append("+=================== [End Filtered " + fileTypeDescription + "]\n\n");

        // Log all.
        log.debug(builder.toString().replace("\n", AbstractJaxbMojo.NEWLINE));
    }

    // All done.
    return toReturn;
}

From source file:org.codehaus.mojo.jaxb2.shared.FileSystemUtilities.java

License:Apache License

/**
 * Filters files found either in the sources paths (or in the standardDirectory if no explicit sources are given),
 * and retrieves a List holding those files that do not match any of the supplied Java Regular Expression
 * excludePatterns.//from ww w.j a v  a 2 s  .c  om
 *
 * @param baseDir             The non-null basedir Directory.
 * @param sources             The sources which should be either absolute or relative (to the given baseDir)
 *                            paths to files or to directories that should be searched recursively for files.
 * @param standardDirectory   If no sources are given, revert to searching all files under this standard directory.
 *                            This is the path appended to the baseDir to reach a directory.
 * @param log                 A non-null Maven Log for logging any operations performed.
 * @param fileTypeDescription A human-readable short description of what kind of files are searched for, such as
 *                            "xsdSources" or "xjbSources".
 * @param excludeFilters      An optional List of Filters used to identify files which should be excluded from
 *                            the result.
 * @return All files under the supplied sources (or standardDirectory, if no explicit sources are given) which
 * do not match the supplied Java Regular excludePatterns.
 */
@SuppressWarnings("CheckStyle")
public static List<File> filterFiles(final File baseDir, final List<String> sources,
        final String standardDirectory, final Log log, final String fileTypeDescription,
        final List<Filter<File>> excludeFilters) {

    // Check sanity
    Validate.notNull(baseDir, "baseDir");
    Validate.notNull(log, "log");
    Validate.notEmpty(standardDirectory, "standardDirectory");
    Validate.notEmpty(fileTypeDescription, "fileTypeDescription");

    // No sources provided? Fallback to the standard (which should be a relative path).
    List<String> effectiveSources = sources;
    if (sources == null || sources.isEmpty()) {
        effectiveSources = new ArrayList<String>();

        final File tmp = new File(standardDirectory);
        final File rootDirectory = tmp.isAbsolute() ? tmp : new File(baseDir, standardDirectory);
        effectiveSources.add(FileSystemUtilities.getCanonicalPath(rootDirectory));
    }

    // First, remove the non-existent sources.
    List<File> existingSources = new ArrayList<File>();
    for (String current : effectiveSources) {

        final File existingFile = FileSystemUtilities.getExistingFile(current, baseDir);
        if (existingFile != null) {
            existingSources.add(existingFile);

            if (log.isDebugEnabled()) {
                log.debug("Accepted configured " + fileTypeDescription + " ["
                        + FileSystemUtilities.getCanonicalFile(existingFile) + "]");
            }
        } else {
            if (log.isInfoEnabled()) {
                log.info("Ignored given or default " + fileTypeDescription + " [" + current
                        + "], since it is not an existent file or directory.");
            }
        }
    }

    if (log.isDebugEnabled() && existingSources.size() > 0) {

        final int size = existingSources.size();

        log.debug(" [" + size + " existing " + fileTypeDescription + "] ...");
        for (int i = 0; i < size; i++) {
            log.debug("   " + (i + 1) + "/" + size + ": " + existingSources.get(i));
        }
        log.debug(" ... End [" + size + " existing " + fileTypeDescription + "]");
    }

    // All Done.
    return FileSystemUtilities.resolveRecursively(existingSources, excludeFilters, log);
}

From source file:org.codehaus.mojo.jaxb2.shared.FileSystemUtilities.java

License:Apache License

private static void checkAndAdd(final List<File> toPopulate, final File current,
        final List<Filter<File>> fileFilters, final boolean excludeFilterOperation, final Log log) {

    ////from  ww w. j av  a 2  s . c o m
    // When no filters are supplied...
    // [Include Operation]: all files will be rejected
    // [Exclude Operation]: all files will be included
    //
    final boolean noFilters = fileFilters == null || fileFilters.isEmpty();
    final boolean addFile = excludeFilterOperation
            ? noFilters || Filters.rejectAtLeastOnce(current, fileFilters)
            : noFilters || Filters.matchAtLeastOnce(current, fileFilters);
    final String logPrefix = (addFile ? "Accepted " : "Rejected ")
            + (current.isDirectory() ? "directory" : "file") + " [";

    if (addFile) {
        toPopulate.add(current);
    }

    if (log.isDebugEnabled()) {
        log.debug(logPrefix + getCanonicalPath(current) + "]");
    }
}

From source file:org.codehaus.mojo.jaxb2.shared.filters.AbstractFilter.java

License:Apache License

/**
 * {@inheritDoc}/* w  ww. ja va  2  s .c o m*/
 */
@Override
public final void initialize(final Log log) {

    // Check sanity
    Validate.notNull(log, "log");

    // Assign internal state
    this.log = log;

    if (delayedLogMessages.size() > 0) {
        for (DelayedLogMessage current : delayedLogMessages) {
            if (current.logLevel.equalsIgnoreCase("warn") && log.isWarnEnabled()) {
                log.warn(current.message);
            } else if (current.logLevel.equals("info") && log.isInfoEnabled()) {
                log.info(current.message);
            } else if (log.isDebugEnabled()) {
                log.debug(current.message);
            }
        }

        delayedLogMessages.clear();
    }

    // Delegate
    onInitialize();
}

From source file:org.codehaus.mojo.license.AbstractAddThirdPartyMojo.java

License:Open Source License

/**
 * {@inheritDoc}/*w  w w .  j a va  2  s  .  c  om*/
 */
@Override
protected void init() throws Exception {

    Log log = getLog();

    if (log.isDebugEnabled()) {

        // always be verbose in debug mode
        setVerbose(true);
    }

    thirdPartyFile = new File(getOutputDirectory(), thirdPartyFilename);

    long buildTimestamp = getBuildTimestamp();

    if (isVerbose()) {
        log.info("Build start   at : " + buildTimestamp);
        log.info("third-party file : " + thirdPartyFile.lastModified());
    }

    doGenerate = isForce() || !thirdPartyFile.exists() || buildTimestamp > thirdPartyFile.lastModified();

    if (generateBundle) {

        File bundleFile = FileUtil.getFile(getOutputDirectory(), bundleThirdPartyPath);

        if (isVerbose()) {
            log.info("bundle third-party file : " + bundleFile.lastModified());
        }
        doGenerateBundle = isForce() || !bundleFile.exists() || buildTimestamp > bundleFile.lastModified();
    } else {

        // not generating bundled file
        doGenerateBundle = false;
    }

    projectDependencies = loadDependencies();

    licenseMap = getHelper().createLicenseMap(projectDependencies);

    unsafeDependencies = getHelper().getProjectsWithNoLicense(licenseMap);

    if (!CollectionUtils.isEmpty(unsafeDependencies)) {
        if (isUseMissingFile() && isDoGenerate()) {
            // load unsafeMapping from local file and/or third-party classified items.
            unsafeMappings = createUnsafeMapping();
        }
    }

    getHelper().mergeLicenses(licenseMerges, licenseMap);
}

From source file:org.codehaus.mojo.license.ArtifactHelper.java

License:Open Source License

protected static boolean isIncludable(Log log, Artifact project, Pattern includedGroupPattern,
        Pattern includedArtifactPattern) {

    // check if the groupId of the project should be included
    if (includedGroupPattern != null) {
        // we have some defined license filters
        try {//from w w  w .j a va2  s .c om
            Matcher matchGroupId = includedGroupPattern.matcher(project.getGroupId());
            if (matchGroupId.find()) {
                if (log.isDebugEnabled()) {
                    log.debug("Include " + project.getGroupId());
                }
                return true;
            }
        } catch (PatternSyntaxException e) {
            log.warn(String.format(INVALIDE_PATTERN_MESSAGE, includedGroupPattern.pattern()));
        }
    }

    // check if the artifactId of the project should be included
    if (includedArtifactPattern != null) {
        // we have some defined license filters
        try {
            Matcher matchGroupId = includedArtifactPattern.matcher(project.getArtifactId());
            if (matchGroupId.find()) {
                if (log.isDebugEnabled()) {
                    log.debug("Include " + project.getArtifactId());
                }
                return true;
            }
        } catch (PatternSyntaxException e) {
            log.warn(String.format(INVALIDE_PATTERN_MESSAGE, includedArtifactPattern.pattern()));
        }
    }

    return false;
}

From source file:org.codehaus.mojo.license.ArtifactHelper.java

License:Open Source License

protected static boolean isExcludable(Log log, Artifact project, Pattern excludedGroupPattern,
        Pattern excludedArtifactPattern) {

    // check if the groupId of the project should be included
    if (excludedGroupPattern != null) {
        // we have some defined license filters
        try {//from  w  w w  . j av a  2s  . com
            Matcher matchGroupId = excludedGroupPattern.matcher(project.getGroupId());
            if (matchGroupId.find()) {
                if (log.isDebugEnabled()) {
                    log.debug("Exclude " + project.getGroupId());
                }
                return true;
            }
        } catch (PatternSyntaxException e) {
            log.warn(String.format(INVALIDE_PATTERN_MESSAGE, excludedGroupPattern.pattern()));
        }
    }

    // check if the artifactId of the project should be included
    if (excludedArtifactPattern != null) {
        // we have some defined license filters
        try {
            Matcher matchGroupId = excludedArtifactPattern.matcher(project.getArtifactId());
            if (matchGroupId.find()) {
                if (log.isDebugEnabled()) {
                    log.debug("Exclude " + project.getArtifactId());
                }
                return true;
            }
        } catch (PatternSyntaxException e) {
            log.warn(String.format(INVALIDE_PATTERN_MESSAGE, excludedArtifactPattern.pattern()));
        }
    }

    return false;
}