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:de.tarent.maven.plugins.pkg.signing.DebianSigner.java

License:Open Source License

/**
 * Generates a changelog file which complies to the Debian-Policy.
 * // ww  w. j  a  v  a2  s .  com
 * @param l
 * @param base
 * @throws MojoExecutionException
 */
protected void generateChangelogFile(Log l, File base) throws MojoExecutionException {
    l.info("generating changelog-file");

    File pathToChangelogFile = new File(base, "changelog");

    // name, version, repoName, change, author, date
    ChangelogFileGenerator cgen = new ChangelogFileGenerator();
    cgen.setPackageName(packageName);
    cgen.setVersion(packageVersion);
    cgen.setMaintainer(maintainer);
    cgen.setDate(getRFC2822Date(l, base));
    cgen.setRepositoryName(repositoryName);
    cgen.setChanges(promptForChanges());

    try {
        cgen.generate(pathToChangelogFile);
    } catch (IOException e) {
        throw new MojoExecutionException("IOException while creating changelog file.", e);
    }
}

From source file:de.tarent.maven.plugins.pkg.signing.DebianSigner.java

License:Open Source License

protected void generateChangesFile(Log l, File base) throws MojoExecutionException {
    l.info("calling " + changesGenCmd + " to generate changes-file");

    File pathToControlFile = new File(tempRoot, "control");
    File pathToChangelogFile = new File(base, "changelog");
    File pathToFileListFile = new File(tempRoot, "files");

    File pathToChangesFile = new File(base, packageFileNameWithoutExtension + ".changes");

    InputStream processOutput = Utils.exec(
            new String[] { changesGenCmd, "-b", "-c" + pathToControlFile.getAbsolutePath(),
                    "-l" + pathToChangelogFile.getAbsolutePath(), "-f" + pathToFileListFile.getAbsolutePath(),
                    "-m" + maintainer, "-e" + maintainer },
            tempRoot, "Generating changes-file failed", "Error creating the changes-file.");

    // Store output of the executed process into a .changes-file
    if (processOutput != null) {
        Utils.storeInputStream(processOutput, pathToChangesFile, "Error when storing the changes-file.");
    } else {/*from  ww w. j a v a2s . c  o m*/
        throw new MojoExecutionException("Storing the changes-file to \"" + pathToChangesFile.getAbsolutePath()
                + "\"failed (No output from " + changesGenCmd + ").");
    }
}

From source file:de.tarent.maven.plugins.pkg.signing.DebianSigner.java

License:Open Source License

/**
 * Generates a control-file containing a 'Source' line which is needed for
 * generating the .changes-file.//ww w.j  a  v a2  s  .  c o m
 * 
 * @param l
 * @param base
 * @throws MojoExecutionException
 */
protected void generateSourceControlFile(Log l, File base) throws MojoExecutionException {
    File pathToControlFile = new File(tempRoot, "control");

    l.info("creating source-control file: " + pathToControlFile.getAbsolutePath());

    SourceControlFileGenerator cgen = new SourceControlFileGenerator();
    cgen.setSource(packageName);
    cgen.setPackageName(packageName);
    cgen.setVersion(packageVersion);
    cgen.setSection(section);
    cgen.setMaintainer(maintainer);
    cgen.setArchitecture(architecture);

    l.info("creating control file: " + pathToControlFile.getAbsolutePath());
    Utils.createFile(pathToControlFile, "control");

    try {
        cgen.generate(pathToControlFile);
    } catch (IOException ioe) {
        throw new MojoExecutionException("IOException while creating control file.", ioe);
    }
}

From source file:de.tarent.maven.plugins.pkg.Utils.java

License:Open Source License

/**
 * This wraps doing a "chmod +x" on a file + logging.
 * /*from w w  w  .  j  a va  2  s.c o m*/
 * @param l
 * @param f
 * @param item
 * @throws MojoExecutionException
 */
