Hi Subclipse committers(and others)
I've added two refinements to the repo viewer "Checkout -> As Project"
feature, as implemented in
subclipse/ui/src/org/tigris/subversion/subclipse/ui/actions/CheckoutAsProjectAction.java.
1) A bug fix: Right now, the feature will only work when the repository
location is the direct parent of the project. This is because of the
missing path elements in the call to
folders[i].getRepository().getRemoteFile("/" + name + "/.project")
This is fixed by inserting the relative path into the project path first.
2) An enhancement/decoupling: Since Eclipse is probably better at
reading .project file descriptions than we are, I've added the reference
to Eclipse's reader,
org.eclipse.core.internal.resources.ProjectDescriptionReader.
This simplifies the code somewhat.
The patch is against the trunk.
-Jesper
Index: D:/Java/subclipse-trunk/subclipse/ui/src/org/tigris/subversion/subclipse/ui/actions/CheckoutAsProjectAction.java
===================================================================
--- D:/Java/subclipse-trunk/subclipse/ui/src/org/tigris/subversion/subclipse/ui/actions/CheckoutAsProjectAction.java (revision 322)
+++ D:/Java/subclipse-trunk/subclipse/ui/src/org/tigris/subversion/subclipse/ui/actions/CheckoutAsProjectAction.java (working copy)
@@ -19,10 +19,9 @@
import java.util.List;
import java.util.Map;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
+import org.eclipse.core.internal.resources.ProjectDescriptionReader;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -36,10 +35,7 @@
import org.tigris.subversion.subclipse.core.ISVNRepositoryLocation;
import org.tigris.subversion.subclipse.core.resources.SVNWorkspaceRoot;
import org.tigris.subversion.subclipse.ui.Policy;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
+import org.xml.sax.InputSource;
/**
* Add some remote resources to the workspace. Current implementation:
@@ -76,22 +72,13 @@
String name = folders[i].getName();
// Check for a better name for the project
- try {
- ISVNRemoteResource dotProject = folders[i].getRepository().getRemoteFile("/" + name + "/.project");
- InputStream is = dotProject.getContents(monitor);
- DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- org.w3c.dom.Document doc = db.parse(is);
- is.close();
- NodeList nl = doc.getDocumentElement().getChildNodes();
- for (int j = 0; j < nl.getLength(); ++j) {
- Node child = nl.item(j);
- if (child instanceof Element && "name".equals(child.getNodeName())) {
- Node grandChild = child.getFirstChild();
- if (grandChild instanceof Text) name = ((Text)grandChild).getData();
- }
- }
- }
- catch (Exception e) {
+ try {
+ ISVNRemoteResource dotProject = folders[i].getRepository().getRemoteFile(folders[i].getRepositoryRelativePath() + "/.project"); //$NON-NLS-1$
+ InputStream is = dotProject.getContents(monitor);
+ IProjectDescription result = new ProjectDescriptionReader().read(new InputSource(is));
+ name = result.getName();
+ }
+ catch (Exception e) {
// no .project exists ... that's ok
e.printStackTrace();
}
Received on Thu Dec 4 07:53:36 2003