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/09/09 15:05:39 UTC
svn commit: r1521088 - in /uima/sandbox/ruta/trunk: ruta-ep-engine/
ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/
ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/
ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist...
Author: pkluegl
Date: Mon Sep 9 13:05:39 2013
New Revision: 1521088
URL: http://svn.apache.org/r1521088
Log:
UIMA-3255
- activated autocompletion of uimaFIT components again, this time with spring instead of reflections
- fixed autocompletion of scripts
Modified:
uima/sandbox/ruta/trunk/ruta-ep-engine/pom.xml
uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/RutaIdeCorePlugin.java
uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaCompletionEngine.java
uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java
Modified: uima/sandbox/ruta/trunk/ruta-ep-engine/pom.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-engine/pom.xml?rev=1521088&r1=1521087&r2=1521088&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-engine/pom.xml (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-engine/pom.xml Mon Sep 9 13:05:39 2013
@@ -217,7 +217,8 @@ licensed under the Common Public License
org.apache.commons.lang3.*,
org.apache.commons.io.*,
org.apache.uima.fit.*,
- org.apache.commons.math3.*
+ org.apache.commons.math3.*,
+ org.springframework.*
</_exportcontents>
<Import-Package>
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g?rev=1521088&r1=1521087&r2=1521088&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g Mon Sep 9 13:05:39 2013
@@ -2053,11 +2053,15 @@ dottedComponentDeclaration returns [Comp
:
id = Identifier {
ct = new CommonToken(id);
+ ref = StatementFactory.createComponentDeclaration(ct);
}
(
- dot = (DOT | MINUS) {ct.setText(ct.getText() + dot.getText());}
+ {(input.get(id.getTokenIndex()+1).getChannel() != Token.HIDDEN_CHANNEL)}?
+ dot = (DOT | MINUS) {ct.setText(ct.getText() + dot.getText());ref = StatementFactory.createComponentDeclaration(ct);}
+ {(input.get(dot.getTokenIndex()+1).getChannel() != Token.HIDDEN_CHANNEL)}?
id = Identifier {ct.setStopIndex(getBounds(id)[1]);
- ct.setText(ct.getText() + id.getText());}
+ ct.setText(ct.getText() + id.getText());
+ ref = StatementFactory.createComponentDeclaration(ct);}
)*
{
if (!ct.getText().equals("<missing Identifier>")) ref = StatementFactory.createComponentDeclaration(ct);}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/RutaIdeCorePlugin.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/RutaIdeCorePlugin.java?rev=1521088&r1=1521087&r2=1521088&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/RutaIdeCorePlugin.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/RutaIdeCorePlugin.java Mon Sep 9 13:05:39 2013
@@ -20,15 +20,20 @@
package org.apache.uima.ruta.ide;
import java.io.IOException;
+import java.net.URL;
+import org.eclipse.core.runtime.FileLocator;
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;
import org.eclipse.dltk.core.environment.IFileHandle;
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
@@ -41,6 +46,8 @@ public class RutaIdeCorePlugin extends A
// The shared instance
private static RutaIdeCorePlugin plugin;
+ private BundleContext bundleContext;
+
/**
* The constructor
*/
@@ -54,6 +61,7 @@ public class RutaIdeCorePlugin extends A
*/
public void start(BundleContext context) throws Exception {
super.start(context);
+ bundleContext = context;
plugin = this;
}
@@ -90,5 +98,34 @@ public class RutaIdeCorePlugin extends A
path.append("ConsoleProxy.ruta");
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;
+ }
+
+ public String pluginIdToJarPath(String pluginId) throws IOException {
+ Bundle bundle = getBundle(pluginId);
+ URL url = bundle.getEntry("/");
+ if (url == null) {
+ throw new IOException();
+ }
+ return FileLocator.toFileURL(url).getFile();
+ }
}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaCompletionEngine.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaCompletionEngine.java?rev=1521088&r1=1521087&r2=1521088&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaCompletionEngine.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaCompletionEngine.java Mon Sep 9 13:05:39 2013
@@ -30,8 +30,10 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.TreeSet;
import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_component.AnalysisComponent;
import org.apache.uima.resource.ResourceManager;
import org.apache.uima.resource.metadata.TypeDescription;
import org.apache.uima.resource.metadata.TypeSystemDescription;
@@ -39,6 +41,7 @@ import org.apache.uima.ruta.ide.RutaIdeC
import org.apache.uima.ruta.ide.core.IRutaKeywords;
import org.apache.uima.ruta.ide.core.RutaExtensionManager;
import org.apache.uima.ruta.ide.core.RutaKeywordsManager;
+import org.apache.uima.ruta.ide.core.RutaNature;
import org.apache.uima.ruta.ide.core.builder.RutaProjectUtils;
import org.apache.uima.ruta.ide.core.extensions.ICompletionExtension;
import org.apache.uima.ruta.ide.core.parser.RutaParseUtils;
@@ -54,7 +57,9 @@ import org.apache.uima.util.XMLInputSour
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.dltk.ast.ASTNode;
@@ -72,6 +77,15 @@ import org.eclipse.dltk.core.ModelExcept
import org.eclipse.dltk.internal.core.SourceField;
import org.eclipse.dltk.internal.core.SourceMethod;
import org.eclipse.dltk.internal.core.SourceModule;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.JavaProject;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.core.type.filter.AssignableTypeFilter;
public class RutaCompletionEngine extends ScriptCompletionEngine {
@@ -127,10 +141,8 @@ public class RutaCompletionEngine extend
if (classloader == null) {
IScriptProject scriptProject = sourceModule.getModelElement().getScriptProject();
try {
- Collection<String> dependencies = new ArrayList<String>();
// TODO UIMA-3077
- // Collection<String> dependencies = RutaLaunchConfigurationDelegate
- // .getClassPath(scriptProject);
+ Collection<String> dependencies = getDependencies(scriptProject.getProject());
URL[] urls = new URL[dependencies.size()];
int counter = 0;
for (String dep : dependencies) {
@@ -142,6 +154,8 @@ public class RutaCompletionEngine extend
// RutaIdeCorePlugin.error(e);
} catch (MalformedURLException e) {
RutaIdeCorePlugin.error(e);
+ } catch (CoreException e) {
+ RutaIdeCorePlugin.error(e);
}
}
@@ -243,7 +257,21 @@ public class RutaCompletionEngine extend
}
} else if (type == ComponentDeclaration.UIMAFIT_ENGINE) {
List<String> engines = new ArrayList<String>();
- // TODO: collect engines
+
+ ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
+ ResourceLoader resourceLoader = new DefaultResourceLoader(classloader);
+ provider.setResourceLoader(resourceLoader);
+ provider.addIncludeFilter(new AssignableTypeFilter(AnalysisComponent.class));
+
+ String pack = complString.replaceAll("[.]", "/");
+ if(pack.endsWith("/")) {
+ pack = pack.substring(0, pack.length()-1);
+ }
+ Set<BeanDefinition> components = provider.findCandidateComponents(pack);
+ for (BeanDefinition component : components) {
+ String beanClassName = component.getBeanClassName();
+ engines.add(beanClassName);
+ }
for (String string : engines) {
if (match(complString, string)) {
addProposal(complString, string, CompletionProposal.PACKAGE_REF);
@@ -343,7 +371,7 @@ public class RutaCompletionEngine extend
result.addAll(collectScripts(folder2, newPrefix));
} else if (iResource instanceof IFile) {
IFile file = (IFile) iResource;
- if (file.getFileExtension().equals("tm")) {
+ if (file.getFileExtension().equals("ruta")) {
result.add(prefix + file.getName().substring(0, file.getName().length() - 5));
}
}
@@ -639,4 +667,68 @@ public class RutaCompletionEngine extend
findKeywords(startPart.toCharArray(), keywords.toArray(new String[0]), true);
}
+ public static List<String> getClassPath(IScriptProject project) throws CoreException {
+ List<String> extendedClasspath = new ArrayList<String>();
+ Collection<String> dependencies = getDependencies(project.getProject());
+ extendedClasspath.addAll(dependencies);
+ return extendedClasspath;
+ }
+
+ private static Collection<String> getDependencies(IProject project) throws CoreException {
+ Collection<String> result = new TreeSet<String>();
+ IProject[] referencedProjects = project.getReferencedProjects();
+ for (IProject eachProject : referencedProjects) {
+ // for each java project
+ extendClasspathWithProject(result, eachProject, new HashSet<IProject>());
+ IProjectNature nature = eachProject.getNature(RutaNature.NATURE_ID);
+ if (nature != null) {
+ result.addAll(getDependencies(eachProject));
+ }
+ }
+ return result;
+ }
+
+ private static void extendClasspathWithProject(Collection<String> result, IProject project,
+ Collection<IProject> visited) throws CoreException, JavaModelException {
+ IProjectNature nature = project.getNature(RutaProjectUtils.JAVANATURE);
+ if (nature != null) {
+ JavaProject javaProject = (JavaProject) JavaCore.create(project);
+
+ // add output, e.g., target/classes
+ IPath readOutputLocation = javaProject.readOutputLocation();
+ IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(readOutputLocation);
+ result.add(folder.getLocation().toPortableString());
+
+ IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
+ for (IClasspathEntry each : rawClasspath) {
+ int entryKind = each.getEntryKind();
+ IPath path = each.getPath();
+ if (entryKind == IClasspathEntry.CPE_PROJECT) {
+ IProject p = RutaProjectUtils.getProject(path);
+ if (!visited.contains(p)) {
+ visited.add(p);
+ extendClasspathWithProject(result, p, visited);
+ }
+ } else if (entryKind != IClasspathEntry.CPE_SOURCE) {
+ String segment = path.segment(0);
+ if (!segment.equals("org.eclipse.jdt.launching.JRE_CONTAINER")) {
+ IClasspathEntry[] resolveClasspath = javaProject
+ .resolveClasspath(new IClasspathEntry[] { each });
+ for (IClasspathEntry eachResolved : resolveClasspath) {
+ if (eachResolved.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
+ IProject p = RutaProjectUtils.getProject(eachResolved.getPath());
+ if (!visited.contains(p)) {
+ visited.add(p);
+ extendClasspathWithProject(result, p, visited);
+ }
+ } else {
+ result.add(eachResolved.getPath().toPortableString());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java?rev=1521088&r1=1521087&r2=1521088&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java Mon Sep 9 13:05:39 2013
@@ -322,7 +322,8 @@ public class StatementFactory extends Ab
public static ComponentDeclaration createComponentDeclaration(CommonToken ct) {
int nameBounds[] = getBounds(ct);
- return new ComponentDeclaration(nameBounds[0], nameBounds[1], ct.getText());
+ String text = ct.getText();
+ return new ComponentDeclaration(nameBounds[0], nameBounds[0] + text.length(), text);
}
}