List of usage examples for org.apache.maven.plugin.logging Log warn
void warn(Throwable error);
From source file:com.igormaznitsa.upom.UPomModel.java
License:Apache License
private static void duplicatedSiblingJanitor(final Log log, final Node node, final List<String> path) { if (node == null) { return;/*from ww w . ja v a2 s. c o m*/ } insideElementJanitor(log, node, path); Node sibling = nextSiblingElement(node); while (sibling != null) { insideElementJanitor(log, sibling, path); sibling = nextSiblingElement(sibling); } sibling = nextSiblingElement(node); while (sibling != null) { if (node.isEqualNode(sibling)) { path.add(node.getNodeName()); final Node deleting = sibling; sibling = nextSiblingElement(sibling); if (log != null) { log.warn("Removing duplicated element : " + pathToString(path)); } deleting.getParentNode().removeChild(deleting); path.remove(path.size() - 1); } else { sibling = nextSiblingElement(sibling); } } }
From source file:com.igormaznitsa.upom.UPomModel.java
License:Apache License
public String asXML(final Log log, final boolean removeDuplicatedSiblings) throws Exception { final MavenXpp3Writer mavenWritter = new MavenXpp3Writer(); final StringWriter buffer = new StringWriter(16384); mavenWritter.write(buffer, this.model); String result = buffer.toString(); if (removeDuplicatedSiblings) { if (log != null) { log.warn("Activated search and removing of duplicated sibling elements!"); }//from w w w.j av a 2 s .com result = findAndRemoveDuplicatedSiblings(log, result); } else if (log != null) { log.info("Search and removing of duplicated sibling elements is OFF"); } return result; }
From source file:com.mastfrog.maven.merge.configuration.MergeConfigurationMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { // XXX a LOT of duplicate code here Log log = super.getLog(); log.info("Merging properties files"); if (repoSession == null) { throw new MojoFailureException("RepositorySystemSession is null"); }/*from w w w . j a v a 2s.co m*/ List<File> jars = new ArrayList<>(); List<String> exclude = new LinkedList<>(); for (String ex : this.exclude.split(",")) { ex = ex.trim(); ex = ex.replace('.', '/'); exclude.add(ex); } try { DependencyResolutionResult result = resolver .resolve(new DefaultDependencyResolutionRequest(project, repoSession)); log.info("FOUND " + result.getDependencies().size() + " dependencies"); for (Dependency d : result.getDependencies()) { switch (d.getScope()) { case "test": case "provided": break; default: File f = d.getArtifact().getFile(); if (f.getName().endsWith(".jar") && f.isFile() && f.canRead()) { jars.add(f); } } } } catch (DependencyResolutionException ex) { throw new MojoExecutionException("Collecting dependencies failed", ex); } Map<String, Properties> m = new LinkedHashMap<>(); Map<String, Set<String>> linesForName = new LinkedHashMap<>(); Map<String, Integer> fileCountForName = new HashMap<>(); boolean buildMergedJar = mainClass != null && !"none".equals(mainClass); JarOutputStream jarOut = null; Set<String> seen = new HashSet<>(); try { if (buildMergedJar) { try { File outDir = new File(project.getBuild().getOutputDirectory()).getParentFile(); File jar = new File(outDir, project.getBuild().getFinalName() + ".jar"); if (!jar.exists()) { throw new MojoExecutionException("Could not find jar " + jar); } try (JarFile jf = new JarFile(jar)) { Manifest manifest = new Manifest(jf.getManifest()); if (mainClass != null) { manifest.getMainAttributes().putValue("Main-Class", mainClass); } String jn = jarName == null || "none".equals(jarName) ? strip(mainClass) : jarName; File outJar = new File(outDir, jn + ".jar"); log.info("Will build merged JAR " + outJar); if (outJar.equals(jar)) { throw new MojoExecutionException( "Merged jar and output jar are the same file: " + outJar); } if (!outJar.exists()) { outJar.createNewFile(); } jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(outJar)), manifest); jarOut.setLevel(9); jarOut.setComment("Merged jar created by " + getClass().getName()); Enumeration<JarEntry> en = jf.entries(); while (en.hasMoreElements()) { JarEntry e = en.nextElement(); String name = e.getName(); for (String s : exclude) { if (name.startsWith(s)) { continue; } } // if (!seen.contains(name)) { switch (name) { case "META-INF/MANIFEST.MF": case "META-INF/": break; case "META-INF/LICENSE": case "META-INF/LICENSE.txt": case "META-INF/http/pages.list": case "META-INF/http/modules.list": case "META-INF/http/numble.list": case "META-INF/settings/namespaces.list": Set<String> s = linesForName.get(name); if (s == null) { s = new LinkedHashSet<>(); linesForName.put(name, s); } Integer ct = fileCountForName.get(name); if (ct == null) { ct = 1; } fileCountForName.put(name, ct); try (InputStream in = jf.getInputStream(e)) { s.addAll(readLines(in)); } break; default: if (name.startsWith("META-INF/services/") && !name.endsWith("/")) { Set<String> s2 = linesForName.get(name); if (s2 == null) { s2 = new HashSet<>(); linesForName.put(name, s2); } Integer ct2 = fileCountForName.get(name); if (ct2 == null) { ct2 = 1; } fileCountForName.put(name, ct2); try (InputStream in = jf.getInputStream(e)) { s2.addAll(readLines(in)); } seen.add(name); } else if (PAT.matcher(name).matches()) { log.info("Include " + name); Properties p = new Properties(); try (InputStream in = jf.getInputStream(e)) { p.load(in); } Properties all = m.get(name); if (all == null) { all = p; m.put(name, p); } else { for (String key : p.stringPropertyNames()) { if (all.containsKey(key)) { Object old = all.get(key); Object nue = p.get(key); if (!Objects.equal(old, nue)) { log.warn(key + '=' + nue + " in " + jar + '!' + name + " overrides " + key + '=' + old); } } } all.putAll(p); } } else if (!seen.contains(name) && !SIG1.matcher(name).find() && !SIG2.matcher(name).find() && !SIG3.matcher(name).find()) { log.info("Bundle " + name); JarEntry je = new JarEntry(name); je.setTime(e.getTime()); try { jarOut.putNextEntry(je); } catch (ZipException ex) { throw new MojoExecutionException("Exception putting zip entry " + name, ex); } try (InputStream in = jf.getInputStream(e)) { copy(in, jarOut); } jarOut.closeEntry(); seen.add(name); } else { System.err.println("Skip " + name); } } // } seen.add(e.getName()); } } } catch (IOException ex) { throw new MojoExecutionException("Failed to create merged jar", ex); } } for (File f : jars) { log.info("Merge JAR " + f); try (JarFile jar = new JarFile(f)) { Enumeration<JarEntry> en = jar.entries(); while (en.hasMoreElements()) { JarEntry entry = en.nextElement(); String name = entry.getName(); for (String s : exclude) { if (name.startsWith(s)) { continue; } } if (PAT.matcher(name).matches()) { log.info("Include " + name + " in " + f); Properties p = new Properties(); try (InputStream in = jar.getInputStream(entry)) { p.load(in); } Properties all = m.get(name); if (all == null) { all = p; m.put(name, p); } else { for (String key : p.stringPropertyNames()) { if (all.containsKey(key)) { Object old = all.get(key); Object nue = p.get(key); if (!Objects.equal(old, nue)) { log.warn(key + '=' + nue + " in " + f + '!' + name + " overrides " + key + '=' + old); } } } all.putAll(p); } } else if (SERVICES.matcher(name).matches() || "META-INF/settings/namespaces.list".equals(name) || "META-INF/http/pages.list".equals(name) || "META-INF/http/modules.list".equals(name) || "META-INF/http/numble.list".equals(name)) { log.info("Include " + name + " in " + f); try (InputStream in = jar.getInputStream(entry)) { List<String> lines = readLines(in); Set<String> all = linesForName.get(name); if (all == null) { all = new LinkedHashSet<>(); linesForName.put(name, all); } all.addAll(lines); } Integer ct = fileCountForName.get(name); if (ct == null) { ct = 1; } else { ct++; } fileCountForName.put(name, ct); } else if (jarOut != null) { // if (!seen.contains(name)) { switch (name) { case "META-INF/MANIFEST.MF": case "META-INF/": break; case "META-INF/LICENSE": case "META-INF/LICENSE.txt": case "META-INF/settings/namespaces.list": case "META-INF/http/pages.list": case "META-INF/http/numble.list": case "META-INF/http/modules.list": Set<String> s = linesForName.get(name); if (s == null) { s = new LinkedHashSet<>(); linesForName.put(name, s); } Integer ct = fileCountForName.get(name); if (ct == null) { ct = 1; } fileCountForName.put(name, ct); try (InputStream in = jar.getInputStream(entry)) { s.addAll(readLines(in)); } break; default: if (!seen.contains(name)) { if (!SIG1.matcher(name).find() && !SIG2.matcher(name).find() && !SIG3.matcher(name).find()) { JarEntry je = new JarEntry(name); je.setTime(entry.getTime()); try { jarOut.putNextEntry(je); } catch (ZipException ex) { throw new MojoExecutionException("Exception putting zip entry " + name, ex); } try (InputStream in = jar.getInputStream(entry)) { copy(in, jarOut); } jarOut.closeEntry(); } } else { if (!name.endsWith("/") && !name.startsWith("META-INF")) { log.warn("Saw more than one " + name + ". One will clobber the other."); } } } // } else { // if (!name.endsWith("/") && !name.startsWith("META-INF")) { // log.warn("Saw more than one " + name + ". One will clobber the other."); // } // } seen.add(name); } } } catch (IOException ex) { throw new MojoExecutionException("Error opening " + f, ex); } } if (!m.isEmpty()) { log.warn("Writing merged files: " + m.keySet()); } else { return; } String outDir = project.getBuild().getOutputDirectory(); File dir = new File(outDir); // Don't bother rewriting META-INF/services files of which there is // only one // for (Map.Entry<String, Integer> e : fileCountForName.entrySet()) { // if (e.getValue() == 1) { // linesForName.remove(e.getKey()); // } // } for (Map.Entry<String, Set<String>> e : linesForName.entrySet()) { File outFile = new File(dir, e.getKey()); log.info("Merge configurating rewriting " + outFile); Set<String> lines = e.getValue(); if (!outFile.exists()) { try { Path path = outFile.toPath(); if (!Files.exists(path.getParent())) { Files.createDirectories(path.getParent()); } path = Files.createFile(path); outFile = path.toFile(); } catch (IOException ex) { throw new MojoFailureException("Could not create " + outFile, ex); } } if (!outFile.isDirectory()) { try (FileOutputStream out = new FileOutputStream(outFile)) { try (PrintStream ps = new PrintStream(out)) { for (String line : lines) { ps.println(line); } } } catch (IOException ex) { throw new MojoFailureException("Exception writing " + outFile, ex); } } if (jarOut != null) { log.warn("Concatenating " + fileCountForName.get(e.getKey()) + " copies of " + e.getKey()); JarEntry je = new JarEntry(e.getKey()); try { jarOut.putNextEntry(je); PrintStream ps = new PrintStream(jarOut); for (String line : lines) { ps.println(line); } jarOut.closeEntry(); } catch (IOException ex) { throw new MojoFailureException("Exception writing " + outFile, ex); } } } for (Map.Entry<String, Properties> e : m.entrySet()) { File outFile = new File(dir, e.getKey()); Properties local = new Properties(); if (outFile.exists()) { try { try (InputStream in = new FileInputStream(outFile)) { local.load(in); } } catch (IOException ioe) { throw new MojoExecutionException("Could not read " + outFile, ioe); } } else { try { Path path = outFile.toPath(); if (!Files.exists(path.getParent())) { Files.createDirectories(path.getParent()); } path = Files.createFile(path); outFile = path.toFile(); } catch (IOException ex) { throw new MojoFailureException("Could not create " + outFile, ex); } } Properties merged = e.getValue(); for (String key : local.stringPropertyNames()) { if (merged.containsKey(key) && !Objects.equal(local.get(key), merged.get(key))) { log.warn("Overriding key=" + merged.get(key) + " with locally defined key=" + local.get(key)); } } merged.putAll(local); try { log.info("Saving merged properties to " + outFile); try (FileOutputStream out = new FileOutputStream(outFile)) { merged.store(out, getClass().getName()); } } catch (IOException ex) { throw new MojoExecutionException("Failed to write " + outFile, ex); } if (jarOut != null) { JarEntry props = new JarEntry(e.getKey()); try { jarOut.putNextEntry(props); merged.store(jarOut, getClass().getName() + " merged " + e.getKey()); jarOut.closeEntry(); } catch (IOException ex) { throw new MojoExecutionException("Failed to write jar entry " + e.getKey(), ex); } } File copyTo = new File(dir.getParentFile(), "settings"); if (!copyTo.exists()) { copyTo.mkdirs(); } File toFile = new File(copyTo, outFile.getName()); try { Files.copy(outFile.toPath(), toFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException ex) { throw new MojoExecutionException("Failed to copy " + outFile + " to " + toFile, ex); } } } finally { if (jarOut != null) { try { jarOut.close(); } catch (IOException ex) { throw new MojoExecutionException("Failed to close Jar", ex); } } } }
From source file:com.offbynull.coroutines.mavenplugin.MainInstrumentMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { Log log = getLog(); File mainOutputFolder = new File(getProject().getBuild().getOutputDirectory()); if (!mainOutputFolder.isDirectory()) { log.warn("Test folder doesn't exist -- nothing to instrument"); return;/*from ww w . ja va2 s . c o m*/ } List<String> classpath; try { classpath = getProject().getCompileClasspathElements(); } catch (DependencyResolutionRequiredException ex) { throw new MojoExecutionException("Dependency resolution problem", ex); } Instrumenter instrumenter = getInstrumenter(log, classpath); log.info("Processing main output folder ... "); instrumentPath(log, instrumenter, mainOutputFolder); }
From source file:com.puresoltechnologies.maven.plugins.license.AbstractValidationMojo.java
private boolean hasCycle(DependencyTree dependencyTree, Dependency dependency) { Log log = getLog(); List<DependencyTree> path = new ArrayList<>(); while (dependencyTree != null) { path.add(0, dependencyTree);//from w w w . j a v a 2s .c om Artifact artifact = dependencyTree.getArtifact(); String artifactString = ArtifactUtilities.toString(artifact); String dependencyString = ArtifactUtilities.toString(dependency); if (artifactString.equals(dependencyString)) { while (dependencyTree != null) { path.add(0, dependencyTree); dependencyTree = dependencyTree.getParent(); } log.warn("WARNING! Cycle detected for '" + artifactString + "':"); for (int i = 0; i < path.size(); i++) { DependencyTree node = path.get(i); StringBuffer buffer = new StringBuffer(); for (int col = 0; col < i; col++) { buffer.append(" "); } buffer.append("\\-> "); buffer.append(ArtifactUtilities.toString(node.getArtifact())); log.warn(buffer.toString()); } StringBuffer buffer = new StringBuffer(); buffer.append(" !! "); for (int col = 0; col < path.size(); col++) { buffer.append(" "); } buffer.append("\\-> "); buffer.append(artifactString); buffer.append(" !! "); log.warn(buffer.toString()); return true; } dependencyTree = dependencyTree.getParent(); } return false; }
From source file:com.pushtechnology.mvndar.AddDependenciesTask.java
License:Apache License
@Override public void perform(final DARMojoContext context) throws IOException { // This only gets the direct dependencies. See // https://github.com/pushtechnology/mvndar/issues/1 @SuppressWarnings("unchecked") final Set<Artifact> dependencies = context.getProject().getDependencyArtifacts(); final Log log = context.getLog(); for (final Artifact a : dependencies) { if (a.isOptional()) { log.debug("Ignoring optional dependency: " + a); continue; }// ww w .j a va 2 s . c om if (!context.getAcceptedDependencyScopes().contains(a.getScope())) { log.debug("Ignoring dependency (scope): " + a); continue; } if ("com.pushtechnology".equals(a.getGroupId()) && "diffusion-api".equals(a.getArtifactId())) { continue; } if (context.getExtTypes().contains(a.getType())) { if (a.getFile() == null) { // Happens for relocated artifacts, e.g. // org.apache.commons:commons-io:jar:1.3.2 log.warn("Failed to locate dependency " + a + ", skipping"); continue; } final File f = a.getFile().getCanonicalFile(); final File target = FileUtils.getFile(context.getPrefixDirectoryName(), context.getExtDirectoryName(), f.getName()); context.getArchiver().addFile(f, target.toString()); log.debug("Dependency " + a + " has been copied to " + target); } else { log.debug("Ignoring dependency: " + a); } } }
From source file:com.qq.tars.maven.util.ArchiveEntryUtils.java
License:Open Source License
public static void chmod(final File file, final int mode, final Log logger, boolean useJvmChmod) throws ArchiverException { if (!Os.isFamily(Os.FAMILY_UNIX)) { return;/*from ww w . j a v a 2 s. c o m*/ } final String m = Integer.toOctalString(mode & 0xfff); if (useJvmChmod && !jvmFilePermAvailable) { logger.info("chmod it's not possible where your current jvm"); useJvmChmod = false; } if (useJvmChmod && jvmFilePermAvailable) { applyPermissionsWithJvm(file, m, logger); return; } try { final Commandline commandline = new Commandline(); commandline.setWorkingDirectory(file.getParentFile().getAbsolutePath()); if (logger.isDebugEnabled()) { logger.debug(file + ": mode " + Integer.toOctalString(mode) + ", chmod " + m); } commandline.setExecutable("chmod"); commandline.createArg().setValue(m); final String path = file.getAbsolutePath(); commandline.createArg().setValue(path); final CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); final CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); final int exitCode = CommandLineUtils.executeCommandLine(commandline, stderr, stdout); if (exitCode != 0) { logger.warn("-------------------------------"); logger.warn("Standard error:"); logger.warn("-------------------------------"); logger.warn(stderr.getOutput()); logger.warn("-------------------------------"); logger.warn("Standard output:"); logger.warn("-------------------------------"); logger.warn(stdout.getOutput()); logger.warn("-------------------------------"); throw new ArchiverException("chmod exit code was: " + exitCode); } } catch (final CommandLineException e) { throw new ArchiverException("Error while executing chmod.", e); } }
From source file:com.qq.tars.maven.util.FilePermissionUtils.java
License:Open Source License
public static FilePermission getFilePermissionFromMode(String mode, Log logger) { if (StringUtils.isBlank(mode)) { throw new IllegalArgumentException(" file mode cannot be empty"); }//w w w .j a v a 2s. c o m if (mode.length() != 3 && mode.length() != 4) { throw new IllegalArgumentException(" file mode must be 3 or 4 characters"); } List modes = new ArrayList(mode.length()); for (int i = 0, size = mode.length(); i < size; i++) { modes.add(String.valueOf(mode.charAt(i))); } boolean executable = false, ownerOnlyExecutable = true, ownerOnlyReadable = true, readable = false, ownerOnlyWritable = true, writable = false; // handle user perm try { int userMode = Integer.valueOf((String) modes.get(mode.length() == 4 ? 1 : 0)).intValue(); switch (userMode) { case 0: break; case 1: executable = true; break; case 2: writable = true; break; case 3: writable = true; executable = true; break; case 4: readable = true; break; case 5: readable = true; executable = true; break; case 6: readable = true; writable = true; break; case 7: writable = true; readable = true; executable = true; break; default: logger.warn("ignore file mode " + userMode); } } catch (NumberFormatException e) { throw new IllegalArgumentException(" file mode must contains only number " + mode); } try { int allMode = Integer.valueOf((String) modes.get(mode.length() == 4 ? 3 : 2)).intValue(); switch (allMode) { case 0: break; case 1: executable = true; ownerOnlyExecutable = false; break; case 2: writable = true; ownerOnlyWritable = false; break; case 3: writable = true; executable = true; ownerOnlyExecutable = false; ownerOnlyWritable = false; break; case 4: readable = true; ownerOnlyReadable = false; break; case 5: readable = true; executable = true; ownerOnlyReadable = false; ownerOnlyExecutable = false; break; case 6: readable = true; ownerOnlyReadable = false; writable = true; ownerOnlyWritable = false; break; case 7: writable = true; readable = true; executable = true; ownerOnlyReadable = false; ownerOnlyExecutable = false; ownerOnlyWritable = false; break; default: logger.warn("ignore file mode " + allMode); } } catch (NumberFormatException e) { throw new IllegalArgumentException(" file mode must contains only number " + mode); } return new FilePermission(executable, ownerOnlyExecutable, ownerOnlyReadable, readable, ownerOnlyWritable, writable); }
From source file:com.qwazr.mavenplugin.QwazrStopMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { final Log log = getLog(); log.info("Stopping QWAZR"); public_addr = getProperty(public_addr, "PUBLIC_ADDR", "localhost"); webservice_port = getProperty(webservice_port, "WEBSERVICE_PORT", 9091); wait_ms = getProperty(webservice_port, null, 5000); CloseableHttpResponse response = null; CloseableHttpClient httpClient = null; try {/*from w w w . ja va 2 s . co m*/ httpClient = HttpUtils.createHttpClient_AcceptsUntrustedCerts(); URI uri = new URI("http", null, public_addr, webservice_port, "/shutdown", null, null); log.info("Post HTTP Delete on: " + uri); response = httpClient.execute(new HttpDelete(uri)); log.info("HTTP Status Code: " + response.getStatusLine().getStatusCode()); } catch (IOException | URISyntaxException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { if (fault_tolerant == null || fault_tolerant) log.warn(e); else throw new MojoExecutionException(e.getMessage(), e); } finally { IOUtils.close(httpClient, response); } try { Thread.sleep(wait_ms); } catch (InterruptedException e) { log.warn(e); } }
From source file:com.redhat.victims.VictimsRule.java
License:Open Source License
/** * Updates the database according to the given configuration * @param ctx/*from ww w . jav a 2s .co m*/ * @throws VictimsException */ public void updateDatabase(ExecutionContext ctx) throws VictimsException { Log log = ctx.getLog(); // Disable updates via command line -Dvictims.skip.update=true String override = System.getProperty(Settings.UPDATES_OVERRIDE); if (override != null && override.equalsIgnoreCase("true")) { log.warn("[victims-enforcer] Updates disabled via system property."); return; } VictimsDBInterface db = ctx.getDatabase(); Date updated = db.lastUpdated(); // update automatically every time if (ctx.updateAlways()) { log.info(TextUI.fmt(Resources.INFO_UPDATES, updated.toString(), VictimsConfig.uri())); db.synchronize(); // update once per day } else if (ctx.updateDaily()) { Date today = new Date(); SimpleDateFormat cmp = new SimpleDateFormat("yyyyMMdd"); boolean updatedToday = cmp.format(today).equals(cmp.format(updated)); if (!updatedToday) { log.info(TextUI.fmt(Resources.INFO_UPDATES, updated.toString(), VictimsConfig.uri())); db.synchronize(); } else { log.debug("[victims-enforcer] database last synchronized: " + updated.toString()); } } else if (ctx.updateWeekly()) { Date today = new Date(); SimpleDateFormat cmp = new SimpleDateFormat("yyyyw"); if (cmp.format(today).equals(cmp.format(updated))) { log.info(TextUI.fmt(Resources.INFO_UPDATES, updated.toString(), VictimsConfig.uri())); db.synchronize(); } else { log.debug("[victims-enforcer] database last synchronized: " + updated.toString()); } // updates disabled } else { log.debug("[victims-enforcer] database synchronization disabled."); } }