[jboss-svn-commits] JBL Code SVN: r12814 - in labs/jbossrules/trunk/drools-compiler: src/main/java/org/apache/commons/jci/compilers and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jun 24 22:14:32 EDT 2007
Author: mark.proctor at jboss.com
Date: 2007-06-24 22:14:32 -0400 (Sun, 24 Jun 2007)
New Revision: 12814
Added:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompilerSettings.java
Modified:
labs/jbossrules/trunk/drools-compiler/.classpath
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/EclipseCompilationProblem.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JaninoCompilationProblem.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JavaCompiler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/problems/CompilationProblem.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/problems/CompilationProblemHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/readers/MemoryResourceReader.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/readers/ResourceReader.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/stores/ResourceStore.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialect.java
Log:
-updated to jci 1.0
Modified: labs/jbossrules/trunk/drools-compiler/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-compiler/.classpath 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/.classpath 2007-06-25 02:14:32 UTC (rev 12814)
@@ -1,18 +1,19 @@
-<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
- <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
- <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/>
- <classpathentry kind="output" path="target/classes"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="var" path="M2_REPO/org/antlr/antlr-runtime/3.0/antlr-runtime-3.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta26/mvel14-1.2beta26.jar"/>
- <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.2.3.v_686_R32x/core-3.2.3.v_686_R32x.jar"/>
- <classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
- <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.7/janino-2.5.7.jar"/>
- <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
- <classpathentry kind="src" path="/drools-core"/>
-</classpath>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var" path="M2_REPO/org/antlr/antlr-runtime/3.0/antlr-runtime-3.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta26/mvel14-1.2beta26.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.2.3.v_686_R32x/core-3.2.3.v_686_R32x.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
+ <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.7/janino-2.5.7.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
+ <classpathentry kind="src" path="/drools-core"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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;
import org.apache.commons.jci.problems.CompilationProblemHandler;
@@ -4,30 +21,34 @@
import org.apache.commons.jci.readers.ResourceReader;
import org.apache.commons.jci.stores.ResourceStore;
-public abstract class AbstractJavaCompiler
- implements
- JavaCompiler {
+/**
+ * Base class for compiler implementations. Provides just a few
+ * convenience methods.
+ *
+ * @author tcurdt
+ */
+public abstract class AbstractJavaCompiler implements JavaCompiler {
+
protected CompilationProblemHandler problemHandler;
- public void setCompilationProblemHandler(final CompilationProblemHandler pHandler) {
- this.problemHandler = pHandler;
+ public void setCompilationProblemHandler( final CompilationProblemHandler pHandler ) {
+ problemHandler = pHandler;
}
- public CompilationResult compile(final String[] pClazzNames,
- final ResourceReader pReader,
- final ResourceStore pStore) {
+ public CompilationResult compile( final String[] pClazzNames, final ResourceReader pReader, final ResourceStore pStore ) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- if ( classLoader == null ) {
+ if (classLoader == null) {
classLoader = this.getClass().getClassLoader();
}
- return compile( pClazzNames,
- pReader,
- pStore,
- classLoader );
+ return compile(pClazzNames, pReader, pStore, classLoader, createDefaultSettings());
}
+ public CompilationResult compile( final String[] pClazzNames, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader ) {
+ return compile(pClazzNames, pReader, pStore, pClassLoader, createDefaultSettings());
+ }
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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;
import java.util.ArrayList;
@@ -4,36 +21,44 @@
import java.util.Collection;
import org.apache.commons.jci.problems.CompilationProblem;
+/**
+ * A CompilationResult represents the result of a compilation.
+ * It includes errors (which failed the compilation) or warnings
+ * (that can be ignored and do not affect the creation of the
+ * class files)
+ *
+ * @author tcurdt
+ */
public final class CompilationResult {
-
+
private final CompilationProblem[] errors;
private final CompilationProblem[] warnings;
-
- public CompilationResult(final CompilationProblem[] pProblems) {
+
+ public CompilationResult( final CompilationProblem[] pProblems ) {
final Collection errorsColl = new ArrayList();
final Collection warningsColl = new ArrayList();
- for ( int i = 0; i < pProblems.length; i++ ) {
+ for (int i = 0; i < pProblems.length; i++) {
final CompilationProblem problem = pProblems[i];
- if ( problem.isError() ) {
- errorsColl.add( problem );
+ if (problem.isError()) {
+ errorsColl.add(problem);
} else {
- warningsColl.add( problem );
+ warningsColl.add(problem);
}
}
+
+ errors = new CompilationProblem[errorsColl.size()];
+ errorsColl.toArray(errors);
- this.errors = new CompilationProblem[errorsColl.size()];
- errorsColl.toArray( this.errors );
-
- this.warnings = new CompilationProblem[warningsColl.size()];
- warningsColl.toArray( this.warnings );
+ warnings = new CompilationProblem[warningsColl.size()];
+ warningsColl.toArray(warnings);
}
-
+
public CompilationProblem[] getErrors() {
- return this.errors;
+ return errors;
}
public CompilationProblem[] getWarnings() {
- return this.warnings;
+ return warnings;
}
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/EclipseCompilationProblem.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/EclipseCompilationProblem.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/EclipseCompilationProblem.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -14,35 +14,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.jci.compilers;
import org.apache.commons.jci.problems.CompilationProblem;
import org.eclipse.jdt.core.compiler.IProblem;
-public class EclipseCompilationProblem
- implements
- CompilationProblem {
+/**
+ * Wrapping an Eclipse compiler problem
+ *
+ * @author tcurdt
+ */
+public final class EclipseCompilationProblem implements CompilationProblem {
private final IProblem problem;
public EclipseCompilationProblem(final IProblem pProblem) {
- this.problem = pProblem;
+ problem = pProblem;
}
public boolean isError() {
- return this.problem.isError();
+ return problem.isError();
}
public String getFileName() {
- return new String( this.problem.getOriginatingFileName() );
+ return new String(problem.getOriginatingFileName());
}
public int getStartLine() {
- return this.problem.getSourceLineNumber();
+ return problem.getSourceLineNumber();
}
public int getStartColumn() {
- return this.problem.getSourceStart();
+ return problem.getSourceStart();
}
public int getEndLine() {
@@ -50,26 +54,26 @@
}
public int getEndColumn() {
- return this.problem.getSourceEnd();
+ return problem.getSourceEnd();
}
public String getMessage() {
- return this.problem.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() );
+ sb.append(getFileName()).append(" (");
+ sb.append(getStartLine());
+ sb.append(":");
+ sb.append(getStartColumn());
+ sb.append(") : ");
+ sb.append(getMessage());
return sb.toString();
}
public int getId() {
- return this.problem.getID();
+ return problem.getID();
}
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -44,21 +44,25 @@
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
+/**
+ * Eclipse compiler implemenation
+ *
+ * @author tcurdt
+ */
public final class EclipseJavaCompiler extends AbstractJavaCompiler {
- //private final Log log = LogFactory.getLog(EclipseJavaCompiler.class);
- private final Map settings;
+ private final EclipseJavaCompilerSettings defaultSettings;
public EclipseJavaCompiler() {
this( new EclipseJavaCompilerSettings() );
}
public EclipseJavaCompiler(final Map pSettings) {
- this.settings = pSettings;
+ this.defaultSettings = new EclipseJavaCompilerSettings( pSettings );
}
public EclipseJavaCompiler(final EclipseJavaCompilerSettings pSettings) {
- this.settings = pSettings.getMap();
+ this.defaultSettings = pSettings;
}
final class CompilationUnit
@@ -83,16 +87,11 @@
this.typeName = this.clazzName.toCharArray();
}
- // log.debug("className=" + clazzName);
- // log.debug("fileName=" + fileName);
- // log.debug("typeName=" + new String(typeName));
-
final StringTokenizer izer = new StringTokenizer( this.clazzName,
"." );
this.packageName = new char[izer.countTokens() - 1][];
for ( int i = 0; i < this.packageName.length; i++ ) {
this.packageName[i] = izer.nextToken().toCharArray();
- // log.debug("package[" + i + "]=" + new String(packageName[i]));
}
}
@@ -101,7 +100,14 @@
}
public char[] getContents() {
- return new String( this.reader.getBytes( this.fileName ) ).toCharArray();
+ final byte[] content = this.reader.getBytes( this.fileName );
+
+ if ( content == null ) {
+ return null;
+ //throw new RuntimeException("resource " + fileName + " could not be found");
+ }
+
+ return new String( content ).toCharArray();
}
public char[] getMainTypeName() {
@@ -116,19 +122,71 @@
public org.apache.commons.jci.compilers.CompilationResult compile(final String[] pSourceFiles,
final ResourceReader pReader,
final ResourceStore pStore,
- final ClassLoader pClassLoader) {
+ final ClassLoader pClassLoader,
+ final JavaCompilerSettings pSettings) {
- final Map settingsMap = this.settings;
- // final Set sourceFileIndex = new HashSet();
+ final Map settingsMap = ((EclipseJavaCompilerSettings) pSettings).getMap();
+
+ final Collection problems = new ArrayList();
+
final ICompilationUnit[] compilationUnits = new ICompilationUnit[pSourceFiles.length];
for ( int i = 0; i < compilationUnits.length; i++ ) {
final String sourceFile = pSourceFiles[i];
- compilationUnits[i] = new CompilationUnit( pReader,
- sourceFile );
- // sourceFileIndex.add(sourceFile);
- // log.debug("compiling " + sourceFile);
+
+ if ( pReader.isAvailable( sourceFile ) ) {
+ compilationUnits[i] = new CompilationUnit( pReader,
+ sourceFile );
+ } else {
+
+ final CompilationProblem problem = new CompilationProblem() {
+
+ public int getEndColumn() {
+ return 0;
+ }
+
+ public int getEndLine() {
+ return 0;
+ }
+
+ public String getFileName() {
+ return sourceFile;
+ }
+
+ public String getMessage() {
+ return "Source " + sourceFile + " could not be found";
+ }
+
+ public int getStartColumn() {
+ return 0;
+ }
+
+ public int getStartLine() {
+ return 0;
+ }
+
+ public boolean isError() {
+ return true;
+ }
+
+ public String toString() {
+ return getMessage();
+ }
+ };
+
+ if ( this.problemHandler != null ) {
+ this.problemHandler.handle( problem );
+ }
+
+ problems.add( problem );
+ }
}
+ if ( problems.size() > 0 ) {
+ final CompilationProblem[] result = new CompilationProblem[problems.size()];
+ problems.toArray( result );
+ return new org.apache.commons.jci.compilers.CompilationResult( result );
+ }
+
final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
final IProblemFactory problemFactory = new DefaultProblemFactory( Locale.getDefault() );
final INameEnvironment nameEnvironment = new INameEnvironment() {
@@ -155,7 +213,7 @@
result.append( '.' );
}
- // log.debug("finding typeName=" + new String(typeName) + " packageName=" + result.toString());
+ // log.debug("finding typeName=" + new String(typeName) + " packageName=" + result.toString());
result.append( pTypeName );
return findType( result.toString() );
@@ -167,13 +225,10 @@
return null;
}
- // log.debug("finding " + pClazzName);
-
final String resourceName = ClassUtils.convertClassToResourcePath( pClazzName );
final byte[] clazzBytes = pStore.read( pClazzName );
if ( clazzBytes != null ) {
- // log.debug("loading from store " + pClazzName);
final char[] fileName = pClazzName.toCharArray();
try {
@@ -183,22 +238,12 @@
return new NameEnvironmentAnswer( classFileReader,
null );
} catch ( final ClassFormatException e ) {
- // log.error("wrong class format", e);
- return null;
+ throw new RuntimeException( "ClassFormatException in loading class '" + fileName + "' with JCI." );
}
}
- // log.debug("not in store " + pClazzName);
-
- // if (pReader.isAvailable(clazzName.replace('.', '/') + ".java")) {
- // log.debug("compile " + clazzName);
- // ICompilationUnit compilationUnit = new CompilationUnit(pReader, clazzName);
- // return new NameEnvironmentAnswer(compilationUnit, null);
- // }
-
final InputStream is = pClassLoader.getResourceAsStream( resourceName );
if ( is == null ) {
- // log.debug("class " + pClazzName + " not found");
return null;
}
@@ -221,25 +266,23 @@
return new NameEnvironmentAnswer( classFileReader,
null );
} catch ( final IOException e ) {
- e.printStackTrace();
- // log.error("could not read class", e);
- return null;
+ throw new RuntimeException( "could not read class",
+ e );
} catch ( final ClassFormatException e ) {
- e.printStackTrace();
- // log.error("wrong class format", e);
- return null;
+ throw new RuntimeException( "wrong class format",
+ e );
} finally {
try {
baos.close();
} catch ( final IOException oe ) {
- oe.printStackTrace();
- // log.error("could not close output stream", oe);
+ throw new RuntimeException( "could not close output stream",
+ oe );
}
try {
is.close();
} catch ( final IOException ie ) {
- ie.printStackTrace();
- // log.error("could not close input stream", ie);
+ throw new RuntimeException( "could not close input stream",
+ ie );
}
}
}
@@ -248,14 +291,13 @@
final InputStream is = pClassLoader.getResourceAsStream( ClassUtils.convertClassToResourcePath( pClazzName ) );
if ( is != null ) {
- // log.debug("found the class for " + pClazzName + "- no package");
return false;
}
+ // FIXME: this should not be tied to the extension
final String source = pClazzName.replace( '.',
'/' ) + ".java";
if ( pReader.isAvailable( source ) ) {
- // log.debug("found the source " + source + " for " + pClazzName + " - no package ");
return false;
}
@@ -284,11 +326,9 @@
}
public void cleanup() {
- // log.debug("cleanup");
}
};
- final Collection problems = new ArrayList();
final ICompilerRequestor compilerRequestor = new ICompilerRequestor() {
public void acceptResult(final CompilationResult pResult) {
if ( pResult.hasProblems() ) {
@@ -335,4 +375,8 @@
problems.toArray( result );
return new org.apache.commons.jci.compilers.CompilationResult( result );
}
+
+ public JavaCompilerSettings createDefaultSettings() {
+ return this.defaultSettings;
+ }
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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;
import java.util.HashMap;
@@ -2,34 +19,47 @@
import java.util.Map;
-import org.apache.commons.jci.compilers.JavaCompilerSettings;
+
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
-public class EclipseJavaCompilerSettings extends JavaCompilerSettings {
+/**
+ * Native Eclipse compiler settings
+ *
+ * @author tcurdt
+ */
+public final class EclipseJavaCompilerSettings extends JavaCompilerSettings {
final private Map defaultEclipseSettings = new HashMap();
public EclipseJavaCompilerSettings() {
- this.defaultEclipseSettings.put( CompilerOptions.OPTION_LineNumberAttribute,
+ defaultEclipseSettings.put( CompilerOptions.OPTION_LineNumberAttribute,
CompilerOptions.GENERATE );
- this.defaultEclipseSettings.put( CompilerOptions.OPTION_SourceFileAttribute,
+ defaultEclipseSettings.put( CompilerOptions.OPTION_SourceFileAttribute,
CompilerOptions.GENERATE );
- this.defaultEclipseSettings.put( CompilerOptions.OPTION_ReportUnusedImport,
+ defaultEclipseSettings.put( CompilerOptions.OPTION_ReportUnusedImport,
CompilerOptions.IGNORE );
- this.defaultEclipseSettings.put( CompilerOptions.OPTION_LocalVariableAttribute,
+ defaultEclipseSettings.put( CompilerOptions.OPTION_LocalVariableAttribute,
CompilerOptions.GENERATE );
}
+ public EclipseJavaCompilerSettings(final Map pMap) {
+ defaultEclipseSettings.putAll( pMap );
+ }
+
public Map getMap() {
- final Map map = new HashMap( this.defaultEclipseSettings );
+ final Map map = new HashMap( defaultEclipseSettings );
map.put( CompilerOptions.OPTION_ReportDeprecation,
- CompilerOptions.GENERATE );
+ CompilerOptions.GENERATE ); // Not sure what we put here from JavaCompilerSettings
map.put( CompilerOptions.OPTION_TargetPlatform,
- CompilerOptions.VERSION_1_4 );
+ (getTargetVersion() != null) ? getTargetVersion() : CompilerOptions.VERSION_1_4 );
map.put( CompilerOptions.OPTION_Source,
- CompilerOptions.VERSION_1_4 );
+ (getSourceVersion() != null) ? getSourceVersion() : CompilerOptions.VERSION_1_4 );
map.put( CompilerOptions.OPTION_Encoding,
- "UTF-8" );
+ (getSourceEncoding() != null) ? getSourceEncoding() : "UTF-8" );
return map;
}
+
+ public String toString() {
+ return defaultEclipseSettings.toString();
+ }
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JaninoCompilationProblem.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JaninoCompilationProblem.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JaninoCompilationProblem.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -14,75 +14,64 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.jci.compilers;
import org.apache.commons.jci.problems.CompilationProblem;
import org.codehaus.janino.Location;
import org.codehaus.janino.Scanner.LocatedException;
-public class JaninoCompilationProblem
- implements
- CompilationProblem {
+/**
+ * Janino version of a CompilationProblem
+ *
+ * @author tcurdt
+ */
+public final class JaninoCompilationProblem implements CompilationProblem {
private final Location location;
- private final String fileName;
- private final String message;
- private final boolean error;
+ private final String fileName;
+ private final String message;
+ private final boolean error;
public JaninoCompilationProblem(final LocatedException pLocatedException) {
- this( pLocatedException.getLocation(),
- pLocatedException.getMessage(),
- true );
+ 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 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 String pMessage, final boolean pError) {
+ this(pFilename, null, pMessage, pError);
}
- public JaninoCompilationProblem(final String pFilename,
- final Location pLocation,
- final String pMessage,
- final boolean pError) {
- this.location = pLocation;
- this.fileName = pFilename;
- this.message = pMessage;
- this.error = 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 this.error;
+ return error;
}
public String getFileName() {
- return this.fileName;
+ return fileName;
}
public int getStartLine() {
- if ( this.location == null ) {
+ if (location == null) {
return 0;
}
- return this.location.getLineNumber();
+ return location.getLineNumber();
}
public int getStartColumn() {
- if ( this.location == null ) {
+ if (location == null) {
return 0;
}
- return this.location.getColumnNumber();
+ return location.getColumnNumber();
}
public int getEndLine() {
@@ -94,17 +83,17 @@
}
public String getMessage() {
- return this.message;
+ 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() );
+ sb.append(getFileName()).append(" (");
+ sb.append(getStartLine());
+ sb.append(":");
+ sb.append(getStartColumn());
+ sb.append(") : ");
+ sb.append(getMessage());
return sb.toString();
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.jci.compilers;
import java.io.BufferedReader;
@@ -51,102 +52,83 @@
*/
public final class JaninoJavaCompiler extends AbstractJavaCompiler {
- // private final Log log = LogFactory.getLog(JaninoJavaCompiler.class);
-
private class CompilingIClassLoader extends IClassLoader {
- private final Map types = new HashMap();
+ private final Map types = new HashMap();
private final ResourceReader resourceReader;
- private final Map classes;
- private final Collection problems = new ArrayList();
+ private final Map classes;
+ private final Collection problems = new ArrayList();
- private CompilingIClassLoader(final ResourceReader pResourceReader,
- final Map pClasses,
- final ClassLoader classLoader) {
+ private CompilingIClassLoader(final ResourceReader pResourceReader, final Map pClasses, final ClassLoader classLoader) {
super( new ClassLoaderIClassLoader( classLoader ) );
- this.resourceReader = pResourceReader;
- this.classes = pClasses;
+ resourceReader = pResourceReader;
+ classes = pClasses;
super.postConstruct();
}
protected Collection getProblems() {
- return this.problems;
+ return problems;
}
-
+
protected IClass findIClass(final String pType) {
- final String className = Descriptor.toClassName( pType );
- if ( this.types.containsKey( pType ) ) {
- return (IClass) this.types.get( pType );
+ final String className = Descriptor.toClassName(pType);
+ if (types.containsKey(pType)) {
+ return (IClass) types.get(pType);
}
- final String resourceNameFromClass = className.replace( '.',
- '/' ) + ".java";
+
+ // FIXME: should not be tied to the extension
+ final String resourceNameFromClass = className.replace('.', '/') + ".java";
- final byte[] content = this.resourceReader.getBytes( resourceNameFromClass );
- if ( content == null ) {
+ final byte[] content = resourceReader.getBytes(resourceNameFromClass);
+ if (content == null) {
return null;
}
- final Reader reader = new BufferedReader( new StringReader( new String( content ) ) );
+ final Reader reader = new BufferedReader(new StringReader(new String(content)));
Scanner scanner = null;
try {
- scanner = new Scanner( resourceNameFromClass,
- reader );
- final Java.CompilationUnit unit = new Parser( scanner ).parseCompilationUnit();
- final UnitCompiler uc = new UnitCompiler( unit,
- this );
- uc.setCompileErrorHandler( new ErrorHandler() {
- public void handleError(final String pMessage,
- final Location pOptionalLocation) throws CompileException {
- final CompilationProblem problem = new JaninoCompilationProblem( pOptionalLocation,
- pMessage,
- true );
- if ( JaninoJavaCompiler.this.problemHandler != null ) {
- JaninoJavaCompiler.this.problemHandler.handle( problem );
+ scanner = new Scanner(resourceNameFromClass, reader);
+ final Java.CompilationUnit unit = new Parser(scanner).parseCompilationUnit();
+ final UnitCompiler uc = new UnitCompiler(unit, this);
+ uc.setCompileErrorHandler(new ErrorHandler() {
+ public void handleError(final String pMessage, final Location pOptionalLocation) throws CompileException {
+ final CompilationProblem problem = new JaninoCompilationProblem(pOptionalLocation, pMessage, true);
+ if (problemHandler != null) {
+ problemHandler.handle(problem);
}
- CompilingIClassLoader.this.problems.add( problem );
+ problems.add(problem);
}
- } );
- uc.setWarningHandler( new WarningHandler() {
- public void handleWarning(final String pHandle,
- final String pMessage,
- final Location pOptionalLocation) {
- final CompilationProblem problem = new JaninoCompilationProblem( pOptionalLocation,
- pMessage,
- false );
- if ( JaninoJavaCompiler.this.problemHandler != null ) {
- JaninoJavaCompiler.this.problemHandler.handle( problem );
+ });
+ uc.setWarningHandler(new WarningHandler() {
+ public void handleWarning(final String pHandle, final String pMessage, final Location pOptionalLocation) {
+ final CompilationProblem problem = new JaninoCompilationProblem(pOptionalLocation, pMessage, false);
+ if (problemHandler != null) {
+ problemHandler.handle(problem);
}
- CompilingIClassLoader.this.problems.add( problem );
+ problems.add(problem);
}
- } );
- // log.debug("compile " + className);
- final ClassFile[] classFiles = uc.compileUnit( DebuggingInformation.ALL );
- for ( int i = 0; i < classFiles.length; i++ ) {
- // log.debug("compiled " + classFiles[i].getThisClassName());
- this.classes.put( classFiles[i].getThisClassName(),
- classFiles[i].toByteArray() );
+ });
+
+ final ClassFile[] classFiles = uc.compileUnit(DebuggingInformation.ALL);
+ for (int i = 0; i < classFiles.length; i++) {
+ classes.put(classFiles[i].getThisClassName(), classFiles[i].toByteArray());
}
- final IClass ic = uc.findClass( className );
- if ( null != ic ) {
- this.types.put( pType,
- ic );
+ final IClass ic = uc.findClass(className);
+ if (null != ic) {
+ types.put(pType, ic);
}
return ic;
- } catch ( final LocatedException e ) {
- this.problems.add( new JaninoCompilationProblem( e ) );
- } catch ( final IOException e ) {
- this.problems.add( new JaninoCompilationProblem( resourceNameFromClass,
- "IOException:" + e.getMessage(),
- true ) );
- } catch ( final Exception e ) {
- this.problems.add( new JaninoCompilationProblem( resourceNameFromClass,
- "Exception:" + e.getMessage(),
- true ) );
+ } catch (final LocatedException e) {
+ problems.add(new JaninoCompilationProblem(e));
+ } catch (final IOException e) {
+ problems.add(new JaninoCompilationProblem(resourceNameFromClass, "IOException:" + e.getMessage(), true));
+ } catch (final Exception e) {
+ problems.add(new JaninoCompilationProblem(resourceNameFromClass, "Exception:" + e.getMessage(), true));
} finally {
- if ( scanner != null ) {
+ if (scanner != null) {
try {
scanner.close();
- } catch ( final IOException e ) {
- // log.error("IOException occured while compiling " + className, e);
+ } catch (IOException e) {
+ throw new RuntimeException( "IOException occured while compiling " + className, e );
}
}
}
@@ -154,35 +136,36 @@
}
}
- public CompilationResult compile(final String[] pClasses,
- final ResourceReader pResourceReader,
- final ResourceStore pStore,
- final ClassLoader classLoader) {
- final Map classFilesByName = new HashMap();
+ public CompilationResult compile( final String[] pSourceNames, final ResourceReader pResourceReader, final ResourceStore pStore, final ClassLoader pClassLoader, final JavaCompilerSettings pSettings ) {
- final CompilingIClassLoader icl = new CompilingIClassLoader( pResourceReader,
- classFilesByName,
- classLoader );
- for ( int i = 0; i < pClasses.length; i++ ) {
- try {
- icl.loadIClass( Descriptor.fromClassName( ClassUtils.convertResourceToClassName( pClasses[i] ) ) );
+ final Map classFilesByName = new HashMap();
+
+ final CompilingIClassLoader icl = new CompilingIClassLoader(pResourceReader, classFilesByName, pClassLoader);
+ for (int i = 0; i < pSourceNames.length; i++) {
+ try {
+ icl.loadIClass(Descriptor.fromClassName(ClassUtils.convertResourceToClassName(pSourceNames[i])));
} catch ( final ClassNotFoundException e ) {
// @TODO: if an exception is thrown here, how do we handle it?
e.printStackTrace();
- }
+ }
}
+
// Store all fully compiled classes
- for ( final Iterator i = classFilesByName.entrySet().iterator(); i.hasNext(); ) {
- final Map.Entry entry = (Map.Entry) i.next();
- final String clazzName = (String) entry.getKey();
- pStore.write( ClassUtils.convertClassToResourcePath( clazzName ),
- (byte[]) entry.getValue() );
+ for (Iterator i = classFilesByName.entrySet().iterator(); i.hasNext();) {
+ final Map.Entry entry = (Map.Entry)i.next();
+ final String clazzName = (String)entry.getKey();
+ pStore.write(ClassUtils.convertClassToResourcePath(clazzName), (byte[])entry.getValue());
}
-
+
final Collection problems = icl.getProblems();
final CompilationProblem[] result = new CompilationProblem[problems.size()];
- problems.toArray( result );
- return new CompilationResult( result );
+ problems.toArray(result);
+ return new CompilationResult(result);
}
+ public JavaCompilerSettings createDefaultSettings() {
+ // FIXME
+ return null;
+ }
+
}
Added: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompilerSettings.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompilerSettings.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompilerSettings.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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;
+
+public final class JaninoJavaCompilerSettings extends JavaCompilerSettings {
+ // TODO: implement the native janino compiler settings
+}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JavaCompiler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JavaCompiler.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JavaCompiler.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -14,13 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.jci.compilers;
import org.apache.commons.jci.problems.CompilationProblemHandler;
import org.apache.commons.jci.readers.ResourceReader;
import org.apache.commons.jci.stores.ResourceStore;
+
/**
+ * The general compiler interface. All compilers implementing
+ * this interface should read the resources from the reader
+ * and store the java class files into the ResourceStore.
+ *
+ * The actual compilation language does not matter. But the
+ * contract is that the result of the compilation will be a
+ * class file.
+ *
+ * If possible the compiler should notify the optional
+ * CompilationProblemHandler as soon as a problem is found.
+ *
* @author tcurdt
*/
public interface JavaCompiler {
@@ -33,9 +46,24 @@
*
* @param pHandler
*/
- void setCompilationProblemHandler(final CompilationProblemHandler pHandler);
+ void setCompilationProblemHandler( final CompilationProblemHandler pHandler );
/**
+ * factory method to create the underlying default settings
+ */
+ JavaCompilerSettings createDefaultSettings();
+
+ /**
+ * uses the default compiler settings and the current classloader
+ */
+ CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore );
+
+ /**
+ * uses the default compiler settings
+ */
+ CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader );
+
+ /**
* Compiles the java resources "some/path/to/MyJava.java"
* read through the ResourceReader and then stores the resulting
* classes in the ResourceStore under "some/path/to/MyJava.class".
@@ -50,18 +78,10 @@
* @param pResourcePaths
* @param pReader
* @param pStore
+ * @param pClassLoader
+ * @param pSettings
* @return always a CompilationResult
*/
- CompilationResult compile(final String[] pResourcePaths,
- final ResourceReader pReader,
- final ResourceStore pStore);
+ CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader, final JavaCompilerSettings pSettings );
- /**
- * As the usual compiler but you can provide the classloader
- * and therefor the classpath you are compiling with.
- */
- CompilationResult compile(final String[] pResourcePaths,
- final ResourceReader pReader,
- final ResourceStore pStore,
- final ClassLoader classLoader);
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.jci.compilers;
import java.util.HashMap;
@@ -21,22 +22,30 @@
import org.drools.util.ClassUtils;
+
+/**
+ * Creates JavaCompilers
+ *
+ * TODO use META-INF discovery mechanism
+ *
+ * @author tcurdt
+ */
public final class JavaCompilerFactory {
/**
- * @deprecated
+ * @deprecated will be remove after the next release, please create an instance yourself
*/
private static final JavaCompilerFactory INSTANCE = new JavaCompilerFactory();
+ private final Map classCache = new HashMap();
+
/**
- * @deprecated
+ * @deprecated will be remove after the next release, please create an instance yourself
*/
public static JavaCompilerFactory getInstance() {
return JavaCompilerFactory.INSTANCE;
}
- private final Map classCache = new HashMap();
-
/**
* Tries to guess the class name by convention. So for compilers
* following the naming convention
@@ -49,40 +58,36 @@
*
* @param pHint
* @return JavaCompiler or null
- *
- * TODO use META-INF discovery mechanism
*/
public JavaCompiler createCompiler(final String pHint) {
-
+
final String className;
- if ( pHint.indexOf( '.' ) < 0 ) {
- className = "org.apache.commons.jci.compilers." + ClassUtils.toJavaCasing( pHint ) + "JavaCompiler";
+ if (pHint.indexOf('.') < 0) {
+ className = "org.apache.commons.jci.compilers." + ClassUtils.toJavaCasing(pHint) + "JavaCompiler";
} else {
className = pHint;
}
-
- Class clazz = (Class) this.classCache.get( className );
-
- if ( clazz == null ) {
+
+ Class clazz = (Class) classCache.get(className);
+
+ if (clazz == null) {
try {
- clazz = Class.forName( className );
- this.classCache.put( className,
- clazz );
- } catch ( final ClassNotFoundException e ) {
+ clazz = Class.forName(className);
+ classCache.put(className, clazz);
+ } catch (ClassNotFoundException e) {
clazz = null;
}
}
- if ( clazz == null ) {
+ if (clazz == null) {
return null;
}
-
+
try {
return (JavaCompiler) clazz.newInstance();
- } catch ( final Throwable t ) {
- t.printStackTrace();
+ } catch (Throwable t) {
return null;
}
}
-
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -14,32 +14,80 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.jci.compilers;
+
+/**
+ * Most common denominator for JavaCompiler settings.
+ *
+ * If you need more specific settings you have to provide
+ * the native compiler configurations to the compilers.
+ * Writing of a custom factory is suggested.
+ *
+ * @author tcurdt
+ */
public class JavaCompilerSettings {
- public void setTargetVersion(final String pTargetVersion) {
+ private String targetVersion;
+ private String sourceVersion;
+ private String sourceEncoding;
+ private boolean warnings;
+ private boolean deprecations;
+ private boolean verbose;
+
+ public void setTargetVersion( final String pTargetVersion ) {
+ targetVersion = pTargetVersion;
}
- public void setSourceVersion(final String pSourceVersion) {
+ public String getTargetVersion() {
+ return targetVersion;
+ }
+
+ public void setSourceVersion( final String pSourceVersion ) {
+ sourceVersion = pSourceVersion;
}
- public void setSourceEncoding(final String pSourceEncoding) {
+ public String getSourceVersion() {
+ return sourceVersion;
+ }
+
+ public void setSourceEncoding( final String pSourceEncoding ) {
+ sourceEncoding = pSourceEncoding;
}
- public void setWarnings(final boolean pWarnings) {
+ public String getSourceEncoding() {
+ return sourceEncoding;
+ }
+
+ public void setWarnings( final boolean pWarnings ) {
+ warnings = pWarnings;
}
- public void setDeprecations(final boolean pDeprecations) {
+ public boolean isWarnings() {
+ return warnings;
+ }
+
+ public void setDeprecations( final boolean pDeprecations ) {
+ deprecations = pDeprecations;
}
- public void setVerbose(final boolean pVerbose) {
+ public boolean isDeprecations() {
+ return deprecations;
+ }
+
+ public void setVerbose( final boolean pVerbose ) {
+ verbose = pVerbose;
}
+ public boolean isVerbose() {
+ return verbose;
+ }
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/problems/CompilationProblem.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/problems/CompilationProblem.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/problems/CompilationProblem.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -14,22 +14,52 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.jci.problems;
+/**
+ * An abstract definition of a compilation problem
+ *
+ * @author tcurdt
+ */
public interface CompilationProblem {
+ /**
+ * is the problem an error and compilation cannot continue
+ * or just a warning and compilation can proceed
+ *
+ * @return
+ */
boolean isError();
+ /**
+ * name of the file where the problem occurred
+ *
+ * @return
+ */
String getFileName();
+ /**
+ * position of where the problem starts in the source code
+ *
+ * @return
+ */
int getStartLine();
-
int getStartColumn();
+ /**
+ * position of where the problem stops in the source code
+ *
+ * @return
+ */
int getEndLine();
-
int getEndColumn();
+ /**
+ * the description of the problem
+ *
+ * @return
+ */
String getMessage();
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/problems/CompilationProblemHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/problems/CompilationProblemHandler.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/problems/CompilationProblemHandler.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -14,8 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.jci.problems;
+
/**
* A CompilationProblemHandler gets access to a problem
* as soon as the problem is available while the
@@ -31,5 +33,7 @@
* @author tcurdt
*/
public interface CompilationProblemHandler {
- boolean handle(final CompilationProblem pProblem);
+
+ boolean handle( final CompilationProblem pProblem );
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/readers/MemoryResourceReader.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/readers/MemoryResourceReader.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/readers/MemoryResourceReader.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.readers;
import java.util.Map;
@@ -3,46 +20,48 @@
import java.util.HashMap;
-public class MemoryResourceReader
- implements
- ResourceReader {
-
+/**
+ * A memory based reader to compile from memory
+ *
+ * @author tcurdt
+ */
+public class MemoryResourceReader implements ResourceReader {
+
private Map resources;
- public boolean isAvailable(final String pResourceName) {
- if ( this.resources == null ) {
+ public boolean isAvailable( final String pResourceName ) {
+ if (resources == null) {
return false;
}
- return this.resources.containsKey( pResourceName );
+ return resources.containsKey(pResourceName);
}
-
- public void add(final String pResourceName,
- final byte[] pContent) {
- if ( this.resources == null ) {
- this.resources = new HashMap();
+
+ public void add( final String pResourceName, final byte[] pContent ) {
+ if (resources == null) {
+ resources = new HashMap();
}
-
- this.resources.put( pResourceName,
- pContent );
+
+ resources.put(pResourceName, pContent);
}
+
+ public void remove( final String pResourceName ) {
+ if (resources != null) {
+ resources.remove(pResourceName);
+ }
+ }
+
- public void remove(final String pResourceName) {
- if ( this.resources != null ) {
- this.resources.remove( pResourceName );
- }
+ public byte[] getBytes( final String pResourceName ) {
+ return (byte[]) resources.get(pResourceName);
}
- public byte[] getBytes(final String pResourceName) {
- return (byte[]) this.resources.get( pResourceName );
- }
-
/**
* @deprecated
*/
public String[] list() {
- if ( this.resources == null ) {
+ if (resources == null) {
return new String[0];
}
- return (String[]) this.resources.keySet().toArray( new String[this.resources.size()] );
+ return (String[]) resources.keySet().toArray(new String[resources.size()]);
}
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/readers/ResourceReader.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/readers/ResourceReader.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/readers/ResourceReader.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -14,13 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.jci.readers;
/**
+ * A ResourceReader provide acces to resource like e.g. source code
+ *
* @author tcurdt
*/
public interface ResourceReader {
- boolean isAvailable(final String pResourceName);
- byte[] getBytes(final String pResourceName);
+ boolean isAvailable( final String pResourceName );
+ byte[] getBytes( final String pResourceName );
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/stores/ResourceStore.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/stores/ResourceStore.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/apache/commons/jci/stores/ResourceStore.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -17,14 +17,13 @@
package org.apache.commons.jci.stores;
/**
+ * A Store is where the compilers are storing the results
+ *
* @author tcurdt
*/
public interface ResourceStore {
- void write(final String pResourceName,
- final byte[] pResourceData);
-
- byte[] read(final String pResourceName);
-
- void remove(final String pResourceName);
+ void write( final String pResourceName, final byte[] pResourceData );
+ byte[] read( final String pResourceName );
+ void remove( final String pResourceName );
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialect.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialect.java 2007-06-25 00:33:07 UTC (rev 12813)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialect.java 2007-06-25 02:14:32 UTC (rev 12814)
@@ -13,6 +13,7 @@
import org.apache.commons.jci.compilers.EclipseJavaCompilerSettings;
import org.apache.commons.jci.compilers.JavaCompiler;
import org.apache.commons.jci.compilers.JavaCompilerFactory;
+import org.apache.commons.jci.compilers.JavaCompilerSettings;
import org.apache.commons.jci.problems.CompilationProblem;
import org.apache.commons.jci.readers.MemoryResourceReader;
import org.apache.commons.jci.readers.ResourceReader;
@@ -487,19 +488,18 @@
}
case PackageBuilderConfiguration.ECLIPSE :
default : {
- final EclipseJavaCompilerSettings eclipseSettings = new EclipseJavaCompilerSettings();
- final Map map = eclipseSettings.getMap();
+ this.compiler = JavaCompilerFactory.getInstance().createCompiler( "eclipse" );
+ JavaCompilerSettings settings = this.compiler.createDefaultSettings();
+
String lngLevel = this.configuration.getJavaLanguageLevel();
- map.put( CompilerOptions.OPTION_TargetPlatform,
- lngLevel );
-
+ settings.setTargetVersion( lngLevel );
+
if ( lngLevel == "1.4" ) {
// 1.5 is the minimum for source langauge level, so we can use static imports.
lngLevel = "1.5";
}
- map.put( CompilerOptions.OPTION_Source,
- lngLevel );
- this.compiler = new EclipseJavaCompiler( map );
+
+ settings.setSourceVersion( lngLevel );
break;
}
}
More information about the jboss-svn-commits
mailing list