/*
* 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-2013 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.
*
*/
{
// The argument parser
/**
* The enumeration containing the different return codes that the command-line
* can have.
*
*/
public enum ErrorReturnCode
{
/**
* Successful setup.
*/
/**
* We did no have an error but the setup was not executed (displayed version
* or usage).
*/
/**
* Unexpected error (potential bug).
*/
/**
* Cannot parse arguments or data provided by user is not valid.
*/
/**
* Error writing to destination file.
*/
private int returnCode;
{
this.returnCode = returnCode;
}
/**
* Get the corresponding return code value.
*
* @return The corresponding return code value.
*/
public int getReturnCode()
{
return returnCode;
}
}
"overwrite-env-java-home";
"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
{
{
}
else
{
}
}
catch (IOException ioe)
{
ioe));
}
// Add some information if we are not in quiet mode about
// what is going to happen.
{
}
else
{
}
}
/**
* 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)
{
"# See if the environment variables for java home are set"+EOL+
"# in the path and try to figure it out."+EOL+
"if test ! -f \"${OPENDJ_JAVA_BIN}\""+EOL+
"then"+EOL+
" if test ! -d \"${OPENDJ_JAVA_HOME}\""+EOL+
" then"+EOL+
" if test ! -f \"${OPENDS_JAVA_BIN}\""+EOL+
" then"+EOL+
" if test ! -d \"${OPENDS_JAVA_HOME}\""+EOL);
}
boolean propertiesAdded = false;
int nIfs = 0;
while (propertyNames.hasMoreElements())
{
{
{
// Already handled
}
{
propertiesAdded = true;
String s;
if (nIfs > 0)
{
if (!overwriteJavaHome)
{
s = " ";
}
else
{
s = "";
}
}
else if (!overwriteJavaHome)
{
" then"+EOL+
s = " ";
}
else
{
s = "";
}
s+"then"+EOL+
s+" if test -f \"${TEMP}\""+EOL+
s+" then"+EOL+
s+" export OPENDJ_JAVA_BIN"+EOL+
s+" fi"+EOL);
nIfs++;
}
}
}
if (defaultJavaHome != null)
{
if (propertiesAdded)
{
String s;
if (!overwriteJavaHome)
{
s = " ";
}
else
{
s = "";
}
s+"else"+EOL+
s+" export OPENDJ_JAVA_BIN"+EOL);
}
else
{
if (!overwriteJavaHome)
{
" then"+EOL+
" if test -f \"${TEMP}\""+EOL+
" then"+EOL+
" OPENDJ_JAVA_BIN=\"${TEMP}\""+EOL+
" export OPENDJ_JAVA_BIN"+EOL+
" fi"+EOL);
}
else
{
"export OPENDJ_JAVA_BIN"+EOL);
}
}
propertiesAdded = true;
}
if (nIfs > 0)
{
String s;
if (!overwriteJavaHome)
{
s = " ";
}
else
{
s = "";
}
s+"fi"+EOL);
}
if (!overwriteJavaHome)
{
if (!propertiesAdded)
{
// No properties added: this is required not to break the script
" then"+EOL+
" OPENDJ_JAVA_BIN=\"${OPENDJ_JAVA_BIN}\""+EOL);
}
" else"+EOL+
" export OPENDJ_JAVA_BIN"+EOL+
" fi"+EOL+
" else"+EOL+
" OPENDJ_JAVA_BIN=\"${OPENDS_JAVA_BIN}\""+EOL+
" export OPENDJ_JAVA_BIN"+EOL+
" fi"+EOL+
" else"+EOL+
" export OPENDJ_JAVA_BIN"+EOL+
" fi"+EOL+
}
else if (defaultJavaHome == null)
{
EOL+
"if test ! -f \"${OPENDJ_JAVA_BIN}\""+EOL+
"then"+EOL+
" if test ! -d \"${OPENDJ_JAVA_HOME}\""+EOL+
" then"+EOL+
" if test ! -f \"${OPENDS_JAVA_BIN}\""+EOL+
" then"+EOL+
" if test ! -d \"${OPENDS_JAVA_HOME}\""+EOL+
" then"+EOL+
" if test ! -f \"${JAVA_BIN}\""+EOL+
" then"+EOL+
" if test ! -d \"${JAVA_HOME}\""+EOL+
" then"+EOL+
" if test ${?} -eq 0"+EOL+
" then"+EOL+
" export OPENDJ_JAVA_BIN"+EOL+
" else"+EOL+
" echo \"You must specify the path to a valid Java 6.0 "+
"or higher version in the\""+EOL+
" echo \"properties file and then run the "+
"dsjavaproperties tool. \""+EOL+
" echo \"The procedure to follow is:\""+EOL+
" echo \"You must specify the path to a valid Java 6.0 "+
"or higher version. The \""+EOL+
" echo \"procedure to follow is:\""+EOL+
" echo \"1. Delete the file "+
"${INSTANCE_ROOT}/lib/set-java-home\""+EOL+
" echo \"2. Set the environment variable "+
"OPENDJ_JAVA_HOME to the root of a valid \""+EOL+
" echo \"Java 6.0 installation.\""+EOL+
" echo \"If you want to have specificjava settings for"+
" each command line you must\""+EOL+
" echo \"follow the steps 3 and 4\""+EOL+
" echo \"3. Edit the properties file specifying the "+
"java binary and the java arguments\""+EOL+
" echo \"for each command line. The java properties "+
"file is located in:\""+EOL+
" echo \"${INSTANCE_ROOT}/config/java.properties.\""+EOL+
" echo \"4. Run the command-line "+
"${INSTANCE_ROOT}/bin/dsjavaproperties\""+EOL+
" exit 1"+EOL+
" fi"+EOL+
" else"+EOL+
" export OPENDJ_JAVA_BIN"+EOL+
" fi"+EOL+
" else"+EOL+
" OPENDJ_JAVA_BIN=\"${JAVA_BIN}\""+EOL+
" export OPENDJ_JAVA_BIN"+EOL+
" fi"+EOL+
" else"+EOL+
" export OPENDJ_JAVA_BIN"+EOL+
" fi"+EOL+
" else"+EOL+
" OPENDJ_JAVA_BIN=\"${OPENDS_JAVA_BIN}\""+EOL+
" export OPENDJ_JAVA_BIN"+EOL+
" fi"+EOL+
" else"+EOL+
" export OPENDJ_JAVA_BIN"+EOL+
" fi"+EOL+
}
if (!overwriteJavaArgs)
{
EOL+
"# See if the environment variables for arguments are set."+EOL+
"if test -z \"${OPENDJ_JAVA_ARGS}\""+EOL+
"then"+EOL+
" if test -z \"${OPENDS_JAVA_ARGS}\""+EOL);
}
propertiesAdded = false;
nIfs = 0;
while (propertyNames.hasMoreElements())
{
{
{
// Already handled
}
{
propertiesAdded = true;
if (nIfs > 0)
{
}
else if (!overwriteJavaArgs)
{
" then"+EOL+
}
else
{
}
s+" then"+EOL+
s+" export OPENDJ_JAVA_ARGS"+EOL);
nIfs++;
}
}
}
if (defaultJavaArgs != null)
{
if (propertiesAdded)
{
s+" else"+EOL+
s+" export OPENDJ_JAVA_ARGS"+EOL);
}
else
{
if (!overwriteJavaArgs)
{
" then"+EOL+
" export OPENDJ_JAVA_ARGS"+EOL);
}
else
{
EOL+
" export OPENDJ_JAVA_ARGS"+EOL);
}
}
propertiesAdded = true;
}
if (nIfs > 0)
{
}
if (!overwriteJavaArgs)
{
if (!propertiesAdded)
{
// No properties added: this is required not to break the script
" then"+EOL+
" OPENDJ_JAVA_ARGS=${OPENDJ_JAVA_ARGS}"+EOL);
}
" else"+EOL+
" OPENDJ_JAVA_ARGS=${OPENDS_JAVA_ARGS}"+EOL+
" export OPENDJ_JAVA_ARGS"+EOL+
" fi"+EOL+
"fi"+EOL);
}
}
{
if (!overwriteJavaHome)
{
}
else
{
}
if (!overwriteJavaArgs)
{
}
else
{
}
"if \"%OPENDS_JAVA_BIN%\" == \"\" goto checkOpendjJavaHome"+EOL+
"if not exist \"%OPENDS_JAVA_BIN%\" goto checkOpendjJavaHome"+EOL+
":checkOpendjJavaHome"+EOL
);
if (javaHomeLabel1 == CHECK_ENV_JAVA_HOME)
{
"set TEMP_EXE=%OPENDJ_JAVA_HOME%\\bin\\java.exe"+EOL+
"set OPENDJ_JAVA_BIN=%TEMP_EXE%"+EOL+
"set TEMP_EXE=%OPENDS_JAVA_HOME%\\bin\\java.exe"+EOL+
"set OPENDJ_JAVA_BIN=%TEMP_EXE%"+EOL+
);
}
else
{
"set TEMP_EXE=%OPENDJ_JAVA_HOME%\\bin\\java.exe"+EOL+
"set OPENDJ_JAVA_BIN=%TEMP_EXE%"+EOL+
"set TEMP_EXE=%OPENDS_JAVA_HOME%\\bin\\java.exe"+EOL+
"set OPENDJ_JAVA_BIN=%TEMP_EXE%"+EOL+
);
}
if (defaultJavaHome != null)
{
if (javaHomeLabel1 == CHECK_ENV_JAVA_HOME)
{
"set OPENDJ_JAVA_BIN=%TEMP_EXE%"+EOL+
);
}
else
{
"set OPENDJ_JAVA_BIN=%TEMP_EXE%"+EOL+
);
}
}
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)
{
}
"set OPENDJ_JAVA_BIN=%TEMP_EXE%"+EOL+
}
}
if (javaArgsLabel1 == CHECK_ENV_JAVA_ARGS)
{
"set OPENDJ_JAVA_ARGS=%OPENDS_JAVA_ARGS%"+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
}
{
}
}
}
}