Skip to content

Commit

Permalink
Merge pull request #387 from cherylking/addBuildDirInstallFeature
Browse files Browse the repository at this point in the history
Enable schema regen for Liberty Tools
  • Loading branch information
cherylking authored Sep 28, 2022
2 parents 9b65570 + 678e848 commit 261a0ce
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import org.xml.sax.SAXException;

import org.apache.maven.artifact.versioning.DefaultArtifactVersion;

import org.apache.commons.io.FileUtils;


/**
Expand All @@ -83,6 +83,8 @@ public abstract class InstallFeatureUtil extends ServerFeatureUtil {

private final File installDirectory;

private final File buildDirectory;

private File installJarFile;

private final List<ProductProperties> propertiesList;
Expand Down Expand Up @@ -126,8 +128,9 @@ public abstract class InstallFeatureUtil extends ServerFeatureUtil {
* @throws PluginExecutionException If properties files cannot be found in the
* installDirectory/lib/versions
*/
public InstallFeatureUtil(File installDirectory, String from, String to, Set<String> pluginListedEsas, List<ProductProperties> propertiesList, String openLibertyVersion, String containerName, List<String> additionalJsons) throws PluginScenarioException, PluginExecutionException {
public InstallFeatureUtil(File installDirectory, File buildDirectory, String from, String to, Set<String> pluginListedEsas, List<ProductProperties> propertiesList, String openLibertyVersion, String containerName, List<String> additionalJsons) throws PluginScenarioException, PluginExecutionException {
this.installDirectory = installDirectory;
this.buildDirectory = buildDirectory;
this.to = to;
this.propertiesList = propertiesList;
this.openLibertyVersion = openLibertyVersion;
Expand Down Expand Up @@ -651,6 +654,17 @@ public void installFeatures(boolean isAcceptLicense, List<String> featuresList)
}
productInfoValidate();
info("The following features have been installed: " + installedFeaturesBuilder.toString());

// Look for and remove .libertyls folder (Liberty Tools) to cause regeneration of the schema
File schemaGenDir = new File(buildDirectory, ".libertyls");
if (schemaGenDir.exists() && schemaGenDir.isDirectory()) {
try {
FileUtils.deleteDirectory(schemaGenDir);
debug("Deleted .libertyls directory after installing features.");
} catch (IOException e) {
debug("Could not delete .libertyls directory after installing features.");
}
}
} catch (PrivilegedActionException e) {
throw new PluginExecutionException("Could not load the jar " + installJarFile.getAbsolutePath(), e);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class BaseInstallFeatureUtilTest {
private static final String RESOURCES_INSTALL_DIR = RESOURCES_DIR + "/installdir";

public File installDir;
public File buildDir;

@Rule
public TemporaryFolder temp = new TemporaryFolder();
Expand All @@ -45,11 +46,13 @@ public void setupInstallDir() throws IOException {
installDir = temp.newFolder();
File src = new File(RESOURCES_INSTALL_DIR);
FileUtils.copyDirectory(src, installDir);

buildDir = temp.newFolder();
}

public class InstallFeatureTestUtil extends InstallFeatureUtil {
public InstallFeatureTestUtil(File installDirectory, String from, String to, Set<String> pluginListedEsas, List<ProductProperties> propertiesList, String openLibertyVersion, List<String> additionalJsons) throws PluginScenarioException, PluginExecutionException {
super(installDirectory, from, to, pluginListedEsas, propertiesList, openLibertyVersion, null, additionalJsons);
public InstallFeatureTestUtil(File installDirectory, File buildDirectory, String from, String to, Set<String> pluginListedEsas, List<ProductProperties> propertiesList, String openLibertyVersion, List<String> additionalJsons) throws PluginScenarioException, PluginExecutionException {
super(installDirectory, buildDirectory, from, to, pluginListedEsas, propertiesList, openLibertyVersion, null, additionalJsons);
}

@Override
Expand Down Expand Up @@ -99,15 +102,15 @@ public File downloadArtifact(String groupId, String artifactId, String type, Str
}

public InstallFeatureUtil getNewInstallFeatureUtil() throws PluginExecutionException, PluginScenarioException {
return getNewInstallFeatureUtil(installDir, null, null, new HashSet<String>());
return getNewInstallFeatureUtil(installDir, buildDir, null, null, new HashSet<String>());
}

public InstallFeatureUtil getNewInstallFeatureUtil(File installDirectory, String from, String to, Set<String> pluginListedEsas) throws PluginExecutionException, PluginScenarioException {
public InstallFeatureUtil getNewInstallFeatureUtil(File installDirectory, File buildDirectory, String from, String to, Set<String> pluginListedEsas) throws PluginExecutionException, PluginScenarioException {
List<ProductProperties> propertiesList = InstallFeatureUtil.loadProperties(installDirectory);
String openLibertyVersion = InstallFeatureUtil.getOpenLibertyVersion(propertiesList);
List<String> additionalJsons = new ArrayList<String>();

return new InstallFeatureTestUtil(installDirectory, from, to, pluginListedEsas, propertiesList, openLibertyVersion, additionalJsons);
return new InstallFeatureTestUtil(installDirectory, buildDirectory, from, to, pluginListedEsas, propertiesList, openLibertyVersion, additionalJsons);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testConstructorNoProperties() throws Exception {
File wlProps = new File(installDir, "lib/versions/WebSphereApplicationServer.properties");
assertTrue(olProps.delete());
assertTrue(wlProps.delete());
getNewInstallFeatureUtil(installDir, null, null, new HashSet<String>());
getNewInstallFeatureUtil(installDir, buildDir, null, null, new HashSet<String>());
}

/**
Expand All @@ -57,7 +57,7 @@ public void testConstructorNoProperties() throws Exception {
public void testConstructorNoInstallMap() throws Exception {
File installMap = new File(installDir, "lib/com.ibm.ws.install.map_1.0.21.jar");
assertTrue(installMap.delete());
getNewInstallFeatureUtil(installDir, null, null, new HashSet<String>());
getNewInstallFeatureUtil(installDir, buildDir, null, null, new HashSet<String>());
}

/**
Expand All @@ -67,7 +67,7 @@ public void testConstructorNoInstallMap() throws Exception {
public void testConstructorNoOpenLibertyProperties() throws Exception {
File olProps = new File(installDir, "lib/versions/openliberty.properties");
assertTrue(olProps.delete());
getNewInstallFeatureUtil(installDir, null, null, new HashSet<String>());
getNewInstallFeatureUtil(installDir, buildDir, null, null, new HashSet<String>());
}

/**
Expand All @@ -79,12 +79,12 @@ public void testConstructorNoInstallMapNoOpenLibertyProperties() throws Exceptio
assertTrue(olProps.delete());
File installMap = new File(installDir, "lib/com.ibm.ws.install.map_1.0.21.jar");
assertTrue(installMap.delete());
getNewInstallFeatureUtil(installDir, null, null, new HashSet<String>());
getNewInstallFeatureUtil(installDir, buildDir, null, null, new HashSet<String>());
}

@Test
public void testConstructorTo() throws Exception {
InstallFeatureUtil util = getNewInstallFeatureUtil(installDir, null, "myextension", new HashSet<String>());
InstallFeatureUtil util = getNewInstallFeatureUtil(installDir, buildDir, null, "myextension", new HashSet<String>());
assertNotNull(util);
}

Expand All @@ -93,7 +93,7 @@ public void testConstructorTo() throws Exception {
*/
@Test(expected = PluginScenarioException.class)
public void testConstructorFrom() throws Exception {
getNewInstallFeatureUtil(installDir, installDir.getAbsolutePath(), null, new HashSet<String>());
getNewInstallFeatureUtil(installDir, buildDir, installDir.getAbsolutePath(), null, new HashSet<String>());
}

/**
Expand All @@ -103,7 +103,7 @@ public void testConstructorFrom() throws Exception {
public void testConstructorEsas() throws Exception {
Set<String> esas = new HashSet<String>();
esas.add("abc.esa");
getNewInstallFeatureUtil(installDir, null, null, esas);
getNewInstallFeatureUtil(installDir, buildDir, null, null, esas);
}

/**
Expand Down Expand Up @@ -193,7 +193,7 @@ public void testDownloadOverrideBundle() throws Exception {
List<ProductProperties> propertiesList = InstallFeatureUtil.loadProperties(installDir);
String openLibertyVersion = InstallFeatureUtil.getOpenLibertyVersion(propertiesList);
List<String> additionalJsons = new ArrayList<String>();
InstallFeatureUtil util = new InstallFeatureTestUtil(installDir, null, null, new HashSet<String>(), propertiesList, openLibertyVersion, additionalJsons) {
InstallFeatureUtil util = new InstallFeatureTestUtil(installDir, buildDir, null, null, new HashSet<String>(), propertiesList, openLibertyVersion, additionalJsons) {
@Override
public File downloadArtifact(String groupId, String artifactId, String type, String version)
throws PluginExecutionException {
Expand Down

0 comments on commit 261a0ce

Please sign in to comment.