commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r233135 - in /jakarta/commons/sandbox/jci/trunk: ./ src/java/org/apache/commons/jci/compilers/eclipse/ src/java/org/apache/commons/jci/compilers/groovy/ src/java/org/apache/commons/jci/compilers/janino/ src/java/org/apache/commons/jci/monit...
Date Wed, 17 Aug 2005 08:34:57 GMT
Author: tcurdt
Date: Wed Aug 17 01:34:29 2005
New Revision: 233135

URL: http://svn.apache.org/viewcvs?rev=233135&view=rev
Log:
CompilationProblem changed to an interface (thanks to Joerg),
more testcase coverage,
a first working groovy compiler implementation


Added:
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseCompilationProblem.java   (with props)
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyCompilationProblem.java   (with props)
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoCompilationProblem.java   (with props)
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/utils/
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/utils/ThreadUtils.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/GroovySources.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/JavaSources.java
      - copied, changed from r233037, jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/Programs.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/utils/
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/utils/ThreadUtilsTestCase.java
Removed:
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/Programs.java
Modified:
    jakarta/commons/sandbox/jci/trunk/.classpath
    jakarta/commons/sandbox/jci/trunk/project.xml
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/CompilationProblem.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/ConsoleCompilationProblemHandler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/LogCompilationProblemHandler.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/AbstractTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/groovy/GroovyJavaCompilerTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/janino/JaninoJavaCompilerTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java

Modified: jakarta/commons/sandbox/jci/trunk/.classpath
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/.classpath?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/.classpath (original)
+++ jakarta/commons/sandbox/jci/trunk/.classpath Wed Aug 17 01:34:29 2005
@@ -12,5 +12,12 @@
 	<classpathentry kind="var" path="MAVEN_REPO/eclipse/jars/jdtcore-3.1.0.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/groovy/jars/groovy-1.0-jsr-02.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/janino/jars/janino-2.3.7.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/asm/jars/asm-util-2.0.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/asm/jars/asm-tree-2.0.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/asm/jars/asm-attrs-2.0.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/asm/jars/asm-analysis-2.0.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/asm/jars/asm-2.0.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/asm/jars/asm-commons-2.0.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/antlr/jars/antlr-2.7.5.jar"/>
 	<classpathentry kind="output" path="eclipse"/>
 </classpath>

Modified: jakarta/commons/sandbox/jci/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/project.xml?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/project.xml (original)
+++ jakarta/commons/sandbox/jci/trunk/project.xml Wed Aug 17 01:34:29 2005
@@ -121,6 +121,41 @@
       <artifactId>groovy</artifactId>
       <version>1.0-jsr-02</version>
     </dependency>
+    <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm-util</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm-attrs</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm-analysis</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm-tree</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm-commons</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>antlr</groupId>
+      <artifactId>antlr</artifactId>
+      <version>2.7.5</version>
+    </dependency>
 
   </dependencies>
 

