|
From: <caw...@us...> - 2007-01-23 18:30:53
|
Revision: 1863
http://svn.sourceforge.net/rubyeclipse/?rev=1863&view=rev
Author: cawilliams
Date: 2007-01-23 10:30:51 -0800 (Tue, 23 Jan 2007)
Log Message:
-----------
getting ever closer to having external libraries hooked up properly...
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyElement.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModel.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRootInfo.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java 2007-01-23 17:17:26 UTC (rev 1862)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java 2007-01-23 18:30:51 UTC (rev 1863)
@@ -852,7 +852,7 @@
}
// outside the workspace
if (target instanceof File) {
- File externalFile = RubyModel.getFile(target);
+ File externalFile = RubyModel.getFolder(target);
if (externalFile != null) {
return RubyCore.newLibraryEntry(resolvedPath, entry.isExported());
} else { // external binary folder
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolder.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolder.java 2007-01-23 18:30:51 UTC (rev 1863)
@@ -0,0 +1,28 @@
+package org.rubypeople.rdt.internal.core;
+
+import java.util.HashMap;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.rubypeople.rdt.core.RubyModelException;
+
+public class ExternalSourceFolder extends SourceFolder {
+
+ public ExternalSourceFolder(SourceFolderRoot parent, String[] names) {
+ super(parent, names);
+ }
+
+ /*
+ * @see RubyElement#generateInfos
+ */
+ protected void generateInfos(Object info, HashMap newElements, IProgressMonitor pm) throws RubyModelException {
+ // Open my folder: this creates all the pkg infos
+ Openable openableParent = (Openable)this.parent;
+ if (!openableParent.isOpen()) {
+ openableParent.generateInfos(openableParent.createElementInfo(), newElements, pm);
+ }
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java 2007-01-23 17:17:26 UTC (rev 1862)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java 2007-01-23 18:30:51 UTC (rev 1863)
@@ -1,31 +1,95 @@
package org.rubypeople.rdt.internal.core;
+import java.io.File;
import java.util.ArrayList;
import java.util.Map;
-import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyModelStatusConstants;
+import org.rubypeople.rdt.core.ISourceFolder;
import org.rubypeople.rdt.core.ISourceFolderRoot;
-import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.util.CharOperation;
+import org.rubypeople.rdt.internal.core.util.Util;
-public class ExternalSourceFolderRoot extends SourceFolderRoot implements
- ISourceFolderRoot {
-
+public class ExternalSourceFolderRoot extends SourceFolderRoot implements ISourceFolderRoot {
+
public final static ArrayList EMPTY_LIST = new ArrayList();
protected final IPath folderPath;
-
- protected ExternalSourceFolderRoot(IPath resource,
- RubyProject project) {
+
+ protected ExternalSourceFolderRoot(IPath resource, RubyProject project) {
super(null, project);
this.folderPath = resource;
}
+
+ @Override
+ protected boolean computeChildren(OpenableElementInfo info, Map newElements) throws RubyModelException {
+ try {
+ // the underlying resource may be a folder or a project (in the case
+ // that the project folder
+ // is actually the source folder root)
+ Object target = RubyModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.folderPath, false);
+ if (target instanceof File) {
+ ArrayList vChildren = new ArrayList(5);
+ computeFolderChildren((File) target, CharOperation.NO_STRINGS, vChildren);
+ IRubyElement[] children = new IRubyElement[vChildren.size()];
+ vChildren.toArray(children);
+ info.setChildren(children);
+ }
+ } catch (RubyModelException e) {
+ // problem resolving children; structure remains unknown
+ info.setChildren(new IRubyElement[] {});
+ throw e;
+ }
+ return true;
+ }
+
+ protected void computeFolderChildren(File folder, String[] pkgName, ArrayList vChildren) throws RubyModelException {
+ ISourceFolder pkg = getSourceFolder(pkgName);
+ vChildren.add(pkg);
+
+ try {
+ RubyProject rubyProject = (RubyProject) getRubyProject();
+ RubyModelManager manager = RubyModelManager.getRubyModelManager();
+ File[] members = folder.listFiles();
+
+ for (int i = 0, max = members.length; i < max; i++) {
+ File member = members[i];
+ String memberName = member.getName();
+ if (member.isDirectory()) {
+ String[] newNames = Util.arrayConcat(pkgName, manager.intern(memberName));
+ computeFolderChildren(member, newNames, vChildren);
+ ISourceFolder child = getSourceFolder(newNames);
+ vChildren.add(child);
+ } else if (member.isFile()) {
+ // do nothing
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ throw new RubyModelException(e, IRubyModelStatusConstants.ELEMENT_DOES_NOT_EXIST); // could
+ // be
+ // thrown
+ // by
+ // ElementTree
+ // when
+ // path
+ // is
+ // not
+ // found
+ } catch (CoreException e) {
+ throw new RubyModelException(e);
+ }
+ }
+ public SourceFolder getSourceFolder(String[] pkgName) {
+ return new ExternalSourceFolder(this, pkgName);
+ }
+
@Override
public IPath getPath() {
return folderPath;
@@ -35,51 +99,76 @@
public boolean isExternal() {
return true;
}
-
+
public int hashCode() {
return this.folderPath.hashCode();
}
-
+
@Override
public boolean isReadOnly() {
return true;
}
-
+
/**
- * Returns true if this handle represents the same folder
- * as the given handle.
- *
+ * Returns true if this handle represents the same folder as the given
+ * handle.
+ *
* @see Object#equals
*/
public boolean equals(Object o) {
if (this == o)
return true;
if (o instanceof ExternalSourceFolderRoot) {
- ExternalSourceFolderRoot other= (ExternalSourceFolderRoot) o;
+ ExternalSourceFolderRoot other = (ExternalSourceFolderRoot) o;
return this.folderPath.equals(other.folderPath);
}
return false;
}
-
- @Override
- protected boolean computeChildren(OpenableElementInfo info, Map newElements) throws RubyModelException {
- try {
- // the underlying resource may be a folder or a project (in the case that the project folder
- // is actually the source folder root)
- IWorkspaceRoot workspaceRoot = RubyCore.getWorkspace().getRoot();
- IContainer rootFolder = workspaceRoot.getContainerForLocation(folderPath.makeAbsolute());
- if (rootFolder.getType() == IResource.FOLDER || rootFolder.getType() == IResource.PROJECT) {
- ArrayList vChildren = new ArrayList(5);
- computeFolderChildren(rootFolder, CharOperation.NO_STRINGS, vChildren);
- IRubyElement[] children = new IRubyElement[vChildren.size()];
- vChildren.toArray(children);
- info.setChildren(children);
- }
- } catch (RubyModelException e) {
- //problem resolving children; structure remains unknown
- info.setChildren(new IRubyElement[]{});
- throw e;
+
+ /**
+ * @see IRubyElement
+ */
+ public IResource getUnderlyingResource() throws RubyModelException {
+ if (isExternal()) {
+ if (!exists())
+ throw newNotPresentException();
+ return null;
}
- return true;
+ return super.getUnderlyingResource();
}
+
+ /**
+ * Returns a new element info for this element.
+ */
+ protected Object createElementInfo() {
+ return new ExternalSourceFolderRootInfo();
+ }
+
+ public IResource getResource() {
+ if (this.resource == null) {
+ this.resource = RubyModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.folderPath, false);
+ }
+ if (this.resource instanceof IResource) {
+ return super.getResource();
+ }
+ return null;
+ }
+
+ protected boolean resourceExists() {
+ if (this.isExternal()) {
+ return RubyModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.getPath(), // don't
+ // make
+ // the
+ // path
+ // relative
+ // as
+ // this
+ // is
+ // an
+ // external
+ // archive
+ true) != null;
+ }
+ return super.resourceExists();
+ }
}
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRootInfo.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRootInfo.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRootInfo.java 2007-01-23 18:30:51 UTC (rev 1863)
@@ -0,0 +1,11 @@
+package org.rubypeople.rdt.internal.core;
+
+public class ExternalSourceFolderRootInfo extends SourceFolderRootInfo {
+ /**
+ * Returns an array of non-ruby resources contained in the receiver.
+ */
+ public Object[] getNonRubyResources() {
+ fNonRubyResources = NO_NON_RUBY_RESOURCES;
+ return fNonRubyResources;
+ }
+}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyElement.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyElement.java 2007-01-23 17:17:26 UTC (rev 1862)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyElement.java 2007-01-23 18:30:51 UTC (rev 1863)
@@ -26,7 +26,6 @@
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModel.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModel.java 2007-01-23 17:17:26 UTC (rev 1862)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModel.java 2007-01-23 18:30:51 UTC (rev 1863)
@@ -43,7 +43,7 @@
* been confirmed as file (ie. which returns true to {@link java.io.File#isFile()}.
* Note this cache is kept for the whole session.
*/
- public static HashSet existingExternalConfirmedFiles = new HashSet();
+ public static HashSet existingExternalConfirmedFolders = new HashSet();
protected RubyModel() {
super(null);
@@ -54,7 +54,7 @@
*/
public static void flushExternalFileCache() {
existingExternalFiles = new HashSet();
- existingExternalConfirmedFiles = new HashSet();
+ existingExternalConfirmedFolders = new HashSet();
}
/**
@@ -231,23 +231,23 @@
}
/**
- * Helper method - returns whether an object is afile (ie. which returns true to {@link java.io.File#isFile()}.
+ * Helper method - returns whether an object is a file (ie. which returns true to {@link java.io.File#isFile()}.
*/
-public static boolean isFile(Object target) {
- return getFile(target) != null;
+public static boolean isFolder(Object target) {
+ return getFolder(target) != null;
}
/**
* Helper method - returns the file item (ie. which returns true to {@link java.io.File#isFile()},
* or null if unbound
*/
-public static synchronized File getFile(Object target) {
- if (existingExternalConfirmedFiles.contains(target))
+public static synchronized File getFolder(Object target) {
+ if (existingExternalConfirmedFolders.contains(target))
return (File) target;
if (target instanceof File) {
File f = (File) target;
- if (f.isFile()) {
- existingExternalConfirmedFiles.add(f);
+ if (f.isDirectory()) {
+ existingExternalConfirmedFolders.add(f);
return f;
}
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java 2007-01-23 17:17:26 UTC (rev 1862)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java 2007-01-23 18:30:51 UTC (rev 1863)
@@ -16,7 +16,6 @@
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
@@ -46,6 +45,7 @@
import org.osgi.service.prefs.BackingStoreException;
import org.rubypeople.rdt.core.ILoadpathContainer;
import org.rubypeople.rdt.core.ILoadpathEntry;
+import org.rubypeople.rdt.core.IParent;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyModelMarker;
import org.rubypeople.rdt.core.IRubyModelStatus;
@@ -406,15 +406,8 @@
ISourceFolderRoot[] roots = getAllSourceFolderRoots(reverseMap);
for (int i = 0; i < roots.length; i++) {
SourceFolderRoot root = (SourceFolderRoot) roots[i];
- List<IRubyElement> childen = root.getChildrenOfType(IRubyElement.TYPE);
- for (IRubyElement element : childen) {
- if (element.isType(IRubyElement.TYPE)) {
- IType aType = (IType) element;
- if (aType.getElementName().equals(className)) {
- return aType;
- }
- }
- }
+ IType type = getType(root, className);
+ if (type != null) return type;
}
} catch (RubyModelException e) {
e.printStackTrace();
@@ -422,6 +415,22 @@
return null;
}
+ private IType getType(IParent parent, String className) throws RubyModelException {
+ IRubyElement[] children = parent.getChildren();
+ for (int j = 0; j < children.length; j++) {
+ IRubyElement child = children[j];
+ if (child.isType(IRubyElement.SOURCE_FOLDER)) {
+ ISourceFolder folder = (ISourceFolder) child;
+ IType type = getType(folder, className);
+ if (type != null) return type;
+ } else if(child.isType(IRubyElement.TYPE)) {
+ IType type = (IType) child;
+ if (type.getElementName().equals(className)) return type;
+ }
+ }
+ return null;
+ }
+
/**
* @param project
* @return
@@ -591,7 +600,7 @@
root = getSourceFolderRoot((IResource) target);
} else {
// external target
- if (RubyModel.isFile(target)) {
+ if (RubyModel.isFolder(target)) {
root = new ExternalSourceFolderRoot(entryPath, this);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|