You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by tc...@apache.org on 2006/04/25 02:57:53 UTC
svn commit: r396752 [1/3] - in /jakarta/commons/sandbox/jci/trunk: ./
classes/ compilers/ compilers/commons-jci-eclipse/
compilers/commons-jci-eclipse/src/ compilers/commons-jci-eclipse/src/java/
compilers/commons-jci-eclipse/src/java/org/ compilers/co...
Author: tcurdt
Date: Mon Apr 24 17:57:46 2006
New Revision: 396752
URL: http://svn.apache.org/viewcvs?rev=396752&view=rev
Log:
move to multi-module maven2 build
Added:
jakarta/commons/sandbox/jci/trunk/compilers/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/pom.xml (with props)
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseCompilationProblem.java (with props)
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java (with props)
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java (with props)
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/pom.xml (with props)
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyCompilationProblem.java (with props)
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyJavaCompiler.java (with props)
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/pom.xml (with props)
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoCompilationProblem.java (with props)
jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java (with props)
jakarta/commons/sandbox/jci/trunk/compilers/pom.xml-notused (with props)
jakarta/commons/sandbox/jci/trunk/core/
jakarta/commons/sandbox/jci/trunk/core/pom.xml (with props)
jakarta/commons/sandbox/jci/trunk/core/src/
jakarta/commons/sandbox/jci/trunk/core/src/java/
jakarta/commons/sandbox/jci/trunk/core/src/java/org/
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoader.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/CompilationResult.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompiler.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/listeners/
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/listeners/CompilingListener.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/listeners/FileChangeListener.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/listeners/NotificationListener.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/listeners/NotifyingListener.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/listeners/ReloadingListener.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/listeners/ResourceStoringListener.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/monitor/
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/monitor/FilesystemAlterationListener.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/problems/
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/problems/CompilationProblem.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/problems/CompilationProblemHandler.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/FileResourceReader.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/ResourceReader.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/FileResourceStore.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/ResourceStore.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/Transactional.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/TransactionalResourceStore.java (with props)
jakarta/commons/sandbox/jci/trunk/core/src/java/simplelog.properties (with props)
jakarta/commons/sandbox/jci/trunk/core/src/site/
jakarta/commons/sandbox/jci/trunk/core/src/site/site.xml (with props)
jakarta/commons/sandbox/jci/trunk/core/src/site/xdocs/
jakarta/commons/sandbox/jci/trunk/core/src/site/xdocs/downloads.xml (with props)
jakarta/commons/sandbox/jci/trunk/core/src/site/xdocs/images/
jakarta/commons/sandbox/jci/trunk/core/src/site/xdocs/images/jci-logo-white.png (with props)
jakarta/commons/sandbox/jci/trunk/core/src/site/xdocs/index.xml (with props)
jakarta/commons/sandbox/jci/trunk/core/src/site/xdocs/navigation.xml (with props)
jakarta/commons/sandbox/jci/trunk/examples/
jakarta/commons/sandbox/jci/trunk/examples/pom.xml (with props)
jakarta/commons/sandbox/jci/trunk/examples/src/
jakarta/commons/sandbox/jci/trunk/examples/src/java/
jakarta/commons/sandbox/jci/trunk/examples/src/java/org/
jakarta/commons/sandbox/jci/trunk/examples/src/java/org/apache/
jakarta/commons/sandbox/jci/trunk/examples/src/java/org/apache/commons/
jakarta/commons/sandbox/jci/trunk/examples/src/java/org/apache/commons/jci/
jakarta/commons/sandbox/jci/trunk/examples/src/java/org/apache/commons/jci/examples/
jakarta/commons/sandbox/jci/trunk/examples/src/java/org/apache/commons/jci/examples/commandline/
jakarta/commons/sandbox/jci/trunk/examples/src/java/org/apache/commons/jci/examples/commandline/Compile.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/
jakarta/commons/sandbox/jci/trunk/tests/pom.xml (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/
jakarta/commons/sandbox/jci/trunk/tests/src/java/
jakarta/commons/sandbox/jci/trunk/tests/src/test/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/AbstractTestCase.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilerUtils.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyBar.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyFoo.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/GroovySources.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaCompilerFactoryTestCase.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaSources.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/eclipse/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/groovy/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/janino/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/monitor/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/problems/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/FileResourceReaderTestCase.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/AbstractStoreTestCase.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/FileResourceStoreTestCase.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/MemoryResourceStoreTestCase.java (with props)
jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/TransactinonalResourceStoreTestCase.java (with props)
Removed:
jakarta/commons/sandbox/jci/trunk/classes/
jakarta/commons/sandbox/jci/trunk/maven.xml
jakarta/commons/sandbox/jci/trunk/project.properties
jakarta/commons/sandbox/jci/trunk/src/
jakarta/commons/sandbox/jci/trunk/xdocs/
Modified:
jakarta/commons/sandbox/jci/trunk/pom.xml
Added: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/pom.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/pom.xml?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/pom.xml (added)
+++ jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/pom.xml Mon Apr 24 17:57:46 2006
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>jar</packaging>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-eclipse</artifactId>
+ <version>3.1.0</version>
+
+ <name>Jakarta Commons JCI Compiler - Eclipse</name>
+<!--
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <org.apache.commons.jci.compilers.JavaCompiler>org.apache.commons.jci.compilers.EclipseJavaCompiler</org.apache.commons.jci.compilers.JavaCompiler>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+-->
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jdt</groupId>
+ <artifactId>core</artifactId>
+ <version>3.2.0.653</version>
+ </dependency>
+
+ </dependencies>
+</project>
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/pom.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseCompilationProblem.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseCompilationProblem.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseCompilationProblem.java (added)
+++ jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseCompilationProblem.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,72 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci.compilers;
+
+import org.apache.commons.jci.problems.CompilationProblem;
+import org.eclipse.jdt.core.compiler.IProblem;
+
+public class EclipseCompilationProblem implements CompilationProblem {
+
+ private final IProblem problem;
+
+ public EclipseCompilationProblem(final IProblem pProblem) {
+ problem = pProblem;
+ }
+
+ public boolean isError() {
+ return problem.isError();
+ }
+
+ public String getFileName() {
+ return new String(problem.getOriginatingFileName());
+ }
+
+ public int getStartLine() {
+ return problem.getSourceLineNumber();
+ }
+
+ public int getStartColumn() {
+ return problem.getSourceStart();
+ }
+
+ public int getEndLine() {
+ return getStartLine();
+ }
+
+ public int getEndColumn() {
+ return problem.getSourceEnd();
+ }
+
+ public String getMessage() {
+ return problem.getMessage();
+ }
+
+ public String toString() {
+ final StringBuffer sb = new StringBuffer();
+ sb.append(getFileName()).append(" (");
+ sb.append(getStartLine());
+ sb.append(":");
+ sb.append(getStartColumn());
+ sb.append(") : ");
+ sb.append(getMessage());
+ return sb.toString();
+ }
+
+ public int getId() {
+ return problem.getID();
+ }
+
+}
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseCompilationProblem.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseCompilationProblem.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseCompilationProblem.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java (added)
+++ jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,271 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci.compilers;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import org.apache.commons.jci.problems.CompilationProblem;
+import org.apache.commons.jci.readers.ResourceReader;
+import org.apache.commons.jci.stores.ResourceStore;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.internal.compiler.ClassFile;
+import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.Compiler;
+import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
+import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
+import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
+import org.eclipse.jdt.internal.compiler.IProblemFactory;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
+import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
+import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
+import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
+import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
+
+public final class EclipseJavaCompiler extends AbstractJavaCompiler {
+
+ private final static Log log = LogFactory.getLog(EclipseJavaCompiler.class);
+ private final EclipseJavaCompilerSettings settings;
+
+ public EclipseJavaCompiler() {
+ this(new EclipseJavaCompilerSettings());
+ }
+
+ public EclipseJavaCompiler(final EclipseJavaCompilerSettings pSettings) {
+ settings = pSettings;
+ }
+
+ final class CompilationUnit implements ICompilationUnit {
+
+ final private String clazzName;
+ final private String fileName;
+ final private char[] typeName;
+ final private char[][] packageName;
+ final private ResourceReader reader;
+
+ CompilationUnit(final ResourceReader pReader, final String pClazzName) {
+ reader = pReader;
+ clazzName = pClazzName;
+ clazzName.replace('.', '/');
+ fileName = clazzName.replace('.', '/') + ".java";
+ int dot = clazzName.lastIndexOf('.');
+ if (dot > 0) {
+ typeName = clazzName.substring(dot + 1).toCharArray();
+ } else {
+ typeName = clazzName.toCharArray();
+ }
+ final StringTokenizer izer = new StringTokenizer(clazzName, ".");
+ packageName = new char[izer.countTokens() - 1][];
+ for (int i = 0; i < packageName.length; i++) {
+ packageName[i] = izer.nextToken().toCharArray();
+ }
+ }
+
+ public char[] getFileName() {
+ return fileName.toCharArray();
+ }
+
+ public char[] getContents() {
+ return reader.getContent(fileName);
+ }
+
+ public char[] getMainTypeName() {
+ return typeName;
+ }
+
+ public char[][] getPackageName() {
+ return packageName;
+ }
+ }
+
+ public org.apache.commons.jci.compilers.CompilationResult compile(
+ final String[] pClazzNames,
+ final ResourceReader pReader,
+ final ResourceStore pStore,
+ final ClassLoader classLoader
+ ) {
+
+ final Map settingsMap = settings.getMap();
+ final Set clazzIndex = new HashSet();
+ ICompilationUnit[] compilationUnits = new ICompilationUnit[pClazzNames.length];
+ for (int i = 0; i < compilationUnits.length; i++) {
+ final String clazzName = pClazzNames[i];
+ compilationUnits[i] = new CompilationUnit(pReader, clazzName);
+ clazzIndex.add(clazzName);
+ log.debug("compiling " + clazzName);
+ }
+
+ final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
+ final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
+ final INameEnvironment nameEnvironment = new INameEnvironment() {
+
+ public NameEnvironmentAnswer findType( final char[][] compoundTypeName ) {
+ final StringBuffer result = new StringBuffer();
+ for (int i = 0; i < compoundTypeName.length; i++) {
+ if (i != 0) {
+ result.append('.');
+ }
+ result.append(compoundTypeName[i]);
+ }
+ return findType(result.toString());
+ }
+
+ public NameEnvironmentAnswer findType( final char[] typeName, final char[][] packageName ) {
+ final StringBuffer result = new StringBuffer();
+ for (int i = 0; i < packageName.length; i++) {
+ result.append(packageName[i]);
+ result.append('.');
+ }
+ result.append(typeName);
+ return findType(result.toString());
+ }
+
+ private NameEnvironmentAnswer findType( final String clazzName ) {
+ byte[] clazzBytes = pStore.read(clazzName);
+ if (clazzBytes != null) {
+ // log.debug("loading from store " + clazzName);
+ final char[] fileName = clazzName.toCharArray();
+ try {
+ final ClassFileReader classFileReader = new ClassFileReader(clazzBytes, fileName, true);
+ return new NameEnvironmentAnswer(classFileReader, null);
+ } catch (final ClassFormatException e) {
+ log.error("wrong class format", e);
+ }
+ } else {
+ if (pReader.isAvailable(clazzName.replace('.', '/') + ".java")) {
+ log.debug("compile " + clazzName);
+ ICompilationUnit compilationUnit = new CompilationUnit(pReader, clazzName);
+ return new NameEnvironmentAnswer(compilationUnit, null);
+ }
+
+ final String resourceName = clazzName.replace('.', '/') + ".class";
+ final InputStream is = classLoader.getResourceAsStream(resourceName);
+ if (is != null) {
+ final byte[] buffer = new byte[8192];
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream(buffer.length);
+ int count;
+ try {
+ while ((count = is.read(buffer, 0, buffer.length)) > 0) {
+ baos.write(buffer, 0, count);
+ }
+ baos.flush();
+ clazzBytes = baos.toByteArray();
+ final char[] fileName = clazzName.toCharArray();
+ ClassFileReader classFileReader =
+ new ClassFileReader(clazzBytes, fileName, true);
+ return new NameEnvironmentAnswer(classFileReader, null);
+ } catch (final IOException e) {
+ log.error("could not read class", e);
+ } catch (final ClassFormatException e) {
+ log.error("wrong class format", e);
+ } finally {
+ try {
+ baos.close();
+ } catch (final IOException oe) {
+ log.error("could not close output stream", oe);
+ }
+ try {
+ is.close();
+ } catch (final IOException ie) {
+ log.error("could not close input stream", ie);
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private boolean isPackage( final String clazzName ) {
+ final String resourceName = clazzName.replace('.', '/') + ".class";
+ final URL resource = classLoader.getResource(resourceName);
+ return resource == null;
+ }
+
+ public boolean isPackage( char[][] parentPackageName, char[] packageName ) {
+ final StringBuffer result = new StringBuffer();
+ if (parentPackageName != null) {
+ for (int i = 0; i < parentPackageName.length; i++) {
+ if (i != 0) {
+ result.append('.');
+ }
+ result.append(parentPackageName[i]);
+ }
+ }
+ if (Character.isUpperCase(packageName[0])) {
+ return false;
+ }
+ if (parentPackageName != null && parentPackageName.length > 0) {
+ result.append('.');
+ }
+ result.append(packageName);
+ return isPackage(result.toString());
+ }
+
+ public void cleanup() {
+ }
+ };
+
+ final Collection problems = new ArrayList();
+ final ICompilerRequestor compilerRequestor = new ICompilerRequestor() {
+ public void acceptResult( CompilationResult result ) {
+ if (result.hasProblems()) {
+ final IProblem[] iproblems = result.getProblems();
+ for (int i = 0; i < iproblems.length; i++) {
+ final IProblem iproblem = iproblems[i];
+ final CompilationProblem problem = new EclipseCompilationProblem(iproblem);
+ if (problemHandler != null) {
+ problemHandler.handle(problem);
+ }
+ problems.add(problem);
+ }
+ }
+ if (!result.hasErrors()) {
+ final ClassFile[] clazzFiles = result.getClassFiles();
+ for (int i = 0; i < clazzFiles.length; i++) {
+ final ClassFile clazzFile = clazzFiles[i];
+ final char[][] compoundName = clazzFile.getCompoundName();
+ final StringBuffer clazzName = new StringBuffer();
+ for (int j = 0; j < compoundName.length; j++) {
+ if (j != 0) {
+ clazzName.append('.');
+ }
+ clazzName.append(compoundName[j]);
+ }
+ pStore.write(clazzName.toString(), clazzFile.getBytes());
+ }
+ }
+ }
+ };
+
+ final Compiler compiler =
+ new Compiler(nameEnvironment, policy, settingsMap, compilerRequestor, problemFactory, false);
+
+ compiler.compile(compilationUnits);
+
+ return new org.apache.commons.jci.compilers.CompilationResult(problems);
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java (added)
+++ jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,26 @@
+package org.apache.commons.jci.compilers;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.jci.compilers.JavaCompilerSettings;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+
+
+public class EclipseJavaCompilerSettings implements JavaCompilerSettings {
+ private final Map map = new HashMap();
+
+ public EclipseJavaCompilerSettings() {
+ map.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
+ map.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
+ map.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.GENERATE);
+ map.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
+ map.put(CompilerOptions.OPTION_Encoding, "UTF-8");
+ map.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
+ map.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4);
+ map.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
+ }
+
+ public Map getMap() {
+ return map;
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/pom.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/pom.xml?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/pom.xml (added)
+++ jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/pom.xml Mon Apr 24 17:57:46 2006
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>jar</packaging>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-groovy</artifactId>
+ <version>1.0-jsr-03</version>
+
+ <name>Jakarta Commons JCI Compiler - Groovy</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>groovy</groupId>
+ <artifactId>groovy-all-1.0-jsr</artifactId>
+ <version>03</version>
+ </dependency>
+
+ </dependencies>
+</project>
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/pom.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyCompilationProblem.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyCompilationProblem.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyCompilationProblem.java (added)
+++ jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyCompilationProblem.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,99 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci.compilers;
+
+import org.apache.commons.jci.problems.CompilationProblem;
+import org.codehaus.groovy.control.messages.ExceptionMessage;
+import org.codehaus.groovy.control.messages.Message;
+import org.codehaus.groovy.control.messages.SimpleMessage;
+import org.codehaus.groovy.control.messages.SyntaxErrorMessage;
+import org.codehaus.groovy.syntax.SyntaxException;
+
+public class GroovyCompilationProblem implements CompilationProblem {
+
+ private final String fileName;
+ private final String message;
+ private final boolean error;
+ private final int startLine;
+ private final int startColumn;
+ private final int endLine;
+ private final int endColumn;
+
+ public GroovyCompilationProblem(final Message pMessage) {
+ if (pMessage instanceof SimpleMessage) {
+ error = false;
+ } else {
+ error = true;
+ }
+ if (pMessage instanceof SyntaxErrorMessage) {
+ SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage)pMessage;
+ SyntaxException syntaxException = syntaxErrorMessage.getCause();
+ message = syntaxException.getMessage();
+ fileName = syntaxException.getSourceLocator();
+ // FIXME: getStartLine() vs. getLine()
+ startLine = syntaxException.getStartLine();
+ startColumn = syntaxException.getStartColumn();
+ endLine = syntaxException.getLine();
+ endColumn = syntaxException.getEndColumn();
+ } else {
+ fileName = "";
+ startLine = 0;
+ startColumn = 0;
+ endLine = 0;
+ endColumn = 0;
+ if (pMessage instanceof ExceptionMessage) {
+ message = ((ExceptionMessage)pMessage).getCause().getMessage();
+ } else if (pMessage instanceof SimpleMessage) {
+ message = ((SimpleMessage)pMessage).getMessage();
+ } else {
+ message = pMessage.toString();
+ }
+ }
+ }
+
+ public boolean isError() {
+ return error;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public int getStartLine() {
+ return startLine;
+ }
+
+ public int getStartColumn() {
+ return startColumn;
+ }
+
+ public int getEndLine() {
+ return endLine;
+ }
+
+ public int getEndColumn() {
+ return endColumn;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public String toString() {
+ return getMessage();
+ }
+
+}
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyCompilationProblem.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyCompilationProblem.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyCompilationProblem.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyJavaCompiler.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyJavaCompiler.java (added)
+++ jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyJavaCompiler.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,96 @@
+package org.apache.commons.jci.compilers;
+
+import groovy.lang.GroovyClassLoader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.commons.jci.compilers.AbstractJavaCompiler;
+import org.apache.commons.jci.compilers.CompilationResult;
+import org.apache.commons.jci.problems.CompilationProblem;
+import org.apache.commons.jci.readers.ResourceReader;
+import org.apache.commons.jci.stores.ResourceStore;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.groovy.control.CompilationFailedException;
+import org.codehaus.groovy.control.CompilationUnit;
+import org.codehaus.groovy.control.CompilerConfiguration;
+import org.codehaus.groovy.control.ErrorCollector;
+import org.codehaus.groovy.control.MultipleCompilationErrorsException;
+import org.codehaus.groovy.control.Phases;
+import org.codehaus.groovy.control.SourceUnit;
+import org.codehaus.groovy.control.messages.Message;
+import org.codehaus.groovy.control.messages.WarningMessage;
+import org.codehaus.groovy.tools.GroovyClass;
+
+public final class GroovyJavaCompiler extends AbstractJavaCompiler {
+
+ private final static Log log = LogFactory.getLog(GroovyJavaCompiler.class);
+
+ public CompilationResult compile(
+ final String[] clazzNames,
+ final ResourceReader reader,
+ final ResourceStore store,
+ final ClassLoader classLoader
+ ) {
+ final CompilerConfiguration configuration = new CompilerConfiguration();
+ final ErrorCollector collector = new ErrorCollector(configuration);
+ final GroovyClassLoader groovyClassLoader = new GroovyClassLoader(classLoader);
+ final CompilationUnit unit = new CompilationUnit(configuration, null, groovyClassLoader);
+ final SourceUnit[] source = new SourceUnit[clazzNames.length];
+ for (int i = 0; i < source.length; i++) {
+ final String filename = clazzNames[i].replace('.','/') + ".groovy";
+ source[i] = new SourceUnit(
+ filename,
+ new String(reader.getContent(filename)), // FIXME delay the read
+ configuration,
+ groovyClassLoader,
+ collector
+ );
+ unit.addSource(source[i]);
+ }
+
+ final Collection problems = new ArrayList();
+
+ try {
+ log.debug("compiling");
+ unit.compile(Phases.CLASS_GENERATION);
+
+ final List classes = unit.getClasses();
+ for (final Iterator it = classes.iterator(); it.hasNext();) {
+ final GroovyClass clazz = (GroovyClass) it.next();
+ final byte[] bytes = clazz.getBytes();
+ store.write(clazz.getName(), bytes);
+ }
+ } catch (final MultipleCompilationErrorsException e) {
+ final ErrorCollector col = e.getErrorCollector();
+ final Collection warnings = col.getWarnings();
+ if (warnings != null) {
+ for (final Iterator it = warnings.iterator(); it.hasNext();) {
+ final WarningMessage warning = (WarningMessage) it.next();
+ final CompilationProblem problem = new GroovyCompilationProblem(warning);
+ if (problemHandler != null) {
+ problemHandler.handle(problem);
+ }
+ problems.add(problem);
+ }
+ }
+
+ final Collection errors = col.getErrors();
+ if (errors != null) {
+ for (final Iterator it = errors.iterator(); it.hasNext();) {
+ final Message message = (Message) it.next();
+ final CompilationProblem problem = new GroovyCompilationProblem(message);
+ if (problemHandler != null) {
+ problemHandler.handle(problem);
+ }
+ problems.add(problem);
+ }
+ }
+ } catch (CompilationFailedException e) {
+ throw new RuntimeException("no expected");
+ }
+
+ return new CompilationResult(problems);
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyJavaCompiler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-groovy/src/java/org/apache/commons/jci/compilers/GroovyJavaCompiler.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/pom.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/pom.xml?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/pom.xml (added)
+++ jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/pom.xml Mon Apr 24 17:57:46 2006
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>jar</packaging>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-janino</artifactId>
+ <version>2.3.7</version>
+
+ <name>Jakarta Commons JCI Compiler - Janino</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>janino</groupId>
+ <artifactId>janino</artifactId>
+ <version>2.3.7</version>
+ </dependency>
+
+ </dependencies>
+</project>
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/pom.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoCompilationProblem.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoCompilationProblem.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoCompilationProblem.java (added)
+++ jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoCompilationProblem.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,93 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci.compilers;
+
+import org.apache.commons.jci.problems.CompilationProblem;
+import org.codehaus.janino.Location;
+import org.codehaus.janino.Scanner.LocatedException;
+
+public class JaninoCompilationProblem implements CompilationProblem {
+
+ private final Location location;
+ private final String fileName;
+ private final String message;
+ private final boolean error;
+
+ public JaninoCompilationProblem(final LocatedException pLocatedException) {
+ this(pLocatedException.getLocation(), pLocatedException.getMessage(), true);
+ }
+
+ public JaninoCompilationProblem(final Location pLocation, final String pMessage, final boolean pError) {
+ this(pLocation.getFileName(), pLocation, pMessage, pError);
+ }
+
+ public JaninoCompilationProblem(final String pFilename, final String pMessage, final boolean pError) {
+ this(pFilename, null, pMessage, pError);
+ }
+
+ public JaninoCompilationProblem(final String pFilename, final Location pLocation, final String pMessage, final boolean pError) {
+ location = pLocation;
+ fileName = pFilename;
+ message = pMessage;
+ error = pError;
+ }
+
+ public boolean isError() {
+ return error;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public int getStartLine() {
+ if (location == null) {
+ return 0;
+ }
+ return location.getLineNumber();
+ }
+
+ public int getStartColumn() {
+ if (location == null) {
+ return 0;
+ }
+ return location.getColumnNumber();
+ }
+
+ public int getEndLine() {
+ return getStartLine();
+ }
+
+ public int getEndColumn() {
+ return getStartColumn();
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public String toString() {
+ final StringBuffer sb = new StringBuffer();
+ sb.append(getFileName()).append(" (");
+ sb.append(getStartLine());
+ sb.append(":");
+ sb.append(getStartColumn());
+ sb.append(") : ");
+ sb.append(getMessage());
+ return sb.toString();
+ }
+
+}
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoCompilationProblem.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoCompilationProblem.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoCompilationProblem.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java (added)
+++ jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,159 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci.compilers;
+
+import java.io.BufferedReader;
+import java.io.CharArrayReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.apache.commons.jci.problems.CompilationProblem;
+import org.apache.commons.jci.readers.ResourceReader;
+import org.apache.commons.jci.stores.ResourceStore;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.janino.ClassLoaderIClassLoader;
+import org.codehaus.janino.CompileException;
+import org.codehaus.janino.DebuggingInformation;
+import org.codehaus.janino.Descriptor;
+import org.codehaus.janino.IClass;
+import org.codehaus.janino.IClassLoader;
+import org.codehaus.janino.Java;
+import org.codehaus.janino.Location;
+import org.codehaus.janino.Parser;
+import org.codehaus.janino.Scanner;
+import org.codehaus.janino.UnitCompiler;
+import org.codehaus.janino.WarningHandler;
+import org.codehaus.janino.Scanner.LocatedException;
+import org.codehaus.janino.UnitCompiler.ErrorHandler;
+import org.codehaus.janino.util.ClassFile;
+
+/**
+ * @author art@gramlich-net.com
+ */
+public final class JaninoJavaCompiler extends AbstractJavaCompiler {
+
+ private final static Log log = LogFactory.getLog(JaninoJavaCompiler.class);
+
+ private class CompilingIClassLoader extends IClassLoader {
+
+ private final Map types = new HashMap();
+ private final ResourceReader resourceReader;
+ private final Map classes;
+ private final Collection problems = new ArrayList();
+
+ private CompilingIClassLoader(final ResourceReader pResourceReader, final Map pClasses, final ClassLoader classLoader) {
+ super( new ClassLoaderIClassLoader( classLoader ) );
+ resourceReader = pResourceReader;
+ classes = pClasses;
+ super.postConstruct();
+ }
+
+ protected Collection getProblems() {
+ return problems;
+ }
+
+ protected IClass findIClass(final String pType) {
+ final String className = Descriptor.toClassName(pType);
+ if (types.containsKey(pType)) {
+ return (IClass) types.get(pType);
+ }
+ final String fileNameForClass = className.replace('.', File.separatorChar) + ".java";
+
+ final char[] content = resourceReader.getContent(fileNameForClass);
+ if (content == null) {
+ return null;
+ }
+ final Reader reader = new BufferedReader(new CharArrayReader(content));
+ Scanner scanner = null;
+ try {
+ scanner = new Scanner(fileNameForClass, 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);
+ }
+ 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 (problemHandler != null) {
+ problemHandler.handle(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());
+ classes.put(classFiles[i].getThisClassName(), classFiles[i].toByteArray());
+ }
+ final IClass ic = uc.findClass(className);
+ if (null != ic) {
+ types.put(pType, ic);
+ }
+ return ic;
+ } catch (final LocatedException e) {
+ problems.add(new JaninoCompilationProblem(e));
+ } catch (final IOException e) {
+ problems.add(new JaninoCompilationProblem(fileNameForClass, "IO:" + e.getMessage(), true));
+ } finally {
+ if (scanner != null) {
+ try {
+ scanner.close();
+ } catch (IOException e) {
+ log.error("IOException occured while compiling " + className, e);
+ }
+ }
+ }
+ return null;
+ }
+ }
+
+ public CompilationResult compile(
+ final String[] pClasses,
+ final ResourceReader pResourceReader,
+ final ResourceStore pStore,
+ final ClassLoader classLoader
+ ) {
+ final Map classFilesByName = new HashMap();
+
+ final CompilingIClassLoader icl = new CompilingIClassLoader(pResourceReader, classFilesByName, classLoader);
+ for (int i = 0; i < pClasses.length; i++) {
+ log.debug("compiling " + pClasses[i]);
+ icl.loadIClass(Descriptor.fromClassName(pClasses[i]));
+ }
+ // Store all fully compiled classes
+ for (Iterator i = classFilesByName.entrySet().iterator(); i.hasNext();) {
+ final Map.Entry entry = (Map.Entry)i.next();
+ pStore.write((String)entry.getKey(), (byte[])entry.getValue());
+ }
+
+ return new CompilationResult(icl.getProblems());
+ }
+
+}
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/commons-jci-janino/src/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/compilers/pom.xml-notused
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/pom.xml-notused?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/pom.xml-notused (added)
+++ jakarta/commons/sandbox/jci/trunk/compilers/pom.xml-notused Mon Apr 24 17:57:46 2006
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>pom</packaging>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-compilers</artifactId>
+
+ <name>Jakarta Commons JCI Compilers</name>
+
+ <modules>
+ <module>commons-jci-eclipse</module>
+ <module>commons-jci-janino</module>
+ <module>commons-jci-groovy</module>
+ </modules>
+</project>
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/pom.xml-notused
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/compilers/pom.xml-notused
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/core/pom.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/pom.xml?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/pom.xml (added)
+++ jakarta/commons/sandbox/jci/trunk/core/pom.xml Mon Apr 24 17:57:46 2006
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>jar</packaging>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <name>Jakarta Commons JCI Core</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging-api</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.1</version>
+ </dependency>
+ </dependencies>
+
+</project>
Propchange: jakarta/commons/sandbox/jci/trunk/core/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/core/pom.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoader.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoader.java (added)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoader.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,189 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import org.apache.commons.jci.listeners.NotificationListener;
+import org.apache.commons.jci.listeners.ReloadingListener;
+import org.apache.commons.jci.stores.ResourceStore;
+import org.apache.commons.jci.stores.ResourceStoreClassLoader;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author tcurdt
+ *
+ */
+public class ReloadingClassLoader extends ClassLoader implements NotificationListener {
+
+ private final static Log log = LogFactory.getLog(ReloadingClassLoader.class);
+
+ private final ClassLoader parent;
+ //private final Collection reloadingListeners = new HashSet();
+ private ResourceStore[] stores = new ResourceStore[0];
+ private ClassLoader delegate;
+
+ public ReloadingClassLoader(final ClassLoader pParent) {
+ super(pParent);
+ parent = pParent;
+
+ delegate = new ResourceStoreClassLoader(parent, stores);
+ }
+
+ public void addListener(final ReloadingListener pListener) {
+ pListener.setNotificationListener(this);
+ addResourceStore(pListener.getStore());
+ }
+
+ public void removeListener(final ReloadingListener pListener) {
+ removeResourceStore(pListener.getStore());
+ pListener.setNotificationListener(null);
+ }
+
+ private boolean addResourceStore(final ResourceStore pStore) {
+ try {
+ final int n = stores.length;
+ final ResourceStore[] newStores = new ResourceStore[n + 1];
+ System.arraycopy(stores, 0, newStores, 0, n);
+ newStores[n] = pStore;
+ stores = newStores;
+ delegate = new ResourceStoreClassLoader(parent, stores);
+ return true;
+ } catch ( final Exception e ) {
+ // FIXME: rethrow?
+ }
+ return false;
+ }
+
+ private boolean removeResourceStore(final ResourceStore pStore) {
+ try {
+ final int n = stores.length;
+ int i = 0;
+
+ //find the pStore and index position with var i
+ while ( ( i <= n ) && ( stores[i] != pStore ) ) {
+ i++;
+ }
+
+
+ //pStore was not found
+ if ( i == n ) {
+ throw new Exception( "pStore was not found" );
+ }
+
+ // if stores length > 1 then array copy old values, else create new empty store
+ if (n > 1) {
+ final ResourceStore[] newStores = new ResourceStore[n - 1];
+
+ System.arraycopy(stores, 0, newStores, 0, i-1);
+ System.arraycopy(stores, i, newStores, i, newStores.length - 1);
+
+ stores = newStores;
+ delegate = new ResourceStoreClassLoader(parent, stores);
+ } else {
+ stores = new ResourceStore[0];
+ }
+ return true;
+
+ } catch ( final Exception e ) {
+ // FIXME: re-throw?
+ }
+
+ return false;
+ }
+
+ /*
+ public void start() {
+ fam = new FilesystemAlterationMonitor();
+ fam.addListener(new ReloadingListener(store) {
+ protected void needsReload( boolean pReload ) {
+ super.needsReload(pReload);
+ if (pReload) {
+ ReloadingClassLoader.this.reload();
+ } else {
+ ReloadingClassLoader.this.notifyReloadingListeners(false);
+ }
+ }
+ }, repository);
+ fam.start();
+ }
+
+ public void stop() {
+ fam.stop();
+ }
+ */
+ /*
+ public void addListener(final ReloadingClassLoaderListener pListener) {
+ synchronized (reloadingListeners) {
+ reloadingListeners.add(pListener);
+ }
+ }
+
+ public boolean removeListener(final ReloadingClassLoaderListener pListener) {
+ synchronized (reloadingListeners) {
+ return reloadingListeners.remove(pListener);
+ }
+ }
+ */
+ public void handleNotification() {
+ log.debug("reloading");
+ delegate = new ResourceStoreClassLoader(parent, stores);
+ //notifyReloadingListeners();
+ }
+ /*
+ private void notifyReloadingListeners() {
+ synchronized (reloadingListeners) {
+ for (final Iterator it = reloadingListeners.iterator(); it.hasNext();) {
+ final ReloadingClassLoaderListener listener = (ReloadingClassLoaderListener) it.next();
+ listener.hasReloaded();
+ }
+ }
+ }
+ */
+ 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 void clearAssertionStatus() {
+ delegate.clearAssertionStatus();
+ }
+ public URL getResource(String name) {
+ return delegate.getResource(name);
+ }
+ public InputStream getResourceAsStream(String name) {
+ return delegate.getResourceAsStream(name);
+ }
+ public Class loadClass(String name) throws ClassNotFoundException {
+ return delegate.loadClass(name);
+ }
+ public void setClassAssertionStatus(String className, boolean enabled) {
+ delegate.setClassAssertionStatus(className, enabled);
+ }
+ public void setDefaultAssertionStatus(boolean enabled) {
+ delegate.setDefaultAssertionStatus(enabled);
+ }
+ public void setPackageAssertionStatus(String packageName, boolean enabled) {
+ delegate.setPackageAssertionStatus(packageName, enabled);
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoader.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java (added)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,24 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci;
+
+
+/**
+ * @author tcurdt
+ */
+public interface ReloadingClassLoaderListener {
+ void hasReloaded();
+}
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java (added)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,31 @@
+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;
+
+
+public abstract class AbstractJavaCompiler implements JavaCompiler {
+
+ protected CompilationProblemHandler problemHandler;
+
+ public void setCompilationProblemHandler( final CompilationProblemHandler pHandler ) {
+ problemHandler = pHandler;
+ }
+
+ public CompilationResult compile(
+ final String[] pClazzNames,
+ final ResourceReader pReader,
+ final ResourceStore pStore
+ ) {
+
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+
+ if (classLoader == null) {
+ classLoader = this.getClass().getClassLoader();
+ }
+
+ return compile(pClazzNames, pReader, pStore, classLoader);
+ }
+
+}
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/CompilationResult.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/CompilationResult.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/CompilationResult.java (added)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/CompilationResult.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,36 @@
+package org.apache.commons.jci.compilers;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import org.apache.commons.jci.problems.CompilationProblem;
+
+
+public final class CompilationResult {
+
+ final Collection errors = new ArrayList();
+ final Collection warnings = new ArrayList();
+
+ public CompilationResult( final Collection pProblems ) {
+ for (final Iterator it = pProblems.iterator(); it.hasNext();) {
+ final CompilationProblem problem = (CompilationProblem) it.next();
+ if (problem.isError()) {
+ errors.add(problem);
+ } else {
+ warnings.add(problem);
+ }
+ }
+ }
+
+ public CompilationProblem[] getErrors() {
+ final CompilationProblem[] result = new CompilationProblem[errors.size()];
+ errors.toArray(result);
+ return result;
+ }
+
+ public CompilationProblem[] getWarnings() {
+ final CompilationProblem[] result = new CompilationProblem[warnings.size()];
+ warnings.toArray(result);
+ return result;
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/CompilationResult.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/CompilationResult.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompiler.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompiler.java (added)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompiler.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci.compilers;
+
+import org.apache.commons.jci.problems.CompilationProblemHandler;
+import org.apache.commons.jci.readers.ResourceReader;
+import org.apache.commons.jci.stores.ResourceStore;
+
+
+/**
+ * @author tcurdt
+ *
+ */
+public interface JavaCompiler {
+
+ void setCompilationProblemHandler( final CompilationProblemHandler pHandler );
+
+ CompilationResult compile(
+ final String[] pClazzNames,
+ final ResourceReader pReader,
+ final ResourceStore pStore );
+
+
+ CompilationResult compile(
+ final String[] pClazzNames,
+ final ResourceReader pReader,
+ final ResourceStore pStore,
+ final ClassLoader classLoader );
+}
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java (added)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,107 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci.compilers;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+
+public final class JavaCompilerFactory {
+
+ private Map classCache = new HashMap();
+
+ private static final JavaCompilerFactory INSTANCE = new JavaCompilerFactory();
+
+ public static JavaCompilerFactory getInstance() {
+ return JavaCompilerFactory.INSTANCE;
+ }
+
+ private JavaCompilerFactory() {
+ }
+
+
+// private Map getImplementations() {
+// final String[] jars = System.getProperty("java.class.path").split(System.getProperty("path.separator"));
+// final Map implementations = new HashMap(jars.length);
+// for (int i = 0; i < jars.length; i++) {
+// try {
+// final JarFile jar = new JarFile(jars[i]);
+// final Manifest manifest = jar.getManifest();
+// final String revision = (String) manifest.getMainAttributes().getValue("" + JavaCompiler.class);
+// implementations.put(jars[i], revision);
+// } catch (IOException e) {
+// }
+// }
+//
+// return implementations;
+// }
+
+// public JavaCompiler createCompiler(final JavaCompilerSettings pSettings) {
+// if (pSettings instanceof EclipseJavaCompilerSettings) {
+// return new EclipseJavaCompiler((EclipseJavaCompilerSettings) pSettings);
+// }
+
+ // FIXME create settings for the other compilers and add here
+
+// return null;
+// }
+
+ private String toJavaCasing(final String pName) {
+ final char[] name = pName.toCharArray();
+ name[0] = Character.toUpperCase(name[0]);
+ return new String(name);
+ }
+ /**
+ * Can accept the following strings "ECLIPSE", "JANINO", "GROOVY" and returns the appropriate
+ * JavaCompiler. Return null for any other type of string.
+ *
+ * @param compiler
+ * @return
+ */
+ public JavaCompiler createCompiler(final String pHint) {
+
+ final String className;
+ if (pHint.charAt('.') < 0) {
+ className = "org.apache.commons.jci.compilers." + toJavaCasing(pHint) + "JavaCompiler";
+ } else {
+ className = pHint;
+ }
+
+ Class clazz = (Class) classCache.get(className);
+
+ if (clazz == null) {
+ try {
+ clazz = Class.forName(className);
+ classCache.put(className, clazz);
+ } catch (ClassNotFoundException e) {
+ clazz = null;
+ }
+ }
+
+ if (clazz == null) {
+ return null;
+ }
+
+ try {
+ return (JavaCompiler) clazz.newInstance();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return null;
+ }
+ }
+
+}
\ No newline at end of file
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java (added)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,20 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci.compilers;
+
+
+public interface JavaCompilerSettings {
+}
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org