Added: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseCompilationProblem.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseCompilationProblem.java?rev=233135&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseCompilationProblem.java (added)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseCompilationProblem.java Wed Aug 17 01:34:29 2005
@@ -0,0 +1,72 @@
+/*
+ * Copyright 1999-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.commons.jci.compilers.eclipse;
+
+import org.apache.commons.jci.problems.CompilationProblem;
+import org.eclipse.jdt.core.compiler.IProblem;
+
+public class EclipseCompilationProblem implements CompilationProblem {
+
+    private final IProblem problem;
+
+    public EclipseCompilationProblem(final IProblem pProblem) {
+        problem = pProblem;
+    }
+
+    public boolean isError() {
+        return problem.isError();
+    }
+
+    public String getFileName() {
+        return new String(problem.getOriginatingFileName());
+    }
+
+    public int getStartLine() {
+        return problem.getSourceLineNumber();
+    }
+
+    public int getStartColumn() {
+        return problem.getSourceStart();
+    }
+
+    public int getEndLine() {
+        return getStartLine();
+    }
+
+    public int getEndColumn() {
+        return problem.getSourceEnd();
+    }
+
+    public String getMessage() {
+        return problem.getMessage();
+    }
+
+    public String toString() {
+        final StringBuffer sb = new StringBuffer();
+        sb.append(getFileName()).append(" (");
+        sb.append(getStartLine());
+        sb.append(":");
+        sb.append(getStartColumn());
+        sb.append(") : ");
+        sb.append(getMessage());
+        return sb.toString();
+    }
+
+    public int getId() {
+        return problem.getID();
+    }
+
+}

Propchange: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseCompilationProblem.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java Wed Aug 17 01:34:29 2005
@@ -25,7 +25,6 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 import org.apache.commons.jci.compilers.JavaCompiler;
-import org.apache.commons.jci.problems.CompilationProblem;
 import org.apache.commons.jci.problems.CompilationProblemHandler;
 import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.ResourceStore;
@@ -232,10 +231,7 @@
                         final IProblem[] problems = result.getProblems();
                         for (int i = 0; i < problems.length; i++) {
                             final IProblem problem = problems[i];
-                            pProblemHandler.handle(new CompilationProblem(problem.getID(),
-                                    new String(problem.getOriginatingFileName()), problem
-                                            .getMessage(), problem.getSourceLineNumber(), problem
-                                            .getSourceLineNumber(), problem.isError()));
+                            pProblemHandler.handle(new EclipseCompilationProblem(problem));
                         }
                     }
                 }

Added: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyCompilationProblem.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyCompilationProblem.java?rev=233135&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyCompilationProblem.java (added)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyCompilationProblem.java Wed Aug 17 01:34:29 2005
@@ -0,0 +1,99 @@
+/*
+ * Copyright 1999-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.commons.jci.compilers.groovy;
+
+import org.apache.commons.jci.problems.CompilationProblem;
+import org.codehaus.groovy.control.messages.ExceptionMessage;
+import org.codehaus.groovy.control.messages.Message;
+import org.codehaus.groovy.control.messages.SimpleMessage;
+import org.codehaus.groovy.control.messages.SyntaxErrorMessage;
+import org.codehaus.groovy.syntax.SyntaxException;
+
+public class GroovyCompilationProblem implements CompilationProblem {
+
+    private final String fileName;
+    private final String message;
+    private final boolean error;
+    private final int startLine;
+    private final int startColumn;
+    private final int endLine;
+    private final int endColumn;
+
+    public GroovyCompilationProblem(final Message pMessage) {
+        if (pMessage instanceof SimpleMessage) {
+            error = false;
+        } else {
+            error = true;
+        }
+        if (pMessage instanceof SyntaxErrorMessage) {
+            SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage)pMessage;
+            SyntaxException syntaxException = syntaxErrorMessage.getCause();
+            message = syntaxException.getMessage();
+            fileName = syntaxException.getSourceLocator();
+            // FIXME: getStartLine() vs. getLine()
+            startLine = syntaxException.getStartLine();
+            startColumn = syntaxException.getStartColumn();
+            endLine = syntaxException.getLine();
+            endColumn = syntaxException.getEndColumn();
+        } else {
+            fileName = "";
+            startLine = 0;
+            startColumn = 0;
+            endLine = 0;
+            endColumn = 0;
+            if (pMessage instanceof ExceptionMessage) {
+                message = ((ExceptionMessage)pMessage).getCause().getMessage();
+            } else if (pMessage instanceof SimpleMessage) {
+                message = ((SimpleMessage)pMessage).getMessage();
+            } else {
+                message = pMessage.toString();
+            }
+        }
+    }
+
+    public boolean isError() {
+        return error;
+    }
+
+    public String getFileName() {
+        return fileName;
+    }
+
+    public int getStartLine() {
+        return startLine;
+    }
+
+    public int getStartColumn() {
+        return startColumn;
+    }
+
+    public int getEndLine() {
+        return endLine;
+    }
+
+    public int getEndColumn() {
+        return endColumn;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public String toString() {
+        return getMessage();
+    }
+
+}

Propchange: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyCompilationProblem.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java Wed Aug 17 01:34:29 2005
@@ -4,7 +4,6 @@
 import java.util.Iterator;
 import java.util.List;
 import org.apache.commons.jci.compilers.JavaCompiler;
-import org.apache.commons.jci.problems.CompilationProblem;
 import org.apache.commons.jci.problems.CompilationProblemHandler;
 import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.ResourceStore;
@@ -30,15 +29,17 @@
             final CompilationProblemHandler problemHandler
             ) {
      
-        final ClassLoader classloader = null;
-        final ErrorCollector collector = null;
-        final CompilerConfiguration configuration = null;
-        final CompilationUnit unit = null;
+        final CompilerConfiguration configuration = new CompilerConfiguration();
+        final ClassLoader classloader = this.getClass().getClassLoader();
+        final ErrorCollector collector = new ErrorCollector(configuration);
+        final CompilationUnit unit = new CompilationUnit(configuration);
         final SourceUnit[] source = new SourceUnit[clazzNames.length];
         for (int i = 0; i < source.length; i++) {
+            final String filename = clazzNames[i].replace('.','/') + ".java";
+            log.debug("adding source unit " + filename);
             source[i] = new SourceUnit(
-                    clazzNames[i],
-                    new String(reader.getContent(clazzNames[i])),
+                    filename,
+                    new String(reader.getContent(filename)), // FIXME delay the read
                     configuration,
                     classloader,
                     collector
@@ -46,31 +47,34 @@
             unit.addSource(source[i]);
         }
         try {
+            log.debug("compiling");
             unit.compile();
             
             final List classes = unit.getClasses();
             for (final Iterator it = classes.iterator(); it.hasNext();) {
                 final GroovyClass clazz = (GroovyClass) it.next();
                 final String name = clazz.getName().replace('.', File.separatorChar) + ".class";
-                byte[] bytes = clazz.getBytes();
+                final byte[] bytes = clazz.getBytes();
                 store.write(name, bytes);
             }
         } catch (final CompilationFailedException e) {
-            final ErrorCollector errorC = e.getUnit().getErrorCollector();
+            final ErrorCollector col = e.getUnit().getErrorCollector();
             
-            final List warnings = errorC.getWarnings();
+            final List warnings = col.getWarnings();
+            log.debug("handling " + warnings.size() + " warnings");
             for (final Iterator it = warnings.iterator(); it.hasNext();) {
                 final WarningMessage warning = (WarningMessage) it.next();
                 problemHandler.handle(
-                        new CompilationProblem(0, "", warning.getMessage(), 0, 0, false)
+                        new GroovyCompilationProblem(warning)
                         );
             }
 
-            final List errors = errorC.getErrors();
+            final List errors = col.getErrors();
+            log.debug("handling " + errors.size() + " errors");
             for (final Iterator it = errors.iterator(); it.hasNext();) {
                 final Message message = (Message) it.next();
                 problemHandler.handle(
-                        new CompilationProblem(0, "", "", 0, 0, false)
+                        new GroovyCompilationProblem(message)
                         );                
             }
         }

Added: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoCompilationProblem.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoCompilationProblem.java?rev=233135&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoCompilationProblem.java (added)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoCompilationProblem.java Wed Aug 17 01:34:29 2005
@@ -0,0 +1,93 @@
+/*
+ * Copyright 1999-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.commons.jci.compilers.janino;
+
+import org.apache.commons.jci.problems.CompilationProblem;
+import org.codehaus.janino.Location;
+import org.codehaus.janino.Scanner.LocatedException;
+
+public class JaninoCompilationProblem implements CompilationProblem {
+
+    private final Location location;
+    private final String fileName;
+    private final String message;
+    private final boolean error;
+
+    public JaninoCompilationProblem(final LocatedException pLocatedException) {
+        this(pLocatedException.getLocation(), pLocatedException.getMessage(), true);
+    }
+
+    public JaninoCompilationProblem(final Location pLocation, final String pMessage, final boolean pError) {
+      this(pLocation.getFileName(), pLocation, pMessage, pError);
+    }
+
+    public JaninoCompilationProblem(final String pFilename, final String pMessage, final boolean pError) {
+        this(pFilename, null, pMessage, pError);
+    }
+
+    public JaninoCompilationProblem(final String pFilename, final Location pLocation, final String pMessage, final boolean pError) {
+        location = pLocation;
+        fileName = pFilename;
+        message = pMessage;
+        error = pError;
+    }
+
+    public boolean isError() {
+        return error;
+    }
+
+    public String getFileName() {
+        return fileName;
+    }
+
+    public int getStartLine() {
+        if (location == null) {
+            return 0;
+        }
+        return location.getLineNumber();
+    }
+
+    public int getStartColumn() {
+        if (location == null) {
+            return 0;
+        }
+        return location.getColumnNumber();
+    }
+
+    public int getEndLine() {
+        return getStartLine();
+    }
+
+    public int getEndColumn() {
+        return getStartColumn();
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public String toString() {
+        final StringBuffer sb = new StringBuffer();
+        sb.append(getFileName()).append(" (");
+        sb.append(getStartLine());
+        sb.append(":");
+        sb.append(getStartColumn());
+        sb.append(") : ");
+        sb.append(getMessage());
+        return sb.toString();
+    }
+
+}

Propchange: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoCompilationProblem.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java Wed Aug 17 01:34:29 2005
@@ -22,7 +22,6 @@
 import java.util.Iterator;
 import java.util.Map;
 import org.apache.commons.jci.compilers.JavaCompiler;
-import org.apache.commons.jci.problems.CompilationProblem;
 import org.apache.commons.jci.problems.CompilationProblemHandler;
 import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.ResourceStore;
@@ -36,10 +35,8 @@
 import org.codehaus.janino.Java;
 import org.codehaus.janino.Parser;
 import org.codehaus.janino.Scanner;
-import org.codehaus.janino.CompileException;
 import org.codehaus.janino.UnitCompiler;
-import org.codehaus.janino.Parser.ParseException;
-import org.codehaus.janino.Scanner.ScanException;
+import org.codehaus.janino.Scanner.LocatedException;
 import org.codehaus.janino.util.ClassFile;
 
 /**
@@ -103,15 +100,10 @@
                     types.put(type, ic);
                 }
                 return ic;
-            } catch (ScanException e) {
-                problemHandler.handle(new CompilationProblem(0, e.getLocation().getFileName(), e.getMessage(), e.getLocation().getLineNumber(), e.getLocation().getLineNumber(), true));
-            } catch (ParseException e) {
-                problemHandler.handle(new CompilationProblem(0, e.getLocation().getFileName(), e.getMessage(), e.getLocation().getLineNumber(), e.getLocation().getLineNumber(), true));
+            } catch (LocatedException e) {
+                problemHandler.handle(new JaninoCompilationProblem(e));
             } catch (IOException e) {
-                problemHandler.handle(new CompilationProblem(0, fileNameForClass, "IO:" + e.getMessage(), 0, 0, true));
-            } catch (CompileException e) {
-                e.printStackTrace();
-                problemHandler.handle(new CompilationProblem(0, e.getLocation().getFileName(), e.getMessage(), e.getLocation().getLineNumber(), e.getLocation().getLineNumber(), true));
+                problemHandler.handle(new JaninoCompilationProblem(fileNameForClass, "IO:" + e.getMessage(), true));
             } finally {
                 if (scanner != null) {
                     try {

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java Wed Aug 17 01:34:29 2005
@@ -24,6 +24,7 @@
 import java.util.Map;
 import java.util.Set;
 import org.apache.commons.collections.MultiHashMap;
+import org.apache.commons.jci.utils.ThreadUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -398,10 +399,7 @@
                 }
             }
 
-            try {
-                Thread.sleep(delay);
-            } catch (InterruptedException e) {
-            }
+            ThreadUtils.sleep(delay);
         }
         
         log.info("fam exiting");

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/CompilationProblem.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/CompilationProblem.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/CompilationProblem.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/CompilationProblem.java Wed Aug 17 01:34:29 2005
@@ -15,50 +15,20 @@
  */
 package org.apache.commons.jci.problems;
 
