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.AotCompileUtils.java

License:Open Source License

public static void compile(Log l, File jar, File binary) throws MojoExecutionException {
    Utils.createParentDirs(binary, "aot binary");

    l.info("compiling to binary: " + binary.getAbsolutePath());
    Utils.exec(/*w  w  w . jav a2s  .  c o  m*/
            new String[] { GCJ_EXECUTABLE, "-O2", "-g", "-Wl,-Bsymbolic", "-shared", "-fPIC", "-fjni",
                    "-findirect-dispatch", "-o", binary.getAbsolutePath(), jar.getAbsolutePath(), },
            GCJ_EXECUTABLE + " returned with an error.", "IOException while doing aot compilation.");

}

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

License:Open Source License

public static void generateClassmap(Log l, File classmap, File jar, File binary, String overridePath)
        throws MojoExecutionException {
    l.info("creating classmap file with " + GCJ_DBTOOL_EXECUTABLE + ": " + classmap.getAbsolutePath());

    Utils.createParentDirs(classmap, "classmap file");

    Utils.exec(new String[] { GCJ_DBTOOL_EXECUTABLE, "-n", classmap.getAbsolutePath() },
            GCJ_DBTOOL_EXECUTABLE + " returned with an error.", "IOException while creating classmap file.");

    String dsoName = (overridePath.length() > 0) ? overridePath + "/" + binary.getName() : binary.getName();

    l.info("filling classmap file");
    Utils.exec(/*from  ww  w .j  a v  a2s. c  o m*/
            new String[] { GCJ_DBTOOL_EXECUTABLE, "-f", classmap.getAbsolutePath(), jar.getAbsolutePath(),
                    dsoName },
            GCJ_DBTOOL_EXECUTABLE + " returned with an error.", "IOException while creating classmap file.");

}

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

License:Open Source License

public static void depositPostinstFile(Log l, File postinstFile) throws MojoExecutionException {
    l.info("depositing postinst file for aot-compilation: " + postinstFile.getAbsolutePath());

    Utils.createFile(postinstFile, "postinst");

    // The postinst file does not change and is therefore part of the
    // plugins classpath and can be retrieved from there.
    Utils.storeInputStream(AotCompileUtils.class.getResourceAsStream("postinst"), postinstFile,
            "IOException while depositing the postinst file.");

    // Make the postinst file executable.
    Utils.makeExecutable(postinstFile, "postinst");

}

From source file:de.tarent.maven.plugins.pkg.helper.Helper.java

License:Open Source License

final void prepareDirectories(Log l, File basePkgDir, File jniDir) throws MojoExecutionException {

    if (l != null) {
        l.info("creating package directory: " + basePkgDir.getAbsolutePath());
    }//from  ww w  .  j  a  va2s.c om
    if (!basePkgDir.mkdirs()) {
        throw new MojoExecutionException("Could not create package directory.");
    }
    if (jniDir != null && targetConfiguration.getJniFiles() != null
            && targetConfiguration.getJniFiles().size() > 0 && !jniDir.mkdirs()) {
        throw new MojoExecutionException("Could not create JNI directory.");
    }

}

From source file:de.tarent.maven.plugins.pkg.helper.Helper.java

License:Open Source License

/**
 * Creates the bootclasspath and classpath line from the project's
 * dependencies.//from   ww  w.j a  v  a2 s. c  o m
 * 
 * @param pm
 *            The package map used to resolve the Jar file names.
 * @param bundled
 *            A set used to track the bundled jars for later file-size
 *            calculations.
 * @param bcp
 *            StringBuilder which contains the boot classpath line at the
 *            end of the method.
 * @param cp
 *            StringBuilder which contains the classpath line at the end of
 *            the method.
 */
