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:de.thetaphi.forbiddenapis.AbstractCheckMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    final Log log = getLog();

    if (skip) {/*from ww w. j av a  2  s  .co  m*/
        log.info("Skipping forbidden-apis checks.");
        return;
    }

    // In multi-module projects, one may want to configure the plugin in the parent/root POM.
    // However, it should not be executed for this type of POMs.
    if ("pom".equals(packaging)) {
        log.info("Skipping execution for packaging \"" + packaging + "\"");
        return;
    }

    // set default param:
    if (includes == null)
        includes = new String[] { "**/*.class" };

    final URL[] urls;
    try {
        final List<String> cp = getClassPathElements();
        urls = new URL[cp.size()];
        int i = 0;
        for (final String cpElement : cp) {
            urls[i++] = new File(cpElement).toURI().toURL();
        }
        assert i == urls.length;
        if (log.isDebugEnabled())
            log.debug("Compile Classpath: " + Arrays.toString(urls));
    } catch (MalformedURLException e) {
        throw new MojoExecutionException("Failed to build classpath: " + e);
    }

    URLClassLoader urlLoader = null;
    final ClassLoader loader = (urls.length > 0)
            ? (urlLoader = URLClassLoader.newInstance(urls, ClassLoader.getSystemClassLoader()))
            : ClassLoader.getSystemClassLoader();

    try {
        final EnumSet<Checker.Option> options = EnumSet.noneOf(Checker.Option.class);
        if (internalRuntimeForbidden)
            options.add(INTERNAL_RUNTIME_FORBIDDEN);
        if (failOnMissingClasses)
            options.add(FAIL_ON_MISSING_CLASSES);
        if (failOnViolation)
            options.add(FAIL_ON_VIOLATION);
        if (failOnUnresolvableSignatures)
            options.add(FAIL_ON_UNRESOLVABLE_SIGNATURES);
        final Checker checker = new Checker(loader, options) {
            @Override
            protected void logError(String msg) {
                log.error(msg);
            }

            @Override
            protected void logWarn(String msg) {
                log.warn(msg);
            }

            @Override
            protected void logInfo(String msg) {
                log.info(msg);
            }
        };

        if (!checker.isSupportedJDK) {
            final String msg = String.format(Locale.ENGLISH,
                    "Your Java runtime (%s %s) is not supported by the forbiddenapis MOJO. Please run the checks with a supported JDK!",
                    System.getProperty("java.runtime.name"), System.getProperty("java.runtime.version"));
            if (failOnUnsupportedJava) {
                throw new MojoExecutionException(msg);
            } else {
                log.warn(msg);
                return;
            }
        }

        if (suppressAnnotations != null) {
            for (String a : suppressAnnotations) {
                checker.addSuppressAnnotation(a);
            }
        }

        log.info("Scanning for classes to check...");
        final File classesDirectory = getClassesDirectory();
        if (!classesDirectory.exists()) {
            log.warn("Classes directory does not exist, forbiddenapis check skipped: " + classesDirectory);
            return;
        }
        final DirectoryScanner ds = new DirectoryScanner();
        ds.setBasedir(classesDirectory);
        ds.setCaseSensitive(true);
        ds.setIncludes(includes);
        ds.setExcludes(excludes);
        ds.addDefaultExcludes();
        ds.scan();
        final String[] files = ds.getIncludedFiles();
        if (files.length == 0) {
            log.warn(String.format(Locale.ENGLISH,
                    "No classes found in '%s' (includes=%s, excludes=%s), forbiddenapis check skipped.",
                    classesDirectory.toString(), Arrays.toString(includes), Arrays.toString(excludes)));
            return;
        }

        try {
            final String sig = (signatures != null) ? signatures.trim() : null;
            if (sig != null && sig.length() != 0) {
                log.info("Reading inline API signatures...");
                checker.parseSignaturesString(sig);
            }
            if (bundledSignatures != null) {
                String targetVersion = getTargetVersion();
                if ("".equals(targetVersion))
                    targetVersion = null;
                if (targetVersion == null) {
                    log.warn("The 'targetVersion' parameter or '${maven.compiler.target}' property is missing. "
                            + "Trying to read bundled JDK signatures without compiler target. "
                            + "You have to explicitely specify the version in the resource name.");
                }
                for (String bs : bundledSignatures) {
                    log.info("Reading bundled API signatures: " + bs);
                    checker.parseBundledSignatures(bs, targetVersion);
                }
            }
            if (signaturesFiles != null)
                for (final File f : signaturesFiles) {
                    log.info("Reading API signatures: " + f);
                    checker.parseSignaturesFile(new FileInputStream(f));
                }
        } catch (IOException ioe) {
            throw new MojoExecutionException("IO problem while reading files with API signatures: " + ioe);
        } catch (ParseException pe) {
            throw new MojoExecutionException("Parsing signatures failed: " + pe.getMessage());
        }

        if (checker.hasNoSignatures()) {
            if (failOnUnresolvableSignatures) {
                throw new MojoExecutionException(
                        "No API signatures found; use parameters 'signatures', 'bundledSignatures', and/or 'signaturesFiles' to define those!");
            } else {
                log.info("Skipping execution because no API signatures are available.");
                return;
            }
        }

        log.info("Loading classes to check...");
        try {
            for (String f : files) {
                checker.addClassToCheck(new FileInputStream(new File(classesDirectory, f)));
            }
        } catch (IOException ioe) {
            throw new MojoExecutionException("Failed to load one of the given class files: " + ioe);
        }

        log.info("Scanning for API signatures and dependencies...");
        try {
            checker.run();
        } catch (ForbiddenApiException fae) {
            throw new MojoFailureException(fae.getMessage());
        }
    } finally {
        // Java 7 supports closing URLClassLoader, so check for Closeable interface:
        if (urlLoader instanceof Closeable)
            try {
                ((Closeable) urlLoader).close();
            } catch (IOException ioe) {
                // ignore
            }
    }
}

