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

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

Introduction

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

Prototype

void error(Throwable error);

Source Link

Document

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

Usage

From source file:org.reficio.p2.utils.JarUtils.java

License:Open Source License

public static void adjustFeaturePluginData(Document featureSpec, File pluginDir, Log log) throws IOException {
    //get list of all plugins
    NodeList plugins = featureSpec.getElementsByTagName("plugin");
    for (int i = 0; i < plugins.getLength(); ++i) {
        Node n = plugins.item(i);
        if (n instanceof Element) {
            Element el = (Element) n;
            String pluginId = el.getAttribute("id");
            File[] files = findFiles(pluginDir, pluginId);
            if (files.length < 0) {
                log.error("Cannot find plugin " + pluginId);
            } else {
                //in case more than one plugin with same id
                Arrays.sort(files, fileComparator);
                //File firstFile = files[0];
                File lastFile = files[files.length - 1];
                //String firstVersion = BundleUtils.INSTANCE.getBundleVersion(new Jar(firstFile));
                String lastVersion = BundleUtils.INSTANCE.getBundleVersion(new Jar(lastFile)); //may throw IOException
                log.info("Adjusting version for plugin " + pluginId + " to " + lastVersion);
                el.setAttribute("version", lastVersion);
            }/*from w ww  .  j  av  a 2  s.  c  o  m*/
        }
    }
}

From source file:org.sonar.maven.ExceptionHandling.java

License:Open Source License

static RuntimeException handle(Exception e, Log log) throws MojoExecutionException {
    Throwable source = e;//  w  ww  . j a v a 2s. co m
    if ("org.sonar.runner.impl.RunnerException".equals(e.getClass().getName()) && e.getCause() != null) {
        source = e.getCause();
    }
    log.error(source.getMessage());
    throw new MojoExecutionException(source.getMessage(), source);
}

From source file:org.spdx.maven.MavenToSpdxLicenseMapper.java

License:Apache License

/**
 * Initialize the urlSTringToSpdxLicense map with the SPDX listed licenses
 * @param jsonReader Reader for the JSON input file containing the listed licenses
 * @param log Optional logger//ww  w  . j a v  a  2  s .c  o m
 * @throws LicenseMapperException 
 */
private void initializeUrlMap(Reader jsonReader, Log log) throws LicenseMapperException {
    JSONParser parser = new JSONParser();
    Object parsedObject = null;
    try {
        parsedObject = parser.parse(jsonReader);
    } catch (IOException e1) {
        if (log != null) {
            log.error("I/O error parsing listed licenses JSON file: " + e1.getMessage());
        }
        throw (new LicenseMapperException("I/O Error parsing listed licenses"));
    } catch (ParseException e1) {
        if (log != null) {
            log.error("JSON parsing error parsing listed licenses JSON file: " + e1.getMessage());
        }
        throw (new LicenseMapperException("JSON parsing error parsing listed licenses"));
    }
    JSONObject listedLicenseSource = (JSONObject) parsedObject;

    JSONArray listedLicenses = (JSONArray) listedLicenseSource.get("licenses");
    urlStringToSpdxLicenseId = new HashMap<String, String>();
    List<String> urlsWithMultipleIds = new ArrayList<String>();
    for (int i = 0; i < listedLicenses.size(); i++) {
        JSONObject listedLicense = (JSONObject) listedLicenses.get(i);
        String licenseId = (String) listedLicense.get(SpdxRdfConstants.PROP_LICENSE_ID);
        this.urlStringToSpdxLicenseId.put(SPDX_LICENSE_URL_PREFIX + licenseId, licenseId);
        JSONArray urls = (JSONArray) listedLicense.get(SpdxRdfConstants.RDFS_PROP_SEE_ALSO);
        if (urls != null) {
            for (int j = 0; j < urls.size(); j++) {
                String url = (String) urls.get(j);
                if (this.urlStringToSpdxLicenseId.containsKey(url)) {
                    urlsWithMultipleIds.add(url);
                } else {
                    this.urlStringToSpdxLicenseId.put(url, licenseId);
                }
            }
        }
    }
    // Remove any mappings which have ambiguous URL mappings
    for (String redundantUrl : urlsWithMultipleIds) {
        this.urlStringToSpdxLicenseId.remove(redundantUrl);
    }
    addManualMappings();
}

