xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r161139 - in xmlbeans/trunk: src/typeimpl/org/apache/xmlbeans/impl/schema/ src/typeimpl/org/apache/xmlbeans/impl/util/ src/xmlcomp/org/apache/xmlbeans/impl/tool/ test/src/compile/scomp/common/mockobj/
Date Wed, 13 Apr 2005 01:20:42 GMT
Author: radup
Date: Tue Apr 12 18:20:39 2005
New Revision: 161139

URL: http://svn.apache.org/viewcvs?view=rev&rev=161139
Log:
Completed the implementation of Filer.

Added:
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/Diff.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/FilerImpl.java
      - copied, changed from r160947, xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/FilerImpl.java
Removed:
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/FilerImpl.java
Modified:
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscComplexTypeResolver.java
    xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/Diff.java
    xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java
    xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
    xmlbeans/trunk/test/src/compile/scomp/common/mockobj/TestFiler.java

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java?view=diff&r1=161138&r2=161139
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
(original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
Tue Apr 12 18:20:39 2005
@@ -43,6 +43,7 @@
 import org.apache.xmlbeans.impl.common.NameUtil;
 import org.apache.xmlbeans.impl.common.QNameHelper;
 import org.apache.xmlbeans.impl.common.XBeanDebug;
+import org.apache.xmlbeans.impl.util.FilerImpl;
 import org.apache.xmlbeans.impl.util.HexBin;
 import org.apache.xmlbeans.impl.values.XmlObjectBase;
 import org.apache.xmlbeans.impl.xb.xsdschema.AttributeGroupDocument;

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscComplexTypeResolver.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscComplexTypeResolver.java?view=diff&r1=161138&r2=161139
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscComplexTypeResolver.java
(original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscComplexTypeResolver.java
Tue Apr 12 18:20:39 2005
@@ -1083,7 +1083,7 @@
                     }
                     if (group == null)
                     {
-                        state.notFoundError(ref, SchemaType.ATTRIBUTE_GROUP, xsdag.xgetRef(),
false);
+                        state.notFoundError(ref, SchemaType.ATTRIBUTE_GROUP, xsdag.xgetRef(),
true);
                         continue;
                     }
                     if (state.isProcessing(group))
@@ -1305,7 +1305,7 @@
                 }
                 if (group == null)
                 {
-                    state.notFoundError(ref, SchemaType.MODEL_GROUP, ((Group)parseTree).xgetRef(),
false);
+                    state.notFoundError(ref, SchemaType.MODEL_GROUP, ((Group)parseTree).xgetRef(),
true);
                     return null;
                 }
                 if (state.isProcessing(group))

Added: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/Diff.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/Diff.java?view=auto&rev=161139
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/Diff.java (added)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/Diff.java Tue Apr 12 18:20:39
2005
@@ -0,0 +1,55 @@
+/*   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.impl.util;
+
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.Reader;
+import java.util.List;
+
+/**
+ * This needs to be here so that it can be accessed by FilerImpl
+ */
+public class Diff
+{
+    public static void readersAsText(Reader r1, String name1, Reader r2, String name2,
+        List diffs)
+        throws IOException
+    {
+        LineNumberReader reader1 = new LineNumberReader(r1);
+        LineNumberReader reader2 = new LineNumberReader(r2);
+        String line1 = reader1.readLine();
+        String line2 = reader2.readLine();
+        while (line1 != null && line2 != null)
+        {
+            if (!line1.equals(line2))
+            {
+                diffs.add("File \"" + name1 + "\" and file \"" +
+                    name2 + "\" differ at line " + reader1.getLineNumber() +
+                    ":" + "\n" + line1 + "\n========\n" + line2);
+                break;
+            }
+            line1 = reader1.readLine();
+            line2 = reader2.readLine();
+        }
+        if (line1 == null && line2 != null)
+            diffs.add("File \"" + name2 + "\" has extra lines at line " +
+                reader2.getLineNumber() + ":\n" + line2);
+        if (line1 != null && line2 == null)
+            diffs.add("File \"" + name1 + "\" has extra lines at line " +
+                reader1.getLineNumber() + ":\n" + line1);
+    }
+}

