List of usage examples for org.apache.maven.plugin.logging Log warn
void warn(Throwable error);
From source file:org.codehaus.mojo.jaxb2.shared.filters.AbstractFilter.java
License:Apache License
/** * {@inheritDoc}/*from w ww. j a va 2 s.com*/ */ @Override public final void initialize(final Log log) { // Check sanity Validate.notNull(log, "log"); // Assign internal state this.log = log; if (delayedLogMessages.size() > 0) { for (DelayedLogMessage current : delayedLogMessages) { if (current.logLevel.equalsIgnoreCase("warn") && log.isWarnEnabled()) { log.warn(current.message); } else if (current.logLevel.equals("info") && log.isInfoEnabled()) { log.info(current.message); } else if (log.isDebugEnabled()) { log.debug(current.message); } } delayedLogMessages.clear(); } // Delegate onInitialize(); }
From source file:org.codehaus.mojo.jspc.CompilationMojoSupport.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { if (skip) {/*from ww w .ja v a 2 s . co m*/ return; } final Log log = this.getLog(); final boolean isWar = "war".equals(project.getPackaging()); if (!isWar) { log.warn("Compiled JSPs will not be added to the project and web.xml will " + "not be modified because the project's packaging is not 'war'."); } if (!includeInProject) { log.warn("Compiled JSPs will not be added to the project and web.xml will " + "not be modified because includeInProject is set to false."); } final JspCompiler jspCompiler = this.jspCompilerFactory.createJspCompiler(); // Setup defaults (complex, can"t init from expression) if (sources == null) { sources = new FileSet(); sources.setDirectory(this.defaultSourcesDirectory.getAbsolutePath()); sources.setExcludes(Arrays.asList("WEB-INF/web.xml", "META-INF/**")); } jspCompiler.setWebappDirectory(sources.getDirectory()); log.debug("Source directory: " + this.sources.getDirectory()); jspCompiler.setOutputDirectory(this.workingDirectory); log.debug("Output directory: " + this.workingDirectory); jspCompiler.setEncoding(this.javaEncoding); log.debug("Encoding: " + this.javaEncoding); jspCompiler.setShowSuccess(this.showSuccess); jspCompiler.setListErrors(this.listErrors); jspCompiler.setWebFragmentFile(webFragmentFile); log.debug("Web Fragment: " + this.webFragmentFile); jspCompiler.setPackageName(packageName); log.debug("Package Name: " + this.packageName); final List<String> classpathElements = getClasspathElements(); jspCompiler.setClasspath(classpathElements); log.debug("Classpath: " + classpathElements); final List<File> jspFiles; if (sources.getIncludes() != null) { //Always need to get a full list of JSP files as incremental builds would result in an invalid web.xml final Scanner scanner = this.buildContext.newScanner(new File(sources.getDirectory()), true); scanner.setIncludes(sources.getIncludesArray()); scanner.setExcludes(sources.getExcludesArray()); scanner.addDefaultExcludes(); scanner.scan(); final String[] includes = scanner.getIncludedFiles(); jspFiles = new ArrayList<File>(includes.length); for (final String it : includes) { jspFiles.add(new File(sources.getDirectory(), it)); } } else { jspFiles = Collections.emptyList(); } jspCompiler.setSmapDumped(smapDumped); jspCompiler.setSmapSuppressed(smapSuppressed); jspCompiler.setCompile(compile); jspCompiler.setValidateXml(validateXml); jspCompiler.setTrimSpaces(trimSpaces); jspCompiler.setVerbose(verbose); jspCompiler.setErrorOnUseBeanInvalidClassAttribute(errorOnUseBeanInvalidClassAttribute); jspCompiler.setCompilerSourceVM(source); jspCompiler.setCompilerTargetVM(target); jspCompiler.setCaching(caching); jspCompiler.setGenStringAsCharArray(genStringAsCharArray); jspCompiler.setPoolingEnabled(poolingEnabled); jspCompiler.setClassDebugInfo(classDebugInfo); jspCompiler.setCompileThreads(compileThreads); jspCompiler.setCompileTimeout(TimeUnit.MINUTES.toMillis(compilationTimeout)); // Make directories if needed workingDirectory.mkdirs(); webFragmentFile.getParentFile().mkdirs(); outputWebXml.getParentFile().mkdirs(); // JspC needs URLClassLoader, with tools.jar final ClassLoader parent = Thread.currentThread().getContextClassLoader(); final JspcMojoClassLoader cl = new JspcMojoClassLoader(parent); cl.addURL(findToolsJar()); Thread.currentThread().setContextClassLoader(cl); try { // Show a nice message when we know how many files are included if (!jspFiles.isEmpty()) { log.info("Compiling " + jspFiles.size() + " JSP source file" + (jspFiles.size() > 1 ? "s" : "") + " to " + workingDirectory); } else { log.info("Compiling JSP source files to " + workingDirectory); } final StopWatch watch = new StopWatch(); watch.start(); jspCompiler.compile(jspFiles); log.info("Compilation completed in " + watch); } catch (Exception e) { throw new MojoFailureException("Failed to compile JSPS", e); } finally { // Set back the old classloader Thread.currentThread().setContextClassLoader(parent); } //Notify the build context that the jspFiles have been modified by the jsp compiler for (final File jspFile : jspFiles) { this.buildContext.refresh(jspFile); } // Maybe install the generated classes into the default output directory if (compile && isWar) { final Scanner scanner = buildContext.newScanner(this.workingDirectory); scanner.addDefaultExcludes(); scanner.setIncludes(new String[] { "**/*.class" }); scanner.scan(); for (final String includedFile : scanner.getIncludedFiles()) { final File s = new File(this.workingDirectory, includedFile); final File d = new File(this.project.getBuild().getOutputDirectory(), includedFile); d.getParentFile().mkdirs(); OutputStream fos = null; try { fos = this.buildContext.newFileOutputStream(d); org.apache.commons.io.FileUtils.copyFile(s, fos); } catch (IOException e) { throw new MojoFailureException("Failed to copy '" + s + "' to '" + d + "'", e); } finally { IOUtils.closeQuietly(fos); } } } if (isWar && includeInProject) { writeWebXml(); project.addCompileSourceRoot(workingDirectory.toString()); } }
From source file:org.codehaus.mojo.license.AbstractAddThirdPartyMojo.java
License:Open Source License
protected boolean checkUnsafeDependencies() { SortedSet<MavenProject> unsafeDeps = getUnsafeDependencies(); boolean unsafe = !CollectionUtils.isEmpty(unsafeDeps); if (unsafe) { Log log = getLog(); log.warn("There is " + unsafeDeps.size() + " dependencies with no license :"); for (MavenProject dep : unsafeDeps) { // no license found for the dependency log.warn(" - " + MojoHelper.getArtifactId(dep.getArtifact())); }/* w w w .j av a 2 s . c om*/ } return unsafe; }
From source file:org.codehaus.mojo.license.AbstractAddThirdPartyMojo.java
License:Open Source License
protected boolean checkForbiddenLicenses() { List<String> whiteLicenses = getIncludedLicenses(); List<String> blackLicenses = getExcludedLicenses(); Set<String> unsafeLicenses = new HashSet<String>(); if (CollectionUtils.isNotEmpty(blackLicenses)) { Set<String> licenses = getLicenseMap().keySet(); getLog().info("Excluded licenses (blacklist): " + blackLicenses); for (String excludeLicense : blackLicenses) { if (licenses.contains(excludeLicense) && CollectionUtils.isNotEmpty(getLicenseMap().get(excludeLicense))) { //bad license found unsafeLicenses.add(excludeLicense); }// w ww. java2 s .c o m } } if (CollectionUtils.isNotEmpty(whiteLicenses)) { Set<String> dependencyLicenses = getLicenseMap().keySet(); getLog().info("Included licenses (whitelist): " + whiteLicenses); for (String dependencyLicense : dependencyLicenses) { getLog().debug("Testing license '" + dependencyLicense + "'"); if (!whiteLicenses.contains(dependencyLicense) && CollectionUtils.isNotEmpty(getLicenseMap().get(dependencyLicense))) { getLog().debug( "Testing dependency license '" + dependencyLicense + "' against all other licenses"); for (MavenProject dependency : getLicenseMap().get(dependencyLicense)) { getLog().debug(" testing dependency " + dependency); boolean forbiddenLicenseUsed = true; for (String otherLicense : dependencyLicenses) { // skip this license if it is the same as the dependency license // skip this license if it has no projects assigned if (otherLicense.equals(dependencyLicense) || getLicenseMap().get(dependencyLicense).isEmpty()) { continue; } // skip this license if it isn't one of the whitelisted if (!whiteLicenses.contains(otherLicense)) { continue; } if (getLicenseMap().get(otherLicense).contains(dependency)) { getLog().info("License '" + dependencyLicense + "' for '" + dependency + "'is OK since it is also licensed under '" + otherLicense + "'"); // this dependency is licensed under another license from white list forbiddenLicenseUsed = false; break; } } //bad license found if (forbiddenLicenseUsed) { unsafeLicenses.add(dependencyLicense); break; } } } } } boolean safe = CollectionUtils.isEmpty(unsafeLicenses); if (!safe) { Log log = getLog(); log.warn("There are " + unsafeLicenses.size() + " forbidden licenses used:"); for (String unsafeLicense : unsafeLicenses) { SortedSet<MavenProject> deps = getLicenseMap().get(unsafeLicense); if (!deps.isEmpty()) { StringBuilder sb = new StringBuilder(); sb.append("License ").append(unsafeLicense).append(" used by ").append(deps.size()) .append(" dependencies:"); for (MavenProject dep : deps) { sb.append("\n -").append(MojoHelper.getArtifactName(dep)); } log.warn(sb.toString()); } } } return safe; }
From source file:org.codehaus.mojo.license.ArtifactHelper.java
License:Open Source License
/** * Get the list of project dependencies after applying transitivity and filtering rules. * //from w ww . j ava 2s. c om * @param mojo * @param log * @param cache * @return */ public static SortedMap<String, MavenProject> loadProjectDependencies(MavenProjectDependenciesLoader mojo, Log log, SortedMap<String, MavenProject> cache) { boolean haveNoIncludedGroups = StringUtils.isEmpty(mojo.getIncludedGroups()); boolean haveNoIncludedArtifacts = StringUtils.isEmpty(mojo.getIncludedArtifacts()); boolean haveExcludedGroups = StringUtils.isNotEmpty(mojo.getExcludedGroups()); boolean haveExcludedArtifacts = StringUtils.isNotEmpty(mojo.getExcludedArtifacts()); boolean haveExclusions = haveExcludedGroups || haveExcludedArtifacts; Pattern includedGroupPattern = null; Pattern includedArtifactPattern = null; Pattern excludedGroupPattern = null; Pattern excludedArtifactPattern = null; if (!haveNoIncludedGroups) { includedGroupPattern = Pattern.compile(mojo.getIncludedGroups()); } if (!haveNoIncludedArtifacts) { includedArtifactPattern = Pattern.compile(mojo.getIncludedArtifacts()); } if (haveExcludedGroups) { excludedGroupPattern = Pattern.compile(mojo.getExcludedGroups()); } if (haveExcludedArtifacts) { excludedArtifactPattern = Pattern.compile(mojo.getExcludedArtifacts()); } MavenProject project = mojo.getProject(); Set<?> depArtifacts; if (mojo.isIncludeTransitiveDependencies()) { // All project dependencies depArtifacts = project.getArtifacts(); } else { // Only direct project dependencies depArtifacts = project.getDependencyArtifacts(); } ArtifactRepository localRepository = mojo.getLocalRepository(); List remoteRepositories = mojo.getRemoteRepositories(); MavenProjectBuilder projectBuilder = mojo.getMavenProjectBuilder(); List<String> excludeScopes = mojo.getExcludeScopes(); boolean verbose = mojo.isVerbose(); SortedMap<String, MavenProject> result = new TreeMap<String, MavenProject>(); for (Object o : depArtifacts) { Artifact artifact = (Artifact) o; if (excludeScopes.contains(artifact.getScope())) { // never treate system artifacts (they are mysterious and // no information can be retrive from anywhere)... continue; } String id = getArtifactId(artifact); if (verbose) { log.info("detected artifact " + id); } // Check if the project should be included // If there is no specified artifacts and group to include, include all boolean isToInclude = haveNoIncludedArtifacts && haveNoIncludedGroups || isIncludable(log, artifact, includedGroupPattern, includedArtifactPattern); // Check if the project should be excluded boolean isToExclude = isToInclude && haveExclusions && isExcludable(log, artifact, excludedGroupPattern, excludedArtifactPattern); if (!isToInclude || isToExclude) { if (verbose) { log.info("skip artifact " + id); } continue; } MavenProject depMavenProject = null; if (cache != null) { // try to get project from cache depMavenProject = cache.get(id); } if (depMavenProject != null) { if (verbose) { log.info("add dependency [" + id + "] (from cache)"); } } else { // build project try { depMavenProject = projectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, true); } catch (ProjectBuildingException e) { log.warn("Unable to obtain POM for artifact : " + artifact); log.warn(e); continue; } if (verbose) { log.info("add dependency [" + id + "]"); } if (cache != null) { // store it also in cache cache.put(id, depMavenProject); } } // keep the project result.put(id, depMavenProject); } return result; }
From source file:org.codehaus.mojo.license.ArtifactHelper.java
License:Open Source License
protected static boolean isIncludable(Log log, Artifact project, Pattern includedGroupPattern, Pattern includedArtifactPattern) { // check if the groupId of the project should be included if (includedGroupPattern != null) { // we have some defined license filters try {// w w w. java2 s. co m Matcher matchGroupId = includedGroupPattern.matcher(project.getGroupId()); if (matchGroupId.find()) { if (log.isDebugEnabled()) { log.debug("Include " + project.getGroupId()); } return true; } } catch (PatternSyntaxException e) { log.warn(String.format(INVALIDE_PATTERN_MESSAGE, includedGroupPattern.pattern())); } } // check if the artifactId of the project should be included if (includedArtifactPattern != null) { // we have some defined license filters try { Matcher matchGroupId = includedArtifactPattern.matcher(project.getArtifactId()); if (matchGroupId.find()) { if (log.isDebugEnabled()) { log.debug("Include " + project.getArtifactId()); } return true; } } catch (PatternSyntaxException e) { log.warn(String.format(INVALIDE_PATTERN_MESSAGE, includedArtifactPattern.pattern())); } } return false; }
From source file:org.codehaus.mojo.license.ArtifactHelper.java
License:Open Source License
protected static boolean isExcludable(Log log, Artifact project, Pattern excludedGroupPattern, Pattern excludedArtifactPattern) { // check if the groupId of the project should be included if (excludedGroupPattern != null) { // we have some defined license filters try {/*w ww. java2s. c om*/ Matcher matchGroupId = excludedGroupPattern.matcher(project.getGroupId()); if (matchGroupId.find()) { if (log.isDebugEnabled()) { log.debug("Exclude " + project.getGroupId()); } return true; } } catch (PatternSyntaxException e) { log.warn(String.format(INVALIDE_PATTERN_MESSAGE, excludedGroupPattern.pattern())); } } // check if the artifactId of the project should be included if (excludedArtifactPattern != null) { // we have some defined license filters try { Matcher matchGroupId = excludedArtifactPattern.matcher(project.getArtifactId()); if (matchGroupId.find()) { if (log.isDebugEnabled()) { log.debug("Exclude " + project.getArtifactId()); } return true; } } catch (PatternSyntaxException e) { log.warn(String.format(INVALIDE_PATTERN_MESSAGE, excludedArtifactPattern.pattern())); } } return false; }
From source file:org.codehaus.mojo.nbm.AbstractNbmMojo.java
License:Apache License
static Dependency resolveNetBeansDependency(Artifact artifact, List<Dependency> deps, ExamineManifest manifest, Log log) { String artId = artifact.getArtifactId(); String grId = artifact.getGroupId(); String id = grId + ":" + artId; for (Dependency dep : deps) { if (id.equals(dep.getId())) { if (manifest.isNetBeansModule()) { return dep; } else { if (dep.getExplicitValue() != null) { return dep; }//from w w w . ja va2 s .co m log.warn(id + " declared as module dependency in descriptor, but not a NetBeans module"); return null; } } } if ("nbm".equals(artifact.getType())) { Dependency dep = new Dependency(); dep.setId(id); dep.setType("spec"); log.debug("Adding nbm module dependency - " + id); return dep; } if (manifest.isNetBeansModule()) { Dependency dep = new Dependency(); dep.setId(id); dep.setType("spec"); log.debug("Adding direct NetBeans module dependency - " + id); return dep; } return null; }
From source file:org.codehaus.mojo.nbm.AbstractNbmMojo.java
License:Apache License
static List<ModuleWrapper> getModuleDependencyArtifacts(DependencyNode treeRoot, NetBeansModule module, Dependency[] customDependencies, MavenProject project, Map<Artifact, ExamineManifest> examinerCache, List<Artifact> libraryArtifacts, Log log, boolean useOsgiDependencies) throws MojoExecutionException { List<Dependency> deps = new ArrayList<Dependency>(); if (customDependencies != null) { deps.addAll(Arrays.asList(customDependencies)); }/*w w w . ja v a 2 s . c om*/ if (module != null && !module.getDependencies().isEmpty()) { log.warn( "dependencies in module descriptor are deprecated, use the plugin's parameter moduleDependencies"); //we need to make sure a dependency is not twice there, module deps override the config (as is the case with other //configurations) for (Dependency d : module.getDependencies()) { Dependency found = null; for (Dependency d2 : deps) { if (d2.getId().equals(d.getId())) { found = d2; break; } } if (found != null) { deps.remove(found); } deps.add(d); } } List<ModuleWrapper> include = new ArrayList<ModuleWrapper>(); @SuppressWarnings("unchecked") List<Artifact> artifacts = project.getCompileArtifacts(); for (Artifact artifact : artifacts) { if (libraryArtifacts.contains(artifact)) { continue; } ExamineManifest depExaminator = examinerCache.get(artifact); if (depExaminator == null) { depExaminator = new ExamineManifest(log); depExaminator.setArtifactFile(artifact.getFile()); depExaminator.checkFile(); examinerCache.put(artifact, depExaminator); } Dependency dep = resolveNetBeansDependency(artifact, deps, depExaminator, log); if (dep != null) { ModuleWrapper wr = new ModuleWrapper(); wr.dependency = dep; wr.artifact = artifact; wr.transitive = false; //only direct deps matter to us.. if (depExaminator.isNetBeansModule() && artifact.getDependencyTrail().size() > 2) { log.debug(artifact.getId() + " omitted as NetBeans module dependency, not a direct one. Declare it in the pom for inclusion."); wr.transitive = true; } include.add(wr); } else { if (useOsgiDependencies && depExaminator.isOsgiBundle()) { ModuleWrapper wr = new ModuleWrapper(); wr.osgi = true; String id = artifact.getGroupId() + ":" + artifact.getArtifactId(); for (Dependency depe : deps) { if (id.equals(depe.getId())) { wr.dependency = depe; } } boolean print = false; if (wr.dependency == null) { Dependency depe = new Dependency(); depe.setId(id); depe.setType("spec"); wr.dependency = depe; print = true; } wr.artifact = artifact; wr.transitive = false; //only direct deps matter to us.. if (artifact.getDependencyTrail().size() > 2) { log.debug(artifact.getId() + " omitted as NetBeans module OSGi dependency, not a direct one. Declare it in the pom for inclusion."); wr.transitive = true; } else { if (print) { log.info("Adding OSGi bundle dependency - " + id); } } include.add(wr); } } } return include; }
From source file:org.codehaus.mojo.rpm.FileHelper.java
License:Apache License
/** * Copy an artifact./*from w w w.j av a 2s. co m*/ * * @param art The artifact to copy * @param dest The destination directory * @param stripVersion Whether or not to strip the artifact version from the filename * @return Artifact file name * @throws MojoExecutionException if a problem occurs */ private String copyArtifact(Artifact art, File dest, boolean stripVersion) throws MojoExecutionException { if (art.getFile() == null) { final Log log = mojo.getLog(); log.warn("Artifact " + art + " requested in configuration."); log.warn("Plugin must be run in Maven's build lifecycle for this to work."); throw new MojoExecutionException("Unable to resolve artifact."); } String outputFileName; if (stripVersion) { final String classifier = art.getClassifier(); // strip the version from the file name outputFileName = art.getArtifactId(); if (classifier != null) { outputFileName += '-'; outputFileName += classifier; } outputFileName += '.'; outputFileName += art.getType(); } else { outputFileName = art.getFile().getName(); } copySource(art.getFile(), outputFileName, dest, null, null, false, false); return outputFileName; }