protected final void createClasspathLine(final Log l, final File targetJarPath, final Path bcp, final Path cp,
        File targetArtifactFile) throws MojoExecutionException {
    // final Set<Artifact> bundled = new HashSet<Artifact>();

    l.info("resolving dependency artifacts");

    Set<Artifact> dependencies = new HashSet<Artifact>();
    try {
        // Notice only compilation dependencies which are Jars.
        // Shared Libraries ("so") are filtered out because the
        // JNI dependency is solved by the system already.

        // Here a filter for depencies of the COMPILE scope is created
        AndArtifactFilter compileFilter = new AndArtifactFilter();
        compileFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_COMPILE));
        compileFilter.add(new TypeArtifactFilter("jar"));

        // The result of the COMPILE filter will be added to the depencies
        // set
        dependencies.addAll(Utils.findArtifacts(compileFilter, apm.getFactory(), apm.getResolver(),
                apm.getProject(), apm.getProject().getArtifact(), apm.getLocalRepo(), apm.getRemoteRepos(),
                apm.getMetadataSource()));

        // Here a filter for depencies of the RUNTIME scope is created
        AndArtifactFilter runtimeFilter = new AndArtifactFilter();
        runtimeFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME));
        runtimeFilter.add(new TypeArtifactFilter("jar"));

        // The result of the RUNTIME filter will be added to the depencies
        // set
        dependencies.addAll(Utils.findArtifacts(runtimeFilter, apm.getFactory(), apm.getResolver(),
                apm.getProject(), apm.getProject().getArtifact(), apm.getLocalRepo(), apm.getRemoteRepos(),
                apm.getMetadataSource()));

        // Here a filter for depencies of the PROVIDED scope is created
        AndArtifactFilter providedFilter = new AndArtifactFilter();
        providedFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_PROVIDED));
        providedFilter.add(new TypeArtifactFilter("jar"));

        // The result of the PROVIDED filter will be added to the depencies
        // set
        dependencies.addAll(Utils.findArtifacts(providedFilter, apm.getFactory(), apm.getResolver(),
                apm.getProject(), apm.getProject().getArtifact(), apm.getLocalRepo(), apm.getRemoteRepos(),
                apm.getMetadataSource()));

    } catch (ArtifactNotFoundException anfe) {
        throw new MojoExecutionException("Exception while resolving dependencies", anfe);
    } catch (InvalidDependencyVersionException idve) {
        throw new MojoExecutionException("Exception while resolving dependencies", idve);
    } catch (ProjectBuildingException pbe) {
        throw new MojoExecutionException("Exception while resolving dependencies", pbe);
    } catch (ArtifactResolutionException are) {
        throw new MojoExecutionException("Exception while resolving dependencies", are);
    }

    Visitor v = new Visitor() {
        public void bundle(Artifact artifact) {
            // Nothing to do here. bundleDependencies should take care of
            // this.

        }

        public void visit(Artifact artifact, Entry entry) {
            // If all dependencies should be bundled skip adding them to the
            // classpath
            // thereby overriding what was configured through property
            // files.
            if (targetConfiguration.isBundleAll()) {
                return;
            }

            Path b = (entry.isBootClasspath) ? bcp : cp;

            Iterator<String> ite = entry.jarFileNames.iterator();
            while (ite.hasNext()) {
                StringBuilder sb = new StringBuilder();
                String fileName = ite.next();

                // Prepend default Jar path if file is not absolute.
                if (fileName.charAt(0) != '/') {
                    sb.append(packageMap.getDefaultJarPath());
                    sb.append("/");
                }

                sb.append(fileName);

                b.append(sb.toString());
            }
        }

    };

    if (!targetConfiguration.isIgnoreDependencies()) {
        packageMap.iterateDependencyArtifacts(l, dependencies, v, true);
    }

    // Add the custom jar files to the classpath
    for (Iterator<JarFile> ite = targetConfiguration.getJarFiles().iterator(); ite.hasNext();) {
        AuxFile auxFile = ite.next();

        cp.append(targetJarPath.toString() + "/" + new File(auxFile.getFrom()).getName());
    }

    // Add the project's own artifact at last. This way we can
    // save the deletion of the colon added in the loops above.
    cp.append(targetArtifactFile.toString());

    // return bundled;
}

From source file:de.tarent.maven.plugins.pkg.helper.Helper.java

License:Open Source License

/**
 * Investigates the project's runtime dependencies and prepares them to be
 * copied into the package./*from   www .j  a v  a 2s .  co  m*/
 * 
 * @param l
 * @param targetJarPath
 * @param bcp
 * @param cp
 * @param targetArtifactFile
 * @return
 * @throws MojoExecutionException
 */
