in src/main/java/org/apache/sling/feature/maven/mojos/InfoMojo.java [137:263]
public void execute() throws MojoExecutionException, MojoFailureException {
final boolean isStandalone = "standalone-pom".equals(project.getArtifactId());
if ( outputExportedPackages != null ) {
getLog().warn("Deprecated configuration 'outputExportedPackages' is used. Please use 'reports' instead.");
}
if ( featureFile != null ) {
getLog().warn("Deprecated configuration 'featureFile' is used. Change to 'infoFeatureFiles'");
if ( infoFeatureFiles == null ) {
infoFeatureFiles = featureFile.getAbsolutePath();
} else {
infoFeatureFiles = infoFeatureFiles.concat(",").concat(featureFile.getAbsolutePath());
}
}
if ( isStandalone && infoFeatureFiles == null ) {
throw new MojoExecutionException("Required configuration for standalone execution is missing. Please specify 'infoFeatureFiles'.");
}
OutputFormat format = OutputFormat.FILE;
try {
format = OutputFormat.valueOf(outputFormat.toUpperCase());
} catch ( final IllegalArgumentException iae) {
throw new MojoExecutionException("Invalid value for 'outputFormat', allowed values are file, log or singlefile, configured : ".concat(outputFormat));
}
final List<Reporter> reporters = getReporters(this.reports);
if ( reporters.isEmpty() ) {
getLog().warn("No reporters specified.");
return;
}
final List<Feature> selection = selectFeatures(infoFeatureFiles);
// setup scanner
final Scanner scanner = setupScanner();
final IncludeExcludeMatcher matcher;
if ( this.artifactIncludesList != null && !this.artifactIncludesList.isEmpty()) {
matcher = new IncludeExcludeMatcher(Stream.of(this.artifactIncludesList.split(",")).map(v -> v.trim()).collect(Collectors.toList()),
this.artifactExcludesList == null ? null : Stream.of(this.artifactExcludesList.split(",")).map(v -> v.trim()).collect(Collectors.toList()),
null, false);
} else {
matcher = null;
}
final Map<String, List<String>> reportsFromSingleReporter = new LinkedHashMap<>();
final ReportContext ctx = new ReportContext() {
@Override
public Scanner getScanner() {
return scanner;
}
@Override
public List<Feature> getFeatures() {
return selection;
}
@Override
public void addReport(final String key, final List<String> output) {
reportsFromSingleReporter.put(key, output);
}
@Override
public boolean matches(final ArtifactId id) {
return matcher == null || matcher.matches(id) != null;
}
};
final Map<String, Map<String, List<String>>> allReports = new HashMap<>();
for(final Reporter reporter : reporters) {
getLog().info("Generating report ".concat(reporter.getName().concat("...")));
reporter.generateReport(ctx);
allReports.put(reporter.getName(), new HashMap<>(reportsFromSingleReporter));
reportsFromSingleReporter.clear();
}
final File directory;
if ( outputDirectory != null ) {
directory = outputDirectory;
} else if ( isStandalone ) {
// wired code to get the current directory, but its needed
directory = Paths.get(".").toAbsolutePath().getParent().toFile();
} else {
directory = buildDirectory;
}
switch (format) {
case FILE:
directory.mkdirs();
allReports.values().forEach(map -> {
map.forEach((key, value) -> {
try {
final File out = new File(directory, key);
getLog().info("Writing " + out + "...");
Files.write(out.toPath(), value);
} catch (final IOException e) {
throw new RuntimeException("Unable to write file: " + e.getMessage(), e);
}
});
});
break;
case SINGLEFILE:
directory.mkdirs();
allReports.entrySet().forEach(entry -> {
final List<String> result = new ArrayList<>();
for(final List<String> value : entry.getValue().values()) {
result.addAll(value);
}
Collections.sort(result);
try {
final File out = new File(directory, "report-" + entry.getKey() + ".txt");
getLog().info("Writing " + out + "...");
Files.write(out.toPath(), result);
} catch (final IOException e) {
throw new RuntimeException("Unable to write file: " + e.getMessage(), e);
}
});
break;
case LOG:
allReports.values().forEach(map -> {
map.forEach((key, value) -> {
getLog().info("");
getLog().info("Report ".concat(key));
getLog().info("================================================================");
value.stream().forEach(l -> getLog().info(l));
getLog().info("");
});
});
break;
}
}