From source file:io.cloudslang.lang.enforcer.SpringCleansingRule.java

License:Open Source License

private void applyForJavaSourcesInRoot(final String path, final Log log) throws EnforcerRuleException {
    Iterator<File> fileIterator = iterateFiles(new File(path), new String[] { JAVA }, true);
    while (fileIterator.hasNext()) {
        File source = fileIterator.next();

        if (isRegularFile(source.toPath(), NOFOLLOW_LINKS)) {
            if (log.isDebugEnabled()) {
                log.debug(format(STARTED_SCANNING_ORG_SPRINGFRAMEWORK, source.getAbsolutePath()));
            }/*  ww  w  . j  a v  a2  s  .c  o  m*/
            try {
                String contents = readFileToString(source, UTF_8.displayName());
                if (isSpringConfigurationAnnotatedClass(contents)) {
                    log.info(format("Skipping verification for Spring configuration class in file '%s'",
                            source.getAbsolutePath()));
                    continue;
                }
                // At this point it is clear this is a regular Java class that is not a Spring Configuration class
                // and just validate we don't have org.springframework in it

                findMatchesUsingPattern(source, log, contents, patternImport,
                        FOUND_USAGE_OF_ORG_SPRINGFRAMEWORK_IN_IMPORT_AT_LINE);
                findMatchesUsingPattern(source, log, contents, patternCodeLine,
                        FOUND_USAGE_OF_ORG_SPRINGFRAMEWORK_IN_CODE_FRAGMENT_AT_LINE);
            } catch (IOException ignore) {
                log.error(format("Could not process file '%s'", source));
            }
            if (log.isDebugEnabled()) {
                log.debug(format(FINISHED_SCANNING_ORG_SPRINGFRAMEWORK, source.getAbsolutePath()));
            }
        }
    }
}

From source file:io.sarl.maven.compiler.CompileMojo.java

License:Apache License

private void compileSARL() throws MojoExecutionException, MojoFailureException {
    final Log log = getLog();
    File outputDirectory = getOutput();
    log.info(Locale.getString(CompileMojo.class, "COMPILING_SARL")); //$NON-NLS-1$
    if (log.isDebugEnabled()) {
        final StringBuilder properties = new StringBuilder();
        buildPropertyString(properties);
        log.debug(properties.toString());
    }//  www  .  j a v a 2 s  .c o m
    // If output is not explicitly set try to read SARL prefs from eclipse .settings folder
    if (getDefaultOutput().equals(getOutput())) {
        final String settingsValue = readSarlEclipseSetting(getProject().getBuild().getSourceDirectory());
        if (settingsValue != null && !settingsValue.isEmpty()) {
            outputDirectory = new File(settingsValue);
            getLog().info(Locale.getString(CompileMojo.class, "OUTPUT_DIR_UPDATE", outputDirectory)); //$NON-NLS-1$
        }
    }
    final MavenProject project = getProject();
    final List<File> compileSourceRoots = new ArrayList<>();
    for (final String filename : project.getCompileSourceRoots()) {
        final File file = new File(filename);
        if (!file.equals(outputDirectory)) {
            compileSourceRoots.add(file);
        }
    }
    final List<File> classPath = getClassPath();
    project.addCompileSourceRoot(outputDirectory.getAbsolutePath());
    compile(classPath, compileSourceRoots, outputDirectory);
}

From source file:it.javalinux.sibilla.plugins.SibillaMojo.java

License:Open Source License

