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

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

Introduction

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

Prototype

boolean isDebugEnabled();

Source Link

Usage

From source file:com.github.jrh3k5.flume.mojo.plugin.plexus.MojoLogger.java

License:Apache License

/**
 * Determine a {@link Logger} level based on the configuration of the given
 * {@link Log}.// w  ww.  j a  v  a2  s .c  o  m
 * 
 * @param log
 *            The {@link Log} to determine the logger level.
 * @return A {@link Logger} level corresponding to the log level in the
 *         given {@link Log}.
 */
private static int determineThreshold(Log log) {
    if (log.isDebugEnabled()) {
        return Logger.LEVEL_DEBUG;
    } else if (log.isInfoEnabled()) {
        return Logger.LEVEL_INFO;
    } else if (log.isWarnEnabled()) {
        return Logger.LEVEL_WARN;
    } else if (log.isErrorEnabled()) {
        return Logger.LEVEL_ERROR;
    } else {
        return Logger.LEVEL_DISABLED;
    }
}

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.
 * //from w w w. j  a  v a2  s.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.maven.plugins.core.GitHubProjectMojo.java

License:Open Source License

/**
 * Is debug logging enabled?/* w w w  .  j av  a  2s .  co m*/
 * 
 * @return true if enabled, false otherwise
 */
protected boolean isDebug() {
    final Log log = getLog();
    return log != null ? log.isDebugEnabled() : false;
}

From source file:com.github.shyiko.jwarpack.maven.PackMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    Log logger = getLog();
    File esJar = getESJar();/*  w w w .ja  v  a2 s .  c om*/
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("ES JAR location: %s", esJar));
    }
    File appWar = getAppWar();
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Application WAR location: %s", appWar));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Output JAR location: %s", outputJar));
    }
    Metadata metadata = new Metadata(esJar.getAbsolutePath(), appWar.getAbsolutePath(), outputJar,
            useCompression);
    try {
        new Packager().pack(metadata);
    } catch (IOException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e);
        }
        throw new MojoFailureException("Packaging failed. Error message: " + e.getMessage());
    }
}

From source file:com.github.veithen.alta.AbstractGenerateFilesMojo.java

License:Apache License

@Override
protected final void process(Map<String, String> result) throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    File outputDirectory = getOutputDirectory();
    for (Map.Entry<String, String> entry : result.entrySet()) {
        String resource = entry.getKey();
        File outputFile = new File(outputDirectory, resource);
        File parentDir = outputFile.getParentFile();
        if (!parentDir.exists()) {
            if (log.isDebugEnabled()) {
                log.debug("Creating directory " + parentDir);
            }/*w  w w .  j  a va2 s. co  m*/
            if (!parentDir.mkdirs()) {
                throw new MojoExecutionException("Unable to create directory " + parentDir);
            }
        }
        try {
            FileOutputStream fos = new FileOutputStream(outputFile);
            try {
                // TODO: charset encoding
                Writer out = new OutputStreamWriter(fos);
                out.write(entry.getValue());
                out.flush();
            } finally {
                fos.close();
            }
        } catch (IOException ex) {
            throw new MojoExecutionException("Failed to write file " + outputFile, ex);
        }
    }
    postProcess(outputDirectory);
}

From source file:com.github.veithen.alta.AbstractGenerateMojo.java

License:Apache License

