List of usage examples for org.apache.maven.plugin.logging Log debug
void debug(Throwable error);
From source file:com.github.rvesse.airline.maven.AbstractAirlineOutputMojo.java
License:Apache License
/** * Ensures the necessary output directory exists or can be created failing * the build if not/*w w w .j ava2 s . co m*/ * * @throws MojoFailureException * Thrown if the output directory does not exist or cannot be * created */ protected void ensureOutputDirectory() throws MojoFailureException { Log log = getLog(); log.debug(String.format("Configured output directory is %s", outputDirectory)); if (!outputDirectory.exists() || !outputDirectory.isDirectory()) { if (!outputDirectory.mkdirs()) throw new MojoFailureException(String.format("Failed to create required output directory %s", outputDirectory.getAbsolutePath())); } }
From source file:com.github.rvesse.airline.maven.AbstractAirlineOutputMojo.java
License:Apache License
protected void outputCommandHelp(String format, FormatProvider provider, FormatOptions options, CommandUsageGenerator commandGenerator, PreparedSource source, String programName, String[] groupNames) throws MojoFailureException { // Skip hidden commands unless explicitly included if (source.getCommmand().isHidden() && !options.includeHidden()) return;//from w ww .j a va 2s .c o m Log log = getLog(); log.debug(String.format("Generating command help for %s in format %s", source.getSourceClass(), format)); outputCommandHelp(format, provider, options, commandGenerator, source, source.getCommmand(), source.getParserConfiguration(), programName, groupNames); }
From source file:com.github.rvesse.airline.maven.AbstractAirlineOutputMojo.java
License:Apache License
protected void outputGroupHelp(String format, FormatProvider provider, FormatOptions options, CommandGroupUsageGenerator<Object> groupGenerator, PreparedSource source, CommandGroupMetadata[] groups) throws MojoFailureException { Log log = getLog(); log.debug(String.format("Generating Group help for %s in format %s", source.getSourceClass(), format)); GlobalMetadata<Object> global = source.getGlobal(); File groupHelpFile = new File(this.outputDirectory, global.getName() + provider.getExtension(options)); try (OutputStream output = new FileOutputStream(groupHelpFile)) { groupGenerator.usage(global, groups, output); output.flush();/*w w w . ja v a 2 s . c o m*/ output.close(); if (!groupHelpFile.exists()) throw new MojoFailureException(String.format("Failed to create help file %s", groupHelpFile)); log.info(String.format("Generated Group help for %s in format %s to file %s", source.getSourceClass(), format, groupHelpFile)); } catch (IOException e) { throw new MojoFailureException(String.format("Failed to generate Group help for %s in format %s", source.getSourceClass(), format), e); } }
From source file:com.github.rvesse.airline.maven.AbstractAirlineOutputMojo.java
License:Apache License
protected void outputGlobalHelp(String format, FormatProvider provider, FormatOptions options, GlobalUsageGenerator<Object> globalGenerator, PreparedSource source) throws MojoFailureException { Log log = getLog(); log.debug(String.format("Generating CLI help for %s in format %s", source.getSourceClass(), format)); GlobalMetadata<Object> global = source.getGlobal(); File cliHelpFile = new File(this.outputDirectory, global.getName() + provider.getExtension(options)); try (OutputStream output = new FileOutputStream(cliHelpFile)) { globalGenerator.usage(global, output); output.flush();// w w w .java 2s . com output.close(); if (!cliHelpFile.exists()) throw new MojoFailureException(String.format("Failed to create help file %s", cliHelpFile)); log.info(String.format("Generated CLI help for %s in format %s to file %s", source.getSourceClass(), format, cliHelpFile)); } catch (IOException e) { throw new MojoFailureException(String.format("Failed to generate CLI help for %s in format %s", source.getSourceClass(), format), e); } }
From source file:com.github.rvesse.airline.maven.GenerateMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (project == null) throw new MojoFailureException("Maven project was not injected into Mojo"); if (pluginDescriptor == null) throw new MojoFailureException("Plugin Descriptor was not injected into Mojo"); Log log = getLog(); // Prepare the class realm prepareClassRealm();/*from w ww .ja v a 2 s. c om*/ // Discover classes and get their meta-data as appropriate List<PreparedSource> sources = prepareSources(this.skipBadSources); if (sources.size() == 0) { log.info("No valid sources discovered so nothing to do"); return; } // See how many of each type of output we have int commandOutputs, groupOutputs, cliOutputs; commandOutputs = groupOutputs = cliOutputs = 0; for (PreparedSource source : sources) { if (source.shouldOutputCommandHelp()) { commandOutputs++; } else if (source.shouldOutputGroupHelp()) { groupOutputs++; } else if (source.shouldOutputGlobalHelp()) { cliOutputs++; } } // Ensure directory is created ensureOutputDirectory(); // Prepare default format options FormatOptions defaultOptions = this.defaultOptions == null ? new FormatOptions() : new FormatOptions(this.defaultOptions); log.debug(String.format("Default format options are %s", defaultOptions)); // Prepare format mappings Map<String, FormatOptions> mappedOptions = prepareFormatMappings(defaultOptions); for (String format : formats) { // Prepare the format provider and the appropriate formatting // options FormatProvider provider = FormatMappingRegistry.find(format); if (provider == null) { if (failOnUnknownFormat) throw new MojoFailureException( String.format("Format %s does not have a format mapping defined", format)); log.debug(String.format("Format %s is unknown and was skipped", format)); continue; } FormatOptions options = mappedOptions.get(format); if (options == null) options = defaultOptions; if (options != defaultOptions) log.debug(String.format("Format %s format options are %s", format, options)); if (commandOutputs > 0) { // Command outputs CommandUsageGenerator commandGenerator = provider.getCommandGenerator(this.outputDirectory, options); if (commandGenerator == null) { if (failOnUnsupportedOutputMode) throw new MojoFailureException( String.format("Command help is not supported by format %s", format)); log.warn("Command help is not supported by format " + format); } else { log.info(String.format("Using command help generator %s for format %s", commandGenerator.getClass(), format)); // Generate command help for (PreparedSource source : sources) { FormatOptions sourceOptions = source.getFormatOptions(options); CommandUsageGenerator sourceCommandGenerator = commandGenerator; if (source.isCommand()) { if (!source.shouldOutputCommandHelp()) { log.debug(String.format( "Skipping command help for %s because configured output mode is %s", source.getSourceClass(), source.getOutputMode())); continue; } if (sourceOptions != options) { // Source specific options and thus potentially // generator sourceCommandGenerator = prepareCommandGenerator(provider, source, sourceOptions); } outputCommandHelp(format, provider, sourceOptions, sourceCommandGenerator, source); } else if (source.isGlobal()) { if (!source.shouldOutputCommandHelp()) { log.debug(String.format( "Skipping command help for %s because configured output mode is %s", source.getSourceClass(), source.getOutputMode())); continue; } log.debug(String.format("Generating command help for all commands provided by CLI %s", source.getSourceClass())); if (sourceOptions != options) { sourceCommandGenerator = prepareCommandGenerator(provider, source, sourceOptions); } // Firstly dump the default commands group and then // dump // the command groups GlobalMetadata<Object> global = source.getGlobal(); outputCommandsInGroup(format, provider, sourceOptions, sourceCommandGenerator, source, global.getDefaultGroupCommands(), global.getParserConfiguration(), global.getName(), (String[]) null); for (CommandGroupMetadata group : global.getCommandGroups()) { if (group.isHidden() && !sourceOptions.includeHidden()) continue; outputGroupCommandsHelp(format, provider, sourceOptions, sourceCommandGenerator, source, group, global.getParserConfiguration(), global.getName(), (String[]) null); } } } } } else { log.debug( "Skipping command help as no configured sources were commands or had their output mode set to COMMAND"); } if (groupOutputs > 0) { // Group Outputs CommandGroupUsageGenerator<Object> groupGenerator = provider.getGroupGenerator(this.outputDirectory, options); if (groupGenerator == null) { if (failOnUnsupportedOutputMode) throw new MojoFailureException( String.format("Group help is not supported by format %s", format)); log.warn("Group help is not supported by format " + format); } else { log.info(String.format("Using group help generator %s for format %s", groupGenerator.getClass(), format)); // Generate group help for (PreparedSource source : sources) { if (source.isCommand()) continue; if (source.isGlobal()) { if (!source.shouldOutputGroupHelp()) { log.debug(String.format( "Skipping group help for %s because configured output mode is %s", source.getSourceClass(), source.getOutputMode())); continue; } CommandGroupUsageGenerator<Object> sourceGroupGenerator = groupGenerator; FormatOptions sourceOptions = source.getFormatOptions(options); if (sourceOptions != options) { sourceGroupGenerator = prepareCommandGroupUsageGenerator(provider, source, sourceOptions); } GlobalMetadata<Object> global = source.getGlobal(); for (CommandGroupMetadata group : global.getCommandGroups()) { outputGroupsHelp(format, provider, sourceOptions, sourceGroupGenerator, source, new CommandGroupMetadata[] { group }, global.getParserConfiguration(), global.getName()); } } } } } else { log.debug("Skipping group help as no configured sources had their output mode set to GROUP"); } if (cliOutputs > 0) { // CLI outputs GlobalUsageGenerator<Object> globalGenerator = provider.getGlobalGenerator(this.outputDirectory, options); if (globalGenerator == null) { if (failOnUnsupportedOutputMode) throw new MojoFailureException( String.format("CLI help is not supported by format %s", format)); log.warn("CLI help is not supported by format " + format); } else { log.info(String.format("Using CLI help generator %s for format %s", globalGenerator.getClass(), format)); // Generate global help for (PreparedSource source : sources) { if (!source.isGlobal()) continue; if (!source.shouldOutputGlobalHelp()) { log.debug(String.format( "Skipping global help for %s because configured output mode is %s", source.getSourceClass(), source.getOutputMode())); continue; } GlobalUsageGenerator<Object> sourceGlobalGenerator = globalGenerator; FormatOptions sourceOptions = source.getFormatOptions(options); if (sourceOptions != options) { globalGenerator = prepareGlobalUsageGenerator(provider, source, sourceOptions); } outputGlobalHelp(format, provider, sourceOptions, sourceGlobalGenerator, source); } } } else { log.debug("Skipping command help as no configured sources were CLIs"); } } }
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 ww .j a v a 2 s .co m*/ 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); }/*from w w w. j a v a2 s. c o 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 . j av a 2 s . com 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.maven.plugin.http.client.utils.HttpRequestUtils.java
License:Apache License
public static HttpResponse query(DefaultHttpClient httpclient, Request request, Proxy proxy, Log log) throws ClientProtocolException, IOException, MojoExecutionException { log.debug("preparing " + request); if (proxy != null) { log.info("setting up " + proxy + " for request " + request); proxy.prepare(httpclient);/*from w w w . ja v a 2 s . co m*/ } HttpRequestBase httpRequest = request.buildHttpRequestBase(httpclient, log); HttpHost targetHost = request.buildHttpHost(log); log.debug("HTTP " + request.getMethod() + " url=" + request.getFinalUrl()); long responseTime = System.currentTimeMillis(); HttpResponse response = httpclient.execute(targetHost, httpRequest); log.debug("received response (time=" + (System.currentTimeMillis() - responseTime) + "ms) for request [" + "HTTP " + request.getMethod() + " url=" + request.getFinalUrl() + "]"); return response; }
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;// w w w. j a v a2 s . c o 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); } } }