From source file:org.teatrove.maven.plugins.teacompiler.TeaCompilerMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {

    final Log logger = getLog();

    // Create the Helper for the Context Class Builder
    ContextClassBuilderHelper helper = new DefaultContextClassBuilderHelper(session,
            new TeaCompilerExpressionEvaluator(session, translator, project), logger, container,
            this.getClass().getClassLoader(), rootPackage);

    // Merge the contexts
    final Class<?> contextClass;
    try {/*from w ww. j a va 2s  .c  om*/
        if (this.context == null) {
            if (contextClassBuilder == null) {
                throw new MojoExecutionException(
                        "Either context or contextClassBuilder parameter is required.");
            }
            contextClass = contextClassBuilder.getContextClass(helper);
        } else {
            contextClass = Class.forName(this.context);
        }
    } catch (ContextClassBuilderException e) {
        throw new MojoExecutionException("Unable to find or create the Context.", e);
    } catch (ClassNotFoundException e) {
        throw new MojoExecutionException("Unable to load the Context.", e);
    }

    final File realOutputDirectory = new File(outputDirectory, rootPackage.replace('.', File.separatorChar));

    realOutputDirectory.mkdirs();

    if (sourceDirectories == null || sourceDirectories.length == 0) {
        sourceDirectories = new File[] { defaultSourceDirectory };
    } else {
        // Filter out any that don't exist
        List<File> existing = new ArrayList<File>(sourceDirectories.length);
        for (File sourceDirectory : sourceDirectories) {
            if (sourceDirectory.exists()) {
                existing.add(sourceDirectory);
            } else if (logger.isDebugEnabled()) {
                logger.debug("Removing source directory because it does not exist. [" + sourceDirectory + "].");
            }
        }
        sourceDirectories = existing.toArray(new File[existing.size()]);
    }

    final Compiler compiler = new Compiler(rootPackage, realOutputDirectory, encoding, 0);

    for (File sourceDirectory : sourceDirectories) {
        compiler.addCompilationProvider(new FileCompilationProvider(sourceDirectory));
    }

    compiler.setClassLoader(contextClass.getClassLoader());
    compiler.setRuntimeContext(contextClass);
    compiler.setForceCompile(force);
    compiler.addCompileListener(new CompileListener() {
        public void compileError(CompileEvent e) {
            logger.error(e.getDetailedMessage());
        }

        public void compileWarning(CompileEvent e) {
            logger.warn(e.getDetailedMessage());
        }
    });
    compiler.setExceptionGuardianEnabled(guardian);

    final String[] names;
    try {
        if (includes == null || includes.length == 0) {
            names = compiler.compileAll(true);
        } else {
            names = compiler.compile(includes);
        }
    } catch (IOException e) {
        throw new MojoExecutionException("I/O error while compiling templates.", e);
    }

    final int errorCount = compiler.getErrorCount();
    if (errorCount > 0) {
        String msg = errorCount + " error" + (errorCount != 1 ? "s" : "");
        if (failOnError) {
            throw new MojoFailureException(msg);
        } else if (logger.isWarnEnabled()) {
            logger.warn(msg);
        }
    }

    final int warningCount = compiler.getWarningCount();
    if (warningCount > 0) {
        String msg = warningCount + " warning" + (warningCount != 1 ? "s" : "");
        if (failOnWarning) {
            throw new MojoFailureException(msg);
        } else if (logger.isWarnEnabled()) {
            logger.warn(msg);
        }
    }

    if (logger.isInfoEnabled()) {
        logger.info("Compiled the following templates:");
        Arrays.sort(names);
        for (String name : names) {
            logger.info(name);
        }
    }
}