public static void makeExecutable(Log l, String f) throws MojoExecutionException {
    l.info("make executable " + f);
    exec(new String[] { "chmod", "+x", f }, "Changing the " + f + " file attributes failed.",
            "Unable to make " + f + " file executable.");

}

From source file:de.tarent.maven.plugins.pkg.Utils.java

License:Open Source License

public static long copyProjectArtifact(Log l, File src, File dst) throws MojoExecutionException {

    if (l != null) {
        l.info("copying artifact: " + src.getAbsolutePath());
        l.info("destination: " + dst.getAbsolutePath());
    }//w  ww .  j  a va2  s  .  c  o  m
    Utils.createFile(dst, "destination artifact");

    try {
        FileUtils.copyFile(src, dst);
        return src.length();
    } catch (IOException ioe) {
        throw new MojoExecutionException("IOException while copying artifact file.", ioe);
    }

}

From source file:de.tarent.maven.plugins.pkg.Utils.java

License:Open Source License

/**
 * Copies the <code>AuxFile</code> instances contained within the set. It
 * takes the <code>srcAuxFilesDir</code> and <code>auxFileDstDir</code>
 * arguments into account to specify the parent source and destination
 * directory of the files./*  w  ww . ja  v  a2 s  . c o  m*/
 * 
 * By default files are copied into directories. If the <code>rename</code>
 * property of the <code>AuxFile</code> instance is set however the file is
 * copied and renamed to the last part of the path.
 * 
 * The return value is the amount of copied bytes.
 * 
 * @param l
 * @param srcAuxFilesDir
 * @param dstDir
 * @param auxFiles
 * @param makeExecutable
 * @return
 * @throws MojoExecutionException
 */
public static long copyFiles(Log l, File srcDir, File dstDir, List<? extends AuxFile> auxFiles, String type,
        boolean makeExecutable) throws MojoExecutionException {
    long size = 0;

    Iterator<? extends AuxFile> ite = auxFiles.iterator();
    while (ite.hasNext()) {
        AuxFile af = (AuxFile) ite.next();
        File from = new File(srcDir, af.from);
        File to = new File(dstDir, af.to);

        l.info("copying " + type + ": " + from.toString());
        l.info("destination: " + to.toString());

        if (!from.exists()) {
            throw new MojoExecutionException("File to copy does not exist: " + from.toString());
        }
        createParentDirs(to, type);

        try {
            if (from.isDirectory()) {
                to = new File(to, from.getName());
                FileUtils.copyDirectory(from, to, FILTER);
                for (final Iterator<File> files = FileUtils.iterateFiles(from, FILTER, FILTER); files
                        .hasNext();) {
                    final File nextFile = files.next();
                    size += nextFile.length();
                }
            } else if (af.isRename()) {
                FileUtils.copyFile(from, to);
                size += from.length();

                if (makeExecutable) {
                    makeExecutable(l, to.getAbsolutePath());
                }
            } else {
                FileUtils.copyFileToDirectory(from, to);
                size += from.length();

                if (makeExecutable) {
                    makeExecutable(l, to.getAbsolutePath() + File.separator + from.getName());
                }
            }
        } catch (IOException ioe) {
            throw new MojoExecutionException("IOException while copying " + type, ioe);
        }
    }

    return size;
}

From source file:de.tarent.maven.plugins.pkg.Utils.java

License:Open Source License

/**
 * Copies the starter classfile to the starter path, prepares the classpath
 * properties file and stores it at that location, too.
 * /* w  w  w.  ja va 2  s.c om*/
 * @param dstStarterRoot
 * @param dependencies
 * @param libraryPrefix
 * @throws MojoExecutionException
 */
