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.expedia.tesla.tools.mojo.CompileMojo.java

License:Apache License

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

    log.info("Generating source code from Tesla schemas.");
    log.debug(String.format("language: %s", language));
    log.debug(String.format("outputDir: %s", outputDir));
    log.debug(String.format("classTemplate: %s", classTemplate));
    log.debug(String.format("enumTemplate: %s", enumTemplate));
    log.debug(String.format("serializerTemplate: %s", serializerTemplate));
    log.debug(String.format("generateTypes: %s", generateTypes ? "yes" : "no"));
    PrintStream os = new PrintStream(new ByteArrayOutputStream());
    MapUtils.debugPrint(os, null, extension);
    log.debug(String.format("extension: %s", os.toString()));
    try {/*from  w w  w.j a  va2s  .c om*/
        Compiler compiler = new Compiler();
        compiler.setLanguage(language);
        compiler.setOutputDir(outputDir);
        compiler.setAppSchemaClassName(serializerClassName);
        if (serializerTemplate != null) {
            compiler.setAppSchemaTemplatePath(serializerTemplate.getAbsolutePath());
        }
        compiler.setNotGenerateUserTypes(!generateTypes);
        if (classTemplate != null) {
            compiler.setClassTemplatePath(classTemplate.getAbsolutePath());
        }
        if (enumTemplate != null) {
            compiler.setEnumTemplatePath(enumTemplate.getAbsolutePath());
        }
        compiler.setExtension(extension);
        compiler.setSchemaFiles(getTmlFiles());
        compiler.compile();
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to generate Tesla schema from Java.", e);
    }
    log.info("Generated source code from Tesla schemas successfully.");
}

From source file:com.expedia.tesla.tools.mojo.GenerateSchemaMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    Log log = getLog();
    try {//from   w  w w. java 2s  .co m
        classpath += StringUtils.join(project.getCompileClasspathElements(),
                System.getProperty("path.separator"));
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("Failed to resolve project dependencies: " + e.getMessage(), e);
    }

    if (outputTml == null) {
        log.warn("Output is not set, using default value 'output.tml'.");
        outputTml = new File("output.tml");
    }

    log.info("Generating Tesla schema.");
    log.debug(String.format("classpath: %s", classpath));
    log.debug(String.format("Classes: %s", Arrays.toString(this.classes.toArray())));
    log.debug(String.format("Schema version name: %s", schemaVersion.getName()));
    log.debug(String.format("Schema version number: %s", schemaVersion.getVersionNumber()));
    log.debug(String.format("Output: %s", outputTml));
    OutputStream os = null;
    try {
        Util.forceMkdirParent(outputTml);
        os = new FileOutputStream(outputTml);
        SchemaGenerator.genTml(classes,
                new SchemaVersion(0L, schemaVersion.getVersionNumber(), schemaVersion.getName(), null), os,
                classpath);
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to generate Tesla schema from Java.", e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
    log.info("Generated Tesla schema successfully.");
}

From source file:com.flipkart.masquerade.Masque.java

License:Apache License

public ClassLoader getClassLoader(MavenProject project, final ClassLoader parent, Log log)
        throws DependencyResolutionRequiredException {

    @SuppressWarnings("unchecked")
    List<String> classpathElements = project.getCompileClasspathElements();

    final List<URL> classpathUrls = new ArrayList<URL>(classpathElements.size());

    for (String classpathElement : classpathElements) {
        try {/* ww w .  j  av a  2  s .  c om*/
            log.debug("Adding project artifact to classpath: " + classpathElement);
            classpathUrls.add(new File(classpathElement).toURI().toURL());
        } catch (MalformedURLException e) {
            log.debug("Unable to use classpath entry as it could not be understood as a valid URL: "
                    + classpathElement, e);
        }
    }

    return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        @Override
        public ClassLoader run() {
            return new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()]), parent);
        }
    });

}

From source file:com.github.bmaggi.conditional.validation.ValidationMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    log.debug("There are " + conditions.size() + "conditions");
    for (Condition condition : conditions) {
        log.debug("Evaluate (Condition type): " + condition.toString() + " (" + condition.getClass() + ")");
        if (!(condition).evaluate()) {
            String message = condition.getMessage();
            if (LEVEL.ERROR == condition.getLevel()) {
                log.error(" Condition failed" + message);
                throw new MojoExecutionException("A condition with a level ERROR failed");
            } else {
                log.warn("Condition failed" + message);
            }//from w  ww.ja  va  2 s . c  om
        }
    }
}

From source file:com.github.formatter.JSBeautifier.java

License:Apache License

