List of usage examples for org.apache.maven.plugin.logging Log debug
void debug(Throwable error);
From source file:org.gdms.maven.sql.AbstractGenerateSql.java
License:Open Source License
private void printProperties(Properties p) { Log log = getLog(); log.debug(" {"); for (String key : p.stringPropertyNames()) { log.debug(" " + key + " = " + p.getProperty(key)); }//from ww w.ja v a2 s .c om log.debug(" }"); }
From source file:org.gephi.maven.GenerateUtils.java
License:Apache License
protected static void addModuleToPom(File pomFile, String moduleName, Log log) throws MojoExecutionException { try {//from w w w. j av a 2 s .co m StringBuilder fileContent = new StringBuilder(); BufferedReader reader = new BufferedReader(new FileReader(pomFile)); String toAdd = " <module>modules/" + moduleName + "</module>"; String line; boolean skip = false; while ((line = reader.readLine()) != null) { if (line.contains(toAdd)) { log.debug("Found the module path, skipping to avoid duplicate"); skip = true; } if (!skip && line.contains("</modules>")) { fileContent.append(toAdd).append("\n"); log.debug("Found '</modules>' string, inserting module path"); } fileContent.append(line).append("\n"); } reader.close(); FileWriter writer = new FileWriter(pomFile); writer.append(fileContent.toString()); writer.close(); } catch (IOException ex) { throw new MojoExecutionException( "Error while reading/writing 'pom.xml' at '" + pomFile.getAbsolutePath() + "'", ex); } }
From source file:org.gephi.maven.GenerateUtils.java
License:Apache License
protected static File createFolder(File folder, Log log) { if (folder.mkdirs()) { log.debug("Created folder at '" + folder.getAbsolutePath() + "'"); }// w w w . j av a 2 s.com return folder; }
From source file:org.gephi.maven.MetadataUtils.java
License:Apache License
/** * Lookup and return the content of the README.md file for this plugin. * * @param project project//from w ww.j ava2s . com * @param log log * @return content of REDME.md file or null if not found */ protected static String getReadme(MavenProject project, Log log) { File readmePath = new File(project.getBasedir(), "README.md"); if (readmePath.exists()) { log.debug("README.md file has been found: '" + readmePath.getAbsolutePath() + "'"); try { StringBuilder builder = new StringBuilder(); LineNumberReader fileReader = new LineNumberReader(new FileReader(readmePath)); String line; while ((line = fileReader.readLine()) != null) { builder.append(line); builder.append("\n"); } log.info("File README.md with " + builder.length() + " characters has been attached to project '" + project.getName() + "'"); return builder.toString(); } catch (IOException ex) { log.error("Error while reading README.md file", ex); } } return null; }
From source file:org.gephi.maven.MetadataUtils.java
License:Apache License
/** * Lookup source code configuration or default to SCM. * * @param project project// w ww . java2 s . co m * @param log log * @return source code url or null */ protected static String getSourceCode(MavenProject project, Log log) { Plugin nbmPlugin = lookupNbmPlugin(project); if (nbmPlugin != null) { Xpp3Dom config = (Xpp3Dom) nbmPlugin.getConfiguration(); if (config != null && config.getChild("sourceCodeUrl") != null) { return config.getChild("sourceCodeUrl").getValue(); } } Scm scm = project.getScm(); if (scm != null && scm.getUrl() != null && !scm.getUrl().isEmpty()) { log.debug("SCM configuration found, with url = '" + scm.getUrl() + "'"); return scm.getUrl(); } else { } return null; }
From source file:org.gephi.maven.MetadataUtils.java
License:Apache License
/** * Use local Git repository configuration to lookup the sourcecode URL. * * @param project project/*w w w . j a v a 2 s .co m*/ * @param log log * @return source code url or null */ protected static String getSourceCodeUrlFromGit(MavenProject project, Log log) { File gitPath = new File(project.getBasedir(), ".git"); if (gitPath.exists() && gitPath.isDirectory()) { File gitPathConfig = new File(gitPath, "config"); if (gitPathConfig.exists() && gitPathConfig.isFile()) { log.debug("Git config gile located at '" + gitPathConfig.getAbsolutePath() + "'"); try { BufferedReader fileReader = new BufferedReader(new FileReader(gitPathConfig)); Pattern pattern = Pattern.compile("\\s*url = (.*)"); String line, url = null; while ((line = fileReader.readLine()) != null) { Matcher m = pattern.matcher(line); if (m.matches()) { url = m.group(1); break; } } fileReader.close(); if (url != null) { log.debug("URL found in .git/config: '" + url + "'"); if (url.startsWith("http://")) { return url; } else if (url.startsWith("git@")) { Pattern gitPattern = Pattern.compile("git@([^:]*):([^.]*).git"); Matcher gitMatcher = gitPattern.matcher(url); if (gitMatcher.matches()) { String res = "http://" + gitMatcher.group(1) + "/" + gitMatcher.group(2); log.debug("Rewrote URL to '" + res + "'"); return res; } } else { log.debug("Couldn't find a pattern in the git URL: " + url); } } } catch (IOException e) { log.error("Error while reading Git config", e); } } } else { log.debug("The .git folder couldn't be found at '" + gitPath.getAbsolutePath() + "'"); } return null; }
From source file:org.gephi.maven.ModuleUtils.java
License:Apache License
/** * Investigate modules dependencies and return a map where keys are * top-level modules and values are all modules that it depends on plus the * key module.//from w w w. ja v a 2s. c om * * @param modules list of modules * @param log log * @return map that represents the tree of modules */ protected static Map<MavenProject, List<MavenProject>> getModulesTree(List<MavenProject> modules, Log log) { Map<MavenProject, List<MavenProject>> result = new LinkedHashMap<MavenProject, List<MavenProject>>(); for (MavenProject proj : modules) { List<Dependency> dependencies = proj.getDependencies(); log.debug("Investigating the " + dependencies.size() + " dependencies of project '" + proj.getName() + "'"); // Init List<MavenProject> deps = new ArrayList<MavenProject>(); deps.add(proj); result.put(proj, deps); // Add all module-based dependencies for (Dependency d : dependencies) { for (MavenProject projDependency : modules) { if (projDependency != proj && projDependency.getArtifactId().equals(d.getArtifactId()) && projDependency.getGroupId().equals(d.getGroupId()) && projDependency.getVersion().equals(d.getVersion())) { log.debug("Found a dependency that matches another module '" + proj.getName() + "' -> '" + projDependency.getName() + "'"); deps.add(projDependency); } } } } // Remove modules that are entirely dependencies of others List<MavenProject> toBeRemoved = new ArrayList<MavenProject>(); for (MavenProject proj : modules) { List<MavenProject> projDeps = result.get(proj); for (MavenProject proj2 : modules) { if (proj != proj2) { if (result.get(proj2).containsAll(projDeps)) { log.debug("Remove '" + proj.getName() + "' from list of top modules because is a dependency of '" + proj2.getName() + "'"); toBeRemoved.add(proj); break; } } } } for (MavenProject mp : toBeRemoved) { result.remove(mp); } return result; }
From source file:org.gephi.maven.ModuleUtils.java
License:Apache License
protected static String getModuleDownloadPath(MavenProject topPlugin, List<MavenProject> modules, File directory, Log log) throws MojoExecutionException { File dest;//from ww w . java 2s .co m if (modules.size() > 1) { dest = new File(directory, topPlugin.getArtifactId() + "-" + topPlugin.getVersion() + ".zip"); log.debug("The plugin '" + topPlugin + "' is a suite, creating zip archive at '" + dest.getAbsolutePath() + "'"); // Verify files exist and add to archive try { ZipArchiver archiver = new ZipArchiver(); for (MavenProject module : modules) { File f = new File(directory, module.getArtifactId() + "-" + module.getVersion() + ".nbm"); if (!f.exists()) { throw new MojoExecutionException( "The NBM file '" + f.getAbsolutePath() + "' can't be found"); } archiver.addFile(f, f.getName()); log.debug(" Add file '" + f.getAbsolutePath() + "' to the archive"); } archiver.setCompress(false); archiver.setDestFile(dest); archiver.setForced(true); archiver.createArchive(); log.info("Created ZIP archive for project '" + topPlugin.getName() + "' at '" + dest.getAbsolutePath() + "'"); } catch (IOException ex) { throw new MojoExecutionException( "Something went wrong with the creation of the ZIP archive for project '" + topPlugin.getName() + "'", ex); } catch (ArchiverException ex) { throw new MojoExecutionException( "Something went wrong with the creation of the ZIP archive for project '" + topPlugin.getName() + "'", ex); } } else { dest = new File(directory, topPlugin.getArtifactId() + "-" + topPlugin.getVersion() + ".nbm"); log.debug("The plugin is not a suite, return nbm file '" + dest.getAbsolutePath() + "'"); } return dest.getName(); }
From source file:org.gephi.maven.ScreenshotUtils.java
License:Apache License
protected static List<Image> copyScreenshots(MavenProject mavenProject, File outputFolder, String urlPrefix, Log log) throws MojoExecutionException { File folder = new File(mavenProject.getBasedir(), "src/img"); if (folder.exists()) { log.debug("Folder '" + folder.getAbsolutePath() + "' exists"); // List images in folder File[] files = folder.listFiles(new FilenameFilter() { @Override//from www. ja v a 2 s .c o m public boolean accept(File dir, String name) { return !name.startsWith(".") && (name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".gif")) && !name.contains(THUMBNAIL_SUFFIX); } }); // Sort files alphabetically Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { return f1.getName().compareTo(f2.getName()); } }); log.debug(files.length + " images found in source folder"); // Create dest folder if (outputFolder.mkdirs()) { log.debug("Output folder '" + outputFolder.getAbsolutePath() + "' was created"); } List<Image> images = new ArrayList<Image>(); for (File file : files) { if (file.getName().contains(" ")) { throw new MojoExecutionException("Image file '" + file.getAbsolutePath() + "' contains spaces. Please rename image and try again"); } // Read original file and copy to dest folder String fileName = file.getName().substring(0, file.getName().lastIndexOf(".")) + ".png"; File imageDestFile = new File(outputFolder, fileName); try { Thumbnails.of(file).outputFormat("png").outputQuality(0.90).resizer(Resizers.NULL).scale(1.0) .toFile(imageDestFile); } catch (IOException ex) { log.error("Can't copy image file from '" + file.getAbsolutePath() + "' to '" + imageDestFile.getAbsolutePath() + "'", ex); } Image image = new Image(); image.image = urlPrefix + fileName; images.add(image); // Thumbnail path String thumFileName = file.getName().substring(0, file.getName().lastIndexOf(".")) + THUMBNAIL_SUFFIX + ".png"; File thumbFile = new File(outputFolder, thumFileName); if (!thumbFile.exists()) { // Thumbnail creation try { Thumbnails.of(file).outputFormat("png").outputQuality(0.90).size(140, 140) .crop(Positions.CENTER).toFile(thumbFile); log.debug("Created thumbnail in file '" + thumbFile.getAbsolutePath() + "'"); image.thumbnail = urlPrefix + thumFileName; } catch (IOException ex) { log.error("Can't create thumbnail for image file '" + file.getAbsolutePath() + "'", ex); } } log.info("Attached image '" + file.getName() + "' to plugin " + mavenProject.getName()); } return images; } else { log.debug("Folder '" + folder.getAbsolutePath() + "' was not found"); } return null; }
From source file:org.glassfish.maven.plugin.command.AbstractAsadminCommand.java
License:Open Source License
public void execute(ProcessBuilder processBuilder) throws MojoExecutionException, MojoFailureException { List<String> commandLine = new ArrayList<String>(getParameters()); File binDir = new File(sharedContext.getGlassfishDirectory(), "bin"); File asadmin = new File(binDir, "asadmin"); // bnevins 9/13/11 -- the install may have both asadmin and asadmin.bat // if we are on Windows - then prefer the .bat file and explicitly set it. // o/w windows will attempt running the UNIX script which is trouble! // http://java.net/jira/browse/MAVEN_GLASSFISH_PLUGIN-5 if (System.getProperty("os.name").contains("indows")) { File asadminBat = new File(binDir, "asadmin.bat"); if (asadminBat.exists()) { asadmin = asadminBat;// ww w . jav a 2 s .c o m } } commandLine.addAll(0, Arrays.asList(asadmin.getAbsolutePath(), getName(), "--echo=" + sharedContext.isEcho(), "--terse=" + sharedContext.isTerse())); Log log = sharedContext.getLog(); log.debug(commandLine.toString()); processBuilder.command(commandLine); try { int exitValue; Process process = processBuilder.start(); processOut = process.getInputStream(); processErr = process.getErrorStream(); BufferedReader outReader = new BufferedReader(new InputStreamReader(processOut)); do { try { exitValue = process.exitValue(); break; } catch (IllegalThreadStateException e) { Thread.sleep(PROCESS_LOOP_SLEEP_MILLIS); } finally { doReadOutput(outReader); } } while (true); if (exitValue != EXIT_SUCCESS) { BufferedReader errorReader = new BufferedReader(new InputStreamReader(processErr)); doReadError(errorReader); String errorMessage = getErrorMessage(); log.error(errorMessage); log.error( "For more detail on what might be causing the problem try running maven with the --debug option "); log.error("or setting the maven-glassfish-plugin \"echo\" property to \"true\"."); throw new MojoFailureException(errorMessage); } } catch (IOException e) { throw new MojoExecutionException(getErrorMessage() + " IOException: " + e.getMessage()); } catch (InterruptedException e) { throw new MojoExecutionException(getErrorMessage() + " Process was interrupted: " + e.getMessage()); } }