List of usage examples for org.apache.maven.plugin.logging Log debug
void debug(Throwable error);
From source file:net.sf.buildbox.maven.contentcheck.LicenseShowMojo.java
License:Open Source License
private List<MavenProject> getMavenProjectForDependencies() throws MojoExecutionException, MojoFailureException { DependencyNode dependencyTreeNode = resolveProject(); MavenProject project = getMavenProject(); Dependencies dependencies = new Dependencies(project, dependencyTreeNode, classesAnalyzer); Log log = getLog(); RepositoryUtils repoUtils = new RepositoryUtils(log, wagonManager, settings, mavenProjectBuilder, factory, resolver, project.getRemoteArtifactRepositories(), project.getPluginArtifactRepositories(), localRepository, repositoryMetadataManager); Artifact projectArtifact = project.getArtifact(); log.info(String.format("Resolving project %s:%s:%s dependencies", projectArtifact.getGroupId(), projectArtifact.getArtifactId(), projectArtifact.getVersion())); List<Artifact> allDependencies = dependencies.getAllDependencies(); List<MavenProject> mavenProjects = new ArrayList<MavenProject>(); for (Artifact artifact : allDependencies) { log.debug(String.format("Resolving project information for %s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion())); try {/*from w w w . ja v a 2s. c o m*/ MavenProject mavenProject = repoUtils.getMavenProjectFromRepository(artifact); mavenProjects.add(mavenProject); } catch (ProjectBuildingException e) { throw new MojoFailureException( String.format("Cannot get project information for artifact %s:%s:%s from repository", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()), e); } } return mavenProjects; }
From source file:net.sf.junite2.JUnitEEMojo.java
License:Apache License
protected void execute(JUnitEETest test) throws Exception { StringBuffer arguments = new StringBuffer(); boolean done; String sessionCookie;//from www . ja va2s .c o m URL requestUrl; URLConnection con; Log log = getLog(); arguments.append(url).append("?output=xml"); if (threaded) { log.debug("Threaded mode"); arguments.append("&thread=true"); } if (test.getResource() != null) { arguments.append("&resource=").append(test.getResource()); } if (test.getRunall()) { arguments.append("&all=true"); } else if (test.getName() != null) { arguments.append("&suite=").append(URLEncoder.encode(test.getName())); } else { throw new Exception("You must specify the test name or runall attribute"); } if (!test.getFiltertrace()) { arguments.append("&filterTrace=false"); } log.debug("url is " + arguments.toString()); InputStream in = null; requestUrl = new URL(arguments.toString()); try { con = requestUrl.openConnection(); sessionCookie = con.getHeaderField("Set-Cookie"); log.debug("Session cookie : " + sessionCookie); if (sessionCookie != null) { int index = sessionCookie.indexOf(';'); if (index != -1) { sessionCookie = sessionCookie.substring(0, index); } } in = con.getInputStream(); done = parseResult(in, test); } catch (MojoExecutionException me) { throw me; } catch (Exception e) { throw new Exception("Error accessing url " + requestUrl.toString(), e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } try { while (!done) { try { log.debug("Sleeping ... "); Thread.sleep(1000); } catch (InterruptedException e) { // continue work } //log("Get xml again using URL " + requestUrl, Project.MSG_DEBUG); con = requestUrl.openConnection(); if (sessionCookie != null) { con.setRequestProperty("Cookie", sessionCookie); } in = con.getInputStream(); try { done = parseResult(in, test); } catch (MojoExecutionException me) { throw me; } catch (Throwable thr) { log.debug(thr); throw new MojoExecutionException(thr.getMessage()); } finally { try { in.close(); } catch (IOException e) { } } } } catch (Exception e) { log.error("Failed to execute test: " + e.getMessage()); throw new Exception(e); } }
From source file:net.sf.junite2.JUnitEEMojo.java
License:Apache License
private boolean parseResult(InputStream in, JUnitEETest test) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Log log = getLog(); Document document;/*from w w w .j a v a 2 s .c o m*/ byte[] buffer = readInput(in); try { document = builder.parse(new ByteArrayInputStream(buffer)); } catch (SAXException e) { log.error("Invalid xml:\n " + new String(buffer)); throw new Exception("Unable to parse test result (no valid xml)."); } Element root = document.getDocumentElement(); if (root.getAttributeNode("unfinished") != null) { log.debug(String.valueOf(root.getAttributeNode("unfinished"))); return false; } root.normalize(); NodeList testcases = root.getElementsByTagName("testsuite"); Vector resultFormatters = createFormatters(test); log.debug("Found " + testcases.getLength() + " testsuites"); if (testcases.getLength() <= 0) { log.debug("No testsuites found " + new String(buffer)); throw new MojoExecutionException("No testsuites found!"); } int failure_count = 0; int error_count = 0; for (int i = 0; i < testcases.getLength(); i++) { Node node = testcases.item(i); NamedNodeMap attributes = node.getAttributes(); String testClass = attributes.getNamedItem("name").getNodeValue(); String testPkg = attributes.getNamedItem("package").getNodeValue(); int errors = Integer.parseInt(attributes.getNamedItem("errors").getNodeValue()); int failures = Integer.parseInt(attributes.getNamedItem("failures").getNodeValue()); String testName; if (testPkg != null && testPkg.length() != 0) { testName = testPkg + "." + testClass; } else { testName = testClass; } Enumeration enumeration = resultFormatters.elements(); while (enumeration.hasMoreElements()) { JUnitEEResultFormatter formatter = (JUnitEEResultFormatter) enumeration.nextElement(); log.debug("Calling formatter " + formatter + " for node " + node); formatter.format(node); formatter.flush(); } if (errors != 0) { error_count += errors; } if (failures != 0) { failure_count += failures; } } NodeList errorMessages = root.getElementsByTagName("errorMessage"); for (int i = 0; i < errorMessages.getLength(); i++) { Node message = errorMessages.item(i); log.debug(message.getFirstChild().getNodeValue()); } if (errorMessages.getLength() != 0) { throw new MojoExecutionException("Test execution failed."); } if (error_count > 0) throw new MojoExecutionException(error_count + " errors occured"); if (failure_count > 0) throw new MojoExecutionException(failure_count + " failures occured"); return true; }
From source file:net.sf.junite2.JUnitEEMojo.java
License:Apache License
private Vector createFormatters(JUnitEETest test) throws Exception { Log log = getLog(); Vector answer = new Vector(); Enumeration enumeration = formatters.elements(); while (enumeration.hasMoreElements()) { FormatterElement element = (FormatterElement) enumeration.nextElement(); element.setOutFile(test.getOutfile()); element.setFilterTrace(test.getFiltertrace()); answer.add(element.createFormatter()); }// w ww .j a va 2s . c o m enumeration = test.getFormatters(); while (enumeration.hasMoreElements()) { FormatterElement element = (FormatterElement) enumeration.nextElement(); log.debug("outfile=" + test.getOutfile()); element.setOutFile(test.getOutfile()); element.setFilterTrace(test.getFiltertrace()); answer.add(element.createFormatter()); } if (printSummary) { log.debug("Adding summary formatter"); SummaryResultFormatter summary = new SummaryResultFormatter(); summary.setOut(System.out); answer.add(summary); } log.debug("Formatters: " + answer); return answer; }
From source file:net.sf.maven.plugin.autotools.FileUtils.java
License:Apache License
/** * Replace all occurences, in <code>files</code>, of <code>regex</code> with <code>replace</code> * @param regex the original text to replace * @param replace the placeholder/*from ww w. j a v a2 s . c om*/ * @param files the files */ public static void replace(Log log, @Nonnull String regex, @Nullable String replace, File... files) throws IOException { if (files == null) return; Preconditions.checkArgument(!Strings.isNullOrEmpty(regex), "regex is empty"); replace = Strings.nullToEmpty(replace); for (File file : files) { log.debug(String.format("Replacing [%s] with [%s] in [%s]", regex, replace, file.getAbsolutePath())); String text = Files.toString(file, Charset.defaultCharset()); Files.write(text.replaceAll(regex, replace), file, Charset.defaultCharset()); } }
From source file:net.sf.yal10n.analyzer.ResourceAnalyzer.java
License:Apache License
/** * Analyzes the given dstPath and adds any resource bundles found. * * @param log the log/*from w w w. j a v a 2 s . c om*/ * @param svnUrl the svn url * @param dstPath the dst path * @param config the config * @param repo the repo * @param repoId the repo id */ public void analyze(Log log, String svnUrl, String dstPath, DashboardConfiguration config, Repository repo, String repoId) { DirectoryScanner scanner = new DirectoryScanner(); Set<String> allIncludes = new HashSet<String>(); if (config.getIncludes() != null) { allIncludes.addAll(config.getIncludes()); } if (repo.getIncludes() != null) { allIncludes.addAll(repo.getIncludes()); } Set<String> allExcludes = new HashSet<String>(); if (config.getExcludes() != null) { allExcludes.addAll(config.getExcludes()); } if (repo.getExcludes() != null) { allExcludes.addAll(repo.getExcludes()); } scanner.setBasedir(dstPath); scanner.setIncludes(allIncludes.toArray(new String[allIncludes.size()])); scanner.setExcludes(allExcludes.toArray(new String[allExcludes.size()])); scanner.scan(); String[] includedFiles = scanner.getIncludedFiles(); Arrays.sort(includedFiles); for (String s : includedFiles) { try { log.debug("found: " + s); String fullDstPath = new File(dstPath).getCanonicalPath(); String svnPath = RepositoryUtil.getCheckoutUrl(config, repo) + "/" + s; ResourceFile resourceFile = new ResourceFile(config, repo, svnUrl, dstPath, s, svn, svnPath); String baseBundleName = resourceFile.getBundleBaseName(); ResourceBundle bundle = bundles.get(baseBundleName); if (bundle == null) { String svnBaseUrl = svnUrl + "/" + FileUtils.basename(s); if (svnBaseUrl.endsWith(".")) { svnBaseUrl = svnBaseUrl.substring(0, svnBaseUrl.length() - 1); } bundle = new ResourceBundle(config, svnBaseUrl, repoId, baseBundleName, fullDstPath); bundles.put(baseBundleName, bundle); } bundle.addFile(resourceFile); } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:net.sf.yal10n.svn.SVNUtil.java
License:Apache License
/** * Checkout from the given svn url to the destination directory. * * @param log the log/* w ww.ja v a2 s . c o m*/ * @param type the scm type * @param svnUrl the svn url * @param destination the destination * @return the current checked out version */ public String checkout(Log log, ScmType type, String svnUrl, String destination) { try { log.info("Updating " + svnUrl); String scmUrl = createScmSvnUrl(type, svnUrl); log.debug("Converted Url: " + scmUrl); ScmProvider scm = scmManager.getProviderByUrl(scmUrl); ScmRepository repository = scmManager.makeScmRepository(scmUrl); ScmProviderRepository providerRepository = repository.getProviderRepository(); File dstPath = new File(destination); if (dstPath.exists() && !dstPath.isDirectory()) { throw new RuntimeException("Path is not a directory: " + dstPath); } else if (!dstPath.exists() && !dstPath.mkdirs()) { throw new RuntimeException("Couldn't create directory " + dstPath); } CheckOutScmResult checkOutResult = scm.checkOut(repository, new ScmFileSet(dstPath)); checkResult(checkOutResult); String revision = checkOutResult.getRevision(); if (revision == null) { InfoScmResult info = scm.info(providerRepository, new ScmFileSet(dstPath), null); checkResult(info); revision = info.getInfoItems().get(0).getRevision(); } log.info("At revision " + revision); return revision; } catch (ScmException e) { throw new RuntimeException(e); } }
From source file:nl.geodienstencentrum.maven.plugin.sass.AbstractSassMojo.java
License:Apache License
/** * Execute the Sass Compilation Ruby Script. * * @param sassScript/* w ww .j a va 2 s . c o m*/ * the sass script * @throws MojoExecutionException * the mojo execution exception * @throws MojoFailureException * the mojo failure exception */ protected void executeSassScript(final String sassScript) throws MojoExecutionException, MojoFailureException { if (this.skip) { return; } final Log log = this.getLog(); System.setProperty("org.jruby.embed.localcontext.scope", "threadsafe"); log.debug("Execute Sass Ruby script:\n\n" + sassScript + "\n\n"); final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); final ScriptEngine jruby = scriptEngineManager.getEngineByName("jruby"); try { final CompilerCallback compilerCallback = new CompilerCallback(log); jruby.getBindings(ScriptContext.ENGINE_SCOPE).put("compiler_callback", compilerCallback); jruby.eval(sassScript); if (this.failOnError && compilerCallback.hadError()) { throw new MojoFailureException("Sass compilation encountered errors (see above for details)."); } } catch (final ScriptException e) { throw new MojoExecutionException("Failed to execute Sass ruby script:\n" + sassScript, e); } log.debug("\n"); }
From source file:nl.geodienstencentrum.maven.plugin.sass.AbstractSassMojo.java
License:Apache License
/** * Gets the template locations.//from w w w .j av a 2 s.c o m * * @return the template locations */ private Iterator<Entry<String, String>> getTemplateLocations() { final Log log = this.getLog(); List<Resource> resList = this.resources; if (resList.isEmpty()) { log.info("No resource element was specified, using short configuration."); // If no resources specified, create a resource based on the other // parameters and defaults final Resource resource = new Resource(); resource.source = new FileSet(); if (this.sassSourceDirectory != null) { log.debug("Setting source directory: " + this.sassSourceDirectory.toString()); resource.source.setDirectory(this.sassSourceDirectory.toString()); } else { log.error("\"" + this.sassSourceDirectory + "\" is not a directory."); resource.source.setDirectory("./src/main/sass"); } if (this.includes != null) { log.debug("Setting includes: " + Arrays.toString(this.includes)); resource.source.setIncludes(Arrays.asList(this.includes)); } if (this.excludes != null) { log.debug("Setting excludes: " + Arrays.toString(this.excludes)); resource.source.setExcludes(Arrays.asList(this.excludes)); } resource.relativeOutputDirectory = this.relativeOutputDirectory; resource.destination = this.destination; resList = ImmutableList.of(resource); } final List<Entry<String, String>> locations = new ArrayList<Entry<String, String>>(); for (final Resource source : resList) { for (final Entry<String, String> entry : source.getDirectoriesAndDestinations(log).entrySet()) { log.info("Queueing Sass template for compile: " + entry.getKey() + " => " + entry.getValue()); locations.add(entry); } } return locations.iterator(); }
From source file:nl.geodienstencentrum.maven.plugin.sass.report.SCSSLintMojo.java
License:Apache License
/** * Execute the lint script./*from w w w . j a v a2 s .c o m*/ * * @see org.apache.maven.plugin.Mojo#execute() * @throws MojoExecutionException when the execution of the plugin * errored * @throws MojoFailureException when the Sass compilation fails * */ @Override public void execute() throws MojoExecutionException, MojoFailureException { if (this.isSkip()) { return; } final Log log = this.getLog(); // create directory this.outputFile.getParentFile().mkdirs(); log.info("Linting Sass sources in: " + this.getSassSourceDirectory()); final StringBuilder sassScript = new StringBuilder(); this.buildBasicSassScript(sassScript); log.debug("scss-lint ruby script:\n" + sassScript); System.setProperty("org.jruby.embed.localcontext.scope", "threadsafe"); final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); final ScriptEngine jruby = scriptEngineManager.getEngineByName("jruby"); ScriptContext context = jruby.getContext(); ArrayList<String> argv = new ArrayList<>(); argv.add("--format=Checkstyle"); argv.add("-o" + this.outputFile); // argv.add("--config " + get config from some params,); argv.addAll(this.getSourceDirs()); // this.getSassSourceDirectory().getPath() context.setAttribute(ScriptEngine.ARGV, argv.toArray(new String[argv.size()]), ScriptContext.GLOBAL_SCOPE); try { log.info("Reporting scss lint in: " + this.outputFile.getAbsolutePath()); ExitCode result = ExitCode .getExitCode(Ints.checkedCast((Long) jruby.eval(sassScript.toString(), context))); log.debug("scss-lint result: " + result.toString()); switch (result) { case CODE_0: log.info(result.msg()); break; case CODE_1: log.warn(result.msg()); break; case CODE_2: log.error(result.toString()); if (this.failOnError) { throw new MojoFailureException(result.toString()); } case CODE_64: // fall through case CODE_66: // fall through case CODE_70: // fall through case CODE_78: // fall through default: log.error(result.toString()); throw new MojoExecutionException(result.toString()); } } catch (final ScriptException e) { throw new MojoExecutionException("Failed to execute scss-lint Ruby script:\n" + sassScript, e); } }