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:com.insideaem.maven.plugins.aemjasmine.AEMJasmineMoJo.java

License:Apache License

/**
 * Scans a single directory.//from  w  w  w.ja  va2 s  .  c  o  m
 * 
 * @param root
 *            Directory to scan
 * @param writer
 *            Where to write the source list
 * @throws MojoExecutionException
 *             in case of IO errors
 */
private void scan(File root) throws MojoExecutionException {
    final Log log = getLog();

    if (!root.exists()) {
        return;
    }

    log.info("scanning source file directory '" + root + "'");

    final DirectoryScanner directoryScanner = new DirectoryScanner();
    directoryScanner.setIncludes(includes);
    directoryScanner.setBasedir(root);
    directoryScanner.scan();

    for (String fileName : directoryScanner.getIncludedFiles()) {
        final File file = new File(root, fileName);
        try {
            this.getLog().info("Found file: " + file.getAbsolutePath());
        } catch (Exception e) {
            throw new MojoExecutionException("io error while writing source list", e);
        }
    }
}

From source file:com.jboss.devstudio.enforcer.rule.ParentPomVersionCheckRule.java

License:Apache License

public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
    Log log = helper.getLog();

    try {/*from   ww w.  j  av a 2 s.  c  om*/
        // get the various expressions out of the helper.
        MavenProject project = (MavenProject) helper.evaluate("${project}");
        MavenSession session = (MavenSession) helper.evaluate("${session}");
        String target = (String) helper.evaluate("${project.build.directory}");
        String artifactId = (String) helper.evaluate("${project.artifactId}");

        // retreive any component out of the session directly
        ArtifactResolver resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class);
        RuntimeInformation rti = (RuntimeInformation) helper.getComponent(RuntimeInformation.class);

        log.info("Retrieved Target Folder: " + target);
        log.info("Retrieved ArtifactId: " + artifactId);
        log.info("Retrieved Project: " + project);
        log.info("Retrieved RuntimeInfo: " + rti);
        log.info("Retrieved Session: " + session);
        log.info("Retrieved Resolver: " + resolver);

        // retrieve the version of the parent pom; if it contains .Final then JBDS builds need to override with -DBUILD_ALIAS=GA
        String parentVersion = (String) helper.evaluate("${project.parent.version}");
        String BUILD_ALIAS = (String) helper.evaluate("${BUILD_ALIAS}");

        if (this.shouldIfail && parentVersion.indexOf(".Final") > 0 && !BUILD_ALIAS.equals("GA")) {
            throw new EnforcerRuleException(" ** Parent pom version (" + parentVersion
                    + ") contains .Final; must set -DBUILD_ALIAS=GA **");
        }
    } catch (ComponentLookupException e) {
        throw new EnforcerRuleException("Unable to lookup a component " + e.getLocalizedMessage(), e);
    } catch (ExpressionEvaluationException e) {
        throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
    }
}

From source file:com.kaaprotech.satu.mojo.SatuMojo.java

License:Apache License

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

    if (log.isDebugEnabled()) {
        for (String e : excludes) {
            log.debug("SATU: Exclude: " + e);
        }//from w  w  w  . j  ava 2s  .  c o  m

        for (String e : includes) {
            log.debug("SATU: Include: " + e);
        }

        log.debug("SATU: Output: " + outputDirectory);
    }

    if (!sourceDirectory.isDirectory()) {
        log.info("SATU: Root source directory doesn't exist " + sourceDirectory.getAbsolutePath());
        return;
    }

    log.info("SATU: Processing root source directory " + sourceDirectory.getAbsolutePath());

    log.debug("Output root directory is " + outputDirectory.getAbsolutePath());

    if (!outputDirectory.exists()) {
        outputDirectory.mkdirs();
    }

    final List<File> satuModelFiles;
    try {
        satuModelFiles = getSatuModelDefinitionFiles();
    } catch (InclusionScanException e) {
        log.error(e);
        throw new MojoExecutionException("Error occured finding the Satu model definition files", e);
    }

    log.info("Compiling " + satuModelFiles.size() + " Satu model definition files to "
            + outputDirectory.getAbsolutePath());

    final SatuToJava generator = new SatuToJava(outputDirectory.getAbsolutePath());

    Exception exception = null;
    for (File file : satuModelFiles) {
        try {
            generator.generate(file.getPath(), encoding, jsonCompatible);
        } catch (Exception e) {
            if (exception == null) {
                exception = e;
            }
            log.error("Failed to generate code for Satu model definition " + file.getPath(), e);
        }
    }

    if (exception != null) {
        throw new MojoExecutionException("Error occured generating code for Sata model definition files",
                exception);
    }

    if (project != null) {
        project.addCompileSourceRoot(outputDirectory.getPath());
    }
}

