Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public ServerConfigDocument(CommonLoggerI log, File originalServerXMLFile, Map<S
this.originalServerXMLFile = originalServerXMLFile;
}

private DocumentBuilder getDocumentBuilder() {
private static DocumentBuilder getDocumentBuilder() {
DocumentBuilder docBuilder;

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
Expand Down Expand Up @@ -1005,4 +1005,32 @@ public void setSpringBootAppNodeLocation(Optional<String> springBootAppNodeLocat
this.springBootAppNodeLocation = springBootAppNodeLocation;
}

/**
* Parses a loose application XML file and returns a list of all sourceOnDisk
* attribute values found on {@code <file>} and {@code <dir>} elements.
*
* @param looseAppFile - the loose application XML file to parse
* @return a List of sourceOnDisk path strings; empty if none are found or the file cannot be parsed
* @throws FileNotFoundException if the file does not exist
* @throws IOException if the file cannot be read
*/
public static Set<String> getSourceOnDiskPaths(File looseAppFile) throws FileNotFoundException, IOException {
Set<String> result = new HashSet<String>();
Document doc;
try (FileInputStream is = new FileInputStream(looseAppFile)) {
doc = getDocumentBuilder().parse(is);
} catch (SAXException e) {
return result; // not valid XML
}
for (String tag : new String[]{"file", "dir"}) {
NodeList nodes = doc.getElementsByTagName(tag);
for (int i = 0; i < nodes.getLength(); i++) {
org.w3c.dom.Node attr = nodes.item(i).getAttributes().getNamedItem("sourceOnDisk");
if (attr != null && !attr.getNodeValue().isEmpty()) {
result.add(attr.getNodeValue());
}
}
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5878,7 +5878,7 @@ protected void triggerMainModuleCompile(boolean testsOnly) throws IOException {

/**
* Trigger a compile of the entire specified module. This is only used in a
* multi-module scenario. Adds all Java files to the to be compiled list so that
* multi-module scenario. Adds all Java files to the to-be-compiled list so that
* they will be compiled on next watch loop.
*
* @param project ProjectModule, the module to be compiled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.openliberty.tools.common.plugins.util;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
Expand All @@ -26,6 +27,8 @@
import java.util.Map;
import java.util.Set;

import io.openliberty.tools.common.plugins.config.ServerConfigDocument;

public abstract class FeatureGeneratorUtil {

public static final String FEATURE_GEN_MAVEN_GROUP_ID = "com.ibm.websphere.appmod.tools";
Expand Down Expand Up @@ -135,6 +138,7 @@ public FeatureGeneratorUtil(File featureGen) {
* @param currentFeatureSet - the features already specified in the server configuration
* @param classFiles - a set of class files for the generator to handle. Should be a subset of allClassesDirectories
* @param allClassesDirectories - the directories containing all the class files of the application
* @param looseConfigFilePath - the absolute path to the xml config of the loose application
* @param logLocation - directory name relative to project or absolute path passed to feature generator
* @param targetJavaEE - generate features valid for the indicated version of EE
* @param targetMicroProfile - generate features valid for the indicated version of MicroProfile
Expand All @@ -155,7 +159,7 @@ public FeatureGeneratorUtil(File featureGen) {
* generator when used in combination with each other. E.g. EE 7 and MP 2.1
*/
public Set<String> runFeatureGenerator(Set<String> currentFeatureSet, List<String> classFiles, Set<String> allClassesDirectories,
String logLocation, String targetJavaEE, String targetMicroProfile, Map featureListFileMap, boolean optimize)
String looseConfigFilePath, String logLocation, String targetJavaEE, String targetMicroProfile, Map featureListFileMap, boolean optimize)
throws PluginExecutionException, NoRecommendationException, RecommendationSetException, FeatureModifiedException,
FeatureUnavailableException, IllegalTargetException, IllegalTargetComboException, VersionlessFeatureDetectedException {
Set<String> generatedFeatureList = null;
Expand All @@ -167,7 +171,8 @@ public Set<String> runFeatureGenerator(Set<String> currentFeatureSet, List<Strin
try {
Method generateFeatureSetMethod = getGeneratorMethod();
// names: binaryInputs, targetJavaEE, targetMicroProfile, currentFeatures, logLocation, logLevel, locale
Set<String> binaryInputs = getBinaryInputs(classFiles, allClassesDirectories, optimize);
Set<String> binaryInputs = getBinaryInputs(classFiles, allClassesDirectories, looseConfigFilePath, optimize);

String logLevel;
if (isDebugEnabled()) {
logLevel = "*=FINE"; // generate messages for debugging by support team
Expand Down Expand Up @@ -384,9 +389,24 @@ private Method getGeneratorMethod() throws MalformedURLException, ClassNotFoundE
return featureGenMethod;
}

private static Set<String> getBinaryInputs(List<String> classFiles, Set<String> classDirectories, boolean optimize) throws PluginExecutionException {
private Set<String> getBinaryInputs(List<String> classFiles, Set<String> classDirectories, String looseConfigFilePath, boolean optimize) throws PluginExecutionException {
Set<String> resultSet;
if (optimize) {
// Use either the loose app config or the class directories
if (looseConfigFilePath != null) {
try {
File looseAppFile = new File(looseConfigFilePath);
if (looseAppFile.exists()) {
resultSet = ServerConfigDocument.getSourceOnDiskPaths(looseAppFile);
if (!resultSet.isEmpty()) {
return resultSet;
}
}
} catch (IOException e) {
// if the app config is invalid try the class directories instead
}
warn("Application descriptor file not found while generating features, using class files instead: " + looseConfigFilePath);
}
if (classDirectories == null || classDirectories.isEmpty()) {
return new HashSet<String>();
}
Expand Down
Loading