List of usage examples for org.apache.maven.plugin.logging Log debug
void debug(Throwable error);
From source file:com.github.maven_nar.AbstractNarLayout.java
License:Apache License
/** * @return//from ww w . j av a 2 s .com * @throws MojoExecutionException */ public static NarLayout getLayout(final String layoutName, final Log log) throws MojoExecutionException { final String className = layoutName.indexOf('.') < 0 ? NarLayout21.class.getPackage().getName() + "." + layoutName : layoutName; log.debug("Using " + className); Class cls; try { cls = Class.forName(className); final Constructor ctor = cls.getConstructor(new Class[] { Log.class }); return (NarLayout) ctor.newInstance(new Object[] { log }); } catch (final ClassNotFoundException e) { throw new MojoExecutionException("Cannot find class for layout " + className, e); } catch (final InstantiationException e) { throw new MojoExecutionException("Cannot instantiate class for layout " + className, e); } catch (final IllegalAccessException e) { throw new MojoExecutionException("Cannot access class for layout " + className, e); } catch (final SecurityException e) { throw new MojoExecutionException("Cannot access class for layout " + className, e); } catch (final NoSuchMethodException e) { throw new MojoExecutionException("Cannot find ctor(Log) for layout " + className, e); } catch (final IllegalArgumentException e) { throw new MojoExecutionException("Wrong arguments ctor(Log) for layout " + className, e); } catch (final InvocationTargetException e) { throw new MojoExecutionException("Cannot invokector(Log) for layout " + className, e); } }
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 v a2 s . 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/*from ww w. ja v a 2 s. co 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.paulmoloney.maven.plugins.enforcer.RuleJavaVersionToolchainAware.java
License:Apache License
/** * This particular rule determines if the specified Java compiler version referenced in the toolchains.xml is an appropriate version * @see org.apache.maven.enforcer.rule.api.EnforcerRule&#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper) *///from w w w .j a v a 2s . com public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { try { super.init(helper); try { compilerManager = (CompilerManager) helper.getComponent(CompilerManager.class); } catch (ComponentLookupException e) { throw new MojoExecutionException("Unable to retrieve component", e); } if (null == compilerId || "".equals(compilerId)) { compilerId = "javac"; } if (null == compilerArgument || "".equals(compilerArgument)) { compilerArgument = "-version"; } /*try { compilerId = (String) helper.evaluate("maven.compiler.compilerId"); } catch (ExpressionEvaluationException e) { throw new MojoExecutionException ("Unable to determine compiler id", e); }*/ } catch (MojoExecutionException e) { throw new EnforcerRuleException("Error initialising mojo", e); } String java_version; final Log log = helper.getLog(); log.debug("Using compiler id'" + getCompilerId() + "'."); try { getCompilerManager().getCompiler(getCompilerId()); } catch (NoSuchCompilerException e) { throw new EnforcerRuleException("No compiler with id: '" + e.getCompilerId() + "'."); } try { Toolchain tc = findToolChain("jdk", helper, null); if (tc != null) { executable = tc.findTool(getCompilerId()); } } catch (MojoExecutionException e) { throw new EnforcerRuleException("", e); } if (null == executable && isFallBackAllowed()) { executable = findToolExecutable(getCompilerId() + getExecutableExtension(), log, "java.home", new String[] { "../bin", "bin", "../sh" }, new String[] { "JDK_HOME", "JAVA_HOME" }, new String[] { "bin", "sh" }); } if (null == executable || "".equals(executable.trim())) { throw new EnforcerRuleException("No valid executable found, aborting"); } setProcess(process); java_version = runToolAndRetrieveVersion(process, log); String clean_java_version = normalizeJDKVersion(java_version); log.debug("Normalized Java Version: " + clean_java_version); ArtifactVersion detectedJdkVersion = new DefaultArtifactVersion(clean_java_version); log.debug("Parsed Version: Major: " + detectedJdkVersion.getMajorVersion() + " Minor: " + detectedJdkVersion.getMinorVersion() + " Incremental: " + detectedJdkVersion.getIncrementalVersion() + " Build: " + detectedJdkVersion.getBuildNumber() + "Qualifier: " + detectedJdkVersion.getQualifier()); log.debug("Rule requires: " + version); enforceVersion(log, "JDK", getVersion(), detectedJdkVersion); }
From source file:com.github.paulmoloney.maven.plugins.enforcer.RuleJavaVersionToolchainAware.java
License:Apache License
/** * Runs the specified java compiler to find out its version * @param process to run/*from w w w .ja v a2 s .co m*/ * @param log to write to * @return the version of specified executable * @throws EnforcerRuleException if version can not be determined */ private String runToolAndRetrieveVersion(ProcessExecutor process, final Log log) throws EnforcerRuleException { try { String firstLine = process.runApplication(); String[] output = firstLine.split("\\s"); if (output.length > 1) { log.debug(executable + " version: " + output[1]); return output[1]; } throw new EnforcerRuleException("No valid version could be determined for " + process.toString()); } catch (ProcessExecutorException e) { throw new EnforcerRuleException("Error determining version", e); } }
From source file:com.github.randomcodeorg.netmaven.netmaven.NetMavenSetupMojo.java
protected void extract(Log log, ZipFile zipFile, ZipEntry entry, PathBuilder target) throws IOException { log.debug(String.format("Extracting '%s' to '%s'", entry.getName(), target.build())); File targetFile = new File(target.build()); if (!targetFile.getParentFile().exists()) targetFile.getParentFile().mkdirs(); InputStream in = zipFile.getInputStream(entry); ReadableByteChannel rbc = Channels.newChannel(in); FileOutputStream fos = new FileOutputStream(targetFile); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); fos.flush();/* w w w . j a v a 2 s.co m*/ fos.close(); rbc.close(); in.close(); log.debug(String.format("Completed extracting '%s'", entry.getName())); }
From source file:com.github.randomcodeorg.netmaven.netmaven.NetMavenSetupMojo.java
protected File dowanloadIKVM(Log log) throws MojoExecutionException { try {/*from w w w . ja va 2 s. 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) {/*from w ww.j a v a2 s .c o 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 w w.java 2 s.c om return sourceGlobalGenerator; }