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

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

Introduction

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

Prototype

void debug(Throwable error);

Source Link

Document

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

Usage

From source file:com.igormaznitsa.upom.UPomModel.java

License:Apache License

public void injectIntoProject(final Log log, final MavenProject project) throws Exception {
    for (final Method setter : project.getClass().getMethods()) {
        final String methodName = setter.getName();
        final Class<?>[] setterParams = setter.getParameterTypes();
        if (setterParams.length == 1 && methodName.startsWith("set")) {
            final String paramName = methodName.substring(3).toLowerCase(Locale.ENGLISH);
            if (paramName.equals("build")) {
                continue;
            }/*  w w w. j a v  a  2  s . c  o m*/

            Method getter = null;
            for (final Method g : this.model.getClass().getMethods()) {
                final Class<?>[] getterParams = g.getParameterTypes();
                if (getterParams.length == 0 && g.getName().equalsIgnoreCase("get" + paramName)) {
                    getter = g;
                    break;
                }
            }
            if (getter != null && setterParams[0].isAssignableFrom(getter.getReturnType())) {
                final Object value = getter.invoke(this.model);
                if (value == null) {
                    log.debug(getter.getName() + "() X-> " + setter.getName() + "()");
                } else {
                    log.debug(getter.getName() + "() --> " + setter.getName() + "()");
                    setter.invoke(project, getter.invoke(this.model));
                }
            }
        }
    }
}

From source file:com.jayway.maven.plugins.android.phase09package.ApkBuilder.java

License:Apache License

/**
 * Before being able to use the ApkBuilder, an initialization is required.
 *
 * @param log//from ww  w.  jav  a  2 s  . co m
 *            the Mojo Logger
 * @param sdkLibs
 *            the File pointing on {@code sdklib.jar}
 * @throws MojoExecutionException
 *             if the ApkBuilder class cannot be loaded
 */
@SuppressWarnings("unchecked")
public static void initialize(Log log, File sdkLibs) throws MojoExecutionException {
    if (apkBuilderClass != null) {
        // Already initialized
        return;
    }

    ApkBuilder.log = log;

    // Loads the ApkBuilder class
    try {
        URLClassLoader child = new URLClassLoader(new URL[] { sdkLibs.toURI().toURL() },
                ApkBuilder.class.getClassLoader());
        apkBuilderClass = child.loadClass("com.android.sdklib.build.ApkBuilder");
    } catch (MalformedURLException e) {
        // This one cannot happen.
        throw new RuntimeException("Cannot create a correct URL from file " + sdkLibs.getAbsolutePath());
    } catch (ClassNotFoundException e) {
        log.error(e);
        throw new MojoExecutionException("Cannot load 'com.android.sdklib.build.ApkBuilder'");
    }
    log.debug("ApkBuilder loaded " + apkBuilderClass);

    // In order to improve performence and to check that all methods are available
    // we cache used methods.

    try {
        apkBuilderConstructor = apkBuilderClass.getConstructor(
                new Class[] { File.class, File.class, File.class, String.class, PrintStream.class });

        setDebugMethod = apkBuilderClass.getMethod("setDebugMode", new Class[] { Boolean.TYPE });

        addResourcesFromJarMethod = apkBuilderClass.getMethod("addResourcesFromJar",
                new Class[] { File.class });

        addNativeLibrariesMethod = apkBuilderClass.getMethod("addNativeLibraries",
                new Class[] { File.class, String.class });

        addSourceFolderMethod = apkBuilderClass.getMethod("addSourceFolder", new Class[] { File.class });

        sealApkMethod = apkBuilderClass.getMethod("sealApk", new Class[0]);

        getDebugKeyStoreMethod = apkBuilderClass.getMethod("getDebugKeystore", new Class[0]);
    } catch (Exception e) {
        log.error("Cannot find required method", e);
        throw new MojoExecutionException("Cannot find the required method", 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);
        }//  www  .  j a  v a2  s  .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;//from w w w  . j a v a  2 s . c  om
    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.monday_consulting.maven.plugins.fsm.util.PrototypeXml.java

License:Apache License

public PrototypeXml(final Log log, final File prototypeXml) throws XmlPullParserException, IOException {
    this.dependencyJointList = new ArrayList<PrototypeXml.DependencyJoint>();
    this.log = log;
    this.prototypeDom = Xpp3DomBuilder.build(new XmlStreamReader(prototypeXml));
    if (log.isDebugEnabled())
        this.log.debug("Getting dependency-joints\nDependency-Joints to fill:");

    for (final Xpp3Dom xpp3Dom : new Xpp3DomIterator(prototypeDom)) {
        if (xpp3Dom.getName().equals("dependencies")) {
            if (xpp3Dom.getValue().equals("")) {
                log.error(/*from  ww  w  .  j  a va  2  s.  c o  m*/
                        "Prototype-Xml-Error:\nTried to retrieve dependency-joint, but because its value was empty, no connection to a module can be made");
            }
            dependencyJointList.add(new DependencyJoint(xpp3Dom.getValue(), xpp3Dom));
            if (log.isDebugEnabled())
                log.debug("\t" + xpp3Dom.getValue());
        }
    }
}

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 ww  .  j a va 2s  .c o  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);
    }
}

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

