List of usage examples for org.apache.maven.plugin.logging Log info
void info(Throwable error);
From source file:com.github.maven_nar.NarUtil.java
License:Apache License
public static int runCommand(final String cmd, final String[] args, final File workingDirectory, final String[] env, final Log log) throws MojoExecutionException, MojoFailureException { if (log.isInfoEnabled()) { final StringBuilder argLine = new StringBuilder(); if (args != null) { for (final String arg : args) { argLine.append(" " + arg); }/*from w w w. j a va 2s.c o m*/ } if (workingDirectory != null) { log.info("+ cd " + workingDirectory.getAbsolutePath()); } log.info("+ " + cmd + argLine); } return runCommand(cmd, args, workingDirectory, env, new TextStream() { @Override public void println(final String text) { log.info(text); } }, new TextStream() { @Override public void println(final String text) { log.error(text); } }, new TextStream() { @Override public void println(final String text) { log.debug(text); } }, log); }
From source file:com.github.mikkoi.maven.plugins.enforcer.rule.charsetencoding.CharacterSetEncodingRule.java
License:Apache License
/** * @param helper EnforcerRuleHelper//w ww. j av a 2 s .c o m * @throws EnforcerRuleException Throws when error */ public void execute(@Nonnull final EnforcerRuleHelper helper) throws EnforcerRuleException { Log log = helper.getLog(); try { // get the various expressions out of the helper. String basedir = helper.evaluate("${project.basedir}").toString(); log.debug("Retrieved Basedir: " + basedir); log.debug("requireEncoding: " + (requireEncoding == null ? "null" : requireEncoding)); log.debug("directory: " + (directory == null ? "null" : directory)); log.debug("includeRegex: " + (includeRegex == null ? "null" : includeRegex)); log.debug("excludeRegex: " + (excludeRegex == null ? "null" : excludeRegex)); if (this.getRequireEncoding() == null || this.getRequireEncoding().trim().length() == 0) { final String sourceEncoding = (String) helper.evaluate("${project.build.sourceEncoding}"); log.info( "No parameter 'requiredEncoding' set. Defaults to property 'project.build.sourceEncoding'."); if (sourceEncoding != null && sourceEncoding.trim().length() > 0) { this.setRequireEncoding(sourceEncoding); } else { throw new EnforcerRuleException( "Missing parameter 'requireEncoding' and property 'project.build.sourceEncoding'."); } } try { Charset.forName(this.getRequireEncoding()); // Charset names are not case-sensitive } catch (IllegalCharsetNameException e) { throw new EnforcerRuleException("Illegal value (illegal character set name) '" + requireEncoding + "' for parameter 'requireEncoding'."); } catch (UnsupportedCharsetException e) { throw new EnforcerRuleException("Illegal value (not supported character set) '" + requireEncoding + "' for parameter 'requireEncoding'."); } catch (IllegalArgumentException e) { throw new EnforcerRuleException( "Illegal value (empty) '" + requireEncoding + "' for parameter 'requireEncoding'."); } if (this.getDirectory() == null || this.getDirectory().trim().length() == 0) { log.info("No parameter 'directory' set. Defaults to '" + DIRECTORY_DEFAULT + "'."); this.setDirectory(DIRECTORY_DEFAULT); } if (this.getIncludeRegex() == null || this.getIncludeRegex().trim().length() == 0) { log.info("No parameter 'includeRegex' set. Defaults to '" + INCLUDE_REGEX_DEFAULT + "'."); this.setIncludeRegex(INCLUDE_REGEX_DEFAULT); } if (this.getExcludeRegex() == null || this.getExcludeRegex().trim().length() == 0) { log.info("No parameter 'excludeRegex' set. Defaults to '" + EXCLUDE_REGEX_DEFAULT + "'."); this.setExcludeRegex(EXCLUDE_REGEX_DEFAULT); } log.debug("requireEncoding: " + this.getRequireEncoding()); log.debug("directory: " + this.getDirectory()); log.debug("includeRegex: " + this.getIncludeRegex()); log.debug("excludeRegex: " + this.getExcludeRegex()); // Check the existence of the wanted directory: final Path dir = Paths.get(basedir, getDirectory()); log.debug("Get files in dir '" + dir.toString() + "'."); if (!dir.toFile().exists()) { throw new EnforcerRuleException("Directory '" + dir.toString() + "' not found." + " Specified by parameter 'directory' (value: '" + this.getDirectory() + "')!"); } // Put all files into this collection: Collection<FileResult> allFiles = getFileResults(log, dir); // Copy faulty files to another list. log.debug("Moving possible faulty files (faulty encoding) to another list."); for (FileResult res : allFiles) { log.debug("Checking if file '" + res.getPath().toString() + "' has encoding '" + requireEncoding + "'."); boolean hasCorrectEncoding = true; try (FileInputStream fileInputStream = new FileInputStream(res.getPath().toFile())) { byte[] bytes = ByteStreams.toByteArray(fileInputStream); Charset charset = Charset.forName(this.getRequireEncoding()); CharsetDecoder decoder = charset.newDecoder(); ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); decoder.decode(byteBuffer); } catch (CharacterCodingException e) { hasCorrectEncoding = false; } catch (IOException e) { e.printStackTrace(); log.error(e.getMessage()); hasCorrectEncoding = false; } if (!hasCorrectEncoding) { log.debug("Moving faulty file: " + res.getPath()); FileResult faultyFile = new FileResult.Builder(res.getPath()) .lastModified(res.getLastModified()).build(); faultyFiles.add(faultyFile); } else { log.debug("Has correct encoding. Not moving to faulty files list."); } } log.debug("All faulty files moved."); // Report if (!faultyFiles.isEmpty()) { final StringBuilder builder = new StringBuilder(); builder.append("Wrong encoding in following files:"); builder.append(System.getProperty("line.separator")); for (FileResult res : faultyFiles) { builder.append(res.getPath()); builder.append(System.getProperty("line.separator")); } throw new EnforcerRuleException(builder.toString()); } } catch (ExpressionEvaluationException e) { throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e); } }
From source file:com.github.randomcodeorg.netmaven.netmaven.NetMavenSetupMojo.java
protected void setupIKVMLibrary(Log log) throws MojoExecutionException { String ikvmHome = getIKVMLibraryPath(); if (ikvmHome != null) { log.info("The IKVM library is already present at '" + ikvmHome + "'."); return;/*from www . j a v a2 s . co m*/ } String ikvmPath = getDefaultIKVMPath(); File ikvmFile = new File(ikvmPath); if (!ikvmFile.exists()) { log.info("Creating IKVM home directory at '" + ikvmPath + "'"); ikvmFile.mkdirs(); } File tmpFile = dowanloadIKVM(log); extractIKVM(log, tmpFile, ikvmFile); log.info("Deleting the temporary file"); tmpFile.delete(); log.info(""); printLicenseAndDisclaimerInfo(log, ikvmFile.getAbsolutePath()); log.info(""); log.info(""); log.info("Setup completed!"); log.info(""); }
From source file:com.github.randomcodeorg.netmaven.netmaven.NetMavenSetupMojo.java
protected void extractIKVM(Log log, File tmpFile, File targetDir) throws MojoExecutionException { try {//from w w w. java 2 s . c o m log.info("Extracting the IKVM library..."); ZipFile zipFile = new ZipFile(tmpFile); Enumeration<? extends ZipEntry> entries = zipFile.entries(); ZipEntry entry; String[] parts; PathBuilder currentTarget; while (entries.hasMoreElements()) { entry = entries.nextElement(); parts = entry.getName().split("/"); if (parts.length < 2 || parts[1].isEmpty()) continue; currentTarget = PathBuilder.create(targetDir.getAbsolutePath()); for (int i = 1; i < parts.length; i++) { currentTarget.sub(parts[i]); } if (entry.isDirectory()) { if (!new File(currentTarget.build()).exists()) new File(currentTarget.build()).mkdirs(); } else { extract(log, zipFile, entry, currentTarget); } } } catch (IOException e) { throw new MojoExecutionException("Could not extract the IKVM zip file because an I/O error occured.", e); } }
From source file:com.github.randomcodeorg.netmaven.netmaven.NetMavenSetupMojo.java
protected File dowanloadIKVM(Log log) throws MojoExecutionException { try {// w ww . java 2s . c o m log.info("Downloading the IKVM executables..."); File tmpFile = File.createTempFile("mvn", ".zip"); log.debug("Temporary file will be at '" + tmpFile.getAbsolutePath() + "'"); tmpFile.deleteOnExit(); URL resource = new URL(IKVM_DOWNLOAD_DIR); ReadableByteChannel rbc = Channels.newChannel(resource.openStream()); FileOutputStream fos = new FileOutputStream(tmpFile); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); fos.flush(); fos.close(); rbc.close(); log.info("Download completed!"); return tmpFile; } catch (IOException e) { log.error("An I/O error occured during the download of the IKVM library.", e); throw new MojoExecutionException("AnI/O error occured during the download of the IKVM library.", e); } }
From source file:com.github.rvesse.airline.maven.AbstractAirlineOutputMojo.java
License:Apache License
protected CommandUsageGenerator prepareCommandGenerator(FormatProvider provider, PreparedSource source, FormatOptions sourceOptions) {/* w w w .ja v a 2 s . co m*/ Log log = getLog(); CommandUsageGenerator sourceCommandGenerator; log.debug(String.format("Source %s format options are %s", source.getSourceClass(), sourceOptions)); sourceCommandGenerator = provider.getCommandGenerator(this.outputDirectory, sourceOptions); log.info(String.format("Using command help generator %s for source %s", sourceCommandGenerator.getClass(), source.getSourceClass())); return sourceCommandGenerator; }
From source file:com.github.rvesse.airline.maven.AbstractAirlineOutputMojo.java
License:Apache License
protected CommandGroupUsageGenerator<Object> prepareCommandGroupUsageGenerator(FormatProvider provider, PreparedSource source, FormatOptions sourceOptions) { Log log = getLog(); CommandGroupUsageGenerator<Object> sourceGroupGenerator; log.debug(String.format("Source %s format options are %s", source.getSourceClass(), sourceOptions)); sourceGroupGenerator = provider.getGroupGenerator(this.outputDirectory, sourceOptions); log.info(String.format("Using command group help generator %s for source %s", sourceGroupGenerator.getClass(), source.getSourceClass())); return sourceGroupGenerator; }
From source file:com.github.rvesse.airline.maven.AbstractAirlineOutputMojo.java
License:Apache License
protected GlobalUsageGenerator<Object> prepareGlobalUsageGenerator(FormatProvider provider, PreparedSource source, FormatOptions sourceOptions) { Log log = getLog(); GlobalUsageGenerator<Object> sourceGlobalGenerator; log.debug(String.format("Source %s format options are %s", source.getSourceClass(), sourceOptions)); sourceGlobalGenerator = provider.getGlobalGenerator(this.outputDirectory, sourceOptions); log.info(String.format("Using global generator %s for source %s", sourceGlobalGenerator.getClass(), source.getSourceClass()));/*from w ww. ja v a2 s . c o m*/ return sourceGlobalGenerator; }
From source file:com.github.rvesse.airline.maven.AbstractAirlineOutputMojo.java
License:Apache License
private void outputCommandHelp(String format, CommandUsageGenerator commandGenerator, PreparedSource source, File commandHelpFile, CommandMetadata command, ParserMetadata<Object> parser, String programName, String[] groupNames) throws MojoFailureException { Log log = getLog(); try (OutputStream output = new FileOutputStream(commandHelpFile)) { commandGenerator.usage(programName, groupNames, command.getName(), command, parser, output); output.flush();//from w w w . jav a 2 s. c o m output.close(); if (!commandHelpFile.exists()) throw new MojoFailureException(String.format("Failed to create help file %s", commandHelpFile)); log.info(String.format("Generated command help for %s in format %s to file %s", source.getSourceClass(), format, commandHelpFile)); } catch (IOException e) { throw new MojoFailureException( String.format("Failed to generate 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 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();//from w w w . j a v a2 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); } }