Finished fixing problems related to log4j.properties on Windows.

This commit is contained in:
Juan Carlos Luciani 2007-03-05 16:41:54 +00:00
parent 12e1705227
commit 72a6a0003c
3 changed files with 723 additions and 702 deletions

View File

@ -18,7 +18,7 @@
* To contact Novell about this file by physical or electronic mail, * To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com. * you may find current contact information at www.novell.com.
* *
* Author: Juan Carlos Luciani <jluciani@novell.com> * Author: Greg Richardson
* *
***********************************************************************/ ***********************************************************************/
@ -30,488 +30,512 @@ import java.util.*;
*/ */
public class InitConfigFile public class InitConfigFile
{ {
final static int ERROR_NO_ERROR = 0; final static int ERROR_NO_ERROR = 0;
final static int ERROR_INVALID_NUMBER_OF_PARAMS = -1; final static int ERROR_INVALID_NUMBER_OF_PARAMS = -1;
final static int ERROR_MISSING_TEMPLATE = -3; final static int ERROR_MISSING_TEMPLATE = -3;
final static int ERROR_MISSING_TEMPLATE_FILE = -8; final static int ERROR_MISSING_TEMPLATE_FILE = -8;
final static int ERROR_OUTPUT_PROPERTY_MISSING = -9; final static int ERROR_OUTPUT_PROPERTY_MISSING = -9;
final static int ERROR_OUTPUT_COPY_FAILED = -12; final static int ERROR_OUTPUT_COPY_FAILED = -12;
final static int ERROR_IO_EXCEPTION = -13; final static int ERROR_IO_EXCEPTION = -13;
final static int ERROR_MISSING_PROPERTIES = -15; final static int ERROR_MISSING_PROPERTIES = -15;
final static int ERROR_UNABLE_TO_READ_PROPERTIES = -16; final static int ERROR_UNABLE_TO_READ_PROPERTIES = -16;
final static int ERROR_PROPERTIES_FILE_IS_EMPTY = -17; final static int ERROR_PROPERTIES_FILE_IS_EMPTY = -17;
final static int ERROR_MISSING_INSTALL_DIR = -18; final static int ERROR_MISSING_INSTALL_DIR = -18;
final static int ERROR_INSTALL_DIR_NOT_A_DIR = -19; final static int ERROR_INSTALL_DIR_NOT_A_DIR = -19;
final static int ERROR_BAD_INSTALL_DIR_PARAM = -20; final static int ERROR_BAD_INSTALL_DIR_PARAM = -20;
final static int ERROR_BAD_PROPERTY_FILE_PARAM = -21; final static int ERROR_BAD_PROPERTY_FILE_PARAM = -21;
final static int ERROR_MISSING_PROPERTIES_FILE = -22; final static int ERROR_MISSING_PROPERTIES_FILE = -22;
final static int ERROR_MISSING_INSTALL_DIR_PARAM = -23; final static int ERROR_MISSING_INSTALL_DIR_PARAM = -23;
final static int ERROR_MISSING_PROPERTY_FILE_PARAM = -24; final static int ERROR_MISSING_PROPERTY_FILE_PARAM = -24;
final static int ERROR_BAD_TEMPLATE_FILE_PARAM = -25; final static int ERROR_BAD_TEMPLATE_FILE_PARAM = -25;
final static int ERROR_BAD_OUTPUT_FILE_PARAM = -26; final static int ERROR_BAD_OUTPUT_FILE_PARAM = -26;
final static int ERROR_MISSING_TEMPLATE_FILE_PARAM = -27; final static int ERROR_MISSING_TEMPLATE_FILE_PARAM = -27;
final static int ERROR_MISSING_OUTPUT_FILE_PARAM = -28; final static int ERROR_MISSING_OUTPUT_FILE_PARAM = -28;
final static int ERROR_BAD_PROPERTY_PARAM = -29; final static int ERROR_BAD_PROPERTY_PARAM = -29;
final static int ERROR_UNABLE_TO_OPEN_TEMPLATE = -30; final static int ERROR_UNABLE_TO_OPEN_TEMPLATE = -30;
final static int ERROR_FILEWRITER_CREATE_FAILED = -31; final static int ERROR_FILEWRITER_CREATE_FAILED = -31;
final static String TEMPLATE_FILE_PARAM = "template="; final static String TEMPLATE_FILE_PARAM = "template=";
final static String OUTPUT_FILE_PARAM = "output="; final static String OUTPUT_FILE_PARAM = "output=";
final static String INSTALL_DIR_PARAM = "ATS_INSTALL_DIR="; final static String INSTALL_DIR_PARAM = "ATS_INSTALL_DIR=";
final static String INSTALL_DIR_PROPERTY = "ATS_INSTALL_DIR"; final static String INSTALL_DIR_PROPERTY = "ATS_INSTALL_DIR";
final static String PROPERTY_FILE_PARAM = "propertyfile="; final static String PROPERTY_FILE_PARAM = "propertyfile=";
final static String ESCAPE_PATH_CHARS = "escape_path_chars=";
Properties properties; Properties properties;
File fileProperties; File fileProperties;
FileInputStream fisProperties; FileInputStream fisProperties;
File fileTemplate; File fileTemplate;
File fileOutput; File fileOutput;
File file; File file;
//FileWriter fw; //FileWriter fw;
RandomAccessFile raf; RandomAccessFile raf;
String[] rgsSearchFor; String[] rgsSearchFor;
String[] rgsReplaceWith; String[] rgsReplaceWith;
String sInstallDir; String sInstallDir;
String sTemplate; String sTemplate;
String sOutput; String sOutput;
int rc; int rc;
boolean escapePathCharsInReplaceString = false;
public static void main(String[] args) public static void main(String[] args)
{ {
InitConfigFile p = new InitConfigFile(args); InitConfigFile p = new InitConfigFile(args);
System.exit(p.rc); System.exit(p.rc);
} }
InitConfigFile(String[] args) InitConfigFile(String[] args)
{ {
rc = ERROR_NO_ERROR; rc = ERROR_NO_ERROR;
properties = new Properties(); properties = new Properties();
fileProperties = null; fileProperties = null;
fisProperties = null; fisProperties = null;
fileTemplate = null; fileTemplate = null;
fileOutput = null; fileOutput = null;
try try
{ {
file = new File("c:\\test.log"); file = new File("c:\\test.log");
//fw = new FileWriter(file); //fw = new FileWriter(file);
raf = new RandomAccessFile(file, "rw"); raf = new RandomAccessFile(file, "rw");
raf.seek(raf.length()); raf.seek(raf.length());
// Process the arguments // Process the arguments
if (ERROR_NO_ERROR == (rc = processArgs(args))) if (ERROR_NO_ERROR == (rc = processArgs(args)))
{ {
// Process the properties // Process the properties
if (ERROR_NO_ERROR == (rc = processProperties())) if (ERROR_NO_ERROR == (rc = processProperties()))
{ {
rc = createOutputFile(); rc = createOutputFile();
} }
} }
} }
catch (IOException e) catch (IOException e)
{ {
rc = ERROR_IO_EXCEPTION; rc = ERROR_IO_EXCEPTION;
} }
finally finally
{ {
try try
{ {
log(rc, " " + sOutput + "\n\n\n"); log(rc, " " + sOutput + "\n\n\n");
raf.close(); raf.close();
} }
catch (Exception e1) catch (Exception e1)
{ {
} }
} }
} }
int processArgs(String[] argsOld) int processArgs(String[] argsOld)
{ {
String sProperties; String sProperties;
File fileInstallDir = null; File fileInstallDir = null;
int iEquals; int iEquals;
String sKey; String sKey;
String sValue; String sValue;
int iOld; int iOld;
int i; int i;
String args[] = new String[argsOld.length]; String args[] = new String[argsOld.length];
int iNew; int iNew;
log("Original arg count " + argsOld.length); log("Original arg count " + argsOld.length);
for (i = 0; i < argsOld.length; i++) for (i = 0; i < argsOld.length; i++)
{ {
log("Arg " + i + " = " + argsOld[i] + "\r\n"); log("Arg " + i + " = " + argsOld[i] + "\r\n");
} }
// Validate the number of parameters // Validate the number of parameters
if (argsOld.length < 2) if (argsOld.length < 2)
{ {
return ERROR_INVALID_NUMBER_OF_PARAMS; return ERROR_INVALID_NUMBER_OF_PARAMS;
} }
iNew = -1; iNew = -1;
for (iOld = 0; iOld < argsOld.length; iOld++) for (iOld = 0; iOld < argsOld.length; iOld++)
{ {
if (0 <= argsOld[iOld].indexOf("=")) if (0 <= argsOld[iOld].indexOf("="))
{ {
iNew++; iNew++;
args[iNew] = argsOld[iOld]; args[iNew] = argsOld[iOld];
for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++) for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++)
{ {
args[iNew] += " " + argsOld[i]; args[iNew] += " " + argsOld[i];
} }
} }
} }
log("New arg count " + args.length); log("New arg count " + args.length);
for (i = 0; i < args.length; i++) for (i = 0; i < args.length; i++)
{ {
if (null == args[i]) if (null == args[i])
{ {
continue; continue;
} }
log("arg[" + i + "] = " +args[i]); log("arg[" + i + "] = " +args[i]);
// is this the install dir param? // is this the install dir param?
if (args[i].startsWith(INSTALL_DIR_PARAM)) if (args[i].startsWith(INSTALL_DIR_PARAM))
{ {
// Make sure it is more the the param tag // Make sure it is more the the param tag
if (args[i].length() <= INSTALL_DIR_PARAM.length()) if (args[i].length() <= INSTALL_DIR_PARAM.length())
{ {
return ERROR_BAD_INSTALL_DIR_PARAM; return ERROR_BAD_INSTALL_DIR_PARAM;
} }
sInstallDir = args[i].substring(INSTALL_DIR_PARAM.length()).trim(); sInstallDir = args[i].substring(INSTALL_DIR_PARAM.length()).trim();
fileInstallDir = new File(sInstallDir); fileInstallDir = new File(sInstallDir);
// Make sure the install dir can be found // Make sure the install dir can be found
if (!fileInstallDir.exists()) if (!fileInstallDir.exists())
{ {
return ERROR_MISSING_INSTALL_DIR; return ERROR_MISSING_INSTALL_DIR;
} }
// Make sure the install dir is a directory // Make sure the install dir is a directory
if (!fileInstallDir.isDirectory()) if (!fileInstallDir.isDirectory())
{ {
return ERROR_INSTALL_DIR_NOT_A_DIR; return ERROR_INSTALL_DIR_NOT_A_DIR;
} }
log("Adding property (key = " + INSTALL_DIR_PROPERTY + " - value = " + sInstallDir); log("Adding property (key = " + INSTALL_DIR_PROPERTY + " - value = " + sInstallDir);
properties.setProperty(INSTALL_DIR_PROPERTY, sInstallDir); properties.setProperty(INSTALL_DIR_PROPERTY, sInstallDir);
} }
// is this the properties file param? // is this the properties file param?
else if (args[i].startsWith(PROPERTY_FILE_PARAM)) else if (args[i].startsWith(PROPERTY_FILE_PARAM))
{ {
// Make sure it is more than the param tag // Make sure it is more than the param tag
if (args[i].length() <= PROPERTY_FILE_PARAM.length()) if (args[i].length() <= PROPERTY_FILE_PARAM.length())
{ {
return ERROR_BAD_PROPERTY_FILE_PARAM; return ERROR_BAD_PROPERTY_FILE_PARAM;
} }
sProperties = args[i].substring(PROPERTY_FILE_PARAM.length()).trim(); sProperties = args[i].substring(PROPERTY_FILE_PARAM.length()).trim();
fileProperties = new File(sProperties); fileProperties = new File(sProperties);
// Make sure the properties file can be found // Make sure the properties file can be found
if (!fileProperties.exists()) if (!fileProperties.exists())
{ {
return ERROR_MISSING_PROPERTIES_FILE; return ERROR_MISSING_PROPERTIES_FILE;
} }
// Read the properties // Read the properties
try try
{ {
fisProperties = new FileInputStream(fileProperties); fisProperties = new FileInputStream(fileProperties);
properties.load(fisProperties); properties.load(fisProperties);
} }
catch (IOException ioe) catch (IOException ioe)
{ {
return ERROR_UNABLE_TO_READ_PROPERTIES; return ERROR_UNABLE_TO_READ_PROPERTIES;
} }
} }
else if (args[i].startsWith(TEMPLATE_FILE_PARAM)) else if (args[i].startsWith(TEMPLATE_FILE_PARAM))
{ {
// Make sure it is more than the param tag // Make sure it is more than the param tag
if (args[i].length() <= TEMPLATE_FILE_PARAM.length()) if (args[i].length() <= TEMPLATE_FILE_PARAM.length())
{ {
return ERROR_BAD_TEMPLATE_FILE_PARAM; return ERROR_BAD_TEMPLATE_FILE_PARAM;
} }
sTemplate = args[i].substring(TEMPLATE_FILE_PARAM.length()).trim(); sTemplate = args[i].substring(TEMPLATE_FILE_PARAM.length()).trim();
fileTemplate = new File(sTemplate); fileTemplate = new File(sTemplate);
// Make sure the template file can be found // Make sure the template file can be found
if (!fileTemplate.exists()) if (!fileTemplate.exists())
{ {
log(ERROR_MISSING_TEMPLATE_FILE, sTemplate); log(ERROR_MISSING_TEMPLATE_FILE, sTemplate);
return ERROR_MISSING_TEMPLATE_FILE; return ERROR_MISSING_TEMPLATE_FILE;
} }
} }
else if (args[i].startsWith(OUTPUT_FILE_PARAM)) else if (args[i].startsWith(OUTPUT_FILE_PARAM))
{ {
// Make sure it is more than the param tag // Make sure it is more than the param tag
if (args[i].length() <= OUTPUT_FILE_PARAM.length()) if (args[i].length() <= OUTPUT_FILE_PARAM.length())
{ {
return ERROR_BAD_OUTPUT_FILE_PARAM; return ERROR_BAD_OUTPUT_FILE_PARAM;
} }
sOutput = args[i].substring(OUTPUT_FILE_PARAM.length()).trim(); sOutput = args[i].substring(OUTPUT_FILE_PARAM.length()).trim();
fileOutput = new File(sOutput); fileOutput = new File(sOutput);
} }
// Handle additional parameters else if (args[i].startsWith(ESCAPE_PATH_CHARS))
else {
{ // Make sure it is more than the param tag
if (-1 == (iEquals = args[i].indexOf("=")) || if (args[i].length() <= OUTPUT_FILE_PARAM.length())
0 == iEquals || {
args[i].length() == iEquals) return ERROR_BAD_OUTPUT_FILE_PARAM;
{ }
return ERROR_BAD_PROPERTY_PARAM;
}
sKey = args[i].substring(0, iEquals);
sValue = args[i].substring(iEquals + 1);
log("Adding property (key = " + sKey + " - value = " + sValue);
properties.setProperty(sKey, sValue);
}
}
// Make sure we got an install dir String value = args[i].substring(OUTPUT_FILE_PARAM.length()).trim();
if (null == fileInstallDir) if (value.equalsIgnoreCase("true"))
{ {
return ERROR_MISSING_INSTALL_DIR_PARAM; escapePathCharsInReplaceString = true;
} }
}
// Make sure we got a template file // Handle additional parameters
if (null == fileTemplate) else
{ {
return ERROR_MISSING_TEMPLATE_FILE_PARAM; if (-1 == (iEquals = args[i].indexOf("=")) ||
} 0 == iEquals ||
args[i].length() == iEquals)
{
return ERROR_BAD_PROPERTY_PARAM;
}
sKey = args[i].substring(0, iEquals);
sValue = args[i].substring(iEquals + 1);
log("Adding property (key = " + sKey + " - value = " + sValue);
properties.setProperty(sKey, sValue);
}
}
// Make sure we got an output file // Make sure we got an install dir
if (null == fileOutput) if (null == fileInstallDir)
{ {
return ERROR_MISSING_OUTPUT_FILE_PARAM; return ERROR_MISSING_INSTALL_DIR_PARAM;
} }
// Note: the properties file parameter is optional // Make sure we got a template file
if (null == fileTemplate)
{
return ERROR_MISSING_TEMPLATE_FILE_PARAM;
}
return ERROR_NO_ERROR; // Make sure we got an output file
} if (null == fileOutput)
{
return ERROR_MISSING_OUTPUT_FILE_PARAM;
}
int processProperties() // Note: the properties file parameter is optional
{
try
{
Enumeration e;
String sKey;
String sValue;
int i = 0;
e = properties.propertyNames(); return ERROR_NO_ERROR;
}
rgsSearchFor = new String[properties.size()]; int processProperties()
rgsReplaceWith = new String[properties.size()]; {
try
{
Enumeration e;
String sKey;
String sValue;
int i = 0;
log("property count = " + properties.size()); e = properties.propertyNames();
while (e.hasMoreElements())
{
sKey = (String)e.nextElement();
sValue = (String)properties.get(sKey);
log("Property key = " + sKey + " Value = " + sValue); rgsSearchFor = new String[properties.size()];
rgsReplaceWith = new String[properties.size()];
rgsSearchFor[i] = sKey; log("property count = " + properties.size());
rgsReplaceWith[i] = sValue; while (e.hasMoreElements())
i++; {
} sKey = (String)e.nextElement();
} sValue = (String)properties.get(sKey);
catch (Exception ex1)
{
return -111;
}
return ERROR_NO_ERROR; log("Property key = " + sKey + " Value = " + sValue);
}
int createOutputFile() rgsSearchFor[i] = sKey;
{ if (escapePathCharsInReplaceString)
LineNumberReader lnr = null; {
FileWriter fwOutput = null; rgsReplaceWith[i] = sValue.replace("\\", "\\\\");
String sLineTemplate; }
String sLineOutput; else
int iSearchFor; {
int i; rgsReplaceWith[i] = sValue;
}
i++;
}
}
catch (Exception ex1)
{
return -111;
}
try return ERROR_NO_ERROR;
{ }
// Open the files
lnr = new LineNumberReader(new FileReader(fileTemplate));
}
catch (Exception e)
{
return ERROR_UNABLE_TO_OPEN_TEMPLATE;
}
try int createOutputFile()
{ {
fwOutput = new FileWriter(fileOutput); LineNumberReader lnr = null;
} FileWriter fwOutput = null;
catch (Exception e) String sLineTemplate;
{ String sLineOutput;
return ERROR_FILEWRITER_CREATE_FAILED; int iSearchFor;
} int i;
try
{
// For each line of text in the template file...
while (null != (sLineTemplate = lnr.readLine()))
{
sLineOutput = sLineTemplate;
log("<-- " + sLineOutput);
// For each term to be replaced... try
for (i = 0; i < rgsSearchFor.length; i++) {
{ // Open the files
log("searching for " + rgsSearchFor[i]); lnr = new LineNumberReader(new FileReader(fileTemplate));
// Replace all instances of the term on the line }
while (-1 != (iSearchFor = sLineOutput.indexOf(rgsSearchFor[i]))) catch (Exception e)
{ {
log("replacing " + rgsSearchFor[i] + " at position " + iSearchFor + " with " + rgsReplaceWith[i]); return ERROR_UNABLE_TO_OPEN_TEMPLATE;
sLineOutput = sLineOutput.substring(0, iSearchFor) + rgsReplaceWith[i] + }
sLineOutput.substring(iSearchFor + rgsSearchFor[i].length());
}
}
try
{
fwOutput.write(sLineOutput + "\r\n");
log("--> " + sLineOutput);
}
catch (Exception e)
{
return -42;
}
}
// Clean up try
fwOutput.flush(); {
fwOutput.close(); fwOutput = new FileWriter(fileOutput);
lnr.close(); }
} catch (Exception e)
catch (Exception e) {
{ return ERROR_FILEWRITER_CREATE_FAILED;
return ERROR_OUTPUT_COPY_FAILED; }
} try
return ERROR_NO_ERROR; {
} // For each line of text in the template file...
while (null != (sLineTemplate = lnr.readLine()))
{
sLineOutput = sLineTemplate;
log("<-- " + sLineOutput);
void log(int err) // For each term to be replaced...
{ for (i = 0; i < rgsSearchFor.length; i++)
log(err, null); {
} log("searching for " + rgsSearchFor[i]);
// Replace all instances of the term on the line
while (-1 != (iSearchFor = sLineOutput.indexOf(rgsSearchFor[i])))
{
log("replacing " + rgsSearchFor[i] + " at position " + iSearchFor + " with " + rgsReplaceWith[i]);
sLineOutput = sLineOutput.substring(0, iSearchFor) + rgsReplaceWith[i] +
sLineOutput.substring(iSearchFor + rgsSearchFor[i].length());
}
}
try
{
fwOutput.write(sLineOutput + "\r\n");
log("--> " + sLineOutput);
}
catch (Exception e)
{
return -42;
}
}
void log(int err, String s) // Clean up
{ fwOutput.flush();
String sMessage = ""; fwOutput.close();
lnr.close();
}
catch (Exception e)
{
return ERROR_OUTPUT_COPY_FAILED;
}
return ERROR_NO_ERROR;
}
switch (err) void log(int err)
{ {
case ERROR_NO_ERROR: log(err, null);
sMessage = "No error"; }
break;
case ERROR_INVALID_NUMBER_OF_PARAMS:
sMessage = "Invalid number of parameters: 4 expected";
break;
case ERROR_MISSING_TEMPLATE:
sMessage = "Template file not found";
break;
case ERROR_OUTPUT_PROPERTY_MISSING:
sMessage = "Output file parameter missing";
break;
case ERROR_OUTPUT_COPY_FAILED:
sMessage = "Unable to create output file";
break;
case ERROR_IO_EXCEPTION:
sMessage = "IOException";
break;
case ERROR_MISSING_PROPERTIES:
sMessage = "Properties file not found";
break;
case ERROR_MISSING_TEMPLATE_FILE:
sMessage = "Missing template file";
break;
case ERROR_PROPERTIES_FILE_IS_EMPTY:
sMessage = "Properties file is empty";
break;
case ERROR_MISSING_INSTALL_DIR:
sMessage = "Missing install dir";
break;
case ERROR_INSTALL_DIR_NOT_A_DIR:
sMessage = "Install directory is not a directory";
break;
case ERROR_BAD_INSTALL_DIR_PARAM:
sMessage = "Bad install directory parameter";
break;
case ERROR_BAD_PROPERTY_FILE_PARAM:
sMessage = "Bad property file parameter";
break;
case ERROR_MISSING_PROPERTIES_FILE:
sMessage = "Missing properties file";
break;
case ERROR_MISSING_INSTALL_DIR_PARAM:
sMessage = "Missing install directory parameter";
break;
case ERROR_MISSING_PROPERTY_FILE_PARAM:
sMessage = "Missing property file parameter";
break;
case ERROR_BAD_TEMPLATE_FILE_PARAM:
sMessage = "Bad template file parameter";
break;
case ERROR_BAD_OUTPUT_FILE_PARAM:
sMessage = "Bad output file parameter";
break;
case ERROR_MISSING_TEMPLATE_FILE_PARAM:
sMessage = "Missing template file parameter";
break;
case ERROR_MISSING_OUTPUT_FILE_PARAM:
sMessage = "Missing output file parameter";
break;
case ERROR_BAD_PROPERTY_PARAM:
sMessage = "Bad property parameter";
break;
case ERROR_UNABLE_TO_READ_PROPERTIES:
sMessage = "Unable to read properties file";
break;
case ERROR_UNABLE_TO_OPEN_TEMPLATE:
sMessage = "Unable to open template";
break;
case ERROR_FILEWRITER_CREATE_FAILED:
sMessage = "FileWriter create failed";
break;
default:
sMessage = "Unknown error: " + err;
break;
}
if (null != s) void log(int err, String s)
{ {
sMessage = sMessage + s; String sMessage = "";
}
log(sMessage);
}
void log(String s) switch (err)
{ {
try case ERROR_NO_ERROR:
{ sMessage = "No error";
raf.writeUTF(this.getClass().getName() + ": " + s + "\r\n"); break;
} case ERROR_INVALID_NUMBER_OF_PARAMS:
catch (IOException ioe) sMessage = "Invalid number of parameters: 4 expected";
{ break;
} case ERROR_MISSING_TEMPLATE:
} sMessage = "Template file not found";
break;
case ERROR_OUTPUT_PROPERTY_MISSING:
sMessage = "Output file parameter missing";
break;
case ERROR_OUTPUT_COPY_FAILED:
sMessage = "Unable to create output file";
break;
case ERROR_IO_EXCEPTION:
sMessage = "IOException";
break;
case ERROR_MISSING_PROPERTIES:
sMessage = "Properties file not found";
break;
case ERROR_MISSING_TEMPLATE_FILE:
sMessage = "Missing template file";
break;
case ERROR_PROPERTIES_FILE_IS_EMPTY:
sMessage = "Properties file is empty";
break;
case ERROR_MISSING_INSTALL_DIR:
sMessage = "Missing install dir";
break;
case ERROR_INSTALL_DIR_NOT_A_DIR:
sMessage = "Install directory is not a directory";
break;
case ERROR_BAD_INSTALL_DIR_PARAM:
sMessage = "Bad install directory parameter";
break;
case ERROR_BAD_PROPERTY_FILE_PARAM:
sMessage = "Bad property file parameter";
break;
case ERROR_MISSING_PROPERTIES_FILE:
sMessage = "Missing properties file";
break;
case ERROR_MISSING_INSTALL_DIR_PARAM:
sMessage = "Missing install directory parameter";
break;
case ERROR_MISSING_PROPERTY_FILE_PARAM:
sMessage = "Missing property file parameter";
break;
case ERROR_BAD_TEMPLATE_FILE_PARAM:
sMessage = "Bad template file parameter";
break;
case ERROR_BAD_OUTPUT_FILE_PARAM:
sMessage = "Bad output file parameter";
break;
case ERROR_MISSING_TEMPLATE_FILE_PARAM:
sMessage = "Missing template file parameter";
break;
case ERROR_MISSING_OUTPUT_FILE_PARAM:
sMessage = "Missing output file parameter";
break;
case ERROR_BAD_PROPERTY_PARAM:
sMessage = "Bad property parameter";
break;
case ERROR_UNABLE_TO_READ_PROPERTIES:
sMessage = "Unable to read properties file";
break;
case ERROR_UNABLE_TO_OPEN_TEMPLATE:
sMessage = "Unable to open template";
break;
case ERROR_FILEWRITER_CREATE_FAILED:
sMessage = "FileWriter create failed";
break;
default:
sMessage = "Unknown error: " + err;
break;
}
if (null != s)
{
sMessage = sMessage + s;
}
log(sMessage);
}
void log(String s)
{
try
{
raf.writeUTF(this.getClass().getName() + ": " + s + "\r\n");
}
catch (IOException ioe)
{
}
}
} }