protected final Set<Artifact> bundleDependencies(final Log l, final Set<Artifact> resolvedDependencies,
        final File targetJarPath, final Path bcp, final Path cp, File targetArtifactFile)
        throws MojoExecutionException {

    final Set<Artifact> bundled = new HashSet<Artifact>();

    l.info("Copying dependencies into package");

    Visitor v = new Visitor() {
        public void bundle(Artifact artifact) {
            // Put to artifacts which will be bundled (allows copying and
            // filesize
            // summing later).
            bundled.add(artifact);

            // TODO: Perhaps one want a certain bundled dependency in boot
            // classpath.

            // Bundled Jars will always live in targetJarPath
            File file = artifact.getFile();
            if (file != null) {
                cp.append(targetJarPath.toString() + "/" + file.getName());
            } else {
                l.warn("Cannot bundle artifact " + artifact.getArtifactId());
            }
        }

        public void visit(Artifact artifact, Entry entry) {

            /**
             * Only if we wish to bundle dependency artifacts we will do so
             */
            if (targetConfiguration.isBundleDependencyArtifacts()) {

                // If all dependencies should be bundled take a short-cut to
                // bundle()
                // thereby overriding what was configured through property
                // files.
                if (targetConfiguration.isBundleAll()) {
                    bundle(artifact);
                    return;
                }

                Path b = (entry.isBootClasspath) ? bcp : cp;

                Iterator<String> ite = entry.jarFileNames.iterator();

                while (ite.hasNext()) {
                    StringBuilder sb = new StringBuilder();
                    String fileName = ite.next();

                    // Prepend default Jar path if file is not absolute.
                    if (fileName.charAt(0) != '/') {
                        sb.append(packageMap.getDefaultJarPath());
                        sb.append("/");
                    }

                    sb.append(fileName);

                    b.append(sb.toString());
                }
            }
        }

    };

    packageMap.iterateDependencyArtifacts(l, resolvedDependencies, v, true);

    // Add the custom jar files to the classpath
    for (Iterator<JarFile> ite = targetConfiguration.getJarFiles().iterator(); ite.hasNext();) {
        AuxFile auxFile = ite.next();

        cp.append(targetJarPath.toString() + "/" + new File(auxFile.getFrom()).getName());
    }

    // Add the project's own artifact at last. This way we can
    // save the deletion of the colon added in the loops above.
    cp.append(targetArtifactFile.toString());

    return bundled;
}

From source file:de.tarent.maven.plugins.pkg.helper.Helper.java

License:Open Source License

/**
 * //from   ww  w.j  a va 2  s.  c om
 * Removes the new macros file and restores the backup created by
 * {@link #createrpmmacrosfile}
 * 
 * @param l
 * @throws IOException
 */
public void restoreRpmMacrosFileBackup(Log l) throws IOException {
    String userHome = System.getProperty("user.home");
    File original = new File(userHome + "/.rpmmacros");
    File backup = new File(userHome + "/.rpmmacros_bck");
    if (backup.exists()) {
        if (l != null) {
            l.info("Restoring .rpmmacros backup file.");
        }
        if (original.delete()) {
            FileUtils.copyFile(backup, original);
        }
    } else {
        original.delete();
    }
}

From source file:de.tarent.maven.plugins.pkg.packager.DebPackager.java

License:Open Source License

/**
 * Validates arguments and test tools.//from www.j av a  2s. c o m
 * 
 * @throws MojoExecutionException
 */
@Override
public void checkEnvironment(Log l, WorkspaceSession workspaceSession) throws MojoExecutionException {

    Utils.checkProgramAvailability("dpkg-deb");
    String output = Utils.getProgramVersionOutput("dpkg-deb");

    /*
     * We will check if the minor version number is smaller than 15.
     * Problems have been reported regarding older versions of dpkg-deb and
     * - what dpkg-deb understands as version numbers - not containing
     * numbers (bug #2912), e.g. "-SNAPSHOT".
     */

    Pattern p = Pattern.compile("version (1\\.([0-9]{2})\\.([0-9]*\\.*)*)* ", Pattern.MULTILINE);
    Matcher m = p.matcher(output);
    if (m.find()) {
        l.info("dpkg-deb version: " + m.group(1));
        int versionNumber = Integer.parseInt(m.group(2));
        if (versionNumber < 15 && workspaceSession.getHelper().getPackageVersion().contains("-SNAPSHOT")) {
            throw new MojoExecutionException(
                    "You are trying to build a snapshot with an older version of dpkg-deb. "
                            + "You are advised to add a revision number to your package (e.g. r1) or "
                            + "your package will not be built correctly.");
        }
    }
    // Some external tools are only needed if the package is to be signed
    if (workspaceSession.getTargetConfiguration().isSign()) {
        Utils.checkProgramAvailability("dpkg-distaddfile");
        Utils.checkProgramAvailability("gpg");
        Utils.checkProgramAvailability("ar");
    }
}

