Handle optimizing or non-optimizing cases
@@ -55,7 +55,7 @@ import io.openliberty.tools.maven.InstallFeatureSupport;
public class GenerateFeaturesMojo extends InstallFeatureSupport {
private static final String GENERATED_FEATURES_FILE_NAME = "generated-features.xml";
- protected static final String GENERATED_FEATURES_FILE_PATH = "configDropins/overrides/generated-features.xml";
+ protected static final String GENERATED_FEATURES_FILE_PATH = "configDropins/overrides/" + GENERATED_FEATURES_FILE_NAME;
protected static final String FEATURES_FILE_MESSAGE = "The Liberty Maven Plugin has generated Liberty features necessary for your application in " + GENERATED_FEATURES_FILE_PATH;
protected static final String HEADER = "# Generated by liberty-maven-plugin";
@@ -108,13 +108,11 @@ public class GenerateFeaturesMojo extends InstallFeatureSupport {
util.setLowerCaseFeatures(false);
final boolean optimize = (classFiles == null || classFiles.isEmpty()) ? true : false;
- Set<String> dropinsFilesToIgnore = null;
- if (optimize) {
- dropinsFilesToIgnore = new HashSet<String>();
- dropinsFilesToIgnore.add(GENERATED_FEATURES_FILE_NAME);
- }
+ Set<String> generatedFiles = new HashSet<String>();
+ generatedFiles.add(GENERATED_FEATURES_FILE_NAME);
- Set<String> existingFeatures = util.getServerFeatures(serverDirectory, libertyDirPropertyFiles, dropinsFilesToIgnore);
+ // if optimizing, ignore generated files when passing in existing features to binary scanner
+ Set<String> existingFeatures = util.getServerFeatures(serverDirectory, libertyDirPropertyFiles, optimize ? generatedFiles : null);
if (existingFeatures == null) {
existingFeatures = new HashSet<String>();
}
@@ -141,7 +139,15 @@ public class GenerateFeaturesMojo extends InstallFeatureSupport {
Set<String> missingLibertyFeatures = new HashSet<String>();
if (scannedFeatureList != null) {
missingLibertyFeatures.addAll(scannedFeatureList);
- missingLibertyFeatures.removeAll(existingFeatures);
+
+ util.setLowerCaseFeatures(false);
+ // get set of user defined features so they can be omitted from the generated file that will be written
+ Set<String> userDefinedFeatures = optimize ? existingFeatures : util.getServerFeatures(serverDirectory, libertyDirPropertyFiles, generatedFiles);
+ log.debug("User defined features:" + userDefinedFeatures);
+ util.setLowerCaseFeatures(true);
+ if (userDefinedFeatures != null) {
+ missingLibertyFeatures.removeAll(userDefinedFeatures);
+ }
}
log.debug("Features detected by binary scanner which are not in server.xml" + missingLibertyFeatures);
