You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ni...@apache.org on 2007/04/25 16:57:24 UTC
svn commit: r532377 [2/3] - in /jakarta/commons/proper/jci/trunk:
compilers/eclipse/src/main/java/org/apache/commons/jci/compilers/
compilers/eclipse/src/test/java/org/apache/commons/jci/compilers/
compilers/groovy/src/main/java/org/apache/commons/jci/...
Modified: jakarta/commons/proper/jci/trunk/compilers/rhino/src/main/java/org/apache/commons/jci/compilers/RhinoJavaCompiler.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/compilers/rhino/src/main/java/org/apache/commons/jci/compilers/RhinoJavaCompiler.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/compilers/rhino/src/main/java/org/apache/commons/jci/compilers/RhinoJavaCompiler.java (original)
+++ jakarta/commons/proper/jci/trunk/compilers/rhino/src/main/java/org/apache/commons/jci/compilers/RhinoJavaCompiler.java Wed Apr 25 07:57:21 2007
@@ -54,7 +54,7 @@
public RhinoJavaCompiler() {
- defaultSettings = new RhinoJavaCompilerSettings();
+ defaultSettings = new RhinoJavaCompilerSettings();
}
/**
@@ -63,217 +63,217 @@
*/
private final class RhinoCompilingClassLoader extends ClassLoader {
- private final ScriptableObject scope;
- private final ResourceReader reader;
- private final ResourceStore store;
-
- private final Collection problems = new ArrayList();
-
- private final class ProblemCollector implements ErrorReporter {
-
- public void error(String pMessage, String pFileName, int pLine, String pScript, int pColumn) {
-
- final CompilationProblem problem = new RhinoCompilationProblem(pMessage, pFileName, pLine, pScript, pColumn, true);
-
- if (problemHandler != null) {
- problemHandler.handle(problem);
- }
-
- problems.add(problem);
- }
-
- public void warning(String pMessage, String pFileName, int pLine, String pScript, int pColumn) {
-
- final CompilationProblem problem = new RhinoCompilationProblem(pMessage, pFileName, pLine, pScript, pColumn, false);
-
- if (problemHandler != null) {
- problemHandler.handle(problem);
- }
-
- problems.add(problem);
- }
-
- public EvaluatorException runtimeError(String pMessage, String pFileName, int pLine, String pScript, int pColumn) {
- return new EvaluatorException(pMessage, pFileName, pLine, pScript, pColumn);
- }
- }
-
- public RhinoCompilingClassLoader( final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader) {
- super(pClassLoader);
-
- reader = pReader;
- store = pStore;
-
- final Context context = Context.enter();
- scope = new ImporterTopLevel(context);
- Context.exit();
- }
-
- public Collection getProblems() {
- return problems;
- }
-
- protected Class findClass( final String pName ) throws ClassNotFoundException {
- final Context context = Context.enter();
- context.setErrorReporter(new ProblemCollector());
-
- try {
- return compileClass(context, pName);
- } catch( EvaluatorException e ) {
- throw new ClassNotFoundException(e.getMessage(), e);
- } catch (IOException e) {
- throw new ClassNotFoundException(e.getMessage(), e);
- } finally {
- Context.exit();
- }
- }
-
-
- private Class compileClass( final Context pContext, final String pClassName) throws IOException, ClassNotFoundException {
-
- Class superclass = null;
-
- final String pSourceName = pClassName.replace('.', '/') + ".js";
-
- final Scriptable target = evaluate(pContext, pSourceName);
-
- final Object baseClassName = ScriptableObject.getProperty(target, "__extends__");
-
- if (baseClassName instanceof String) {
- superclass = Class.forName((String) baseClassName);
- }
-
- final ArrayList interfaceClasses = new ArrayList();
-
- final Object interfaceNames = ScriptableObject.getProperty(target, "__implements__");
-
- if (interfaceNames instanceof NativeArray) {
-
- final NativeArray interfaceNameArray = (NativeArray) interfaceNames;
-
- for (int i=0; i<interfaceNameArray.getLength(); i++) {
-
- final Object obj = interfaceNameArray.get(i, interfaceNameArray);
-
- if (obj instanceof String) {
- interfaceClasses.add(Class.forName((String) obj));
- }
- }
-
- } else if (interfaceNames instanceof String) {
-
- interfaceClasses.add(Class.forName((String) interfaceNames));
-
- }
-
- final Class[] interfaces;
-
- if (!interfaceClasses.isEmpty()) {
- interfaces = new Class[interfaceClasses.size()];
- interfaceClasses.toArray(interfaces);
- } else {
- // FIXME: hm ...really no empty array good enough?
- interfaces = null;
- }
-
- return compileClass(pContext, pSourceName, pClassName, superclass, interfaces);
-
- }
-
-
- private Class compileClass( final Context pContext, final String pSourceName, final String pClassName, final Class pSuperClass, final Class[] pInterfaces) throws IOException {
-
- final CompilerEnvirons environments = new CompilerEnvirons();
- environments.initFromContext(pContext);
- final ClassCompiler compiler = new ClassCompiler(environments);
-
- if (pSuperClass != null) {
- compiler.setTargetExtends(pSuperClass);
- }
-
- if (pInterfaces != null) {
- compiler.setTargetImplements(pInterfaces);
- }
-
- final byte[] sourceBytes = reader.getBytes(pSourceName);
-
- final Object[] classes = compiler.compileToClassFiles(new String(sourceBytes), getName(pSourceName), 1, pClassName);
-
- final GeneratedClassLoader loader = pContext.createClassLoader(pContext.getApplicationClassLoader());
-
- Class clazz = null;
-
- for (int i = 0; i < classes.length; i += 2) {
-
- final String clazzName = (String) classes[i];
- final byte[] clazzBytes = (byte[]) classes[i+1];
-
- store.write(clazzName.replace('.', '/') + ".class", clazzBytes);
-
- Class c = loader.defineClass(clazzName, clazzBytes);
- loader.linkClass(c);
-
- if (i == 0) {
- clazz = c;
- }
-
- }
-
- return clazz;
- }
-
- private String getName(String s) {
- final int i = s.lastIndexOf('/');
- if (i < 0) {
- return s;
- }
-
- return s.substring(i + 1);
- }
-
- private Scriptable evaluate( final Context pContext, final String pSourceName) throws JavaScriptException, IOException {
-
- if (!reader.isAvailable(pSourceName)) {
- throw new FileNotFoundException("File " + pSourceName + " not found");
- }
-
- final Scriptable target = pContext.newObject(scope);
-
- final byte[] sourceBytes = reader.getBytes(pSourceName);
-
- final Reader reader = new InputStreamReader(new ByteArrayInputStream(sourceBytes));
+ private final ScriptableObject scope;
+ private final ResourceReader reader;
+ private final ResourceStore store;
- pContext.evaluateReader(target, reader, getName(pSourceName), 1, null);
+ private final Collection problems = new ArrayList();
+
+ private final class ProblemCollector implements ErrorReporter {
- return target;
- }
+ public void error(String pMessage, String pFileName, int pLine, String pScript, int pColumn) {
+
+ final CompilationProblem problem = new RhinoCompilationProblem(pMessage, pFileName, pLine, pScript, pColumn, true);
+
+ if (problemHandler != null) {
+ problemHandler.handle(problem);
+ }
+
+ problems.add(problem);
+ }
+
+ public void warning(String pMessage, String pFileName, int pLine, String pScript, int pColumn) {
+
+ final CompilationProblem problem = new RhinoCompilationProblem(pMessage, pFileName, pLine, pScript, pColumn, false);
+
+ if (problemHandler != null) {
+ problemHandler.handle(problem);
+ }
+
+ problems.add(problem);
+ }
+
+ public EvaluatorException runtimeError(String pMessage, String pFileName, int pLine, String pScript, int pColumn) {
+ return new EvaluatorException(pMessage, pFileName, pLine, pScript, pColumn);
+ }
+ }
+
+ public RhinoCompilingClassLoader( final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader) {
+ super(pClassLoader);
+
+ reader = pReader;
+ store = pStore;
+
+ final Context context = Context.enter();
+ scope = new ImporterTopLevel(context);
+ Context.exit();
+ }
+
+ public Collection getProblems() {
+ return problems;
+ }
+
+ protected Class findClass( final String pName ) throws ClassNotFoundException {
+ final Context context = Context.enter();
+ context.setErrorReporter(new ProblemCollector());
+
+ try {
+ return compileClass(context, pName);
+ } catch( EvaluatorException e ) {
+ throw new ClassNotFoundException(e.getMessage(), e);
+ } catch (IOException e) {
+ throw new ClassNotFoundException(e.getMessage(), e);
+ } finally {
+ Context.exit();
+ }
+ }
+
+
+ private Class compileClass( final Context pContext, final String pClassName) throws IOException, ClassNotFoundException {
+
+ Class superclass = null;
+
+ final String pSourceName = pClassName.replace('.', '/') + ".js";
+
+ final Scriptable target = evaluate(pContext, pSourceName);
+
+ final Object baseClassName = ScriptableObject.getProperty(target, "__extends__");
+
+ if (baseClassName instanceof String) {
+ superclass = Class.forName((String) baseClassName);
+ }
+
+ final ArrayList interfaceClasses = new ArrayList();
+
+ final Object interfaceNames = ScriptableObject.getProperty(target, "__implements__");
+
+ if (interfaceNames instanceof NativeArray) {
+
+ final NativeArray interfaceNameArray = (NativeArray) interfaceNames;
+
+ for (int i=0; i<interfaceNameArray.getLength(); i++) {
+
+ final Object obj = interfaceNameArray.get(i, interfaceNameArray);
+
+ if (obj instanceof String) {
+ interfaceClasses.add(Class.forName((String) obj));
+ }
+ }
+
+ } else if (interfaceNames instanceof String) {
+
+ interfaceClasses.add(Class.forName((String) interfaceNames));
+
+ }
+
+ final Class[] interfaces;
+
+ if (!interfaceClasses.isEmpty()) {
+ interfaces = new Class[interfaceClasses.size()];
+ interfaceClasses.toArray(interfaces);
+ } else {
+ // FIXME: hm ...really no empty array good enough?
+ interfaces = null;
+ }
+
+ return compileClass(pContext, pSourceName, pClassName, superclass, interfaces);
+
+ }
+
+
+ private Class compileClass( final Context pContext, final String pSourceName, final String pClassName, final Class pSuperClass, final Class[] pInterfaces) throws IOException {
+
+ final CompilerEnvirons environments = new CompilerEnvirons();
+ environments.initFromContext(pContext);
+ final ClassCompiler compiler = new ClassCompiler(environments);
+
+ if (pSuperClass != null) {
+ compiler.setTargetExtends(pSuperClass);
+ }
+
+ if (pInterfaces != null) {
+ compiler.setTargetImplements(pInterfaces);
+ }
+
+ final byte[] sourceBytes = reader.getBytes(pSourceName);
+
+ final Object[] classes = compiler.compileToClassFiles(new String(sourceBytes), getName(pSourceName), 1, pClassName);
+
+ final GeneratedClassLoader loader = pContext.createClassLoader(pContext.getApplicationClassLoader());
+
+ Class clazz = null;
+
+ for (int i = 0; i < classes.length; i += 2) {
+
+ final String clazzName = (String) classes[i];
+ final byte[] clazzBytes = (byte[]) classes[i+1];
+
+ store.write(clazzName.replace('.', '/') + ".class", clazzBytes);
+
+ Class c = loader.defineClass(clazzName, clazzBytes);
+ loader.linkClass(c);
+
+ if (i == 0) {
+ clazz = c;
+ }
+
+ }
+
+ return clazz;
+ }
+
+ private String getName(String s) {
+ final int i = s.lastIndexOf('/');
+ if (i < 0) {
+ return s;
+ }
+
+ return s.substring(i + 1);
+ }
+
+ private Scriptable evaluate( final Context pContext, final String pSourceName) throws JavaScriptException, IOException {
+
+ if (!reader.isAvailable(pSourceName)) {
+ throw new FileNotFoundException("File " + pSourceName + " not found");
+ }
+
+ final Scriptable target = pContext.newObject(scope);
+
+ final byte[] sourceBytes = reader.getBytes(pSourceName);
+
+ final Reader reader = new InputStreamReader(new ByteArrayInputStream(sourceBytes));
+
+ pContext.evaluateReader(target, reader, getName(pSourceName), 1, null);
+
+ return target;
+ }
}
- public CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader, final JavaCompilerSettings pSettings ) {
+ public CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader, final JavaCompilerSettings pSettings ) {
+
+ final RhinoCompilingClassLoader cl = new RhinoCompilingClassLoader(pReader, pStore, pClassLoader);
- final RhinoCompilingClassLoader cl = new RhinoCompilingClassLoader(pReader, pStore, pClassLoader);
-
- for (int i = 0; i < pResourcePaths.length; i++) {
+ for (int i = 0; i < pResourcePaths.length; i++) {
log.debug("compiling " + pResourcePaths[i]);
final String clazzName = ConversionUtils.convertResourceToClassName(pResourcePaths[i]);
try {
- cl.loadClass(clazzName);
- } catch (ClassNotFoundException e) {
- }
- }
-
+ cl.loadClass(clazzName);
+ } catch (ClassNotFoundException e) {
+ }
+ }
+
final Collection problems = cl.getProblems();
final CompilationProblem[] result = new CompilationProblem[problems.size()];
problems.toArray(result);
return new CompilationResult(result);
- }
+ }
- public JavaCompilerSettings createDefaultSettings() {
- return defaultSettings;
- }
-
+ public JavaCompilerSettings createDefaultSettings() {
+ return defaultSettings;
+ }
+
}
Modified: jakarta/commons/proper/jci/trunk/compilers/rhino/src/test/java/org/apache/commons/jci/compilers/RhinoJavaCompilerTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/compilers/rhino/src/test/java/org/apache/commons/jci/compilers/RhinoJavaCompilerTestCase.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/compilers/rhino/src/test/java/org/apache/commons/jci/compilers/RhinoJavaCompilerTestCase.java (original)
+++ jakarta/commons/proper/jci/trunk/compilers/rhino/src/test/java/org/apache/commons/jci/compilers/RhinoJavaCompilerTestCase.java Wed Apr 25 07:57:21 2007
@@ -29,94 +29,94 @@
*/
public final class RhinoJavaCompilerTestCase extends AbstractCompilerTestCase {
- public JavaCompiler createJavaCompiler() {
- return new RhinoJavaCompiler();
- }
-
- public String getCompilerName() {
- return "rhino";
- }
-
- public void testSimpleCompile() throws Exception {
- final JavaCompiler compiler = createJavaCompiler();
-
- final ResourceReader reader = new ResourceReader() {
- final private Map sources = new HashMap() {
- private static final long serialVersionUID = 1L;
- {
- put("jci/Simple.js", (
- " var i = 0;\n" +
- "\n"
- ).getBytes());
- }};
-
- public byte[] getBytes( final String pResourceName ) {
- return (byte[]) sources.get(pResourceName);
- }
-
- public boolean isAvailable( final String pResourceName ) {
- return sources.containsKey(pResourceName);
- }
-
- };
-
- final MemoryResourceStore store = new MemoryResourceStore();
- final CompilationResult result = compiler.compile(
- new String[] {
- "jci/Simple.js"
- }, reader, store);
-
- assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
- assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
-
- final byte[] clazzBytes = store.read("jci/Simple.class");
- assertNotNull(clazzBytes);
- assertTrue(clazzBytes.length > 0);
- }
-
- public void testExtendedCompile() throws Exception {
- }
-
- public void testInternalClassCompile() throws Exception {
- }
-
- public void testUppercasePackageNameCompile() throws Exception {
- final JavaCompiler compiler = createJavaCompiler();
-
- final ResourceReader reader = new ResourceReader() {
- final private Map sources = new HashMap() {
- private static final long serialVersionUID = 1L;
- {
- put("Jci/Simple.js", (
- " var i = 0;\n" +
- "\n"
- ).getBytes());
- }};
-
- public byte[] getBytes( final String pResourceName ) {
- return (byte[]) sources.get(pResourceName);
- }
-
- public boolean isAvailable( final String pResourceName ) {
- return sources.containsKey(pResourceName);
- }
-
- };
-
- final MemoryResourceStore store = new MemoryResourceStore();
- final CompilationResult result = compiler.compile(
- new String[] {
- "Jci/Simple.js"
- }, reader, store);
-
- assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
- assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
-
- final byte[] clazzBytes = store.read("Jci/Simple.class");
- assertNotNull(clazzBytes);
- assertTrue(clazzBytes.length > 0);
- }
-
-
+ public JavaCompiler createJavaCompiler() {
+ return new RhinoJavaCompiler();
+ }
+
+ public String getCompilerName() {
+ return "rhino";
+ }
+
+ public void testSimpleCompile() throws Exception {
+ final JavaCompiler compiler = createJavaCompiler();
+
+ final ResourceReader reader = new ResourceReader() {
+ final private Map sources = new HashMap() {
+ private static final long serialVersionUID = 1L;
+ {
+ put("jci/Simple.js", (
+ " var i = 0;\n" +
+ "\n"
+ ).getBytes());
+ }};
+
+ public byte[] getBytes( final String pResourceName ) {
+ return (byte[]) sources.get(pResourceName);
+ }
+
+ public boolean isAvailable( final String pResourceName ) {
+ return sources.containsKey(pResourceName);
+ }
+
+ };
+
+ final MemoryResourceStore store = new MemoryResourceStore();
+ final CompilationResult result = compiler.compile(
+ new String[] {
+ "jci/Simple.js"
+ }, reader, store);
+
+ assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
+ assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
+
+ final byte[] clazzBytes = store.read("jci/Simple.class");
+ assertNotNull(clazzBytes);
+ assertTrue(clazzBytes.length > 0);
+ }
+
+ public void testExtendedCompile() throws Exception {
+ }
+
+ public void testInternalClassCompile() throws Exception {
+ }
+
+ public void testUppercasePackageNameCompile() throws Exception {
+ final JavaCompiler compiler = createJavaCompiler();
+
+ final ResourceReader reader = new ResourceReader() {
+ final private Map sources = new HashMap() {
+ private static final long serialVersionUID = 1L;
+ {
+ put("Jci/Simple.js", (
+ " var i = 0;\n" +
+ "\n"
+ ).getBytes());
+ }};
+
+ public byte[] getBytes( final String pResourceName ) {
+ return (byte[]) sources.get(pResourceName);
+ }
+
+ public boolean isAvailable( final String pResourceName ) {
+ return sources.containsKey(pResourceName);
+ }
+
+ };
+
+ final MemoryResourceStore store = new MemoryResourceStore();
+ final CompilationResult result = compiler.compile(
+ new String[] {
+ "Jci/Simple.js"
+ }, reader, store);
+
+ assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
+ assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
+
+ final byte[] clazzBytes = store.read("Jci/Simple.class");
+ assertNotNull(clazzBytes);
+ assertTrue(clazzBytes.length > 0);
+ }
+
+
}
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java Wed Apr 25 07:57:21 2007
@@ -30,25 +30,25 @@
*/
public abstract class AbstractJavaCompiler implements JavaCompiler {
- protected CompilationProblemHandler problemHandler;
+ protected CompilationProblemHandler problemHandler;
- public void setCompilationProblemHandler( final CompilationProblemHandler pHandler ) {
- 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();
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- if (classLoader == null) {
- classLoader = this.getClass().getClassLoader();
- }
+ if (classLoader == null) {
+ classLoader = this.getClass().getClassLoader();
+ }
- return compile(pClazzNames, pReader, pStore, classLoader, createDefaultSettings());
- }
+ 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());
- }
+ public CompilationResult compile( final String[] pClazzNames, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader ) {
+ return compile(pClazzNames, pReader, pStore, pClassLoader, createDefaultSettings());
+ }
}
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java Wed Apr 25 07:57:21 2007
@@ -35,19 +35,19 @@
private final CompilationProblem[] warnings;
public CompilationResult( final CompilationProblem[] pProblems ) {
- final Collection errorsColl = new ArrayList();
+ final Collection errorsColl = new ArrayList();
final Collection warningsColl = new ArrayList();
-
- for (int i = 0; i < pProblems.length; i++) {
- final CompilationProblem problem = pProblems[i];
+
+ for (int i = 0; i < pProblems.length; i++) {
+ final CompilationProblem problem = pProblems[i];
if (problem.isError()) {
errorsColl.add(problem);
} else {
warningsColl.add(problem);
- }
- }
+ }
+ }
- errors = new CompilationProblem[errorsColl.size()];
+ errors = new CompilationProblem[errorsColl.size()];
errorsColl.toArray(errors);
warnings = new CompilationProblem[warningsColl.size()];
@@ -59,6 +59,6 @@
}
public CompilationProblem[] getWarnings() {
- return warnings;
+ return warnings;
}
}
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompiler.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompiler.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompiler.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompiler.java Wed Apr 25 07:57:21 2007
@@ -38,14 +38,14 @@
*/
public interface JavaCompiler {
- /**
- * Set the the handler that gets the notification of an error
- * or warning as soon as this information is available from
- * the compiler.
- * Note: Some compilers might not support this feature.
- *
- * @param pHandler
- */
+ /**
+ * Set the the handler that gets the notification of an error
+ * or warning as soon as this information is available from
+ * the compiler.
+ * Note: Some compilers might not support this feature.
+ *
+ * @param pHandler
+ */
void setCompilationProblemHandler( final CompilationProblemHandler pHandler );
/**
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java Wed Apr 25 07:57:21 2007
@@ -35,7 +35,7 @@
/**
* @deprecated will be remove after the next release, please create an instance yourself
*/
- private static final JavaCompilerFactory INSTANCE = new JavaCompilerFactory();
+ private static final JavaCompilerFactory INSTANCE = new JavaCompilerFactory();
private final Map classCache = new HashMap();
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java Wed Apr 25 07:57:21 2007
@@ -28,66 +28,66 @@
* @author tcurdt
*/
public class JavaCompilerSettings {
-
- 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 String getTargetVersion() {
- return targetVersion;
- }
-
-
- public void setSourceVersion( final String pSourceVersion ) {
- sourceVersion = pSourceVersion;
- }
-
- public String getSourceVersion() {
- return sourceVersion;
- }
-
-
- public void setSourceEncoding( final String pSourceEncoding ) {
- sourceEncoding = pSourceEncoding;
- }
-
- public String getSourceEncoding() {
- return sourceEncoding;
- }
-
-
- public void setWarnings( final boolean pWarnings ) {
- warnings = pWarnings;
- }
-
- public boolean isWarnings() {
- return warnings;
- }
-
-
- public void setDeprecations( final boolean pDeprecations ) {
- deprecations = pDeprecations;
- }
-
- public boolean isDeprecations() {
- return deprecations;
- }
-
-
- public void setVerbose( final boolean pVerbose ) {
- verbose = pVerbose;
- }
-
- public boolean isVerbose() {
- return verbose;
- }
+
+ 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 String getTargetVersion() {
+ return targetVersion;
+ }
+
+
+ public void setSourceVersion( final String pSourceVersion ) {
+ sourceVersion = pSourceVersion;
+ }
+
+ public String getSourceVersion() {
+ return sourceVersion;
+ }
+
+
+ public void setSourceEncoding( final String pSourceEncoding ) {
+ sourceEncoding = pSourceEncoding;
+ }
+
+ public String getSourceEncoding() {
+ return sourceEncoding;
+ }
+
+
+ public void setWarnings( final boolean pWarnings ) {
+ warnings = pWarnings;
+ }
+
+ public boolean isWarnings() {
+ return warnings;
+ }
+
+
+ public void setDeprecations( final boolean pDeprecations ) {
+ deprecations = pDeprecations;
+ }
+
+ public boolean isDeprecations() {
+ return deprecations;
+ }
+
+
+ public void setVerbose( final boolean pVerbose ) {
+ verbose = pVerbose;
+ }
+
+ public boolean isVerbose() {
+ return verbose;
+ }
}
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java Wed Apr 25 07:57:21 2007
@@ -60,26 +60,26 @@
}
public CompilingListener( final JavaCompiler pCompiler, final TransactionalResourceStore pTransactionalStore ) {
- super(pTransactionalStore);
+ super(pTransactionalStore);
compiler = pCompiler;
transactionalStore = pTransactionalStore;
lastResult = null;
}
public JavaCompiler getCompiler() {
- return compiler;
+ return compiler;
}
public String getSourceFileExtension() {
- return ".java";
+ return ".java";
}
public ResourceReader getReader( final FilesystemAlterationObserver pObserver ) {
- return new FileResourceReader(pObserver.getRootDirectory());
+ return new FileResourceReader(pObserver.getRootDirectory());
}
public String getSourceNameFromFile( final FilesystemAlterationObserver pObserver, final File pFile ) {
- return ConversionUtils.stripExtension(ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(), pFile))) + getSourceFileExtension();
+ return ConversionUtils.stripExtension(ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(), pFile))) + getSourceFileExtension();
}
public ResourceStore getStore() {
@@ -107,25 +107,25 @@
for (final Iterator it = created.iterator(); it.hasNext();) {
final File createdFile = (File) it.next();
if (createdFile.getName().endsWith(getSourceFileExtension())) {
- resourceNames.add(getSourceNameFromFile(pObserver, createdFile));
+ resourceNames.add(getSourceNameFromFile(pObserver, createdFile));
}
}
for (final Iterator it = changed.iterator(); it.hasNext();) {
final File changedFile = (File) it.next();
if (changedFile.getName().endsWith(getSourceFileExtension())) {
- resourceNames.add(getSourceNameFromFile(pObserver, changedFile));
+ resourceNames.add(getSourceNameFromFile(pObserver, changedFile));
}
}
-
+
final String[] result = new String[resourceNames.size()];
resourceNames.toArray(result);
return result;
}
public boolean isReloadRequired( final FilesystemAlterationObserver pObserver ) {
- boolean reload = false;
-
+ boolean reload = false;
+
final Collection created = getCreatedFiles();
final Collection changed = getChangedFiles();
final Collection deleted = getDeletedFiles();
@@ -139,11 +139,11 @@
final String resourceName = ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(), deletedFile));
if (resourceName.endsWith(getSourceFileExtension())) {
- // if source resource got removed delete the corresponding class
+ // if source resource got removed delete the corresponding class
transactionalStore.remove(ConversionUtils.stripExtension(resourceName) + ".class");
} else {
- // ordinary resource to be removed
- transactionalStore.remove(resourceName);
+ // ordinary resource to be removed
+ transactionalStore.remove(resourceName);
}
// FIXME: does not remove nested classes
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/FileChangeListener.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/FileChangeListener.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/FileChangeListener.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/FileChangeListener.java Wed Apr 25 07:57:21 2007
@@ -31,16 +31,16 @@
private boolean changed;
public boolean hasChanged() {
- return changed;
+ return changed;
}
public void onStart( final FilesystemAlterationObserver pObserver ) {
changed = false;
- super.onStart(pObserver);
+ super.onStart(pObserver);
}
public void onStop( final FilesystemAlterationObserver pObserver ) {
- super.onStop(pObserver);
+ super.onStop(pObserver);
}
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadNotificationListener.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadNotificationListener.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadNotificationListener.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadNotificationListener.java Wed Apr 25 07:57:21 2007
@@ -24,6 +24,6 @@
*/
public interface ReloadNotificationListener {
- void handleNotification();
+ void handleNotification();
}
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadingListener.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadingListener.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadingListener.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadingListener.java Wed Apr 25 07:57:21 2007
@@ -60,17 +60,17 @@
}
public void addReloadNotificationListener( final ReloadNotificationListener pNotificationListener ) {
- notificationListeners.add(pNotificationListener);
-
- if (pNotificationListener instanceof ReloadingClassLoader) {
- ((ReloadingClassLoader)pNotificationListener).addResourceStore(store);
- }
-
+ notificationListeners.add(pNotificationListener);
+
+ if (pNotificationListener instanceof ReloadingClassLoader) {
+ ((ReloadingClassLoader)pNotificationListener).addResourceStore(store);
+ }
+
}
public boolean isReloadRequired( final FilesystemAlterationObserver pObserver ) {
- boolean reload = false;
-
+ boolean reload = false;
+
final Collection created = getCreatedFiles();
final Collection changed = getChangedFiles();
final Collection deleted = getDeletedFiles();
@@ -91,14 +91,14 @@
final File file = (File) it.next();
FileInputStream is = null;
try {
- is = new FileInputStream(file);
+ is = new FileInputStream(file);
final byte[] bytes = IOUtils.toByteArray(is);
final String resourceName = ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(), file));
store.write(resourceName, bytes);
} catch(final Exception e) {
log.error("could not load " + file, e);
} finally {
- IOUtils.closeQuietly(is);
+ IOUtils.closeQuietly(is);
}
}
}
@@ -108,19 +108,19 @@
final File file = (File) it.next();
FileInputStream is = null;
try {
- is = new FileInputStream(file);
+ is = new FileInputStream(file);
final byte[] bytes = IOUtils.toByteArray(is);
final String resourceName = ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(), file));
store.write(resourceName, bytes);
} catch(final Exception e) {
log.error("could not load " + file, e);
} finally {
- IOUtils.closeQuietly(is);
+ IOUtils.closeQuietly(is);
}
}
reload = true;
}
-
+
return reload;
}
@@ -138,7 +138,7 @@
}
if (reload) {
- notifyReloadNotificationListeners();
+ notifyReloadNotificationListeners();
}
super.onStop(pObserver);
@@ -146,13 +146,13 @@
void notifyReloadNotificationListeners() {
- for (Iterator it = notificationListeners.iterator(); it.hasNext();) {
- final ReloadNotificationListener listener = (ReloadNotificationListener) it.next();
+ for (Iterator it = notificationListeners.iterator(); it.hasNext();) {
+ final ReloadNotificationListener listener = (ReloadNotificationListener) it.next();
log.debug("notifying listener " + listener);
- listener.handleNotification();
- }
+ listener.handleNotification();
+ }
}
public void onDirectoryCreate( final File pDir ) {
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/CompilationProblem.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/CompilationProblem.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/CompilationProblem.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/CompilationProblem.java Wed Apr 25 07:57:21 2007
@@ -24,42 +24,42 @@
*/
public interface CompilationProblem {
- /**
- * is the problem an error and compilation cannot continue
- * or just a warning and compilation can proceed
- *
- * @return
- */
- boolean isError();
+ /**
+ * 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();
+ /**
+ * 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 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();
+ /**
+ * position of where the problem stops in the source code
+ *
+ * @return
+ */
+ int getEndLine();
+ int getEndColumn();
- /**
- * the description of the problem
- *
- * @return
- */
- String getMessage();
+ /**
+ * the description of the problem
+ *
+ * @return
+ */
+ String getMessage();
}
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/CompilationProblemHandler.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/CompilationProblemHandler.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/CompilationProblemHandler.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/CompilationProblemHandler.java Wed Apr 25 07:57:21 2007
@@ -34,6 +34,6 @@
*/
public interface CompilationProblemHandler {
- boolean handle( final CompilationProblem pProblem );
+ boolean handle( final CompilationProblem pProblem );
}
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/ResourceReader.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/ResourceReader.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/ResourceReader.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/ResourceReader.java Wed Apr 25 07:57:21 2007
@@ -24,7 +24,7 @@
*/
public interface ResourceReader {
- boolean isAvailable( final String pResourceName );
+ boolean isAvailable( final String pResourceName );
byte[] getBytes( final String pResourceName );
}
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/FileResourceStore.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/FileResourceStore.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/FileResourceStore.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/FileResourceStore.java Wed Apr 25 07:57:21 2007
@@ -49,9 +49,9 @@
final byte[] data = IOUtils.toByteArray(is);
return data;
} catch (Exception e) {
- return null;
+ return null;
} finally {
- IOUtils.closeQuietly(is);
+ IOUtils.closeQuietly(is);
}
}
@@ -68,9 +68,9 @@
os = new FileOutputStream(file);
os.write(pData);
} catch (Exception e) {
- // FIXME: now what?
+ // FIXME: now what?
} finally {
- IOUtils.closeQuietly(os);
+ IOUtils.closeQuietly(os);
}
}
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/MemoryResourceStore.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/MemoryResourceStore.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/MemoryResourceStore.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/MemoryResourceStore.java Wed Apr 25 07:57:21 2007
@@ -35,18 +35,18 @@
private final Log log = LogFactory.getLog(MemoryResourceStore.class);
- private final Map store = new HashMap();
-
- public byte[] read( final String pResourceName ) {
- log.debug("reading resource " + pResourceName);
- return (byte[]) store.get(pResourceName);
- }
+ private final Map store = new HashMap();
+
+ public byte[] read( final String pResourceName ) {
+ log.debug("reading resource " + pResourceName);
+ return (byte[]) store.get(pResourceName);
+ }
+
+ public void write( final String pResourceName, final byte[] pData ) {
+ log.debug("writing resource " + pResourceName + "(" + pData.length + ")");
+ store.put(pResourceName, pData);
+ }
- public void write( final String pResourceName, final byte[] pData ) {
- log.debug("writing resource " + pResourceName + "(" + pData.length + ")");
- store.put(pResourceName, pData);
- }
-
public void remove( final String pResourceName ) {
log.debug("removing resource " + pResourceName);
store.remove(pResourceName);
Modified: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/ResourceStore.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/ResourceStore.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/ResourceStore.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/ResourceStore.java Wed Apr 25 07:57:21 2007
@@ -23,7 +23,7 @@
*/
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: jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/ConversionUtils.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/ConversionUtils.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/ConversionUtils.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/ConversionUtils.java Wed Apr 25 07:57:21 2007
@@ -26,69 +26,69 @@
*/
public final class ConversionUtils {
- /**
- * Please do not use - internal
- * org/my/Class.xxx -> org.my.Class
- */
- public static String convertResourceToClassName( final String pResourceName ) {
- return ConversionUtils.stripExtension(pResourceName).replace('/', '.');
- }
-
- /**
- * Please do not use - internal
- * org.my.Class -> org/my/Class.class
- */
- public static String convertClassToResourcePath( final String pName ) {
- return pName.replace('.', '/') + ".class";
- }
-
- /**
- * Please do not use - internal
- * org/my/Class.xxx -> org/my/Class
- */
- public static String stripExtension( final String pResourceName ) {
- final int i = pResourceName.lastIndexOf('.');
- if (i < 0) {
- return pResourceName;
- }
- final String withoutExtension = pResourceName.substring(0, i);
- return withoutExtension;
- }
-
- public static String toJavaCasing(final String pName) {
- final char[] name = pName.toLowerCase().toCharArray();
- name[0] = Character.toUpperCase(name[0]);
- return new String(name);
- }
-
- public static String clazzName( final File base, final File file ) {
- final int rootLength = base.getAbsolutePath().length();
- final String absFileName = file.getAbsolutePath();
- final int p = absFileName.lastIndexOf('.');
- final String relFileName = absFileName.substring(rootLength + 1, p);
- final String clazzName = relFileName.replace(File.separatorChar, '.');
- return clazzName;
- }
-
- public static String relative( final File base, final File file ) {
- final int rootLength = base.getAbsolutePath().length();
- final String absFileName = file.getAbsolutePath();
- final String relFileName = absFileName.substring(rootLength + 1);
- return relFileName;
- }
-
- /**
- * a/b/c.java -> a/b/c.java
- * a\b\c.java -> a/b/c.java
- * @param pFileName
- * @return
- */
+ /**
+ * Please do not use - internal
+ * org/my/Class.xxx -> org.my.Class
+ */
+ public static String convertResourceToClassName( final String pResourceName ) {
+ return ConversionUtils.stripExtension(pResourceName).replace('/', '.');
+ }
+
+ /**
+ * Please do not use - internal
+ * org.my.Class -> org/my/Class.class
+ */
+ public static String convertClassToResourcePath( final String pName ) {
+ return pName.replace('.', '/') + ".class";
+ }
+
+ /**
+ * Please do not use - internal
+ * org/my/Class.xxx -> org/my/Class
+ */
+ public static String stripExtension( final String pResourceName ) {
+ final int i = pResourceName.lastIndexOf('.');
+ if (i < 0) {
+ return pResourceName;
+ }
+ final String withoutExtension = pResourceName.substring(0, i);
+ return withoutExtension;
+ }
+
+ public static String toJavaCasing(final String pName) {
+ final char[] name = pName.toLowerCase().toCharArray();
+ name[0] = Character.toUpperCase(name[0]);
+ return new String(name);
+ }
+
+ public static String clazzName( final File base, final File file ) {
+ final int rootLength = base.getAbsolutePath().length();
+ final String absFileName = file.getAbsolutePath();
+ final int p = absFileName.lastIndexOf('.');
+ final String relFileName = absFileName.substring(rootLength + 1, p);
+ final String clazzName = relFileName.replace(File.separatorChar, '.');
+ return clazzName;
+ }
+
+ public static String relative( final File base, final File file ) {
+ final int rootLength = base.getAbsolutePath().length();
+ final String absFileName = file.getAbsolutePath();
+ final String relFileName = absFileName.substring(rootLength + 1);
+ return relFileName;
+ }
+
+ /**
+ * a/b/c.java -> a/b/c.java
+ * a\b\c.java -> a/b/c.java
+ * @param pFileName
+ * @return
+ */
public static String getResourceNameFromFileName( final String pFileName ) {
- if ('/' == File.separatorChar) {
- return pFileName;
- }
-
- return pFileName.replace(File.separatorChar, '/');
+ if ('/' == File.separatorChar) {
+ return pFileName;
+ }
+
+ return pFileName.replace(File.separatorChar, '/');
}
-
+
}
Modified: jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/AbstractTestCase.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/AbstractTestCase.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/AbstractTestCase.java Wed Apr 25 07:57:21 2007
@@ -37,9 +37,9 @@
protected File directory;
protected void setUp() throws Exception {
-
- System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
-
+
+ System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
+
directory = createTempDirectory();
assertTrue(directory.exists());
assertTrue(directory.isDirectory());
@@ -95,7 +95,7 @@
}
protected void delay() {
- try {
+ try {
Thread.sleep(1500);
} catch (final InterruptedException e) {
}
Modified: jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/CompilingClassLoaderTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/CompilingClassLoaderTestCase.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/CompilingClassLoaderTestCase.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/CompilingClassLoaderTestCase.java Wed Apr 25 07:57:21 2007
@@ -41,7 +41,7 @@
*/
public final class CompilingClassLoaderTestCase extends AbstractTestCase {
- private final Log log = LogFactory.getLog(CompilingClassLoaderTestCase.class);
+ private final Log log = LogFactory.getLog(CompilingClassLoaderTestCase.class);
private ReloadingClassLoader classloader;
private CompilingListener listener;
@@ -51,59 +51,59 @@
private final Log log = LogFactory.getLog(MockJavaCompiler.class);
- public CompilationResult compile(String[] pResourcePaths, ResourceReader pReader, ResourceStore pStore, ClassLoader pClassLoader, JavaCompilerSettings pSettings ) {
-
- for (int i = 0; i < pResourcePaths.length; i++) {
- final String resourcePath = pResourcePaths[i];
- final byte[] resourceContent = pReader.getBytes(resourcePath);
-
- log.debug("resource " + resourcePath + " = " + ((resourceContent!=null)?new String(resourceContent):null) );
-
- final byte[] data;
-
- if ("jci/Simple.java".equals(resourcePath)) {
-
- try {
- data = SimpleDump.dump(new String(resourceContent));
- } catch (Exception e) {
- throw new RuntimeException("cannot handle resource " + resourcePath, e);
- }
-
- } else if ("jci/Extended.java".equals(resourcePath)) {
-
- try {
- data = ExtendedDump.dump();
- } catch (Exception e) {
- throw new RuntimeException("cannot handle resource " + resourcePath, e);
- }
-
- } else {
- throw new RuntimeException("cannot handle resource " + resourcePath);
- }
-
- log.debug("compiling " + resourcePath + " (" + data.length + ")");
-
- pStore.write(ConversionUtils.stripExtension(resourcePath) + ".class", data);
-
- }
-
- return new CompilationResult(new CompilationProblem[0]);
- }
-
- public CompilationResult compile(String[] pResourcePaths, ResourceReader pReader, ResourceStore pStore, ClassLoader pClassLoader) {
- return compile(pResourcePaths, pReader, pStore, pClassLoader, null);
- }
-
- public CompilationResult compile(String[] pResourcePaths, ResourceReader pReader, ResourceStore pStore) {
- return compile(pResourcePaths, pReader, pStore, null);
- }
-
- public void setCompilationProblemHandler(CompilationProblemHandler pHandler) {
- }
-
- public JavaCompilerSettings createDefaultSettings() {
- return null;
- }
+ public CompilationResult compile(String[] pResourcePaths, ResourceReader pReader, ResourceStore pStore, ClassLoader pClassLoader, JavaCompilerSettings pSettings ) {
+
+ for (int i = 0; i < pResourcePaths.length; i++) {
+ final String resourcePath = pResourcePaths[i];
+ final byte[] resourceContent = pReader.getBytes(resourcePath);
+
+ log.debug("resource " + resourcePath + " = " + ((resourceContent!=null)?new String(resourceContent):null) );
+
+ final byte[] data;
+
+ if ("jci/Simple.java".equals(resourcePath)) {
+
+ try {
+ data = SimpleDump.dump(new String(resourceContent));
+ } catch (Exception e) {
+ throw new RuntimeException("cannot handle resource " + resourcePath, e);
+ }
+
+ } else if ("jci/Extended.java".equals(resourcePath)) {
+
+ try {
+ data = ExtendedDump.dump();
+ } catch (Exception e) {
+ throw new RuntimeException("cannot handle resource " + resourcePath, e);
+ }
+
+ } else {
+ throw new RuntimeException("cannot handle resource " + resourcePath);
+ }
+
+ log.debug("compiling " + resourcePath + " (" + data.length + ")");
+
+ pStore.write(ConversionUtils.stripExtension(resourcePath) + ".class", data);
+
+ }
+
+ return new CompilationResult(new CompilationProblem[0]);
+ }
+
+ public CompilationResult compile(String[] pResourcePaths, ResourceReader pReader, ResourceStore pStore, ClassLoader pClassLoader) {
+ return compile(pResourcePaths, pReader, pStore, pClassLoader, null);
+ }
+
+ public CompilationResult compile(String[] pResourcePaths, ResourceReader pReader, ResourceStore pStore) {
+ return compile(pResourcePaths, pReader, pStore, null);
+ }
+
+ public void setCompilationProblemHandler(CompilationProblemHandler pHandler) {
+ }
+
+ public JavaCompilerSettings createDefaultSettings() {
+ return null;
+ }
}
Modified: jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/classes/ExtendedDump.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/classes/ExtendedDump.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/classes/ExtendedDump.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/classes/ExtendedDump.java Wed Apr 25 07:57:21 2007
@@ -25,53 +25,53 @@
public class ExtendedDump implements Opcodes {
- public static byte[] dump() throws Exception {
+ public static byte[] dump() throws Exception {
- ClassWriter cw = new ClassWriter(true);
- MethodVisitor mv;
+ ClassWriter cw = new ClassWriter(true);
+ MethodVisitor mv;
- cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, "jci/Extended", null, "jci/Simple", null);
+ cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, "jci/Extended", null, "jci/Simple", null);
- cw.visitSource("Extended.java", null);
+ cw.visitSource("Extended.java", null);
- {
- mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
- mv.visitCode();
- Label l0 = new Label();
- mv.visitLabel(l0);
- mv.visitLineNumber(3, l0);
- mv.visitVarInsn(ALOAD, 0);
- mv.visitMethodInsn(INVOKESPECIAL, "jci/Simple", "<init>", "()V");
- mv.visitInsn(RETURN);
- Label l1 = new Label();
- mv.visitLabel(l1);
- mv.visitLocalVariable("this", "Ljci/Extended;", null, l0, l1, 0);
- mv.visitMaxs(1, 1);
- mv.visitEnd();
- }
- {
- mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
- mv.visitCode();
- Label l0 = new Label();
- mv.visitLabel(l0);
- mv.visitLineNumber(6, l0);
- mv.visitTypeInsn(NEW, "java/lang/StringBuffer");
- mv.visitInsn(DUP);
- mv.visitLdcInsn("Extended:");
- mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuffer", "<init>", "(Ljava/lang/String;)V");
- mv.visitVarInsn(ALOAD, 0);
- mv.visitMethodInsn(INVOKESPECIAL, "jci/Simple", "toString", "()Ljava/lang/String;");
- mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer", "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
- mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer", "toString", "()Ljava/lang/String;");
- mv.visitInsn(ARETURN);
- Label l1 = new Label();
- mv.visitLabel(l1);
- mv.visitLocalVariable("this", "Ljci/Extended;", null, l0, l1, 0);
- mv.visitMaxs(3, 1);
- mv.visitEnd();
- }
- cw.visitEnd();
+ {
+ mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitLineNumber(3, l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, "jci/Simple", "<init>", "()V");
+ mv.visitInsn(RETURN);
+ Label l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLocalVariable("this", "Ljci/Extended;", null, l0, l1, 0);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ {
+ mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitLineNumber(6, l0);
+ mv.visitTypeInsn(NEW, "java/lang/StringBuffer");
+ mv.visitInsn(DUP);
+ mv.visitLdcInsn("Extended:");
+ mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuffer", "<init>", "(Ljava/lang/String;)V");
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, "jci/Simple", "toString", "()Ljava/lang/String;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer", "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer", "toString", "()Ljava/lang/String;");
+ mv.visitInsn(ARETURN);
+ Label l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLocalVariable("this", "Ljci/Extended;", null, l0, l1, 0);
+ mv.visitMaxs(3, 1);
+ mv.visitEnd();
+ }
+ cw.visitEnd();
- return cw.toByteArray();
- }
+ return cw.toByteArray();
+ }
}
Modified: jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/classes/SimpleDump.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/classes/SimpleDump.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/classes/SimpleDump.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/classes/SimpleDump.java Wed Apr 25 07:57:21 2007
@@ -24,46 +24,46 @@
public class SimpleDump implements Opcodes {
- public static byte[] dump( final String to ) throws Exception {
+ public static byte[] dump( final String to ) throws Exception {
- ClassWriter cw = new ClassWriter(true);
- MethodVisitor mv;
+ ClassWriter cw = new ClassWriter(true);
+ MethodVisitor mv;
- cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, "jci/Simple", null, "java/lang/Object", null);
+ cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, "jci/Simple", null, "java/lang/Object", null);
- cw.visitSource("Simple.java", null);
+ cw.visitSource("Simple.java", null);
- {
- mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
- mv.visitCode();
- Label l0 = new Label();
- mv.visitLabel(l0);
- mv.visitLineNumber(3, l0);
- mv.visitVarInsn(ALOAD, 0);
- mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
- mv.visitInsn(RETURN);
- Label l1 = new Label();
- mv.visitLabel(l1);
- mv.visitLocalVariable("this", "Ljci/Simple;", null, l0, l1, 0);
- mv.visitMaxs(1, 1);
- mv.visitEnd();
- }
- {
- mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
- mv.visitCode();
- Label l0 = new Label();
- mv.visitLabel(l0);
- mv.visitLineNumber(6, l0);
- mv.visitLdcInsn(to);
- mv.visitInsn(ARETURN);
- Label l1 = new Label();
- mv.visitLabel(l1);
- mv.visitLocalVariable("this", "Ljci/Simple;", null, l0, l1, 0);
- mv.visitMaxs(1, 1);
- mv.visitEnd();
- }
- cw.visitEnd();
+ {
+ mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitLineNumber(3, l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
+ mv.visitInsn(RETURN);
+ Label l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLocalVariable("this", "Ljci/Simple;", null, l0, l1, 0);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ {
+ mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitLineNumber(6, l0);
+ mv.visitLdcInsn(to);
+ mv.visitInsn(ARETURN);
+ Label l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLocalVariable("this", "Ljci/Simple;", null, l0, l1, 0);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ cw.visitEnd();
- return cw.toByteArray();
- }
+ return cw.toByteArray();
+ }
}
Modified: jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java Wed Apr 25 07:57:21 2007
@@ -33,209 +33,209 @@
*/
public abstract class AbstractCompilerTestCase extends TestCase {
- public abstract JavaCompiler createJavaCompiler();
-
- public abstract String getCompilerName();
-
- public void testFactoryCreation() {
- final JavaCompiler factoryCompiler = new JavaCompilerFactory().createCompiler(getCompilerName());
- assertNotNull(factoryCompiler);
-
- final JavaCompiler compiler = createJavaCompiler();
- assertEquals(factoryCompiler.getClass().getName(), compiler.getClass().getName());
- }
-
- public void testSimpleCompile() throws Exception {
- final JavaCompiler compiler = createJavaCompiler();
-
- final ResourceReader reader = new ResourceReader() {
- final private Map sources = new HashMap() {
- private static final long serialVersionUID = 1L;
- {
- put("jci/Simple.java", (
- "package jci;\n" +
- "public class Simple {\n" +
- " public String toString() {\n" +
- " return \"Simple\";\n" +
- " }\n" +
- "}").getBytes());
- }};
-
- public byte[] getBytes( final String pResourceName ) {
- return (byte[]) sources.get(pResourceName);
- }
-
- public boolean isAvailable( final String pResourceName ) {
- return sources.containsKey(pResourceName);
- }
-
- };
-
- final MemoryResourceStore store = new MemoryResourceStore();
- final CompilationResult result = compiler.compile(
- new String[] {
- "jci/Simple.java"
- }, reader, store);
-
- assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
- assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
-
- final byte[] clazzBytes = store.read("jci/Simple.class");
- assertNotNull(clazzBytes);
- assertTrue(clazzBytes.length > 0);
- }
-
- public void testExtendedCompile() throws Exception {
- final JavaCompiler compiler = createJavaCompiler();
-
- final ResourceReader reader = new ResourceReader() {
- final private Map sources = new HashMap() {
- private static final long serialVersionUID = 1L;
- {
- put("jci/Simple.java", (
- "package jci;\n" +
- "public class Simple {\n" +
- " public String toString() {\n" +
- " return \"Simple\";\n" +
- " }\n" +
- "}").getBytes());
- put("jci/Extended.java", (
- "package jci;\n" +
- "public class Extended extends Simple {\n" +
- " public String toString() {\n" +
- " return \"Extended\" + super.toString();\n" +
- " }\n" +
- "}").getBytes());
- }};
-
- public byte[] getBytes( final String pResourceName ) {
- return (byte[]) sources.get(pResourceName);
- }
-
- public boolean isAvailable( final String pResourceName ) {
- return sources.containsKey(pResourceName);
- }
-
- };
-
- final MemoryResourceStore store = new MemoryResourceStore();
- final CompilationResult result = compiler.compile(
- new String[] {
- "jci/Extended.java",
- "jci/Simple.java"
- }, reader, store);
-
- assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
- assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
-
- final byte[] clazzBytesSimple = store.read("jci/Simple.class");
- assertNotNull(clazzBytesSimple);
- assertTrue(clazzBytesSimple.length > 0);
-
- final byte[] clazzBytesExtended = store.read("jci/Extended.class");
- assertNotNull(clazzBytesExtended);
- assertTrue(clazzBytesExtended.length > 0);
- }
-
- public void testInternalClassCompile() throws Exception {
- final JavaCompiler compiler = createJavaCompiler();
-
- final ResourceReader reader = new ResourceReader() {
- final private Map sources = new HashMap() {
- private static final long serialVersionUID = 1L;
- {
- put("jci/Simple.java", (
- "package jci;\n" +
- "public class Simple {\n" +
- " private class Sub {\n" +
- " }\n" +
- " public String toString() {\n" +
- " new Sub();\n" +
- " return \"Simple\";\n" +
- " }\n" +
- "}").getBytes());
- }};
-
- public byte[] getBytes( final String pResourceName ) {
- return (byte[]) sources.get(pResourceName);
- }
-
- public boolean isAvailable( final String pResourceName ) {
- return sources.containsKey(pResourceName);
- }
-
- };
-
- final MemoryResourceStore store = new MemoryResourceStore();
- final CompilationResult result = compiler.compile(
- new String[] {
- "jci/Simple.java"
- }, reader, store);
-
- assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
- assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
-
- final byte[] clazzBytes = store.read("jci/Simple.class");
- assertNotNull(clazzBytes);
- assertTrue(clazzBytes.length > 0);
-
- final byte[] subClazzBytes = store.read("jci/Simple$Sub.class");
- assertNotNull(subClazzBytes);
- assertTrue(subClazzBytes.length > 0);
-
- }
-
- public void testUppercasePackageNameCompile() throws Exception {
- final JavaCompiler compiler = createJavaCompiler();
-
- final ResourceReader reader = new ResourceReader() {
- final private Map sources = new HashMap() {
- private static final long serialVersionUID = 1L;
- {
- put("Jci/Simple.java", (
- "package Jci;\n" +
- "public class Simple {\n" +
- " public String toString() {\n" +
- " return \"Simple\";\n" +
- " }\n" +
- "}").getBytes());
- }};
-
- public byte[] getBytes( final String pResourceName ) {
- return (byte[]) sources.get(pResourceName);
- }
-
- public boolean isAvailable( final String pResourceName ) {
- return sources.containsKey(pResourceName);
- }
-
- };
-
- final MemoryResourceStore store = new MemoryResourceStore();
- final CompilationResult result = compiler.compile(
- new String[] {
- "Jci/Simple.java"
- }, reader, store);
-
- assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
- assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
-
- final byte[] clazzBytes = store.read("Jci/Simple.class");
- assertNotNull(clazzBytes);
- assertTrue(clazzBytes.length > 0);
- }
-
-
-
- public final String toString( final CompilationProblem[] pProblems ) {
- final StringBuffer sb = new StringBuffer();
-
- for (int i = 0; i < pProblems.length; i++) {
- final CompilationProblem problem = pProblems[i];
- sb.append(problem.getMessage()).append(", ");
- }
-
- return sb.toString();
- }
-
+ public abstract JavaCompiler createJavaCompiler();
+
+ public abstract String getCompilerName();
+
+ public void testFactoryCreation() {
+ final JavaCompiler factoryCompiler = new JavaCompilerFactory().createCompiler(getCompilerName());
+ assertNotNull(factoryCompiler);
+
+ final JavaCompiler compiler = createJavaCompiler();
+ assertEquals(factoryCompiler.getClass().getName(), compiler.getClass().getName());
+ }
+
+ public void testSimpleCompile() throws Exception {
+ final JavaCompiler compiler = createJavaCompiler();
+
+ final ResourceReader reader = new ResourceReader() {
+ final private Map sources = new HashMap() {
+ private static final long serialVersionUID = 1L;
+ {
+ put("jci/Simple.java", (
+ "package jci;\n" +
+ "public class Simple {\n" +
+ " public String toString() {\n" +
+ " return \"Simple\";\n" +
+ " }\n" +
+ "}").getBytes());
+ }};
+
+ public byte[] getBytes( final String pResourceName ) {
+ return (byte[]) sources.get(pResourceName);
+ }
+
+ public boolean isAvailable( final String pResourceName ) {
+ return sources.containsKey(pResourceName);
+ }
+
+ };
+
+ final MemoryResourceStore store = new MemoryResourceStore();
+ final CompilationResult result = compiler.compile(
+ new String[] {
+ "jci/Simple.java"
+ }, reader, store);
+
+ assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
+ assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
+
+ final byte[] clazzBytes = store.read("jci/Simple.class");
+ assertNotNull(clazzBytes);
+ assertTrue(clazzBytes.length > 0);
+ }
+
+ public void testExtendedCompile() throws Exception {
+ final JavaCompiler compiler = createJavaCompiler();
+
+ final ResourceReader reader = new ResourceReader() {
+ final private Map sources = new HashMap() {
+ private static final long serialVersionUID = 1L;
+ {
+ put("jci/Simple.java", (
+ "package jci;\n" +
+ "public class Simple {\n" +
+ " public String toString() {\n" +
+ " return \"Simple\";\n" +
+ " }\n" +
+ "}").getBytes());
+ put("jci/Extended.java", (
+ "package jci;\n" +
+ "public class Extended extends Simple {\n" +
+ " public String toString() {\n" +
+ " return \"Extended\" + super.toString();\n" +
+ " }\n" +
+ "}").getBytes());
+ }};
+
+ public byte[] getBytes( final String pResourceName ) {
+ return (byte[]) sources.get(pResourceName);
+ }
+
+ public boolean isAvailable( final String pResourceName ) {
+ return sources.containsKey(pResourceName);
+ }
+
+ };
+
+ final MemoryResourceStore store = new MemoryResourceStore();
+ final CompilationResult result = compiler.compile(
+ new String[] {
+ "jci/Extended.java",
+ "jci/Simple.java"
+ }, reader, store);
+
+ assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
+ assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
+
+ final byte[] clazzBytesSimple = store.read("jci/Simple.class");
+ assertNotNull(clazzBytesSimple);
+ assertTrue(clazzBytesSimple.length > 0);
+
+ final byte[] clazzBytesExtended = store.read("jci/Extended.class");
+ assertNotNull(clazzBytesExtended);
+ assertTrue(clazzBytesExtended.length > 0);
+ }
+
+ public void testInternalClassCompile() throws Exception {
+ final JavaCompiler compiler = createJavaCompiler();
+
+ final ResourceReader reader = new ResourceReader() {
+ final private Map sources = new HashMap() {
+ private static final long serialVersionUID = 1L;
+ {
+ put("jci/Simple.java", (
+ "package jci;\n" +
+ "public class Simple {\n" +
+ " private class Sub {\n" +
+ " }\n" +
+ " public String toString() {\n" +
+ " new Sub();\n" +
+ " return \"Simple\";\n" +
+ " }\n" +
+ "}").getBytes());
+ }};
+
+ public byte[] getBytes( final String pResourceName ) {
+ return (byte[]) sources.get(pResourceName);
+ }
+
+ public boolean isAvailable( final String pResourceName ) {
+ return sources.containsKey(pResourceName);
+ }
+
+ };
+
+ final MemoryResourceStore store = new MemoryResourceStore();
+ final CompilationResult result = compiler.compile(
+ new String[] {
+ "jci/Simple.java"
+ }, reader, store);
+
+ assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
+ assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
+
+ final byte[] clazzBytes = store.read("jci/Simple.class");
+ assertNotNull(clazzBytes);
+ assertTrue(clazzBytes.length > 0);
+
+ final byte[] subClazzBytes = store.read("jci/Simple$Sub.class");
+ assertNotNull(subClazzBytes);
+ assertTrue(subClazzBytes.length > 0);
+
+ }
+
+ public void testUppercasePackageNameCompile() throws Exception {
+ final JavaCompiler compiler = createJavaCompiler();
+
+ final ResourceReader reader = new ResourceReader() {
+ final private Map sources = new HashMap() {
+ private static final long serialVersionUID = 1L;
+ {
+ put("Jci/Simple.java", (
+ "package Jci;\n" +
+ "public class Simple {\n" +
+ " public String toString() {\n" +
+ " return \"Simple\";\n" +
+ " }\n" +
+ "}").getBytes());
+ }};
+
+ public byte[] getBytes( final String pResourceName ) {
+ return (byte[]) sources.get(pResourceName);
+ }
+
+ public boolean isAvailable( final String pResourceName ) {
+ return sources.containsKey(pResourceName);
+ }
+
+ };
+
+ final MemoryResourceStore store = new MemoryResourceStore();
+ final CompilationResult result = compiler.compile(
+ new String[] {
+ "Jci/Simple.java"
+ }, reader, store);
+
+ assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
+ assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
+
+ final byte[] clazzBytes = store.read("Jci/Simple.class");
+ assertNotNull(clazzBytes);
+ assertTrue(clazzBytes.length > 0);
+ }
+
+
+
+ public final String toString( final CompilationProblem[] pProblems ) {
+ final StringBuffer sb = new StringBuffer();
+
+ for (int i = 0; i < pProblems.length; i++) {
+ final CompilationProblem problem = pProblems[i];
+ sb.append(problem.getMessage()).append(", ");
+ }
+
+ return sb.toString();
+ }
+
}
Modified: jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/readers/ResourceReaderTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/readers/ResourceReaderTestCase.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/readers/ResourceReaderTestCase.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/readers/ResourceReaderTestCase.java Wed Apr 25 07:57:21 2007
@@ -25,18 +25,18 @@
*/
public final class ResourceReaderTestCase extends AbstractTestCase {
- public void testFileResourceReader() throws Exception {
+ public void testFileResourceReader() throws Exception {
writeFile("test", "test");
- checkRead(new FileResourceReader(directory));
- }
+ checkRead(new FileResourceReader(directory));
+ }
- public void testMemoryResourceReader() throws Exception {
- final MemoryResourceReader reader = new MemoryResourceReader();
- reader.add("test", "test".getBytes());
- checkRead(reader);
- }
-
- private void checkRead( final ResourceReader reader ) throws Exception {
+ public void testMemoryResourceReader() throws Exception {
+ final MemoryResourceReader reader = new MemoryResourceReader();
+ reader.add("test", "test".getBytes());
+ checkRead(reader);
+ }
+
+ private void checkRead( final ResourceReader reader ) throws Exception {
assertTrue(reader.isAvailable("test"));
final byte[] content = reader.getBytes("test");
assertTrue(content != null);
Modified: jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/stores/ResourceStoreTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/stores/ResourceStoreTestCase.java?view=diff&rev=532377&r1=532376&r2=532377
==============================================================================
--- jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/stores/ResourceStoreTestCase.java (original)
+++ jakarta/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/stores/ResourceStoreTestCase.java Wed Apr 25 07:57:21 2007
@@ -27,21 +27,21 @@
*/
public final class ResourceStoreTestCase extends AbstractTestCase {
- public void testMemoryResourceStore() {
- checkReadWrite(new MemoryResourceStore());
- checkRemove(new MemoryResourceStore());
- }
-
- public void testFileResourceStore() {
- checkReadWrite(new FileResourceStore(directory));
- checkRemove(new FileResourceStore(directory));
- }
+ public void testMemoryResourceStore() {
+ checkReadWrite(new MemoryResourceStore());
+ checkRemove(new MemoryResourceStore());
+ }
+
+ public void testFileResourceStore() {
+ checkReadWrite(new FileResourceStore(directory));
+ checkRemove(new FileResourceStore(directory));
+ }
+
+ public void testTransactionalFileResourceStore() {
+ checkReadWrite(new TransactionalResourceStore(new FileResourceStore(directory)));
+ checkRemove(new TransactionalResourceStore(new FileResourceStore(directory)));
+ }
- public void testTransactionalFileResourceStore() {
- checkReadWrite(new TransactionalResourceStore(new FileResourceStore(directory)));
- checkRemove(new TransactionalResourceStore(new FileResourceStore(directory)));
- }
-
private void checkReadWrite( final ResourceStore pStore ) {
final byte[] data = { 1, 2, 3 };
pStore.write("key", data);
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org