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 2014/03/19 18:56:46 UTC

svn commit: r1579326 - in /uima/ruta/trunk: ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/ ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/ ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/ ruta-ep-ide/...

Author: pkluegl
Date: Wed Mar 19 17:56:46 2014
New Revision: 1579326

URL: http://svn.apache.org/r1579326
Log:
UIMA-3668
- moved classpath calc to ide-core
- include (not import) type system imported from maven dependencies
- adapted language checker
- adapted autocompletion

Modified:
    uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/RutaLaunchConfigurationDelegate.java
    uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardFirstPage.java
    uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java
    uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java
    uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java
    uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaLanguageChecker.java
    uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaBuilder.java
    uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaProjectUtils.java
    uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaSimpleBuilder.java
    uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaCompletionEngine.java
    uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java

Modified: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/RutaLaunchConfigurationDelegate.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/RutaLaunchConfigurationDelegate.java?rev=1579326&r1=1579325&r2=1579326&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/RutaLaunchConfigurationDelegate.java (original)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/RutaLaunchConfigurationDelegate.java Wed Mar 19 17:56:46 2014
@@ -28,7 +28,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
-import java.util.HashSet;
 import java.util.List;
 import java.util.TreeSet;
 
@@ -37,12 +36,8 @@ import org.apache.uima.cas.CAS;
 import org.apache.uima.ruta.ide.RutaIdeCorePlugin;
 import org.apache.uima.ruta.ide.RutaIdeUIPlugin;
 import org.apache.uima.ruta.ide.core.RutaCorePreferences;
-import org.apache.uima.ruta.ide.core.RutaNature;
 import org.apache.uima.ruta.ide.core.builder.RutaProjectUtils;
 import org.eclipse.core.internal.resources.Folder;
-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;
@@ -57,13 +52,8 @@ import org.eclipse.core.runtime.Platform
 import org.eclipse.core.runtime.Status;
 import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.dltk.core.DLTKCore;
 import org.eclipse.dltk.core.IScriptProject;
 import org.eclipse.dltk.launching.AbstractScriptLaunchConfigurationDelegate;
-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.eclipse.jdt.launching.JavaLaunchDelegate;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.osgi.framework.Bundle;
@@ -210,10 +200,9 @@ public class RutaLaunchConfigurationDele
               "Failed to compose classpath!", e));
     }
     
-    extendClasspathWithProject(extendedClasspath, project.getProject(), new HashSet<IProject>());
-
-    Collection<String> dependencies = getDependencies(project.getProject());
-    extendedClasspath.addAll(dependencies);
+    
+    Collection<String> classPath = RutaProjectUtils.getClassPath(project.getProject());
+    extendedClasspath.addAll(classPath);
 
     Collection<String> extensions = getExtensions();
     extendedClasspath.addAll(extensions);
@@ -267,78 +256,6 @@ public class RutaLaunchConfigurationDele
     }
   }
 
-  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 rutaNature = project.getNature(RutaNature.NATURE_ID);
-    if (rutaNature != null) {
-      IScriptProject sp = DLTKCore.create(project);
-      List<IFolder> scriptFolders = RutaProjectUtils.getScriptFolders(sp);
-      for (IFolder each : scriptFolders) {
-        result.add(each.getLocation().toPortableString());
-      }
-      List<IFolder> descriptorFolders = RutaProjectUtils.getDescriptorFolders(project);
-      for (IFolder each : descriptorFolders) {
-        result.add(each.getLocation().toPortableString());
-      }
-      IFolder resourceFolder = project.getFolder(RutaProjectUtils.getDefaultResourcesLocation());
-      if(resourceFolder != null && resourceFolder.exists()) {
-        result.add(resourceFolder.getLocation().toPortableString());
-      }
-    }
-    IProjectNature javaNature = project.getNature(RutaProjectUtils.JAVANATURE);
-    if (javaNature != 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());
-              }
-            }
-          }
-        }
-      }
-    }
-  }
 
   @Override
   public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch,

Modified: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardFirstPage.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardFirstPage.java?rev=1579326&r1=1579325&r2=1579326&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardFirstPage.java (original)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardFirstPage.java Wed Mar 19 17:56:46 2014
@@ -20,10 +20,7 @@
 package org.apache.uima.ruta.ide.ui.wizards;
 
 import org.eclipse.dltk.ui.wizards.ProjectWizardFirstPage;
