Skip to content

Commit

Permalink
Merge pull request #6003 from kalinchan/Revert-FISH-6588-P5
Browse files Browse the repository at this point in the history
Revert "Merge pull request #5991 from Pandrex247/FISH-6588"
  • Loading branch information
kalinchan authored Oct 27, 2022
2 parents 5e3fd7e + aa9227b commit 4ccc729
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ public PayaraMicroRuntime bootStrap() throws BootstrapException {
gfproperties.setConfigFileURI(runtimeDir.getDomainXML().toURI().toString());

try {
parsePreBootCommandFiles();
configureCommandFiles();
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Unable to load command file", ex);
}
Expand All @@ -1078,12 +1078,7 @@ public PayaraMicroRuntime bootStrap() throws BootstrapException {
callHandler(preBootHandler);
gf.start();

// Parse and execute post boot commands
try {
parsePostBootCommandFiles();
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Unable to load command file", ex);
}
// Execute post boot commands
postBootCommands.executeCommands(gf.getCommandRunner());
callHandler(postBootHandler);
this.runtime = new PayaraMicroRuntimeImpl(gf, gfruntime);
Expand All @@ -1093,12 +1088,6 @@ public PayaraMicroRuntime bootStrap() throws BootstrapException {
// These steps are separated in case any steps need to be done in between
gf.getCommandRunner().run("initialize-all-applications");

// Parse and execute post deploy commands
try {
parsePostDeployCommandFiles();
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Unable to load command file", ex);
}
postDeployCommands.executeCommands(gf.getCommandRunner());

long end = System.currentTimeMillis();
Expand Down Expand Up @@ -1871,53 +1860,33 @@ private ByteArrayInputStream replaceEnvProperties(InputStream is) throws IOExcep
return new ByteArrayInputStream(writer.getBuffer().toString().getBytes());
}

/**
* Helper method to parse the pre-boot command file.
*
* @throws IOException
*/
private void parsePreBootCommandFiles() throws IOException {
parseCommandFiles("MICRO-INF/pre-boot-commands.txt", preBootFileName, preBootCommands, false);
}
private void configureCommandFiles() throws IOException {
// load the embedded files
URL scriptURL = Thread.currentThread().getContextClassLoader().getResource("MICRO-INF/pre-boot-commands.txt");
if (scriptURL != null) {
preBootCommands.parseCommandScript(scriptURL);
}

/**
* Helper method to parse the post-boot command file.
*
* @throws IOException
*/
private void parsePostBootCommandFiles() throws IOException {
parseCommandFiles("MICRO-INF/post-boot-commands.txt", postBootFileName, postBootCommands, true);
}
if (preBootFileName != null) {
preBootCommands.parseCommandScript(new File(preBootFileName));
}

/**
* Helper method to parse the post-deploy command file.
*
* @throws IOException
*/
private void parsePostDeployCommandFiles() throws IOException {
parseCommandFiles("MICRO-INF/post-deploy-commands.txt", postDeployFileName, postDeployCommands, true);
}
scriptURL = Thread.currentThread().getContextClassLoader().getResource("MICRO-INF/post-boot-commands.txt");
if (scriptURL != null) {
postBootCommands.parseCommandScript(scriptURL);
}

/**
* Parse the pre-boot, post-boot, or post-deploy command files - both the embedded one in MICRO-INF and the file
* provided by the user.
*
* @param resourcePath The path of the embedded pre-boot, post-boot, or post-deploy command file.
* @param fileName The path of the pre-boot, post-boot, or post-deploy command file provided by the user.
* @param bootCommands The {@link BootCommands} object to add the parsed commands to.
* @param expandValues Whether variable expansion should be attempted - cannot be done during pre-boot.
* @throws IOException
*/
private void parseCommandFiles(String resourcePath, String fileName, BootCommands bootCommands,
boolean expandValues) throws IOException {
// Load the embedded file
URL scriptURL = Thread.currentThread().getContextClassLoader().getResource(resourcePath);
if (postBootFileName != null) {
postBootCommands.parseCommandScript(new File(postBootFileName));
}

scriptURL = Thread.currentThread().getContextClassLoader().getResource("MICRO-INF/post-deploy-commands.txt");
if (scriptURL != null) {
bootCommands.parseCommandScript(scriptURL, expandValues);
postDeployCommands.parseCommandScript(scriptURL);
}

if (fileName != null) {
bootCommands.parseCommandScript(new File(fileName), expandValues);
if (postDeployFileName != null) {
postDeployCommands.parseCommandScript(new File(postDeployFileName));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,51 +94,27 @@ public List<BootCommand> getCommands() {
return commands;
}

/**
* Parse the given pre-boot, post-boot, or post-deploy command file, optionally performing variable expansion.
*
* @param file The {@link File} to parse commands from
* @param expandValues Whether variable expansion should be performed - cannot be done during pre-boot
* @throws IOException
*/
public void parseCommandScript(File file, boolean expandValues) throws IOException {
parseCommandScript(file.toURI().toURL(), expandValues);
public void parseCommandScript(File file) throws IOException {
parseCommandScript(file.toURI().toURL());
}

/**
* Parse the given pre-boot, post-boot, or post-deploy command file, optionally performing variable expansion.
*
* @param scriptURL The {@link URL} to parse commands from
* @param expandValues Whether variable expansion should be performed - cannot be done during pre-boot
* @throws IOException
*/
public void parseCommandScript(URL scriptURL, boolean expandValues) throws IOException {
public void parseCommandScript(URL scriptURL) throws IOException {
try (InputStream scriptStream = scriptURL.openStream()) {
Reader reader = new InputStreamReader(scriptStream);
parseCommandScript(reader, expandValues);
parseCommandScript(reader);
} catch (IOException ex) {
LOGGER.log(SEVERE, null, ex);
}
}

/**
* Parse the given pre-boot, post-boot, or post-deploy command file, optionally performing variable expansion.
*
* @param reader The {@link Reader} to parse commands from
* @param expandValues Whether variable expansion should be performed - cannot be done during pre-boot
* @throws IOException
*/
void parseCommandScript(Reader reader, boolean expandValues) throws IOException {
void parseCommandScript(Reader reader) throws IOException {
BufferedReader bufferReader = new BufferedReader(reader);
String commandStr = bufferReader.readLine();
while (commandStr != null) {
commandStr = commandStr.trim();
// # is a comment
if (commandStr.length() > 0 && !commandStr.startsWith("#")) {
// Variable expansion cannot be done during pre-boot since the required services won't have started yet
if (expandValues) {
commandStr = TranslatedConfigView.expandValue(commandStr);
}
commandStr = TranslatedConfigView.expandValue(commandStr);
String[] command;
List<String> elements = new ArrayList<>();
Matcher flagMatcher = COMMAND_FLAG_PATTERN.matcher(commandStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

import fish.payara.boot.runtime.BootCommand;
import fish.payara.boot.runtime.BootCommands;
import org.junit.Test;

/**
Expand All @@ -59,7 +61,7 @@ public void parseCommand() throws IOException {
BootCommands bootCommands = new BootCommands();
String commandText = "create-custom-resource --restype java.lang.String -s v --name='custom-res' --description=\"results \\\"in\\\" error\" --property value=\"${ENV=ini_ws_uri}\" vfp/vfp-menu/ini.ws.uri";
try (Reader reader = new StringReader(commandText)){
bootCommands.parseCommandScript(reader, false);
bootCommands.parseCommandScript(reader);
}
assertThat(bootCommands.getCommands().size(), is(1));

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ public void launch(Properties ctx) throws Exception {
addShutdownHook();
gfr = GlassFishRuntime.bootstrap(new BootstrapProperties(ctx), getClass().getClassLoader());
gf = gfr.newGlassFish(new GlassFishProperties(ctx));
// Services required for variable expansion aren't available during pre-boot, so don't expand values
doBootCommands(ctx.getProperty("-prebootcommandfile"), false);
doBootCommands(ctx.getProperty("-prebootcommandfile"));
if (Boolean.valueOf(Util.getPropertyOrSystemProperty(ctx, "GlassFish_Interactive", "false"))) {
startConsole();
} else {
Expand Down Expand Up @@ -294,14 +293,14 @@ private List<String> parseCommand(String line) {
* Runs a series of commands from a file
* @param file
*/
private void doBootCommands(String file, boolean expandValues) {
private void doBootCommands(String file) {
if (file == null) {
return;
}
try {
BootCommands bootCommands = new BootCommands();
System.out.println("Reading in commandments from " + file);
bootCommands.parseCommandScript(new File(file), expandValues);
bootCommands.parseCommandScript(new File(file));
bootCommands.executeCommands(gf.getCommandRunner());
} catch (IOException ex) {
LOGGER.log(SEVERE, "Error reading from file");
Expand Down
Loading

0 comments on commit 4ccc729

Please sign in to comment.