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:org.apache.tuscany.maven.bundle.plugin.ModuleBundlesBuildMojo.java

License:Apache License

private void generateANTPath(ProjectSet jarNames, File root, Log log)
        throws FileNotFoundException, IOException {
    for (Map.Entry<String, Set<String>> e : jarNames.nameMap.entrySet()) {
        Set<String> jars = e.getValue();
        File feature = new File(root,
                "../" + featuresName + "/" + (useDistributionName ? trim(e.getKey()) : ""));
        feature.mkdirs();/*  www.j a  v a 2s  .  c o  m*/
        File antPath = new File(feature, "build-path.xml");
        log.info("Generating ANT build path: " + antPath.getCanonicalPath());
        FileOutputStream fos = new FileOutputStream(antPath);
        PrintStream ps = new PrintStream(fos);
        // ps.println(XML_PI);
        ps.println(ASL_HEADER);
        String name = trim(e.getKey());
        ps.println("<project name=\"tuscany." + name + "\">");
        ps.println("  <property name=\"tuscany.distro\" value=\"" + name + "\"/>");
        ps.println("  <property name=\"tuscany.manifest\" value=\""
                + new File(feature, manifestJarName).getCanonicalPath() + "\"/>");
        ps.println("  <path id=\"" + "tuscany.path" + "\">");
        ps.println("    <fileset dir=\"" + root.getCanonicalPath() + "\">");
        for (String jar : jars) {
            ps.println("      <include name=\"" + jar + "\"/>");
        }
        ps.println("    </fileset>");
        ps.println("  </path>");
        ps.println("</project>");
    }
}

From source file:org.apache.tuscany.maven.bundle.plugin.ModuleBundlesBuildMojo.java

License:Apache License

private void generateManifestJar(ProjectSet jarNames, File root, Log log)
        throws FileNotFoundException, IOException {
    for (Map.Entry<String, Set<String>> e : jarNames.nameMap.entrySet()) {
        MavenProject pom = jarNames.getProject(e.getKey());
        Set<String> jars = e.getValue();
        File feature = new File(root,
                "../" + featuresName + "/" + (useDistributionName ? trim(e.getKey()) : ""));
        feature.mkdirs();// www  .  j  a  v  a 2s. c om
        File mfJar = new File(feature, manifestJarName);
        log.info("Generating manifest jar: " + mfJar.getCanonicalPath());
        FileOutputStream fos = new FileOutputStream(mfJar);
        Manifest mf = new Manifest();
        StringBuffer cp = new StringBuffer();
        String path = (useDistributionName ? "../../" : "../") + root.getName();
        for (String jar : jars) {
            cp.append(path).append('/').append(jar).append(' ');
        }
        if (cp.length() > 0) {
            cp.deleteCharAt(cp.length() - 1);
        }
        Attributes attrs = mf.getMainAttributes();
        attrs.putValue("Manifest-Version", "1.0");
        attrs.putValue("Implementation-Title", pom.getName());
        attrs.putValue("Implementation-Vendor", "The Apache Software Foundation");
        attrs.putValue("Implementation-Vendor-Id", "org.apache");
        attrs.putValue("Implementation-Version", pom.getVersion());
        attrs.putValue("Class-Path", cp.toString());
        attrs.putValue("Main-Class", "org.apache.tuscany.sca.node.launcher.NodeMain");
        JarOutputStream jos = new JarOutputStream(fos, mf);
        addFileToJar(jos, "META-INF/LICENSE", getClass().getResource("LICENSE.txt"));
        addFileToJar(jos, "META-INF/NOTICE", getClass().getResource("NOTICE.txt"));
        jos.close();
    }
}

From source file:org.apache.tuscany.maven.bundle.plugin.ThirdPartyBundleBuildMojo.java