Copied: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/FilerImpl.java (from r160947,
xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/FilerImpl.java)
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/FilerImpl.java?view=diff&rev=161139&p1=xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/FilerImpl.java&r1=160947&p2=xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/FilerImpl.java&r2=161139
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/FilerImpl.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/util/FilerImpl.java Tue Apr 12 18:20:39
2005
@@ -13,7 +13,7 @@
 *  limitations under the License.
 */
 
-package org.apache.xmlbeans.impl.schema;
+package org.apache.xmlbeans.impl.util;
 
 import org.apache.xmlbeans.Filer;
 
@@ -21,7 +21,9 @@
 import java.io.IOException;
 import java.io.File;
 import java.io.Writer;
+import java.io.FileReader;
 import java.io.FileWriter;
+import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.FileOutputStream;
 import java.util.Set;
@@ -101,16 +103,20 @@
         if (verbose)
             System.err.println("created source: " + sourcefile.getAbsolutePath());
 
+        sourceFiles.add(sourcefile);
+
         if (incrSrcGen && sourcefile.exists())
         {
-            // KHK: ?
+            // Generate the file in a buffer and then compare it to the
+            // file already on disk
+            return new IncrFileWriter(sourcefile, repackager);
+        }
+        else
+        {
+            return repackager == null ?
+                (Writer) new FileWriter( sourcefile ) :
+                (Writer) new RepackagingWriter( sourcefile, repackager );
         }
-
-        sourceFiles.add(sourcefile);
-
-        return repackager == null
-            ? (Writer) new FileWriter( sourcefile )
-            : (Writer) new RepackagingWriter( sourcefile, repackager );
     }
 
     public List getSourceFiles()
@@ -123,6 +129,56 @@
         return repackager;
     }
 
+    static class IncrFileWriter extends StringWriter
+    {
+        private File _file;
+        private Repackager _repackager;
+
+        public IncrFileWriter(File file, Repackager repackager)
+        {
+            _file = file;
+            _repackager = repackager;
+        }
+
+        public void close() throws IOException
+        {
+            super.close();
+
+            // This is where all the real work happens
+            StringBuffer sb = _repackager != null ?
+                _repackager.repackage(getBuffer()) :
+                getBuffer();
+            String str = sb.toString();
+            List diffs = new ArrayList();
+            StringReader sReader = new StringReader(str);
+            FileReader fReader = new FileReader(_file);
+
+            try
+            {
+                Diff.readersAsText(sReader, "<generated>",
+                    fReader, _file.getName(), diffs);
+            }
+            finally
+            {
+                sReader.close();
+                fReader.close();
+            }
+
+            if (diffs.size() > 0)
+            {
+                // Diffs encountered, replace the file on disk with text from
+                // the buffer
+                FileWriter fw = new FileWriter(_file);
+                try
+                {   fw.write(str); }
+                finally
+                {   fw.close(); }
+            }
+            else
+                ; // If no diffs, don't do anything
+        }
+    }
+
     static class RepackagingWriter extends StringWriter
     {
         public RepackagingWriter ( File file, Repackager repackager )
@@ -136,8 +192,10 @@
             super.close();
 
             FileWriter fw = new FileWriter( _file );
-            fw.write( _repackager.repackage( getBuffer() ).toString() );
-            fw.close();
+            try
+            { fw.write( _repackager.repackage( getBuffer() ).toString() ); }
+            finally
+            { fw.close(); }
         }
 
         private File _file;