public final void execute() throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    if (skip) {/* w w  w  .  java2  s.  co  m*/
        log.info("Skipping plugin execution");
        return;
    }
    Template<Context> nameTemplate;
    try {
        nameTemplate = templateCompiler.compile(name);
    } catch (InvalidTemplateException ex) {
        throw new MojoExecutionException("Invalid destination name template", ex);
    }
    Template<Context> valueTemplate;
    try {
        valueTemplate = templateCompiler.compile(value);
    } catch (InvalidTemplateException ex) {
        throw new MojoExecutionException("Invalid value template", ex);
    }
    List<Artifact> resolvedArtifacts = new ArrayList<Artifact>();

    if (dependencySet != null) {
        if (log.isDebugEnabled()) {
            log.debug("Resolving project dependencies in scope " + dependencySet.getScope());
        }
        AndArtifactFilter filter = new AndArtifactFilter();
        filter.add(new ScopeArtifactFilter(dependencySet.getScope()));
        filter.add(new IncludeExcludeArtifactFilter(dependencySet.getIncludes(), dependencySet.getExcludes(),
                null));
        for (Artifact artifact : project.getArtifacts()) {
            if (filter.include(artifact)) {
                resolvedArtifacts.add(artifact);
            }
        }
        if (dependencySet.isUseProjectArtifact()) {
            resolvedArtifacts.add(project.getArtifact());
        }
    }

    if (artifacts != null && artifacts.length != 0) {
        List<ArtifactRepository> pomRepositories = project.getRemoteArtifactRepositories();
        List<ArtifactRepository> effectiveRepositories;
        if (repositories != null && repositories.length > 0) {
            effectiveRepositories = new ArrayList<ArtifactRepository>(
                    pomRepositories.size() + repositories.length);
            effectiveRepositories.addAll(pomRepositories);
            for (Repository repository : repositories) {
                try {
                    effectiveRepositories.add(repositorySystem.buildArtifactRepository(repository));
                } catch (InvalidRepositoryException ex) {
                    throw new MojoExecutionException("Invalid repository", ex);
                }
            }
        } else {
            effectiveRepositories = pomRepositories;
        }
        for (ArtifactItem artifactItem : artifacts) {
            String version = artifactItem.getVersion();
            if (StringUtils.isEmpty(version)) {
                version = getMissingArtifactVersion(artifactItem);
            }
            Dependency dependency = new Dependency();
            dependency.setGroupId(artifactItem.getGroupId());
            dependency.setArtifactId(artifactItem.getArtifactId());
            dependency.setVersion(version);
            dependency.setType(artifactItem.getType());
            dependency.setClassifier(artifactItem.getClassifier());
            dependency.setScope(Artifact.SCOPE_COMPILE);
            Artifact artifact = repositorySystem.createDependencyArtifact(dependency);
            try {
                // Find an appropriate version in the specified version range
                ArtifactResolutionResult artifactResolutionResult = artifactCollector.collect(
                        Collections.singleton(artifact), project.getArtifact(), localRepository,
                        effectiveRepositories, artifactMetadataSource, null, Collections.EMPTY_LIST);
                artifact = ((ResolutionNode) artifactResolutionResult.getArtifactResolutionNodes().iterator()
                        .next()).getArtifact();

                // Download the artifact
                resolver.resolve(artifact, effectiveRepositories, localRepository);
            } catch (ArtifactResolutionException ex) {
                throw new MojoExecutionException("Unable to resolve artifact", ex);
            } catch (ArtifactNotFoundException ex) {
                throw new MojoExecutionException("Artifact not found", ex);
            }
            resolvedArtifacts.add(artifact);
        }
    }

    Map<String, String> result = new HashMap<String, String>();
    for (Artifact artifact : resolvedArtifacts) {
        if (log.isDebugEnabled()) {
            log.debug("Processing artifact " + artifact.getId());
        }
        Context context = new Context(artifact);
        try {
            String name = nameTemplate.evaluate(context);
            if (log.isDebugEnabled()) {
                log.debug("name = " + name);
            }
            if (name == null) {
                continue;
            }
            String value = valueTemplate.evaluate(context);
            if (log.isDebugEnabled()) {
                log.debug("value = " + value);
            }
            if (value == null) {
                continue;
            }
            String currentValue = result.get(name);
            if (currentValue == null) {
                currentValue = value;
            } else if (separator == null) {
                throw new MojoExecutionException("No separator configured");
            } else {
                currentValue = currentValue + separator + value;
            }
            result.put(name, currentValue);
        } catch (EvaluationException ex) {
            throw new MojoExecutionException(
                    "Failed to process artifact " + artifact.getId() + ": " + ex.getMessage(), ex);
        }
    }
    process(result);
}

From source file:com.google.code.rptm.CheckSourceDistMojo.java

License:Apache License

private void check(NamedNode node, ScmUtil scmUtil, File dir) throws MojoExecutionException {
    Log log = getLog();
    FilenameMatcher ignore;/*from  w  w w. java2  s. co m*/
    try {
        ignore = scmUtil.getIgnoredEntries(dir);
    } catch (ScmException ex) {
        throw new MojoExecutionException("Unable to get ignore list for " + dir);
    }
    if (log.isDebugEnabled()) {
        log.debug("=================");
        log.debug("Archive entry: " + node.getName());
        log.debug("Directory: " + dir);
        log.debug("Ignore list: " + ignore);
    }
    for (NamedNode child : node.getChildren()) {
        File file = new File(dir, child.getName());
        if (ignore.matches(child.getName())) {
            log.error("Source distribution contains entry that is ignored in SCM: " + file);
        } else if (file.isDirectory()) {
            check(child, scmUtil, file);
        }
    }
}

From source file:com.google.dart.util.WagonUtils.java

License:Apache License

/**
 * Convenient method to create a wagon//from   ww w.ja  va 2  s  . com
 * 
 * @param id
 * @param url
 * @param wagonManager
 * @param settings
 * @param logger
 * @return
 * @throws MojoExecutionException
 */
public static Wagon createWagon(final String id, final String url, final WagonManager wagonManager,
        final Settings settings, final Log logger)
        throws WagonException, UnsupportedProtocolException, WagonConfigurationException {
    Wagon wagon = null;

    final Repository repository = new Repository(id, url);

    wagon = wagonManager.getWagon(repository);

    if (logger.isDebugEnabled()) {
        final Debug debug = new Debug();
        wagon.addSessionListener(debug);
        wagon.addTransferListener(debug);
    }

    final ProxyInfo proxyInfo = getProxyInfo(settings);
    if (proxyInfo != null) {
        wagon.connect(repository, wagonManager.getAuthenticationInfo(repository.getId()), proxyInfo);
    } else {
        wagon.connect(repository, wagonManager.getAuthenticationInfo(repository.getId()));
    }

    return wagon;
}

From source file:com.googlecode.cmakemavenproject.CompileMojo.java

License:Apache License

