List of usage examples for org.apache.maven.plugin.logging Log debug
void debug(Throwable error);
From source file:org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper.java
License:Apache License
/** * Replaces all namespaces within generated schema files, as instructed by the configured Schema instances. * * @param resolverMap The map relating generated schema file name to SimpleNamespaceResolver instances. * @param configuredTransformSchemas The Schema instances read from the configuration of this plugin. * @param mavenLog The active Log. * @param schemaDirectory The directory where all generated schema files reside. * @throws MojoExecutionException If the namespace replacement could not be done. *///from w w w .ja va 2s . c o m public static void replaceNamespacePrefixes(final Map<String, SimpleNamespaceResolver> resolverMap, final List<TransformSchema> configuredTransformSchemas, final Log mavenLog, final File schemaDirectory) throws MojoExecutionException { if (mavenLog.isDebugEnabled()) { mavenLog.debug("Got resolverMap.keySet() [generated filenames]: " + resolverMap.keySet()); } for (SimpleNamespaceResolver currentResolver : resolverMap.values()) { File generatedSchemaFile = new File(schemaDirectory, currentResolver.getSourceFilename()); Document generatedSchemaFileDocument = null; for (TransformSchema currentTransformSchema : configuredTransformSchemas) { // Should we alter the namespace prefix as instructed by the current schema? final String newPrefix = currentTransformSchema.getToPrefix(); final String currentUri = currentTransformSchema.getUri(); if (StringUtils.isNotEmpty(newPrefix)) { // Find the old/current prefix of the namespace for the current schema uri. final String oldPrefix = currentResolver.getNamespaceURI2PrefixMap().get(currentUri); if (StringUtils.isNotEmpty(oldPrefix)) { // Can we perform the prefix substitution? validatePrefixSubstitutionIsPossible(oldPrefix, newPrefix, currentResolver); if (mavenLog.isDebugEnabled()) { mavenLog.debug("Subtituting namespace prefix [" + oldPrefix + "] with [" + newPrefix + "] in file [" + currentResolver.getSourceFilename() + "]."); } // Get the Document of the current schema file. if (generatedSchemaFileDocument == null) { generatedSchemaFileDocument = parseXmlToDocument(generatedSchemaFile); } // Replace all namespace prefixes within the provided document. process(generatedSchemaFileDocument.getFirstChild(), true, new ChangeNamespacePrefixProcessor(oldPrefix, newPrefix)); } } } if (generatedSchemaFileDocument != null) { // Overwrite the generatedSchemaFile with the content of the generatedSchemaFileDocument. mavenLog.debug("Overwriting file [" + currentResolver.getSourceFilename() + "] with content [" + getHumanReadableXml(generatedSchemaFileDocument) + "]"); savePrettyPrintedDocument(generatedSchemaFileDocument, generatedSchemaFile); } else { mavenLog.debug("No namespace prefix changes to generated schema file [" + generatedSchemaFile.getName() + "]"); } } }
From source file:org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper.java
License:Apache License
/** * Updates all schemaLocation attributes within the generated schema files to match the 'file' properties within the * Schemas read from the plugin configuration. After that, the files are physically renamed. * * @param resolverMap The map relating generated schema file name to SimpleNamespaceResolver instances. * @param configuredTransformSchemas The Schema instances read from the configuration of this plugin. * @param mavenLog The active Log. * @param schemaDirectory The directory where all generated schema files reside. */// w w w. j a v a 2s . c om public static void renameGeneratedSchemaFiles(final Map<String, SimpleNamespaceResolver> resolverMap, final List<TransformSchema> configuredTransformSchemas, final Log mavenLog, final File schemaDirectory) { // Create the map relating namespace URI to desired filenames. Map<String, String> namespaceUriToDesiredFilenameMap = new TreeMap<String, String>(); for (TransformSchema current : configuredTransformSchemas) { if (StringUtils.isNotEmpty(current.getToFile())) { namespaceUriToDesiredFilenameMap.put(current.getUri(), current.getToFile()); } } // Replace the schemaLocation values to correspond to the new filenames for (SimpleNamespaceResolver currentResolver : resolverMap.values()) { File generatedSchemaFile = new File(schemaDirectory, currentResolver.getSourceFilename()); Document generatedSchemaFileDocument = parseXmlToDocument(generatedSchemaFile); // Replace all namespace prefixes within the provided document. process(generatedSchemaFileDocument.getFirstChild(), true, new ChangeFilenameProcessor(namespaceUriToDesiredFilenameMap)); // Overwrite the generatedSchemaFile with the content of the generatedSchemaFileDocument. if (mavenLog.isDebugEnabled()) { mavenLog.debug("Changed schemaLocation entries within [" + currentResolver.getSourceFilename() + "]. " + "Result: [" + getHumanReadableXml(generatedSchemaFileDocument) + "]"); } savePrettyPrintedDocument(generatedSchemaFileDocument, generatedSchemaFile); } // Now, rename the actual files. for (SimpleNamespaceResolver currentResolver : resolverMap.values()) { final String localNamespaceURI = currentResolver.getLocalNamespaceURI(); if (StringUtils.isEmpty(localNamespaceURI)) { mavenLog.warn("SimpleNamespaceResolver contained no localNamespaceURI; aborting rename."); continue; } final String newFilename = namespaceUriToDesiredFilenameMap.get(localNamespaceURI); final File originalFile = new File(schemaDirectory, currentResolver.getSourceFilename()); if (StringUtils.isNotEmpty(newFilename)) { File renamedFile = FileUtils.resolveFile(schemaDirectory, newFilename); String renameResult = (originalFile.renameTo(renamedFile) ? "Success " : "Failure "); if (mavenLog.isDebugEnabled()) { String suffix = "renaming [" + originalFile.getAbsolutePath() + "] to [" + renamedFile + "]"; mavenLog.debug(renameResult + suffix); } } } }
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.//from ww w . j a v a2 s .co 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 standardDirectories If no sources are given, revert to searching all files under these standard * directories. Each path is {@code relativize()}-d to the supplied baseDir to * reach a directory path. * @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 excludePatterns An optional List of patterns used to construct an ExclusionRegExpFileFilter used to * identify files which should be excluded from the result. * @return URLs to all Files under the supplied sources (or standardDirectories, if no explicit sources * are given) which do not match the supplied Java Regular excludePatterns. */ @SuppressWarnings("all") public static List<URL> filterFiles(final File baseDir, final List<String> sources, final List<String> standardDirectories, final Log log, final String fileTypeDescription, final List<Filter<File>> excludePatterns) { final SortedMap<String, File> pathToResolvedSourceMap = new TreeMap<String, File>(); for (String current : standardDirectories) { for (File currentResolvedSource : FileSystemUtilities.filterFiles(baseDir, sources, FileSystemUtilities.relativize(current, baseDir), log, fileTypeDescription, excludePatterns)) { // Add the source pathToResolvedSourceMap.put(FileSystemUtilities.getCanonicalPath(currentResolvedSource), currentResolvedSource); } } final List<URL> toReturn = new ArrayList<URL>(); // Extract the URLs for all resolved Java sources. for (Map.Entry<String, File> current : pathToResolvedSourceMap.entrySet()) { toReturn.add(FileSystemUtilities.getUrlFor(current.getValue())); } if (log.isDebugEnabled()) { final StringBuilder builder = new StringBuilder(); builder.append("\n+=================== [Filtered " + fileTypeDescription + "]\n"); builder.append("|\n"); builder.append("| " + excludePatterns.size() + " Exclude patterns:\n"); for (int i = 0; i < excludePatterns.size(); i++) { builder.append( "| [" + (i + 1) + "/" + excludePatterns.size() + "]: " + excludePatterns.get(i) + "\n"); } builder.append("|\n"); builder.append("| " + standardDirectories.size() + " Standard Directories:\n"); for (int i = 0; i < standardDirectories.size(); i++) { builder.append("| [" + (i + 1) + "/" + standardDirectories.size() + "]: " + standardDirectories.get(i) + "\n"); } builder.append("|\n"); builder.append("| " + toReturn.size() + " Results:\n"); for (int i = 0; i < toReturn.size(); i++) { builder.append("| [" + (i + 1) + "/" + toReturn.size() + "]: " + toReturn.get(i) + "\n"); } builder.append("|\n"); builder.append("+=================== [End Filtered " + fileTypeDescription + "]\n\n"); // Log all. log.debug(builder.toString().replace("\n", AbstractJaxbMojo.NEWLINE)); } // All done. return toReturn; }
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.//www . j a v a 2 s . c om * * @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.FileSystemUtilities.java
License:Apache License
private static void checkAndAdd(final List<File> toPopulate, final File current, final List<Filter<File>> fileFilters, final boolean excludeFilterOperation, final Log log) { ///*w ww . j a v a2 s . co m*/ // When no filters are supplied... // [Include Operation]: all files will be rejected // [Exclude Operation]: all files will be included // final boolean noFilters = fileFilters == null || fileFilters.isEmpty(); final boolean addFile = excludeFilterOperation ? noFilters || Filters.rejectAtLeastOnce(current, fileFilters) : noFilters || Filters.matchAtLeastOnce(current, fileFilters); final String logPrefix = (addFile ? "Accepted " : "Rejected ") + (current.isDirectory() ? "directory" : "file") + " ["; if (addFile) { toPopulate.add(current); } if (log.isDebugEnabled()) { log.debug(logPrefix + getCanonicalPath(current) + "]"); } }
From source file:org.codehaus.mojo.jaxb2.shared.filters.AbstractFilter.java
License:Apache License
/** * {@inheritDoc}/* w w w .j av a 2s . 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 a2 s . com 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.keytool.GenkeyMojo.java
License:Apache License
private static String getJDKCommandPath(String command, Log logger) { String path = getJDKCommandExe(command).getAbsolutePath(); logger.debug(command + " executable=[" + path + "]"); return path;//from w ww. jav a2s .com }
From source file:org.codehaus.mojo.keytool.KeyToolMojoSupport.java
License:Apache License
/** * Constructs the operating system specific absolute path of the JDK command given the specified command name. * @param command the executable name //from w ww . ja v a 2 s .c om * @return a String representing the absolute path to the command. */ public static String getJDKCommandPath(String command, Log logger) { String path = getJDKCommandExe(command).getAbsolutePath(); logger.debug(command + " executable=[" + path + "]"); return path; }
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 {// ww w . jav a 2 s . c o 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; }