From source file:com.kaaprotech.satu.mojo.SatuMojo.java

License:Apache License

private List<File> getSatuModelDefinitionFiles() throws InclusionScanException {
    final Log log = getLog();
    final Set<String> inculdePatterns = includes == null || includes.isEmpty()
            ? Collections.singleton("**/*.satu")
            : includes;//  w w  w .  ja  va  2 s  .com
    final SourceInclusionScanner scanner = new SimpleSourceInclusionScanner(inculdePatterns, excludes);
    scanner.addSourceMapping(new SuffixMapping("satu", Collections.<String>emptySet()));
    final Set<File> modelFiles = scanner.getIncludedSources(sourceDirectory, null);

    if (modelFiles.isEmpty()) {
        log.info("No Satu model files to process");
        return Collections.emptyList();
    }

    final List<File> retVal = new ArrayList<File>();
    for (File modelFile : modelFiles) {
        if (!buildContext.hasDelta(modelFile)) {
            continue;
        }
        buildContext.removeMessages(modelFile);
        log.debug("Satu model file detected: " + modelFile.getPath());
        retVal.add(modelFile);
    }

    Collections.sort(retVal);
    return retVal;
}

From source file:com.kamomileware.maven.plugin.opencms.native2ascii.Native2Ascii.java

License:Apache License

private void logPerform(Log log, PlainEncodingConfig n2aConfig, File src, File target) {
    log.info(new StringBuilder().append("Converting for ")
            .append(n2aConfig.getEncoding() == null ? " default" : n2aConfig.getEncoding()).append(" [")
            .append(src.getAbsolutePath()).append("] to[").append(target.getAbsolutePath()).append("] (")
            .append("Includes: ").append(n2aConfig.getIncludes())
            .append(n2aConfig.getExcludes() != null ? " / Excludes: " + n2aConfig.getExcludes() : "")
            .append(")").toString());
}

From source file:com.maltera.technologic.maven.mcforge.PythonLauncher.java

License:Open Source License

public PythonLauncher(final Log log, File dir) {
    logger = new StreamConsumer() {
        public void consumeLine(String line) {
            log.info(line);
        }/*from w  w w .j a  v  a2  s  .  c o  m*/
    };

    this.dir = dir;

    if (System.getProperty("os.name").toLowerCase().contains("win")) {
        String result = null;
        for (String candidate : PYTHON_EXES) {
            final File file = new File(dir, candidate);
            if (file.isFile()) {
                result = file.getPath();
                break;
            }
        }

        if (null == result) {
            throw new IllegalArgumentException("no supported Python executable found");
        } else {
            python = result;
        }
    } else {
        python = "python";
    }

}

