You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2013/04/01 18:27:18 UTC
svn commit: r1463190 - in /uima/sandbox/textmarker/trunk/textmarker-ep-ide:
./ src/main/java/org/apache/uima/textmarker/ide/
src/main/java/org/apache/uima/textmarker/ide/launching/
src/main/java/org/apache/uima/textmarker/ide/ui/wizards/
Author: pkluegl
Date: Mon Apr 1 16:27:17 2013
New Revision: 1463190
URL: http://svn.apache.org/r1463190
Log:
UIMA-2519
- started by adding some classes (not working yet)
Added:
uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConfigurationDelegate2.java
uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConstants.java
uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLauncher.java
uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerJavaContainerPage.java
Modified:
uima/sandbox/textmarker/trunk/textmarker-ep-ide/plugin.xml
uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/TextMarkerIdePlugin.java
Modified: uima/sandbox/textmarker/trunk/textmarker-ep-ide/plugin.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-ide/plugin.xml?rev=1463190&r1=1463189&r2=1463190&view=diff
==============================================================================
--- uima/sandbox/textmarker/trunk/textmarker-ep-ide/plugin.xml (original)
+++ uima/sandbox/textmarker/trunk/textmarker-ep-ide/plugin.xml Mon Apr 1 16:27:17 2013
@@ -1439,5 +1439,21 @@ under the License.
id="org.apache.uima.textmarker.ide.validator.checkvalidator"
nature="org.apache.uima.textmarker.ide.nature">
</validatorType>
- </extension>
+ </extension>
+ <extension
+ point="org.eclipse.dltk.ui.buildpathContainerPage">
+ <buildpathContainerPage
+ class="org.apache.uima.textmarker.ide.ui.wizards.TextMarkerJavaContainerPage"
+ id="org.apache.uima.textmarker.ide.java.page"
+ name="Java"
+ nature="org.apache.uima.textmarker.ide.nature">
+ </buildpathContainerPage>
+ </extension>
+ <extension
+ point="org.eclipse.dltk.launching.buildpathProviders">
+ <buildpathProvider
+ class="abstractinterpreterinstalltype.AbstractInterpreterInstallType1"
+ id="textmarker-ep-ide.buildpathProvider1">
+ </buildpathProvider>
+ </extension>
</plugin>
Modified: uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/TextMarkerIdePlugin.java
URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/TextMarkerIdePlugin.java?rev=1463190&r1=1463189&r2=1463190&view=diff
==============================================================================
--- uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/TextMarkerIdePlugin.java (original)
+++ uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/TextMarkerIdePlugin.java Mon Apr 1 16:27:17 2013
@@ -26,6 +26,7 @@ import java.util.List;
import org.apache.uima.textmarker.ide.ui.text.TextMarkerTextTools;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.dltk.core.environment.IDeployment;
import org.eclipse.dltk.core.environment.IExecutionEnvironment;
@@ -37,7 +38,9 @@ import org.eclipse.ui.IWorkbenchListener
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.service.packageadmin.PackageAdmin;
/**
* The activator class controls the plug-in life cycle
@@ -49,6 +52,8 @@ public class TextMarkerIdePlugin extends
private TextMarkerTextTools textTools;
+ private BundleContext bundleContext;
+
// The shared instance
private static TextMarkerIdePlugin plugin;
@@ -66,6 +71,7 @@ public class TextMarkerIdePlugin extends
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+ bundleContext = context;
IWorkbench workbench = PlatformUI.getWorkbench();
workbench.addWorkbenchListener(new IWorkbenchListener() {
public boolean preShutdown(IWorkbench workbench, boolean forced) {
@@ -131,6 +137,25 @@ public class TextMarkerIdePlugin extends
IPath path = deployment.add(this.getBundle(), "console");
path.append("ConsoleProxy.tm");
return deployment.getFile(path);
-
+ }
+
+ public Bundle getBundle(String bundleName) {
+ Bundle[] bundles = getBundles(bundleName, null);
+ if (bundles != null && bundles.length > 0)
+ return bundles[0];
+ return null;
+ }
+
+public Bundle[] getBundles(String bundleName, String version) {
+ Bundle[] bundles = Platform.getBundles(bundleName, version);
+ if (bundles != null)
+ return bundles;
+ // Accessing bundle which is not resolved
+ PackageAdmin admin = (PackageAdmin) bundleContext.getService(
+ bundleContext.getServiceReference(PackageAdmin.class.getName()));
+ bundles = admin.getBundles(bundleName, version);
+ if (bundles != null && bundles.length > 0)
+ return bundles;
+ return null;
}
}
Added: uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConfigurationDelegate2.java
URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConfigurationDelegate2.java?rev=1463190&view=auto
==============================================================================
--- uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConfigurationDelegate2.java (added)
+++ uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConfigurationDelegate2.java Mon Apr 1 16:27:17 2013
@@ -0,0 +1,261 @@
+/*
+ * 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.textmarker.ide.launching;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.textmarker.ide.TextMarkerIdePlugin;
+import org.apache.uima.textmarker.ide.core.TextMarkerCorePreferences;
+import org.apache.uima.textmarker.ide.core.builder.TextMarkerProjectUtils;
+import org.eclipse.core.internal.resources.Project;
+import org.eclipse.core.internal.resources.Workspace;
+import org.eclipse.core.resources.IBuildConfiguration;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.IBuildpathEntry;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.ScriptProjectUtil;
+import org.eclipse.dltk.internal.core.ScriptProject;
+import org.eclipse.dltk.launching.AbstractScriptLaunchConfigurationDelegate;
+import org.eclipse.dltk.launching.InterpreterConfig;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.core.JavaProject;
+import org.eclipse.jdt.launching.JavaLaunchDelegate;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.internal.Workbench;
+import org.osgi.framework.Bundle;
+
+public class TextMarkerLaunchConfigurationDelegate2 extends JavaLaunchDelegate {
+
+ @Override
+ public String getProgramArguments(ILaunchConfiguration configuration) throws CoreException {
+ StringBuilder cmdline = new StringBuilder();
+ IScriptProject proj = AbstractScriptLaunchConfigurationDelegate.getScriptProject(configuration);
+
+ String mainScriptAttribute = configuration.getAttribute("mainScript", "");
+ IResource member = proj.getProject().findMember(mainScriptAttribute);
+ IPath projectPath = proj.getResource().getLocation();
+ IPath inputDirPath = projectPath.append(TextMarkerProjectUtils.getDefaultInputLocation());
+ IPath outputDirPath = projectPath.append(TextMarkerProjectUtils.getDefaultOutputLocation());
+ String engine = TextMarkerProjectUtils.getEngineDescriptorPath(member.getLocation(),
+ proj.getProject()).toPortableString();
+
+ File inputDirFile = new File(inputDirPath.toPortableString());
+ File inputFile = new File(inputDirFile, "test.text");
+ URI relativize1 = inputFile.toURI().relativize(inputDirFile.toURI());
+ URI relativize2 = inputDirFile.toURI().relativize(inputFile.toURI());
+
+ // String category = configuration.getCategory();
+ // IFile file = configuration.getFile();
+ // String name = configuration.getName();
+ // ILaunchConfigurationType type = configuration.getType();
+ // IResource[] mappedResources = configuration.getMappedResources();
+ // Map attributes = configuration.getAttributes();
+
+ cmdline.append(TextMarkerLaunchConstants.ARG_DESCRIPTOR + " ");
+ cmdline.append(engine + " ");
+
+ cmdline.append(TextMarkerLaunchConstants.ARG_INPUT_FOLDER + " ");
+ cmdline.append(inputDirPath.toPortableString() + " ");
+
+ cmdline.append(TextMarkerLaunchConstants.ARG_OUTPUT_FOLDER + " ");
+ cmdline.append(outputDirPath.toPortableString() + " ");
+
+ return cmdline.toString();
+ }
+
+ @Override
+ public String getMainTypeName(ILaunchConfiguration configuration) throws CoreException {
+ return "org.apache.uima.textmarker.ide.launching.TextMarkerLauncher";
+ }
+
+ @Override
+ public String[] getClasspath(ILaunchConfiguration configuration) throws CoreException {
+ // The class path already contains the jars which are specified in the Classpath tab
+ List<String> extendedClasspath = new ArrayList<String>();
+ Collections.addAll(extendedClasspath, super.getClasspath(configuration));
+
+ // TODO mixed
+ String projectName = configuration.getAttribute("project", "");
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ IBuildConfiguration[] buildConfigs = project.getBuildConfigs();
+ IProject[] referencedProjects = project.getReferencedProjects();
+ for (IProject iProject : referencedProjects) {
+ Map<QualifiedName, String> persistentProperties = iProject.getPersistentProperties();
+ IProjectNature nature = iProject.getNature("org.eclipse.jdt.core.javanature");
+ if(nature !=null) {
+ IJavaProject javaProject = JavaCore.create(iProject);
+ IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
+ IClasspathEntry[] referencedClasspathEntries = javaProject.getReferencedClasspathEntries();
+ IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true);
+ IPath readOutputLocation = javaProject.readOutputLocation();
+ IClasspathEntry[] readRawClasspath = javaProject.readRawClasspath();
+ IResource findMember = ResourcesPlugin.getWorkspace().getRoot().getFolder(readOutputLocation);
+
+ extendedClasspath.add(findMember.getLocation().toPortableString());
+
+ }
+ }
+ IScriptProject scriptProject = DLTKCore.create(project);
+ IBuildpathEntry[] rawBuildpath = scriptProject.getRawBuildpath();
+ IBuildpathEntry[] resolvedBuildpath = scriptProject.getResolvedBuildpath(true);
+
+
+ Map attributes = configuration.getAttributes();
+
+ // Normal mode, add the launcher plugin and uima runtime jar to the classpath
+ if (!Platform.inDevelopmentMode()) {
+ try {
+ // Add this plugin jar to the classpath
+ extendedClasspath.add(pluginIdToJarPath(TextMarkerIdePlugin.PLUGIN_ID));
+
+ // UIMA jar should be added the end of the class path, because user uima jars
+ // (maybe a different version) should appear first on the class path
+ extendedClasspath.add(pluginIdToJarPath("org.apache.uima.runtime"));
+ extendedClasspath.add(pluginIdToJarPath("org.apache.uima.textmarker.engine"));
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, TextMarkerIdePlugin.PLUGIN_ID,
+ IStatus.OK, "Failed to compose classpath!", e));
+ }
+ }
+ // When running inside eclipse with PDE in development mode the plugins
+ // are not installed inform of jar files and the classes must be loaded
+ // from the target/classes folder or target/org.apache.uima.runtime.*.jar file
+ else {
+ try {
+ // Add classes folder of this plugin to class path
+ extendedClasspath.add(pluginIdToJarPath(TextMarkerIdePlugin.PLUGIN_ID) + "target/classes");
+
+ // Add org.apache.uima.runtime jar to class path
+ Bundle bundle = TextMarkerIdePlugin.getDefault().getBundle("org.apache.uima.runtime");
+
+ // Ignore the case when runtime bundle does not exist ...
+ if (bundle != null) {
+ Enumeration<?> jarEnum = bundle.findEntries("/", "*.jar", true);
+ if (jarEnum == null) {
+ extendedClasspath.add(pluginIdToJarPath("org.apache.uima.runtime"));
+ }
+ while (jarEnum != null && jarEnum.hasMoreElements()) {
+ URL element = (URL) jarEnum.nextElement();
+ extendedClasspath.add(FileLocator.toFileURL(element).getFile());
+ }
+ }
+
+ // TODO
+
+ // Add org.apache.uima.runtime jar to class path
+ Bundle bundle2 = TextMarkerIdePlugin.getDefault().getBundle(
+ "org.apache.uima.textmarker.engine");
+
+ // Ignore the case when runtime bundle does not exist ...
+ if (bundle2 != null) {
+ Enumeration<?> jarEnum = bundle2.findEntries("/", "*.jar", true);
+ while (jarEnum != null && jarEnum.hasMoreElements()) {
+ URL element = (URL) jarEnum.nextElement();
+ extendedClasspath.add(FileLocator.toFileURL(element).getFile());
+ }
+ }
+
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, TextMarkerIdePlugin.PLUGIN_ID,
+ IStatus.OK, "Failed to compose classpath!", e));
+ }
+ }
+
+ return extendedClasspath.toArray(new String[extendedClasspath.size()]);
+ }
+
+ @Override
+ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch,
+ IProgressMonitor monitor) throws CoreException {
+ // clearOutputFolder();
+ super.launch(configuration, mode, launch, monitor);
+ while (!launch.isTerminated()) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ Thread.interrupted();
+ }
+ }
+ IScriptProject proj = AbstractScriptLaunchConfigurationDelegate.getScriptProject(configuration);
+ IPath projectPath = proj.getResource().getLocation();
+ IPath outputDirPath = projectPath.append(TextMarkerProjectUtils.getDefaultOutputLocation());
+ String outputFolderPath = configuration.getAttribute(
+ TextMarkerLaunchConstants.ARG_OUTPUT_FOLDER, outputDirPath.toPortableString());
+ if (outputFolderPath.length() != 0) {
+ IPath path = Path.fromPortableString(outputFolderPath);
+ IResource result = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(path);
+ if (result != null) {
+ result.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ }
+ }
+ }
+
+ private void clearOutputFolder(File outputDir, boolean recursive) {
+ IPreferenceStore store = TextMarkerIdePlugin.getDefault().getPreferenceStore();
+ boolean clearOutput = store.getBoolean(TextMarkerCorePreferences.PROJECT_CLEAR_OUTPUT);
+ if (clearOutput) {
+ // TODO
+ // List<File> outputFiles = getFiles(outputDir, recursive);
+ // for (File file : outputFiles) {
+ // file.delete();
+ // }
+ // outputFolder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ }
+ }
+
+ private String pluginIdToJarPath(String pluginId) throws IOException {
+ Bundle bundle = TextMarkerIdePlugin.getDefault().getBundle(pluginId);
+ URL url = bundle.getEntry("/");
+ if (url == null) {
+ throw new IOException();
+ }
+ return FileLocator.toFileURL(url).getFile();
+ }
+
+}
Added: uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConstants.java
URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConstants.java?rev=1463190&view=auto
==============================================================================
--- uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConstants.java (added)
+++ uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConstants.java Mon Apr 1 16:27:17 2013
@@ -0,0 +1,39 @@
+/*
+ * 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.textmarker.ide.launching;
+
+public class TextMarkerLaunchConstants {
+
+ public static final String ARG_INPUT_FOLDER = "-inputFolder";
+
+ public static final String ARG_OUTPUT_FOLDER = "-outputFolder";
+
+ public static final String ARG_DESCRIPTOR = "-descriptor";
+
+ public static final String ARG_RECURSIVE = "-inputRecursive";
+
+ public static final String ARG_MODE = "-mode";
+
+ public static final String INPUT_FOLDER = "org.apache.uima.textmarker.ide.launching.inputFolder";
+
+ public static final String OUTPUT_FOLDER = "org.apache.uima.textmarker.ide.launching.outputFolder";
+
+
+}
Added: uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLauncher.java
URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLauncher.java?rev=1463190&view=auto
==============================================================================
--- uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLauncher.java (added)
+++ uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLauncher.java Mon Apr 1 16:27:17 2013
@@ -0,0 +1,194 @@
+/*
+ * 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.textmarker.ide.launching;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.impl.XmiCasDeserializer;
+import org.apache.uima.cas.impl.XmiCasSerializer;
+import org.apache.uima.resource.ResourceConfigurationException;
+import org.apache.uima.resource.ResourceSpecifier;
+import org.apache.uima.textmarker.engine.TextMarkerEngine;
+import org.apache.uima.util.FileUtils;
+import org.apache.uima.util.XMLInputSource;
+import org.apache.uima.util.XMLSerializer;
+import org.apache.uima.util.impl.ProcessTrace_impl;
+import org.xml.sax.SAXException;
+
+public class TextMarkerLauncher {
+
+ private static File descriptor;
+
+ private static File inputFolder;
+
+ private static File outputFolder = null;
+
+ private static boolean inputRecursive = false;
+
+ private static String inputEncoding = java.nio.charset.Charset.defaultCharset().name();
+
+ private static String launchMode = "run";
+
+ private static String view = null;
+
+ private static boolean parseCmdLineArgs(String[] args) {
+ int index = 0;
+ int count = 0;
+ while (index < args.length) {
+ String each = args[index++];
+ if (TextMarkerLaunchConstants.ARG_INPUT_FOLDER.equals(each)) {
+ if (index >= args.length) {
+ return false;
+ }
+ count++;
+ inputFolder = new File(args[index++]);
+ } else if (TextMarkerLaunchConstants.ARG_OUTPUT_FOLDER.equals(each)) {
+ if (index >= args.length) {
+ return false;
+ }
+ outputFolder = new File(args[index++]);
+ } else if (TextMarkerLaunchConstants.ARG_DESCRIPTOR.equals(each)) {
+ if (index >= args.length) {
+ return false;
+ }
+ count++;
+ descriptor = new File(args[index++]);
+ } else if (TextMarkerLaunchConstants.ARG_RECURSIVE.equals(each)) {
+ if (index >= args.length) {
+ return false;
+ }
+ inputRecursive = Boolean.parseBoolean(args[index++]);
+ } else if (TextMarkerLaunchConstants.ARG_RECURSIVE.equals(each)) {
+ if (index >= args.length) {
+ return false;
+ }
+ inputEncoding = args[index++];
+ } else if (TextMarkerLaunchConstants.ARG_MODE.equals(each)) {
+ if (index >= args.length) {
+ return false;
+ }
+ launchMode = args[index++];
+ }
+ }
+ return count ==2;
+ }
+
+ public static void main(String[] args) throws Exception {
+ if (!parseCmdLineArgs(args)) {
+ throw new IllegalArgumentException("Passed arguments are invalid!");
+ }
+ XMLInputSource in = new XMLInputSource(descriptor);
+ ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
+ AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
+ configure(ae);
+ CAS cas = ae.newCAS();
+
+ List<File> inputFiles = getFiles(inputFolder, inputRecursive);
+ for (File file : inputFiles) {
+ processFile(file, ae, cas);
+ }
+
+ ae.collectionProcessComplete(new ProcessTrace_impl());
+ cas.release();
+ ae.destroy();
+ }
+
+ private static void processFile(File file, AnalysisEngine ae, CAS cas) throws IOException,
+ AnalysisEngineProcessException, SAXException {
+
+ if (file.getName().endsWith(".xmi")) {
+ XmiCasDeserializer.deserialize(new FileInputStream(file), cas, true);
+ } else {
+ String document = FileUtils.file2String(file, inputEncoding);
+ cas.setDocumentText(document);
+ }
+
+ ae.process(cas);
+
+ if (outputFolder != null) {
+ File outputFile = getOutputFile(file, inputFolder, outputFolder);
+ writeXmi(cas, outputFile);
+ }
+ cas.reset();
+ }
+
+ private static void configure(AnalysisEngine ae) throws ResourceConfigurationException {
+ if ("debug".equals(launchMode)) {
+ ae.setConfigParameterValue(TextMarkerEngine.CREATE_DEBUG_INFO, true);
+ ae.setConfigParameterValue(TextMarkerEngine.CREATE_MATCH_DEBUG_INFO, true);
+ ae.setConfigParameterValue(TextMarkerEngine.CREATE_PROFILING_INFO, true);
+ ae.setConfigParameterValue(TextMarkerEngine.CREATE_STATISTIC_INFO, true);
+ ae.setConfigParameterValue(TextMarkerEngine.CREATE_CREATED_BY_INFO, true);
+ }
+ ae.reconfigure();
+
+ }
+
+ private static List<File> getFiles(File dir, boolean recusive) {
+ List<File> result = new ArrayList<File>();
+ for (File each : dir.listFiles()) {
+ // TODO: find a solution for this hotfix
+ if (each.getName().endsWith(".svn")) {
+ continue;
+ }
+ result.add(each);
+ if (each.isDirectory() && recusive) {
+ result.addAll(getFiles(each, recusive));
+ }
+ }
+ return result;
+ }
+
+ private static void writeXmi(CAS cas, File file) throws IOException, SAXException {
+ FileOutputStream out = null;
+ try {
+ out = new FileOutputStream(file);
+ XmiCasSerializer ser = new XmiCasSerializer(cas.getTypeSystem());
+ XMLSerializer xmlSer = new XMLSerializer(out, false);
+ ser.serialize(cas, xmlSer.getContentHandler());
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
+ }
+
+ private static File getOutputFile(File inputFile, File inputFolder, File outputFolder) {
+ URI relativize = inputFolder.toURI().relativize(inputFile.toURI());
+ String path = relativize.getPath();
+ if(!path.endsWith(".xmi")) {
+ path += ".xmi";
+ }
+ File result = new File(outputFolder, path);
+ result.getParentFile().mkdirs();
+ return result;
+ }
+
+}
Added: uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerJavaContainerPage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerJavaContainerPage.java?rev=1463190&view=auto
==============================================================================
--- uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerJavaContainerPage.java (added)
+++ uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerJavaContainerPage.java Mon Apr 1 16:27:17 2013
@@ -0,0 +1,55 @@
+/*
+ * 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.textmarker.ide.ui.wizards;
+import org.eclipse.dltk.core.IBuildpathEntry;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.internal.ui.wizards.IBuildpathContainerPage;
+import org.eclipse.dltk.ui.wizards.IBuildpathContainerPageExtension;
+import org.eclipse.dltk.ui.wizards.NewElementWizardPage;
+import org.eclipse.swt.widgets.Composite;
+
+
+public class TextMarkerJavaContainerPage extends NewElementWizardPage implements IBuildpathContainerPage, IBuildpathContainerPageExtension{
+
+ public TextMarkerJavaContainerPage() {
+ super("TextMarkerJavaContainerPage");
+ }
+
+ public void createControl(Composite composite) {
+
+ }
+
+ public void initialize(IScriptProject project, IBuildpathEntry[] currentEntries) {
+
+ }
+
+ public boolean finish() {
+ return false;
+ }
+
+ public IBuildpathEntry getSelection() {
+ return null;
+ }
+
+ public void setSelection(IBuildpathEntry containerEntry) {
+ }
+
+
+}