You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2003/02/12 02:17:27 UTC
cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/util OverwriteProperties.java
taylor 2003/02/11 17:17:27
Modified: src/java/org/apache/jetspeed/util OverwriteProperties.java
Log:
completed patch from Eric Pugh (by hand!) - I couldn't get the damn patch to apply
D
Eric - please check to ensure i didn't screw anything up w`
Revision Changes Path
1.2 +198 -68 jakarta-jetspeed/src/java/org/apache/jetspeed/util/OverwriteProperties.java
Index: OverwriteProperties.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/OverwriteProperties.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- OverwriteProperties.java 28 Oct 2002 18:44:46 -0000 1.1
+++ OverwriteProperties.java 12 Feb 2003 01:17:27 -0000 1.2
@@ -63,101 +63,228 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileOutputStream;
+import java.io.File;
/**
* Task to overwrite Properties: used for JRP, TRP and Torque.properties
*
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @author <a href="mailto:ruchi@bluesunrise.com">Ruchi Gatha</a>
+ * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
+ *
* @version $Id$
*/
+
public class OverwriteProperties
{
- protected static String baseProperties;
- protected static String properties;
- protected static String includeRoot;
-
- public static boolean verbose = false;
-
- protected static ArrayList baseArray = new ArrayList(1024);
- protected static ArrayList removeArray = new ArrayList(128);
- protected static HashMap baseMap = new HashMap();
- protected static String lineSeparator = System.getProperty("line.separator", "\r\n");
+ // The file to merge properties into
+ protected File baseProperties;
+ // The file to pull the properties from
+ protected File properties;
+ // The directory to look in for include files
+ protected File includeRoot;
+
+ public boolean verbose = false;
+
+ /** An array of all the properties */
+ protected ArrayList baseArray = new ArrayList(1024);
+ /** An array of all the properties that will be removed */
+ protected ArrayList removeArray = new ArrayList(128);
+ /** Description of the Field */
+ protected HashMap baseMap = new HashMap();
+ /** What to use as a line seperator */
+ protected String lineSeparator = System.getProperty("line.separator", "\r\n");
+
+
+ /**
+ * Sets the file to merge properties into
+ *
+ * @param baseProperties The file path to merge properties into
+ */
+ public void setBaseProperties(File baseProperties) {
+ this.baseProperties = baseProperties;
+ }
+
+
+ /**
+ * Sets the file to pull properties from
+ *
+ * @param properties The file path to the pull the merge properties from
+ */
+ public void setProperties(File properties) {
+ this.properties = properties;
+ }
+
+
+ /**
+ * Sets the directory to look for includes in.
+ *
+ * @param includeRoot the directory to look in.
+ */
+ public void setIncludeRoot(File includeRoot) {
+ this.includeRoot = includeRoot;
+ }
+
+
+ /**
+ * Sets whether to output extra debugging info
+ *
+ * @param verbose The new verbose value
+ */
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+
+ /**
+ * Return the file to merge propertie into
+ *
+ * @return The baseProperties value
+ */
+ public File getBaseProperties() {
+ return baseProperties;
+ }
+
+
+ /**
+ * Gets the properties attribute of the OverwriteProperties object
+ *
+ * @return The properties value
+ */
+ public File getProperties() {
+ return properties;
+ }
+
- public static void main(String[] args) throws Exception
+ /**
+ * Gets the includeRoot attribute of the OverwriteProperties object
+ *
+ * @return The includeRoot value
+ */
+ public File getIncludeRoot() {
+ return includeRoot;
+ }
+
+
+ /**
+ * Gets the verbose attribute of the OverwriteProperties object
+ *
+ * @return The verbose value
+ */
+ public boolean getVerbose() {
+ return verbose;
+ }
+
+
+ /**
+ * The main program for the OverwriteProperties class
+ *
+ * @param args The command line arguments
+ * @exception Exception Description of the Exception
+ */
+ public static void main(String[] args)
+ throws Exception
{
- OverwriteProperties main=new OverwriteProperties();
+
+ OverwriteProperties overwriteProperties = new OverwriteProperties();
- try
+ try
{
- if(args.length < 3)
+ if (args.length < 3)
{
System.out.println("Usage: java OverwriteProperties c:/temp/File1.props c:/temp/File2.props c:/include-root/");
System.out.println("Usage: File1 will be modified, new parameters from File 2 will be added,");
System.out.println("Usage: and same parameters will be updated. The include-root is where include files are found.");
throw new Exception("Incorrect number of arguments supplied");
}
- baseProperties = args[0];
- properties = args[1];
- includeRoot = args[2];
-
-
- BufferedReader reader = new BufferedReader(new FileReader(baseProperties));
- int index = 0;
- String key = null;
- String line = null;
- while((line = reader.readLine()) != null)
- {
- StringTokenizer tokenizer = new StringTokenizer(line, "=");
- baseArray.add(index, line);
- if (verbose)
- {
- System.out.println("While reading baseArray["+index+"] = "+line);
- }
- if(tokenizer.countTokens() >= 1 &&
- !line.startsWith("#") &&
- !line.startsWith("include") &&
- !line.startsWith("module.packages"))
- {
- key = tokenizer.nextToken().trim();
- if(key != null && key.length() > 0)
- {
- baseMap.put(key, new Integer(index));
- if (verbose)
- {
- System.out.println("baseMap["+key+","+index+"]");
- }
- }
- }
- index++;
- }
- reader.close();
- if (verbose)
- {
- System.out.println("\nOverwrite with Delta\n");
- }
-
- readProperties(properties,index);
-
- boolean flags[] = removeProperties();
-
- baseArray.trimToSize();
- main.writeToFile(flags);
+ overwriteProperties.setBaseProperties(new File(args[0]));
+ overwriteProperties.setProperties(new File(args[1]));
+ overwriteProperties.setIncludeRoot(new File(args[2]));
+ overwriteProperties.execute();
+
}
- catch(FileNotFoundException ex)
+ catch (FileNotFoundException ex)
{
System.err.println(ex.getMessage());
}
- catch(IOException ex)
+ catch (IOException ex)
{
System.err.println(ex.getMessage());
}
- catch(SecurityException ex)
+ catch (SecurityException ex)
{
System.err.println(ex.getMessage());
}
}
+
+ public void execute()
+ throws FileNotFoundException,IOException,SecurityException
+ {
+ if (verbose)
+ {
+ System.out.println("Merging into file " + getBaseProperties() + " file " + getProperties());
+ }
+ if (!getBaseProperties().exists())
+ {
+ throw new FileNotFoundException("Could not find file:" + getBaseProperties());
+ }
+
+ if (!getProperties().exists())
+ {
+ throw new FileNotFoundException("Could not find file:" + getProperties());
+ }
+
+ if (!getIncludeRoot().exists() || !getIncludeRoot().isDirectory())
+ {
+ throw new FileNotFoundException("Could not find directory:" + getIncludeRoot());
+ }
+
+ BufferedReader reader = new BufferedReader(new FileReader(baseProperties));
+ int index = 0;
+ String key = null;
+ String line = null;
+ while ((line = reader.readLine()) != null)
+ {
+ StringTokenizer tokenizer = new StringTokenizer(line, "=");
+ baseArray.add(index, line);
+ if (verbose)
+ {
+ System.out.println("While reading baseArray[" + index + "] = " + line);
+ }
+ if (tokenizer.countTokens() >= 1 &&
+ !line.startsWith("#") &&
+ !line.startsWith("include") &&
+ !line.startsWith("module.packages"))
+ {
+ key = tokenizer.nextToken().trim();
+ if (key != null && key.length() > 0)
+ {
+ baseMap.put(key, new Integer(index));
+ if (verbose)
+ {
+ System.out.println("baseMap[" + key + "," + index + "]");
+ }
+ }
+ }
+ index++;
+ }
+ reader.close();
+ if (verbose)
+ {
+ System.out.println("\nOverwrite with Delta\n");
+ }
+ readProperties(properties, index);
+
+ boolean flags[] = removeProperties();
+
+ baseArray.trimToSize();
+ writeToFile(flags);
+
+ }
+
+
public void writeToFile(boolean [] flags) throws FileNotFoundException, IOException
{
FileOutputStream writer = new FileOutputStream(baseProperties);
@@ -184,7 +311,7 @@
}
- public static boolean[] removeProperties()
+ public boolean[] removeProperties()
{
boolean flags[] = new boolean[baseArray.size()];
@@ -212,7 +339,7 @@
return flags;
}
- public static void readProperties(String propFile, int index)
+ public void readProperties(File propFile, int index)
throws FileNotFoundException, IOException
{
BufferedReader reader = new BufferedReader(new FileReader(propFile));
@@ -227,8 +354,11 @@
if (count == 2 && line.startsWith("include"))
{
key = tokenizer.nextToken().trim();
- String includeFile = includeRoot + tokenizer.nextToken().trim();
- System.out.println("include File = " + includeFile);
+ File includeFile = new File(includeRoot + tokenizer.nextToken().trim());
+ if (verbose)
+ {
+ System.out.println("include File = " + includeFile);
+ }
readProperties(includeFile, index);
continue;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org