List of usage examples for org.apache.maven.plugin.logging Log debug
void debug(Throwable error);
From source file:org.codehaus.mojo.rpm.RPMHelper.java
License:Apache License
/** * Gets the default host vendor for system by executing <i>rpm -E %{_host_vendor}</i>. *//*from w w w.j a v a 2 s .c o m*/ public String getHostVendor() throws MojoExecutionException { final Log log = mojo.getLog(); final Commandline cl = new Commandline(); cl.setExecutable("rpm"); cl.addArguments(new String[] { "-E", "%{_host_vendor}" }); final StringStreamConsumer stdout = new StringStreamConsumer(); final StreamConsumer stderr = new LogStreamConsumer(LogStreamConsumer.INFO, log); try { if (log.isDebugEnabled()) { log.debug("About to execute \'" + cl.toString() + "\'"); } int result = CommandLineUtils.executeCommandLine(cl, stdout, stderr); if (result != 0) { throw new MojoExecutionException("RPM query for default vendor returned: \'" + result + "\' executing \'" + cl.toString() + "\'"); } } catch (CommandLineException e) { throw new MojoExecutionException("Unable to query for default vendor from RPM", e); } return stdout.getOutput().trim(); }
From source file:org.codehaus.mojo.rpm.RPMHelper.java
License:Apache License
/** * Run the external command to build the package. * <p>/*from ww w . j a v a 2 s. com*/ * Uses the following attributes from the {@link #mojo}: * <ul> * <li>{@link AbstractRPMMojo#getBuildroot() build root}</li> * <li>{@link AbstractRPMMojo#getKeyname() key name}</li> * <li>{@link AbstractRPMMojo#getKeyPassphrase() key passphrase}</li> * <li>{@link AbstractRPMMojo#getName() name}</li> * <li>{@link AbstractRPMMojo#getRPMFile() rpm file}</li> * <li>{@link AbstractRPMMojo#getTargetArch() target arch}</li> * <li>{@link AbstractRPMMojo#getTargetOS() target OS}</li> * <li>{@link AbstractRPMMojo#getTargetVendor() target vendor}</li> * <li>{@link AbstractRPMMojo#getWorkarea() workarea}</li> * </ul> * </p> * * @throws MojoExecutionException if an error occurs */ public void buildPackage() throws MojoExecutionException { final File workarea = mojo.getWorkarea(); final File f = new File(workarea, "SPECS"); final Commandline cl = new Commandline(); cl.setExecutable("rpmbuild"); cl.setWorkingDirectory(f.getAbsolutePath()); cl.createArg().setValue(mojo.getRpmbuildStage()); cl.createArg().setValue("--target"); cl.createArg().setValue(mojo.getTargetArch() + '-' + mojo.getTargetVendor() + '-' + mojo.getTargetOS()); cl.createArg().setValue("--buildroot"); cl.createArg().setValue(FileHelper.toUnixPath(mojo.getRPMBuildroot())); cl.createArg().setValue("--define"); cl.createArg().setValue("_topdir " + FileHelper.toUnixPath(workarea)); // Don't assume default values for rpm path macros cl.createArg().setValue("--define"); cl.createArg().setValue("_build_name_fmt %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm"); cl.createArg().setValue("--define"); cl.createArg().setValue("_builddir %{_topdir}/BUILD"); cl.createArg().setValue("--define"); cl.createArg().setValue("_rpmdir %{_topdir}/RPMS"); cl.createArg().setValue("--define"); cl.createArg().setValue("_sourcedir %{_topdir}/SOURCES"); cl.createArg().setValue("--define"); cl.createArg().setValue("_specdir %{_topdir}/SPECS"); cl.createArg().setValue("--define"); cl.createArg().setValue("_srcrpmdir %{_topdir}/SRPMS"); // maintain passive behavior for keyPassphrase not being present final String keyname = mojo.getKeyname(); final File keypath = mojo.getKeypath(); final Passphrase keyPassphrase = mojo.getKeyPassphrase(); if (keyname != null && keyPassphrase == null) { cl.createArg().setValue("--define"); cl.createArg().setValue("_gpg_name " + keyname); if (keypath != null) { cl.createArg().setValue("--define"); cl.createArg().setValue("_gpg_path " + keypath); } cl.createArg().setValue("--sign"); } cl.createArg().setValue(mojo.getName() + ".spec"); final Log log = mojo.getLog(); final StreamConsumer stdout = new LogStreamConsumer(LogStreamConsumer.INFO, log); final StreamConsumer stderr = new LogStreamConsumer(LogStreamConsumer.INFO, log); try { if (log.isDebugEnabled()) { log.debug("About to execute \'" + cl.toString() + "\'"); } int result = CommandLineUtils.executeCommandLine(cl, stdout, stderr); if (result != 0) { throw new MojoExecutionException( "RPM build execution returned: \'" + result + "\' executing \'" + cl.toString() + "\'"); } } catch (CommandLineException e) { throw new MojoExecutionException("Unable to build the RPM", e); } // now if the passphrase has been provided and we want to try and sign automatically if (keyname != null && keyPassphrase != null) { RPMSigner signer = new RPMSigner(keypath, keyname, keyPassphrase.getPassphrase(), log); try { signer.sign(mojo.getRPMFile()); } catch (Exception e) { throw new MojoExecutionException("Unable to sign RPM", e); } } }
From source file:org.codehaus.mojo.rpm.RPMHelper.java
License:Apache License
/** * Evaluates the <i>macro</i> by executing <code>rpm --eval %<i>macro</i></code>. * * @param macro The macro to evaluate.//from w w w . ja va 2 s . c o m * @return The result of rpm --eval. * @throws MojoExecutionException * @since 2.1-alpha-1 */ public String evaluateMacro(String macro) throws MojoExecutionException { final Commandline cl = new Commandline(); cl.setExecutable("rpm"); cl.createArg().setValue("--eval"); cl.createArg().setValue('%' + macro); final Log log = mojo.getLog(); final StringStreamConsumer stdout = new StringStreamConsumer(); final StreamConsumer stderr = new LogStreamConsumer(LogStreamConsumer.INFO, log); try { if (log.isDebugEnabled()) { log.debug("About to execute \'" + cl.toString() + "\'"); } int result = CommandLineUtils.executeCommandLine(cl, stdout, stderr); if (result != 0) { throw new MojoExecutionException( "rpm --eval returned: \'" + result + "\' executing \'" + cl.toString() + "\'"); } } catch (CommandLineException e) { throw new MojoExecutionException("Unable to evaluate macro: " + macro, e); } return stdout.getOutput().trim(); }
From source file:org.codehaus.mojo.rpm.SpecWriter.java
License:Apache License
/** * Writes the %files directive based on {@link AbstractRPMMojo#mappings}. *//*from ww w .ja v a 2 s . c o m*/ private void writeFiles() { final Log log = mojo.getLog(); spec.println(); spec.println("%files"); spec.println(getDefAttrString()); for (Mapping map : mojo.getMappings()) { // For each mapping we need to determine which files in the destination were defined by this // mapping so that we can write the %attr statement correctly. final String destination = map.getDestination(); final File absoluteDestination = map.getAbsoluteDestination(); final String attrString = map.getAttrString(mojo.getDefaultFilemode(), mojo.getDefaultGroupname(), mojo.getDefaultUsername()); final String baseFileString = attrString + " \"" + destination + FileHelper.UNIX_FILE_SEPARATOR; if (map.hasSoftLinks() && !absoluteDestination.exists()) { // @TODO will this ever happen since absoluteDestination.exists() always likely true log.debug("writing attribute string for directory created by soft link: " + destination); spec.println(attrString + " \"" + destination + "\""); continue; } final List<String> links = map.getLinkedFileNamesRelativeToDestination(); if (map.isSoftLinkOnly()) { // map has only soft links, no need to do the scan (MRPM-173) log.debug("writing attribute string for softlink only source"); for (String link : links) { spec.print(baseFileString); spec.println(link + "\""); } continue; } // special handling for single map source directory with lots of files such UI/Nodejs // without the need for slow scanner which can be up 10 of minutes for large set if (map.isSourceDirsOnly() && map.isDirectoryIncluded() && !map.isRecurseDirectories()) { boolean simpleDir = true; for (Source source : map.getSources()) { if (!source.isSingleDir()) { simpleDir = false; break; } } if (simpleDir) { log.debug("writing attribute string for directory: " + destination); spec.println(attrString + " \"" + destination + "\""); continue; } } final List<String> includes = map.getCopiedFileNamesRelativeToDestination(); log.debug("scanning: " + absoluteDestination); final DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(absoluteDestination); // the linked files are not present yet (will be "installed" during rpm build) // so they cannot be "included" scanner.setIncludes(includes.isEmpty() ? null : includes.toArray(new String[includes.size()])); scanner.setExcludes(null); scanner.scan(); if (scanner.isEverythingIncluded() && links.isEmpty() && map.isDirectoryIncluded() && !map.isRecurseDirectories()) { log.debug("writing attribute string for directory: " + destination); spec.println(attrString + " \"" + destination + "\""); } else { log.debug("writing attribute string for identified files in directory: " + destination); // only list files if requested (directoryIncluded == false) or we have to if (!(map.isDirectoryIncluded() && scanner.isEverythingIncluded() && links.isEmpty() && !map.isRecurseDirectories())) { final String[] files = scanner.getIncludedFiles(); for (String file : files) { spec.print(baseFileString); spec.println(StringUtils.replace(file, "\\", "/") + "\""); } } if (map.isRecurseDirectories()) { final String[] dirs = scanner.getIncludedDirectories(); if (map.isDirectoryIncluded()) { // write out destination first spec.print("%dir "); spec.println(baseFileString + "\""); } for (String dir : dirs) { // do not write out base file (destination) again if (dir.length() > 0) { spec.print("%dir "); spec.print(baseFileString); spec.println(StringUtils.replace(dir, "\\", "/") + "\""); } } } // since the linked files are not present in directory (yet), the scanner will not find them for (String link : links) { spec.print(baseFileString); spec.println(link + "\""); } } } }
From source file:org.codehaus.mojo.smc.DotConvertor.java
License:Apache License
/** * Convert the specified .dot files to the specified formats using the graphviz tool * @param file/*from w w w . j a v a 2s . co m*/ * @param format e.g. "png", "gif" * @param log */ public static int convert(File file, String format, Log log) throws CommandLineException { Commandline cl = new Commandline(); cl.setExecutable("dot"); cl.createArgument().setValue("-T" + format); cl.createArgument().setValue("-o"); cl.createArgument().setValue(file.getAbsolutePath().replace(".dot", "." + format)); cl.createArgument().setValue(file.getAbsolutePath()); log.debug("executing: " + cl.toString()); CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); int exitCode = CommandLineUtils.executeCommandLine(cl, stdout, stderr); String output = stdout.getOutput(); if (output.length() > 0) { log.debug(output); } String errOutput = stderr.getOutput(); if (errOutput.length() > 0) { log.warn(errOutput); } return exitCode; }
From source file:org.codehaus.mojo.sysdeo.ide.ReadWorkspaceLocations.java
License:Apache License
/** * Read the artefact information from the pom in the project location and the eclipse project name from the .project * file.//from w ww .j a v a 2 s . c om * * @param projectLocation the location of the project * @param logger the logger to report errors and debug info. * @return an {@link IdeDependency} or null. * @throws XmlPullParserException * @throws IOException */ private IdeDependency readArtefact(String projectLocation, Log logger) throws XmlPullParserException, IOException { File baseDir = new File(projectLocation); File projectFile = new File(baseDir, ".project"); String eclipseProjectName = baseDir.getName(); if (projectFile.exists()) { Xpp3Dom project = Xpp3DomBuilder.build(new FileReader(projectFile)); eclipseProjectName = getValue(project, new String[] { "name" }, eclipseProjectName); } File pomFile = new File(baseDir, "pom.xml"); if (pomFile.exists()) { Xpp3Dom pom = Xpp3DomBuilder.build(new FileReader(pomFile)); String artifact = getValue(pom, ARTEFACT_ID, null); String group = getValue(pom, GROUP_ID, getValue(pom, PARENT_GROUP_ID, null)); String version = getValue(pom, VERSION, getValue(pom, PARENT_VERSION, null)); String classifier = getValue(pom, CLASSIFIER, getValue(pom, PARENT_CLASSIFIER, null)); String packaging = getValue(pom, PACKAGING, "jar"); logger.debug("found workspace artefact " + group + ":" + artifact + ":" + version + " " + packaging + " (" + eclipseProjectName + ")" + " -> " + projectLocation); String output = getOutputDirectory(baseDir); return new IdeDependency(group, artifact, version, classifier, null, true, false, null, packaging, output, null); } else { logger.debug("ignored workspace project NO pom available " + projectLocation); return null; } }
From source file:org.codehaus.mojo.sysdeo.ide.ReadWorkspaceLocations.java
License:Apache License
/** * Scan the eclipse workspace and create a array with {@link IdeDependency} for all found artifacts. * * @param workspaceLocation the location of the eclipse workspace. * @param logger the logger to report errors and debug info. */// w ww . j av a 2 s . co m public List readWorkspace(File workspacePath, Log logger) { ArrayList dependencys = new ArrayList(); if (workspacePath != null) { File workspace = new File(workspacePath, ReadWorkspaceLocations.METADATA_PLUGINS_ORG_ECLIPSE_CORE_RESOURCES_PROJECTS); File[] directories = workspace.listFiles(); for (int index = 0; directories != null && index < directories.length; index++) { File project = directories[index]; if (project.isDirectory()) { try { String projectLocation = getProjectLocation(workspacePath, project); if (projectLocation != null) { IdeDependency ideDependency = readArtefact(projectLocation, logger); if (ideDependency != null) { logger.debug("Read workspace project " + ideDependency); ideDependency.setIdeProjectName(project.getName()); dependencys.add(ideDependency); } } } catch (Exception e) { logger.warn("could not read workspace project:" + project, e); } } } } return dependencys; }
From source file:org.codehaus.mojo.versions.api.DefaultVersionsHelper.java
License:Apache License
private static RuleSet loadRuleSet(String serverId, Settings settings, WagonManager wagonManager, String rulesUri, Log logger) throws MojoExecutionException { RuleSet ruleSet = new RuleSet(); if (rulesUri != null && rulesUri.trim().length() != 0) { try {// www .jav a2s.c o m int split = rulesUri.lastIndexOf('/'); String baseUri; String fileUri; if (split != -1) { baseUri = rulesUri.substring(0, split) + '/'; fileUri = split + 1 < rulesUri.length() ? rulesUri.substring(split + 1) : ""; } else { baseUri = rulesUri; fileUri = ""; } try { Wagon wagon = WagonUtils.createWagon(serverId, baseUri, wagonManager, settings, logger); try { logger.debug("Trying to load ruleset from file \"" + fileUri + "\" in " + baseUri); final RuleSet loaded = getRuleSet(wagon, fileUri); ruleSet.setRules(loaded.getRules()); ruleSet.setIgnoreVersions(loaded.getIgnoreVersions()); logger.debug("Rule set loaded"); } finally { if (wagon != null) { try { wagon.disconnect(); } catch (ConnectionException e) { logger.warn("Could not disconnect wagon!", e); } } } } catch (TransferFailedException e) { throw new MojoExecutionException("Could not transfer rules from " + rulesUri, e); } catch (AuthorizationException e) { throw new MojoExecutionException("Authorization failure trying to load rules from " + rulesUri, e); } catch (ResourceDoesNotExistException e) { throw new MojoExecutionException("Could not load specified rules from " + rulesUri, e); } catch (AuthenticationException e) { throw new MojoExecutionException("Authentication failure trying to load rules from " + rulesUri, e); } catch (UnsupportedProtocolException e) { throw new MojoExecutionException("Unsupported protocol for " + rulesUri, e); } catch (ConnectionException e) { throw new MojoExecutionException("Could not establish connection to " + rulesUri, e); } } catch (IOException e) { throw new MojoExecutionException("Could not load specified rules from " + rulesUri, e); } } return ruleSet; }
From source file:org.codehaus.mojo.versions.api.PomHelper.java
License:Apache License
/** * Returns a set of all child modules for a project, including any defined in profiles (ignoring profile * activation)./*from ww w . j av a 2 s . c om*/ * * @param model The project model. * @param logger The logger to use. * @return the set of all child modules of the project. */ public static Set<String> getAllChildModules(Model model, Log logger) { logger.debug("Finding child modules..."); Set<String> childModules = new TreeSet<String>(); childModules.addAll(model.getModules()); for (Profile profile : model.getProfiles()) { childModules.addAll(profile.getModules()); } debugModules(logger, "Child modules:", childModules); return childModules; }
From source file:org.codehaus.mojo.versions.api.PomHelper.java
License:Apache License
/** * Outputs a debug message with a list of modules. * * @param logger The logger to log to.//from w w w . j av a2 s. c o m * @param message The message to display. * @param modules The modules to append to the message. */ public static void debugModules(Log logger, String message, Collection modules) { Iterator i; if (logger.isDebugEnabled()) { logger.debug(message); if (modules.isEmpty()) { logger.debug("None."); } else { i = modules.iterator(); while (i.hasNext()) { logger.debug(" " + i.next()); } } } }