List of usage examples for org.apache.maven.plugin.logging Log info
void info(Throwable error);
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();/*from w w w.jav a 2 s . c o m*/ 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 . j av a 2 s .c o m // 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.rvesse.airline.maven.ValidateMojo.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 w w .j ava 2 s . c o m*/ // Discover classes and get their meta-data as appropriate // Don't ignore bad sources, this will fail if any bad source is found // thus failing the mojo and the build List<PreparedSource> sources = prepareSources(false); if (sources.size() == 0) { log.info("No sources specified so nothing to do"); return; } // Confirm that we have validated each class for (PreparedSource source : sources) { log.info(String.format("Validated Airline metadata for %s", source.getSourceClass())); } }
From source file:com.github.tmarwen.maven.plugins.MultipleOsRule.java
License:Apache License
@Override public void execute(EnforcerRuleHelper enforcerRuleHelper) throws EnforcerRuleException { Log log = enforcerRuleHelper.getLog(); try {/*from www . j a va 2s. co m*/ // get the OS name using the helper String osName = ((String) enforcerRuleHelper.evaluate("${os.name}")).toLowerCase(); log.info("The build is running in a \"" + osName + "\" box. Will check if this OS is within the allowed range."); List<String> osRangeList = retrieveOsRangeList(requiredOSs); if (osRangeList.isEmpty()) { throw new EnforcerRuleException("Allowed Operating System range should be specified."); } else if (!osRangeList.contains(osName)) { throw new EnforcerRuleException("The current Operating System is not in the allowed range."); } else { log.info("--> " + osName + " is in the allowed OS range: " + osRangeList); } } catch (ExpressionEvaluationException e) { throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e); } }
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 ava 2 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.github.zhve.ideaplugin.ArtifactDependencyResolver.java
License:Apache License
/** * Transitive resolve all dependencies for reactor projects * * @param artifactFactory standard Maven's factory to create artifacts * @param reactorArtifacts reactor artifacts * @param reactorProjects reactor projects * @return dependency map: reactor project -> dependency data * @throws InvalidVersionSpecificationException error *///from w w w . j av a 2s. c om private Map<MavenProject, DependencyData> findDependencies(Log log, ArtifactFactory artifactFactory, Set<Artifact> reactorArtifacts, List<MavenProject> reactorProjects) throws InvalidVersionSpecificationException { // artifact -> all transitive dependencies Map<Artifact, DependencyData> dependencyMap = new HashMap<Artifact, DependencyData>(); log.info(""); log.info("Detect Dependencies"); for (MavenProject project : reactorProjects) { log.info(""); log.info(project.getId()); List<Artifact> remoteData = new ArrayList<Artifact>(); List<Artifact> reactorData = new ArrayList<Artifact>(); for (Object object : project.getDependencies()) { Dependency dependency = (Dependency) object; Artifact dependencyArtifact = toDependencyArtifact(artifactFactory, dependency); boolean reactor = reactorArtifacts.contains(dependencyArtifact); String id = dependencyArtifact.getId() + ":" + dependencyArtifact.getScope(); if ("jar".equals(dependencyArtifact.getType())) { if (reactor) { log.info("R " + id); reactorData.add(dependencyArtifact); } else { log.info(" " + id); remoteData.add(dependencyArtifact); } } else { log.info("O " + id + " (type=" + dependencyArtifact.getType() + ")"); } } // save dependency data for project dependencyMap.put(project.getArtifact(), new DependencyData(remoteData, reactorData)); } log.info(""); log.info("Resolve Dependencies"); Map<MavenProject, DependencyData> result = new LinkedHashMap<MavenProject, DependencyData>(); for (MavenProject project : reactorProjects) { log.info(""); log.info(project.getId()); Map<String, Artifact> reactorData = new LinkedHashMap<String, Artifact>(); Map<String, Artifact> remoteData = new LinkedHashMap<String, Artifact>(); Queue<Artifact> queue = new LinkedList<Artifact>(); queue.add(project.getArtifact()); while (!queue.isEmpty()) { Artifact artifact = queue.poll(); log.info("# " + artifact.getId() + ":" + artifact.getScope()); DependencyData artifactDependencyData = dependencyMap.get(artifact); // analyze all remote dependencies for given level for (Artifact dependency : artifactDependencyData.getRemoteList()) { String dependencyConflictId = dependency.getDependencyConflictId(); Artifact dependencyArtifact = toDependencyArtifact(artifactFactory, dependency, artifact.getScope()); if (dependencyArtifact != null) { String fullName = dependencyArtifact.getId() + ":" + dependencyArtifact.getScope(); Artifact prevArtifact = remoteData.get(dependencyConflictId); if (prevArtifact == null) { // new remote dependency log.info(" " + fullName); remoteData.put(dependencyConflictId, dependencyArtifact); } else { // we have already added this remote dependency if (prevArtifact.getId().equals(dependencyArtifact.getId())) { log.info("D " + fullName); } else { log.info("C " + fullName); log.info(" " + project.getArtifact().getId()); log.info(" " + "+-" + prevArtifact.getId() + ":" + prevArtifact.getScope()); log.info(" " + "+-" + artifact.getId() + ":" + artifact.getScope()); log.info(" " + " \\-" + fullName); } } } else { log.info("O " + dependency.getId() + ":" + dependency.getScope() + " (inherit=" + artifact.getId() + ":" + artifact.getScope() + ")"); } } // analyze all reactor dependencies for given level for (Artifact dependency : artifactDependencyData.getReactorList()) { String dependencyConflictId = dependency.getDependencyConflictId(); Artifact dependencyArtifact = toDependencyArtifact(artifactFactory, dependency, artifact.getScope()); if (dependencyArtifact != null) { String fullName = dependencyArtifact.getId() + ":" + dependencyArtifact.getScope(); Artifact prevArtifact = reactorData.get(dependencyConflictId); if (prevArtifact == null) { // new reactor dependency log.info("R " + fullName); reactorData.put(dependencyConflictId, dependencyArtifact); // go deep queue.add(dependencyArtifact); } else { // we have already added this remote dependency if (prevArtifact.getId().equals(dependencyArtifact.getId())) { log.info("D " + fullName); } else { log.info("C " + fullName); log.info(" " + project.getArtifact().getId()); log.info(" " + "+-" + prevArtifact.getId() + ":" + prevArtifact.getScope()); log.info(" " + "+-" + artifact.getId() + ":" + artifact.getScope()); log.info(" " + " \\-" + fullName); } } } else { log.info("O " + dependency.getId() + ":" + dependency.getScope() + " (inherit=" + artifact.getId() + ":" + artifact.getScope() + ")"); } } } result.put(project, new DependencyData(new ArrayList<Artifact>(remoteData.values()), new ArrayList<Artifact>(reactorData.values()))); } return result; }
From source file:com.github.zhve.ideaplugin.ArtifactHolder.java
License:Apache License
public ArtifactHolder(Log log, ArtifactDependencyResolver resolver, List<MavenProject> reactorProjects) throws MojoExecutionException { // collect/*from ww w . jav a 2 s. co m*/ reactorArtifacts = new HashSet<Artifact>(); for (MavenProject reactorProject : reactorProjects) reactorArtifacts.add(reactorProject.getArtifact()); reactorArtifacts = Collections.unmodifiableSet(reactorArtifacts); // Resolve Map<MavenProject, ArtifactDependencyResolver.DependencyData> dependencyDataNewMap; try { dependencyDataNewMap = resolver.findDependencies(reactorProjects); } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException(e.getMessage(), e); } // Find common dependencies Set<Artifact> fullSet = new HashSet<Artifact>(); for (ArtifactDependencyResolver.DependencyData data : dependencyDataNewMap.values()) fullSet.addAll(data.getRemoteList()); // Save allDependencies allDependencies = new ArrayList<Artifact>(fullSet); Collections.sort(allDependencies, ArtifactComparator.INSTANCE); allDependencies = Collections.unmodifiableList(allDependencies); log.info(""); log.info("Full Dependencies"); log.info(""); for (Artifact artifact : allDependencies) log.info(" " + artifact.getId()); // Save dependencyMap this.dependencyMap = new HashMap<MavenProject, List<Artifact>>(); for (Map.Entry<MavenProject, ArtifactDependencyResolver.DependencyData> entry : dependencyDataNewMap .entrySet()) { MavenProject project = entry.getKey(); // Remove commonSet from dependencies List<Artifact> remoteList = new ArrayList<Artifact>(entry.getValue().getRemoteList()); List<Artifact> reactorList = new ArrayList<Artifact>(entry.getValue().getReactorList()); Collections.sort(remoteList, ArtifactComparator.INSTANCE); Collections.sort(reactorList, ArtifactComparator.INSTANCE); List<Artifact> artifacts = new ArrayList<Artifact>(); artifacts.addAll(reactorList); artifacts.addAll(remoteList); this.dependencyMap.put(project, Collections.unmodifiableList(artifacts)); } }
From source file:com.github.zhve.ideaplugin.Util.java
License:Apache License
public static void deleteFileOrDirectory(Log log, File file) { if (file.exists()) { if (file.isDirectory()) { // clean directory File[] files = file.listFiles(); if (files != null) { for (File f : files) deleteFileOrDirectory(log, f); }//from ww w .j a v a 2s.c o m } // delete file or empty directory if (file.delete()) log.info(" " + file.getAbsolutePath()); else log.error(file.getAbsolutePath()); } else { log.info(" " + file.getAbsolutePath()); } }
From source file:com.google.code.maven.plugin.http.client.FormCredentials.java
License:Apache License
/** * @param httpclient// ww w .ja v a 2 s . co m * @param beanResolver * @return * @throws IOException */ public void authenticate(DefaultHttpClient httpclient, Log log) throws IOException { HttpPost httpPost = new HttpPost(formUrl); UsernamePasswordCredentials credentials = toUsernamePasswordCredentials(); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new Parameter(loginParameterName, credentials.getUserName()).toNameValuePair()); nvps.add(new Parameter(passwordParameterName, credentials.getPassword()).toNameValuePair()); for (Parameter parameter : parameters) { nvps.add(parameter.toNameValuePair()); } httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse response = httpclient.execute(httpPost); EntityUtils.consume(response.getEntity()); log.info("form authentication submitted to " + formUrl); }
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);// 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; }