List of usage examples for org.apache.maven.plugin.logging Log debug
void debug(Throwable error);
From source file:org.codehaus.mojo.apt.AptUtils.java
License:Open Source License
public static boolean invoke(Log log, List<String> args) throws MojoExecutionException { // get apt method Class<?> apt = getAptClass(); StringWriter stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter, true); String[] argsArray = args.toArray(new String[args.size()]); Method method;/*from ww w . j a v a2 s .c om*/ Object[] methodArgs; try { method = apt.getMethod("process", new Class[] { PrintWriter.class, String[].class }); methodArgs = new Object[] { writer, argsArray }; } catch (NoSuchMethodException exception) { try { method = apt.getMethod("compile", new Class[] { String[].class, PrintWriter.class }); methodArgs = new Object[] { argsArray, writer }; } catch (NoSuchMethodException exception2) { throw new MojoExecutionException("Error while executing the apt compiler", exception2); } } // invoke apt log.debug("Invoking apt with arguments:"); LogUtils.log(log, LogUtils.LEVEL_DEBUG, args, " "); int result; try { result = ((Integer) method.invoke(null, methodArgs)).intValue(); } catch (IllegalAccessException exception) { throw new MojoExecutionException("Error while executing the apt compiler", exception); } catch (InvocationTargetException exception) { throw new MojoExecutionException("Error while executing the apt compiler", exception); } // log output LogUtils.log(log, LogUtils.LEVEL_WARN, new StringReader(stringWriter.toString())); // log result log.debug("Apt returned " + result); return (result == 0); }
From source file:org.codehaus.mojo.apt.AptUtils.java
License:Open Source License
public static boolean invokeForked(Log log, File workingDirectory, String executable, String meminitial, String maxmemory, List<String> args) throws MojoExecutionException { // create command Commandline cli = new Commandline(); cli.setWorkingDirectory(workingDirectory.getAbsolutePath()); log.debug("Using working directory " + cli.getWorkingDirectory()); cli.setExecutable(executable);//from ww w . jav a 2s. c om if (StringUtils.isNotEmpty(meminitial)) { cli.createArg().setValue("-J-Xms" + meminitial); } if (StringUtils.isNotEmpty(maxmemory)) { cli.createArg().setValue("-J-Xmx" + maxmemory); } // create arguments file File argsFile; try { argsFile = createArgsFile(args); String argsPath = argsFile.getCanonicalPath().replace(File.separatorChar, '/'); cli.createArg().setValue("@" + argsPath); } catch (IOException exception) { throw new MojoExecutionException("Error creating arguments file", exception); } log.debug("Using argument file:"); LogUtils.log(log, LogUtils.LEVEL_DEBUG, argsFile, " "); // invoke apt if (log.isDebugEnabled()) { log.debug("Invoking apt with command " + cli); } StringStreamConsumer out = new StringStreamConsumer(); StringStreamConsumer err = new StringStreamConsumer(); int result; try { result = CommandLineUtils.executeCommandLine(cli, out, err); } catch (CommandLineException exception) { throw new MojoExecutionException("Error while executing the apt compiler", exception); } // log output LogUtils.log(log, LogUtils.LEVEL_INFO, new StringReader(out.getOutput())); LogUtils.log(log, LogUtils.LEVEL_WARN, new StringReader(err.getOutput())); // log result log.debug("Apt returned " + result); return (result == 0); }
From source file:org.codehaus.mojo.apt.LogUtils.java
License:Open Source License
public static void log(Log log, int level, CharSequence message) { if (level == LEVEL_DEBUG) { log.debug(message); } else if (level == LEVEL_INFO) { log.info(message);//w ww . j a v a 2s .c o m } else if (level == LEVEL_WARN) { log.warn(message); } else if (level == LEVEL_ERROR) { log.error(message); } else { throw new IllegalArgumentException("Unknown log level: " + level); } }
From source file:org.codehaus.mojo.cassandra.Utils.java
License:Apache License
/** * Starts the Cassandra server.// w w w . ja v a 2 s .co m * * @param cassandraDir The directory to start the Server process in. * @param commandLine The command line to use to start the Server process. * @param environment The environment to start the Server process with. * @param log The log to send the output to. * @return The {@link ExecuteResultHandler} for the started process. * @throws MojoExecutionException if something went wrong. */ protected static DefaultExecuteResultHandler startCassandraServer(File cassandraDir, CommandLine commandLine, Map environment, Log log) throws MojoExecutionException { try { Executor exec = new DefaultExecutor(); DefaultExecuteResultHandler execHandler = new DefaultExecuteResultHandler(); exec.setWorkingDirectory(cassandraDir); exec.setProcessDestroyer(new ShutdownHookProcessDestroyer()); LogOutputStream stdout = new MavenLogOutputStream(log); LogOutputStream stderr = new MavenLogOutputStream(log); log.debug("Executing command line: " + commandLine); exec.setStreamHandler(new PumpStreamHandler(stdout, stderr)); exec.execute(commandLine, environment, execHandler); return execHandler; } catch (ExecuteException e) { throw new MojoExecutionException("Command execution failed.", e); } catch (IOException e) { throw new MojoExecutionException("Command execution failed.", e); } }
From source file:org.codehaus.mojo.fitnesse.FitnesseReportMojo.java
License:Open Source License
static void copyFile(Log pLogger, InputStream pIn, File pDestFile) throws MavenReportException { FileOutputStream tOut = null; try {//from w w w .jav a2 s . c om if (!pDestFile.exists()) { pDestFile.createNewFile(); } tOut = new FileOutputStream(pDestFile); byte[] tBuff = new byte[100]; int tRead = pIn.read(tBuff); while (tRead >= 0) { tOut.write(tBuff, 0, tRead); tRead = pIn.read(tBuff); } pLogger.debug("File copied to " + pDestFile); pLogger.debug("File exist " + pDestFile.exists()); } catch (FileNotFoundException e) { throw new MavenReportException("File doesn't exist", e); } catch (IOException e) { throw new MavenReportException("Unable to write into file...", e); } finally { try { if (tOut != null) { tOut.close(); } if (pIn != null) { pIn.close(); } } catch (IOException e) { throw new MavenReportException("Unable to close report file report...", e); } } }
From source file:org.codehaus.mojo.fitnesse.runner.ClassPathBuilder.java
License:Open Source License
public String getPath(List pSubstitutions, Log pLog) throws MojoExecutionException { String tOriginalPath;/*from w w w . ja v a 2 s .c o m*/ String tUrl = "GET /" + mPage + "?responder=fitClient&includePaths=yes HTTP/1.1\r\n\r\n"; pLog.debug("Use URL for classPath download [" + tUrl + "]"); try { StreamReader tSocketReader = establishConnection(tUrl); int tNbBytes = FitProtocol.readSize(tSocketReader); if (tNbBytes != 0) { throw new MojoExecutionException("Unable to connect to server."); } tNbBytes = FitProtocol.readSize(tSocketReader); tOriginalPath = FitProtocol.readDocument(tSocketReader, tNbBytes); pLog.debug("Download classpath is [" + tOriginalPath + "]"); String tPath = transformPath(tOriginalPath, pSubstitutions); pLog.info("Use path [" + tPath + "]"); return tPath; } catch (Exception e) { throw new MojoExecutionException("Unable to download path from FitNesse Server", e); } }
From source file:org.codehaus.mojo.javascript.titanium.TitaniumBuilder.java
License:Open Source License
/** * Parse a line and output to the specified logger using the appropriate level. * @param line The line to parse./* w w w . j ava 2 s . c o m*/ * @param log The logger. * @param defaultLogLevel The log level to use if the parsed line doesn't contain * the log level info. * @return the log level used to log the line. */ private static String parseTitaniumBuilderLine(String line, Log log, String defaultLogLevel) { final Pattern pattern = Pattern.compile("\\[(TRACE|INFO|DEBUG|WARN|ERROR)\\] (.+)"); final Matcher matcher = pattern.matcher(line); if (matcher.find()) { String type = matcher.group(1); String msg = matcher.group(2); if (type.equals("TRACE") || type.equals("DEBUG")) { log.debug(msg); return "DEBUG"; } else if (type.equals("INFO")) { log.info(msg); return "INFO"; } else if (type.equals("ERROR")) { log.error(msg); return "ERROR"; } else if (type.equals("WARN")) { log.warn(msg); return "WARN"; } else { log.debug(msg); return "DEBUG"; } } else { if (defaultLogLevel != null) { defaultLogLevel = defaultLogLevel.toUpperCase(); if (defaultLogLevel.equals("DEBUG") || defaultLogLevel.equals("TRACE")) { log.debug(line); } else if (defaultLogLevel.equals("INFO")) { log.info(line); } else if (defaultLogLevel.equals("ERROR")) { log.error(line); } else if (defaultLogLevel.equals("WARN")) { log.warn(line); } else { log.debug(line); defaultLogLevel = "DEBUG"; } return defaultLogLevel; } else { log.debug(line); return "DEBUG"; } } }
From source file:org.codehaus.mojo.jaxb2.AbstractJaxbMojo.java
License:Apache License
/** * {@inheritDoc}//ww w . j a v a 2 s . com */ @Override public final void execute() throws MojoExecutionException, MojoFailureException { // 0) Get the log and its relevant level final Log log = getLog(); final boolean isDebugEnabled = log.isDebugEnabled(); final boolean isInfoEnabled = log.isInfoEnabled(); // 1) Should we skip execution? if (shouldExecutionBeSkipped()) { if (isDebugEnabled) { log.debug("Skipping execution, as instructed."); } return; } // 2) Printout relevant version information. if (isDebugEnabled) { logPluginAndJaxbDependencyInfo(); } // 3) Are generated files stale? if (isReGenerationRequired()) { if (performExecution()) { // As instructed by the performExecution() method, update // the timestamp of the stale File. updateStaleFileTimestamp(); // Hack to support M2E buildContext.refresh(getOutputDirectory()); } else if (isInfoEnabled) { log.info("Not updating staleFile timestamp as instructed."); } } else if (isInfoEnabled) { log.info("No changes detected in schema or binding files - skipping JAXB generation."); } // 4) If the output directories exist, add them to the MavenProject's source directories if (getOutputDirectory().exists() && getOutputDirectory().isDirectory()) { final String canonicalPathToOutputDirectory = FileSystemUtilities .getCanonicalPath(getOutputDirectory()); if (log.isDebugEnabled()) { log.debug("Adding existing JAXB outputDirectory [" + canonicalPathToOutputDirectory + "] to Maven's sources."); } // Add the output Directory. getProject().addCompileSourceRoot(canonicalPathToOutputDirectory); } }
From source file:org.codehaus.mojo.jaxb2.helpers.SchemagenHelper.java
License:Apache License
/** * Replaces all namespaces within generated schema files, as instructed by the configured Schema instances. * * @param resolverMap The map relating generated schema file name to * SimpleNamespaceResolver instances. * @param configuredTransformSchemas The Schema instances read from the configuration of this plugin. * @param mavenLog The active Log. * @param schemaDirectory The directory where all generated schema files reside. * @throws MojoExecutionException If the namespace replacement could not be done. *///from w ww. j a v a2 s . c om public static void replaceNamespacePrefixes(final Map<String, SimpleNamespaceResolver> resolverMap, final List<TransformSchema> configuredTransformSchemas, final Log mavenLog, final File schemaDirectory) throws MojoExecutionException { if (mavenLog.isDebugEnabled()) { mavenLog.debug("Got resolverMap.keySet() [generated filenames]: " + resolverMap.keySet()); } for (SimpleNamespaceResolver currentResolver : resolverMap.values()) { File generatedSchemaFile = new File(schemaDirectory, currentResolver.getSourceFilename()); Document generatedSchemaFileDocument = null; for (TransformSchema currentTransformSchema : configuredTransformSchemas) { // Should we alter the namespace prefix as instructed by the current schema? final String newPrefix = currentTransformSchema.getToPrefix(); final String currentUri = currentTransformSchema.getUri(); if (StringUtils.isNotEmpty(newPrefix)) { // Find the old/current prefix of the namespace for the current schema uri. final String oldPrefix = currentResolver.getNamespaceURI2PrefixMap().get(currentUri); if (StringUtils.isNotEmpty(oldPrefix)) { // Can we perform the prefix substitution? validatePrefixSubstitutionIsPossible(oldPrefix, newPrefix, currentResolver); if (mavenLog.isDebugEnabled()) { mavenLog.debug("Subtituting namespace prefix [" + oldPrefix + "] with [" + newPrefix + "] in file [" + currentResolver.getSourceFilename() + "]."); } // Get the Document of the current schema file. if (generatedSchemaFileDocument == null) { generatedSchemaFileDocument = parseXmlToDocument(generatedSchemaFile); } // Replace all namespace prefixes within the provided document. process(generatedSchemaFileDocument.getFirstChild(), true, new ChangeNamespacePrefixProcessor(oldPrefix, newPrefix)); } } } if (generatedSchemaFileDocument != null) { // Overwrite the generatedSchemaFile with the content of the generatedSchemaFileDocument. mavenLog.debug("Overwriting file [" + currentResolver.getSourceFilename() + "] with content [" + getHumanReadableXml(generatedSchemaFileDocument) + "]"); savePrettyPrintedDocument(generatedSchemaFileDocument, generatedSchemaFile); } else { mavenLog.debug("No namespace prefix changes to generated schema file [" + generatedSchemaFile.getName() + "]"); } } }
From source file:org.codehaus.mojo.jaxb2.helpers.SchemagenHelper.java
License:Apache License
/** * Updates all schemaLocation attributes within the generated schema files to match the 'file' * properties within the Schemas read from the plugin configuration. After that, the files are * physically renamed.//from ww w.ja v a 2 s . c om * * @param resolverMap The map relating generated schema file name to * SimpleNamespaceResolver instances. * @param configuredTransformSchemas The Schema instances read from the configuration of this plugin. * @param mavenLog The active Log. * @param schemaDirectory The directory where all generated schema files reside. */ public static void renameGeneratedSchemaFiles(final Map<String, SimpleNamespaceResolver> resolverMap, final List<TransformSchema> configuredTransformSchemas, final Log mavenLog, final File schemaDirectory) { // Create the map relating namespace URI to desired filenames. Map<String, String> namespaceUriToDesiredFilenameMap = new TreeMap<String, String>(); for (TransformSchema current : configuredTransformSchemas) { if (StringUtils.isNotEmpty(current.getToFile())) { namespaceUriToDesiredFilenameMap.put(current.getUri(), current.getToFile()); } } // Replace the schemaLocation values to correspond to the new filenames for (SimpleNamespaceResolver currentResolver : resolverMap.values()) { File generatedSchemaFile = new File(schemaDirectory, currentResolver.getSourceFilename()); Document generatedSchemaFileDocument = parseXmlToDocument(generatedSchemaFile); // Replace all namespace prefixes within the provided document. process(generatedSchemaFileDocument.getFirstChild(), true, new ChangeFilenameProcessor(namespaceUriToDesiredFilenameMap)); // Overwrite the generatedSchemaFile with the content of the generatedSchemaFileDocument. if (mavenLog.isDebugEnabled()) { mavenLog.debug("Changed schemaLocation entries within [" + currentResolver.getSourceFilename() + "]. " + "Result: [" + getHumanReadableXml(generatedSchemaFileDocument) + "]"); } savePrettyPrintedDocument(generatedSchemaFileDocument, generatedSchemaFile); } // Now, rename the actual files. for (SimpleNamespaceResolver currentResolver : resolverMap.values()) { final String newFilename = namespaceUriToDesiredFilenameMap.get(currentResolver.getLocalNamespaceURI()); final File originalFile = new File(schemaDirectory, currentResolver.getSourceFilename()); if (StringUtils.isNotEmpty(newFilename)) { File renamedFile = FileUtils.resolveFile(schemaDirectory, newFilename); String renameResult = (originalFile.renameTo(renamedFile) ? "Success " : "Failure "); if (mavenLog.isDebugEnabled()) { String suffix = "renaming [" + originalFile.getAbsolutePath() + "] to [" + renamedFile + "]"; mavenLog.debug(renameResult + suffix); } } } }