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

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

Introduction

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

Prototype

void info(Throwable error);

Source Link

Document

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

Usage

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  ww  w. jav  a2s. c o  m*/

            }
        }
    } else {
        createSourceRootFolder(sourceRoot, log);
    }
    this.log = log;
    this.sourceRoot = sourceRoot;
}

From source file:net.sourceforge.mavenhippo.FileManager.java

License:Apache License

private void createSourceRootFolder(File sourceRoot, Log log) throws FileManagerException {
    if (sourceRoot.mkdirs()) {
        log.info("sourceRoot folder was created at \"" + sourceRoot.getAbsolutePath() + "\"");
    } else {//from www  . ja  v a  2  s. c  o m
        log.error("Could not create the source root file. It is probably caused by lack of permissions.");
        throw new FileManagerException("Could not create the source root.");
    }
}

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

License:Apache License

/**
 * Builds the basic sass script.// ww w  .  j  ava2  s.com
 *
 * @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.AbstractSassMojo.java

License:Apache License

/**
 * Gets the template locations.// ww w . java 2  s .com
 *
 * @return the template locations
 */
private Iterator<Entry<String, String>> getTemplateLocations() {
    final Log log = this.getLog();
    List<Resource> resList = this.resources;

    if (resList.isEmpty()) {
        log.info("No resource element was specified, using short configuration.");
        // If no resources specified, create a resource based on the other
        // parameters and defaults
        final Resource resource = new Resource();
        resource.source = new FileSet();

        if (this.sassSourceDirectory != null) {
            log.debug("Setting source directory: " + this.sassSourceDirectory.toString());
            resource.source.setDirectory(this.sassSourceDirectory.toString());
        } else {
            log.error("\"" + this.sassSourceDirectory + "\" is not a directory.");
            resource.source.setDirectory("./src/main/sass");
        }
        if (this.includes != null) {
            log.debug("Setting includes: " + Arrays.toString(this.includes));
            resource.source.setIncludes(Arrays.asList(this.includes));
        }
        if (this.excludes != null) {
            log.debug("Setting excludes: " + Arrays.toString(this.excludes));
            resource.source.setExcludes(Arrays.asList(this.excludes));
        }
        resource.relativeOutputDirectory = this.relativeOutputDirectory;
        resource.destination = this.destination;
        resList = ImmutableList.of(resource);
    }

    final List<Entry<String, String>> locations = new ArrayList<Entry<String, String>>();
    for (final Resource source : resList) {
        for (final Entry<String, String> entry : source.getDirectoriesAndDestinations(log).entrySet()) {
            log.info("Queueing Sass template for compile: " + entry.getKey() + " => " + entry.getValue());
            locations.add(entry);
        }
    }
    return locations.iterator();
}

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

License:Apache License

/**
 * Extract the Bourbon assets to the build directory.
 * @param destinationDir directory for the Bourbon resources
 *//* w w  w  .ja va 2  s  .c  o  m*/
private void extractBourbonResources(String destinationDir) {
    final Log log = this.getLog();
    try {
        File destDir = new File(destinationDir);
        if (destDir.isDirectory()) {
            // skip extracting Bourbon, as it seems to hav been done
            log.info("Bourbon resources seems to have been extracted before.");
            return;
        }
        log.info("Extracting Bourbon resources to: " + destinationDir);
        destDir.mkdirs();
        // find the jar with the Bourbon directory in the classloader
        URL urlJar = this.getClass().getClassLoader().getResource("scss-report.xsl");
        String resourceFilePath = urlJar.getFile();
        int index = resourceFilePath.indexOf("!");
        String jarFileURI = resourceFilePath.substring(0, index);
        File jarFile = new File(new URI(jarFileURI));
        JarFile jar = new JarFile(jarFile);

        // extract app/assets/stylesheets to destinationDir
        for (Enumeration<JarEntry> enums = jar.entries(); enums.hasMoreElements();) {
            JarEntry entry = enums.nextElement();

            if (entry.getName().contains("app/assets/stylesheets")) {
                // shorten the path a bit
                index = entry.getName().indexOf("app/assets/stylesheets");
                String fileName = destinationDir + File.separator + entry.getName().substring(index);

                File f = new File(fileName);
                if (fileName.endsWith("/")) {
                    f.mkdirs();
                } else {
                    FileOutputStream fos = new FileOutputStream(f);
                    try {
                        IOUtil.copy(jar.getInputStream(entry), fos);
                    } finally {
                        IOUtil.close(fos);
                    }
                }
            }
        }
    } catch (IOException | URISyntaxException ex) {
        log.error("Error extracting Bourbon resources.", ex);
    }
}

From source file:nl.geodienstencentrum.maven.plugin.sass.report.SCSSLintMojo.java

License:Apache License

/**
 * Execute the lint script./*from w  w w  .ja  v  a 2 s .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:org.acmsl.dockerfile.maven.DockerfileMojo.java

License:Open Source License

/**
 * Executes Dockerfile Maven Plugin./*ww  w . ja v  a2  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.templates.packaging.maven.TemplatePackagingMojo.java

License:Open Source License

/**
 * Requests the chained logic to be performed.
 * @param command the command.//from   w  w  w.j a v  a 2 s . c o m
 * @param log the log.
 * @param version the version.
 * @throws MojoExecutionException if the process fails.
 */
protected void execute(@NotNull final QueryJCommand command, @NotNull final Log log, final String version)
        throws MojoExecutionException {
    log.info("Running QueryJ Template Packaging " + version);

    try {
        populateCommand(command, getSources());
        populateCommand(command, getOutputDir());
        populateCommandForTests(command, getOutputDirForTests());
        populateCommand(command, getJdbcDriver(), getJdbcUrl(), getJdbcUserName(), getJdbcPassword());
        populateCommand(command, version);

        new TemplatePackagingChain<>().process(command);
    } catch (@NotNull final QueryJBuildException buildException) {
        throw new MojoExecutionException(buildException.getMessage(), buildException);
    }
}

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

License:Open Source License

/**
 * Logs given message using Maven's mechanism.
 * @param message the message.//from  w ww.  ja v  a  2s .  c om
 * @param log the {@link Log} instance.
 */
protected void log(@NotNull final String message, @NotNull final Log log) {
    log.info(message);
}

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

License:Open Source License

/**
 * See {@link Project#log(String)}./*from  w w  w. j  av a 2s.com*/
 * @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;
    }
}