License:Apache License

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

    String projectGroupId = project.getGroupId();
    Set<File> jarFiles = new HashSet<File>();
    for (Object o : project.getArtifacts()) {
        Artifact artifact = (Artifact) o;

        if (!(Artifact.SCOPE_COMPILE.equals(artifact.getScope())
                || Artifact.SCOPE_RUNTIME.equals(artifact.getScope()))) {
            if (log.isDebugEnabled()) {
                log.debug("Skipping artifact: " + artifact);
            }//from  www . j a v a  2s .  c  om
            continue;
        }
        if (!"jar".equals(artifact.getType())) {
            continue;
        }
        if (projectGroupId.equals(artifact.getGroupId())) {
            continue;
        }

        if (log.isDebugEnabled()) {
            log.debug("Artifact: " + artifact);
        }
        String bundleName = null;
        try {
            bundleName = BundleUtil.getBundleSymbolicName(artifact.getFile());
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
        if (bundleName == null || true) {
            if (artifact.getFile().exists()) {
                log.info("Adding third party jar: " + artifact);
                jarFiles.add(artifact.getFile());
            } else {
                log.warn("Third party jar not found: " + artifact);
            }
        }
    }

    try {
        String version = BundleUtil.osgiVersion(project.getVersion());

        Manifest mf = BundleUtil.libraryManifest(jarFiles, project.getName(), symbolicName, version, "lib");
        File file = new File(project.getBasedir(), "META-INF");
        file.mkdir();
        file = new File(file, "MANIFEST.MF");
        if (log.isDebugEnabled()) {
            log.debug("Generating " + file);
        }

        FileOutputStream fos = new FileOutputStream(file);
        write(mf, fos);
        fos.close();

        File lib = new File(project.getBasedir(), "lib");
        if (lib.isDirectory()) {
            for (File c : lib.listFiles()) {
                c.delete();
            }
        }
        lib.mkdir();
        byte[] buf = new byte[4096];
        for (File jar : jarFiles) {
            File jarFile = new File(lib, jar.getName());
            if (log.isDebugEnabled()) {
                log.debug("Copying " + jar + " to " + jarFile);
            }
            FileInputStream in = new FileInputStream(jar);
            FileOutputStream out = new FileOutputStream(jarFile);
            for (;;) {
                int len = in.read(buf);
                if (len > 0) {
                    out.write(buf, 0, len);
                } else {
                    break;
                }
            }
            in.close();
            out.close();
        }
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

}

From source file:org.apache.tuscany.maven.plugin.TuscanyLaunchMojo.java

License:Apache License

protected void waitForShutdown(DomainNode domainNode, Log log) {
    Runtime.getRuntime().addShutdownHook(new ShutdownThread(domainNode, log));
    synchronized (this) {
        try {//from  w ww .ja v a  2 s .c  o m
            log.info("Ctrl-C to end...");
            this.wait();
        } catch (InterruptedException e) {
            log.error(e);
        }
    }
}

From source file:org.appverse.web.tools.codegenerator.ServiceClassLoader.java

License:Mozilla Public License

public static ServiceClassLoader create(ClassLoader pluginClassLoader, MavenProject project, Log logger) {
    List<URL> urls = new ArrayList<URL>();
    try {//from   w w w .ja v  a 2 s . c o  m
        File classDir = null;
        classDir = new File(project.getBuild().getOutputDirectory());
        project.getParent().getModules();
        String s = project.getParent().getBasedir().getAbsolutePath();
        logger.info("parent base path [" + s + "]");
        logger.info("collectedProjects :" + project.getParent().getBuild().getOutputDirectory());
        List<String> l = project.getParent().getModules();
        for (String sModule : l) {
            File classDirTmp = new File(project.getParent().getBasedir(), sModule + "\\target\\classes");
            logger.info("path [" + classDirTmp.getAbsolutePath() + "]");
            urls.add(classDirTmp.toURI().toURL());
        }
        urls.add(classDir.toURI().toURL());
        classDir = new File(project.getBuild().getTestOutputDirectory());
        urls.add(classDir.toURI().toURL());
    } catch (MalformedURLException e) {
        throw new RuntimeException("Error while assembling classpath", e);
    }
    URL[] a = urls.toArray(new URL[0]);
    return new ServiceClassLoader(a, pluginClassLoader);
}

From source file:org.appverse.web.tools.codegenerator.ServiceCodeMojo.java

License:Appverse Public License

@Override
public void execute() throws MojoExecutionException {
    Log logger = getLog();
    try {/* ww  w.j a  v  a  2s. co m*/
        logger.info("generate-service for [" + presentationServiceName + "]");
        logger.info("adding to classpath :" + project.getBuild().getOutputDirectory());
        ServiceCreatorContext serviceContext = new ServiceCreatorContext(presentationServiceName, srcOutputDir,
                presentationSuffix, businessSuffix, integrationSuffix);
        ServiceClassLoader classLoader = ServiceClassLoader.create(this.getClass().getClassLoader(), project,
                logger);
        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(classLoader);
            Class cl = classLoader.loadClass(presentationServiceName);
            Method[] methodList = cl.getMethods();
            serviceContext.setPresentationInterfaceMethods(methodList);
            AbstractServiceFactory factory = AbstractServiceFactory.getFactory(/*genPresentationService*/true,
                    /*genBusinessService*/true, /*genIntegrationService*/true, /*genBusinessModel*/true,
                    /*genIntegrationModel*/true, /*genP2BConfig*/true, /*genB2IConfig*/true, serviceContext);
            StringBuilder sb = new StringBuilder(" LIST OF GENERATED FILES: \n");
            List<AbstractServiceCreator> creatorList = factory.getServiceCreators();
            for (AbstractServiceCreator creator : creatorList) {
                creator.build();
                creator.saveFile();
                sb.append(creator.getGeneratedInfo()).append("\n");
            }
            //System.out.println("Service Context mod");
            //System.out.println(serviceContext);

            //Integration are obtained from different sources...

            List<AbstractServiceCreator> integrationList = factory
                    .getIntegrationCreatorsBasedOnModels(serviceContext);
            for (AbstractServiceCreator creator : integrationList) {
                creator.build();
                creator.saveFile();
                sb.append(creator.getGeneratedInfo()).append("\n");
            }

            //serviceContext has a Map with all Presentation beans that needs to be created
            //Input: Class [org.appverse.web.showcases.gwtshowcase.backend.model.presentation.UserVO]
            //Output: class User
            List<AbstractModelCreator> creatorModelList = factory.getModelCreators(serviceContext);
            for (AbstractModelCreator creator : creatorModelList) {
                creator.build();
                creator.saveFile();
                sb.append(creator.getGeneratedInfo()).append("\n");
            }
            logger.info(sb.toString());

        } finally {
            Thread.currentThread().setContextClassLoader(tccl);
        }

        //classpath!

    } catch (Throwable e) {
        e.printStackTrace();
        throw new MojoExecutionException("Error while generating code", e);
    }
}

