List of usage examples for org.apache.maven.plugin.logging Log error
void error(Throwable error);
From source file:org.glassfish.maven.plugin.command.AbstractAsadminCommand.java
License:Open Source License
public void execute(ProcessBuilder processBuilder) throws MojoExecutionException, MojoFailureException { List<String> commandLine = new ArrayList<String>(getParameters()); File binDir = new File(sharedContext.getGlassfishDirectory(), "bin"); File asadmin = new File(binDir, "asadmin"); // bnevins 9/13/11 -- the install may have both asadmin and asadmin.bat // if we are on Windows - then prefer the .bat file and explicitly set it. // o/w windows will attempt running the UNIX script which is trouble! // http://java.net/jira/browse/MAVEN_GLASSFISH_PLUGIN-5 if (System.getProperty("os.name").contains("indows")) { File asadminBat = new File(binDir, "asadmin.bat"); if (asadminBat.exists()) { asadmin = asadminBat;//w ww . ja v a 2s. c om } } commandLine.addAll(0, Arrays.asList(asadmin.getAbsolutePath(), getName(), "--echo=" + sharedContext.isEcho(), "--terse=" + sharedContext.isTerse())); Log log = sharedContext.getLog(); log.debug(commandLine.toString()); processBuilder.command(commandLine); try { int exitValue; Process process = processBuilder.start(); processOut = process.getInputStream(); processErr = process.getErrorStream(); BufferedReader outReader = new BufferedReader(new InputStreamReader(processOut)); do { try { exitValue = process.exitValue(); break; } catch (IllegalThreadStateException e) { Thread.sleep(PROCESS_LOOP_SLEEP_MILLIS); } finally { doReadOutput(outReader); } } while (true); if (exitValue != EXIT_SUCCESS) { BufferedReader errorReader = new BufferedReader(new InputStreamReader(processErr)); doReadError(errorReader); String errorMessage = getErrorMessage(); log.error(errorMessage); log.error( "For more detail on what might be causing the problem try running maven with the --debug option "); log.error("or setting the maven-glassfish-plugin \"echo\" property to \"true\"."); throw new MojoFailureException(errorMessage); } } catch (IOException e) { throw new MojoExecutionException(getErrorMessage() + " IOException: " + e.getMessage()); } catch (InterruptedException e) { throw new MojoExecutionException(getErrorMessage() + " Process was interrupted: " + e.getMessage()); } }
From source file:org.glassfish.maven.plugin.command.AbstractAsadminCommand.java
License:Open Source License
protected void doReadError(BufferedReader reader) throws IOException { Log log = sharedContext.getLog(); while (reader.ready()) { log.error(reader.readLine()); }/*from w ww.j a v a2 s . c o m*/ }
From source file:org.glassfish.maven.plugin.command.AsadminCommand.java
License:Open Source License
public void execute(ProcessBuilder processBuilder) throws MojoExecutionException, MojoFailureException { List<String> commandLine = new ArrayList<String>(getParameters()); File binDir = new File(sharedContext.getGlassfishDirectory(), "bin"); File asadmin = new File(binDir, "asadmin"); // bnevins 9/13/11 -- the install may have both asadmin and asadmin.bat // if we are on Windows - then prefer the .bat file and explicitly set it. // o/w windows will attempt running the UNIX script which is trouble! // http://java.net/jira/browse/MAVEN_GLASSFISH_PLUGIN-5 if (System.getProperty("os.name").contains("indows")) { File asadminBat = new File(binDir, "asadmin.bat"); if (asadminBat.exists()) { asadmin = asadminBat;/*from ww w . j a v a2s . c om*/ } } commandLine.addAll(0, Arrays.asList(asadmin.getAbsolutePath(), getName(), "--echo=" + sharedContext.isEcho(), "--terse=" + sharedContext.isTerse())); Log log = sharedContext.getLog(); log.debug(commandLine.toString()); processBuilder.command(commandLine); try { int exitValue; Process process = processBuilder.start(); processOut = process.getInputStream(); processErr = process.getErrorStream(); BufferedReader outReader = new BufferedReader(new InputStreamReader(processOut)); do { try { exitValue = process.exitValue(); break; } catch (IllegalThreadStateException e) { Thread.sleep(PROCESS_LOOP_SLEEP_MILLIS); } finally { while (outReader.ready()) { log.info(outReader.readLine()); } } } while (true); if (exitValue != EXIT_SUCCESS) { BufferedReader errorReader = new BufferedReader(new InputStreamReader(processErr)); while (errorReader.ready()) { log.error(errorReader.readLine()); } String errorMessage = getErrorMessage(); log.error(errorMessage); log.error( "For more detail on what might be causing the problem try running maven with the --debug option "); log.error("or setting the maven-glassfish-plugin \"echo\" property to \"true\"."); throw new MojoFailureException(errorMessage); } } catch (IOException e) { throw new MojoExecutionException(getErrorMessage() + " IOException: " + e.getMessage()); } catch (InterruptedException e) { throw new MojoExecutionException(getErrorMessage() + " Process was interrupted: " + e.getMessage()); } }
From source file:org.grouplens.lenskit.eval.maven.MavenLogAppender.java
License:Open Source License
@Override protected void append(E event) { Log log = mavenLogger.get(); if (log == null) { return;//from w w w . j av a 2 s . c o m } String fmt = layout.doLayout(event); Level lvl = event.getLevel(); if (lvl.isGreaterOrEqual(Level.ERROR)) { log.error(fmt); } else if (lvl.isGreaterOrEqual(Level.WARN)) { log.warn(fmt); } else if (lvl.isGreaterOrEqual(Level.INFO)) { log.info(fmt); } else { log.debug(fmt); } }
From source file:org.hardisonbrewing.maven.core.cli.LogStreamConsumer.java
License:Open Source License
@Override public void consumeLine(String line) { Log log = JoJoMojo.getMojo().getLog(); switch (level) { case LEVEL_INFO: log.info(line);//from w w w . ja v a2 s . co m break; case LEVEL_WARN: log.warn(line); break; case LEVEL_ERROR: log.error(line); break; default: log.debug(line); } }
From source file:org.jahia.utils.maven.plugin.support.MavenAetherHelperUtils.java
License:Open Source License
public static boolean doesJarHavePackageName(File jarFile, String packageName, Log log) { JarInputStream jarInputStream = null; if (jarFile == null) { log.warn("File is null !"); return false; }//from w w w . j ava 2 s. co m if (!jarFile.exists()) { log.warn("File " + jarFile + " does not exist !"); return false; } log.debug("Scanning JAR " + jarFile + "..."); try { jarInputStream = new JarInputStream(new FileInputStream(jarFile)); JarEntry jarEntry = null; while ((jarEntry = jarInputStream.getNextJarEntry()) != null) { String jarPackageName = jarEntry.getName().replaceAll("/", "."); if (jarPackageName.endsWith(".")) { jarPackageName = jarPackageName.substring(0, jarPackageName.length() - 1); } if (jarPackageName.equals(packageName)) { return true; } } } catch (IOException e) { log.error(e); ; } finally { IOUtils.closeQuietly(jarInputStream); } return false; }
From source file:org.jahia.utils.maven.plugin.support.MavenAetherHelperUtils.java
License:Open Source License
public static Set<PackageInfo> getJarPackages(File jarFile, boolean optionalJar, String version, ParsingContext parsingContext, Log log) { JarInputStream jarInputStream = null; Set<PackageInfo> packageInfos = new LinkedHashSet<PackageInfo>(); if (jarFile == null) { log.warn("File is null !"); return packageInfos; }// w w w. j a v a2 s . co m if (!jarFile.exists()) { log.warn("File " + jarFile + " does not exist !"); return packageInfos; } log.debug("Scanning JAR " + jarFile + "..."); try { jarInputStream = new JarInputStream(new FileInputStream(jarFile)); JarEntry jarEntry = null; while ((jarEntry = jarInputStream.getNextJarEntry()) != null) { String jarPackageName = jarEntry.getName().replaceAll("/", "."); if (jarPackageName.endsWith(".")) { jarPackageName = jarPackageName.substring(0, jarPackageName.length() - 1); } if (jarPackageName.startsWith("META-INF") || jarPackageName.startsWith("WEB-INF") || jarPackageName.startsWith("OSGI-INF")) { continue; } packageInfos.addAll(PackageUtils.getPackagesFromClass(jarPackageName, optionalJar, version, jarFile.getCanonicalPath(), parsingContext)); } } catch (IOException e) { log.error(e); ; } finally { IOUtils.closeQuietly(jarInputStream); } return packageInfos; }
From source file:org.jasig.maven.notice.AbstractNoticeMojo.java
License:Apache License
/** * Check if there are any unresolved artifacts in the Set. If there are print a helpful error * message and then throw a {@link MojoFailureException} *///from w w w . j a va 2 s .co m protected void checkUnresolved(Set<Artifact> unresolvedArtifacts) throws MojoFailureException { final Log logger = this.getLog(); if (unresolvedArtifacts.isEmpty()) { return; } final LicenseLookup licenseLookup = new LicenseLookup(); final List<ArtifactLicense> artifacts = licenseLookup.getArtifact(); logger.error("Failed to find Licenses for the following dependencies: "); for (final Artifact unresolvedArtifact : unresolvedArtifacts) { logger.error("\t" + unresolvedArtifact); //Build LicenseLookup data model for artifacts that failed resolution final ArtifactLicense artifactLicense = new ArtifactLicense(); artifactLicense.setGroupId(unresolvedArtifact.getGroupId()); artifactLicense.setArtifactId(unresolvedArtifact.getArtifactId()); final List<MappedVersion> mappedVersions = artifactLicense.getVersion(); final MappedVersion mappedVersion = new MappedVersion(); mappedVersion.setValue(unresolvedArtifact.getVersion()); mappedVersions.add(mappedVersion); artifacts.add(artifactLicense); } logger.error("Try adding them to a 'licenseMapping' file."); final File buildDir = new File(project.getBuild().getDirectory()); final File mappingsfile = new File(buildDir, "license-mappings.xml"); //Make sure the target directory exists try { FileUtils.forceMkdir(buildDir); } catch (IOException e) { logger.warn("Failed to write stub license-mappings.xml file to: " + mappingsfile, e); } //Write the example mappings file final Marshaller marshaller = LicenseLookupContext.getMarshaller(); try { marshaller.marshal(licenseLookup, mappingsfile); logger.error( "A stub license-mapping.xml file containing the unresolved dependencies has been written to: " + mappingsfile); } catch (JAXBException e) { logger.warn("Failed to write stub license-mappings.xml file to: " + mappingsfile, e); } throw new MojoFailureException("Failed to find Licenses for " + unresolvedArtifacts.size() + " artifacts"); }
From source file:org.jasig.maven.notice.CheckNoticeMojo.java
License:Apache License
@Override protected void handleNotice(ResourceFinder finder, String noticeContents) throws MojoFailureException { final Log logger = this.getLog(); //Write out the generated notice file final File outputFile = getNoticeOutputFile(); //Make sure the existing NOTICE file exists if (!outputFile.exists()) { throw new MojoFailureException("No NOTICE file exists at: " + outputFile); }/*w w w . ja va2s . com*/ //Load up the existing NOTICE file final Reader existingNoticeContents; try { final FileInputStream outputFileInputStream = new FileInputStream(outputFile); existingNoticeContents = new InputStreamReader(new BufferedInputStream(outputFileInputStream), this.encoding); } catch (IOException e) { throw new MojoFailureException("Failed to read existing NOTICE File from: " + outputFile, e); } //Check if the notice files match final String diffText = this.generateDiff(logger, new StringReader(noticeContents), existingNoticeContents); if (diffText.length() != 0) { final String buildDir = project.getBuild().getDirectory(); final File expectedNoticeFile = new File(new File(buildDir), "NOTICE.expected"); try { FileUtils.writeStringToFile(expectedNoticeFile, noticeContents, this.encoding); } catch (IOException e) { logger.warn("Failed to write expected NOTICE File to: " + expectedNoticeFile, e); } final String msg = "Existing NOTICE file '" + outputFile + "' doesn't match expected NOTICE file: " + expectedNoticeFile; logger.error(msg + "\n" + diffText); throw new MojoFailureException(msg); } logger.info("NOTICE file is up to date"); }
From source file:org.jboss.tools.releng.NoSnapshotsAllowed.java
License:Open Source License
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { Log log = helper.getLog(); try {/*from ww w. j a v a 2 s . c o m*/ // get the various expressions out of the helper. MavenProject project = (MavenProject) helper.evaluate("${project}"); // MavenSession session = (MavenSession) helper.evaluate( "${session}" ); String target = (String) helper.evaluate("${project.build.directory}"); String artifactId = (String) helper.evaluate("${project.artifactId}"); // defaults if not set if (includePattern == null || includePattern.equals("")) { includePattern = ".*"; } if (excludePattern == null || excludePattern.equals("")) { excludePattern = ""; } log.debug("Search for properties matching " + SNAPSHOT + "..."); Properties projProps = project.getProperties(); Enumeration<?> e = projProps.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); // fetch from parent pom if not passed into the rule config if (buildAlias == null && key.equals("BUILD_ALIAS")) { buildAlias = projProps.getProperty(key); if (buildAlias.matches(buildAliasSearch)) { log.info("Found buildAlias = " + buildAlias + " (for buildAliasSearch = " + buildAliasSearch + ")"); } else { log.debug("Found buildAlias = " + buildAlias + " (for buildAliasSearch = " + buildAliasSearch + ")"); } } else if (key.matches(includePattern) && (excludePattern.equals("") || !key.matches(excludePattern)) && projProps.getProperty(key).indexOf(SNAPSHOT) > -1) { log.error("Found property " + key + " = " + projProps.getProperty(key)); snapshotKey = key; // } else { // log.debug("Property: "+ key + " = " + projProps.getProperty(key)); } } // // retrieve any component out of the session directly // ArtifactResolver resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class ); // RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class ); // log.debug( "Retrieved Session: " + session ); // log.debug( "Retrieved Resolver: " + resolver ); // log.debug( "Retrieved RuntimeInfo: " + rti ); log.debug("Retrieved Target Folder: " + target); log.debug("Retrieved ArtifactId: " + artifactId); log.debug("Retrieved Project: " + project); log.debug("Retrieved Project Version: " + project.getVersion()); if (buildAlias.matches(buildAliasSearch) && snapshotKey != null) { throw new EnforcerRuleException("\nWhen buildAlias (" + buildAlias + ") matches /" + buildAliasSearch + "/, cannot include " + SNAPSHOT + " dependencies.\n"); } } catch (ExpressionEvaluationException e) { throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e); } }