You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-cvs@xml.apache.org by pc...@apache.org on 2004/03/19 05:17:52 UTC

cvs commit: xml-xmlbeans/v2/jam/test/tests/org/apache/xmlbeans/test/jam Differ.java JamTestBase.java JamDiffer.java

pcal        2004/03/18 20:17:52

  Modified:    v2/jam/src/org/apache/xmlbeans/impl/jam
                        JAnnotatedElement.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/annotation
                        AnnotationProxy.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements
                        AnnotatedElementImpl.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/internal/javadoc
                        JavadocClassBuilder.java
               v2/jam/test/tests/org/apache/xmlbeans/test/jam
                        JamTestBase.java
  Added:       v2/jam/test/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses
                        ManyTags.java MultilineTags.java
               v2/jam/test/masters/javadoc testManyTags.xml
                        testMultilineTags.xml
               v2/jam/test/tests/org/apache/xmlbeans/test/jam Differ.java
  Removed:     v2/jam/test/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses
                        MultipleTags.java
               v2/jam/test/masters/javadoc testMultipleTags.xml
               v2/jam/test/tests/org/apache/xmlbeans/test/jam
                        JamDiffer.java
  Log:
  java2schema, jam updates
  
  Revision  Changes    Path
  1.4       +0 -4      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/JAnnotatedElement.java
  
  Index: JAnnotatedElement.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/JAnnotatedElement.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JAnnotatedElement.java	17 Mar 2004 23:29:45 -0000	1.3
  +++ JAnnotatedElement.java	19 Mar 2004 04:17:52 -0000	1.4
  @@ -63,9 +63,5 @@
      */
     public JAnnotation[] getAllJavadocTags();
   
  -  /**
  -   * Use of this method is discouraged. DOCME
  -   */
  -  public JAnnotation[] getAllJavadocTags(String tagname);
   
   }
  
  
  
  1.4       +27 -2     xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annotation/AnnotationProxy.java
  
  Index: AnnotationProxy.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annotation/AnnotationProxy.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AnnotationProxy.java	16 Mar 2004 05:34:49 -0000	1.3
  +++ AnnotationProxy.java	19 Mar 2004 04:17:52 -0000	1.4
  @@ -22,6 +22,7 @@
   import java.lang.reflect.Method;
   import java.lang.reflect.Modifier;
   import java.lang.reflect.InvocationTargetException;
  +import java.io.StringWriter;
   
   /**
    * <p>Provides a proxied view of some annotation artifact.  JAM calls the
  @@ -57,6 +58,8 @@
      */
     private static final String DEFAULT_NVPAIR_DELIMS = "\n\r";
   
  +  private static final String VALUE_QUOTE = "\"";
  +
   
     // ========================================================================
     // Variables
  @@ -180,8 +183,30 @@
         int eq = pair.indexOf('=');
         if (eq <= 0) continue; // if not there or is first character
         String name = pair.substring(0, eq).trim();
  -      String value = (eq < pair.length() - 1) ? pair.substring(eq + 1) : null;
  -      if (value != null) setValue(name,value);
  +      if (eq < pair.length() - 1) {
  +        String value = pair.substring(eq + 1).trim();
  +        if (value.startsWith(VALUE_QUOTE)) {
  +          value = parseQuotedValue(value.substring(1),st);
  +        }
  +        setValue(name,value);
  +      }
  +    }
  +  }
  +
  +  private String parseQuotedValue(String line, StringTokenizer st) {
  +    StringWriter out = new StringWriter();
  +    while(true) {
  +      int endQuote = line.indexOf(VALUE_QUOTE);
  +      if (endQuote == -1) {
  +        out.write(line);
  +        if (!st.hasMoreTokens()) return out.toString();
  +        out.write('\n');
  +        line = st.nextToken().trim();
  +        continue;
  +      } else {
  +        out.write(line.substring(0,endQuote).trim());
  +        return out.toString();
  +      }
       }
     }
   
  
  
  
  1.9       +2 -0      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/AnnotatedElementImpl.java
  
  Index: AnnotatedElementImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/AnnotatedElementImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AnnotatedElementImpl.java	17 Mar 2004 23:29:45 -0000	1.8
  +++ AnnotatedElementImpl.java	19 Mar 2004 04:17:52 -0000	1.9
  @@ -80,6 +80,7 @@
       return out;
     }
   
  +  /*
     public JAnnotation[] getAllJavadocTags(String named) {
       //FIXME this impl is quite gross
       if (mAllJavadocTags == null) return NO_ANNOTATION;
  @@ -94,6 +95,7 @@
       list.toArray(out);
       return out;
     }
  +  */
   
     // ========================================================================
     // MAnnotatedElement implementation
  
  
  
  1.15      +0 -1      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassBuilder.java
  
  Index: JavadocClassBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassBuilder.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- JavadocClassBuilder.java	18 Mar 2004 04:31:35 -0000	1.14
  +++ JavadocClassBuilder.java	19 Mar 2004 04:17:52 -0000	1.15
  @@ -225,7 +225,6 @@
     private String[] getJavadocArgs(JamServiceContext ctx) {
       String prop = ctx.getProperty(ARGS_PROPERTY);
       if (prop == null) return null;
  -
       StringTokenizer t = new StringTokenizer(prop);
       String[] out = new String[t.countTokens()];
       int i = 0;
  
  
  
  1.1                  xml-xmlbeans/v2/jam/test/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/ManyTags.java
  
  Index: ManyTags.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.xmlbeans.test.jam.dummyclasses;
  
  /**
   * Tests case for javadoc tags is declared more than once in a document.
   */
  public class ManyTags {
  
    /**
     * @foo x=-43 y=124 z=79
     * @foo y=2
     * @foo z=3
     * x=1
     * @foo w = 0
     *
     * @bar x=-4343
     *
     * @baz x=1
     */
    public int getId() { return -1; }
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/jam/test/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/MultilineTags.java
  
  Index: MultilineTags.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.xmlbeans.test.jam.dummyclasses;
  
  /**
   * @foo x = " this is a tag value which
   * spans several
   *
   * lines indeed"
   *
   * @bar y="  This is also a tag which spans
   *
   * a few lines but also has its closing
   *   quote in a weird place  "  see?
   *
   * @baz z=                       "
   *
   *                  I guess even something weird like
   *                       this should work
   *
   *
   *                              "
  
   * @boo a=   "  Here is a tag with multiple
   *   multiline values"
   * b = " here is another"
   * c = " and another
   * l = but this is still the same one
   * whoa that was = tricky"
   * d = "yup"
   *
   * @ejbgen:cmp-field column = "LicensorEntityID, CompanyID"
   * table-name= "LicensorEntity, Company"
   *
   * @ejbgen:finder
   *   signature = "java.util.Collection findByName(java.lang.String name)"
   *   ejb-ql = "SELECT OBJECT(o)
   *    FROM BandEJB AS o
   *    WHERE o.name = ?1"
   * 
   * @bee question = Can we confuse the parser?   "
   *     " =  "
   *   " ""
   *                                           " = = "
   *
   */
  public interface MultilineTags {
  }
  
  
  
  1.1                  xml-xmlbeans/v2/jam/test/masters/javadoc/testManyTags.xml
  
  Index: testManyTags.xml
  ===================================================================
  <class><name>org.apache.xmlbeans.test.jam.dummyclasses.ManyTags</name><is-interface>false</is-interface><superclass>java.lang.Object</superclass><modifiers>1</modifiers><constructor><modifiers>1</modifiers><source-position><line>20</line><column>8</column><source-uri>file:/X:/xml-xmlbeans/v2/jam/test/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/ManyTags.java</source-uri></source-position></constructor><method><name>getId</name><return-type>int</return-type><modifiers>1</modifiers><annotation><name>foo</name><annotation-value><name>x</name><value>-43 y=124 z=79</value></annotation-value><annotation-value><name>y</name><value>2</value></annotation-value><annotation-value><name>z</name><value>3</value></annotation-value><annotation-value><name>x</name><value>1</value></annotation-value><annotation-value><name>w</name><value>0</value></annotation-value></annotation><annotation><name>baz</name><annotation-value><name>x</name><value>1</value></annotation-value></annotation><annotation><name>bar</name><annotation-value><name>x</name><value>-4343</value></annotation-value></annotation><source-position><line>33</line><column>14</column><source-uri>file:/X:/xml-xmlbeans/v2/jam/test/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/ManyTags.java</source-uri></source-position></method><comment><![CDATA[Tests case for javadoc tags is declared more than once in a document.]]></comment><source-position><line>20</line><column>8</column><source-uri>file:/X:/xml-xmlbeans/v2/jam/test/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/ManyTags.java</source-uri></source-position></class>
  
  
  1.1                  xml-xmlbeans/v2/jam/test/masters/javadoc/testMultilineTags.xml
  
  Index: testMultilineTags.xml
  ===================================================================
  <class><name>org.apache.xmlbeans.test.jam.dummyclasses.MultilineTags</name><is-interface>true</is-interface><modifiers>513</modifiers><annotation><name>foo</name><annotation-value><name>x</name><value> this is a tag value which
  spans several
  lines indeed</value></annotation-value></annotation><annotation><name>ejbgen:cmp-field</name><annotation-value><name>column</name><value>LicensorEntityID, CompanyID</value></annotation-value><annotation-value><name>table-name</name><value>LicensorEntity, Company</value></annotation-value></annotation><annotation><name>boo</name><annotation-value><name>a</name><value>  Here is a tag with multiple
  multiline values</value></annotation-value><annotation-value><name>b</name><value>here is another</value></annotation-value><annotation-value><name>c</name><value> and another
  l = but this is still the same one
  whoa that was = tricky</value></annotation-value><annotation-value><name>d</name><value>yup</value></annotation-value></annotation><annotation><name>baz</name><annotation-value><name>z</name><value>
  I guess even something weird like
  this should work
  </value></annotation-value></annotation><annotation><name>ejbgen:finder</name><annotation-value><name>signature</name><value>java.util.Collection findByName(java.lang.String name)</value></annotation-value><annotation-value><name>ejb-ql</name><value>SELECT OBJECT(o)
  FROM BandEJB AS o
  WHERE o.name = ?1</value></annotation-value></annotation><annotation><name>bar</name><annotation-value><name>y</name><value>  This is also a tag which spans
  a few lines but also has its closing
  quote in a weird place</value></annotation-value></annotation><annotation><name>bee</name><annotation-value><name>question</name><value>Can we confuse the parser?   "</value></annotation-value><annotation-value><name>"</name><value>
  </value></annotation-value><annotation-value><name>"</name><value>= "</value></annotation-value></annotation><source-position><line>59</line><column>8</column><source-uri>file:/X:/xml-xmlbeans/v2/jam/test/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/MultilineTags.java</source-uri></source-position></class>
  
  
  1.10      +42 -24    xml-xmlbeans/v2/jam/test/tests/org/apache/xmlbeans/test/jam/JamTestBase.java
  
  Index: JamTestBase.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/test/tests/org/apache/xmlbeans/test/jam/JamTestBase.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JamTestBase.java	18 Mar 2004 04:31:35 -0000	1.9
  +++ JamTestBase.java	19 Mar 2004 04:17:52 -0000	1.10
  @@ -91,8 +91,11 @@
     // ========================================================================
     // Constants
   
  +  private static final boolean CONTINUE_ON_COMPARE_FAIL = false;
     private static final boolean WRITE_MASTER_ON_FAIL = true;
   
  +  private static final String WRITE_MASTER_PREFIX = "expected-";
  +
     protected static final String
             DUMMY = "org.apache.xmlbeans.test.jam.dummyclasses";
   
  @@ -115,7 +118,8 @@
       DUMMY+".FooImpl",
       DUMMY+".HeavilyCommented",
       DUMMY+".MyException",
  -    DUMMY+".MultipleTags"
  +    DUMMY+".MultilineTags",
  +    DUMMY+".ManyTags"
     };
   
   
  @@ -357,21 +361,25 @@
       }
     }
   
  +
  +  public void testMultilineTags() {
  +    if (!isAnnotationsAvailable()) return;
  +    JClass mt = resolved(mLoader.loadClass(DUMMY+".MultilineTags"));
  +    JAnnotation ann = mt.getAllJavadocTags()[5];
  +    System.out.println("\n\n\n=== "+ann.getValue("signature").asString());
  +    System.out.println("\n\n\n=== "+ann.getValue("ejb-ql").asString());
  +    compare(resolved(mt), "testMultilineTags.xml");
  +  }
  +
     public void testMultipleTags() {
       if (!isAnnotationsAvailable()) return;
  -    JClass mt = resolved(mLoader.loadClass(DUMMY+".MultipleTags"));
  +    JClass mt = resolved(mLoader.loadClass(DUMMY+".ManyTags"));
       JMethod method = mt.getMethods()[0];
       assertTrue(method.getAllJavadocTags().length == 6);
  -    assertTrue(method.getAllJavadocTags("foo").length == 4);
  -    assertTrue(method.getAllJavadocTags("foo")[2].getValue("z").asInt() == 3);
  -    assertTrue(method.getAllJavadocTags("bar").length == 1);
  -    assertTrue(method.getAllJavadocTags("bar")[0].getValue("x").asInt() == -4343);
  -    assertTrue(method.getAllJavadocTags("baz").length == 1);
  -    compare(mt,"testMultipleTags.xml");
  +    compare(mt,"testManyTags.xml");
     }
   
   
  -
     // ========================================================================
     // Private methods
   
  @@ -385,31 +393,41 @@
           jxw = new JamXmlWriter(out);
           jxw.write(element);
           out.flush();
  +        result = resultWriter.toString();
  +        /*
           try {
  -          System.out.println("--------------- "+resultWriter.toString());
  -          result = prettyPrint(resultWriter.toString());
  +        System.out.println("--------------- "+resultWriter.toString());
  +        result = prettyPrint(resultWriter.toString());
           } catch(Exception e) {
  -          e.printStackTrace();
  -          System.err.flush();
  -          System.out.println("Problem with result:");
  -          System.out.println(resultWriter.toString());
  -          System.out.flush();
  -          fail("failed to parse result");
  -          return;
  +        e.printStackTrace();
  +        System.err.flush();
  +        System.out.println("Problem with result:");
  +        System.out.println(resultWriter.toString());
  +        System.out.flush();
  +        fail("failed to parse result");
  +        return;
           }
  +        */
         }
  -      File masterFile = new File(getMasterDir(),masterName);
  -      FileReader inA = new FileReader(masterFile);
  -      StringReader inB = new StringReader(result);
  +      File masterFile = new File(getMasterDir().getAbsolutePath(),masterName);
         StringWriter diff = new StringWriter();
  -      boolean same = JamDiffer.getInstance().diff(inA,inB,diff);
  -      if (same) return;
  +      if (masterFile.exists()) {
  +        FileReader inA = new FileReader(masterFile);
  +        StringReader inB = new StringReader(result);
  +        boolean same = Differ.getInstance().diff(inA,inB,diff);
  +        if (same) return;
  +      } else {
  +        System.out.println("WARNING: Missing master file: "+masterFile);
  +      }
         if (WRITE_MASTER_ON_FAIL) {
  -        File expected = new File(getMasterDir(),"expected-"+masterName);
  +        File expected = new File(getMasterDir(),WRITE_MASTER_PREFIX+masterName);
           FileWriter eout = new FileWriter(expected);
           eout.write(result);
           eout.close();
  +        System.out.println("WARNING: Comparison failed, ignoring, wrote \n"+
  +                           expected);
         }
  +      if (CONTINUE_ON_COMPARE_FAIL) return;
         fail("Result did not match master at "+masterFile+":\n"+
              diff.toString());
       } catch(XMLStreamException xse) {
  
  
  
  1.1                  xml-xmlbeans/v2/jam/test/tests/org/apache/xmlbeans/test/jam/Differ.java
  
  Index: Differ.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.xmlbeans.test.jam;
  
  import java.io.IOException;
  import java.io.Reader;
  import java.io.BufferedReader;
  import java.io.Writer;
  import java.io.StringWriter;
  
  
  /**
   * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
   */
  public class Differ {
  
    // ========================================================================
    // Singleton
  
    public static Differ getInstance() { return INSTANCE; }
  
    private static final Differ INSTANCE = new Differ();
  
    private Differ() {}
  
    // ========================================================================
    // Public methods
  
    public boolean diff(Reader result,
                        Reader expect,
                        Writer out) throws IOException
    {
      //our glorious diffing algorithm.  FIXME find one we can use
      String resultString = getContentsAsString(result);
      String expectedString = getContentsAsString(expect);
      if (resultString.trim().equals(expectedString.trim())) return true;
      out.write("Result does not match expected value.  Result is:\n");
      out.write(resultString);
      out.write("\n\n Expected:\n");
      out.write(expectedString);
      return false;
    }
  
  
    // ========================================================================
    // Private methods
  
    private static String getContentsAsString(Reader in) throws IOException {
      StringWriter out = new StringWriter();
      BufferedReader reader = new BufferedReader(in);
      char[] buff = new char[1024];
      int len;
      while((len = reader.read(buff)) != -1) out.write(buff,0,len);
      return out.toString();
    }
  
    /*
    private static String[] getContentsAsArray(Reader in) throws IOException {
      BufferedReader reader = new BufferedReader(in);
      List list = new ArrayList();
      String s;
      while((s = reader.readLine()) != null) list.add(s);
      String[] out = new String[list.size()];
      list.toArray(out);
      return out;
    }
    */
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org