Skip to content

Commit

Permalink
Merge pull request #24453 from mz1999/rmpe
Browse files Browse the repository at this point in the history
Remove com.sun.enterprise.util.ProcessExecutor
  • Loading branch information
arjantijms committed Jun 8, 2023
2 parents b286ffb + 6a622c2 commit 087b911
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 690 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
import com.sun.enterprise.admin.servermgmt.pe.PEFileLayout;
import com.sun.enterprise.universal.glassfish.ASenvPropertyReader;
import com.sun.enterprise.universal.io.SmartFile;
import com.sun.enterprise.universal.process.ProcessManager;
import com.sun.enterprise.universal.process.ProcessManagerException;
import com.sun.enterprise.universal.process.ProcessUtils;
import com.sun.enterprise.util.ExecException;
import com.sun.enterprise.util.OS;
import com.sun.enterprise.util.ProcessExecutor;
import com.sun.enterprise.util.SystemPropertyConstants;
import com.sun.enterprise.util.i18n.StringManager;
import com.sun.enterprise.util.net.NetUtils;
Expand Down Expand Up @@ -86,46 +86,47 @@ public class KeystoreManager {
KEYTOOL_CMD = nonFinalKeyTool;
}

protected static class KeytoolExecutor extends ProcessExecutor {
protected static class KeytoolExecutor extends ProcessManager {

public KeytoolExecutor(String[] args, long timeoutInSeconds) {
super(args, timeoutInSeconds);
setExecutionRetentionFlag(true);
public KeytoolExecutor(String[] args, int timeoutInSeconds) {
super(args);
setTimeoutMsec(timeoutInSeconds * 1000);
addKeytoolCommand();
}

public KeytoolExecutor(String[] args, long timeoutInSeconds, String[] inputLines) {
super(args, timeoutInSeconds, inputLines);
setExecutionRetentionFlag(true);
public KeytoolExecutor(String[] args, int timeoutInSeconds, String[] inputLines) {
super(args);
setTimeoutMsec(timeoutInSeconds * 1000);
setStdinLines(Arrays.asList(inputLines));
addKeytoolCommand();
}

// We must override this message so that the stdout appears in the exec exception.
// Keytool seems to output errors to stdout.
@Override
protected String getExceptionMessage() {
return getLatestOutput(mOutFile) + " " + getFileBuffer(mErrFile);
return getStdout() + " " + getStderr();
}

private void addKeytoolCommand() {
String[] mCmdStrings = builder.command().toArray(new String[0]);
if (!mCmdStrings[0].equals(KEYTOOL_CMD)) {
String[] newArgs = new String[mCmdStrings.length + 1];
newArgs[0] = KEYTOOL_CMD;
System.arraycopy(mCmdStrings, 0, newArgs, 1, mCmdStrings.length);
mCmdStrings = newArgs;
builder.command(Arrays.asList(mCmdStrings));
}
}

public void execute(String keystoreErrorMsg, File keystoreName) throws RepositoryException {
try {
super.execute();
if (getProcessExitValue() != 0) {
if (super.execute() != 0) {
throw new RepositoryException(
_strMgr.getString(keystoreErrorMsg, keystoreName) + getLastExecutionError() + " " + getLastExecutionOutput());
_strMgr.getString(keystoreErrorMsg, keystoreName) + getStderr() + " " + getStdout());
}
} catch (ExecException ex) {
} catch (ProcessManagerException ex) {
throw new RepositoryException(
_strMgr.getString(keystoreErrorMsg, keystoreName) + getLastExecutionError() + " " + getLastExecutionOutput(), ex);
_strMgr.getString(keystoreErrorMsg, keystoreName) + getStderr() + " " + getStdout(), ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.sun.enterprise.universal.io.SmartFile;
import com.sun.enterprise.universal.process.ProcessManager;
import com.sun.enterprise.util.OS;
import com.sun.enterprise.util.ProcessExecutor;
import com.sun.enterprise.util.SystemPropertyConstants;
import com.sun.enterprise.util.i18n.StringManager;
import com.sun.enterprise.util.io.FileUtils;
Expand Down Expand Up @@ -400,11 +399,11 @@ private boolean isUserSmfAuthorized(final String user, final StringBuilder auths
}
try {
final String[] cmd = new String[] { path2Auths, user };
ProcessExecutor pe = new ProcessExecutor(cmd);
pe.setExecutionRetentionFlag(true);
pe.execute();
auths.append(pe.getLastExecutionOutput());
final StringTokenizer st = new StringTokenizer(pe.getLastExecutionOutput(), at);
ProcessManager pm = new ProcessManager(cmd);
pm.setTimeoutMsec(600 * 1000);
pm.execute();
auths.append(pm.getStdout());
final StringTokenizer st = new StringTokenizer(pm.getStdout(), at);
while (st.hasMoreTokens()) {
String t = st.nextToken();
t = t.trim();
Expand All @@ -423,9 +422,9 @@ private boolean serviceNameExists(final String sn) {
boolean exists = false;
try {
final String[] cmd = new String[] { "/usr/bin/svcs", sn };
ProcessExecutor pe = new ProcessExecutor(cmd);
pe.setExecutionRetentionFlag(true);
pe.execute();
ProcessManager pm = new ProcessManager(cmd);
pm.setTimeoutMsec(600 * 1000);
pm.execute();
exists = true;
} catch (final Exception e) {
//returns a non-zero status -- the service does not exist, status is already set
Expand Down Expand Up @@ -462,22 +461,23 @@ private void validateManifest(final String manifestPath) throws Exception {

private void validateService() throws Exception {
final String[] cmda = new String[] { SMFService.SVCCFG, "validate", getManifestFilePath() };
final ProcessExecutor pe = new ProcessExecutor(cmda);
pe.execute();
final ProcessManager pm = new ProcessManager(cmda);
pm.setTimeoutMsec(600 * 1000);
pm.execute();
if (info.trace) {
printOut("Validated the SMF Service: " + info.fqsn + " using: " + SMFService.SVCCFG);
}
}

private boolean importService() throws Exception {
final String[] cmda = new String[] { SMFService.SVCCFG, "import", getManifestFilePath() };
final ProcessExecutor pe = new ProcessExecutor(cmda);

final ProcessManager pm = new ProcessManager(cmda);
pm.setTimeoutMsec(600 * 1000);
if (info.dryRun) {
cleanupManifest();
}
else {
pe.execute(); //throws ExecException in case of an error
pm.execute(); //throws ExecException in case of an error
}

if (info.trace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@
* @since JDK 1.4
* @author bnevins 2005
*/
@Deprecated
public final class ProcessManager {
public class ProcessManager {
private static final Logger LOG = System.getLogger(ProcessManager.class.getName());

private final ProcessBuilder builder;
protected final ProcessBuilder builder;
private final StringBuffer sb_out;
private final StringBuffer sb_err;
private int timeout;
Expand Down

0 comments on commit 087b911

Please sign in to comment.