From source file:org.universAAL.support.directives.checks.DependencyManagementCheckFix.java

License:Apache License

/** {@inheritDoc} */
public void fix(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {
    try {// w  w  w  .  j a va2s.c  o m
        new PomWriter(this, mavenProject).fix();
    } catch (Exception e) {
        log.error("unable to Write POM.");
        log.error(e);
    }
}

From source file:org.universAAL.support.directives.checks.FelixDepCheckFix.java

License:Apache License

/** {@ inheritDoc}    */
public void fix(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {

    try {//from ww  w .  j a  v a  2 s.c o  m
        new PomWriter(this, mavenProject).fix();
    } catch (Exception e) {
        log.error("unable to Write POM.");
        log.error(e);
    }

}

From source file:org.universAAL.support.directives.checks.ModulesCheckFix.java

License:Apache License

/** 
 * {@inheritDoc}//w w w.j  ava 2s .  c  om
 */
public void fix(MavenProject mavenProject2, Log log) throws MojoFailureException {
    try {
        new PomWriter(this, mavenProject2).fix();
    } catch (Exception e) {
        log.error("unable to Write POM.");
    }
}

From source file:org.universAAL.support.directives.checks.ModulesCheckFix.java

License:Apache License

/**
 * Check whether the pom modules are in the following disposition:
 * <br>//ww  w  .  j  av  a 2 s  .c o m
 * <pre>
 *    parentFolder
 *    L pom.xml
 *    L Module1
 *      L pom.xml
 *    :
 *    L ModuleN
 *      L pom.xml
 * </pre>
 * ie: all of the modules of the pom are children.
 * @param mavenProject2
 * @param log
 * @return
 */
private boolean isOfCommonType(MavenProject mp, Log log) {
    List<String> listed = (List<String>) mp.getModules();
    boolean common = true;
    for (String m : listed) {
        File mDir = new File(mp.getBasedir(), m);
        log.debug("checking \n -" + mp.getBasedir().getAbsolutePath() + "\n -" + mDir.getAbsolutePath());
        try {
            /*
             * for all of the modules:
             *    the parent folder of the module is the same as the parent POMs folder
             */
            common &= mp.getBasedir().equals(mDir.getCanonicalFile().getParentFile());
        } catch (IOException e) {
            log.error(e);
        }
        log.debug(Boolean.toString(common));

    }
    return listed.size() > 0 && common;
}

From source file:org.universAAL.support.directives.checks.ModulesCheckFix.java

License:Apache License

private boolean passRootCheckCommonType(MavenProject mavenProject2, Log log) {
    List<String> mods = (List<String>) mavenProject2.getModules();
    List<File> listed = new ArrayList<File>();
    for (String m : mods) {
        try {/*from   w w  w . j a v  a  2  s  . c  o  m*/
            listed.add(new File(mavenProject2.getBasedir(), m).getCanonicalFile());
        } catch (IOException e) {
            log.error(e);
        }
    }
    //gather the existent modules
    File dir = mavenProject2.getBasedir();
    for (File f : dir.listFiles()) {
        String rel = f.getName();
        if (f.isDirectory() && directoryContains(f, "pom.xml") && !listed.contains(f) // it is not already listed
                && !rel.contains(SVN_FOLDER)
        // it is not the svn folder
        ) {
            toBeFixed.add(rel);
            log.debug("Found not listed module : " + rel);
        }
    }
    return toBeFixed.isEmpty();
}

From source file:org.universAAL.support.directives.checks.SVNCheck.java

License:Apache License

private void fixSCMWith(String surl, Log log) {
    try {// w ww. j a  v  a2s. co  m
        new PomWriter(new SCMFixer(surl), mavenProject).fix();
    } catch (Exception e) {
        log.error("unable to write POM");
    }
}