When generating features do not write the file if the features have not changed.
@@ -258,8 +258,9 @@ public class GenerateFeaturesMojo extends ServerFeatureSupport {
try {
if (missingLibertyFeatures.size() > 0) {
+ Set<String> existingGeneratedFeatures = getGeneratedFeatures(servUtil, newServerXmlSrc);
+ if (!missingLibertyFeatures.equals(existingGeneratedFeatures)) {
// Create special XML file to contain generated features.
-
ServerConfigXmlDocument configDocument = ServerConfigXmlDocument.newInstance();
configDocument.createComment(HEADER);
Element featureManagerElem = configDocument.createFeatureManager();
@@ -268,12 +269,15 @@ public class GenerateFeaturesMojo extends ServerFeatureSupport {
log.debug(String.format("Adding missing feature %s to %s.", missing, GENERATED_FEATURES_FILE_PATH));
configDocument.createFeature(missing);
}
+ // Generate log message before writing file as the file change event kicks off other dev mode actions
+ log.info("Generated the following features: " + missingLibertyFeatures);
configDocument.writeXMLDocument(newServerXmlSrc);
log.debug("Created file " + newServerXmlSrc);
// Add a reference to this new file in existing server.xml.
addGenerationCommentToConfig(doc, serverXml);
-
- log.info("Generated the following features: " + missingLibertyFeatures);
+ } else {
+ log.info("Regenerated the following features: " + missingLibertyFeatures);
+ }
} else {
log.info("No additional features were generated.");
if (newServerXmlSrc.exists()) {
@@ -310,6 +314,16 @@ public class GenerateFeaturesMojo extends ServerFeatureSupport {
return existingFeatures;
}
+ // returns the features specified in the generated-features.xml file
+ private Set<String> getGeneratedFeatures(ServerFeatureUtil servUtil, File generatedFeaturesFile) {
+ servUtil.setLowerCaseFeatures(false);
+ Set<String> genFeatSet = new HashSet<String>();
+ servUtil.getServerXmlFeatures(genFeatSet, configDirectory,
+ generatedFeaturesFile, null, null);
+ servUtil.setLowerCaseFeatures(true);
+ return genFeatSet;
+ }
+
/**
* Gets the binary scanner jar file from the local cache.
* Downloads it first from connected repositories such as Maven Central if a newer release is available than the cached version.