License:Open Source License

/**
 * Creates an {@link Instrumenter} instance.
 * @param log maven logger/*ww  w  . j  av  a 2s.  c  om*/
 * @param classpath classpath for classes being instrumented
 * @return a new {@link Instrumenter}
 * @throws MojoExecutionException if any exception occurs
 */
protected final Instrumenter getInstrumenter(Log log, List<String> classpath) throws MojoExecutionException {
    List<File> classpathFiles;
    try {
        log.debug("Getting compile classpath");
        classpathFiles = classpath.stream().map(x -> new File(x)).collect(Collectors.toList());
        log.debug("Getting bootstrap classpath");
        classpathFiles.addAll(FileUtils.listFiles(new File(jdkLibsDirectory), new String[] { "jar" }, true));

        log.info("Classpath for instrumentation is as follows: " + classpathFiles);
    } catch (Exception ex) {
        throw new MojoExecutionException("Unable to get compile classpath elements", ex);
    }

    log.info("Creating instrumenter...");

    try {
        return new Instrumenter(classpathFiles);
    } catch (Exception ex) {
        throw new MojoExecutionException("Unable to create instrumenter", ex);
    }
}

From source file:com.opoopress.maven.plugins.plugin.AbstractDeployMojo.java

License:Apache License

private static void configureScpWagonIfRequired(Wagon wagon, Log log) {
    log.debug("configureScpWagonIfRequired: " + wagon.getClass().getName());

    if (System.console() == null) {
        log.debug("No System.console(), skip configure Wagon");
        return;//w  w  w  . j a  v  a  2s . co  m
    }

    ClassLoader parent = Thread.currentThread().getContextClassLoader();
    if (parent == null) {
        parent = AbstractDeployMojo.class.getClassLoader();
    }
    List<ClassLoader> loaders = new ArrayList<ClassLoader>();
    loaders.add(wagon.getClass().getClassLoader());
    ChainingClassLoader loader = new ChainingClassLoader(parent, loaders);

    Class<?> scpWagonClass;
    try {
        scpWagonClass = ClassUtils.getClass(loader, "org.apache.maven.wagon.providers.ssh.jsch.ScpWagon");
    } catch (ClassNotFoundException e) {
        log.debug(
                "Class 'org.apache.maven.wagon.providers.ssh.jsch.ScpWagon' not found, skip configure Wagon.");
        return;
    }

    //is ScpWagon
    if (scpWagonClass.isInstance(wagon)) {
        try {
            Class<?> userInfoClass = ClassUtils.getClass(loader,
                    "com.opoopress.maven.plugins.plugin.ssh.SystemConsoleInteractiveUserInfo");
            Object userInfo = userInfoClass.newInstance();
            MethodUtils.invokeMethod(wagon, "setInteractiveUserInfo", userInfo);
            log.debug("ScpWagon using SystemConsoleInteractiveUserInfo(Java 6+).");
        } catch (ClassNotFoundException e) {
            log.debug(
                    "Class 'com.opoopress.maven.plugins.plugin.ssh.SystemConsoleInteractiveUserInfo' not found, skip configure Wagon.");
        } catch (InstantiationException e) {
            log.debug("Instantiate class exception", e);
        } catch (IllegalAccessException e) {
            log.debug(e.getMessage(), e);
        } catch (NoSuchMethodException e) {
            log.debug(e.getMessage(), e);
        } catch (InvocationTargetException e) {
            log.debug(e.getMessage(), e);
        }
    } else {
        log.debug("Not a ScpWagon.");
    }
}