View File

@ -18,7 +18,7 @@
* To contact Novell about this file by physical or electronic mail, * To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com. * you may find current contact information at www.novell.com.
* *
* Author: Juan Carlos Luciani <jluciani@novell.com> * Author: Greg Richardson
* *
***********************************************************************/ ***********************************************************************/
@ -30,311 +30,311 @@ import java.util.*;
*/ */
public class MungeCryptoPropertiesFilePath public class MungeCryptoPropertiesFilePath
{ {
final static int ERROR_NO_ERROR = 0; final static int ERROR_NO_ERROR = 0;
final static int ERROR_INVALID_NUMBER_OF_PARAMS = -1; final static int ERROR_INVALID_NUMBER_OF_PARAMS = -1;
final static int ERROR_MISSING_INPUT_FILE = -2; final static int ERROR_MISSING_INPUT_FILE = -2;
final static int ERROR_OUTPUT_COPY_FAILED = -3; final static int ERROR_OUTPUT_COPY_FAILED = -3;
final static int ERROR_IO_EXCEPTION = -4; final static int ERROR_IO_EXCEPTION = -4;
final static int ERROR_BAD_INPUT_FILE_PARAM = -5; final static int ERROR_BAD_INPUT_FILE_PARAM = -5;
final static int ERROR_BAD_OUTPUT_FILE_PARAM = -6; final static int ERROR_BAD_OUTPUT_FILE_PARAM = -6;
final static int ERROR_MISSING_INPUT_FILE_PARAM = -7; final static int ERROR_MISSING_INPUT_FILE_PARAM = -7;
final static int ERROR_MISSING_OUTPUT_FILE_PARAM = -8; final static int ERROR_MISSING_OUTPUT_FILE_PARAM = -8;
final static int ERROR_CANNOT_READ_FILE = -9; final static int ERROR_CANNOT_READ_FILE = -9;
final static int ERROR_CANNOT_CREATE_FILE = -10; final static int ERROR_CANNOT_CREATE_FILE = -10;
final static String INPUT_FILE_PARAM = "input="; final static String INPUT_FILE_PARAM = "input=";
final static String OUTPUT_FILE_PARAM = "output="; final static String OUTPUT_FILE_PARAM = "output=";
final static String FILE_KEY = "org.apache.ws.security.crypto.merlin.file="; final static String FILE_KEY = "org.apache.ws.security.crypto.merlin.file=";
File fileInput; File fileInput;
File fileOutput; File fileOutput;
File file; File file;
FileWriter fw; FileWriter fw;
String sInput; String sInput;
String sOutput; String sOutput;
int rc; int rc;
public static void main(String[] args) public static void main(String[] args)
{ {
MungeCryptoPropertiesFilePath p = new MungeCryptoPropertiesFilePath(args); MungeCryptoPropertiesFilePath p = new MungeCryptoPropertiesFilePath(args);
System.exit(p.rc); System.exit(p.rc);
} }
MungeCryptoPropertiesFilePath(String[] args) MungeCryptoPropertiesFilePath(String[] args)
{ {
rc = ERROR_NO_ERROR; rc = ERROR_NO_ERROR;
fileInput = null; fileInput = null;
fileOutput = null; fileOutput = null;
try try
{ {
file = new File("c:\\test5.log"); file = new File("c:\\test5.log");
fw = new FileWriter(file); fw = new FileWriter(file);
log("Here we go: " + args.length); log("Here we go: " + args.length);
for (int i = 0; i < args.length; i++) for (int i = 0; i < args.length; i++)
{ {
log("Arg " + i + " = " + args[i]); log("Arg " + i + " = " + args[i]);
} }
// Process the arguments // Process the arguments
if (ERROR_NO_ERROR == (rc = processArgs(args))) if (ERROR_NO_ERROR == (rc = processArgs(args)))
{ {
// Process the file // Process the file
rc = createOutputFile(); rc = createOutputFile();
} }
} }
catch (IOException e) catch (IOException e)
{ {
rc = ERROR_IO_EXCEPTION; rc = ERROR_IO_EXCEPTION;
} }
finally finally
{ {
try try
{ {
log(rc); log(rc);
fw.flush(); fw.flush();
fw.close(); fw.close();
} }
catch (Exception e1) catch (Exception e1)
{ {
} }
} }
} }
int processArgs(String[] argsOld) int processArgs(String[] argsOld)
{ {
int iOld; int iOld;
int i; int i;
String args[] = new String[argsOld.length]; String args[] = new String[argsOld.length];
int iNew; int iNew;
log("Original arg count " + argsOld.length); log("Original arg count " + argsOld.length);
for (i = 0; i < argsOld.length; i++) for (i = 0; i < argsOld.length; i++)
{ {
log("Arg " + i + " = " + argsOld[i] + "\r\n"); log("Arg " + i + " = " + argsOld[i] + "\r\n");
} }
// Validate the number of parameters // Validate the number of parameters
if (argsOld.length < 2) if (argsOld.length < 2)
{ {
return ERROR_INVALID_NUMBER_OF_PARAMS; return ERROR_INVALID_NUMBER_OF_PARAMS;
} }
iNew = -1; iNew = -1;
for (iOld = 0; iOld < argsOld.length; iOld++) for (iOld = 0; iOld < argsOld.length; iOld++)
{ {
if (0 <= argsOld[iOld].indexOf("=")) if (0 <= argsOld[iOld].indexOf("="))
{ {
iNew++; iNew++;
args[iNew] = argsOld[iOld]; args[iNew] = argsOld[iOld];
for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++) for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++)
{ {
args[iNew] += " " + argsOld[i]; args[iNew] += " " + argsOld[i];
} }
} }
} }
log("New arg count " + args.length); log("New arg count " + args.length);
for (i = 0; i < args.length; i++) for (i = 0; i < args.length; i++)
{ {
log("Arg " + i + " = " + args[i] + "\r\n"); log("Arg " + i + " = " + args[i] + "\r\n");
} }
for (i = 0; i <= iNew; i++) for (i = 0; i <= iNew; i++)
{ {
log("arg[" + i + "] = " +args[i]); log("arg[" + i + "] = " +args[i]);
if (args[i].startsWith(INPUT_FILE_PARAM)) if (args[i].startsWith(INPUT_FILE_PARAM))
{ {
// Make sure it is more than the param tag // Make sure it is more than the param tag
if (args[i].length() <= INPUT_FILE_PARAM.length()) if (args[i].length() <= INPUT_FILE_PARAM.length())
{ {
return ERROR_BAD_INPUT_FILE_PARAM; return ERROR_BAD_INPUT_FILE_PARAM;
} }
sInput = args[i].substring(INPUT_FILE_PARAM.length()).trim(); sInput = args[i].substring(INPUT_FILE_PARAM.length()).trim();
fileInput = new File(sInput); fileInput = new File(sInput);
// Make sure the input file can be found // Make sure the input file can be found
if (!fileInput.exists()) if (!fileInput.exists())
{ {
log(ERROR_MISSING_INPUT_FILE, sInput); log(ERROR_MISSING_INPUT_FILE, sInput);
return ERROR_MISSING_INPUT_FILE; return ERROR_MISSING_INPUT_FILE;
} }
} }
else if (args[i].startsWith(OUTPUT_FILE_PARAM)) else if (args[i].startsWith(OUTPUT_FILE_PARAM))
{ {
// Make sure it is more than the param tag // Make sure it is more than the param tag
if (args[i].length() <= OUTPUT_FILE_PARAM.length()) if (args[i].length() <= OUTPUT_FILE_PARAM.length())
{ {
return ERROR_BAD_OUTPUT_FILE_PARAM; return ERROR_BAD_OUTPUT_FILE_PARAM;
} }
sOutput = args[i].substring(OUTPUT_FILE_PARAM.length()).trim(); sOutput = args[i].substring(OUTPUT_FILE_PARAM.length()).trim();
fileOutput = new File(sOutput); fileOutput = new File(sOutput);
} }
} }
// Make sure we got an input file // Make sure we got an input file
if (null == fileInput) if (null == fileInput)
{ {
return ERROR_MISSING_INPUT_FILE_PARAM; return ERROR_MISSING_INPUT_FILE_PARAM;
} }
// Make sure we got an output file // Make sure we got an output file
if (null == fileOutput) if (null == fileOutput)
{ {
return ERROR_MISSING_OUTPUT_FILE_PARAM; return ERROR_MISSING_OUTPUT_FILE_PARAM;
} }
return ERROR_NO_ERROR; return ERROR_NO_ERROR;
} }
int createOutputFile() int createOutputFile()
{ {
LineNumberReader lnr = null; LineNumberReader lnr = null;
FileWriter fwOutput = null; FileWriter fwOutput = null;
String sLineTemplate; String sLineTemplate;
String sLineOutput; String sLineOutput;
int iSearchFor; int iSearchFor;
try try
{ {
// Open the file // Open the file
lnr = new LineNumberReader(new FileReader(fileInput)); lnr = new LineNumberReader(new FileReader(fileInput));
} }
catch (Exception e) catch (Exception e)
{ {
return ERROR_CANNOT_READ_FILE; return ERROR_CANNOT_READ_FILE;
} }
try try
{ {
fwOutput = new FileWriter(fileOutput); fwOutput = new FileWriter(fileOutput);
} }
catch (Exception e) catch (Exception e)
{ {
return ERROR_CANNOT_CREATE_FILE; return ERROR_CANNOT_CREATE_FILE;
} }
try try
{ {
// For each line of text in the template file... // For each line of text in the template file...
while (null != (sLineTemplate = lnr.readLine())) while (null != (sLineTemplate = lnr.readLine()))
{ {
sLineOutput = sLineTemplate; sLineOutput = sLineTemplate;
log("<-- " + sLineOutput); log("<-- " + sLineOutput);
if (sLineOutput.trim().startsWith(FILE_KEY)) if (sLineOutput.trim().startsWith(FILE_KEY))
{ {
// Replace all instances of the line separator on the line // Replace all instances of the line separator on the line
while (-1 != (iSearchFor = sLineOutput.indexOf("\\"))) while (-1 != (iSearchFor = sLineOutput.indexOf("\\")))
{ {
log("replacing \\ at position " + iSearchFor + " with //"); log("replacing \\ at position " + iSearchFor + " with //");
sLineOutput = sLineOutput.substring(0, iSearchFor) + "//" + sLineOutput = sLineOutput.substring(0, iSearchFor) + "//" +
sLineOutput.substring(iSearchFor + 1); sLineOutput.substring(iSearchFor + 1);
} }
} }
try try
{ {
fwOutput.write(sLineOutput + "\r\n"); fwOutput.write(sLineOutput + "\r\n");
log("--> " + sLineOutput); log("--> " + sLineOutput);
} }
catch (Exception e) catch (Exception e)
{ {
return -42; return -42;
} }
} }
// Clean up // Clean up
fwOutput.flush(); fwOutput.flush();
fwOutput.close(); fwOutput.close();
lnr.close(); lnr.close();
} }
catch (Exception e) catch (Exception e)
{ {
return ERROR_OUTPUT_COPY_FAILED; return ERROR_OUTPUT_COPY_FAILED;
} }
return ERROR_NO_ERROR; return ERROR_NO_ERROR;
} }
void log(int err) void log(int err)
{ {
log(err, null); log(err, null);
} }
void log(int err, String s) void log(int err, String s)
{ {
String sMessage = ""; String sMessage = "";
switch (err) switch (err)
{ {
case ERROR_NO_ERROR: case ERROR_NO_ERROR:
sMessage = "No error"; sMessage = "No error";
break; break;
case ERROR_INVALID_NUMBER_OF_PARAMS: case ERROR_INVALID_NUMBER_OF_PARAMS:
sMessage = "Invalid number of parameters: 2 expected"; sMessage = "Invalid number of parameters: 2 expected";
break; break;
case ERROR_MISSING_INPUT_FILE: case ERROR_MISSING_INPUT_FILE:
sMessage = "Missing input file"; sMessage = "Missing input file";
break; break;
case ERROR_OUTPUT_COPY_FAILED: case ERROR_OUTPUT_COPY_FAILED:
sMessage = "Unable to create output file"; sMessage = "Unable to create output file";
break; break;
case ERROR_IO_EXCEPTION: case ERROR_IO_EXCEPTION:
sMessage = "IOException"; sMessage = "IOException";
break; break;
case ERROR_BAD_INPUT_FILE_PARAM: case ERROR_BAD_INPUT_FILE_PARAM:
sMessage = "Invalid input file parameter"; sMessage = "Invalid input file parameter";
break; break;
case ERROR_BAD_OUTPUT_FILE_PARAM: case ERROR_BAD_OUTPUT_FILE_PARAM:
sMessage = "Invalid output file parameter"; sMessage = "Invalid output file parameter";
break; break;
case ERROR_MISSING_INPUT_FILE_PARAM: case ERROR_MISSING_INPUT_FILE_PARAM:
sMessage = "Missing input file parameter"; sMessage = "Missing input file parameter";
break; break;
case ERROR_MISSING_OUTPUT_FILE_PARAM: case ERROR_MISSING_OUTPUT_FILE_PARAM:
sMessage = "Missing output file parameter"; sMessage = "Missing output file parameter";
break; break;
case ERROR_CANNOT_READ_FILE: case ERROR_CANNOT_READ_FILE:
sMessage = "Cannot read file"; sMessage = "Cannot read file";
break; break;
case ERROR_CANNOT_CREATE_FILE: case ERROR_CANNOT_CREATE_FILE:
sMessage = "Cannot create file"; sMessage = "Cannot create file";
break; break;
default: default:
sMessage = "Unknown error: " + err; sMessage = "Unknown error: " + err;
break; break;
} }
if (null != s) if (null != s)
{ {
sMessage = sMessage + s; sMessage = sMessage + s;
} }
log(sMessage); log(sMessage);
} }
void log(String s) void log(String s)
{ {
try try
{ {
fw.write(this.getClass().getName() + ": " + s + "\r\n"); fw.write(this.getClass().getName() + ": " + s + "\r\n");
} }
catch (IOException ioe) catch (IOException ioe)
{ {
} }
} }
} }

