List of usage examples for org.apache.maven.plugin.logging Log error
void error(CharSequence content, Throwable error);
From source file:de.taimos.dvalin.interconnect.model.maven.GeneratorHelper.java
License:Apache License
static void writeFile(Log log, VelocityContext context, String templateName, String pkgName, String clazzName, String outputDirectory, String targetDir) throws MojoExecutionException { Template template = null;//ww w . j a v a2 s .co m try { template = Velocity.getTemplate(templateName, "UTF-8"); } catch (Exception e) { log.error("Failed to retrieve Template " + templateName, e); throw new MojoExecutionException("Failed to retrieve Template " + templateName, e); } try { File pckDir = new File(outputDirectory + targetDir + pkgName.replace('.', '/')); if (!pckDir.exists()) { pckDir.mkdirs(); } try (OutputStreamWriter fw = new OutputStreamWriter( new FileOutputStream( outputDirectory + targetDir + pkgName.replace('.', '/') + "/" + clazzName + ".java"), "UTF-8")) { template.merge(context, fw); } } catch (IOException e) { log.error("Failed to write the generated file " + clazzName, e); throw new MojoExecutionException("Failed to write the generated file " + clazzName, e); } }
From source file:de.taimos.dvalin.interconnect.model.maven.GeneratorHelper.java
License:Apache License
@SuppressWarnings("unchecked") static <T> T parseXML(Class<T> clazz, Log log, File f) throws MojoExecutionException { try {// ww w . ja v a 2 s. com JAXBContext jcontext = JAXBContext.newInstance(clazz); return (T) jcontext.createUnmarshaller().unmarshal(f); } catch (Exception e) { log.error("Failed to read input file " + f.getAbsolutePath(), e); throw new MojoExecutionException("Failed to read input file " + f.getAbsolutePath(), e); } }
From source file:fr.jetoile.hadoopunit.HadoopBootstrapRemoteUtils.java
License:Apache License
public void tailLogFileUntilFind(Path hadoopLogFilePath, String find, Log log) { try {/* w ww .j av a 2 s . c o m*/ BufferedReader reader = new BufferedReader(new FileReader(hadoopLogFilePath.toFile())); String line; boolean keepReading = true; while (keepReading) { line = reader.readLine(); if (line == null) { //wait until there is more of the file for us to read Thread.sleep(1000); } else { keepReading = !StringUtils.containsIgnoreCase(line, find); //do something interesting with the line } } } catch (IOException | InterruptedException e) { log.error("unable to read wrapper.log file", e); } }
From source file:fr.synchrotron.soleil.ica.ci.maven.plugins.soleildependency.util.DependencyUtil.java
License:Apache License
/** * Writes the specified string to the specified file. * * @param string the string to write//from ww w .j a v a 2 s . c om * @param file the file to write to * @throws IOException if an I/O error occurs */ public synchronized static void write(String string, File file, Log log) throws IOException { file.getParentFile().mkdirs(); FileWriter writer = null; try { writer = new FileWriter(file); writer.write(string); } finally { if (writer != null) { try { writer.close(); } catch (IOException exception) { log.error("Cannot close file", exception); } } } }
From source file:ibeam.maven.plugins.Tools.java
License:Apache License
/** * Deletes a directory and all sub-file or directories, never throwing an exception. * If deleteOnExistMode option is activated, the deletion will be attempted only for normal termination of the virtual machine. * A directory to be deleted does not have to be empty. No exceptions are thrown when a file or directory cannot be deleted. * /* w ww.ja v a 2 s .c om*/ * @param file * @param deleteOnExistMode * @param log */ public static void deleteFolderQuietly(final File file, final boolean deleteOnExistMode, final Log log) { try { if (file.exists()) { final Collection<File> files = listFilesAndFolders(file); deleteFileCollectionQuietly(files, deleteOnExistMode, log); } } catch (Exception e) { log.error(Enumeres.EXCEPTION.FILE_DELETION_EXCEPTION + file, e); } }
From source file:ibeam.maven.plugins.Tools.java
License:Apache License
/** * Deletes a file (or a directory), never throwing an exception. * If deleteOnExistMode option is activated, the deletion will be attempted only for normal termination of the virtual machine. * A directory to be deleted does not have to be empty. No exceptions are thrown when a file or directory cannot be deleted. * // w w w . j a v a 2s . c o m * @param file * @param deleteOnExistMode * @param log */ public static void deleteQuietly(final File file, final boolean deleteOnExistMode, final Log log) { try { if (deleteOnExistMode) { file.deleteOnExit(); } else { FileUtils.deleteQuietly(file); } } catch (SecurityException e) { log.error(Enumeres.EXCEPTION.FILE_DELETION_EXCEPTION + file, e); } }
From source file:io.fabric8.vertx.maven.plugin.utils.WebJars.java
License:Apache License
/** * Checks whether the given file is a WebJar or not (http://www.webjars.org/documentation). * The check is based on the presence of {@literal META-INF/resources/webjars/} directory in the jar file. * * @param file the file./* w w w .j a v a 2 s . c om*/ * @return {@literal true} if it's a bundle, {@literal false} otherwise. */ public static boolean isWebJar(Log log, File file) { if (file == null) { return false; } Set<String> found = new LinkedHashSet<>(); if (file.isFile() && file.getName().endsWith(".jar")) { JarFile jar = null; try { jar = new JarFile(file); // Fast return if the base structure is not there if (jar.getEntry(WEBJAR_LOCATION) == null) { return false; } Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); Matcher matcher = WEBJAR_REGEX.matcher(entry.getName()); if (matcher.matches()) { found.add(matcher.group(1) + "-" + matcher.group(2)); } } } catch (IOException e) { log.error("Cannot check if the file " + file.getName() + " is a webjar, cannot open it", e); return false; } finally { final JarFile finalJar = jar; IOUtils.closeQuietly(() -> { if (finalJar != null) { finalJar.close(); } }); } for (String lib : found) { log.info("Web Library found in " + file.getName() + " : " + lib); } return !found.isEmpty(); } return false; }
From source file:io.reactiverse.vertx.maven.plugin.utils.WebJars.java
License:Apache License
/** * Checks whether the given file is a WebJar or not (http://www.webjars.org/documentation). * The check is based on the presence of {@literal META-INF/resources/webjars/} directory in the jar file. * * @param file the file./*from ww w . ja v a 2 s . c om*/ * @return {@literal true} if it's a bundle, {@literal false} otherwise. */ public static boolean isWebJar(Log log, File file) { if (file == null) { return false; } Set<String> found = new LinkedHashSet<>(); if (file.isFile() && file.getName().endsWith(".jar")) { try (JarFile jar = new JarFile(file)) { // Fast return if the base structure is not there if (jar.getEntry(WEBJAR_LOCATION) == null) { return false; } Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); Matcher matcher = WEBJAR_REGEX.matcher(entry.getName()); if (matcher.matches()) { found.add(matcher.group(1) + "-" + matcher.group(2)); } } } catch (IOException e) { log.error("Cannot check if the file " + file.getName() + " is a webjar, cannot open it", e); return false; } for (String lib : found) { log.info("Web Library found in " + file.getName() + " : " + lib); } return !found.isEmpty(); } return false; }
From source file:nl.geodienstencentrum.maven.plugin.sass.AbstractSassMojo.java
License:Apache License
/** * Extract the Bourbon assets to the build directory. * @param destinationDir directory for the Bourbon resources *///from ww w . jav a 2 s . c o m private void extractBourbonResources(String destinationDir) { final Log log = this.getLog(); try { File destDir = new File(destinationDir); if (destDir.isDirectory()) { // skip extracting Bourbon, as it seems to hav been done log.info("Bourbon resources seems to have been extracted before."); return; } log.info("Extracting Bourbon resources to: " + destinationDir); destDir.mkdirs(); // find the jar with the Bourbon directory in the classloader URL urlJar = this.getClass().getClassLoader().getResource("scss-report.xsl"); String resourceFilePath = urlJar.getFile(); int index = resourceFilePath.indexOf("!"); String jarFileURI = resourceFilePath.substring(0, index); File jarFile = new File(new URI(jarFileURI)); JarFile jar = new JarFile(jarFile); // extract app/assets/stylesheets to destinationDir for (Enumeration<JarEntry> enums = jar.entries(); enums.hasMoreElements();) { JarEntry entry = enums.nextElement(); if (entry.getName().contains("app/assets/stylesheets")) { // shorten the path a bit index = entry.getName().indexOf("app/assets/stylesheets"); String fileName = destinationDir + File.separator + entry.getName().substring(index); File f = new File(fileName); if (fileName.endsWith("/")) { f.mkdirs(); } else { FileOutputStream fos = new FileOutputStream(f); try { IOUtil.copy(jar.getInputStream(entry), fos); } finally { IOUtil.close(fos); } } } } } catch (IOException | URISyntaxException ex) { log.error("Error extracting Bourbon resources.", ex); } }
From source file:org.acmsl.queryj.tools.maven.AntProjectAdapter.java
License:Open Source License
/** * See {@link Project#log(String, Throwable, int)}. * @param message the message.// w w w . j a v a 2 s . c o m * @param throwable the error. * @param msgLevel either {@link Project#MSG_ERR}, {@link Project#MSG_WARN}, * {@link Project#MSG_INFO}, {@link Project#MSG_VERBOSE}, or {@link Project#MSG_DEBUG}. * @param log the {@link Log} instance. */ protected void log(@NotNull final String message, @NotNull final Throwable throwable, final int msgLevel, @NotNull final Log log) { switch (msgLevel) { case MSG_ERR: log.error(message, throwable); break; case MSG_WARN: log.warn(message, throwable); break; case MSG_VERBOSE: case MSG_DEBUG: log.debug(message, throwable); break; default: log.info(message, throwable); break; } }