From source file:com.mastfrog.maven.merge.configuration.MergeConfigurationMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    // XXX a LOT of duplicate code here
    Log log = super.getLog();
    log.info("Merging properties files");
    if (repoSession == null) {
        throw new MojoFailureException("RepositorySystemSession is null");
    }/*from w  w w  .  j a v  a  2s  .  co m*/
    List<File> jars = new ArrayList<>();
    List<String> exclude = new LinkedList<>();
    for (String ex : this.exclude.split(",")) {
        ex = ex.trim();
        ex = ex.replace('.', '/');
        exclude.add(ex);
    }
    try {
        DependencyResolutionResult result = resolver
                .resolve(new DefaultDependencyResolutionRequest(project, repoSession));
        log.info("FOUND " + result.getDependencies().size() + " dependencies");
        for (Dependency d : result.getDependencies()) {
            switch (d.getScope()) {
            case "test":
            case "provided":
                break;
            default:
                File f = d.getArtifact().getFile();
                if (f.getName().endsWith(".jar") && f.isFile() && f.canRead()) {
                    jars.add(f);
                }
            }
        }
    } catch (DependencyResolutionException ex) {
        throw new MojoExecutionException("Collecting dependencies failed", ex);
    }

    Map<String, Properties> m = new LinkedHashMap<>();

    Map<String, Set<String>> linesForName = new LinkedHashMap<>();
    Map<String, Integer> fileCountForName = new HashMap<>();

    boolean buildMergedJar = mainClass != null && !"none".equals(mainClass);
    JarOutputStream jarOut = null;
    Set<String> seen = new HashSet<>();

    try {
        if (buildMergedJar) {
            try {
                File outDir = new File(project.getBuild().getOutputDirectory()).getParentFile();
                File jar = new File(outDir, project.getBuild().getFinalName() + ".jar");
                if (!jar.exists()) {
                    throw new MojoExecutionException("Could not find jar " + jar);
                }
                try (JarFile jf = new JarFile(jar)) {
                    Manifest manifest = new Manifest(jf.getManifest());
                    if (mainClass != null) {
                        manifest.getMainAttributes().putValue("Main-Class", mainClass);
                    }
                    String jn = jarName == null || "none".equals(jarName) ? strip(mainClass) : jarName;
                    File outJar = new File(outDir, jn + ".jar");
                    log.info("Will build merged JAR " + outJar);
                    if (outJar.equals(jar)) {
                        throw new MojoExecutionException(
                                "Merged jar and output jar are the same file: " + outJar);
                    }
                    if (!outJar.exists()) {
                        outJar.createNewFile();
                    }
                    jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(outJar)),
                            manifest);
                    jarOut.setLevel(9);
                    jarOut.setComment("Merged jar created by " + getClass().getName());
                    Enumeration<JarEntry> en = jf.entries();
                    while (en.hasMoreElements()) {
                        JarEntry e = en.nextElement();
                        String name = e.getName();
                        for (String s : exclude) {
                            if (name.startsWith(s)) {
                                continue;
                            }
                        }
                        //                            if (!seen.contains(name)) {
                        switch (name) {
                        case "META-INF/MANIFEST.MF":
                        case "META-INF/":
                            break;
                        case "META-INF/LICENSE":
                        case "META-INF/LICENSE.txt":
                        case "META-INF/http/pages.list":
                        case "META-INF/http/modules.list":
                        case "META-INF/http/numble.list":
                        case "META-INF/settings/namespaces.list":
                            Set<String> s = linesForName.get(name);
                            if (s == null) {
                                s = new LinkedHashSet<>();
                                linesForName.put(name, s);
                            }
                            Integer ct = fileCountForName.get(name);
                            if (ct == null) {
                                ct = 1;
                            }
                            fileCountForName.put(name, ct);
                            try (InputStream in = jf.getInputStream(e)) {
                                s.addAll(readLines(in));
                            }
                            break;
                        default:
                            if (name.startsWith("META-INF/services/") && !name.endsWith("/")) {
                                Set<String> s2 = linesForName.get(name);
                                if (s2 == null) {
                                    s2 = new HashSet<>();
                                    linesForName.put(name, s2);
                                }
                                Integer ct2 = fileCountForName.get(name);
                                if (ct2 == null) {
                                    ct2 = 1;
                                }
                                fileCountForName.put(name, ct2);
                                try (InputStream in = jf.getInputStream(e)) {
                                    s2.addAll(readLines(in));
                                }
                                seen.add(name);
                            } else if (PAT.matcher(name).matches()) {
                                log.info("Include " + name);
                                Properties p = new Properties();
                                try (InputStream in = jf.getInputStream(e)) {
                                    p.load(in);
                                }
                                Properties all = m.get(name);
                                if (all == null) {
                                    all = p;
                                    m.put(name, p);
                                } else {
                                    for (String key : p.stringPropertyNames()) {
                                        if (all.containsKey(key)) {
                                            Object old = all.get(key);
                                            Object nue = p.get(key);
                                            if (!Objects.equal(old, nue)) {
                                                log.warn(key + '=' + nue + " in " + jar + '!' + name
                                                        + " overrides " + key + '=' + old);
                                            }
                                        }
                                    }
                                    all.putAll(p);
                                }
                            } else if (!seen.contains(name) && !SIG1.matcher(name).find()
                                    && !SIG2.matcher(name).find() && !SIG3.matcher(name).find()) {
                                log.info("Bundle " + name);
                                JarEntry je = new JarEntry(name);
                                je.setTime(e.getTime());
                                try {
                                    jarOut.putNextEntry(je);
                                } catch (ZipException ex) {
                                    throw new MojoExecutionException("Exception putting zip entry " + name, ex);
                                }
                                try (InputStream in = jf.getInputStream(e)) {
                                    copy(in, jarOut);
                                }
                                jarOut.closeEntry();
                                seen.add(name);
                            } else {
                                System.err.println("Skip " + name);
                            }
                        }
                        //                            }
                        seen.add(e.getName());
                    }
                }
            } catch (IOException ex) {
                throw new MojoExecutionException("Failed to create merged jar", ex);
            }
        }

        for (File f : jars) {
            log.info("Merge JAR " + f);
            try (JarFile jar = new JarFile(f)) {
                Enumeration<JarEntry> en = jar.entries();
                while (en.hasMoreElements()) {
                    JarEntry entry = en.nextElement();
                    String name = entry.getName();
                    for (String s : exclude) {
                        if (name.startsWith(s)) {
                            continue;
                        }
                    }
                    if (PAT.matcher(name).matches()) {
                        log.info("Include " + name + " in " + f);
                        Properties p = new Properties();
                        try (InputStream in = jar.getInputStream(entry)) {
                            p.load(in);
                        }
                        Properties all = m.get(name);
                        if (all == null) {
                            all = p;
                            m.put(name, p);
                        } else {
                            for (String key : p.stringPropertyNames()) {
                                if (all.containsKey(key)) {
                                    Object old = all.get(key);
                                    Object nue = p.get(key);
                                    if (!Objects.equal(old, nue)) {
                                        log.warn(key + '=' + nue + " in " + f + '!' + name + " overrides " + key
                                                + '=' + old);
                                    }
                                }
                            }
                            all.putAll(p);
                        }
                    } else if (SERVICES.matcher(name).matches()
                            || "META-INF/settings/namespaces.list".equals(name)
                            || "META-INF/http/pages.list".equals(name)
                            || "META-INF/http/modules.list".equals(name)
                            || "META-INF/http/numble.list".equals(name)) {
                        log.info("Include " + name + " in " + f);
                        try (InputStream in = jar.getInputStream(entry)) {
                            List<String> lines = readLines(in);
                            Set<String> all = linesForName.get(name);
                            if (all == null) {
                                all = new LinkedHashSet<>();
                                linesForName.put(name, all);
                            }
                            all.addAll(lines);
                        }
                        Integer ct = fileCountForName.get(name);
                        if (ct == null) {
                            ct = 1;
                        } else {
                            ct++;
                        }
                        fileCountForName.put(name, ct);
                    } else if (jarOut != null) {
                        //                            if (!seen.contains(name)) {
                        switch (name) {
                        case "META-INF/MANIFEST.MF":
                        case "META-INF/":
                            break;
                        case "META-INF/LICENSE":
                        case "META-INF/LICENSE.txt":
                        case "META-INF/settings/namespaces.list":
                        case "META-INF/http/pages.list":
                        case "META-INF/http/numble.list":
                        case "META-INF/http/modules.list":
                            Set<String> s = linesForName.get(name);
                            if (s == null) {
                                s = new LinkedHashSet<>();
                                linesForName.put(name, s);
                            }
                            Integer ct = fileCountForName.get(name);
                            if (ct == null) {
                                ct = 1;
                            }
                            fileCountForName.put(name, ct);
                            try (InputStream in = jar.getInputStream(entry)) {
                                s.addAll(readLines(in));
                            }
                            break;
                        default:
                            if (!seen.contains(name)) {
                                if (!SIG1.matcher(name).find() && !SIG2.matcher(name).find()
                                        && !SIG3.matcher(name).find()) {
                                    JarEntry je = new JarEntry(name);
                                    je.setTime(entry.getTime());
                                    try {
                                        jarOut.putNextEntry(je);
                                    } catch (ZipException ex) {
                                        throw new MojoExecutionException("Exception putting zip entry " + name,
                                                ex);
                                    }
                                    try (InputStream in = jar.getInputStream(entry)) {
                                        copy(in, jarOut);
                                    }
                                    jarOut.closeEntry();
                                }
                            } else {
                                if (!name.endsWith("/") && !name.startsWith("META-INF")) {
                                    log.warn("Saw more than one " + name + ".  One will clobber the other.");
                                }
                            }
                        }
                        //                            } else {
                        //                                if (!name.endsWith("/") && !name.startsWith("META-INF")) {
                        //                                    log.warn("Saw more than one " + name + ".  One will clobber the other.");
                        //                                }
                        //                            }
                        seen.add(name);
                    }
                }
            } catch (IOException ex) {
                throw new MojoExecutionException("Error opening " + f, ex);
            }
        }
        if (!m.isEmpty()) {
            log.warn("Writing merged files: " + m.keySet());
        } else {
            return;
        }
        String outDir = project.getBuild().getOutputDirectory();
        File dir = new File(outDir);
        // Don't bother rewriting META-INF/services files of which there is
        // only one
        //            for (Map.Entry<String, Integer> e : fileCountForName.entrySet()) {
        //                if (e.getValue() == 1) {
        //                    linesForName.remove(e.getKey());
        //                }
        //            }
        for (Map.Entry<String, Set<String>> e : linesForName.entrySet()) {
            File outFile = new File(dir, e.getKey());
            log.info("Merge configurating rewriting " + outFile);
            Set<String> lines = e.getValue();
            if (!outFile.exists()) {
                try {
                    Path path = outFile.toPath();
                    if (!Files.exists(path.getParent())) {
                        Files.createDirectories(path.getParent());
                    }
                    path = Files.createFile(path);
                    outFile = path.toFile();
                } catch (IOException ex) {
                    throw new MojoFailureException("Could not create " + outFile, ex);
                }
            }
            if (!outFile.isDirectory()) {
                try (FileOutputStream out = new FileOutputStream(outFile)) {
                    try (PrintStream ps = new PrintStream(out)) {
                        for (String line : lines) {
                            ps.println(line);
                        }
                    }
                } catch (IOException ex) {
                    throw new MojoFailureException("Exception writing " + outFile, ex);
                }
            }
            if (jarOut != null) {
                log.warn("Concatenating " + fileCountForName.get(e.getKey()) + " copies of " + e.getKey());
                JarEntry je = new JarEntry(e.getKey());
                try {
                    jarOut.putNextEntry(je);
                    PrintStream ps = new PrintStream(jarOut);
                    for (String line : lines) {
                        ps.println(line);
                    }
                    jarOut.closeEntry();
                } catch (IOException ex) {
                    throw new MojoFailureException("Exception writing " + outFile, ex);
                }
            }
        }
        for (Map.Entry<String, Properties> e : m.entrySet()) {
            File outFile = new File(dir, e.getKey());
            Properties local = new Properties();
            if (outFile.exists()) {
                try {
                    try (InputStream in = new FileInputStream(outFile)) {
                        local.load(in);
                    }
                } catch (IOException ioe) {
                    throw new MojoExecutionException("Could not read " + outFile, ioe);
                }
            } else {
                try {
                    Path path = outFile.toPath();
                    if (!Files.exists(path.getParent())) {
                        Files.createDirectories(path.getParent());
                    }
                    path = Files.createFile(path);
                    outFile = path.toFile();
                } catch (IOException ex) {
                    throw new MojoFailureException("Could not create " + outFile, ex);
                }
            }
            Properties merged = e.getValue();
            for (String key : local.stringPropertyNames()) {
                if (merged.containsKey(key) && !Objects.equal(local.get(key), merged.get(key))) {
                    log.warn("Overriding key=" + merged.get(key) + " with locally defined key="
                            + local.get(key));
                }
            }
            merged.putAll(local);
            try {
                log.info("Saving merged properties to " + outFile);
                try (FileOutputStream out = new FileOutputStream(outFile)) {
                    merged.store(out, getClass().getName());
                }
            } catch (IOException ex) {
                throw new MojoExecutionException("Failed to write " + outFile, ex);
            }
            if (jarOut != null) {
                JarEntry props = new JarEntry(e.getKey());
                try {
                    jarOut.putNextEntry(props);
                    merged.store(jarOut, getClass().getName() + " merged " + e.getKey());
                    jarOut.closeEntry();
                } catch (IOException ex) {
                    throw new MojoExecutionException("Failed to write jar entry " + e.getKey(), ex);
                }
            }
            File copyTo = new File(dir.getParentFile(), "settings");
            if (!copyTo.exists()) {
                copyTo.mkdirs();
            }
            File toFile = new File(copyTo, outFile.getName());
            try {
                Files.copy(outFile.toPath(), toFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
            } catch (IOException ex) {
                throw new MojoExecutionException("Failed to copy " + outFile + " to " + toFile, ex);
            }
        }
    } finally {
        if (jarOut != null) {
            try {
                jarOut.close();
            } catch (IOException ex) {
                throw new MojoExecutionException("Failed to close Jar", ex);
            }
        }
    }
}