From source file:org.arsenico.BaseMojo.java

License:Apache License

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

    Settings s = Settings.getInstance();

    s.setDatabaseUrl(databaseUrl);//from  ww  w . ja v  a 2 s. co  m
    s.setDatabaseUsername(databaseUser);
    s.setDatabasePassword(databasePwd);
    s.setDatabaseType(databaseType);

    s.setSvnUrl(svnUrl);
    s.setVersion(version);
    s.setBuildNumber(buildNumber);

    s.setDirectorySource(sqlDirectory);
    s.setFileNamePattern(fileNameFilter);

    s.setIgnoredErrors(ignoredErrors);
    s.setLogger(new LoggerImpl(log));

    try {
        log.info("Build number = " + this.buildNumber);
        log.info("DB Url = " + databaseUrl);
        log.info("DB User = " + databaseUser);
        log.info("DB Type = " + databaseType);
        log.info("SCM Url = " + svnUrl);
        log.info("Version = " + version);
        log.info("Sql Directory (relative) = " + sqlDirectory);
        log.info("Sql Directory (absolute) = " + (new File(sqlDirectory)).getAbsolutePath());

        executor.execute();
        log.info("Esecuzione terminata correttamente");
    } catch (Exception e) {
        //log.error(e.getMessage());
        throw (new MojoExecutionException("Errore durante l'esecuzione del plugin SqlDeployer!", e));
    }
}

From source file:org.boretti.drools.integration.drools5.DroolsClassProcessor.java

License:Open Source License

public static void ClassProcessor(Log logger, File src, DroolsGoalExecutionLogs dgel)
        throws MojoExecutionException {
    if (src == null)
        return;/*from  w  w w  . j av  a 2 s .  c om*/
    try {
        DroolsGoalExecutionLog del = new DroolsGoalExecutionLog(src.getAbsolutePath(), "postprocessor",
                "Class defined by file " + src.getAbsolutePath() + " has been rewritten by the plugin");
        FileInputStream fis = new FileInputStream(src);
        ClassReader cr = new ClassReader(fis);
        ClassWriter cw = new ClassWriter(cr, 0);
        DroolsClassVisitor dcv = new DroolsClassVisitor(logger, cw, del);
        cr.accept(dcv, ClassReader.EXPAND_FRAMES);
        byte clazz[] = cw.toByteArray();
        fis.close();
        if (dcv.isNeedChange()) {
            logger.info("File " + src + " must be rewritten.");
            fis.close();
            FileOutputStream fos = new FileOutputStream(src);
            fos.write(clazz);
            dgel.getLogs().add(del);
        }
    } catch (FileNotFoundException e) {
        logger.error("" + e.getMessage(), e);
        throw new MojoExecutionException("" + e.getMessage(), e);
    } catch (IOException e) {
        logger.error("" + e.getMessage(), e);
        throw new MojoExecutionException("" + e.getMessage(), e);
    }
}

