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 2016/07/22 13:45:37 UTC
svn commit: r1753793 - in /uima/uimaj/trunk/uimaj-ep-cas-editor: pom.xml
src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java
Author: pkluegl
Date: Fri Jul 22 13:45:37 2016
New Revision: 1753793
URL: http://svn.apache.org/viewvc?rev=1753793&view=rev
Log:
UIMA-5021
- use java project classpath in ResourceManager
Modified:
uima/uimaj/trunk/uimaj-ep-cas-editor/pom.xml
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/pom.xml
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/pom.xml?rev=1753793&r1=1753792&r2=1753793&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/pom.xml (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/pom.xml Fri Jul 22 13:45:37 2016
@@ -150,6 +150,13 @@
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.eclipse.jdt</groupId>
+ <artifactId>launching</artifactId>
+ <version>[3.3.0,6.0.0)</version>
+ <scope>provided</scope>
+ </dependency>
+
<!-- https://issues.apache.org/jira/browse/UIMA-3510 -->
<dependency>
<groupId>org.eclipse.equinox</groupId>
@@ -223,6 +230,7 @@
org.eclipse.ui.workbench,
org.eclipse.core.runtime,
org.eclipse.core.resources,
+ org.eclipse.jdt.core,
org.junit4;bundle-version="4.5.0";resolution:=optional
</Require-Bundle>
<Import-Package>
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java?rev=1753793&r1=1753792&r2=1753793&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DocumentUimaImpl.java Fri Jul 22 13:45:37 2016
@@ -25,8 +25,13 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
+import java.util.List;
import org.apache.uima.ResourceSpecifierFactory;
import org.apache.uima.UIMAFramework;
@@ -42,6 +47,7 @@ import org.apache.uima.caseditor.CasEdit
import org.apache.uima.caseditor.editor.util.StrictTypeConstraint;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.impl.ResourceManager_impl;
import org.apache.uima.resource.metadata.FsIndexDescription;
import org.apache.uima.resource.metadata.TypePriorities;
import org.apache.uima.resource.metadata.TypeSystemDescription;
@@ -53,11 +59,16 @@ import org.apache.uima.util.XMLInputSour
import org.apache.uima.util.XMLParser;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.core.JavaProject;
+import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jface.preference.IPreferenceStore;
/**
@@ -65,6 +76,8 @@ import org.eclipse.jface.preference.IPre
*/
public class DocumentUimaImpl extends AbstractDocument {
+ public static final String JAVA_NATURE = "org.eclipse.jdt.core.javanature";
+
private CAS mCAS;
private SerialFormat format = SerialFormat.XMI;
@@ -279,8 +292,17 @@ public class DocumentUimaImpl extends Ab
try {
typeSystemDesciptor = (TypeSystemDescription) xmlParser.parse(xmlTypeSystemSource);
- ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager();
- String dataPath = typeSystemFile.getProject()
+ IProject project = typeSystemFile.getProject();
+ ClassLoader classLoader = getProjectClassLoader(project);
+
+ ResourceManager resourceManager = null;
+ if(classLoader != null) {
+ resourceManager = new ResourceManager_impl(classLoader);
+ } else {
+ resourceManager = UIMAFramework.newDefaultResourceManager();
+ }
+
+ String dataPath = project
.getPersistentProperty((new QualifiedName("", "CDEdataPath")));
if (dataPath != null) {
resourceManager.setDataPath(dataPath);
@@ -316,6 +338,24 @@ public class DocumentUimaImpl extends Ab
return cas;
}
-
+ public static ClassLoader getProjectClassLoader(IProject project) throws CoreException {
+ IProjectNature javaNature = project.getNature(JAVA_NATURE);
+ if (javaNature != null) {
+ JavaProject javaProject = (JavaProject) JavaCore.create(project);
+
+ String[] runtimeClassPath = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
+ List<URL> urls = new ArrayList<>();
+ for (int i = 0; i < runtimeClassPath.length; i++) {
+ String cp = runtimeClassPath[i];
+ try {
+ urls.add(Paths.get(cp).toUri().toURL());
+ } catch (MalformedURLException e) {
+ CasEditorPlugin.log(e);
+ }
+ }
+ return new URLClassLoader(urls.toArray(new URL[0]));
+ }
+ return null;
+ }
}