List of usage examples for org.apache.maven.plugin.logging Log info
void info(Throwable error);
From source file:org.codehaus.mojo.jaxb2.shared.FileSystemUtilities.java
License:Apache License
/** * Filters files found either in the sources paths (or in the standardDirectory if no explicit sources are given), * and retrieves a List holding those files that do not match any of the supplied Java Regular Expression * excludePatterns.// w ww .ja v a2 s.c o m * * @param baseDir The non-null basedir Directory. * @param sources The sources which should be either absolute or relative (to the given baseDir) * paths to files or to directories that should be searched recursively for files. * @param standardDirectory If no sources are given, revert to searching all files under this standard directory. * This is the path appended to the baseDir to reach a directory. * @param log A non-null Maven Log for logging any operations performed. * @param fileTypeDescription A human-readable short description of what kind of files are searched for, such as * "xsdSources" or "xjbSources". * @param excludeFilters An optional List of Filters used to identify files which should be excluded from * the result. * @return All files under the supplied sources (or standardDirectory, if no explicit sources are given) which * do not match the supplied Java Regular excludePatterns. */ @SuppressWarnings("CheckStyle") public static List<File> filterFiles(final File baseDir, final List<String> sources, final String standardDirectory, final Log log, final String fileTypeDescription, final List<Filter<File>> excludeFilters) { // Check sanity Validate.notNull(baseDir, "baseDir"); Validate.notNull(log, "log"); Validate.notEmpty(standardDirectory, "standardDirectory"); Validate.notEmpty(fileTypeDescription, "fileTypeDescription"); // No sources provided? Fallback to the standard (which should be a relative path). List<String> effectiveSources = sources; if (sources == null || sources.isEmpty()) { effectiveSources = new ArrayList<String>(); final File tmp = new File(standardDirectory); final File rootDirectory = tmp.isAbsolute() ? tmp : new File(baseDir, standardDirectory); effectiveSources.add(FileSystemUtilities.getCanonicalPath(rootDirectory)); } // First, remove the non-existent sources. List<File> existingSources = new ArrayList<File>(); for (String current : effectiveSources) { final File existingFile = FileSystemUtilities.getExistingFile(current, baseDir); if (existingFile != null) { existingSources.add(existingFile); if (log.isDebugEnabled()) { log.debug("Accepted configured " + fileTypeDescription + " [" + FileSystemUtilities.getCanonicalFile(existingFile) + "]"); } } else { if (log.isInfoEnabled()) { log.info("Ignored given or default " + fileTypeDescription + " [" + current + "], since it is not an existent file or directory."); } } } if (log.isDebugEnabled() && existingSources.size() > 0) { final int size = existingSources.size(); log.debug(" [" + size + " existing " + fileTypeDescription + "] ..."); for (int i = 0; i < size; i++) { log.debug(" " + (i + 1) + "/" + size + ": " + existingSources.get(i)); } log.debug(" ... End [" + size + " existing " + fileTypeDescription + "]"); } // All Done. return FileSystemUtilities.resolveRecursively(existingSources, excludeFilters, log); }
From source file:org.codehaus.mojo.jaxb2.shared.filters.AbstractFilter.java
License:Apache License
/** * {@inheritDoc}/*from w w w.j av a2s.co m*/ */ @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) {// w w 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
/** * {@inheritDoc}// ww w . j a v a2 s. c o m */ @Override protected void init() throws Exception { Log log = getLog(); if (log.isDebugEnabled()) { // always be verbose in debug mode setVerbose(true); } thirdPartyFile = new File(getOutputDirectory(), thirdPartyFilename); long buildTimestamp = getBuildTimestamp(); if (isVerbose()) { log.info("Build start at : " + buildTimestamp); log.info("third-party file : " + thirdPartyFile.lastModified()); } doGenerate = isForce() || !thirdPartyFile.exists() || buildTimestamp > thirdPartyFile.lastModified(); if (generateBundle) { File bundleFile = FileUtil.getFile(getOutputDirectory(), bundleThirdPartyPath); if (isVerbose()) { log.info("bundle third-party file : " + bundleFile.lastModified()); } doGenerateBundle = isForce() || !bundleFile.exists() || buildTimestamp > bundleFile.lastModified(); } else { // not generating bundled file doGenerateBundle = false; } projectDependencies = loadDependencies(); licenseMap = getHelper().createLicenseMap(projectDependencies); unsafeDependencies = getHelper().getProjectsWithNoLicense(licenseMap); if (!CollectionUtils.isEmpty(unsafeDependencies)) { if (isUseMissingFile() && isDoGenerate()) { // load unsafeMapping from local file and/or third-party classified items. unsafeMappings = createUnsafeMapping(); } } getHelper().mergeLicenses(licenseMerges, licenseMap); }
From source file:org.codehaus.mojo.license.AddThirdPartyMojo.java
License:Open Source License
/** * Write the missing file ({@link #getMissingFile()}. * * @throws IOException if error while writing missing file *//* www.j a v a2s . c o m*/ private void writeMissingFile() throws IOException { Log log = getLog(); LicenseMap licenseMap = getLicenseMap(); File file = getMissingFile(); FileUtil.createDirectoryIfNecessary(file.getParentFile()); log.info("Regenerate missing license file " + file); FileOutputStream writer = new FileOutputStream(file); try { StringBuilder sb = new StringBuilder(" Generated by " + getClass().getName()); List<String> licenses = new ArrayList<String>(licenseMap.keySet()); licenses.remove(LicenseMap.UNKNOWN_LICENSE_MESSAGE); if (!licenses.isEmpty()) { sb.append("\n-------------------------------------------------------------------------------"); sb.append("\n Already used licenses in project :"); for (String license : licenses) { sb.append("\n - ").append(license); } } sb.append("\n-------------------------------------------------------------------------------"); sb.append("\n Please fill the missing licenses for dependencies :\n\n"); getUnsafeMappings().store(writer, sb.toString()); } finally { writer.close(); } }
From source file:org.codehaus.mojo.license.AggregatorAddThirdPartyMojo.java
License:Open Source License
/** * {@inheritDoc}/*w ww . j av a2 s. c o m*/ */ @Override protected void doAction() throws Exception { Log log = getLog(); if (isVerbose()) { log.info("After executing on " + reactorProjects.size() + " project(s)"); } // SortedMap<String, MavenProject> aatifacts = getHelper().getArtifactCache(); LicenseMap licenseMap = getLicenseMap(); // getLog().info( artifacts.size() + " detected artifact(s)." ); // if ( isVerbose() ) // { // for ( String id : artifacts.keySet() ) // { // getLog().info( " - " + id ); // } // } getLog().info(licenseMap.size() + " detected license(s)."); if (isVerbose()) { for (String id : licenseMap.keySet()) { getLog().info(" - " + id); } } if (checkUnsafeDependencies()) { resolveUnsafeDependenciesFromFile(aggregateMissingLicensesFile); } if (!StringUtils.isBlank(aggregateMissingLicensesFileArtifact) && checkUnsafeDependencies()) { String[] tokens = StringUtils.split(aggregateMissingLicensesFileArtifact, ":"); if (tokens.length != 3) { throw new MojoFailureException( "Invalid missing licenses artifact, you must specify groupId:artifactId:version " + aggregateMissingLicensesFileArtifact); } String groupId = tokens[0]; String artifactId = tokens[1]; String version = tokens[2]; resolveUnsafeDependenciesFromArtifact(groupId, artifactId, version); } boolean unsafe = checkUnsafeDependencies(); boolean safeLicense = checkForbiddenLicenses(); if (!safeLicense && isFailIfWarning()) { throw new MojoFailureException( "There are some forbidden licenses used, please check your dependencies."); } writeThirdPartyFile(); if (unsafe && isFailIfWarning()) { throw new MojoFailureException( "There are some dependencies with no license, please review the modules."); } }
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 w w.j ava 2s.co m*/ * @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.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)); }/*from w ww . j ava 2s .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 the files from the various mapping sources into the build root. * * @throws MojoExecutionException if a problem occurs * @throws MojoFailureException//from ww w . j a v a2 s.c o m */ public void installFiles() throws MojoExecutionException, MojoFailureException { final File workarea = mojo.getWorkarea(); final File buildroot = mojo.getBuildroot(); final File icon = mojo.getIcon(); // Copy icon, if specified if (icon != null) { File icondest = new File(workarea, "SOURCES"); copySource(icon, null, icondest, null, null, false, false); } final Log log = mojo.getLog(); // Process each mapping for (Mapping map : mojo.getMappings()) { final String destinationString = map.getDestination(); final String macroEvaluatedDestination = evaluateMacros(destinationString); File dest = new File(buildroot, macroEvaluatedDestination); map.setAbsoluteDestination(dest); if (map.isDirOnly()) { // Build the output directory if it doesn't exist if (!dest.exists()) { log.info("Creating empty directory " + dest.getAbsolutePath()); if (!dest.mkdirs()) { throw new MojoExecutionException("Unable to create " + dest.getAbsolutePath()); } } } else { processSources(map, dest); ArtifactMap art = map.getArtifact(); if (art != null) { List<Artifact> artlist = selectArtifacts(art); for (Artifact artifactInstance : artlist) { copyArtifact(artifactInstance, dest, false); map.addCopiedFileNameRelativeToDestination(artifactInstance.getFile().getName()); } } Dependency dep = map.getDependency(); if (dep != null) { List<Artifact> deplist = selectDependencies(dep); for (Artifact artifactInstance : deplist) { // pass in dependency stripVersion parameter String outputFileName = copyArtifact(artifactInstance, dest, dep.getStripVersion()); map.addCopiedFileNameRelativeToDestination(outputFileName); } } if (map.getCopiedFileNamesRelativeToDestination().isEmpty()) { log.info("Mapping empty with destination: " + dest.getName()); // Build the output directory if it doesn't exist if (!dest.exists()) { log.info("Creating empty directory " + dest.getAbsolutePath()); if (!dest.mkdirs()) { throw new MojoExecutionException("Unable to create " + dest.getAbsolutePath()); } } } } } }
From source file:org.codehaus.mojo.smc.Util.java
License:Apache License
/** * execute the net.sf.smc.Smc#main method given the specified arguments. * Standard Output and Err messages are redirected to <code>log.info()</code> and <code>log.error</code>. * @param arguments/*from w ww . j av a2s. c om*/ * @param log * @throws Exception thrown if log.error() is not empty */ static void executeSmc(List arguments, Log log) throws Exception { final StringOutputStream out = new StringOutputStream(); final StringOutputStream err = new StringOutputStream(); executeSmc(arguments, out, err); if (out.toString().length() > 0) { log.info(out.toString()); } if (err.toString().length() > 0) { log.error(".sm file contains errors: \n" + err.toString()); throw new Exception("Error while converting files."); } }