-/**
- * @author tcurdt
- *
- */
-public class CompilationProblem {
-
-    private final int id;
-    private final String filename;
-    private final String message;
-    private final int lineStart;
-    private final int lineStop;
-    private final boolean fatal;
-    
-    public CompilationProblem(
-            final int pId,
-            final String pFilename,
-            final String pMessage,
-            final int pLineStart,
-            final int pLineStop,
-            final boolean pFatal
-            ) {
-        id = pId;
-        filename = pFilename;
-        message = pMessage;
-        lineStart = pLineStart;
-        lineStop = pLineStop;
-        fatal = pFatal;
-    }
-    
-    public boolean isFatal() {
-        return fatal;
-    }
-    
-    public String toString() {
-        final StringBuffer sb = new StringBuffer();
-        sb.append(filename).append(" (");
-        if (lineStart == lineStop) {
-            sb.append(lineStart);            
-        } else {
-            sb.append(lineStart).append('-').append(lineStop);
-        }
-        sb.append(") : ");
-        sb.append(message);
-        
-        return sb.toString();
-    }
-}
+public interface CompilationProblem {
+
+  boolean isError();
+
+  String getFileName();
+
+  int getStartLine();
+
+  int getStartColumn();
+
+  int getEndLine();
+
+  int getEndColumn();
+
+  String getMessage();
+
+}
\ No newline at end of file

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/ConsoleCompilationProblemHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/ConsoleCompilationProblemHandler.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/ConsoleCompilationProblemHandler.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/ConsoleCompilationProblemHandler.java Wed Aug 17 01:34:29 2005
@@ -15,36 +15,29 @@
  */
 package org.apache.commons.jci.problems;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-
