Problems with woproject under cygwin

From: Dave Rathnow (drathno..elus.net)
Date: Fri Aug 27 2004 - 09:01:57 EDT

  • Next message: Ashley Aitken: "Build product files tagged with increasing integer ..."

    Hello WOProject-dev,

    I've been having a problem building some WO projects under cygwin on
    Windows. I logged a bug yesterday but decided to investigate myself this
    morning. Briefly, the problem is that my builds are blowing up with with
    a StringIndexOutOfBoundsException when I build. The exception is coming
    out of at org.objectstyle.woenvironment.env.Environment.

    The problem is that, for some reason, I have an env variable the contains a
    newline character. The var is created by cygwin and I have no clue what
    it's used for. In any case the result is that it blows up the parsing in
    Environment class. The problem is in this section of code in
    Environment.getEnvArgs():

    while ((line = br.readLine()) != null) {
         int idx = line.indexOf('=');
         String key = line.substring(0, idx);
         String value = line.substring(idx + 1);
         envVars.setProperty(key, value);
    }

    The search for the '=' character fails and the next line raises. I was
    able to reproduce the problem and then fix it by putting in a check to -1:

    int idx;
    while ((line = br.readLine()) != null) {
         if ((idx = line.indexOf('=')) != -1) {
             String key = line.substring(0, idx);
             String value = line.substring(idx + 1);
         }
    }

    However, this only address a symptom and not the problem. This solution
    will lose valid variables that contain newline characters. A more
    comprehensive fix may be to add something like this class that will build
    strings

    class EnvironmentStringBuilder {
         protected String variableValue;
         protected String variableName;
         protected Properties properties;

         public EnvironmentStringBuilder(Properties someProperties) {
             properties = someProperties;
         }

         public void takeVariableFromString(String aString) {
             int idx;
                     if ((idx = aString.indexOf('=')) != -1) {
                             variableName = aString.substring(0, idx);
                             variableValue = aString.substring(idx + 1);
                     } else {
                         variableValue += "\n" + aString;
                     }
                     properties.put(variableName,variableValue);
         }
    }

    I briefly tested it with the following testcase:

    import java.util.Properties;
    import junit.framework.TestCase;

    public class EnvironmentStringBuilderTest extends TestCase {

         protected final static String EMPTY_STRING = "bar=";
         protected final static String SIMPLE_STRING = "bar=foo";
         protected final static String COMPLEX_STRING = "bar=foo\nman";
         protected final static String MORE_COMPLEX_STRING = "bar=foo\nman\nchoo";

         protected EnvironmentStringBuilder environmentStringBuilder;
         protected Properties properties;

         protected void setUp() throws Exception {
             properties = new Properties();
             environmentStringBuilder = new EnvironmentStringBuilder(properties);
         }

         protected void tearDown() throws Exception {
         }

         public void testTakeVariableFromStringEmptyString() {
             environmentStringBuilder.takeVariableFromString(EMPTY_STRING);
             assertNotNull(properties.get("bar"));
             assertEquals("",properties.get("bar"));
         }

         public void testTakeVariableFromStringWithSimpleString() {
             environmentStringBuilder.takeVariableFromString(SIMPLE_STRING);
             assertNotNull(properties.get("bar"));
             assertEquals("foo",properties.get("bar"));
         }

         public void testTakeVariableFromStringWithComplexString() {
             environmentStringBuilder.takeVariableFromString(COMPLEX_STRING);
             assertNotNull(properties.get("bar"));
             assertEquals("foo\nman",properties.get("bar"));
         }

         public void testTakeVariableFromStringWithMoreComplexString() {
             environmentStringBuilder.takeVariableFromString(MORE_COMPLEX_STRING);
             assertNotNull(properties.get("bar"));
             assertEquals("foo\nman\nchoo",properties.get("bar"));
         }
    }

    Please feel free to use the code in your project if you feel it's
    worthy. In any case, can you let me know if this is a valid problem and
    and if/when a fix will be available as this is a real nuisance to our
    project. I would be happy to test your next release for you.

    Cheers,
    Dave.



    This archive was generated by hypermail 2.0.0 : Fri Aug 27 2004 - 09:02:02 EDT