-import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
 
 final class RutaProjectWizardFirstPage extends ProjectWizardFirstPage {
 

Modified: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java?rev=1579326&r1=1579325&r2=1579326&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java (original)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java Wed Mar 19 17:56:46 2014
@@ -19,9 +19,9 @@
 
 package org.apache.uima.ruta.ide.validator;
 
-import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -38,6 +38,7 @@ import org.antlr.runtime.Token;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.uima.UIMAFramework;
 import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.impl.ResourceManager_impl;
 import org.apache.uima.resource.metadata.FeatureDescription;
 import org.apache.uima.resource.metadata.TypeDescription;
 import org.apache.uima.resource.metadata.TypeSystemDescription;
@@ -182,13 +183,15 @@ public class LanguageCheckerVisitor exte
 
   private String parentTypeInDeclaration;
 
+  private ClassLoader classLoader;
+
   public LanguageCheckerVisitor(IProblemReporter problemReporter, ISourceLineTracker linetracker,
-          ISourceModule sourceModule) {
+          ISourceModule sourceModule, ClassLoader classLoader) {
     super();
     this.pr = problemReporter;
     this.linetracker = linetracker;
     this.sourceModule = sourceModule;
-
+    this.classLoader = classLoader;
     this.problemFactory = new RutaCheckerProblemFactory(sourceModule.getElementName(), linetracker);
 
     namespaces = new TreeMap<String, String>();
@@ -241,14 +244,19 @@ public class LanguageCheckerVisitor exte
 
         // HOTFIX Peter add also the imported types of the imported type system!
         try {
-          IFile iFile = RutaCheckerUtils.checkScriptImport(localPath,
+          URL url = null;
+          IFile file = RutaCheckerUtils.checkScriptImport(localPath,
                   sourceModule.getScriptProject());
-          if (iFile == null) {
+          if (file == null) {
+            url = RutaCheckerUtils.checkImportExistence(localPath + "TypeSystem", "xml",
+                    classLoader);
+          }
+          if (file == null && url == null) {
             pr.reportProblem(problemFactory.createFileNotFoundProblem(sRef, localPath));
           } else {
             IPath typeSystemDescriptorPath = RutaProjectUtils.getTypeSystemDescriptorPath(
-                    iFile.getLocation(), sourceModule.getScriptProject().getProject());
-            TypeSystemDescription tsDesc = importCompleteTypeSystem(typeSystemDescriptorPath);
+                    file.getLocation(), sourceModule.getScriptProject().getProject());
+            TypeSystemDescription tsDesc = importCompleteTypeSystem(typeSystemDescriptorPath, url);
 
             List<String> checkDuplicateShortNames = checkOnAmbiguousShortNames(tsDesc);
             if (!checkDuplicateShortNames.isEmpty()) {
@@ -385,14 +393,17 @@ public class LanguageCheckerVisitor exte
   private void processCompleteTypeSystemImport(SimpleReference sRef, String localPath,
           Token typeToken, Token pkgToken, Token aliasToken) throws CoreException {
     try {
-      IFile ifile = RutaCheckerUtils.checkTypeSystemImport(localPath,
+      URL url = null;
+      IFile file = RutaCheckerUtils.checkTypeSystemImport(localPath,
               sourceModule.getScriptProject());
-      if (ifile == null) {
+      if (file == null) {
+        url = RutaCheckerUtils.checkImportExistence(localPath, "xml", classLoader);
+      }
+      if (file == null && url == null) {
         pr.reportProblem(problemFactory.createFileNotFoundProblem(sRef, localPath));
       } else {
-        IPath location = ifile.getLocation();
-        TypeSystemDescription tsDesc = importTypeSystem(location, typeToken, pkgToken, aliasToken);
-
+        IPath path = file == null ? null : file.getLocation();
+        TypeSystemDescription tsDesc = importTypeSystem(path, url, typeToken, pkgToken, aliasToken);
         if (reportWarningOnShortNames) {
           List<String> checkDuplicateShortNames = checkOnAmbiguousShortNames(tsDesc);
           if (!checkDuplicateShortNames.isEmpty()) {
@@ -421,13 +432,18 @@ public class LanguageCheckerVisitor exte
     return checkDuplicateShortNames;
   }
 
-  private TypeSystemDescription importTypeSystem(IPath path, Token typeToken, Token pkgToken,
-          Token aliasToken) throws InvalidXMLException, IOException, MalformedURLException,
-          CoreException {
-    File file = path.toFile();
-    TypeSystemDescription tsDesc = UIMAFramework.getXMLParser().parseTypeSystemDescription(
-            new XMLInputSource(file));
-    ResourceManager resMgr = getResourceManager();
+  private TypeSystemDescription importTypeSystem(IPath path, URL url, Token typeToken,
+          Token pkgToken, Token aliasToken) throws InvalidXMLException, IOException,
+          MalformedURLException, CoreException {
+    TypeSystemDescription tsDesc = null;
+    if (path != null) {
+      tsDesc = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+              new XMLInputSource(path.toFile()));
+    } else {
+      tsDesc = UIMAFramework.getXMLParser().parseTypeSystemDescription(new XMLInputSource(url));
+    }
+
+    ResourceManager resMgr = getResourceManager(classLoader);
     tsDesc.resolveImports(resMgr);
     for (TypeDescription each : tsDesc.getTypes()) {
       String longName = each.getName();
@@ -457,9 +473,9 @@ public class LanguageCheckerVisitor exte
     return tsDesc;
   }
 
-  private ResourceManager getResourceManager() throws MalformedURLException, CoreException {
+  private ResourceManager getResourceManager(ClassLoader classloader) throws MalformedURLException, CoreException {
     if (resourceManager == null) {
-      resourceManager = UIMAFramework.newDefaultResourceManager();
+      resourceManager = new ResourceManager_impl(classloader);
       List<IFolder> folders = RutaProjectUtils.getAllDescriptorFolders(sourceModule
               .getScriptProject().getProject());
       StringBuilder sb = new StringBuilder();
@@ -917,7 +933,7 @@ public class LanguageCheckerVisitor exte
       IPath descriptorRootPath = RutaProjectUtils.getDescriptorRootPath(sourceModule
               .getScriptProject().getProject());
       IPath basicTSD = descriptorRootPath.append("BasicTypeSystem.xml");
-      importCompleteTypeSystem(basicTSD);
+      importCompleteTypeSystem(basicTSD, null);
     } catch (Exception e) {
       RutaIdeUIPlugin.error(e);
     }
@@ -965,9 +981,9 @@ public class LanguageCheckerVisitor exte
     }
   }
 
-  private TypeSystemDescription importCompleteTypeSystem(IPath path) throws InvalidXMLException,
-          MalformedURLException, IOException, CoreException {
-    return importTypeSystem(path, null, null, null);
+  private TypeSystemDescription importCompleteTypeSystem(IPath path, URL url)
+          throws InvalidXMLException, MalformedURLException, IOException, CoreException {
+    return importTypeSystem(path, url, null, null, null);
   }
 
   private void initializeExtensionInformation() {
@@ -1189,7 +1205,7 @@ public class LanguageCheckerVisitor exte
     if (descriptorPath.toFile().exists()) {
       typeSysDescr = UIMAFramework.getXMLParser().parseTypeSystemDescription(
               new XMLInputSource(descriptorPath.toPortableString()));
-      ResourceManager resMgr = getResourceManager();
+      ResourceManager resMgr = getResourceManager(classLoader);
       typeSysDescr.resolveImports(resMgr);
     }
     return typeSysDescr;

Modified: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java?rev=1579326&r1=1579325&r2=1579326&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java (original)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java Wed Mar 19 17:56:46 2014
@@ -20,6 +20,7 @@
 package org.apache.uima.ruta.ide.validator;
 
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.lang3.StringUtils;
@@ -67,15 +68,18 @@ public class RutaCheckerProblemFactory i
 
   public IProblem createFileNotFoundProblem(ASTNode fileNode) {
     return createFileNotFoundProblem(fileNode, fileNode.toString());
-    // generateFileNotFoundProblemMsg(fileNode));
   }
 
   public IProblem createDuplicateShortNameInImported(ASTNode node, String localPath,
           List<String> checkDuplicateShortNames, ProblemSeverity severity) {
     StringBuilder sb = new StringBuilder();
-    for (String string : checkDuplicateShortNames) {
+    Iterator<String> iterator = checkDuplicateShortNames.iterator();
+    while (iterator.hasNext()) {
+      String string = (String) iterator.next();
       sb.append(string);
-      sb.append(", ");
+      if(iterator.hasNext()) {
+        sb.append(", ");
+      }
     }
     String msg = String.format(
             "Types in %s share same short name, but with different namespaces: %s.", localPath,

Modified: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java?rev=1579326&r1=1579325&r2=1579326&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java (original)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java Wed Mar 19 17:56:46 2014
@@ -46,6 +46,8 @@ import org.eclipse.dltk.core.IScriptFold
 import org.eclipse.dltk.core.IScriptProject;
 import org.eclipse.dltk.core.ISourceModule;
 import org.eclipse.dltk.core.ModelException;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
 
 public class RutaCheckerUtils {
 
@@ -66,7 +68,8 @@ public class RutaCheckerUtils {
    * @throws ModelException
    */
   public static Set<String> importScript(String path, int type, IScriptProject project,
-          boolean appendPath) throws InvalidXMLException, IOException, ModelException, CoreException {
+          boolean appendPath) throws InvalidXMLException, IOException, ModelException,
+          CoreException {
     Stack<String> namespaceStack = new Stack<String>();
 
     final Set<String> imports = new HashSet<String>();
@@ -177,8 +180,8 @@ public class RutaCheckerUtils {
     }
     for (IFolder folder : allDescriptorFolders) {
       String fileExtended = xmlFilePath.replaceAll("[.]", "/") + ".xml";
-      IFile iFile = RutaCheckerUtils.getFile(folder, fileExtended);
-      result |= iFile.exists();
+      IFile file = RutaCheckerUtils.getFile(folder, fileExtended);
+      result |= file.exists();
     }
     return result;
   }
@@ -209,9 +212,9 @@ public class RutaCheckerUtils {
     }
     for (IFolder folder : allDescriptorFolders) {
       String fileExtended = xmlFilePath.replaceAll("[.]", "/") + RutaEngine.SCRIPT_FILE_EXTENSION;
-      IFile iFile = RutaCheckerUtils.getFile(folder, fileExtended);
-      if(iFile.exists()) {
-        return iFile;
+      IFile file = RutaCheckerUtils.getFile(folder, fileExtended);
+      if (file.exists()) {
+        return file;
       }
     }
     return null;
@@ -277,11 +280,32 @@ public class RutaCheckerUtils {
     }
     for (IFolder folder : allDescriptorFolders) {
       String fileExtended = localPath.replaceAll("[.]", "/") + ".xml";
-      IFile iFile = RutaCheckerUtils.getFile(folder, fileExtended);
-      if(iFile.exists()) {
-        return iFile;
+      IFile file = RutaCheckerUtils.getFile(folder, fileExtended);
+      if (file.exists()) {
+        return file;
       }
     }
     return null;
   }
+
+  public static URL checkImportExistence(String candidate, String extension,
+          ClassLoader classloader) throws IOException {
+    String p = candidate.replaceAll("[.]", "/");
+    p += "." + extension;
+    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(
+            classloader);
+    String prefix = "classpath*:";
+    String pattern = prefix + p;
+    Resource[] resources = resolver.getResources(pattern);
+    if(resources == null || resources.length == 0) {
+      return null;
+    } else {
+      Resource resource = resources[0];
+      URL url = resource.getURL();
+      return url;
+    }
+  }
+
+  
+
 }

Modified: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaLanguageChecker.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaLanguageChecker.java?rev=1579326&r1=1579325&r2=1579326&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaLanguageChecker.java (original)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaLanguageChecker.java Wed Mar 19 17:56:46 2014
@@ -19,7 +19,13 @@
 
 package org.apache.uima.ruta.ide.validator;
 
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Collection;
+
 import org.apache.uima.ruta.ide.RutaIdeUIPlugin;
+import org.apache.uima.ruta.ide.core.builder.RutaProjectUtils;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.dltk.ast.ASTVisitor;
@@ -31,8 +37,8 @@ import org.eclipse.dltk.core.builder.IBu
 import org.eclipse.dltk.core.builder.IBuildParticipantExtension;
 import org.eclipse.dltk.core.builder.ISourceLineTracker;
 
-public class RutaLanguageChecker implements IBuildParticipant, IBuildParticipantExtension{
-  
+public class RutaLanguageChecker implements IBuildParticipant, IBuildParticipantExtension {
+
   public boolean beginBuild(int buildType) {
     return true;
   }
@@ -51,7 +57,17 @@ public class RutaLanguageChecker impleme
     ISourceModule smod = context.getSourceModule();
     ISourceLineTracker linetracker = context.getLineTracker();
     try {
-      ASTVisitor visitor = new LanguageCheckerVisitor(problemReporter, linetracker, smod);
+      Collection<String> dependencies = RutaProjectUtils.getClassPath(smod.getScriptProject()
+              .getProject());
+      URL[] urls = new URL[dependencies.size()];
+      int counter = 0;
+      for (String dep : dependencies) {
+        urls[counter] = new File(dep).toURI().toURL();
+        counter++;
+      }
+      ClassLoader classloader = new URLClassLoader(urls);
+      ASTVisitor visitor = new LanguageCheckerVisitor(problemReporter, linetracker, smod,
+              classloader);
       md.traverse(visitor);
     } catch (Exception e) {
       RutaIdeUIPlugin.error(e);

Modified: uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaBuilder.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaBuilder.java?rev=1579326&r1=1579325&r2=1579326&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaBuilder.java (original)
+++ uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaBuilder.java Wed Mar 19 17:56:46 2014
@@ -19,7 +19,12 @@
 
 package org.apache.uima.ruta.ide.core.builder;
 
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.uima.ruta.engine.RutaEngine;
@@ -42,8 +47,10 @@ import org.eclipse.core.resources.IResou
 import org.eclipse.core.runtime.CoreException;
 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.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
 import org.eclipse.dltk.core.DLTKCore;
@@ -119,7 +126,7 @@ public class RutaBuilder extends Abstrac
   }
 
   private IPath[] generateResources(ModuleDeclaration moduleDeclaration, IPath outputPath,
-          IContainer container, ISourceModule sourceModule) {
+          IContainer container, ISourceModule sourceModule) throws CoreException {
     List<IPath> result = new ArrayList<IPath>();
     if (moduleDeclaration instanceof RutaModuleDeclaration) {
       RutaModuleDeclaration tmmd = (RutaModuleDeclaration) moduleDeclaration;
@@ -167,7 +174,21 @@ public class RutaBuilder extends Abstrac
       if (mainScript.endsWith(RutaEngine.SCRIPT_FILE_EXTENSION)) {
         mainScript = mainScript.substring(0, mainScript.length() - 5);
       }
-      build(basicTS, basicE, typeSystem, engine, sm, mainScript, scriptPaths, descriptorPaths);
+      Collection<String> dependencies = RutaProjectUtils.getClassPath(proj
+              .getProject());
+      URL[] urls = new URL[dependencies.size()];
+      int counter = 0;
+      for (String dep : dependencies) {
+        try {
+          urls[counter] = new File(dep).toURI().toURL();
+        } catch (MalformedURLException e) {
+          throw new CoreException(new Status(IStatus.ERROR,
+                  RutaIdeCorePlugin.PLUGIN_ID, e.getMessage()));
+        }
+        counter++;
+      }
+      ClassLoader classloader = new URLClassLoader(urls);
+      build(basicTS, basicE, typeSystem, engine, sm, mainScript, scriptPaths, descriptorPaths, classloader);
 
       IPath tsPath = Path.fromPortableString(typeSystem);
       IPath ePath = Path.fromPortableString(engine);
@@ -179,7 +200,7 @@ public class RutaBuilder extends Abstrac
 
   private void build(String basicTypesystem, String basicEngine, String typeSystemDest,
           String engineDest, DescriptorManager sm, String mainScript, String[] scriptPaths,
-          String[] enginePaths) {
+          String[] enginePaths, ClassLoader classloader) {
     RutaSimpleBuilder builder = null;
     try {
       builder = new RutaSimpleBuilder(basicTypesystem, basicEngine);
@@ -239,7 +260,7 @@ public class RutaBuilder extends Abstrac
       IPreferenceStore store = RutaIdeCorePlugin.getDefault().getPreferenceStore();
       option.setImportByName(store.getBoolean(RutaCorePreferences.BUILDER_IMPORT_BY_NAME));
       option.setResolveImports(store.getBoolean(RutaCorePreferences.BUILDER_RESOLVE_IMPORTS));
-      builder.build(sm, typeSystemDest, engineDest, option, mainScript, scriptPaths, enginePaths);
+      builder.build(sm, typeSystemDest, engineDest, option, mainScript, scriptPaths, enginePaths, classloader);
     } catch (Exception e) {
       DLTKCore.error(e.getMessage(), e);
       if (DLTKCore.DEBUG_PARSER) {

Modified: uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaProjectUtils.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaProjectUtils.java?rev=1579326&r1=1579325&r2=1579326&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaProjectUtils.java (original)
+++ uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaProjectUtils.java Wed Mar 19 17:56:46 2014
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.TreeSet;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.uima.ruta.engine.RutaEngine;
@@ -44,6 +45,7 @@ import org.eclipse.dltk.core.ModelExcept
 import org.eclipse.jdt.core.IClasspathEntry;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
 import org.eclipse.jdt.internal.core.JavaProject;
 
 public class RutaProjectUtils {
@@ -269,7 +271,88 @@ public class RutaProjectUtils {
     }
     return null;
   }
+  
+  public static Collection<String> getClassPath(IProject project) throws CoreException {
+    Collection<String> result = new TreeSet<String>();
+    extendClasspathWithProject(result, project.getProject(), new HashSet<IProject>());
+    Collection<String> dependencies = getDependencies(project.getProject());
+    result.addAll(dependencies);
+    return result;
+  }
+  
+  private static Collection<String> getDependencies(IProject project) throws CoreException {
+    Collection<String> result = new TreeSet<String>();
+    IProject[] referencedProjects = project.getReferencedProjects();
+    for (IProject eachProject : referencedProjects) {
+      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 rutaNature = project.getNature(RutaNature.NATURE_ID);
+    if (rutaNature != null) {
+      IScriptProject sp = DLTKCore.create(project);
+      List<IFolder> scriptFolders = RutaProjectUtils.getScriptFolders(sp);
+      for (IFolder each : scriptFolders) {
+        result.add(each.getLocation().toPortableString());
+      }
+      List<IFolder> descriptorFolders = RutaProjectUtils.getDescriptorFolders(project);
+      for (IFolder each : descriptorFolders) {
+        result.add(each.getLocation().toPortableString());
+      }
+      IFolder resourceFolder = project.getFolder(RutaProjectUtils.getDefaultResourcesLocation());
+      if(resourceFolder != null && resourceFolder.exists()) {
+        result.add(resourceFolder.getLocation().toPortableString());
+      }
+    }
+    IProjectNature javaNature = project.getNature(RutaProjectUtils.JAVANATURE);
+    if (javaNature != 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());
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+  
+  
   public static String getDefaultInputLocation() {
     return "input";
   }

Modified: uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaSimpleBuilder.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaSimpleBuilder.java?rev=1579326&r1=1579325&r2=1579326&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaSimpleBuilder.java (original)
+++ uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaSimpleBuilder.java Wed Mar 19 17:56:46 2014
@@ -25,6 +25,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -60,6 +61,8 @@ import org.apache.uima.util.XMLSerialize
 import org.apache.uima.util.XMLizable;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
@@ -90,11 +93,11 @@ public class RutaSimpleBuilder {
   }
 
   public void build(DescriptorManager desc, String typeSystemOutput, String engineOutput,
-          RutaBuildOptions option, String mainScript, String[] scriptPaths, String[] enginePaths)
-          throws SAXException, RutaBuildException, InvalidXMLException, IOException,
-          ResourceInitializationException {
+          RutaBuildOptions option, String mainScript, String[] scriptPaths, String[] enginePaths,
+          ClassLoader classloader) throws SAXException, RutaBuildException, InvalidXMLException,
+          IOException, ResourceInitializationException {
 
-    rm = new ResourceManager_impl();
+    rm = new ResourceManager_impl(classloader);
     String dataPath = "";
     for (String string : enginePaths) {
       dataPath += string + File.pathSeparator;
@@ -113,6 +116,7 @@ public class RutaSimpleBuilder {
     CAS cas = CasCreationUtils.createCas(initialTypeSystem, null, new FsIndexDescription[0]);
     fillTypeNameMap(typeNameMap, cas.getTypeSystem());
     cas.release();
+    List<TypeSystemDescription> toInclude = new ArrayList<TypeSystemDescription>();
     List<Import> importList = new ArrayList<Import>();
     Import_impl import_impl = new Import_impl();
     if (option.isImportByName()) {
@@ -129,34 +133,51 @@ public class RutaSimpleBuilder {
     importList.add(import_impl);
     for (String eachName : desc.getImportedTypeSystems()) {
       String locate = RutaEngine.locate(eachName, enginePaths, ".xml");
-      if (locate == null) {
-        throw new FileNotFoundException("Build process can't find " + eachName + " in "
-                + mainScript);
+      URL url = null;
+      boolean include = false;
+      if (locate != null) {
+        File file = new File(locate);
+        url = file.toURI().toURL();
       }
-      File file = new File(locate);
-      TypeSystemDescription each = getTypeSystemDescriptor(file, option);
+      if (url == null) {
+        url = checkImportExistence(eachName, "xml", classloader);
+        include = true;
+        if (url == null) {
+          throw new FileNotFoundException("Build process can't find " + eachName + " in "
+                  + mainScript);
+        }
+      }
+      TypeSystemDescription each = getTypeSystemDescriptor(url, option);
       if (each != null) {
         fillTypeNameMap(typeNameMap, each);
-        import_impl = new Import_impl();
-        if (option.isImportByName()) {
-          import_impl.setName(eachName);
-        } else if (option.isResolveImports()) {
-          String absoluteLocation = each.getSourceUrlString();
-          import_impl.setLocation(absoluteLocation);
+        if (include) {
+          // need to include the complete type system because an import is not possible
+          each.resolveImports(rm);
+          toInclude.add(each);
         } else {
-          String relativeLocation = getRelativeLocation(file.getAbsolutePath(), typeSystemOutput);
-          import_impl.setLocation(relativeLocation);
+          import_impl = new Import_impl();
+          if (option.isImportByName()) {
+            import_impl.setName(eachName);
+          } else if (option.isResolveImports()) {
+            String absoluteLocation = each.getSourceUrlString();
+            import_impl.setLocation(absoluteLocation);
+          } else {
+            String relativeLocation = getRelativeLocation(url.getPath(), typeSystemOutput);
+            import_impl.setLocation(relativeLocation);
+          }
+          importList.add(import_impl);
         }
-        importList.add(import_impl);
       } else {
         throw new FileNotFoundException("Build process can't find " + eachName + " in "
                 + mainScript);
       }
     }
     for (String eachName : desc.getImportedScripts()) {
+      // TODO
       String locate = RutaEngine.locate(eachName, enginePaths, "TypeSystem.xml");
       File file = new File(locate);
-      TypeSystemDescription each = getTypeSystemDescriptor(file, option);
+      URL url = file.toURI().toURL();
+      TypeSystemDescription each = getTypeSystemDescriptor(url, option);
       if (each != null) {
         fillTypeNameMap(typeNameMap, each);
         import_impl = new Import_impl();
@@ -175,7 +196,7 @@ public class RutaSimpleBuilder {
                 + mainScript);
       }
     }
-
+    typeSystemDescription = CasCreationUtils.mergeTypeSystems(toInclude, rm);
     Import[] newImports = importList.toArray(new Import[0]);
     typeSystemDescription.setImports(newImports);
     if (option.isResolveImports()) {
@@ -185,7 +206,8 @@ public class RutaSimpleBuilder {
         throw new RutaBuildException("Failed to resolve imported Type Systems", e);
       }
     }
-
+   
+    
     // TODO hotfixes: where do I get the final types??
     Set<String> finalTypes = new HashSet<String>();
     finalTypes.addAll(Arrays.asList(new String[] { "uima.cas.Boolean", "uima.cas.Byte",
@@ -230,8 +252,11 @@ public class RutaSimpleBuilder {
       }
     }
 
-    typeSystemDescription.setTypes(types.toArray(new TypeDescription[0]));
     File typeSystemFile = getFile(typeSystemOutput);
+    TypeDescription[] presentTypes = typeSystemDescription.getTypes();
+    
+    types.addAll(Arrays.asList(presentTypes));
+    typeSystemDescription.setTypes(types.toArray(new TypeDescription[0]));
     typeSystemDescription.setName(mainScript + "TypeSystem");
     typeSystemDescription.setSourceUrl(typeSystemFile.toURI().toURL());
     TypeSystemDescription aets = uimaFactory.createTypeSystemDescription();
@@ -243,6 +268,7 @@ public class RutaSimpleBuilder {
       import_impl.setLocation(relativeLocation);
     }
 
+    
     File engineFile = configureEngine(desc, engineOutput, option, mainScript, scriptPaths,
             enginePaths, capability, import_impl, aets);
 
@@ -365,8 +391,11 @@ public class RutaSimpleBuilder {
               RutaProjectUtils.getDefaultResourcesLocation());
       resourceLocations.add(defaultResourceDir.getAbsolutePath());
     }
-    analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
-            .setParameterValue(RutaEngine.PARAM_RESOURCE_PATHS, resourceLocations.toArray(new String[0]));
+    analysisEngineDescription
+            .getAnalysisEngineMetaData()
+            .getConfigurationParameterSettings()
+            .setParameterValue(RutaEngine.PARAM_RESOURCE_PATHS,
+                    resourceLocations.toArray(new String[0]));
 
     String[] additionalScriptsArray = desc.getImportedScripts().toArray(new String[] {});
     analysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings()
@@ -381,7 +410,8 @@ public class RutaSimpleBuilder {
     analysisEngineDescription
             .getAnalysisEngineMetaData()
             .getConfigurationParameterSettings()
-            .setParameterValue(RutaEngine.PARAM_ADDITIONAL_UIMAFIT_ENGINES, additionalUimafitEnginesArray);
+            .setParameterValue(RutaEngine.PARAM_ADDITIONAL_UIMAFIT_ENGINES,
+                    additionalUimafitEnginesArray);
 
     analysisEngineDescription.getAnalysisEngineMetaData().setTypeSystem(typeSystemDescription);
 
@@ -406,14 +436,14 @@ public class RutaSimpleBuilder {
 
     configurationParameterSettings.setParameterValue(RutaEngine.PARAM_ADDITIONAL_EXTENSIONS,
             languageExtensions.toArray(new String[0]));
-    configurationParameterSettings.setParameterValue(RutaEngine.PARAM_ADDITIONAL_ENGINE_LOADERS, options
-            .getEngines().toArray(new String[0]));
+    configurationParameterSettings.setParameterValue(RutaEngine.PARAM_ADDITIONAL_ENGINE_LOADERS,
+            options.getEngines().toArray(new String[0]));
   }
 
-  private TypeSystemDescription getTypeSystemDescriptor(File file, RutaBuildOptions option)
+  private TypeSystemDescription getTypeSystemDescriptor(URL url, RutaBuildOptions option)
           throws InvalidXMLException, IOException {
     TypeSystemDescription tsdesc = UIMAFramework.getXMLParser().parseTypeSystemDescription(
-            new XMLInputSource(file));
+            new XMLInputSource(url));
     if (option.isResolveImports()) {
       tsdesc.resolveImports(rm);
     }
@@ -434,4 +464,22 @@ public class RutaSimpleBuilder {
     ch.endDocument();
   }
 
+  public static URL checkImportExistence(String candidate, String extension, ClassLoader classloader)
+          throws IOException {
+    String p = candidate.replaceAll("[.]", "/");
+    p += "." + extension;
+    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(
+            classloader);
+    String prefix = "classpath*:";
+    String pattern = prefix + p;
+    Resource[] resources = resolver.getResources(pattern);
+    if (resources == null || resources.length == 0) {
+      return null;
+    } else {
+      Resource resource = resources[0];
+      URL url = resource.getURL();
+      return url;
+    }
+  }
+
 }

Modified: uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaCompletionEngine.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaCompletionEngine.java?rev=1579326&r1=1579325&r2=1579326&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaCompletionEngine.java (original)
+++ uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaCompletionEngine.java Wed Mar 19 17:56:46 2014
@@ -27,11 +27,14 @@ import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Comparator;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.uima.UIMAFramework;
 import org.apache.uima.analysis_component.AnalysisComponent;
 import org.apache.uima.resource.ResourceManager;
@@ -84,8 +87,11 @@ import org.eclipse.jdt.internal.core.Jav
 import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
 import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.Resource;
 import org.springframework.core.io.ResourceLoader;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
 import org.springframework.core.type.filter.AssignableTypeFilter;
+import org.springframework.util.PathMatcher;
 
 public class RutaCompletionEngine extends ScriptCompletionEngine {
 
@@ -141,17 +147,14 @@ public class RutaCompletionEngine extend
     if (classloader == null) {
       IScriptProject scriptProject = sourceModule.getModelElement().getScriptProject();
       try {
-        // TODO UIMA-3077
-        Collection<String> dependencies = getDependencies(scriptProject.getProject());
+        Collection<String> dependencies = RutaProjectUtils.getClassPath(scriptProject.getProject());
         URL[] urls = new URL[dependencies.size()];
         int counter = 0;
         for (String dep : dependencies) {
-          urls[counter] = new File(dep).toURL();
+          urls[counter] = new File(dep).toURI().toURL();
           counter++;
         }
         classloader = new URLClassLoader(urls);
-        // } catch (CoreException e) {
-        // RutaIdeCorePlugin.error(e);
       } catch (MalformedURLException e) {
         RutaIdeCorePlugin.error(e);
       } catch (CoreException e) {
@@ -165,7 +168,17 @@ public class RutaCompletionEngine extend
         RutaReferenceVisitor referenceVisitor = new RutaReferenceVisitor(actualCompletionPosition);
         parsed.traverse(referenceVisitor);
         node = referenceVisitor.getResult();
-
+        if(node == null) {
+          referenceVisitor = new RutaReferenceVisitor(actualCompletionPosition-1);
+          parsed.traverse(referenceVisitor);
+          node = referenceVisitor.getResult();
+        }
+        if(node == null) {
+          referenceVisitor = new RutaReferenceVisitor(actualCompletionPosition-2);
+          parsed.traverse(referenceVisitor);
+          node = referenceVisitor.getResult();
+        }
+        
         if (node == null) {
           doCompletionOnEmptyStatement(module, position, i);
           doCompletionOnDeclaration(module, startPart);
@@ -240,16 +253,28 @@ public class RutaCompletionEngine extend
   private void doCompletionOnComponentDeclaration(IModuleSource cu, RutaModuleDeclaration parsed,
           String startPart, int type, String complString) throws Exception {
     if (type == ComponentDeclaration.SCRIPT) {
+      List<String> scripts = new ArrayList<String>();
+
       List<IFolder> scriptFolders = RutaProjectUtils.getAllScriptFolders(sourceModule
               .getModelElement().getScriptProject());
-
-      List<String> scripts = new ArrayList<String>();
       for (IFolder folder : scriptFolders) {
         try {
           scripts.addAll(collectScripts(folder, ""));
         } catch (CoreException e) {
         }
       }
+      Resource[] resources = getFilesInClasspath(complString, "ruta");
+      for (Resource resource : resources) {
+        try {
+          String string = getScriptRepresentation(resource, "ruta");
+          if (string != null && !scripts.contains(string)) {
+            scripts.add(string);
+          }
+        } catch (Exception e) {
+          // do not report the exceptions
+        }
+      }
+
       for (String string : scripts) {
         if (match(complString, string)) {
           addProposal(complString, string, CompletionProposal.PACKAGE_REF);
@@ -257,15 +282,15 @@ public class RutaCompletionEngine extend
       }
     } else if (type == ComponentDeclaration.UIMAFIT_ENGINE) {
       List<String> engines = new ArrayList<String>();
-      
-      ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
-      ResourceLoader resourceLoader =  new DefaultResourceLoader(classloader);
+      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);
+      if (pack.endsWith("/")) {
+        pack = pack.substring(0, pack.length() - 1);
       }
       Set<BeanDefinition> components = provider.findCandidateComponents(pack);
       for (BeanDefinition component : components) {
@@ -278,13 +303,28 @@ public class RutaCompletionEngine extend
         }
       }
     } else if (type == ComponentDeclaration.ENGINE) {
-      List<IFolder> descriptorFolders = RutaProjectUtils.getAllDescriptorFolders(sourceModule
-              .getModelElement().getScriptProject().getProject());
       List<String> engines = new ArrayList<String>();
-      for (IFolder folder : descriptorFolders) {
+      Resource[] resources = getFilesInClasspath(complString, "xml");
+      for (Resource resource : resources) {
         try {
-          engines.addAll(collectEngines(folder, ""));
-        } catch (CoreException e) {
+          UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
+                  new XMLInputSource(resource.getURL()));
+          String string = getScriptRepresentation(resource, "xml");
+          if (string != null) {
+            engines.add(string);
+          }
+        } catch (Exception e) {
+          // do not report the exceptions
+        }
+      }
+      if (StringUtils.isAllUpperCase(complString)) {
+        List<IFolder> descriptorFolders = RutaProjectUtils.getAllDescriptorFolders(sourceModule
+                .getModelElement().getScriptProject().getProject());
+        for (IFolder folder : descriptorFolders) {
+          try {
+            engines.addAll(collectEngines(folder, ""));
+          } catch (CoreException e) {
+          }
         }
       }
       for (String string : engines) {
@@ -293,13 +333,29 @@ public class RutaCompletionEngine extend
         }
       }
     } else {
-      List<IFolder> descriptorFolders = RutaProjectUtils.getAllDescriptorFolders(sourceModule
-              .getModelElement().getScriptProject().getProject());
       List<String> tss = new ArrayList<String>();
-      for (IFolder folder : descriptorFolders) {
+      Resource[] resources = getFilesInClasspath(complString, "xml");
+      for (Resource resource : resources) {
         try {
-          tss.addAll(collectTypeSystems(folder, ""));
-        } catch (CoreException e) {
+          UIMAFramework.getXMLParser().parseTypeSystemDescription(
+                  new XMLInputSource(resource.getURL()));
+          String string = getScriptRepresentation(resource, "xml");
+          if (string != null) {
+            tss.add(string);
+          }
+        } catch (Exception e) {
+          // do not report the exceptions
+        }
+      }
+      if (StringUtils.isAllUpperCase(complString)) {
+        // fallback for camel case
+        List<IFolder> descriptorFolders = RutaProjectUtils.getAllDescriptorFolders(sourceModule
+                .getModelElement().getScriptProject().getProject());
+        for (IFolder folder : descriptorFolders) {
+          try {
+            tss.addAll(collectTypeSystems(folder, ""));
+          } catch (CoreException e) {
+          }
         }
       }
       for (String string : tss) {
@@ -310,6 +366,39 @@ public class RutaCompletionEngine extend
     }
   }
 
+  private Resource[] getFilesInClasspath(String prefix, String extension) throws IOException {
+    String pack = prefix.replaceAll("[.]", "/");
+    if (pack.endsWith("/")) {
+      pack = pack.substring(0, pack.length() - 1);
+    }
+    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(
+            classloader);
+    String p = "classpath*:";
+    String suffix = "/**/*." + extension;
+    String pattern = p + pack + suffix;
+    Resource[] resources = resolver.getResources(pattern);
+    return resources;
+  }
+
+  private String getScriptRepresentation(Resource resource, String suffix) throws IOException {
+    URL url = resource.getURL();
+    URL[] urLs = classloader.getURLs();
+    String externalForm = url.toExternalForm();
+    for (URL each : urLs) {
+      String eachExternalForm = each.toExternalForm();
+      if (externalForm.startsWith("jar:")) {
+        eachExternalForm = "jar:" + eachExternalForm + "!/";
+      }
+      if (externalForm.startsWith(eachExternalForm)) {
+        String name = externalForm.substring(eachExternalForm.length(), externalForm.length()
+                - (suffix.length() + 1));
+        name = name.replaceAll("[/]", ".");
+        return name;
+      }
+    }
+    return null;
+  }
+
   private List<String> collectEngines(IFolder folder, String prefix) throws CoreException {
     List<String> result = new ArrayList<String>();
     IResource[] members = folder.members();
@@ -667,68 +756,4 @@ 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/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java?rev=1579326&r1=1579325&r2=1579326&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java (original)
+++ uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/parser/ast/StatementFactory.java Wed Mar 19 17:56:46 2014
@@ -362,7 +362,7 @@ public class StatementFactory extends Ab
     return new ComponentReference(nameBounds[0], nameBounds[1], "");
   }
 
-  public static ComponentDeclaration createComponentDeclaration(CommonToken ct) {
+  public static ComponentDeclaration createComponentDeclaration(Token ct) {
     int nameBounds[] = getBounds(ct);
     String text = ct.getText();
     return new ComponentDeclaration(nameBounds[0], nameBounds[0] + text.length(), text);