List of usage examples for org.apache.maven.plugin.logging Log info
void info(Throwable error);
From source file:org.jahia.utils.maven.plugin.osgi.FindPackageUsesMojo.java
License:Open Source License
public static Map<String, Map<String, Artifact>> findPackageUses(List<String> packageNames, Set<Artifact> artifacts, MavenProject project, File buildOutputDirectory, boolean searchInDependencies, Log log) { final Map<String, Map<String, Artifact>> packageResults = new TreeMap<String, Map<String, Artifact>>(); log.info("Scanning project build directory..."); if (buildOutputDirectory.exists()) { findPackageUsesInDirectory(packageNames, project, log, packageResults, buildOutputDirectory); }/*w w w . ja v a 2 s. com*/ if (!searchInDependencies) { return packageResults; } log.info("Scanning project dependencies..."); for (Artifact artifact : artifacts) { if (artifact.isOptional()) { log.debug("Processing optional dependency " + artifact + "..."); } if (artifact.getType().equals("pom")) { log.warn("Skipping POM artifact " + artifact); continue; } if (!artifact.getType().equals("jar")) { log.warn("Found non JAR artifact " + artifact); } findPackageUsesInArtifact(packageNames, project, log, packageResults, artifact); } return packageResults; }
From source file:org.jahia.utils.maven.plugin.osgi.FindPackageUsesMojo.java
License:Open Source License
public static void findPackageUsesInArtifact(List<String> packageNames, MavenProject project, Log log, Map<String, Map<String, Artifact>> packageResults, Artifact artifact) { boolean currentTrailWasDisplayed = false; int trailDepth = artifact.getDependencyTrail().size(); for (String packageName : packageNames) { Map<String, Artifact> foundClasses = packageResults.get(packageName); if (foundClasses == null) { foundClasses = new TreeMap<String, Artifact>(); }//from w w w . j a va 2s .c o m Set<String> classesThatHaveDependency = findClassesThatUsePackage(artifact.getFile(), packageName, project, log); if (classesThatHaveDependency != null & classesThatHaveDependency.size() > 0) { List<String> trail = new ArrayList<String>(artifact.getDependencyTrail()); if (artifact.isOptional()) { trail.add("[optional]"); } for (String classThatHasDependency : classesThatHaveDependency) { if (!currentTrailWasDisplayed) { displayTrailTree(project, artifact, log); currentTrailWasDisplayed = true; } log.info(getPaddingString(trailDepth) + "+--> Found class " + classThatHasDependency + " that uses package " + packageName); foundClasses.put(classThatHasDependency, artifact); } packageResults.put(packageName, foundClasses); } } }
From source file:org.jahia.utils.maven.plugin.osgi.FindPackageUsesMojo.java
License:Open Source License
public static void findPackageUsesInDirectory(List<String> packageNames, MavenProject project, Log log, Map<String, Map<String, Artifact>> packageResults, File directory) { for (String packageName : packageNames) { Map<String, Artifact> foundClasses = packageResults.get(packageName); if (foundClasses == null) { foundClasses = new TreeMap<String, Artifact>(); }/* w ww . j av a 2s .com*/ Set<String> classesThatHaveDependency = findClassesThatUsePackage(directory, packageName, project, log); if (classesThatHaveDependency != null & classesThatHaveDependency.size() > 0) { for (String classThatHasDependency : classesThatHaveDependency) { log.info("+--> Found class " + classThatHasDependency + " that uses package " + packageName); foundClasses.put(classThatHasDependency, project.getArtifact()); } packageResults.put(packageName, foundClasses); } } }
From source file:org.jahia.utils.maven.plugin.osgi.FindPackageUsesMojo.java
License:Open Source License
private static void displayTrailTree(MavenProject project, Artifact artifact, Log log) { StringBuilder builder = new StringBuilder(); int i = 0;/*from w ww . j a va 2 s.c o m*/ for (String trailEntry : artifact.getDependencyTrail()) { builder.append(trailEntry); Artifact dependencyArtifact = findArtifactInProject(project, trailEntry, log); if (dependencyArtifact != null) { if (dependencyArtifact.isOptional()) { builder.append(" [OPTIONAL]"); } if (dependencyArtifact.getScope() != null && dependencyArtifact.getScope().contains(Artifact.SCOPE_PROVIDED)) { builder.append(" [PROVIDED]"); } } if (i < artifact.getDependencyTrail().size() - 1) { log.info(builder.toString()); builder = new StringBuilder(); builder.append(getPaddingString(i)); builder.append("+- "); } i++; } builder.append(" (" + artifact.getFile() + ") : "); log.info(builder.toString()); }
From source file:org.jahia.utils.maven.plugin.support.AetherHelperFactory.java
License:Open Source License
/** * Obtains an instance of the proper artifact and dependency resolver, depending on the Maven execution environment * //from w w w . j a va2s .com * @param container * @param project * @param session * @param log * @return an instance of the proper artifact and dependency resolver * @throws MojoExecutionException */ @SuppressWarnings("unchecked") public static AetherHelper create(PlexusContainer container, MavenProject project, MavenSession session, Log log) throws MojoExecutionException { try { if (container.hasComponent("org.sonatype.aether.RepositorySystem")) { log.info("Using Aether helper for Maven 3.0.x"); warnMavenVersion(log); return new Maven30AetherHelper(container.lookup(RepositorySystem.class), session.getRepositorySession(), project.getRemoteProjectRepositories(), log); } else if (container.hasComponent(org.eclipse.aether.RepositorySystem.class)) { Object repoSession; try { repoSession = MavenSession.class.getMethod("getRepositorySession").invoke(session); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } List<?> remoteRepos = project.getRemoteProjectRepositories(); log.info("Using Aether helper for Maven 3.1+"); return new Maven31AetherHelper(container.lookup(org.eclipse.aether.RepositorySystem.class), (RepositorySystemSession) repoSession, (List<org.eclipse.aether.repository.RemoteRepository>) remoteRepos, log); } } catch (ComponentLookupException e) { throw new MojoExecutionException(e.getMessage(), e); } throw new MojoExecutionException( "Unable to find either Sonatype's Aether nor Eclipse's Aether implementations"); }
From source file:org.jasig.maven.legal.PackageLegalMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { final Log logger = this.getLog(); if ("pom".equals(project.getPackaging())) { logger.info("Skipping inclusion of legal files for pom project: " + project.getName()); return;/*from w w w. j a va2 s . c o m*/ } final File targetOutputDir = this.getTargetDirectory(); final ResourceFinder resourceFinder = this.getResourceFinder(); this.copyLegalFile(resourceFinder, this.noticeFile, targetOutputDir, "NOTICE"); this.copyLegalFile(resourceFinder, this.licenseFile, targetOutputDir, "LICENSE"); logger.info("Copied NOTICE and LICENSE to: " + targetOutputDir); }
From source file:org.jasig.maven.notice.AbstractNoticeMojo.java
License:Apache License
public final void execute() throws MojoExecutionException, MojoFailureException { final Log logger = this.getLog(); if (this.skipChecks) { logger.info("NOTICE file checks are skipped."); return;//from w ww .java2s .c o m } if (licenseLookup != null && licenseLookup.length > 0) { logger.warn("'licenseLookup' configuration property is deprecated use 'licenseMapping' instead"); if (licenseMapping != null && licenseMapping.length > 0) { throw new MojoFailureException( "Both 'licenseMapping' and 'licenseLookup' configuration properties configured. Only one may be used."); } licenseMapping = licenseLookup; } //Check if NOTICE for child modules should be generated if (!this.generateChildNotices && !this.project.isExecutionRoot()) { return; } final ResourceFinder finder = this.getResourceFinder(); final LicenseLookupHelper licenseLookupHelper = new LicenseLookupHelper(logger, finder, licenseMapping); final List<?> remoteArtifactRepositories = project.getRemoteArtifactRepositories(); final LicenseResolvingNodeVisitor visitor = new LicenseResolvingNodeVisitor(logger, licenseLookupHelper, remoteArtifactRepositories, this.mavenProjectBuilder, this.localRepository); this.parseProject(this.project, visitor); //Check for any unresolved artifacts final Set<Artifact> unresolvedArtifacts = visitor.getUnresolvedArtifacts(); this.checkUnresolved(unresolvedArtifacts); //Convert the resovled notice data into a String final Map<String, String> resolvedLicenses = visitor.getResolvedLicenses(); final String noticeLines = this.generateNoticeLines(resolvedLicenses); final String noticeTemplateContents = this.readNoticeTemplate(finder); //Replace the template placeholder with the generated notice data final String noticeContents = noticeTemplateContents .replaceAll(Pattern.quote(this.noticeTemplatePlaceholder), noticeLines); //Let the subclass deal with the generated NOTICE file this.handleNotice(finder, noticeContents); }
From source file:org.jasig.maven.notice.AbstractNoticeMojo.java
License:Apache License
/** * Loads the dependency tree for the project via {@link #loadDependencyTree(MavenProject)} and then uses * the {@link DependencyNodeVisitor} to load the license data. If {@link #aggregating} is enabled the method * recurses on each child module./*from www .java2 s .c om*/ */ @SuppressWarnings("unchecked") protected void parseProject(MavenProject project, DependencyNodeVisitor visitor) throws MojoExecutionException, MojoFailureException { final Log logger = this.getLog(); logger.info("Parsing Dependencies for: " + project.getName()); //Load and parse immediate dependencies final DependencyNode tree = this.loadDependencyTree(project); tree.accept(visitor); //If not including child deps don't recurse on modules if (!this.includeChildDependencies) { return; } //No child modules, return final List<MavenProject> collectedProjects = project.getCollectedProjects(); if (collectedProjects == null) { return; } //Find all sub-modules for the project for (final MavenProject moduleProject : collectedProjects) { if (this.isExcluded(moduleProject, project.getArtifactId())) { continue; } this.parseProject(moduleProject, visitor); } }
From source file:org.jasig.maven.notice.AbstractNoticeMojo.java
License:Apache License
/** * Check if a project is excluded based on its artifactId or a parent's artifactId *//*w w w.j av a 2 s . c o m*/ protected boolean isExcluded(MavenProject mavenProject, String rootArtifactId) { final Log logger = this.getLog(); final String artifactId = mavenProject.getArtifactId(); if (this.excludedModules.contains(artifactId)) { logger.info("Skipping aggregation of child module " + mavenProject.getName() + " with excluded artifactId: " + artifactId); return true; } MavenProject parentProject = mavenProject.getParent(); while (parentProject != null && !rootArtifactId.equals(parentProject.getArtifactId())) { final String parentArtifactId = parentProject.getArtifactId(); if (this.excludedModules.contains(parentArtifactId)) { logger.info("Skipping aggregation of child module " + mavenProject.getName() + " with excluded parent artifactId: " + parentArtifactId); return true; } parentProject = parentProject.getParent(); } return false; }
From source file:org.jasig.maven.notice.CheckNoticeMojo.java
License:Apache License
@Override protected void handleNotice(ResourceFinder finder, String noticeContents) throws MojoFailureException { final Log logger = this.getLog(); //Write out the generated notice file final File outputFile = getNoticeOutputFile(); //Make sure the existing NOTICE file exists if (!outputFile.exists()) { throw new MojoFailureException("No NOTICE file exists at: " + outputFile); }/*from w w w .ja v a2s . co m*/ //Load up the existing NOTICE file final Reader existingNoticeContents; try { final FileInputStream outputFileInputStream = new FileInputStream(outputFile); existingNoticeContents = new InputStreamReader(new BufferedInputStream(outputFileInputStream), this.encoding); } catch (IOException e) { throw new MojoFailureException("Failed to read existing NOTICE File from: " + outputFile, e); } //Check if the notice files match final String diffText = this.generateDiff(logger, new StringReader(noticeContents), existingNoticeContents); if (diffText.length() != 0) { final String buildDir = project.getBuild().getDirectory(); final File expectedNoticeFile = new File(new File(buildDir), "NOTICE.expected"); try { FileUtils.writeStringToFile(expectedNoticeFile, noticeContents, this.encoding); } catch (IOException e) { logger.warn("Failed to write expected NOTICE File to: " + expectedNoticeFile, e); } final String msg = "Existing NOTICE file '" + outputFile + "' doesn't match expected NOTICE file: " + expectedNoticeFile; logger.error(msg + "\n" + diffText); throw new MojoFailureException(msg); } logger.info("NOTICE file is up to date"); }