View File

@ -473,7 +473,7 @@
"Object" = "8:_32E2D317FBCD4B25904D5402E547B8A8" "Object" = "8:_32E2D317FBCD4B25904D5402E547B8A8"
"FileType" = "3:2" "FileType" = "3:2"
"InstallAction" = "3:1" "InstallAction" = "3:1"
"Arguments" = "8:[ATS_JAVA_EXE] -cp [TARGETDIR]ats\\bin InitConfigFile ATS_INSTALL_DIR=[TARGETDIR] propertyfile=[PROPERTYFILE] template=[TARGETDIR]ats\\etc\\svc\\templates\\log4j.properties output=[TARGETDIR]ats\\etc\\log4j.properties" "Arguments" = "8:[ATS_JAVA_EXE] -cp [TARGETDIR]ats\\bin InitConfigFile ATS_INSTALL_DIR=[TARGETDIR] escape_path_chars=true propertyfile=[PROPERTYFILE] template=[TARGETDIR]ats\\etc\\svc\\templates\\log4j.properties output=[TARGETDIR]ats\\etc\\log4j.properties"
"EntryPoint" = "8:" "EntryPoint" = "8:"
"Sequence" = "3:17" "Sequence" = "3:17"
"Identifier" = "8:_EB425F32_F807_4C36_AC86_B75AEEEC7D29" "Identifier" = "8:_EB425F32_F807_4C36_AC86_B75AEEEC7D29"
@ -2787,8 +2787,5 @@
"ProjectOutput" "ProjectOutput"
{ {
} }
"VJSharpPlugin"
{
}
} }
} }