public static void setupStarter(Log l, String mainClass, File dstStarterRoot, Path classpath)
        throws MojoExecutionException {
    File destStarterClassFile = new File(dstStarterRoot, STARTER_CLASS);

    Utils.createFile(destStarterClassFile, "starter class");
    Utils.storeInputStream(Utils.class.getResourceAsStream("/" + STARTER_CLASS), destStarterClassFile,
            "Unable to store starter class file in destination.");

    File destClasspathFile = new File(dstStarterRoot, "_classpath");
    Utils.createFile(destClasspathFile, "starter classpath");

    PrintWriter writer = null;
    try {
        writer = new PrintWriter(destClasspathFile);

        writer.println("# This file controls the application's classpath and is autogenerated.");
        writer.println("# Slashes (/) in the filenames are replaced with the platform-specific");
        writer.println("# separator char at runtime.");
        writer.println("# The next line is the fully-classified name of the main class:");
        writer.println(mainClass);
        writer.println("# The following lines are the classpath entries:");

        for (String e : classpath) {
            writer.println(e);
        }

        l.info("created library entries");
    } catch (IOException e) {
        throw new MojoExecutionException("storing the classpath entries failed", e);
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
}

From source file:de.tarent.maven.plugins.pkg.Utils.java

License:Open Source License

/**
 * Copies the Artifacts contained in the set to the folder denoted by
 * <code>dst</code> and returns the amount of bytes copied.
 * //from ww  w . j a  va 2 s . co m
 * <p>
 * If an artifact is a zip archive it is unzipped in this folder.
 * </p>
 * 
 * @param l
 * @param artifacts
 * @param dst
 * @return
 * @throws MojoExecutionException
 */
public static long copyArtifacts(Log l, Set<Artifact> artifacts, File dst) throws MojoExecutionException {
    long byteAmount = 0;

    if (artifacts.size() == 0) {
        l.info("no artifact to copy.");
        return byteAmount;
    }

    l.info("copying " + artifacts.size() + " dependency artifacts.");
    l.info("destination: " + dst.toString());

    try {
        Iterator<Artifact> ite = artifacts.iterator();
        while (ite.hasNext()) {
            Artifact a = (Artifact) ite.next();
            l.info("copying artifact: " + a);
            File f = a.getFile();
            if (f != null) {
                l.debug("from file: " + f);
                if (a.getType().equals("zip")) {
                    // Assume that this is a ZIP file with native libraries
                    // inside.

                    // TODO: Determine size of all entries and add this
                    // to the byteAmount.
                    unpack(a.getFile(), dst);
                } else {
                    FileUtils.copyFileToDirectory(f, dst);
                    byteAmount += (long) f.length();
                }

            } else {
                throw new MojoExecutionException(
                        "Unable to copy Artifact " + a + " because it is not locally available.");
            }
        }
    } catch (IOException ioe) {
        throw new MojoExecutionException("IOException while copying dependency artifacts.", ioe);
    }

    return byteAmount;
}

From source file:de.tarent.maven.plugins.pkg.Utils.java

License:Open Source License

/**
 * Returns the default Distro to use for a certain TargetConfiguration.
 * //from   w  w  w. j a  va 2  s.c o  m
 * @param configuration
 * @return
 * @throws MojoExecutionException
 */
public static String getDefaultDistro(String targetString, List<TargetConfiguration> targetConfigurations,
        Log l) throws MojoExecutionException {
    String distro = null;
    TargetConfiguration target = Utils.getTargetConfigurationFromString(targetString, targetConfigurations);

    if (target.getDefaultDistro() != null) {
        distro = target.getDefaultDistro();
        l.info("Default distribution is set to \"" + distro + "\".");
    } else
        switch (target.getDistros().size()) {
        case 0:
            throw new MojoExecutionException("No distros defined for configuration " + targetString);
        case 1:
            distro = (String) target.getDistros().iterator().next();
            l.info(String.format("Only one distro defined, using '%s' as default", distro));
            break;
        default:
            String m = "No default configuration given for distro '" + targetString
                    + "', and more than one distro is supported. Please provide one.";
            l.error(m);
            throw new MojoExecutionException(m);
        }
    return distro;
}

From source file:de.thetaphi.forbiddenapis.AbstractCheckMojo.java

License:Apache License

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

    if (skip) {//from   w w w . j  a va 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
            }
    }
}