From source file:com.mg.maven.minifier.common.SourceFilesEnumeration.java

License:Apache License

/**
 * Enumeration public constructor.//from   w ww . ja  va 2s. c om
 *
 * @param log Maven plugin log
 * @param files list of files
 * @param verbose show source file paths in log output
 */
public SourceFilesEnumeration(Log log, List<File> files, boolean verbose, String charset) {
    this.files = files;
    this.charset = charset;

    for (File file : files) {
        log.info("Processing source file [" + ((verbose) ? file.getPath() : file.getName()) + "].");
    }
}

From source file:com.notemyweb.minify.common.ListOfFiles.java

License:Apache License

/**
 * ListOfFiles public constructor.//from www  . j  a va2 s .c om
 *
 * @param log Maven plugin log
 * @param files list of files
 * @param debug show source file paths in log output
 */
public ListOfFiles(Log log, List<File> files, boolean debug) {
    this.files = files;

    for (File file : files) {
        log.info("Processing source file [" + ((debug) ? file.getPath() : file.getName()) + "].");
    }
}

From source file:com.offbynull.coroutines.mavenplugin.AbstractInstrumentMojo.java

License:Open Source License

/**
 * Instruments all classes in a path recursively.
 * @param log maven logger/*from   w w  w  . j  a v  a  2s.  co m*/
 * @param instrumenter coroutine instrumenter
 * @param path directory containing files to instrument
 * @throws MojoExecutionException if any exception occurs
 */
protected final void instrumentPath(Log log, Instrumenter instrumenter, File path)
        throws MojoExecutionException {
    try {
        for (File classFile : FileUtils.listFiles(path, new String[] { "class" }, true)) {
            log.info("Instrumenting " + classFile);
            byte[] input = FileUtils.readFileToByteArray(classFile);
            byte[] output = instrumenter.instrument(input);
            log.debug("File size changed from " + input.length + " to " + output.length);
            FileUtils.writeByteArrayToFile(classFile, output);
        }
    } catch (Exception ex) {
        throw new MojoExecutionException("Unable to get compile classpath elements", ex);
    }
}