You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2006/12/24 20:16:50 UTC
svn commit: r490059 - in /incubator/uima/uimaj/trunk: ./ src/ src/org/
src/org/apache/ src/org/apache/uima/ src/org/apache/uima/util/
src/org/apache/uima/util/jet/
Author: schor
Date: Sun Dec 24 11:16:49 2006
New Revision: 490059
URL: http://svn.apache.org/viewvc?view=rev&rev=490059
Log:
UIMA-141 Initial import after fixing up for org.apache,
and modifying to handle Apache licensing headers
Added:
incubator/uima/uimaj/trunk/JetExpander.launch
incubator/uima/uimaj/trunk/JetExpander_Type.launch
incubator/uima/uimaj/trunk/Readme.txt
incubator/uima/uimaj/trunk/src/
incubator/uima/uimaj/trunk/src/org/
incubator/uima/uimaj/trunk/src/org/apache/
incubator/uima/uimaj/trunk/src/org/apache/uima/
incubator/uima/uimaj/trunk/src/org/apache/uima/util/
incubator/uima/uimaj/trunk/src/org/apache/uima/util/jet/
incubator/uima/uimaj/trunk/src/org/apache/uima/util/jet/JetExpander.java
Added: incubator/uima/uimaj/trunk/JetExpander.launch
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/JetExpander.launch?view=auto&rev=490059
==============================================================================
--- incubator/uima/uimaj/trunk/JetExpander.launch (added)
+++ incubator/uima/uimaj/trunk/JetExpander.launch Sun Dec 24 11:16:49 2006
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.apache.uima.util.jet.JetExpander"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="uimaj-jet-expander"/>
+<stringAttribute key="org.eclipse.debug.ui.target_run_perspective" value="perspective_default"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="${workspace_loc}/uimaj-tools/src/main/org.apache.uima.tools.jcasgen/templates/JCasType.javajet ${workspace_loc}/uimaj-tools/src/main/java"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/uimaj-jet-expander"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="4"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<stringAttribute key="org.eclipse.debug.ui.target_debug_perspective" value="perspective_default"/>
+</launchConfiguration>
Added: incubator/uima/uimaj/trunk/JetExpander_Type.launch
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/JetExpander_Type.launch?view=auto&rev=490059
==============================================================================
--- incubator/uima/uimaj/trunk/JetExpander_Type.launch (added)
+++ incubator/uima/uimaj/trunk/JetExpander_Type.launch Sun Dec 24 11:16:49 2006
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.apache.uima.util.jet.JetExpander"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="uimaj-jet-expander"/>
+<stringAttribute key="org.eclipse.debug.ui.target_run_perspective" value="perspective_default"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="${workspace_loc}/uimaj-tools/src/main/org.apache.uima.tools.jcasgen/templates/JCas_Type.javajet ${workspace_loc}/uimaj-tools/src/main/java"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/uimaj-jet-expander"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="4"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<stringAttribute key="org.eclipse.debug.ui.target_debug_perspective" value="perspective_default"/>
+</launchConfiguration>
Added: incubator/uima/uimaj/trunk/Readme.txt
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/Readme.txt?view=auto&rev=490059
==============================================================================
--- incubator/uima/uimaj/trunk/Readme.txt (added)
+++ incubator/uima/uimaj/trunk/Readme.txt Sun Dec 24 11:16:49 2006
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+ This java project is a stand alone tool used to generate
+ Java source code that is part of the JCasGen tool.
+
+ It is not included as part of the binary distribution
+ of UIMA.
+
+ It is not part of the Maven build (at this time).
+
+ It is set up with launchers for use within the Eclipse
+ IDE. There are 2 launchers - one creates Java code
+ for uimaj-tools: jcasgen: JCasTypeTemplate.java, the other
+ for uimaj-tools: jcasgen: JCas_TypeTemplate.java.
+
+ When the tool is run, the output is generated back
+ into the original uimaj-tools jcasgen source as
+ JCasTypeTemplate.java and
+ JCas_TypeTemplate.java. After running, compare
+ these to the existing versions to insure correctness,
+ (use Eclipse's compare with local history).
+
+ The Expander code handles the apache 2 licensing
+ and inserts the license in the target.
Added: incubator/uima/uimaj/trunk/src/org/apache/uima/util/jet/JetExpander.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/src/org/apache/uima/util/jet/JetExpander.java?view=auto&rev=490059
==============================================================================
--- incubator/uima/uimaj/trunk/src/org/apache/uima/util/jet/JetExpander.java (added)
+++ incubator/uima/uimaj/trunk/src/org/apache/uima/util/jet/JetExpander.java Sun Dec 24 11:16:49 2006
@@ -0,0 +1,251 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.util.jet;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+
+public class JetExpander {
+
+ static final String APACHE_2_LICENSE_HEADER =
+ "/*\n" +
+" * Licensed to the Apache Software Foundation (ASF) under one\n" +
+" * or more contributor license agreements. See the NOTICE file\n" +
+" * distributed with this work for additional information\n" +
+" * regarding copyright ownership. The ASF licenses this file\n" +
+" * to you under the Apache License, Version 2.0 (the\n" +
+" * \"License\"); you may not use this file except in compliance\n" +
+" * with the License. You may obtain a copy of the License at\n" +
+" * \n" +
+" * http://www.apache.org/licenses/LICENSE-2.0\n" +
+" * \n" +
+" * Unless required by applicable law or agreed to in writing,\n" +
+" * software distributed under the License is distributed on an\n" +
+" * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" +
+" * KIND, either express or implied. See the License for the\n" +
+" * specific language governing permissions and limitations\n" +
+" * under the License.\n" +
+" */\n\n";
+
+ static class ErrorExit extends RuntimeException {
+ String msg;
+ ErrorExit(String msg) {
+ super();
+ this.msg = msg;
+ System.err.println("JetExpander error: " + msg);
+ }
+ }
+
+ FileWriter fileWriter;
+ String outDir;
+ String in;
+ String rootDir;
+
+ public static void main(String[] args) {
+ // arg 1 = source
+ // arg 2 = dir where output goes
+ JetExpander je = new JetExpander();
+ je.main1(args);
+ }
+
+ void main1(String[] args) {
+ try {
+ if (args.length != 2)
+ throw new ErrorExit("Bad Arguments - need 2, source, and output directory.");
+
+ File inputFile = new File(args[0]);
+ outDir = args[1];
+ try {
+ rootDir = pathOnly(inputFile.getCanonicalPath());
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ throw new ErrorExit("trouble getting input file canonical path.");
+ }
+
+ in = readFile(args[0]);
+ int i;
+ try {
+ i = outputStart();
+ expand(i);
+ fileWriter.write("\n return stringBuffer.toString();\n }\n}");
+ fileWriter.close();
+ } catch (IOException e2) {
+ e2.printStackTrace();
+ throw new ErrorExit("IO error writing output file startup.");
+ }
+ }
+ catch (ErrorExit e) {
+ }
+ }
+
+ String readFile(String fileName) {
+
+ char [] buffer;
+
+ try {
+ File file = new File((new File(fileName)).getCanonicalPath());
+
+ FileReader fileReader = new FileReader(file.getCanonicalPath());
+ int fileLength = (int)file.length();
+ buffer = new char [fileLength];
+ int charsRead = fileReader.read(buffer);
+ if (charsRead != fileLength)
+ throw new ErrorExit("Read different length than whats in the file.");
+
+ return new String(buffer).replaceAll("\\r",""); // for linux/unix
+// return new String(buffer);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ throw new ErrorExit("Bad Input File - can't read it: '" + fileName + "'");
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new ErrorExit("IO Error reading input file: '" + fileName + "'");
+ }
+ }
+
+ String pathOnly(String f) {
+ int lastSep = f.lastIndexOf(File.separatorChar);
+ return f.substring(0, lastSep);
+ }
+
+ int outputStart() throws IOException {
+
+ String p1 = "<%@ jet package=\"";
+ int i = in.indexOf(p1);
+ if (i < 0 )
+ throw new ErrorExit("Cant find the <% jet package= sequence.");
+ i = i + p1.length();
+ int nextQuotePos = in.indexOf('"',i);
+ String pkg = in.substring(i,nextQuotePos);
+
+ String p2 = "imports=\"";
+ i = in.indexOf(p2, nextQuotePos) + p2.length();
+ nextQuotePos = in.indexOf('"',i);
+ String [] imports = in.substring(i, nextQuotePos).split("\\s+");
+
+ String p3 = "class=\"";
+ i = in.indexOf(p3, nextQuotePos) + p3.length();
+ nextQuotePos = in.indexOf('"',i);
+ String className = in.substring(i, nextQuotePos);
+
+ String outFileName = null;
+ try {
+ outFileName = outDir + File.separator + pkg.replaceAll("\\.","\\\\") + File.separator + className + ".java";
+ (new File(pathOnly(outFileName))).mkdirs();
+ fileWriter = new FileWriter(outFileName);
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ throw new ErrorExit(
+ "Bad outputFile - can't open for writing: '" + outFileName + "'");
+ }
+ fileWriter.write(APACHE_2_LICENSE_HEADER);
+ fileWriter.write("package " + pkg + ";\n\n");
+
+ for (int j = 0; j < imports.length; j++) {
+ fileWriter.write("import " + imports[j] + ";\n");
+ }
+
+ fileWriter.write("\npublic class " + className + " {\n\n");
+ fileWriter.write(" public String generate(Object argument) {\n");
+ fileWriter.write(" StringBuffer stringBuffer = new StringBuffer();\n");
+
+ return in.indexOf('\n', nextQuotePos);
+ }
+
+ String fixupStr (int start, int end) {
+ // for linux - have to remove the backslash-r sequence
+ return in.substring(start, end).replaceAll("\n","\\\\n").replaceAll("\r","")
+ .replaceAll("\"","\\\\\"")
+ ;
+ }
+
+ void expand (int i) throws IOException{
+ for (; i < in.length(); ) {
+ int trigger = in.indexOf("<%",i);
+ if (trigger >= 0) {
+
+// String [] lines = in.substring(i,trigger).split("\n",-1);
+// for (int j = 0; j < lines.length; j++) {
+// fileWriter.write("\n stringBuffer.append(\"" + lines[j] +
+// ((j < lines.length-1) ? "\\n" : "") + "\");");
+// }
+ fileWriter.write("\n stringBuffer.append(\"" + fixupStr(i, trigger) + "\");");
+
+ if (in.charAt(trigger+2) == '@') {
+ i = doInclude(trigger+3);
+ continue;
+ }
+
+ if (in.charAt(trigger+2) == '=') {
+ i = doInsert(trigger+3);
+ continue;
+ }
+
+ //fileWriter.write("\n ");
+ int triggerEnd = in.indexOf("%>",trigger+2);
+ fileWriter.write("\n " + in.substring(trigger+2, triggerEnd));
+ i = triggerEnd+2;
+ if (in.charAt(i) == '\n')
+ i += 1;
+
+ continue;
+ }
+ else {
+ fileWriter.write("\n stringBuffer.append(\"" + fixupStr(i, in.length()) + "\");");
+ break;
+ }
+ }
+ }
+
+ int doInclude(int i) throws IOException {
+ final String p1 = " include file=\"";
+ String savedIn = in;
+
+ if (!in.substring(i, i + p1.length()).equals(p1)) {
+ throw new ErrorExit("bad include: " + in.substring(i, i+100));
+ }
+ i = i + p1.length();
+ int includeEnd = in.indexOf("\"", i);
+ String includeFileName = in.substring(i, includeEnd);
+ String savedUserDir = System.getProperty("user.dir");
+ System.setProperty("user.dir", rootDir);
+ in = readFile(includeFileName);
+ // strip off headers
+ int endLoc = in.indexOf("*/");
+ if (endLoc < 0)
+ throw new ErrorExit("Missing initial comment in included file " + includeFileName);
+ in = in.substring(endLoc + 3); // skip over */ plus nl
+ expand(0);
+ System.setProperty("user.dir", savedUserDir);
+ in = savedIn;
+ i = in.indexOf("%>", includeEnd) + 2;
+ if (in.charAt(i) == '\n')
+ i += 1;
+ return i;
+ }
+
+ int doInsert(int i) throws IOException {
+ int insertEnd = in.indexOf("%>", i);
+ fileWriter.write("\n stringBuffer.append(" + in.substring(i, insertEnd) + ");");
+ return insertEnd + 2;
+ }
+}