From source file:com.opoopress.maven.plugins.plugin.AbstractDeployMojo.java

License:Apache License

private static void push(final File inputDirectory, final Repository repository, final WagonManager manager,
        final Wagon wagon, final ProxyInfo proxyInfo, final String relativeDir, final Log log)
        throws MojoExecutionException {
    AuthenticationInfo authenticationInfo = manager.getAuthenticationInfo(repository.getId());
    log.debug("authenticationInfo with id '" + repository.getId() + "': "
            + ((authenticationInfo == null) ? "-" : authenticationInfo.getUserName()));

    try {/*from  w w  w .  j  a  v a2s . co  m*/
        Debug debug = new Debug();

        wagon.addSessionListener(debug);

        wagon.addTransferListener(debug);

        if (proxyInfo != null) {
            log.debug("connect with proxyInfo");
            wagon.connect(repository, authenticationInfo, proxyInfo);
        } else if (proxyInfo == null && authenticationInfo != null) {
            log.debug("connect with authenticationInfo and without proxyInfo");
            wagon.connect(repository, authenticationInfo);
        } else {
            log.debug("connect without authenticationInfo and without proxyInfo");
            wagon.connect(repository);
        }

        log.info("Pushing " + inputDirectory);

        // TODO: this also uploads the non-default locales,
        // is there a way to exclude directories in wagon?
        log.info("   >>> to " + repository.getUrl() + relativeDir);

        wagon.putDirectory(inputDirectory, relativeDir);
    } catch (ResourceDoesNotExistException e) {
        throw new MojoExecutionException("Error uploading site", e);
    } catch (TransferFailedException e) {
        throw new MojoExecutionException("Error uploading site", e);
    } catch (AuthorizationException e) {
        throw new MojoExecutionException("Error uploading site", e);
    } catch (ConnectionException e) {
        throw new MojoExecutionException("Error uploading site", e);
    } catch (AuthenticationException e) {
        throw new MojoExecutionException("Error uploading site", e);
    }
}

From source file:com.opoopress.maven.plugins.plugin.AbstractDeployMojo.java

License:Apache License

/**
 * Configure the Wagon with the information from serverConfigurationMap ( which comes from settings.xml )
 *
 * @param wagon//from  w  w w . j a  v a2s.co  m
 * @param repositoryId
 * @param settings
 * @param container
 * @param log
 * @throws WagonConfigurationException
 * @todo Remove when {@link WagonManager#getWagon(Repository) is available}. It's available in Maven 2.0.5.
 */
private static void configureWagon(Wagon wagon, String repositoryId, Settings settings,
        PlexusContainer container, Log log) throws WagonConfigurationException {
    log.debug(" configureWagon ");

    //config log
    configureLog(wagon, log);

    configureScpWagonIfRequired(wagon, log);

    // MSITE-25: Make sure that the server settings are inserted
    for (Server server : settings.getServers()) {
        String id = server.getId();

        log.debug("configureWagon server " + id);

        if (id != null && id.equals(repositoryId) && (server.getConfiguration() != null)) {
            final PlexusConfiguration plexusConf = new XmlPlexusConfiguration(
                    (Xpp3Dom) server.getConfiguration());

            ComponentConfigurator componentConfigurator = null;
            try {
                componentConfigurator = (ComponentConfigurator) container.lookup(ComponentConfigurator.ROLE);
                componentConfigurator.configureComponent(wagon, plexusConf, container.getContainerRealm());
            } catch (final ComponentLookupException e) {
                throw new WagonConfigurationException(repositoryId,
                        "Unable to lookup wagon configurator." + " Wagon configuration cannot be applied.", e);
            } catch (ComponentConfigurationException e) {
                throw new WagonConfigurationException(repositoryId, "Unable to apply wagon configuration.", e);
            } finally {
                if (componentConfigurator != null) {
                    try {
                        container.release(componentConfigurator);
                    } catch (ComponentLifecycleException e) {
                        log.error("Problem releasing configurator - ignoring: " + e.getMessage());
                    }
                }
            }
        }
    }
}