try {
HK2Factory.initialize();
MavenProjectRepository repo = new MavenProjectRepository(
project, artifactResolver, localRepository, artifactFactory);
repo.initialize();
PackageAnalyser analyser = new PackageAnalyser(repo, logger);
Collection<PackageAnalyser.Wire> wires = analyser.analyseWirings();
StringBuilder sb = new StringBuilder("Wiring details are given below:\n");
for (PackageAnalyser.Wire w : wires) {
sb.append(w + "\n");
}
sb.append("Total number of wires = " + wires.size() + "\n");
sb.append("Split-Package details are given below:\n");
Collection<PackageAnalyser.SplitPackage> splitPkgs = analyser.findDuplicatePackages();
for (PackageAnalyser.SplitPackage p : splitPkgs) sb.append(p+"\n");
sb.append("Total number of Split Packages = " + splitPkgs.size() + "\n");
int totalUnusedPkgs = 0;
for (PackageAnalyser.Bundle b : analyser.bundles) {
Collection<PackageAnalyser.PackageCapability> unusedPackages = analyser.findUnusedExports(b);
if (!unusedPackages.isEmpty()) {
sb.append("<Bundle name=" + b.getName()+", totalUnusedPkgs = " + unusedPackages.size() + "> \n" );
for (PackageAnalyser.PackageCapability p : unusedPackages) sb.append("\t" + p + "\n");
sb.append("</Bundle>\n");
}
totalUnusedPkgs += unusedPackages.size();
}
sb.append("Total number of Unused Packages = " + totalUnusedPkgs);
sb.append("******** GROSS STATISTICS *********\n");
sb.append("Total number of bundles in this repository: " + analyser.findAllBundles().size()+"\n");
sb.append("Total number of wires = " + wires.size() + "\n");
Collection<String> exportedPkgs = analyser.findAllExportedPackageNames();
sb.append("Total number of exported packages = " + exportedPkgs.size() + "\n");
sb.append("Total number of split-packages = " + splitPkgs.size()+"\n");
sb.append("Total number of unused-packages = " + totalUnusedPkgs +"\n");
logger.logp(Level.INFO, "PackageAnalyserMojo", "execute", "{0}", new Object[]{sb});
String reportFilePath =
System.getProperty("WiringReportPath",
System.getProperty("java.io.tmpdir")+ File.separator + "wires.xml");
analyser.generateWiringReport(exportedPkgs, wires, new PrintStream(new FileOutputStream(new File(reportFilePath))));
System.out.println("Wiring reported can be found at " + reportFilePath);
} catch (IOException e) {
throw new MojoExecutionException("Unexpected exception", e);
}
}