-
 /**
  * @author tcurdt
  *
  */
 public class ConsoleCompilationProblemHandler implements CompilationProblemHandler {
-    
-    private final static Log log = LogFactory.getLog(ConsoleCompilationProblemHandler.class);
 
     private int errors;
     private int warnings;
-    
+
     public void handle( final CompilationProblem pProblem ) {
-        if (pProblem.isFatal()) {
+        if (pProblem.isError()) {
             errors++;
             System.err.println("error(" + errors + "):" + pProblem);
         } else {
             warnings++;
             System.err.println("warning(" + warnings + "):" + pProblem);
-        }        
+        }
     }
-    
-    
+
     public int getErrorCount() {
         return errors;
     }
+
     public int getWarningCount() {
         return warnings;
     }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/LogCompilationProblemHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/LogCompilationProblemHandler.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/LogCompilationProblemHandler.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/LogCompilationProblemHandler.java Wed Aug 17 01:34:29 2005
@@ -18,33 +18,31 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-
-
 /**
  * @author tcurdt
  *
  */
 public class LogCompilationProblemHandler implements CompilationProblemHandler {
-    
+
     private final static Log log = LogFactory.getLog(ConsoleCompilationProblemHandler.class);
 
     private int errors;
     private int warnings;
-    
+
     public void handle( final CompilationProblem pProblem ) {
-        if (pProblem.isFatal()) {
+        if (pProblem.isError()) {
             errors++;
             log.debug("error(" + errors + "):" + pProblem);
         } else {
             warnings++;
             log.debug("warning(" + warnings + "):" + pProblem);
-        }        
+        }
     }
-    
-    
+
     public int getErrorCount() {
         return errors;
     }
+
     public int getWarningCount() {
         return warnings;
     }

Added: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/utils/ThreadUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/utils/ThreadUtils.java?rev=233135&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/utils/ThreadUtils.java (added)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/utils/ThreadUtils.java Wed Aug 17 01:34:29 2005
@@ -0,0 +1,13 @@
+package org.apache.commons.jci.utils;
+
+
+public final class ThreadUtils {
+
+    public static void sleep( final long pDelay ) {
+        try {
+            Thread.sleep(pDelay);
+        } catch (final InterruptedException e) {
+        }
+    }
+    
+}

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/AbstractTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/AbstractTestCase.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/AbstractTestCase.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/AbstractTestCase.java Wed Aug 17 01:34:29 2005
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import junit.framework.TestCase;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.jci.utils.ThreadUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -128,11 +129,7 @@
     }
     
     protected void delay() {
-        try {
-            Thread.sleep(1500);
-        } catch (final InterruptedException e) {
-            ;
-        }
+        ThreadUtils.sleep(1500);
     }
     
     protected File createTempDirectory() throws IOException {

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java Wed Aug 17 01:34:29 2005
@@ -3,7 +3,7 @@
 import java.io.File;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.jci.compilers.AbstractCompilerTestCase;
-import org.apache.commons.jci.compilers.Programs;
+import org.apache.commons.jci.compilers.JavaSources;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -38,15 +38,15 @@
 
     private void initialCompile() throws Exception {
         delay();        
-        writeFile("jci/Simple.java", Programs.simple);        
-        writeFile("jci/Extended.java", Programs.extended);        
+        writeFile("jci/Simple.java", JavaSources.simple);        
+        writeFile("jci/Extended.java", JavaSources.extended);        
         waitForSignal(reloadSignal);
     }
     
     
     public void testCompileProblems() throws Exception {
         delay();        
-        writeFile("jci/Simple.java", Programs.error);
+        writeFile("jci/Simple.java", JavaSources.error);
         waitForSignal(reloadSignal);
         
         // FIXME
@@ -72,7 +72,7 @@
         assertTrue("Extended:Simple".equals(extended.toString()));
 
         delay();
-        writeFile("jci/Simple.java", Programs.SIMPLE);
+        writeFile("jci/Simple.java", JavaSources.SIMPLE);
         waitForSignal(reloadSignal);
     
         final Object SIMPLE = cl.loadClass("jci.Simple").newInstance();        

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java Wed Aug 17 01:34:29 2005
@@ -16,7 +16,7 @@
 package org.apache.commons.jci;
 
 import java.io.File;
-import org.apache.commons.jci.compilers.Programs;
+import org.apache.commons.jci.compilers.JavaSources;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -36,11 +36,11 @@
     private final byte[] clazzExtended;
     
     public ReloadingClassLoaderTestCase() {
-        clazzSimple = CompilerUtils.compile("jci.Simple", Programs.simple);
-        clazzSIMPLE = CompilerUtils.compile("jci.Simple", Programs.SIMPLE);
+        clazzSimple = CompilerUtils.compile("jci.Simple", JavaSources.simple);
+        clazzSIMPLE = CompilerUtils.compile("jci.Simple", JavaSources.SIMPLE);
         clazzExtended = CompilerUtils.compile(
                 new String[] { "jci.Extended", "jci.Simple" },
-                new String[] { Programs.extended, Programs.simple }
+                new String[] { JavaSources.extended, JavaSources.simple }
                 );
         assertTrue(clazzSimple.length > 0);
         assertTrue(clazzSIMPLE.length > 0);
@@ -170,6 +170,14 @@
         } catch(final ClassNotFoundException e) {
             log.info(e.getMessage());
         }
+    }
+    
+    public void testDelegation() {
+        cl.clearAssertionStatus();
+        cl.setClassAssertionStatus("org.apache.commons.jci.ReloadingClassLoader",true);
+        cl.setDefaultAssertionStatus(false);
+        cl.setPackageAssertionStatus("org.apache.commons.jci", true);
+        // FIXME: compare with delegation
     }
     
     protected void tearDown() throws Exception {

Added: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/GroovySources.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/GroovySources.java?rev=233135&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/GroovySources.java (added)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/GroovySources.java Wed Aug 17 01:34:29 2005
@@ -0,0 +1,48 @@
+package org.apache.commons.jci.compilers;
+
+
+public interface GroovySources {
+    
+    String simple =
+        "package jci;\n"
+        + "public class Simple { \n"
+        + "  public String toString() { \n"
+        + "    return \"Simple\"; \n"
+        + "  } \n"
+        + "} \n";
+
+    String SIMPLE =
+        "package jci;\n"
+        + "public class Simple { \n"
+        + "  public String toString() { \n"
+        + "    return \"SIMPLE\"; \n"
+        + "  } \n"
+        + "} \n";
+    
+    String extended =
+        "package jci;\n"
+        + "public class Extended extends Simple { \n"
+        + "  public String toString() { \n"
+        + "    return \"Extended:\" + super.toString(); \n"
+        + "  } \n"
+        + "} \n";
+
+    String warning =
+        "package jci;\n"
+        + "public class Simple { \n"
+        + "  public int generateWarning() { \n"
+        + "    return new java.util.Date().getHours(); \n"
+        + "  }\n"
+        + "  public String toString() { \n"
+        + "    return \"Simple\"; \n"
+        + "  } \n"
+        + "} \n";
+
+    String error =
+        "package jci;\n"
+        + "public class Simple { \n"
+        + "  public String toString() { \n"
+        + "    return 1; \n"
+        + "  } \n"
+        + "} \n";
+}

Copied: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/JavaSources.java (from r233037, jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/Programs.java)
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/JavaSources.java?p2=jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/JavaSources.java&p1=jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/Programs.java&r1=233037&r2=233135&rev=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/Programs.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/JavaSources.java Wed Aug 17 01:34:29 2005
@@ -1,7 +1,7 @@
 package org.apache.commons.jci.compilers;
 
 
-public interface Programs {
+public interface JavaSources {
     
     String simple =
         "package jci;\n"

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerTestCase.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerTestCase.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerTestCase.java Wed Aug 17 01:34:29 2005
@@ -2,28 +2,28 @@
 
 import org.apache.commons.jci.compilers.AbstractCompilerTestCase;
 import org.apache.commons.jci.compilers.JavaCompiler;
-import org.apache.commons.jci.compilers.Programs;
+import org.apache.commons.jci.compilers.JavaSources;
 import org.apache.commons.jci.problems.CompilationProblemHandler;
 
 
 public final class EclipseJavaCompilerTestCase extends AbstractCompilerTestCase {
     public void testSimpleCompilation() throws Exception {
         final JavaCompiler compiler = new EclipseJavaCompiler();
-        final CompilationProblemHandler handler = compileWith(compiler, Programs.simple);
+        final CompilationProblemHandler handler = compileWith(compiler, JavaSources.simple);
         assertTrue(handler.getWarningCount() == 0);
         assertTrue(handler.getErrorCount() == 0);
     }
     
     public void testCompilationError() throws Exception {
         final JavaCompiler compiler = new EclipseJavaCompiler();
-        final CompilationProblemHandler handler = compileWith(compiler, Programs.error);
+        final CompilationProblemHandler handler = compileWith(compiler, JavaSources.error);
         assertTrue(handler.getWarningCount() == 0);
         assertTrue(handler.getErrorCount() == 1);
     }
 
     public void testCompilationWarning() throws Exception {
         final JavaCompiler compiler = new EclipseJavaCompiler();
-        final CompilationProblemHandler handler = compileWith(compiler, Programs.warning);
+        final CompilationProblemHandler handler = compileWith(compiler, JavaSources.warning);
         assertTrue(handler.getWarningCount() == 1);
         assertTrue(handler.getErrorCount() == 0);
     }    

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/groovy/GroovyJavaCompilerTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/groovy/GroovyJavaCompilerTestCase.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/groovy/GroovyJavaCompilerTestCase.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/groovy/GroovyJavaCompilerTestCase.java Wed Aug 17 01:34:29 2005
@@ -1,15 +1,29 @@
 package org.apache.commons.jci.compilers.groovy;
 
 import org.apache.commons.jci.compilers.AbstractCompilerTestCase;
+import org.apache.commons.jci.compilers.GroovySources;
+import org.apache.commons.jci.compilers.JavaCompiler;
+import org.apache.commons.jci.problems.CompilationProblemHandler;
 
 
 public final class GroovyJavaCompilerTestCase extends AbstractCompilerTestCase {
     public void testSimpleCompilation() throws Exception {
+        final JavaCompiler compiler = new GroovyJavaCompiler();
+        final CompilationProblemHandler handler = compileWith(compiler, GroovySources.simple);
+        assertTrue(handler.getWarningCount() == 0);
+        assertTrue(handler.getErrorCount() == 0);
     }
     
     public void testCompilationError() throws Exception {
+        final JavaCompiler compiler = new GroovyJavaCompiler();
+        final CompilationProblemHandler handler = compileWith(compiler, GroovySources.error);
+        assertTrue(handler.getWarningCount() == 0);
+        assertTrue(handler.getErrorCount() == 1);
     }
 
     public void testCompilationWarning() throws Exception {
-    }
-}
+        final JavaCompiler compiler = new GroovyJavaCompiler();
+        final CompilationProblemHandler handler = compileWith(compiler, GroovySources.warning);
+        assertTrue(handler.getWarningCount() == 1);
+        assertTrue(handler.getErrorCount() == 0);
+    }}

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/janino/JaninoJavaCompilerTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/janino/JaninoJavaCompilerTestCase.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/janino/JaninoJavaCompilerTestCase.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/janino/JaninoJavaCompilerTestCase.java Wed Aug 17 01:34:29 2005
@@ -2,28 +2,28 @@
 
 import org.apache.commons.jci.compilers.AbstractCompilerTestCase;
 import org.apache.commons.jci.compilers.JavaCompiler;
-import org.apache.commons.jci.compilers.Programs;
+import org.apache.commons.jci.compilers.JavaSources;
 import org.apache.commons.jci.problems.CompilationProblemHandler;
 
 
 public final class JaninoJavaCompilerTestCase extends AbstractCompilerTestCase {
     public void testSimpleCompilation() throws Exception {
         final JavaCompiler compiler = new JaninoJavaCompiler();
-        final CompilationProblemHandler handler = compileWith(compiler, Programs.simple);
+        final CompilationProblemHandler handler = compileWith(compiler, JavaSources.simple);
         assertTrue(handler.getWarningCount() == 0);
         assertTrue(handler.getErrorCount() == 0);
     }
     
     public void testCompilationError() throws Exception {
         final JavaCompiler compiler = new JaninoJavaCompiler();
-        final CompilationProblemHandler handler = compileWith(compiler, Programs.error);
+        final CompilationProblemHandler handler = compileWith(compiler, JavaSources.error);
         assertTrue(handler.getWarningCount() == 0);
         assertTrue(handler.getErrorCount() == 1);
     }
 
     public void testCompilationWarning() throws Exception {
         final JavaCompiler compiler = new JaninoJavaCompiler();
-        final CompilationProblemHandler handler = compileWith(compiler, Programs.warning);
+        final CompilationProblemHandler handler = compileWith(compiler, JavaSources.warning);
         //assertTrue(handler.getWarningCount() == 1);
         assertTrue(handler.getErrorCount() == 0);
     }

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java?rev=233135&r1=233134&r2=233135&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java (original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java Wed Aug 17 01:34:29 2005
@@ -1,54 +1,129 @@
 package org.apache.commons.jci.problems;
 
-import junit.framework.TestCase;
+import org.apache.commons.jci.compilers.eclipse.EclipseCompilationProblem;
+import org.apache.commons.jci.compilers.groovy.GroovyCompilationProblem;
+import org.apache.commons.jci.compilers.janino.JaninoCompilationProblem;
+import org.codehaus.groovy.control.SourceUnit;
+import org.codehaus.groovy.control.messages.Message;
+import org.codehaus.groovy.control.messages.SyntaxErrorMessage;
+import org.codehaus.groovy.control.messages.WarningMessage;
+import org.codehaus.groovy.syntax.SyntaxException;
+import org.codehaus.janino.Location;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.internal.compiler.IProblemFactory;
+import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
 
+import junit.framework.TestCase;
 
+/**
+ * TODO: It might be better to actually try to compile some faulty code and
+ *       to handle the problems caused by those errors.
+ */
 public final class CompilationProblemTestCase extends TestCase {
 
-    public void testLocation() {
-        CompilationProblem problem;
-        
-        problem = new CompilationProblem(
-                0,
-                "filename",
-                "message",
-                1,
-                2,
-                true
-                );
-        assertTrue("filename (1-2) : message".equals(problem.toString()));
-
-        problem = new CompilationProblem(
-                0,
-                "filename",
-                "message",
-                1,
-                1,
-                true
-                );
-        assertTrue("filename (1) : message".equals(problem.toString()));
+    private static final String MESSAGE = "message";
+    private static final short COLUMN = 2;
+    private static final short LINE = 1;
+    private static final String FILENAME = "filename";
+
+    public void testJaninoCompilationProblem() {
+        CompilationProblem problem = createJaninoCompilationProblem(true);
+        assertEquals("wrong filename", FILENAME, problem.getFileName());
+        assertEquals("wrong line number", LINE, problem.getStartLine());
+        assertEquals("wrong column number", COLUMN, problem.getStartColumn());
+        assertEquals("wrong message", MESSAGE, problem.getMessage());
+        assertTrue("wrong error level", problem.isError());
+
+        problem = createJaninoCompilationProblem(false);
+        assertEquals("wrong filename", FILENAME, problem.getFileName());
+        assertEquals("wrong line number", LINE, problem.getStartLine());
+        assertEquals("wrong column number", COLUMN, problem.getStartColumn());
+        assertEquals("wrong message", MESSAGE, problem.getMessage());
+        assertFalse("wrong error level", problem.isError());
+    }
+
+    public void testEclipseCompilationProblem() {
+        CompilationProblem problem = createEclipseCompilationProblem(true);
+        assertEquals("wrong filename", FILENAME, problem.getFileName());
+        assertEquals("wrong line number", LINE, problem.getStartLine());
+        assertEquals("wrong column number", COLUMN, problem.getStartColumn());
+        // FIXME: Don't know how to create eclipse's IProblem with message
+        //assertEquals("wrong message", MESSAGE, problem.getMessage());
+        assertTrue("wrong error level", problem.isError());
+
+        problem = createEclipseCompilationProblem(false);
+        assertEquals("wrong filename", FILENAME, problem.getFileName());
+        assertEquals("wrong line number", LINE, problem.getStartLine());
+        assertEquals("wrong column number", COLUMN, problem.getStartColumn());
+        // FIXME: Don't know how to create eclipse's IProblem with message
+        //assertEquals("wrong message", MESSAGE, problem.getMessage());
+        assertFalse("wrong error level", problem.isError());
+
+    }
+
+    public void testGroovyCompilationProblem() {
+        CompilationProblem problem = createGroovyCompilationProblem(true);
+        // FIXME: Don't know how to access filename info.
+        //assertEquals("wrong filename", FILENAME, problem.getFileName());
+        assertEquals("wrong line number", LINE, problem.getStartLine());
+        assertEquals("wrong column number", COLUMN, problem.getStartColumn());
+        // FIXME: Don't know how to access the "real" message.
+        assertEquals("wrong message", MESSAGE + " @ line " + LINE + ", column " + COLUMN + ".", problem.getMessage());
+        assertTrue("wrong error level", problem.isError());
+
+        problem = createGroovyCompilationProblem(false);
+        // FIXME: Don't know how to create a LocatedMessage with filename info.
+        //assertEquals("wrong filename", FILENAME, problem.getFileName());
+        // FIXME: Don't know how to create a LocatedMessage with location info.
+        //assertEquals("wrong line number", LINE, problem.getStartLine());
+        //assertEquals("wrong column number", COLUMN, problem.getStartColumn());
+        assertEquals("wrong message", MESSAGE, problem.getMessage());
+        assertFalse("wrong error level", problem.isError());
     }
 
     public void testErrorHandling() {
         final CompilationProblemHandler handler = new ConsoleCompilationProblemHandler();
-        final CompilationProblem error = new CompilationProblem(
-                0,
-                "filename",
-                "message",
-                1,
-                1,
-                true
-                );
+        final CompilationProblem error = createJaninoCompilationProblem(true);
         handler.handle(error);
+        assertEquals("wrong number of errors", 1, handler.getErrorCount());
+        assertEquals("wrong number of warnings", 0, handler.getWarningCount());
 
-        final CompilationProblem warning = new CompilationProblem(
-                0,
-                "filename",
-                "message",
-                1,
-                1,
-                false
-                );
+        final CompilationProblem warning = createJaninoCompilationProblem(false);
         handler.handle(warning);
+        assertEquals("wrong number of errors", 1, handler.getErrorCount());
+        assertEquals("wrong number of warnings", 1, handler.getWarningCount());
     }
+
+    private static JaninoCompilationProblem createJaninoCompilationProblem(final boolean pError) {
+        Location location = new Location(FILENAME, LINE, COLUMN);
+        return new JaninoCompilationProblem(location, MESSAGE, pError);
+    }
+
+    private static EclipseCompilationProblem createEclipseCompilationProblem(final boolean pError) {
+        int severity;
+        if (pError) {
+            severity = 1;
+        } else {
+            severity = 0;
+        }
+        IProblemFactory problemFactory = new DefaultProblemFactory();
+        IProblem problem =
+            problemFactory.createProblem(FILENAME.toCharArray(), 1, new String[0],
+                    new String[0], severity, COLUMN, COLUMN, LINE);
+        return new EclipseCompilationProblem(problem);
+    }
+
+    private static GroovyCompilationProblem createGroovyCompilationProblem(final boolean pError) {
+        Message message;
+        if (pError) {
+            message =
+                new SyntaxErrorMessage(new SyntaxException(MESSAGE, LINE, COLUMN),
+                                       new SourceUnit(FILENAME, "", null, null, null));
+        } else {
+            message =
+                new WarningMessage(WarningMessage.NONE, MESSAGE, null, null);
+        }
+        return new GroovyCompilationProblem(message);
+    }
+
 }

Added: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/utils/ThreadUtilsTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/utils/ThreadUtilsTestCase.java?rev=233135&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/utils/ThreadUtilsTestCase.java (added)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/utils/ThreadUtilsTestCase.java Wed Aug 17 01:34:29 2005
@@ -0,0 +1,28 @@
+package org.apache.commons.jci.utils;
+
+import junit.framework.TestCase;
+
+
+public final class ThreadUtilsTestCase extends TestCase {
+
+    public void testSleep() {
+        final long start = System.currentTimeMillis();
+        ThreadUtils.sleep(1000);
+        final long stop = System.currentTimeMillis();
+        assertTrue( Math.abs( (stop-start) - 1000) < 20 );
+    }
+
+    public void testSleepInterruption() throws InterruptedException {
+        final Thread thread = new Thread(new Runnable() {
+            public void run() {
+                ThreadUtils.sleep(2000);
+            }
+        });
+        thread.start();
+        final long start = System.currentTimeMillis();
+        thread.interrupt();
+        thread.join();
+        final long stop = System.currentTimeMillis();
+        assertTrue( (stop-start) < 1000 );
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message