Author: pkluegl Date: Tue Apr 23 13:53:58 2013 New Revision: 1470961 URL: http://svn.apache.org/r1470961 Log: UIMA-2519 - textmarker projects now resolve transitive dependencies (also of maven projects) - additionally: small hotfix in feature checker
Modified: uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerProjectUtils.java uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerSimpleBuilder.java uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConfigurationDelegate.java uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/validator/TextMarkerVarRefChecker.java Modified: uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerProjectUtils.java URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerProjectUtils.java?rev=1470961&r1=1470960&r2=1470961&view=diff ============================================================================== --- uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerProjectUtils.java (original) +++ uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerProjectUtils.java Tue Apr 23 13:53:58 2013 @@ -21,7 +21,11 @@ package org.apache.uima.textmarker.ide.c import java.io.File; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.TreeSet; import javax.swing.UIManager; @@ -41,8 +45,10 @@ import org.eclipse.dltk.core.IModelEleme import org.eclipse.dltk.core.IScriptFolder; import org.eclipse.dltk.core.IScriptProject; import org.eclipse.dltk.core.ModelException; +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; public class TextMarkerProjectUtils { @@ -77,11 +83,19 @@ public class TextMarkerProjectUtils { } public static List<IFolder> getReferencedScriptFolders(IScriptProject proj) throws CoreException { + return getReferencedScriptFolders(proj, new HashSet<IProject>()); + } + + public static List<IFolder> getReferencedScriptFolders(IScriptProject proj, Collection<IProject> visited) throws CoreException { List<IFolder> result = new ArrayList<IFolder>(); IProject[] referencedProjects = proj.getProject().getReferencedProjects(); for (IProject eachProject : referencedProjects) { - IScriptProject scriptProject = DLTKCore.create(eachProject); - result.addAll(TextMarkerProjectUtils.getScriptFolders(scriptProject)); + if(!visited.contains(eachProject)) { + IScriptProject scriptProject = DLTKCore.create(eachProject); + result.addAll(TextMarkerProjectUtils.getScriptFolders(scriptProject)); + visited.add(eachProject); + result.addAll(getReferencedScriptFolders(scriptProject, visited)); + } } return result; } @@ -117,10 +131,36 @@ public class TextMarkerProjectUtils { } public static List<IFolder> getReferencedDescriptorFolders(IProject proj) throws CoreException { + return getReferencedDescriptorFolders(proj, new HashSet<IProject>()); + } + + public static List<IFolder> getReferencedDescriptorFolders(IProject proj, Collection<IProject> visited) throws CoreException { List<IFolder> result = new ArrayList<IFolder>(); - IProject[] referencedProjects = proj.getReferencedProjects(); + Collection<IProject> referencedProjects = getReferencedProjects(proj, new HashSet<IProject>()); for (IProject eachProject : referencedProjects) { - result.addAll(TextMarkerProjectUtils.getDescriptorFolders(eachProject)); + if(!visited.contains(eachProject)) { + result.addAll(TextMarkerProjectUtils.getDescriptorFolders(eachProject)); + visited.add(eachProject); + result.addAll(getReferencedDescriptorFolders(eachProject, visited)); + } + } + return result; + } + + private static Collection<IProject> getReferencedProjects(IProject proj, Collection<IProject> visited) throws CoreException { + Collection<IProject> result = new HashSet<IProject>(); + IProject[] referencedProjects = proj.getReferencedProjects(); + result.addAll(Arrays.asList(referencedProjects)); + IProjectNature nature = proj.getNature(JAVANATURE); + if(nature != null) { + JavaProject javaProject = (JavaProject) JavaCore.create(proj); + IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(); + for (IClasspathEntry eachCPE : resolvedClasspath) { + if(eachCPE.getEntryKind() == IClasspathEntry.CPE_PROJECT) { + IProject project = getProject(eachCPE.getPath()); + result.add(project); + } + } } return result; } @@ -213,6 +253,16 @@ public class TextMarkerProjectUtils { project.setPersistentProperty(new QualifiedName("", CDE_DATA_PATH), dataPath); } + public static IProject getProject(IPath path) { + IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(path); + if (member instanceof IProject) { + IProject p = (IProject) member; + return p; + } + return null; + } + + public static String getDefaultInputLocation() { return "input"; } Modified: uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerSimpleBuilder.java URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerSimpleBuilder.java?rev=1470961&r1=1470960&r2=1470961&view=diff ============================================================================== --- uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerSimpleBuilder.java (original) +++ uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/core/builder/TextMarkerSimpleBuilder.java Tue Apr 23 13:53:58 2013 @@ -129,6 +129,10 @@ public class TextMarkerSimpleBuilder { importList.add(import_impl); for (String eachName : desc.getImportedTypeSystems()) { String locate = TextMarkerEngine.locate(eachName, enginePaths, ".xml"); + if(locate == null) { + throw new FileNotFoundException("Build process can't find " + eachName + " in " + + mainScript); + } File file = new File(locate); TypeSystemDescription each = getTypeSystemDescriptor(file, option); if (each != null) { Modified: uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConfigurationDelegate.java URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConfigurationDelegate.java?rev=1470961&r1=1470960&r2=1470961&view=diff ============================================================================== --- uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConfigurationDelegate.java (original) +++ uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/launching/TextMarkerLaunchConfigurationDelegate.java Tue Apr 23 13:53:58 2013 @@ -23,9 +23,12 @@ import java.io.File; import java.io.IOException; import java.net.URL; 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; import org.apache.commons.lang3.StringUtils; import org.apache.uima.cas.CAS; @@ -50,8 +53,10 @@ import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.dltk.core.IScriptProject; import org.eclipse.dltk.launching.AbstractScriptLaunchConfigurationDelegate; -import org.eclipse.jdt.core.IJavaProject; +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; @@ -66,10 +71,10 @@ public class TextMarkerLaunchConfigurati IScriptProject proj = AbstractScriptLaunchConfigurationDelegate.getScriptProject(configuration); String mainScriptAttribute = configuration.getAttribute("mainScript", ""); - + String encoding = proj.getProject().getDefaultCharset(); String view = configuration.getAttribute(TextMarkerLaunchConstants.VIEW, CAS.NAME_DEFAULT_SOFA); - if(StringUtils.isBlank(view)) { + if (StringUtils.isBlank(view)) { view = CAS.NAME_DEFAULT_SOFA; } boolean recursive = configuration.getAttribute(TextMarkerLaunchConstants.RECURSIVE, false); @@ -82,15 +87,15 @@ public class TextMarkerLaunchConfigurati proj.getProject()).toPortableString(); String input = configuration.getAttribute(TextMarkerLaunchConstants.INPUT_FOLDER, inputDirPath.toPortableString()); - if(StringUtils.isBlank(input)) { + if (StringUtils.isBlank(input)) { input = inputDirPath.toPortableString(); } String output = configuration.getAttribute(TextMarkerLaunchConstants.OUTPUT_FOLDER, outputDirPath.toPortableString()); - if(StringUtils.isBlank(output)) { + if (StringUtils.isBlank(output)) { output = outputDirPath.toPortableString(); } - + cmdline.append(TextMarkerLaunchConstants.ARG_DESCRIPTOR + " "); cmdline.append(engine + " "); @@ -115,9 +120,10 @@ public class TextMarkerLaunchConfigurati return cmdline.toString(); } - private String makeAbsolute(String input, ILaunchConfiguration configuration) throws CoreException { + private String makeAbsolute(String input, ILaunchConfiguration configuration) + throws CoreException { IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(input); - if(member != null) { + if (member != null) { return member.getLocation().toPortableString(); } return input; @@ -131,22 +137,9 @@ public class TextMarkerLaunchConfigurati @Override public String[] getClasspath(ILaunchConfiguration configuration) throws CoreException { TextMarkerIdePlugin d = TextMarkerIdePlugin.getDefault(); - // 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)); - IScriptProject scriptProject = AbstractScriptLaunchConfigurationDelegate.getScriptProject(configuration); - IProject[] referencedProjects = scriptProject.getProject().getReferencedProjects(); - for (IProject eachProject : referencedProjects) { - IProjectNature nature = eachProject.getNature(TextMarkerProjectUtils.JAVANATURE); - if(nature != null) { - IJavaProject javaProject = JavaCore.create(eachProject); - IPath readOutputLocation = javaProject.readOutputLocation(); - IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(readOutputLocation); - extendedClasspath.add(folder.getLocation().toPortableString()); - } - } - // Normal mode, add the launcher plugin and uima runtime jar to the classpath if (!Platform.inDevelopmentMode()) { try { @@ -197,9 +190,71 @@ public class TextMarkerLaunchConfigurati } } + Collection<String> dependencies = getDependencies(configuration); + extendedClasspath.addAll(dependencies); + return extendedClasspath.toArray(new String[extendedClasspath.size()]); } + private Collection<String> getDependencies(ILaunchConfiguration configuration) + throws CoreException { + Collection<String> result = new TreeSet<String>(); + + IScriptProject scriptProject = AbstractScriptLaunchConfigurationDelegate + .getScriptProject(configuration); + IProject[] referencedProjects = scriptProject.getProject().getReferencedProjects(); + for (IProject eachProject : referencedProjects) { + // for each java project + extendClasspathWithProject(result, eachProject, new HashSet<IProject>()); + } + return result; + } + + private void extendClasspathWithProject(Collection<String> result, IProject project, + Collection<IProject> visited) throws CoreException, JavaModelException { + IProjectNature nature = project.getNature(TextMarkerProjectUtils.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 = TextMarkerProjectUtils.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 = TextMarkerProjectUtils.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, IProgressMonitor monitor) throws CoreException { @@ -216,16 +271,16 @@ public class TextMarkerLaunchConfigurati } boolean recursive = configuration.getAttribute(TextMarkerLaunchConstants.RECURSIVE, false); clearOutputFolder(new File(ouputFolder.getLocation().toPortableString()), recursive); - -// String[] args = getProgramArguments(configuration).split(" "); -// try { -// TextMarkerLauncher.main(args); -// } catch (Exception e1) { -// e1.printStackTrace(); -// } - + + // String[] args = getProgramArguments(configuration).split(" "); + // try { + // TextMarkerLauncher.main(args); + // } catch (Exception e1) { + // e1.printStackTrace(); + // } + super.launch(configuration, mode, launch, monitor); - + while (!launch.isTerminated()) { try { Thread.sleep(100); Modified: uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/validator/TextMarkerVarRefChecker.java URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/validator/TextMarkerVarRefChecker.java?rev=1470961&r1=1470960&r2=1470961&view=diff ============================================================================== --- uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/validator/TextMarkerVarRefChecker.java (original) +++ uima/sandbox/textmarker/trunk/textmarker-ep-ide/src/main/java/org/apache/uima/textmarker/ide/validator/TextMarkerVarRefChecker.java Tue Apr 23 13:53:58 2013 @@ -321,6 +321,14 @@ public class TextMarkerVarRefChecker imp if(structure == null) { return false; } + + // TODO HOTFIX + if(structure.equals("Document") || structure.equals("DocumentAnnotation") || structure.equals("uima.tcas.DocumentAnnotation")) { + if(feat.equals("language")) { + return true; + } + } + boolean featureFound = false; TypeDescription[] descriptions = description.getTypes(); Map<String, TypeDescription> typeMap = new HashMap<String, TypeDescription>(); @@ -328,9 +336,11 @@ public class TextMarkerVarRefChecker imp String typeName = typeDescription.getName(); typeMap.put(typeName, typeDescription); } + for (TypeDescription typeDescription : descriptions) { String typeName = typeDescription.getName(); - if (typeName.endsWith(structure) || (typeName.equals("uima.tcas.DocumentAnnotation") && structure.equals("Document"))) { + String shortName = getShortName(typeName); + if(typeName.equals(structure) || shortName.equals(structure)) { Collection<FeatureDescription> allFeatures = getAllDeclaredFeatures(typeDescription, typeMap); for (FeatureDescription featureDescription : allFeatures) { @@ -341,6 +351,7 @@ public class TextMarkerVarRefChecker imp } } } + if (featureFound) { break; } @@ -348,6 +359,11 @@ public class TextMarkerVarRefChecker imp return featureFound; } + private String getShortName(String typeName) { + String[] nameSpace = typeName.split("[.]"); + return nameSpace[nameSpace.length - 1]; + } + private Collection<FeatureDescription> getAllDeclaredFeatures(TypeDescription typeDescription, Map<String, TypeDescription> typeMap) { Collection<FeatureDescription> result = new HashSet<FeatureDescription>();