private void printDebugLogs(Log log, Configuration config) {
    if (log.isDebugEnabled()) {
        log.debug("Classpath:");
        for (String s : getClasspathElements()) {
            log.debug(" " + s);
        }//from   w w  w.java2s . c  om
        log.debug("Source roots:");
        for (String root : getSourceRoots()) {
            log.debug(" " + root);
        }
        log.debug("Output directory:");
        log.debug(" " + getOutputDirectory());
        log.debug("Test classpath:");
        for (String s : getTestClasspathElements()) {
            log.debug(" " + s);
        }
        log.debug("Test source roots:");
        for (String root : getTestSourceRoots()) {
            log.debug(" " + root);
        }
        log.debug("Test output directory:");
        log.debug(" " + getTestOutputDirectory());
        log.debug("Classes under test changed since last run: ");
        for (File f : config.getChangedClassesUnderTest()) {
            log.debug(" " + f);
        }
        log.debug("Test classes changed since last run: ");
        for (File f : config.getChangedTestClasses()) {
            log.debug(" " + f);
        }
        log.debug("Provided Sibilla runner:");
        log.debug(" " + config.getRunner());
        log.debug("Provided Sibilla metadata serializer:");
        log.debug(" " + config.getSerializer());
    }
}

From source file:net.oneandone.maven.plugins.prerelease.ProjectBase.java

License:Apache License

protected WorkingCopy checkedWorkingCopy() throws Exception {
    Log log;
    WorkingCopy workingCopy;//from   w ww.  j a  va 2 s . c  om

    log = getLog();
    log.info("checking working copy ...");
    workingCopy = WorkingCopy.load(basedir());
    if (log.isDebugEnabled()) {
        log.debug("revisions: " + workingCopy.revisions);
        log.debug("changes: " + workingCopy.changes);
    }
    workingCopy.check();
    return workingCopy;
}

From source file:nl.geodienstencentrum.maven.plugin.sass.AbstractSassMojo.java

License:Apache License

/**
 * Builds the basic sass script.//from  w  ww  .  ja  va 2 s. co m
 *
 * @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

/**
 * {@inheritDoc}/*from  ww w .  j ava  2 s .  c  om*/
 */
@Override
protected void buildBasicSassScript(final StringBuilder sassScript) throws MojoExecutionException {
    final Log log = this.getLog();
    // build up script
    sassScript.append("require 'scss_lint'\n");
    sassScript.append("require 'scss_lint/cli'\n");
    sassScript.append("require 'scss_lint_reporter_checkstyle'\n");

    if (log.isDebugEnabled()) {
        // make ruby give use some debugging info when requested
        sassScript.append("require 'pp'\n");
        sassScript.append("puts 'parameters: '\n");
        sassScript.append("pp ARGV\n");
    }
    sassScript.append("SCSSLint::CLI.new.run(ARGV)\n");
}

From source file:npanday.plugin.libraryimporter.model.NugetPackage.java

License:Apache License

public Iterable<NugetPackageLibrary> getLibraries(Log log, File mavenProjectsCacheDirectory)
        throws MojoExecutionException {
    List<File> libDirectories = getLibraryDirectories();

    List<NugetPackageLibrary> libImports = Lists.newArrayList();
    for (File libDir : libDirectories) {
        for (File libFile : LibImporterPathUtils.getLibraries(libDir)) {
            NugetPackageLibrary lib = new NugetPackageLibrary(this, libFile, mavenProjectsCacheDirectory);

            ReferenceMapping referenceMapping = tryFindReferenceMappingFor(lib.getAssemblyInfo());
            if (referenceMapping != null && referenceMapping.getMapToPackage() != null) {
                if (log.isDebugEnabled()) {
                    log.debug("NPANDAY-142-004: Will skip inclusion for " + lib
                            + " since references to it are mapped to a different package ("
                            + referenceMapping.getMapToPackage().getId() + ", v"
                            + referenceMapping.getMapToPackage().getVersion() + ").");
                }//from  w w  w . j  a  v  a 2  s. co m

                continue;
            }

            libImports.add(lib);
        }
    }
    return libImports;
}

From source file:org.acmsl.queryj.tools.maven.CommonsLoggingMavenLogAdapter.java

License:Open Source License

/**
 * Checks whether the debug level is enabled.
 * @param mavenLog the underlying {@link Log}.
 * @return {@code true} in such case.//w w  w  . ja v  a  2s .c  o  m
 */
protected boolean isTraceEnabled(@NotNull final Log mavenLog) {
    return mavenLog.isDebugEnabled();
}

From source file:org.acmsl.queryj.tools.maven.CommonsLoggingMavenLogAdapter.java

License:Open Source License

/**
 * Checks whether the debug level is enabled.
 * @param mavenLog the underlying {@link Log}.
 * @return {@code true} in such case.//from w  w  w  .  ja va 2s.  c o  m
 */
protected boolean isDebugEnabled(@NotNull final Log mavenLog) {
    return mavenLog.isDebugEnabled();
}