/**
 * Format individual file.//from   w  ww. java 2 s. c  om
 *
 * @param file
 * @param rc
 * @param hashCache
 * @param basedirPath
 * @throws IOException
 * @throws BadLocationException
 */
private void doFormatFile(File file, ResultCollector rc, Properties hashCache, String basedirPath)
        throws IOException, BadLocationException {
    Log log = getLog();
    log.debug("Processing file: " + file);

    Scriptable options = null;
    Map<String, Object> prefs = new HashMap<String, Object>();

    String code = readFileAsString(file);
    String originalHash = md5hash(code);

    String canonicalPath = file.getCanonicalPath();
    String path = canonicalPath.substring(basedirPath.length());
    String cachedHash = hashCache.getProperty(path);
    if (cachedHash != null && cachedHash.equals(originalHash)) {
        rc.skippedCount++;
        log.debug("File is already formatted.");
        return;
    }

    prefs = getPreferences();

    options = context.newObject(scope);

    scope.put("contents", scope, code);

    for (String key : prefs.keySet()) {
        options.put(key, options, prefs.get(key));
    }

    scope.put("opts", scope, options);

    context.evaluateString(scope, "result = global.js_beautify(contents, opts);", "JSBeautify", 1, null);

    Object result = scope.get("result", scope);
    if (result == null) {
        rc.failCount++;
        return;
    }
    String formattedCode = result.toString();
    String formattedHash = md5hash(formattedCode);
    hashCache.setProperty(path, formattedHash);

    if (originalHash.equals(formattedHash)) {
        rc.skippedCount++;
        log.debug("Equal hash code. Not writing result to file.");
        return;
    }

    writeStringToFile(formattedCode, file);
    rc.successCount++;
    getLog().info(" Formatted file --  " + file.getAbsolutePath());

}

From source file:com.github.genthaler.credentials.SetAllMojo.java

License:Apache License

/**
 * Execute the mojo.//www .j  av  a2  s.  c o  m
 * 
 * @throws MojoExecutionException
 */
@Override
public void execute() throws MojoExecutionException {
    Log log = getLog();
    boolean debugEnabled = log.isDebugEnabled();

    for (Server server : this.settings.getServers()) {
        String settingsKey = server.getId();
        String username = server.getUsername();
        String password = server.getPassword();

        String usernameProperty = settingsKey + "." + DEFAULT_USERNAME_PROPERTY_SUFFIX;

        String passwordProperty = settingsKey + "." + DEFAULT_PASSWORD_PROPERTY_SUFFIX;

        if (!project.getProperties().containsKey(usernameProperty))
            project.getProperties().setProperty(usernameProperty, username);
        if (!project.getProperties().containsKey(passwordProperty))
            project.getProperties().setProperty(passwordProperty, password);

        if (useSystemProperties) {
            if (System.getProperty(usernameProperty) == null)
                System.setProperty(usernameProperty, username);
            if (System.getProperty(passwordProperty) == null)
                System.setProperty(passwordProperty, password);
        }

        if (debugEnabled)
            log.debug(String.format("username property '%s' is '%s'", usernameProperty, username));

        if (debugEnabled)
            log.debug(String.format("password property '%s' is '%s'", passwordProperty, password));
    }
}

From source file:com.github.genthaler.credentials.SetMojo.java

License:Apache License

/**
 * Execute the mojo.//  ww w  .  j a v  a2s.co m
 * 
 * @throws MojoExecutionException
 */
