List of usage examples for org.apache.maven.plugin.logging Log warn
void warn(Throwable error);
From source file:com.anuta.internal.YangHelperMojo.java
License:Open Source License
private Properties readFileHashCacheFile() { Properties props = new Properties(); Log log = getLog(); if (!targetDirectory.exists()) { targetDirectory.mkdirs();//from www. j ava 2 s. co m } else if (!targetDirectory.isDirectory()) { log.warn("Something strange here as the " + "supposedly target directory is not a directory."); return props; } String cacheFileName = getCacheFile(); if (null == cacheFileName) { return null; } File cacheFile = new File(targetDirectory, cacheFileName); if (!cacheFile.exists()) { return props; } try { props.load(new BufferedInputStream(new FileInputStream(cacheFile))); } catch (FileNotFoundException e) { log.warn("Cannot load file hash cache properties file", e); } catch (IOException e) { log.warn("Cannot load file hash cache properties file", e); } return props; }
From source file:com.buisonje.AutoProxyMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException { final Log mojoLog = getLog(); ProxySelector myProxySelector = null; if (isProxyDetectionAlreadyAttempted()) { mojoLog.info("Proxy server detection already attempted in this session. Reapplying result(s)..."); myProxySelector = (ProxySelector) session.getSystemProperties().get(PROXY_SELECTOR_KEY); } else {/* w w w . j ava 2s.co m*/ showMavenProxySettings(mojoLog); // showCurrentSystemWideProxiesInfo(mojoLog); mojoLog.info("Autodetecting system proxy server(s)..."); myProxySelector = autodetectProxySettings(mojoLog); session.getSystemProperties().put(PROXY_DETECTION_TIME_KEY, new Date()); } if (myProxySelector == null) { mojoLog.warn("Could not detect proxy server(s) automatically. Falling back to the initial settings..."); } else { session.getSystemProperties().put(PROXY_SELECTOR_KEY, myProxySelector); /* * NOTE: It seems that Maven either ignores the system-wide * (default) {@link ProxySelector} entirely, or doesn't update it * with the initial proxy settings until it actually starts * downloading something. Either way, replacing the default {@link * ProxySelector} might therefore be pointless here. But it * shouldn't hurt, either. */ ProxySelector.setDefault(myProxySelector); mojoLog.info("Detected available proxy server(s) for HTTP connections:"); List<Proxy> detectedAvailableProxies = getAvailableProxies(myProxySelector); showAvailableProxies(mojoLog, detectedAvailableProxies); Proxy firstDetectedAvailableProxy = detectedAvailableProxies.get(0); mojoLog.info( String.format("Overriding Maven proxy settings with the first detected available proxy (%s)...", firstDetectedAvailableProxy.address().toString())); overrideMavenProxySettings(firstDetectedAvailableProxy, mojoLog); } }
From source file:com.carrotgarden.maven.aws.util.Util.java
License:BSD License
public static long safeNumber(final Log log, final String numberText, final long numberDefault) { try {/* w w w.j a v a 2 s . c om*/ return Long.parseLong(numberText); } catch (final Throwable e) { log.warn("using numberDefault=" + numberDefault); return numberDefault; } }
From source file:com.caucho.maven.MavenCopyTag.java
License:Open Source License
/** * Executes the maven resin:run task/*from ww w . ja v a2 s . co m*/ */ @Override protected void doTask(WebAppDeployClient client) throws MojoExecutionException { Log log = getLog(); CommitBuilder tag = null; //_tag; CommitBuilder sourceTag = null; // _sourceTag; if (tag == null) tag = buildVersionedWarTag(); if (sourceTag == null) { sourceTag = new CommitBuilder(); sourceTag.type("webapp"); sourceTag.stage(_sourceStage); sourceTag.tagKey(_sourceVirtualHost + _sourceContextRoot); // _sourceVersion); } log.info("Copying " + sourceTag + " to " + tag); boolean result = client.copyTag(tag, sourceTag); if (!result) log.warn("Failed to copy " + sourceTag + " to " + tag); }
From source file:com.caucho.maven.MavenDeleteTag.java
License:Open Source License
/** * Executes the maven resin:run task//from w w w. ja v a 2 s . c o m */ @Override protected void doTask(WebAppDeployClient client) throws MojoExecutionException { Log log = getLog(); CommitBuilder tag = null; // = _tag; if (tag == null) tag = buildVersionedWarTag(); log.info("Deleting tag " + tag); if (!client.removeTag(tag)) log.warn("Failed to delete tag " + tag); }
From source file:com.codecrate.webstart.AntToMavenLogger.java
License:Apache License
private void log(BuildEvent event) { int priority = event.getPriority(); Log log = mojo.getLog(); switch (priority) { case Project.MSG_ERR: log.error(event.getMessage());//from www . j av a 2 s. c om break; case Project.MSG_WARN: log.warn(event.getMessage()); break; case Project.MSG_INFO: log.info(event.getMessage()); break; case Project.MSG_VERBOSE: log.debug(event.getMessage()); break; case Project.MSG_DEBUG: log.debug(event.getMessage()); break; default: log.info(event.getMessage()); break; } }
From source file:com.collaborne.jsonschema.validator.plugin.ValidateMojo.java
License:Apache License
@VisibleForTesting protected void log(String filename, ProcessingMessage message) { // FIXME: #getMessage() is ok, but ideally we also need the other key/value pairs. // Doing that would require knowing that "message" is the one holding the message // itself. StringBuilder logMessageBuilder = new StringBuilder(); logMessageBuilder.append(filename);/*from w w w .ja v a2 s . c om*/ logMessageBuilder.append(": "); logMessageBuilder.append(message.getMessage()); String logMessage = logMessageBuilder.toString(); Log log = getLog(); switch (message.getLogLevel()) { case NONE: // XXX: Do nothing? break; case DEBUG: log.debug(logMessage); break; case INFO: log.info(logMessage); break; case WARNING: log.warn(logMessage); break; case ERROR: case FATAL: log.error(logMessage); break; } }
From source file:com.dev9.mvnwatcher.WatcherMojo.java
License:Apache License
public void execute() throws MojoExecutionException { Log log = getLog(); if (!basedir.exists()) { throw new MojoExecutionException("Can't find project directory " + basedir); }//from w w w . java 2 s .c o m if (!sourceDirectory.exists()) { throw new MojoExecutionException("Can't find source directory " + sourceDirectory); } else { log.info("Found: " + sourceDirectory.getAbsolutePath()); } if (resourcesDirectory != null) { if (!resourcesDirectory.exists()) { log.warn("Can't find resources directory " + resourcesDirectory); } else { log.info("Found: " + resourcesDirectory.getAbsolutePath()); } } else { log.warn("No resources directory specified."); } createTargetDirectoryIfNotExists(); MvnWatcher runner = null; try { if (tasks == null) tasks = getDefaultTasks(basedir.toPath()); List<Path> directoriesToWatch = new ArrayList<>(); directoriesToWatch.add(sourceDirectory.toPath()); directoriesToWatch.add(resourcesDirectory.toPath()); runner = new MvnWatcher(directoriesToWatch, basedir.toPath(), directory.toPath(), tasks); runner.startUpWatcher(); runner.terminate = terminate; } catch (IOException e) { e.printStackTrace(); } if (runner != null) runner.waitForCancel(); }
From source file:com.edugility.jpa.maven.plugin.ListEntityClassnamesMojo.java
License:Open Source License
/** * Returns a {@link Set} of {@link URL}s that represents the test * classpath./*ww w . j av a 2s . c o m*/ * * <p>This uses the {@linkplain #getProject() associated * <tt>MavenProject</tt>} to {@linkplain * MavenProject#getTestClasspathElements() supply the information}. * If that {@link MavenProject} is {@code null}, then an {@linkplain * Collection#isEmpty() empty} {@linkplain * Collections#unmodifiableSet(Set) unmodifiable <tt>Set</tt>} is * returned.</p> * * <p>{@link String}-to-{@link URL} conversion is accomplished like * this:</p> * * <ul> * * <li>The {@link MavenProject#getTestClasspathElements()} method * returns an untyped {@link List}. There is no contractual * guarantee about the type of its contents. Each element is * therefore treated as an {@link Object}.</li> * * <li>If the element is non-{@code null}, then its {@link * Object#toString()} method is invoked. The resulting {@link * String} is used to {@linkplain File#File(String) construct a * <tt>File</tt>}.</li> * * <li>The resulting {@link File}'s {@link File#toURI()} method is * invoked and the {@linkplain URI result}'s {@link URI#toURL()} * method is invoked. The return value is added to the {@link Set} * that will be returned.</li> * * </ul> * * <p>This method never returns {@code null}.</p> * * @return a {@link Set} of {@link URL}s representing the test * classpath, never {@code null}. The {@link Set}'s iteration order * is guaranteed to be equal to that of the iteration order of the * return value of the {@link * MavenProject#getTestClasspathElements()} method. * * @exception DependencyResolutionRequiredException if the {@link * MavenProject#getTestClasspathElements()} method throws a {@link * DependencyResolutionRequiredException} */ private final Set<URL> getTestClasspathURLs() throws DependencyResolutionRequiredException { final Set<URL> urls; final Log log = this.getLog(); assert log != null; final MavenProject project = this.getProject(); final List<?> classpathElements; if (project == null) { classpathElements = null; } else { classpathElements = project.getTestClasspathElements(); } if (classpathElements == null || classpathElements.isEmpty()) { if (log.isWarnEnabled()) { log.warn(String .format("The test classpath contained no elements. Consequently no Entities were found.")); } urls = Collections.emptySet(); } else { final Set<URL> mutableUrls = new LinkedHashSet<URL>(classpathElements.size()); for (final Object o : classpathElements) { if (o != null) { final File file = new File(o.toString()); if (file.canRead()) { try { mutableUrls.add(file.toURI().toURL()); } catch (final MalformedURLException wontHappen) { throw (InternalError) new InternalError(String.format( "While attempting to convert a file, %s, into a URL, a MalformedURLException was encountered.", file)).initCause(wontHappen); } } else if (log.isWarnEnabled()) { log.warn(String.format("The test classpath element %s could not be read.", file)); } } } if (mutableUrls.isEmpty()) { urls = Collections.emptySet(); } else { urls = Collections.unmodifiableSet(mutableUrls); } } if (log.isWarnEnabled() && urls.isEmpty()) { log.warn(String.format("No URLs were found from the test classpath (%s).", classpathElements)); } return urls; }
From source file:com.edugility.jpa.maven.plugin.ListEntityClassnamesMojo.java
License:Open Source License
/** * Executes this mojo.//w w w. j a va 2 s . co m * * @exception MojoExecutionException if this mojo could not be executed * * @exception MojoFailureException if the build should fail */ @Override public void execute() throws MojoExecutionException, MojoFailureException { final Log log = this.getLog(); if (log == null) { throw new MojoExecutionException("this.getLog() == null"); } try { this.initialize(); } catch (final DependencyResolutionRequiredException kaboom) { throw new MojoExecutionException(String.format( "Dependencies of the current Maven project could not be downloaded during initialization of the jpa-maven-plugin."), kaboom); } catch (final NotWritableDirectoryException kaboom) { throw new MojoExecutionException(String.format( "The output directory path, %s, exists and is a directory, but the current user, %s, cannot write to it.", kaboom.getFile(), System.getProperty("user.name")), kaboom); } catch (final NotWritableFileException kaboom) { throw new MojoExecutionException(String.format( "The outputFile specified, %s, is a regular file, but cannot be written to by Maven running as user %s. The outputFile parameter must designate either an existing, writable file or a non-existent file.", outputFile, System.getProperty("user.name")), kaboom); } catch (final NotNormalFileException kaboom) { throw new MojoExecutionException(String.format( "The outputFile specified, %s, is not a directory, but is also not a normal file. The outputFile parameter must deisgnate either an existing, writable, normal file or a non-existent file.", outputFile), kaboom); } catch (final NotDirectoryException kaboom) { throw new MojoExecutionException(String.format( "The output directory path, %s, exists but is not a directory.", kaboom.getFile()), kaboom); } catch (final PathCreationFailedException kaboom) { throw new MojoExecutionException( String.format("Some portion of the output directory path, %s, could not be created.", kaboom.getFile()), kaboom); } catch (final FileException other) { throw new MojoExecutionException("An unexpected FileException occurred during initialization.", other); } // Scan the test classpath for Entity, MappedSuperclass, IdClass, // Embeddable, etc. annotations. final AnnotationDB db; AnnotationDB tempDb = null; try { tempDb = this.scan(); } catch (final IOException kaboom) { throw new MojoExecutionException( "Execution failed because an IOException was encountered during URL scanning.", kaboom); } finally { db = tempDb; tempDb = null; } assert db != null; if (log.isDebugEnabled()) { log.debug("Annotation index:"); final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); db.outputAnnotationIndex(pw); log.debug(sw.toString()); try { sw.close(); } catch (final IOException ignored) { // ignored on purpose } pw.close(); } final Properties properties = new Properties(); // Having scanned the classpaths, get the "index", which is a Map // of classnames indexed by annotation classnames. final Map<String, Set<String>> ai = db.getAnnotationIndex(); if (ai == null) { if (log.isWarnEnabled()) { log.warn("After scanning for Entities, a null annotation index was returned by the AnnotationDB."); } } else if (ai.isEmpty()) { if (log.isWarnEnabled()) { log.warn("After scanning for Entities, no annotated Entities were found."); } } else { final Map<String, Set<String>> propertyNameIndex = new HashMap<String, Set<String>>(); // For each of the annotations we are interested in, do some // work on the classes that sport those annotations. for (final String jpaAnnotation : JPA_ANNOTATIONS) { // Find all classnames annotated with that annotation // (e.g. @Entity, @MappedSuperclass, etc.). final Set<String> annotatedClassNames = ai.get(jpaAnnotation); if (annotatedClassNames != null && !annotatedClassNames.isEmpty()) { for (final String annotatedClassName : annotatedClassNames) { assert annotatedClassName != null; // For every classname we find, see which property name it // is going to be assigned to. For example, we might be // configured so that com.foobar.* get assigned to the // foobarClassnames property. final String propertyName = this.determinePropertyName(annotatedClassName); assert propertyName != null; Set<String> relevantClassNames = propertyNameIndex.get(propertyName); if (relevantClassNames == null) { relevantClassNames = new TreeSet<String>(); propertyNameIndex.put(propertyName, relevantClassNames); } assert relevantClassNames != null; // Add the annotated class to the set of other annotated // classnames stored under that property. relevantClassNames.add(annotatedClassName); } } } final Set<Entry<String, Set<String>>> entrySet = propertyNameIndex.entrySet(); assert entrySet != null; if (!entrySet.isEmpty()) { final String firstItemPrefix = this.getFirstItemPrefix(); final String prefix = this.getPrefix(); final String suffix = this.getSuffix(); final String lastItemSuffix = this.getLastItemSuffix(); for (final Entry<String, Set<String>> entry : entrySet) { assert entry != null; // For every entry indexing a set of classes under a property // name, stringify the set of classnames into a single // StringBuilder. Index that stringified set under the // property name. This Properties will be the contents of our file. final StringBuilder sb = new StringBuilder(); final String propertyName = entry.getKey(); assert propertyName != null; final Set<String> classNames = entry.getValue(); assert classNames != null; assert !classNames.isEmpty(); final Iterator<String> classNamesIterator = classNames.iterator(); assert classNamesIterator != null; assert classNamesIterator.hasNext(); while (classNamesIterator.hasNext()) { sb.append(this.decorate(classNamesIterator.next(), sb.length() <= 0 ? firstItemPrefix : prefix, classNamesIterator.hasNext() ? suffix : lastItemSuffix)); } properties.setProperty(propertyName, sb.toString()); } } } if (log.isDebugEnabled()) { final Enumeration<?> propertyNames = properties.propertyNames(); if (propertyNames != null) { while (propertyNames.hasMoreElements()) { final Object nextElement = propertyNames.nextElement(); if (nextElement != null) { final String key = nextElement.toString(); assert key != null; final String value = properties.getProperty(key); log.debug(String.format("%s = %s", key, value)); } } } } final MavenProject project = this.getProject(); if (project != null) { final Properties projectProperties = project.getProperties(); if (projectProperties != null) { @SuppressWarnings("unchecked") final Enumeration<String> propertyNames = (Enumeration<String>) properties.propertyNames(); if (propertyNames != null && propertyNames.hasMoreElements()) { while (propertyNames.hasMoreElements()) { final String propertyName = propertyNames.nextElement(); if (propertyName != null) { projectProperties.setProperty(propertyName, properties.getProperty(propertyName)); } } } } } if (this.getUseOutputFile()) { final File outputFile = this.getOutputFile(); if (outputFile != null) { assert outputFile.exists() ? outputFile.isFile() : true; assert outputFile.getParentFile() != null; assert outputFile.getParentFile().isDirectory(); assert outputFile.getParentFile().canWrite(); assert !outputFile.exists() ? outputFile.getParentFile().canWrite() : true; // Prepare to write. Get the character encoding, accounting for // possible null return values from an overridden getEncoding() // method. String encoding = this.getEncoding(); if (encoding == null) { encoding = ""; } else { encoding = encoding.trim(); } if (encoding.isEmpty()) { encoding = "UTF8"; } // Set up the Writer to point to the outputFile and have the // Properties store itself there. Writer writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), encoding)); properties.store(writer, "Generated by " + this.getClass().getName()); writer.flush(); } catch (final IOException kaboom) { throw new MojoExecutionException(String.format( "While attempting to write to the outputFile parameter (%s), an IOException was encountered.", outputFile), kaboom); } finally { if (writer != null) { try { writer.close(); } catch (final IOException ignore) { // ignored on purpose } } } } } }