List of usage examples for org.apache.maven.plugin.logging Log debug
void debug(Throwable error);
From source file:org.phpmaven.core.ExecutionUtils.java
License:Apache License
/** * Searches for the executable in system path. * @param log logging (maybe null)/*from www . j a v a2 s . c om*/ * @param executable executable name * @param path the path to be searched for (must not be null) * @param preferWindowsExecutable true to prefer windows file extensions (exe etc.) * @return executable path or null if it cannot be found */ public static String searchExecutable(Log log, String executable, String path, boolean preferWindowsExecutable) { if (log != null) { log.debug("searching for " + executable + " in PATH: " + path); } final String[] paths = path.split(File.pathSeparator); final File exec = new File(executable); if (exec.exists()) { return exec.getAbsolutePath(); } for (int i = 0; i < paths.length; i++) { // if not prefer windows executable search without extension first if (!preferWindowsExecutable) { final File file = new File(paths[i], executable); if (file.isFile()) { return file.getAbsolutePath(); } } // search with extension if (isWindows()) { for (final String suffix : WIN_SUFFIXES) { final File file2 = new File(paths[i], executable + "." + suffix); if (file2.isFile()) { return file2.getAbsolutePath(); } } } // if windows extensions are preferred search without if (preferWindowsExecutable) { final File file = new File(paths[i], executable); if (file.isFile()) { return file.getAbsolutePath(); } } } return null; }
From source file:org.phpmaven.phpdoc.impl.AbstractPhpdocSupport.java
License:Apache License
/** * Writes an ini log file.// w w w . j a va 2s . c o m * @param log log * @param request request * @param phpDocConfigFile phpdoc config file * @param generatedPhpDocConfigFile * @throws IOException io exception * @throws PhpCoreException php core exception */ protected void writeIni(Log log, IPhpdocRequest request, File phpDocConfigFile, File generatedPhpDocConfigFile) throws IOException, PhpCoreException { final Properties properties = new Properties(); if (phpDocConfigFile.isFile()) { log.debug("generating phpdoc using config from " + phpDocConfigFile.getAbsolutePath()); properties.load(new FileInputStream(phpDocConfigFile)); } else { log.debug("config file " + phpDocConfigFile.getAbsolutePath() + " not found. ignoring."); } final Iterator<IPhpdocEntry> iter = request.getEntries().iterator(); final IPhpdocEntry entry = iter.next(); if (entry.getType() == EntryType.FILE) { log.error("Report generation for files not supported."); // TODO support it throw new PhpCoreException("Report generation for files not supported."); } if (iter.hasNext()) { log.error("Report generation for multiple source folders not supported."); // TODO support it throw new PhpCoreException("Report generation for multiple folders not supported."); } properties.put("directory", entry.getFile().getAbsolutePath()); properties.put("target", request.getReportFolder().getAbsolutePath()); this.writePropFile(properties, "[Parse Data]", generatedPhpDocConfigFile); }
From source file:org.phpmaven.phpdoc.impl.PhpdocBatchSupport.java
License:Apache License
/** * {@inheritDoc}//from www .j a v a 2 s. c om */ @Override public void generateReport(Log log, IPhpdocRequest request) throws PhpException { try { final IPhpExecutable exec = this.factory .lookup(IPhpExecutableConfiguration.class, this.executableConfig, this.session) .getPhpExecutable(); if (this.phpdocVersion.startsWith("1.")) { writeIni(log, request, phpDocConfigFile, generatedPhpDocConfigFile); } else { writeXml(log, request, phpDocConfigFile, generatedPhpDocConfigFile); } final String path = System.getProperty("java.library.path") + File.pathSeparator + System.getenv("PATH"); log.debug("PATH: " + path); final String[] paths = path.split(File.pathSeparator); File phpDocFile = null; if ("phpdoc".equals(phpDocFilePath)) { for (int i = 0; i < paths.length; i++) { final File file = new File(paths[i], "phpdoc"); if (file.isFile()) { phpDocFile = file; break; } } } else { phpDocFile = new File(phpDocFilePath); } if (phpDocFile == null || !phpDocFile.isFile()) { throw new PhpCoreException("phpdoc not found in path"); } String command = "\"" + phpDocFile + "\" -c \"" + generatedPhpDocConfigFile.getAbsolutePath() + "\""; if (arguments != null && arguments.length() > 0) { command += " " + arguments; } log.debug("Executing PHPDocumentor: " + command); // XXX: commandLine.setWorkingDirectory(phpDocFile.getParent()); String result; try { result = exec.execute(command, phpDocFile); } catch (PhpWarningException ex) { result = ex.getAppendedOutput(); // silently ignore; only errors are important } for (final String line : result.split("\n")) { if (line.startsWith("ERROR:")) { // this is a error of phpdocumentor. log.error("Got error from php-documentor. " + "Enable debug (-X) to fetch the php output.\n" + line); throw new PhpErrorException(phpDocFile, line); } } } catch (PlexusConfigurationException ex) { throw new PhpCoreException("Errors invoking phpdoc", ex); } catch (IOException ex) { throw new PhpCoreException("Errors invoking phpdoc", ex); } catch (ComponentLookupException ex) { throw new PhpCoreException("Errors invoking phpdoc", ex); } }
From source file:org.phpmaven.phpdoc.impl.PhpdocPearSupport.java
License:Apache License
/** * {@inheritDoc}//ww w . j a v a 2 s.c o m */ @Override public void generateReport(Log log, IPhpdocRequest request) throws PhpException { try { final Xpp3Dom dom = new Xpp3Dom("configuration"); if (this.executableConfig != null) { // final Xpp3Dom configNode = new Xpp3Dom("executableConfig"); // configNode.addChild(executableConfig); dom.addChild(this.executableConfig); } final IMavenPearUtility util = this.factory.lookup(IPearConfiguration.class, dom, this.session) .getUtility(log); if (!util.isInstalled()) { util.installPear(false); } // do not try to read remote channels; so that we will work in offline mode etc. util.initChannels(false); boolean disableDeprecatedWarning = false; if (this.phpdocVersion.startsWith("1.")) { writeIni(log, request, phpDocConfigFile, generatedPhpDocConfigFile); util.installFromMavenRepository("net.php", "PhpDocumentor", this.phpdocVersion); disableDeprecatedWarning = true; } else { writeXml(log, request, phpDocConfigFile, generatedPhpDocConfigFile); // there is a very strange dependency mismatching in phpdoc. // an unknown version 0.17.0 is used as dependency for various things. // however it does not really work; maybe we need an empty dummy package. util.installFromMavenRepository("org.phpdoc", "phpDocumentor", "0.17.0"); util.installFromMavenRepository("org.phpdoc", "phpDocumentor", this.phpdocVersion); } String phpDoc = ExecutionUtils.searchExecutable(log, "phpdoc.php", util.getBinDir().getAbsolutePath()); if (phpDoc == null) { phpDoc = ExecutionUtils.searchExecutable(log, "phpdoc", util.getBinDir().getAbsolutePath(), false); if (phpDoc == null) { throw new PhpCoreException("phpdoc not found in path (" + util.getBinDir() + ")"); } } String command = "-c \"" + generatedPhpDocConfigFile.getAbsolutePath() + "\""; if (arguments != null && arguments.length() > 0) { command += " " + arguments; } log.debug("Executing PHPDocumentor with args: " + command); // XXX: commandLine.setWorkingDirectory(phpDocFile.getParent()); String result; try { if (!phpDoc.endsWith(".bat")) { final IPhpExecutableConfiguration config = this.factory .lookup(IPhpExecutableConfiguration.class, this.executableConfig, this.session); // phpdoc overwrites error_reporting. we need to hack if we plan to overwrite it by ourselves. final String newErrorReporting = config.getNumErrorReporting() == -1 ? (disableDeprecatedWarning ? "E_ALL & !E_DEPRECATED" : null) : String.valueOf(config.getNumErrorReporting()); // try to find phpdoc.inc final File phpDocInc = new File(util.getPhpDir(), "PhpDocumentor/phpDocumentor/phpdoc.inc"); if (newErrorReporting != null) { log.debug("setting error reporting to " + newErrorReporting); log.debug("using phpdoc.inc at " + phpDocInc); config.setErrorReporting(newErrorReporting); } config.getIncludePath().add(util.getPhpDir().getAbsolutePath()); if (newErrorReporting == null || !phpDocInc.exists()) { // direct execution final IPhpExecutable exec = config.getPhpExecutable(); result = exec.execute("\"" + phpDoc + "\" " + command, new File(phpDoc)); } else { // try to hack the deprecated warning config.getIncludePath().add(phpDocInc.getParentFile().getParentFile().getAbsolutePath()); final IPhpExecutable exec = config.getPhpExecutable(); result = exec.executeCode("", PHPDOC_INC, command); } } else { final Commandline commandLine = new Commandline("\"" + phpDoc + "\" " + command); final StringBuilder stdout = new StringBuilder(); final StringBuilder stderr = new StringBuilder(); CommandLineUtils.executeCommandLine(commandLine, new StreamConsumer() { @Override public void consumeLine(String line) { stdout.append(line); stdout.append("\n"); } }, new StreamConsumer() { @Override public void consumeLine(String line) { stderr.append(line); stderr.append("\n"); } }); result = stdout.toString(); log.debug("phpdoc output:\n" + result); } } catch (PhpWarningException ex) { result = ex.getAppendedOutput(); // silently ignore; only errors are important } for (final String line : result.split("\n")) { if (line.startsWith("ERROR:")) { // this is a error of phpdocumentor. log.error("Got error from php-documentor. " + "Enable debug (-X) to fetch the php output.\n" + line); throw new PhpErrorException(new File(phpDoc), line); } } } catch (PlexusConfigurationException ex) { throw new PhpCoreException("Errors invoking phpdoc", ex); } catch (IOException ex) { throw new PhpCoreException("Errors invoking phpdoc", ex); } catch (ComponentLookupException ex) { throw new PhpCoreException("Errors invoking phpdoc", ex); } catch (CommandLineException ex) { throw new PhpCoreException("Errors invoking phpdoc", ex); } }
From source file:org.phpmaven.phpdoc.impl.PhpdocSupport.java
License:Apache License
/** * {@inheritDoc}//from www .j a va 2s .c om */ @Override public void generateReport(Log log, IPhpdocRequest request) throws PhpException { try { final IPhpExecutable exec = this.factory .lookup(IPhpExecutableConfiguration.class, this.executableConfig, this.session) .getPhpExecutable(log); writeIni(log, request, phpDocConfigFile, generatedPhpDocConfigFile); final String path = System.getProperty("java.library.path") + File.pathSeparator + System.getenv("PATH"); log.debug("PATH: " + path); final String[] paths = path.split(File.pathSeparator); File phpDocFile = null; if ("phpdoc".equals(phpDocFilePath)) { for (int i = 0; i < paths.length; i++) { final File file = new File(paths[i], "phpdoc"); if (file.isFile()) { phpDocFile = file; break; } } } else { phpDocFile = new File(phpDocFilePath); } if (phpDocFile == null || !phpDocFile.isFile()) { throw new PhpCoreException("phpdoc not found in path"); } final String command = "\"" + phpDocFile + "\" -c \"" + generatedPhpDocConfigFile.getAbsolutePath() + "\""; log.debug("Executing PHPDocumentor: " + command); // XXX: commandLine.setWorkingDirectory(phpDocFile.getParent()); final String result = exec.execute(command, phpDocFile); for (final String line : result.split("\n")) { if (line.startsWith("ERROR:")) { // this is a error of phpdocumentor. log.error("Got error from php-documentor. " + "Enable debug (-X) to fetch the php output.\n" + line); throw new PhpErrorException(phpDocFile, line); } } } catch (PlexusConfigurationException ex) { throw new PhpCoreException("Errors invoking phpdoc", ex); } catch (IOException ex) { throw new PhpCoreException("Errors invoking phpdoc", ex); } catch (ComponentLookupException ex) { throw new PhpCoreException("Errors invoking phpdoc", ex); } }
From source file:org.phpmaven.phpnar.CompileMojo.java
License:Apache License
/** * Executes a command./* w w w .j ava2 s.c o m*/ * @param log the logger * @param command command line * @param workDir working directory * @throws CommandLineException throw on execution errors. */ private static void executeCommand(final Log log, final String command, final File workDir) throws CommandLineException { final Commandline cli = new Commandline(command); if (log != null) { log.debug("Executing " + command); } if (workDir != null) { if (!workDir.exists()) { workDir.mkdirs(); } cli.setWorkingDirectory(workDir); } final StreamConsumer systemOut = new StreamConsumer() { @Override public void consumeLine(String line) { log.info(line); } }; final StreamConsumer systemErr = new StreamConsumer() { @Override public void consumeLine(String line) { log.warn(line); } }; try { final int result = CommandLineUtils.executeCommandLine(cli, systemOut, systemErr); if (result != 0) { if (log != null) { log.warn("Error invoking command. Return code " + result); } throw new CommandLineException("Error invoking command. Return code " + result); } } catch (CommandLineException ex) { if (log != null) { log.warn("Error invoking command"); } throw ex; } }
From source file:org.phpmaven.plugin.build.FileHelper.java
License:Apache License
/** * Unzips all files to the given directory (using jar). * * @param log Logging//w ww .j a v a2 s. c o m * @param targetDirectory where to unpack the files to * @param elements list of files to unpack * @param factory component factory * @param session maven session * @throws IOException if something goes wrong while copying */ public static void unzipElements(Log log, File targetDirectory, List<String> elements, IComponentFactory factory, MavenSession session) throws IOException { Preconditions.checkArgument(!targetDirectory.exists() || targetDirectory.isDirectory(), "Destination Directory"); targetDirectory.mkdirs(); if (!targetDirectory.exists()) { throw new IllegalStateException( "Could not create target directory " + targetDirectory.getAbsolutePath()); } log.debug(elements.toString()); for (String element : elements) { log.debug("unpacking " + element); final File sourceFile = new File(element); if (sourceFile.isFile()) { final int pos = sourceFile.getName().lastIndexOf('.'); String extension = sourceFile.getName(); if (pos != -1) { extension = extension.substring(pos + 1); } if ("jar".equals(extension)) { // for backward compatibility to phpmaven1; there we build jar instead of phar unjar(log, sourceFile, targetDirectory); } else if ("phar".equals(extension)) { unphar(log, targetDirectory, factory, session, sourceFile); } else if ("zip".equals(extension)) { // although jar and zips are compatible to each other this is a implementation detail of jvm. // we should not depend on it. so let us divide it. unzip(log, sourceFile, targetDirectory); } else { throw new IOException( "Unknown archive format. Unable to extract " + sourceFile.getAbsolutePath()); } } } }
From source file:org.phpmaven.plugin.build.FileHelper.java
License:Apache License
/** * Unphar given file to destination directory. * /* w ww . j av a 2 s . c om*/ * @param log Logging * @param targetDirectory where to unpack the files to * @param factory component factory * @param session maven session * @param sourceFile the jar source file * @throws IOException if something goes wrong while copying */ public static void unphar(Log log, File targetDirectory, IComponentFactory factory, final MavenSession session, final File sourceFile) throws IOException { log.debug("unphar " + sourceFile.getAbsolutePath()); try { final IPharPackagerConfiguration config = factory.lookup(IPharPackagerConfiguration.class, IComponentFactory.EMPTY_CONFIG, session); config.getPharPackager().extractPharTo(sourceFile, targetDirectory, log); } catch (ComponentLookupException e) { throw new IOException( "Error while execution unphar script. Unable to extract " + sourceFile.getAbsolutePath(), e); } catch (PlexusConfigurationException e) { throw new IOException( "Error while execution unphar script. Unable to extract " + sourceFile.getAbsolutePath(), e); } catch (PhpException e) { throw new IOException( "Error while execution unphar script. Unable to extract " + sourceFile.getAbsolutePath(), e); } }
From source file:org.phpmaven.plugin.build.FileHelper.java
License:Apache License
/** * Unpacks a jar file.//from w ww . j a v a2 s. c o m * * @param log Logging * @param jarFile the jar file * @param destDir the destination directory * @throws IOException if something goes wrong */ public static void unjar(Log log, File jarFile, File destDir) throws IOException { Preconditions.checkNotNull(jarFile, "JarFile"); final JarFile jar = new JarFile(jarFile); log.debug("unjar " + jarFile.getAbsolutePath()); final Enumeration<JarEntry> items = jar.entries(); while (items.hasMoreElements()) { final JarEntry entry = items.nextElement(); unpackJarEntry(entry, jar.getInputStream(entry), destDir); } }
From source file:org.phpmaven.plugin.build.FileHelper.java
License:Apache License
/** * Unpacks a zip file.//from w w w .jav a 2s. c o m * * @param log Logging * @param zipFile the zip file * @param destDir the destination directory * @throws IOException if something goes wrong */ public static void unzip(Log log, File zipFile, File destDir) throws IOException { Preconditions.checkNotNull(zipFile, "ZipFile"); final ZipFile zip = new ZipFile(zipFile); log.debug("unzip " + zipFile.getAbsolutePath()); final Enumeration<? extends ZipEntry> items = zip.entries(); while (items.hasMoreElements()) { final ZipEntry entry = items.nextElement(); unpackZipEntry(entry, zip.getInputStream(entry), destDir); } }