@Override
public void execute() throws MojoExecutionException {
    Log log = getLog();
    boolean debugEnabled = log.isDebugEnabled();

    if (null == usernameProperty) {
        if (null == settingsKey)
            throw new MojoExecutionException("At least one of settingsKey and usernameProperty must be set");
        usernameProperty = settingsKey + "." + DEFAULT_USERNAME_PROPERTY_SUFFIX;
    }

    if (debugEnabled)
        log.debug(String.format("usernameProperty is %s", usernameProperty));

    if (null == passwordProperty) {
        if (null == settingsKey)
            throw new MojoExecutionException("At least one of settingsKey and passwordProperty must be set");
        passwordProperty = settingsKey + "." + DEFAULT_PASSWORD_PROPERTY_SUFFIX;
    }

    if (debugEnabled)
        log.debug(String.format("passwordProperty is %s", passwordProperty));

    String username = coalesce(System.getProperty(usernameProperty),
            project.getProperties().getProperty(usernameProperty));

    if (debugEnabled)
        log.debug(String.format("username so far is %s", username));

    String password = coalesce(System.getProperty(passwordProperty),
            project.getProperties().getProperty(passwordProperty));

    if (debugEnabled)
        log.debug(String.format("password so far is %s", password));

    // Only lookup credentials if they're not already set.
    if (null == username || null == password) {
        if (null == settingsKey) {
            throw new MojoExecutionException(String.format(
                    "If %s/%s properties not set manually, then the settings key must be specified, either at the command line or in the pom.xml",
                    usernameProperty, passwordProperty));
        }

        Server server = this.settings.getServer(this.settingsKey);

        if (null == server) {
            throw new MojoExecutionException(String.format(
                    "You have specified a settingsKey property value of %s, there must be a server entry with id %s in your settings.xml",
                    settingsKey, settingsKey));
        } else {
            if (null == username)
                username = server.getUsername();

            if (null == password) {
                password = server.getPassword();

                try {
                    password = securityDispatcher.decrypt(password);
                } catch (SecDispatcherException e) {
                    // Don't care if we can't decrypt, either it wasn't
                    // encrypted in the first place, and/or it'll just fail
                    // on the target system.
                    getLog().warn(e);
                }
            }
        }
    }

    if (null == username)
        username = "";
    if (null == password)
        password = "";

    project.getProperties().setProperty(usernameProperty, username);
    project.getProperties().setProperty(passwordProperty, password);

    if (useSystemProperties) {
        System.setProperty(usernameProperty, username);
        System.setProperty(passwordProperty, password);
    }

    if (debugEnabled)
        log.debug(String.format("username property '%s' is '%s'", usernameProperty, username));

    if (debugEnabled)
        log.debug(String.format("password property '%s' is '%s'", passwordProperty, password));
}

From source file:com.github.jrh3k5.mojo.flume.AbstractFlumeAgentsMojo.java

License:Apache License

/**
 * Remove any libraries from the {@code lib/} directory in the given Flume installation directory.
 * /*  ww w  .ja  v  a 2s .  c  o m*/
 * @param agent
 *            The {@link Agent} whose installation's {@code lib/} directory is to be modified.
 * @param flumeDirectory
 *            A {@link File} representing the directory in which a Flume agent - for which the configured libraries are to be removed - is installed.
 * @throws IOException
 *             If any errors occur during the removal.
 */
void removeLibs(Agent agent, File flumeDirectory) throws IOException {
    final File libDir = new File(flumeDirectory, "lib");
    final Log log = getLog();
    final boolean isDebugEnabled = log.isDebugEnabled();
    for (String removal : agent.getLibs().getRemovals()) {
        final File lib = new File(libDir, removal);
        if (lib.exists()) {
            if (isDebugEnabled) {
                log.debug(String.format("The file %s exists and will be removed.", lib.getAbsolutePath()));
            }
            FileUtils.forceDelete(lib);
        } else {
            log.warn(String.format("The file %s was specified for deletion, but could not be found in %s",
                    removal, libDir.getAbsolutePath()));
        }
    }
}

From source file:com.github.lucapino.jira.CreateNewVersionMojo.java

License:Apache License

@Override
public void doExecute() throws Exception {
    Log log = getLog();

    Project jiraProject = jiraClient.getRestClient().getProjectClient().getProject(jiraProjectKey).claim();
    Iterable<Version> versions = jiraProject.getVersions();
    String newDevVersion;/*  w  w  w  .j  av a 2  s.  c o  m*/

    if (finalNameUsedForVersion) {
        newDevVersion = finalName;
    } else {
        newDevVersion = developmentVersion;
    }

    // Removing -SNAPSHOT suffix for safety and sensible formatting
    newDevVersion = WordUtils.capitalize(newDevVersion.replace("-SNAPSHOT", "").replace("-", " "));

    boolean versionExists = isVersionAlreadyPresent(versions, newDevVersion);

    if (!versionExists) {

        VersionInput newVersion = new VersionInput(jiraProjectKey, newDevVersion, null, null, false, false);
        log.debug("New Development version in JIRA is: " + newDevVersion);
        jiraClient.getRestClient().getVersionRestClient().createVersion(newVersion).claim();

        log.info("Version created in JIRA for project key " + jiraProjectKey + " : " + newDevVersion);
    } else {
        log.warn(String.format("Version %s is already created in JIRA. Nothing to do.", newDevVersion));
    }

}

From source file:com.github.maven.plugins.core.GitHubProjectMojo.java

License:Open Source License

/**
 * Log given message at debug level//from  www .  j a v a  2  s .  c o  m
 * 
 * @param message
 */
protected void debug(String message) {
    final Log log = getLog();
    if (log != null)
        log.debug(message);
}