From source file:de.tarent.maven.plugins.pkg.packager.DebPackager.java

License:Open Source License

/**
 * Creates a control file whose dependency line can be provided as an
 * argument./*  w  w  w.  j av a 2 s. c  om*/
 * 
 * @param l
 * @param controlFile
 * @param packageName
 * @param packageVersion
 * @param installedSize
 * @throws MojoExecutionException
 */
private void generateControlFile(Log l, TargetConfiguration targetConfiguration, Helper ph, File controlFile,
        String packageName, String packageVersion, String dependencyLine, String recommendsLine,
        String suggestsLine, String providesLine, String conflictsLine, String replacesLine, long byteAmount)
        throws MojoExecutionException {
    ControlFileGenerator cgen = new ControlFileGenerator();
    cgen.setPackageName(packageName);
    cgen.setVersion(packageVersion);
    cgen.setSection(targetConfiguration.getSection());
    cgen.setDependencies(dependencyLine);
    cgen.setRecommends(recommendsLine);
    cgen.setSuggests(suggestsLine);
    cgen.setProvides(providesLine);
    cgen.setConflicts(conflictsLine);
    cgen.setReplaces(replacesLine);
    cgen.setMaintainer(targetConfiguration.getMaintainer());
    cgen.setShortDescription(ph.getProjectDescription());
    cgen.setDescription(ph.getProjectDescription());
    cgen.setArchitecture(targetConfiguration.getArchitecture());
    cgen.setInstalledSize(Utils.getInstalledSize(byteAmount));

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

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

}

From source file:de.tarent.maven.plugins.pkg.packager.DebPackager.java

License:Open Source License

/**
 * Iterates over the sysconf files and creates the Debian 'conffiles' file
 * for them./*from   w ww.j a  va2 s . co  m*/
 * 
 * <p>
 * If no sysconf files exists nothing is done however.
 * </p>
 * 
 * @param l
 * @param conffilesFile
 * @param ph
 * @param tc
 * @throws MojoExecutionException
 */
private void generateConffilesFile(Log l, File conffilesFile, TargetConfiguration targetConfiguration,
        Helper ph) throws MojoExecutionException {
    List<SysconfFile> sysconffiles = (List<SysconfFile>) targetConfiguration.getSysconfFiles();
    if (sysconffiles.isEmpty()) {
        l.info("No sysconf files defined - not creating file.");
        return;
    }

    StringBuilder sb = new StringBuilder(sysconffiles.size() * 10);
    for (SysconfFile scf : sysconffiles) {
        File targetFile;
        if (scf.isRename()) {
            targetFile = new File(ph.getTargetSysconfDir(), scf.getTo());
        } else {
            File srcFile = new File(ph.getSrcSysconfFilesDir(), scf.getFrom());
            File targetPath = new File(ph.getTargetSysconfDir(), scf.getTo());
            targetFile = new File(targetPath, srcFile.getName());
        }
        sb.append(targetFile.getAbsolutePath());
        sb.append("\n");
    }

    if (!conffilesFile.getParentFile().mkdirs()) {
        throw new MojoExecutionException("Could not create directory for conffiles file.");
    }
    try {
        conffilesFile.createNewFile();
    } catch (IOException ioe) {
        throw new MojoExecutionException("IOException while creating conffiles file.", ioe);
    }

    try {
        FileUtils.writeStringToFile(conffilesFile, sb.toString());
    } catch (IOException ioe) {
        throw new MojoExecutionException("IOException while writing to conffiles file.", ioe);
    }
}