Skip to content

Commit

Permalink
Added hasMainWebFxSourceDirectory field in export
Browse files Browse the repository at this point in the history
  • Loading branch information
salmonb committed Mar 19, 2024
1 parent 7832449 commit af4d577
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/dev/webfx/mavenplugin/ExportMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.function.Consumer;

@Mojo(name = "export", defaultPhase = LifecyclePhase.INSTALL, aggregator = true) // aggregator = true because that goal doesn't need to be run on children
public final class ExportMojo extends AbstractMojo {
Expand Down Expand Up @@ -59,6 +60,8 @@ public final class ExportMojo extends AbstractMojo {
@Component
private MavenProjectHelper projectHelper;

private static Consumer<String> LOGGER;

/**
* Called when this goal is run
*/
Expand All @@ -71,6 +74,8 @@ public void execute() throws MojoFailureException {
getLog().debug("failOnError: " + failOnError);
getLog().debug("-----------------------------------");

LOGGER = getLog()::info;

File webfxXmlArtifactFile = new File(new File(targetDirectory), "webfx-artifact/webfx.xml");

// Calling the export() method that generates the webfx.xml artifact
Expand Down Expand Up @@ -134,20 +139,23 @@ private static Document exportDocument(DevWebFxModuleFile webFxModuleFile) {
if (!webFxModuleFile.generatesExportSnapshot())
return exportNodeWasPresent ? document : null;
// Exporting this and children modules in depth
LOGGER.accept("Exporting children modules");
final Node finalExportNode = exportNode;
DevProjectModule projectModule = webFxModuleFile.getProjectModule();
projectModule.getThisAndChildrenModulesInDepth()
.forEach(pm -> exportChildModuleProject(pm, projectModule, finalExportNode));
// Adding usage to resolve if-uses-java-package and if-uses-java-class directives without downloading the sources
ReusableStream<ProjectModule> usageCoverage = projectModule.getDirectivesUsageCoverage();
// First pass: searching all the if-uses-java-package and if-java-classes directives and collecting the packages or classes that require to find the usage
LOGGER.accept("Collecting usages in directives");
Set<String> packagesListedInDirectives = new HashSet<>(); // To be populated
Set<String> classesListedInDirectives = new HashSet<>(); // To be populated
usageCoverage
.forEach(pm -> collectJavaPackagesAndClassesListedInDirectives(pm, packagesListedInDirectives, classesListedInDirectives));
//System.out.println("packagesListedInDirectives: " + packagesListedInDirectives);
//System.out.println("classesListedInDirectives: " + classesListedInDirectives);
LOGGER.accept("- packages listed in directives: " + packagesListedInDirectives);
LOGGER.accept("- classes listed in directives: " + classesListedInDirectives);
// Third pass: finding usage
LOGGER.accept("Reporting usages in export");
Element usagesElement = document.createElement("usages");
computeAndPopulateUsagesOfJavaPackagesAndClasses(usagesElement, usageCoverage,
convertSetToSortedList(packagesListedInDirectives),
Expand All @@ -166,13 +174,15 @@ private static <T extends Comparable<? super T>> List<T> convertSetToSortedList(
}

private static void exportChildModuleProject(ProjectModule childModule, DevProjectModule projectModule, Node exportNode) {
//LOGGER.accept("Exporting child " + childModule.getName());
Document childDocument = childModule.getWebFxModuleFile().getDocument();
if (childDocument != null) {
Document document = exportNode.getOwnerDocument();
// Duplicating the xml element, so it can be copied into <export-snapshot/>
Element childProjectElement = (Element) document.importNode(childDocument.getDocumentElement(), true);
// Making the project name explicit (so the import knows what module we are talking about)
childProjectElement.setAttribute("name", childModule.getName());
childProjectElement.setAttribute("hasMainWebFxSourceDirectory", String.valueOf(childModule.hasMainWebFxSourceDirectory()));
// Removing tags that are not necessary for the import: <update-options>, <maven-pom-manual>
String[] unnecessaryTags = {"update-options", "maven-pom-manual"};
for (String tag : unnecessaryTags)
Expand Down

0 comments on commit af4d577

Please sign in to comment.