From source file:org.boretti.drools.integration.drools5.DroolsClassProcessor.java

License:Open Source License

public static void postProcess(Log log, File inputDirectory, String extension, File reportDirectory,
        String reportFile, String[] includes, String[] excludes) throws MojoExecutionException {
    DroolsGoalExecutionLogs dgel = new DroolsGoalExecutionLogs();
    DirectoryScanner scanner = new DirectoryScanner();
    if (!inputDirectory.exists()) {
        log.warn("Skipping not existing directory " + inputDirectory);
        return;/*w  w  w. j  a  v a2s .co  m*/
    }
    scanner.setBasedir(inputDirectory);
    if (includes == null || includes.length == 0) {
        scanner.setIncludes(new String[] { "**/*" + extension, "*" + extension });
    } else {
        log.info("Included files are " + Arrays.toString(includes));
        scanner.setIncludes(includes);
    }
    if (excludes != null && excludes.length != 0) {
        log.info("Excluded files are " + Arrays.toString(excludes));
        scanner.setExcludes(excludes);
    }
    log.info("Files must ends with " + extension + " to be processed");
    scanner.scan();
    for (String file : scanner.getIncludedFiles()) {
        if (!file.endsWith(extension))
            continue;
        File sfile = new File(inputDirectory, file);
        DroolsClassProcessor.ClassProcessor(log, sfile, dgel);
    }
    try {
        dgel.writeMeToFile(new File(reportDirectory, reportFile));
    } catch (IOException e) {
        log.error("Unable to write report :" + e.getMessage(), e);
        throw new MojoExecutionException("" + e.getMessage(), e);
    } catch (JAXBException e) {
        log.error("Unable to write report :" + e.getMessage(), e);
        throw new MojoExecutionException("" + e.getMessage(), e);
    }
}

From source file:org.buildforce.tomcat.util.FileSystemUtils.java

License:Apache License

/**
 * Copies given resources to the build directory.
 *
 * @param resources// w  w  w.  ja va2s  .c  o m
 * @param log
 * @throws MojoExecutionException
 */
public static void copyResources(Resource[] resources, Log log) throws MojoExecutionException {
    final String[] emptyStrArray = {};

    for (Resource resource : resources) {
        FileSet fileSet = new FileSet();
        fileSet.setDirectory(resource.getDirectory());

        for (Object include : resource.getIncludes())
            fileSet.addInclude((String) include);

        for (Object exclude : resource.getExcludes())
            fileSet.addExclude((String) exclude);

        File resourceDirectory = new File(fileSet.getDirectory());
        if (!resourceDirectory.isAbsolute())
            resourceDirectory = new File(resourceDirectory.getPath());

        if (!resourceDirectory.exists()) {
            log.info("Additional resource directory does not exist: " + resourceDirectory);
            continue;
        }

        DirectoryScanner scanner = new DirectoryScanner();

        scanner.setBasedir(resourceDirectory);
        if (fileSet.getIncludes() != null && !fileSet.getIncludes().isEmpty())
            //noinspection unchecked
            scanner.setIncludes((String[]) fileSet.getIncludes().toArray(emptyStrArray));
        else
            scanner.setIncludes(DEFAULT_INCLUDES);

        if (fileSet.getExcludes() != null && !fileSet.getExcludes().isEmpty())
            //noinspection unchecked
            scanner.setExcludes((String[]) fileSet.getExcludes().toArray(emptyStrArray));

        scanner.addDefaultExcludes();
        scanner.scan();

        List includedFiles = Arrays.asList(scanner.getIncludedFiles());

        log.info("Copying " + includedFiles.size() + " web resource" + (includedFiles.size() > 1 ? "s" : ""));

        for (Object includedFile : includedFiles) {
            String destination = (String) includedFile;
            File source = new File(resourceDirectory, destination);
            File destinationFile = new File(resource.getTargetPath(), destination);

            if (!destinationFile.getParentFile().exists())
                destinationFile.getParentFile().mkdirs();

            try {
                org.codehaus.plexus.util.FileUtils.copyFile(source, destinationFile);
            } catch (IOException e) {
                throw new MojoExecutionException("Error copying web resource " + source, e);
            }
        }
    }
}