List of usage examples for org.apache.maven.plugin.logging Log warn
void warn(Throwable error);
From source file:org.bytedeco.javacpp.tools.BuildMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException { final Log log = getLog(); try {/* w ww . j a v a2 s . c o m*/ if (log.isDebugEnabled()) { log.debug("classPath: " + classPath); log.debug("classPaths: " + Arrays.deepToString(classPaths)); log.debug("includePath: " + includePath); log.debug("includePaths: " + Arrays.deepToString(includePaths)); log.debug("linkPath: " + linkPath); log.debug("linkPaths: " + Arrays.deepToString(linkPaths)); log.debug("preloadPath: " + preloadPath); log.debug("preloadPaths: " + Arrays.deepToString(preloadPaths)); log.debug("outputDirectory: " + outputDirectory); log.debug("outputName: " + outputName); log.debug("compile: " + compile); log.debug("deleteJniFiles: " + deleteJniFiles); log.debug("header: " + header); log.debug("copyLibs: " + copyLibs); log.debug("jarPrefix: " + jarPrefix); log.debug("properties: " + properties); log.debug("propertyFile: " + propertyFile); log.debug("propertyKeysAndValues: " + propertyKeysAndValues); log.debug("classOrPackageName: " + classOrPackageName); log.debug("classOrPackageNames: " + Arrays.deepToString(classOrPackageNames)); log.debug("environmentVariables: " + environmentVariables); log.debug("compilerOptions: " + Arrays.deepToString(compilerOptions)); log.debug("skip: " + skip); } if (skip) { log.info("Skipping execution of JavaCPP Builder"); return; } classPaths = merge(classPaths, classPath); classOrPackageNames = merge(classOrPackageNames, classOrPackageName); Logger logger = new Logger() { @Override public void debug(String s) { log.debug(s); } @Override public void info(String s) { log.info(s); } @Override public void warn(String s) { log.warn(s); } @Override public void error(String s) { log.error(s); } }; Builder builder = new Builder(logger).classPaths(classPaths).outputDirectory(outputDirectory) .outputName(outputName).compile(compile).deleteJniFiles(deleteJniFiles).header(header) .copyLibs(copyLibs).jarPrefix(jarPrefix).properties(properties).propertyFile(propertyFile) .properties(propertyKeysAndValues).classesOrPackages(classOrPackageNames) .environmentVariables(environmentVariables).compilerOptions(compilerOptions); Properties properties = builder.properties; log.info("Detected platform \"" + Loader.getPlatform() + "\""); log.info("Building for platform \"" + properties.get("platform") + "\""); String separator = properties.getProperty("platform.path.separator"); for (String s : merge(includePaths, includePath)) { String v = properties.getProperty("platform.includepath", ""); properties.setProperty("platform.includepath", v.length() == 0 || v.endsWith(separator) ? v + s : v + separator + s); } for (String s : merge(linkPaths, linkPath)) { String v = properties.getProperty("platform.linkpath", ""); properties.setProperty("platform.linkpath", v.length() == 0 || v.endsWith(separator) ? v + s : v + separator + s); } for (String s : merge(preloadPaths, preloadPath)) { String v = properties.getProperty("platform.preloadpath", ""); properties.setProperty("platform.preloadpath", v.length() == 0 || v.endsWith(separator) ? v + s : v + separator + s); } Properties projectProperties = project.getProperties(); for (String key : properties.stringPropertyNames()) { projectProperties.setProperty("javacpp." + key, properties.getProperty(key)); } File[] outputFiles = builder.build(); if (log.isDebugEnabled()) { log.debug("outputFiles: " + Arrays.deepToString(outputFiles)); } } catch (IOException | ClassNotFoundException | NoClassDefFoundError | InterruptedException | ParserException e) { log.error("Failed to execute JavaCPP Builder: " + e.getMessage()); throw new MojoExecutionException("Failed to execute JavaCPP Builder", e); } }
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);//w w w . j a v a2 s . com } else if (level == LEVEL_INFO) { log.info(message); } 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
/** * Stops the Cassandra service./*from ww w . java2 s . co m*/ * * @param rpcAddress The rpcAddress to connect to in order to see if Cassandra has stopped. * @param rpcPort The rpcPort to connect on to check if Cassandra has stopped. * @param stopPort The port to stop on. * @param stopKey The key to stop with, * @param log The log to write to. */ static void stopCassandraServer(String rpcAddress, int rpcPort, String stopAddress, int stopPort, String stopKey, Log log) { try { Socket s = new Socket(InetAddress.getByName(stopAddress), stopPort); s.setSoLinger(false, 0); OutputStream out = s.getOutputStream(); out.write((stopKey + "\r\nstop\r\n").getBytes()); out.flush(); s.close(); } catch (ConnectException e) { log.info("Cassandra not running!"); return; } catch (Exception e) { log.error(e); return; } log.info("Waiting for Cassandra to stop..."); long maxWaiting = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(30); boolean stopped = false; while (!stopped && System.currentTimeMillis() < maxWaiting) { TTransport tr = new TFramedTransport(new TSocket(rpcAddress, rpcPort)); try { TProtocol proto = new TBinaryProtocol(tr); Cassandra.Client client = new Cassandra.Client(proto); try { tr.open(); } catch (TTransportException e) { if (e.getCause() instanceof ConnectException) { stopped = true; continue; } log.debug(e.getLocalizedMessage(), e); try { Thread.sleep(500); } catch (InterruptedException e1) { // ignore } } } finally { if (tr.isOpen()) { tr.close(); } } } if (stopped) { log.info("Cassandra has stopped."); } else { log.warn("Gave up waiting for Cassandra to stop."); } }
From source file:org.codehaus.mojo.jalopy.JalopyMojo.java
License:Apache License
private void logMessage(Jalopy jalopy, File currentFile) throws MojoExecutionException { Log log = getLog(); if (jalopy.getState() == Jalopy.State.OK) { log.info(currentFile + " formatted correctly."); } else if (jalopy.getState() == Jalopy.State.WARN) { log.warn(currentFile + " formatted with warnings."); } else if (jalopy.getState() == Jalopy.State.ERROR) { log.error(currentFile + " could not be formatted."); if (isFailOnError()) { throw new MojoExecutionException(currentFile + " could not be formatted."); }/*w w w . j av a 2s . c om*/ } else { log.info(currentFile + " formatted with unknown state."); } }
From source file:org.codehaus.mojo.javascript.titanium.TitaniumBuilder.java
License:Open Source License
/** * Launch the specified titanium project on an iOs device. * @param iosVersion The iOS version to use to build the application. * @param tiProjectDirectory The titanium project directory. * @param appId The titanium application identifier. * @param projectName The project name.//from ww w .ja va 2 s. com * @param appuuid The project uuid * @param distName The project dist name. * @param family The family to use when building the project. * @param log The Maven logger. * @throws MojoFailureException When the builder process return an error. * @throws MojoExecutionException When an error occured while launching on the device. */ public void launchIphoneDevice(String iosVersion, File tiProjectDirectory, String appId, String projectName, String appuuid, String distName, String family, Log log) throws MojoExecutionException, MojoFailureException { if (iosBuilder == null) { throw new MojoExecutionException("Unable to retrieve the iphone builder"); } ProcessBuilder pb = new ProcessBuilder(iosBuilder.getAbsolutePath(), "install", iosVersion, tiProjectDirectory.getAbsolutePath(), appId, projectName, appuuid, distName, family); // The first call may fail log.info("ProcessBuilder: " + getProcessBuilderString(pb)); boolean relaunch = false; int result; try { StringBuilder logContent = new StringBuilder(); Process p = pb.start(); TitaniumBuilder.logProcess(p, log, logContent, false); p.waitFor(); result = p.exitValue(); if (failOnTiapp(tiProjectDirectory.getAbsolutePath(), logContent.toString())) { relaunch = true; } } catch (Throwable t) { throw new MojoExecutionException("Error while building iphone", t); } if (relaunch) { log.warn("Relaunching builder as it failed on missing tiapp.xml"); try { Process p = pb.start(); TitaniumBuilder.logProcess(p, log); p.waitFor(); result = p.exitValue(); } catch (Throwable t) { throw new MojoExecutionException("Error while building iphone", t); } } if (result != 0) { throw new MojoFailureException("The titanium builder failed"); } }
From source file:org.codehaus.mojo.javascript.titanium.TitaniumBuilder.java
License:Open Source License
/** * Launch a titanium project on an iOs simulator. * @param iosVersion The ios version to use to build the application. * @param tiProjectDirectory The titanium project directory. * @param projectName The name of the project. * @param family The family to use to build the application. * @param simulatorFamily family The family of the simulator ("universal" translates to "iphone"). * @param log The maven logger.//ww w. ja v a 2 s . c om * @throws MojoFailureException When the builder process return an error. * @throws MojoExecutionException When an error occurs during the simulator process. */ public void launchIphoneEmulator(String iosVersion, String tiProjectDirectory, String projectName, String family, String simulatorFamily, Log log) throws MojoFailureException, MojoExecutionException { if (iosBuilder == null) { throw new MojoExecutionException("Unable to retrieve the iphone builder"); } ProcessBuilder pb = new ProcessBuilder(iosBuilder.getAbsolutePath(), "simulator", iosVersion, tiProjectDirectory, "appid", //project.getGroupId() + "." + project.getArtifactId(), projectName, family, simulatorFamily); //pb.directory(tiProjectDir); // The first call may fail log.info("ProcessBuilder: " + getProcessBuilderString(pb)); boolean relaunch = false; int result; try { StringBuilder logContent = new StringBuilder(); Process p = pb.start(); TitaniumBuilder.logProcess(p, log, logContent, false); p.waitFor(); result = p.exitValue(); if (failOnTiapp(tiProjectDirectory, logContent.toString())) { relaunch = true; } } catch (Throwable t) { throw new MojoExecutionException("Error while building iphone", t); } if (relaunch) { log.warn("Relaunching builder as it failed on missing tiapp.xml"); try { Process p = pb.start(); TitaniumBuilder.logProcess(p, log); p.waitFor(); result = p.exitValue(); } catch (Throwable t) { throw new MojoExecutionException("Error while building iphone", t); } } if (result != 0) { throw new MojoFailureException("The titanium build failed"); } }
From source file:org.codehaus.mojo.javascript.titanium.TitaniumBuilder.java
License:Open Source License
/** * Launch the titanium ios builder distribute command and log its output. * @param iosVersion The ios version.//ww w . j ava 2 s. c om * @param tiProjectDirectory The titanium project directory. * @param appId The application identifier. * @param projectName The project name. * @param appuuid The application uuid. * @param distName The distribution name. * @param targetDir The folder where the resulting file will be created. * @param family The device family. * @param log The maven logger. * @throws MojoFailureException When the builder process return an error. * @throws MojoExecutionException When an error occurs while creating the distribution. */ public void launchIphoneDistribute(String iosVersion, File tiProjectDirectory, String appId, String projectName, String appuuid, String distName, File targetDir, String family, Log log) throws MojoExecutionException, MojoFailureException { if (iosBuilder == null) { throw new MojoExecutionException("Unable to retrieve the iphone builder"); } log.info("iphoneBuilder: " + iosBuilder.getAbsolutePath()); targetDir.mkdirs(); ProcessBuilder pb = new ProcessBuilder(iosBuilder.getAbsolutePath(), "distribute", iosVersion, tiProjectDirectory.getAbsolutePath(), appId, projectName, appuuid, distName, targetDir.getAbsolutePath(), family).redirectErrorStream(true); log.info("ProcessBuilder: " + getProcessBuilderString(pb)); boolean relaunch = false; int result; try { StringBuilder logContent = new StringBuilder(); Process p = pb.start(); TitaniumBuilder.logProcess(p, log, logContent, true); p.waitFor(); result = p.exitValue(); if (failOnTiapp(tiProjectDirectory.getAbsolutePath(), logContent.toString())) { relaunch = true; } } catch (Throwable t) { throw new MojoExecutionException("Error while building iphone", t); } if (relaunch) { log.warn("Relaunching builder as it failed on missing tiapp.xml"); try { Process p = pb.start(); TitaniumBuilder.logProcess(p, log, null, true); p.waitFor(); result = p.exitValue(); } catch (Throwable t) { throw new MojoExecutionException("Error while building iphone", t); } } if (result != 0) { throw new MojoFailureException("The titanium builder failed"); } }
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./*from w w w.j a v a 2s . 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.schemageneration.XsdGeneratorHelper.java
License:Apache License
/** * Inserts XML documentation annotations into all generated XSD files found * within the supplied outputDir.//from w ww . j a v a 2 s . co m * * @param log A Maven Log. * @param outputDir The outputDir, where generated XSD files are found. * @param docs The SearchableDocumentation for the source files within the compilation unit. * @param renderer The JavaDocRenderer used to convert JavaDoc annotations into XML documentation annotations. * @return The number of processed XSDs. */ public static int insertJavaDocAsAnnotations(final Log log, final File outputDir, final SearchableDocumentation docs, final JavaDocRenderer renderer) { // Check sanity Validate.notNull(docs, "docs"); Validate.notNull(log, "log"); Validate.notNull(outputDir, "outputDir"); Validate.isTrue(outputDir.isDirectory(), "'outputDir' must be a Directory."); Validate.notNull(renderer, "renderer"); int processedXSDs = 0; final List<File> foundFiles = new ArrayList<File>(); addRecursively(foundFiles, RECURSIVE_XSD_FILTER, outputDir); if (foundFiles.size() > 0) { // Create the processors. final XsdAnnotationProcessor classProcessor = new XsdAnnotationProcessor(docs, renderer); final XsdEnumerationAnnotationProcessor enumProcessor = new XsdEnumerationAnnotationProcessor(docs, renderer); for (File current : foundFiles) { // Create an XSD document from the current File. final Document generatedSchemaFileDocument = parseXmlToDocument(current); // Replace all namespace prefixes within the provided document. process(generatedSchemaFileDocument.getFirstChild(), true, classProcessor); processedXSDs++; // Overwrite the vanilla file. savePrettyPrintedDocument(generatedSchemaFileDocument, current); } } else { if (log.isWarnEnabled()) { log.warn("Found no generated 'vanilla' XSD files to process under [" + FileSystemUtilities.getCanonicalPath(outputDir) + "]. Aborting processing."); } } // All done. return processedXSDs; }
From source file:org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper.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. * * @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. *//*from ww w .ja v a2 s . c o m*/ 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 localNamespaceURI = currentResolver.getLocalNamespaceURI(); if (StringUtils.isEmpty(localNamespaceURI)) { mavenLog.warn("SimpleNamespaceResolver contained no localNamespaceURI; aborting rename."); continue; } final String newFilename = namespaceUriToDesiredFilenameMap.get(localNamespaceURI); 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); } } } }