Modified: xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/Diff.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/Diff.java?view=diff&r1=161138&r2=161139
==============================================================================
--- xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/Diff.java (original)
+++ xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/Diff.java Tue Apr 12 18:20:39
2005
@@ -334,28 +334,7 @@
         List diffs)
         throws IOException
     {
-        LineNumberReader reader1 = new LineNumberReader(r1);
-        LineNumberReader reader2 = new LineNumberReader(r2);
-        String line1 = reader1.readLine();
-        String line2 = reader2.readLine();
-        while (line1 != null && line2 != null)
-        {
-            if (!line1.equals(line2))
-            {
-                diffs.add("File \"" + name1 + "\" and file \"" +
-                    name2 + "\" differ at line " + reader1.getLineNumber() +
-                    ":" + "\n" + line1 + "\n========\n" + line2);
-                break;
-            }
-            line1 = reader1.readLine();
-            line2 = reader2.readLine();
-        }
-        if (line1 == null && line2 != null)
-            diffs.add("File \"" + name2 + "\" has extra lines at line " +
-                reader2.getLineNumber() + ":\n" + line2);
-        if (line1 != null && line2 == null)
-            diffs.add("File \"" + name1 + "\" has extra lines at line " +
-                reader1.getLineNumber() + ":\n" + line1);
+        org.apache.xmlbeans.impl.util.Diff.readersAsText(r1, name1, r2, name2, diffs);
     }
 
     private static class XsbFilenameFilter implements FilenameFilter

Modified: xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java?view=diff&r1=161138&r2=161139
==============================================================================
--- xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java (original)
+++ xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java Tue
Apr 12 18:20:39 2005
@@ -21,7 +21,7 @@
 import org.apache.xmlbeans.impl.common.XmlErrorWatcher;
 import org.apache.xmlbeans.impl.schema.SchemaTypeCodePrinter;
 import org.apache.xmlbeans.impl.schema.SchemaTypeSystemCompiler;
-import org.apache.xmlbeans.impl.schema.FilerImpl;
+import org.apache.xmlbeans.impl.util.FilerImpl;
 import org.apache.xmlbeans.SchemaCodePrinter;
 import org.apache.xmlbeans.XmlOptions;
 import org.apache.xmlbeans.Filer;
@@ -64,7 +64,7 @@
         system.save(filer);
     }
 
-    private static void deleteObsoleteFiles(File rootDir, File srcDir, Set seenFiles)
+    static void deleteObsoleteFiles(File rootDir, File srcDir, Set seenFiles)
     {
         if (!(rootDir.isDirectory() && srcDir.isDirectory()))
             throw new IllegalArgumentException();

Modified: xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java?view=diff&r1=161138&r2=161139
==============================================================================
--- xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java (original)
+++ xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java Tue Apr 12
18:20:39 2005
@@ -34,8 +34,8 @@
 import org.apache.xmlbeans.impl.schema.SchemaTypeSystemCompiler;
 import org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl;
 import org.apache.xmlbeans.impl.schema.StscState;
-import org.apache.xmlbeans.impl.schema.FilerImpl;
 import org.apache.xmlbeans.impl.common.JarHelper;
+import org.apache.xmlbeans.impl.util.FilerImpl;
 import org.apache.xmlbeans.impl.values.XmlListImpl;
 import org.apache.xmlbeans.impl.xb.xmlconfig.ConfigDocument;
 import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
@@ -1094,6 +1094,13 @@
 
             // gen source files
             result &= SchemaTypeSystemCompiler.generateTypes(system, filer, options);
+
+            if (incrSrcGen)
+            {
+                // We have to delete extra source files that may be out of date
+                SchemaCodeGenerator.deleteObsoleteFiles(srcDir, srcDir,
+                    new HashSet(filer.getSourceFiles()));
+            }
 
             if (result)
             {

Modified: xmlbeans/trunk/test/src/compile/scomp/common/mockobj/TestFiler.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/src/compile/scomp/common/mockobj/TestFiler.java?view=diff&r1=161138&r2=161139
==============================================================================
--- xmlbeans/trunk/test/src/compile/scomp/common/mockobj/TestFiler.java (original)
+++ xmlbeans/trunk/test/src/compile/scomp/common/mockobj/TestFiler.java Tue Apr 12 18:20:39
2005
@@ -15,7 +15,7 @@
 package compile.scomp.common.mockobj;
 
 import org.apache.xmlbeans.Filer;
-import org.apache.xmlbeans.impl.schema.FilerImpl;
+import org.apache.xmlbeans.impl.util.FilerImpl;
 
 import java.io.File;
 import java.io.OutputStream;



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


Mime
View raw message