@Override
@SuppressWarnings("NP_UNWRITTEN_FIELD")
public void execute() throws MojoExecutionException, MojoFailureException {
    try {//from  w w  w . j a  va2  s.c  o  m
        if (!projectDirectory.exists())
            throw new MojoExecutionException(projectDirectory.getAbsolutePath() + " does not exist");
        if (!projectDirectory.isDirectory())
            throw new MojoExecutionException(projectDirectory.getAbsolutePath() + " must be a directory");

        File cmakeFile = new File(project.getBuild().getDirectory(), "dependency/cmake/bin/cmake");
        ProcessBuilder processBuilder = new ProcessBuilder(cmakeFile.getAbsolutePath(), "--build",
                projectDirectory.getPath());
        if (target != null)
            Collections.addAll(processBuilder.command(), "--target", target);
        if (config != null)
            Collections.addAll(processBuilder.command(), "--config", config);
        if (options != null)
            processBuilder.command().addAll(options);

        Map<String, String> env = processBuilder.environment();

        if (environmentVariables != null)
            env.putAll(environmentVariables);
        Log log = getLog();
        if (log.isDebugEnabled()) {
            log.debug("projectDirectory: " + projectDirectory);
            log.debug("target: " + target);
            log.debug("config: " + config);
            log.debug("environment: " + processBuilder.environment());
            log.debug("command-line: " + processBuilder.command());
        }
        int returnCode = Mojos.waitFor(processBuilder);
        if (returnCode != 0)
            throw new MojoExecutionException("Return code: " + returnCode);
    } catch (InterruptedException e) {
        throw new MojoExecutionException("", e);
    } catch (IOException e) {
        throw new MojoExecutionException("", e);
    }
}

From source file:com.googlecode.cmakemavenproject.GenerateMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException {
    try {//from   w w  w  .java2s.  c  o  m
        PluginDescriptor pluginDescriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
        String groupId = pluginDescriptor.getGroupId();
        String version = pluginDescriptor.getVersion();
        String classifier = getClassifier();
        if (!targetPath.exists() && !targetPath.mkdirs())
            throw new MojoExecutionException("Cannot create " + targetPath.getAbsolutePath());

        if (classifier == null) {
            String os = System.getProperty("os.name");
            String arch = System.getProperty("os.arch");
            if (os.toLowerCase().startsWith("windows"))
                classifier = "windows";
            else if (os.toLowerCase().startsWith("linux"))
                if (arch.equals("x86_64") || arch.equals("amd64"))
                    classifier = "linux64";
                else if (arch.equals("i386"))
                    classifier = "linux32";
                else
                    throw new MojoExecutionException("Unsupported Linux arch: " + arch);
            else if (os.toLowerCase().startsWith("mac"))
                if (arch.equals("x86_64"))
                    classifier = "mac64";
                else
                    throw new MojoExecutionException("Unsupported Mac arch: " + arch);
            else
                throw new MojoExecutionException("Unsupported os.name: " + os);
        }
        File cmakeDir = new File(project.getBuild().getDirectory(), "dependency/cmake");
        String binariesArtifact = "cmake-binaries";

        Element groupIdElement = new Element("groupId", groupId);
        Element artifactIdElement = new Element("artifactId", binariesArtifact);
        Element versionElement = new Element("version", version);
        Element classifierElement = new Element("classifier", classifier);
        Element outputDirectoryElement = new Element("outputDirectory", cmakeDir.getAbsolutePath());
        Element artifactItemElement = new Element("artifactItem", groupIdElement, artifactIdElement,
                versionElement, classifierElement, outputDirectoryElement);
        Element artifactItemsItem = new Element("artifactItems", artifactItemElement);
        Xpp3Dom configuration = MojoExecutor.configuration(artifactItemsItem);
        ExecutionEnvironment environment = MojoExecutor.executionEnvironment(project, session, pluginManager);
        Plugin dependencyPlugin = MojoExecutor.plugin("org.apache.maven.plugins", "maven-dependency-plugin",
                "2.8");
        MojoExecutor.executeMojo(dependencyPlugin, "unpack", configuration, environment);

        ProcessBuilder processBuilder = new ProcessBuilder(new File(cmakeDir, "bin/cmake").getAbsolutePath(),
                "-G", generator).directory(targetPath);
        if (options != null)
            processBuilder.command().addAll(options);
        processBuilder.command().add(sourcePath.getAbsolutePath());
        Map<String, String> env = processBuilder.environment();

        if (environmentVariables != null)
            env.putAll(environmentVariables);
        Log log = getLog();
        if (log.isDebugEnabled()) {
            log.debug("sourcePath: " + sourcePath);
            log.debug("targetPath: " + targetPath);
            log.debug("environment: " + processBuilder.environment());
            log.debug("command-line: " + processBuilder.command());
        }
        int returnCode = Mojos.waitFor(processBuilder);
        if (returnCode != 0)
            throw new MojoExecutionException("Return code: " + returnCode);
    } catch (InterruptedException e) {
        throw new MojoExecutionException("", e);
    } catch (IOException e) {
        throw new MojoExecutionException("", e);
    }
}