List of usage examples for org.apache.maven.plugin.logging Log info
void info(Throwable error);
From source file:org.mrgeo.plugins.ListDependencies.java
License:Apache License
public void execute() throws MojoExecutionException { Log log = getLog(); try {/*from w w w . j av a2 s .c o m*/ Model model = project.getModel(); if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } if (outputFile.exists()) { outputFile.delete(); } log.info("Writing to: " + outputFile); FileOutputStream fos = new FileOutputStream(outputFile); PrintWriter pw = new PrintWriter(fos); pw.println("# Main Jar: "); pw.println("# GroupId | ArtifactId | Version | Name"); pw.print(model.getGroupId() + separator + model.getArtifactId() + separator + model.getVersion() + separator); pw.println(model.getArtifactId() + "-" + model.getVersion() + "." + model.getPackaging()); pw.println("\n\n# Dependencies: "); pw.println("# GroupId | ArtifactId | Version | Classifier | Type | Scope | Name"); try { org.apache.maven.shared.dependency.graph.DependencyNode root = dependencyGraphBuilder .buildDependencyGraph(project, null); // StringWriter writer = new StringWriter(); // // SerializingDependencyNodeVisitor visitor = new SerializingDependencyNodeVisitor(writer); // root.accept(visitor); // // log.info(writer.toString()); DependencyVisitor visitor = new DependencyVisitor(); root.accept(visitor); for (Artifact artifact : visitor.getArtifacts()) { { log.debug(artifact.getGroupId() + separator + artifact.getArtifactId() + separator + artifact.getVersion() + separator + (artifact.getClassifier() != null ? artifact.getClassifier() : "") + separator + artifact.getType() + separator + artifact.getScope() + separator + makeFile(artifact)); pw.println(artifact.getGroupId() + separator + artifact.getArtifactId() + separator + artifact.getVersion() + separator + (artifact.getClassifier() != null ? artifact.getClassifier() : "") + separator + artifact.getType() + separator + artifact.getScope() + separator + makeFile(artifact)); } } } catch (DependencyGraphBuilderException e) { e.printStackTrace(); } // Map<String, Artifact> artifacts = new TreeMap<>(); // Map<String, String> scopes = new HashMap<>(); // // for (org.apache.maven.model.Dependency dep : model.getDependencies()) // { // //Artifact root = new DefaultArtifact(model.getGroupId(), model.getArtifactId(), model.getPackaging(), model.getVersion()); // Artifact root = // new DefaultArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getType(), dep.getVersion()); // // artifacts.put(makeName(root), root); // scopes.put(makeName(root), dep.getScope()); // // for (String scope : new String[]{"compile", "runtime"}) // { // try // { // Dependency dependency = new Dependency(root, scope); // CollectRequest collectRequest = new CollectRequest(); // collectRequest.setRoot(dependency); // // // this will collect the transitive dependencies of an artifact and build a dependency graph // DependencyNode node = repoSystem.collectDependencies(repoSession, collectRequest).getRoot(); // DependencyRequest dependencyRequest = new DependencyRequest(); // // dependencyRequest.setRoot(node); // // // this will collect and resolve the transitive dependencies of an artifact // DependencyResult depRes = repoSystem.resolveDependencies(repoSession, dependencyRequest); // // List<ArtifactResult> results = depRes.getArtifactResults(); // // for (ArtifactResult result : results) // { // Artifact artifact = result.getArtifact(); // // ArtifactRequest artifactRequest = new ArtifactRequest(); // artifactRequest.setArtifact(artifact); // // try // { // ArtifactResult ar = repoSystem.resolveArtifact(repoSession, artifactRequest); // // Artifact a = ar.getArtifact(); // log.info("###" + a.toString()); // } // catch (ArtifactResolutionException e) // { // e.printStackTrace(); // } // // artifacts.put(makeName(artifact), artifact); // scopes.put(makeName(artifact), scope); // // if (artifact.getGroupId().equals("org.apache.avro")) // { // log.info("***" + artifact.getGroupId() + separator + // artifact.getArtifactId() + separator + // artifact.getVersion() + separator + // (artifact.getClassifier() != null ? artifact.getClassifier() : "") + separator + // artifact.getExtension() + separator + // scopes.get(makeName(artifact)) + separator + // makeFile(artifact) + " *** " + makeName(root)); // // } // } // } // catch (DependencyCollectionException | DependencyResolutionException e) // { // // no op // } // } // } // // for (Artifact artifact : artifacts.values()) // { // { // log.debug(artifact.getGroupId() + separator + // artifact.getArtifactId() + separator + // artifact.getVersion() + separator + // (artifact.getClassifier() != null ? artifact.getClassifier() : "") + separator + // artifact.getExtension() + separator + // scopes.get(makeName(artifact)) + separator + // makeFile(artifact)); // // pw.println(artifact.getGroupId() + separator + // artifact.getArtifactId() + separator + // artifact.getVersion() + separator + // (artifact.getClassifier() != null ? artifact.getClassifier() : "") + separator + // artifact.getExtension() + separator + // scopes.get(makeName(artifact)) + separator + // makeFile(artifact)); // } // } // String[] scopes = new String[]{MavenClasspath.COMPILE_SCOPE, MavenClasspath.RUNTIME_SCOPE}; //DefaultDependencyGraphBuilder builder = new DefaultDependencyGraphBuilder(); //dumpTree(node); // builder.enableLogging(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG, "DefaultDependencyGraphBuilder" )); // // log.info(builder.toString()); // log.info(project.getId()); // // // DependencyNode node = builder.buildDependencyGraph(project, null); // // MavenClasspath mcp = new MavenClasspath(builder, mavenSession, Arrays.asList(scopes)); // for (File jar: mcp) // { // log.info(jar.getCanonicalPath()); // } // // Classpath jars = new Classpath( // project, // session.getLocalRepository().getBasedir(), Arrays.asList(scopes) // ); // // for (File jar: jars) // { // log.info(jar.getCanonicalPath()); // } // Aether aether = new Aether(project, session.getLocalRepository().getBasedir()); // for (Dependency dep : model.getDependencies()) // { // Artifact root = new DefaultArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getType(), // dep.getVersion()); // String rootName = dep.getArtifactId() + "-" + dep.getVersion() + "." + dep.getType(); // for (String scope : new String[]{"compile", "runtime"}) // { // for (Artifact artifact : aether.resolve(root, scope)) // { // // if (!artifact.getFile().getName().equals(rootName)) // { // log.info(artifact.getGroupId() + separator + // artifact.getArtifactId() + separator + // artifact.getVersion() + separator + // (artifact.getClassifier() != null ? artifact.getClassifier() : "") + separator + // artifact.getExtension() + separator + // scope + separator + // artifact.getFile().getName()); // // pw.println(artifact.getGroupId() + separator + // artifact.getArtifactId() + separator + // artifact.getVersion() + separator + // (artifact.getClassifier() != null ? artifact.getClassifier() : "") + separator + // artifact.getExtension() + separator + // scope + separator + // artifact.getFile().getName()); // } // } // } // // } // Artifact root = new DefaultArtifact(model.getGroupId(), model.getArtifactId(), model.getPackaging(), model.getVersion()); // String rootName = model.getArtifactId() + "-" + model.getVersion() + "." + model.getPackaging(); // // // log.info("***" + session.getLocalRepository().getBasedir()); // Aether aether = new Aether(project, session.getLocalRepository().getBasedir()); // for (String scope : new String[]{"compile", "runtime"}) // { // for (Artifact artifact : aether.resolve(root, scope)) // { // if (!artifact.getFile().getName().equals(rootName)) // { //// log.info(artifact.getGroupId() + separator + //// artifact.getArtifactId() + separator + //// artifact.getVersion() + separator + //// (artifact.getClassifier() != null ? artifact.getClassifier() : "") + separator + //// artifact.getExtension() + separator + //// scope + separator + //// artifact.getFile().getName()); // // pw.println(artifact.getGroupId() + separator + // artifact.getArtifactId() + separator + // artifact.getVersion() + separator + // (artifact.getClassifier() != null ? artifact.getClassifier() : "") + separator + // artifact.getExtension() + separator + // scope + separator + // artifact.getFile().getName()); // } // } // } pw.close(); fos.close(); } catch (IOException e) { e.printStackTrace(); throw new MojoExecutionException(e, "IOException", "IOException"); } }
From source file:org.mule.devkit.maven.AbstractGitHubMojo.java
License:Open Source License
/** * Log given message at info level//from www . j a va 2 s .co m * * @param message */ protected void info(String message) { Log log = getLog(); if (log != null) { log.info(message); } }
From source file:org.mule.tooling.tools.CheckerMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException { try {/*from w w w.ja v a2s . co m*/ Log log = getLog(); switch (packaging) { case "eclipse-plugin": log.debug("Checking for jars SNAPSHOT in the plugin:" + pluginBuildDirectory); CheckerResults results = JarFinder.checkJarSnapshots(pluginDirectory, new JarSnapshotFilter(), log, ignoreJarList); results.logResults(log); if (results.hasSnapshots()) { String message = "There are snapshot jars in this plugin!."; throw new MojoExecutionException(message); } else log.debug("There is not any jar SNAPSHOT in the plugin:" + pluginBuildDirectory); break; case "eclipse-repository": CheckerResults resultsBuilt = JarFinder.checkJarSnapshotsBuilt( pluginBuildDirectory + "/target/repository/plugins", new JarFilter(), log, ignoreJarList); resultsBuilt.logTotalResults(log); if (resultsBuilt.hasResults()) { String message = "There are snapshot jars in the built project!."; throw new MojoExecutionException(message); } break; default: log.info("This pom does not have to be tested"); break; } } catch (IOException e) { throw new MojoExecutionException("Error processing plugin directory ", e); } }
From source file:org.mule.tools.apikit.input.RAMLFilesParser.java
License:Open Source License
public RAMLFilesParser(Log log, Map<File, InputStream> fileStreams, APIFactory apiFactory) { this.log = log; this.apiFactory = apiFactory; List<File> processedFiles = new ArrayList<File>(); for (Map.Entry<File, InputStream> fileInputStreamEntry : fileStreams.entrySet()) { String content;//from w ww.j a va2 s . co m File ramlFile = fileInputStreamEntry.getKey(); try { content = IOUtils.toString(fileInputStreamEntry.getValue()); } catch (IOException ioe) { this.log.info("Error loading file " + ramlFile.getName()); break; } ResourceLoader resourceLoader = new CompositeResourceLoader(new DefaultResourceLoader(), new FileResourceLoader(ramlFile.getParentFile())); if (isValidYaml(ramlFile.getName(), content, resourceLoader)) { RamlDocumentBuilder builderNodeHandler = new RamlDocumentBuilder(resourceLoader); try { Raml raml = builderNodeHandler.build(content, ramlFile.getName()); String host = APIKitTools.getHostFromUri(raml.getBaseUri()); if (host == "") { host = HttpListenerConfig.DEFAULT_HOST; } String port = APIKitTools.getPortFromUri(raml.getBaseUri()); if (port == "") { port = HttpListenerConfig.DEFAULT_PORT; } String path = APIKitTools.getPathFromUri(raml.getBaseUri()); collectResources(ramlFile, raml.getResources(), host, port, HttpListenerConfig.DEFAULT_BASE_PATH, path); processedFiles.add(ramlFile); } catch (Exception e) { log.info("Could not parse [" + ramlFile + "] as root RAML file. Reason: " + e.getMessage()); log.debug(e); } } } if (processedFiles.size() > 0) { this.log.info("The following RAML files were parsed correctly: " + processedFiles); } else { this.log.error("RAML Root not found. None of the files were recognized as valid root RAML files."); } }
From source file:org.mule.tools.jshint.JSHintMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { Log log = getLog(); sourceDirectory = sourceDirectory.getAbsoluteFile(); if (!(sourceDirectory.exists() && sourceDirectory.isDirectory())) { log.warn(String.format("Not executing jshint as the source directory [%s] does not exist.", sourceDirectory));/*from w w w . j a va 2 s.c o m*/ return; } InputStream inputStream; boolean errors = false; for (String file : getIncludedFiles()) { log.info(String.format("Checking [%s]", file)); try { inputStream = new FileInputStream(file); } catch (FileNotFoundException e) { throw new MojoExecutionException(String.format("Error loading file [%s]", file), e); } if (!new JSHint(new WrappingConsoleFactory(MavenConsole.fromMavenLog(log)), getJavascriptFilesDirectory()).check(file, inputStream, config)) { errors = true; } } if (errors) { throw new MojoFailureException("Errors were found while performing jshint over Javascript code"); } log.info("No problems found in analyzed Javascript files."); }
From source file:org.neo4j.build.plugins.ease.EaseHelper.java
License:Apache License
static void writeAndAttachArtifactList(StringBuilder builder, MavenProject project, MavenProjectHelper projectHelper, Log log) throws MojoExecutionException { String buildDir = project.getBuild().getDirectory(); String destFile = buildDir + File.separator + project.getArtifactId() + "-" + project.getVersion() + "-artifacts.txt"; try {//w w w .jav a2 s . c o m if (FileUtils.fileExists(destFile)) { FileUtils.fileDelete(destFile); } if (!FileUtils.fileExists(buildDir)) { FileUtils.mkdir(buildDir); } FileUtils.fileWrite(destFile, "UTF-8", builder.toString()); } catch (IOException ioe) { throw new MojoExecutionException("Could not write artifact list.", ioe); } projectHelper.attachArtifact(project, "txt", "artifacts", FileUtils.getFile(destFile)); log.info("Successfully attached artifact list to the project."); }
From source file:org.onos.yangtools.yang2sources.plugin.Util.java
License:Open Source License
static Collection<File> listFiles(File root, File[] excludedFiles, Log log) throws FileNotFoundException { if (!root.exists()) { if (log != null) { log.warn(Util.message("YANG source directory %s not found. No code will be generated.", YangToSourcesProcessor.LOG_PREFIX, root.toString())); }/*from w ww . ja v a2 s .c o m*/ return Collections.emptyList(); } Collection<File> result = new ArrayList<>(); Collection<File> yangFiles = FileUtils.listFiles(root, new String[] { YANG_SUFFIX }, true); for (File f : yangFiles) { boolean excluded = false; for (File ex : excludedFiles) { if (ex.equals(f)) { excluded = true; break; } } if (excluded) { if (log != null) { log.info(Util.message("%s file excluded %s", YangToSourcesProcessor.LOG_PREFIX, Util.YANG_SUFFIX.toUpperCase(), f)); } } else { result.add(f); } } return result; }
From source file:org.onos.yangtools.yang2sources.plugin.Util.java
License:Open Source License
static YangsInZipsResult findYangFilesInDependenciesAsStream(Log log, MavenProject project) throws MojoFailureException { List<InputStream> yangsFromDependencies = new ArrayList<>(); List<Closeable> zips = new ArrayList<>(); try {//from w w w .jav a2 s .c om List<File> filesOnCp = Util.getClassPath(project); log.info(Util.message("Searching for yang files in following dependencies: %s", YangToSourcesProcessor.LOG_PREFIX, filesOnCp)); for (File file : filesOnCp) { List<String> foundFilesForReporting = new ArrayList<>(); // is it jar file or directory? if (file.isDirectory()) { //FIXME: code duplicate File yangDir = new File(file, YangToSourcesProcessor.META_INF_YANG_STRING); if (yangDir.exists() && yangDir.isDirectory()) { File[] yangFiles = yangDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".yang") && new File(dir, name).isFile(); } }); for (File yangFile : yangFiles) { yangsFromDependencies.add( new NamedFileInputStream(yangFile, YangToSourcesProcessor.META_INF_YANG_STRING + File.separator + yangFile.getName())); } } } else { ZipFile zip = new ZipFile(file); zips.add(zip); Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String entryName = entry.getName(); if (entryName.startsWith(YangToSourcesProcessor.META_INF_YANG_STRING_JAR) && !entry.isDirectory() && entryName.endsWith(".yang")) { foundFilesForReporting.add(entryName); // This will be closed after all streams are // parsed. InputStream entryStream = zip.getInputStream(entry); yangsFromDependencies.add(entryStream); } } } if (foundFilesForReporting.size() > 0) { log.info(Util.message("Found %d yang files in %s: %s", YangToSourcesProcessor.LOG_PREFIX, foundFilesForReporting.size(), file, foundFilesForReporting)); } } } catch (Exception e) { throw new MojoFailureException(e.getMessage(), e); } return new YangsInZipsResult(yangsFromDependencies, zips); }
From source file:org.onos.yangtools.yang2sources.plugin.Util.java
License:Open Source License
static Collection<File> findYangFilesInDependencies(Log log, MavenProject project) throws MojoFailureException { final List<File> yangsFilesFromDependencies = new ArrayList<>(); try {/*from ww w. ja va 2s .co m*/ List<File> filesOnCp = Util.getClassPath(project); log.info(Util.message("Searching for yang files in following dependencies: %s", YangToSourcesProcessor.LOG_PREFIX, filesOnCp)); for (File file : filesOnCp) { // is it jar file or directory? if (file.isDirectory()) { //FIXME: code duplicate File yangDir = new File(file, YangToSourcesProcessor.META_INF_YANG_STRING); if (yangDir.exists() && yangDir.isDirectory()) { File[] yangFiles = yangDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".yang") && new File(dir, name).isFile(); } }); yangsFilesFromDependencies.addAll(Arrays.asList(yangFiles)); } } else { try (ZipFile zip = new ZipFile(file)) { final Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String entryName = entry.getName(); if (entryName.startsWith(YangToSourcesProcessor.META_INF_YANG_STRING_JAR) && !entry.isDirectory() && entryName.endsWith(".yang")) { log.debug(Util.message("Found a YANG file in %s: %s", YangToSourcesProcessor.LOG_PREFIX, file, entryName)); yangsFilesFromDependencies.add(file); break; } } } } } } catch (Exception e) { throw new MojoFailureException("Failed to scan for YANG files in depedencies", e); } return yangsFilesFromDependencies; }
From source file:org.opendaylight.controller.yang2sources.plugin.Util.java
License:Open Source License
static YangsInZipsResult findYangFilesInDependenciesAsStream(Log log, MavenProject project) throws MojoFailureException { List<InputStream> yangsFromDependencies = new ArrayList<>(); List<Closeable> zips = new ArrayList<>(); try {/*from www. j a va2s .c o m*/ List<File> filesOnCp = Util.getClassPath(project); log.info(Util.message("Searching for yang files in following dependencies: %s", YangToSourcesProcessor.LOG_PREFIX, filesOnCp)); for (File file : filesOnCp) { List<String> foundFilesForReporting = new ArrayList<>(); // is it jar file or directory? if (file.isDirectory()) { File yangDir = new File(file, YangToSourcesProcessor.META_INF_YANG_STRING); if (yangDir.exists() && yangDir.isDirectory()) { File[] yangFiles = yangDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".yang") && new File(dir, name).isFile(); } }); for (File yangFile : yangFiles) { yangsFromDependencies.add(new NamedFileInputStream(yangFile)); } } } else { ZipFile zip = new ZipFile(file); zips.add(zip); Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String entryName = entry.getName(); if (entryName.startsWith(YangToSourcesProcessor.META_INF_YANG_STRING_JAR)) { if (entry.isDirectory() == false && entryName.endsWith(".yang")) { foundFilesForReporting.add(entryName); // This will be closed after all strams are // parsed. InputStream entryStream = zip.getInputStream(entry); yangsFromDependencies.add(entryStream); } } } } if (foundFilesForReporting.size() > 0) { log.info(Util.message("Found %d yang files in %s: %s", YangToSourcesProcessor.LOG_PREFIX, foundFilesForReporting.size(), file, foundFilesForReporting)); } } } catch (Exception e) { throw new MojoFailureException(e.getMessage(), e); } return new YangsInZipsResult(yangsFromDependencies, zips); }