JavaPropertiesTool.java revision 098ea79a0533517bfd530190dfda99d205b9af19
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008-2009 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* This class is used to update the scripts that are used to launch the command
* lines. We read the contents of a given properties file and we update the
* scripts setting the arguments and JVM to be used by the different scripts.
*
*/
public class JavaPropertiesTool extends ConsoleApplication
{
/** The argument parser. */
/**
* The enumeration containing the different return codes that the command-line
* can have.
*
*/
public enum ErrorReturnCode
{
/**
* Successful setup.
*/
SUCCESSFUL(0),
/**
* We did no have an error but the setup was not executed (displayed version
* or usage).
*/
SUCCESSFUL_NOP(0),
/**
* Unexpected error (potential bug).
*/
ERROR_UNEXPECTED(1),
/**
* Cannot parse arguments or data provided by user is not valid.
*/
ERROR_USER_DATA(2),
/**
* Error writing to destination file.
*/
/**
* Conflicting command line arguments.
*/
CONFLICTING_ARGS(18);
private int returnCode;
private ErrorReturnCode(int returnCode)
{
this.returnCode = returnCode;
}
/**
* Get the corresponding return code value.
*
* @return The corresponding return code value.
*/
public int getReturnCode()
{
return returnCode;
}
}
private static final String OVERWRITE_ENV_JAVA_HOME_PROP_NAME =
"overwrite-env-java-home";
private static final String OVERWRITE_ENV_JAVA_ARGS_PROP_NAME =
"overwrite-env-java-args";
/**
* Constructor for the JavaPropertiesTool object.
*
* @param out the print stream to use for standard output.
* @param err the print stream to use for standard error.
* @param in the input stream to use for standard input.
*/
{
}
/**
* The main method for the java properties tool.
*
* @param args the command-line arguments provided to this program.
*/
{
}
/**
* Parses the provided command-line arguments and uses that information to
* run the java properties tool.
*
* @param args the command-line arguments provided to this program.
*
* @return The error code.
*/
{
}
/**
* Parses the provided command-line arguments and uses that information to
* run the java properties tool.
*
* @param args The command-line arguments provided to this
* program.
* @param outStream The output stream to use for standard output, or
* <CODE>null</CODE> if standard output is not
* needed.
* @param errStream The output stream to use for standard error, or
* <CODE>null</CODE> if standard error is not
* needed.
* @param inStream The input stream to use for standard input.
* @return The error code.
*/
{
}
/**
* Parses the provided command-line arguments and uses that information to
* run the java properties tool.
*
* @param args the command-line arguments provided to this program.
*
* @return the return code (SUCCESSFUL, USER_DATA_ERROR or BUG).
*/
{
JavaPropertiesTool.class.getName());
try
{
}
catch (ArgumentException ae)
{
}
// Validate user provided data
try
{
}
catch (ArgumentException ae)
{
println();
}
if (argParser.usageOrVersionDisplayed())
{
}
try
{
}
catch (FileNotFoundException fnfe)
{
}
try
{
}
catch (IOException ioe)
{
}
try
{
f.setReadable(true, false);
}
catch (IOException ioe)
{
}
boolean overwriteEnvJavaHome = true;
boolean overwriteEnvJavaArgs = true;
while (propertyNames.hasMoreElements())
{
{
{
}
{
}
{
{
overwriteEnvJavaHome = false;
}
}
{
{
overwriteEnvJavaArgs = false;
}
}
}
}
try
{
if (isWindows())
{
}
else
{
}
}
catch (IOException ioe)
{
ioe));
}
// Add some information if we are not in quiet mode about
// what is going to happen.
{
}
else
{
}
println();
}
/**
* Reads the contents of the provided reader and updates the provided
* Properties object with it. This is required because '\' characters in
* windows paths generates problems.
* @param reader the buffered reader.
* @param properties the properties.
* @throws IOException if there is an error reading the buffered reader.
*/
public static void updateProperties(
throws IOException
{
boolean slashInLastLine = false;
{
{
if (!slashInLastLine)
{
sbValue = new StringBuilder();
if (index > 0)
{
{
}
}
}
// Consider the space: in windows the user might add a path ending
// with '\'. With this approach we minimize the possibilities of
// error.
if (hasSlash)
{
}
if (slashInLastLine)
{
}
{
{
}
}
{
{
sbValue = new StringBuilder();
}
}
{
}
}
}
}
/** {@inheritDoc} */
public boolean isQuiet()
{
}
/** {@inheritDoc} */
public boolean isInteractive()
{
return false;
}
/** {@inheritDoc} */
public boolean isMenuDrivenMode() {
return true;
}
/** {@inheritDoc} */
public boolean isScriptFriendly() {
return false;
}
/** {@inheritDoc} */
public boolean isAdvancedMode() {
return false;
}
/** {@inheritDoc} */
public boolean isVerbose() {
return true;
}
{
if (!overwriteJavaHome)
{
}
boolean propertiesAdded = false;
int nIfs = 0;
while (propertyNames.hasMoreElements())
{
{
{
// Already handled
}
{
propertiesAdded = true;
String s;
if (nIfs > 0)
{
if (!overwriteJavaHome)
{
s = " ";
}
else
{
s = "";
}
buf.append(s).append("elif test \"${SCRIPT_NAME}.java-home\" = \"").append(name).append("\"").append(EOL);
}
else if (!overwriteJavaHome)
{
s = " ";
}
else
{
s = "";
}
nIfs++;
}
}
}
if (defaultJavaHome != null)
{
if (propertiesAdded)
{
String s;
if (!overwriteJavaHome)
{
s = " ";
}
else
{
s = "";
}
}
else
{
if (!overwriteJavaHome)
{
}
else
{
}
}
propertiesAdded = true;
}
if (nIfs > 0)
{
String s;
if (!overwriteJavaHome)
{
s = " ";
}
else
{
s = "";
}
}
if (!overwriteJavaHome)
{
if (!propertiesAdded)
{
// No properties added: this is required not to break the script
}
}
else if (defaultJavaHome == null)
{
.append(" echo \"You must specify the path to a valid Java 7.0 ")
.append(" echo \"properties file and then run the ")
.append(" echo \"You must specify the path to a valid Java 7.0 ")
.append(" echo \"1. Delete the file ")
.append(" echo \"2. Set the environment variable ")
.append(" echo \"If you want to have specificjava settings for")
.append(" echo \"3. Edit the properties file specifying the ")
.append(" echo \"for each command line. The java properties ")
.append(" echo \"4. Run the command-line ")
}
if (!overwriteJavaArgs)
{
}
propertiesAdded = false;
nIfs = 0;
while (propertyNames.hasMoreElements())
{
{
{
// Already handled
}
{
propertiesAdded = true;
if (nIfs > 0)
{
buf.append(s).append(" elif test \"${SCRIPT_NAME}.java-args\" = \"").append(name).append("\"").append(EOL);
}
else if (!overwriteJavaArgs)
{
}
else
{
}
nIfs++;
}
}
}
if (defaultJavaArgs != null)
{
if (propertiesAdded)
{
}
else
{
if (!overwriteJavaArgs)
{
}
else
{
}
}
propertiesAdded = true;
}
if (nIfs > 0)
{
}
if (!overwriteJavaArgs)
{
if (!propertiesAdded)
{
// No properties added: this is required not to break the script
}
}
}
{
if (!overwriteJavaHome)
{
}
else
{
}
if (!overwriteJavaArgs)
{
}
else
{
}
if (javaHomeLabel1 == CHECK_ENV_JAVA_HOME)
{
buf.append("if \"%OPENDJ_JAVA_HOME%\" == \"\" goto ").append(javaHomeLabel2).append(LEGACY).append(EOL)
.append("if \"%OPENDS_JAVA_HOME%\" == \"\" goto ")
}
else
{
buf.append("if \"%OPENDJ_JAVA_HOME%\" == \"\" goto ").append(javaArgsLabel1).append(LEGACY).append(EOL)
.append("if \"%OPENDS_JAVA_HOME%\" == \"\" goto ")
}
if (defaultJavaHome != null)
{
if (javaHomeLabel1 == CHECK_ENV_JAVA_HOME)
{
}
else
{
}
}
while (propertyNames.hasMoreElements())
{
{
// Already handled
}
{
}
}
if (defaultJavaHome != null)
{
}
else if (javaHomeLabel1 != CHECK_ENV_JAVA_HOME)
{
}
else
{
}
while (propertyNames.hasMoreElements())
{
{
// Already handled
}
{
if (defaultJavaHome != null)
{
}
else if (javaHomeLabel1 != CHECK_ENV_JAVA_HOME)
{
}
}
}
if (javaArgsLabel1 == CHECK_ENV_JAVA_ARGS)
{
buf.append("if \"%OPENDJ_JAVA_ARGS%\" == \"\" goto ").append(javaArgsLabel2).append(LEGACY).append(EOL)
}
else
{
}
if (defaultJavaArgs != null)
{
}
while (propertyNames.hasMoreElements())
{
{
// Already handled
}
{
}
}
if (defaultJavaArgs != null)
{
}
else if (javaArgsLabel1 != CHECK_ENV_JAVA_ARGS)
{
}
else
{
}
while (propertyNames.hasMoreElements())
{
{
// Already handled
}
{
}
}
}
}