[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[RFC][PATCH] Subclipse "autoadd" functionality

From: Magnus Naeslund(t) <mag_at_fbab.net>
Date: 2005-03-16 21:49:04 CET

*** This patch is alpha quality, it might eat your cat **

This is a request for comments, also I want to know is if a polished
version of this patch would be accepted by you.

Explaination of as what I'm trying to accomplish:

A while ago I got a patch merged that made it possible to import stuff
that has been checked out by other means than from within Eclipse via a
PSF file (see mail "Subclipse PSF enhancement").

There are several gains in this:
You have the whole repository layout intact.
You can work together with outside tools that need the whole tree (like
a build process).

I'm working at a big financial company, and right now where we are
evaluation migration to eclipse + subversion instead of WSAD + ClearCase.

WSAD + ClearCase works like this: you check out a whole tree to some
directory and then import the projects to WSAD. You can now work from
WSAD and do some more advanced ClearCase maneuvers in the ClearCase
explorer GUI or cleartool command line utility.

I ran into a problem when using subclipse like this: when you create a
new project it would be nice to just "svn add" it to the parent
directory that is already under subversion control.

The usual way you do it in subclipse is to right-click on the project
and then go Team->Share and then you have to be aware of the repository
layout to be able to commit it to the right place.
This is big inconvenice problem to us, ClearCase just throws up a nice
dialog saying "Hey wanna add this to source control?".

So I made patch that does this. It listens for .project file creations
and checks if the parent directory is under subversion control, and just
adds the project directory.
After this is done the normal Team menu works, and you can do commit as

There are several things not finished in this patch.
I want to make it more safe (like checking for isManaged() and stuff
like that), and add a dialog asking the user if it really wants to add
the project to source control.
Right now it just goes ahead and adds it without saying anything.

Some credit goes to Panagiotis Korros, I stole the idea of listening for
metadata changed from his Issue 216 patch :)

This is how to test it:

svn mkdir svn://server/repo/AutoAddTest
svn co svn://server/repo/AutoAddTest /tmp/AutoAddTest

In eclipse, create Project "Test1" in directory /tmp/AutoAddTest/Test1

After it has created the project, it should be acessible thru the Team menu.


So what do you think?
Do I have any chance of getting this accepted (after some changes)?

Magnus Naeslund

Index: core/src/org/tigris/subversion/subclipse/core/SVNTeamProviderType.java
--- core/src/org/tigris/subversion/subclipse/core/SVNTeamProviderType.java (revision 1293)
+++ core/src/org/tigris/subversion/subclipse/core/SVNTeamProviderType.java (working copy)
@@ -11,8 +11,21 @@
 package org.tigris.subversion.subclipse.core;
+import java.io.File;
+import java.io.IOException;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.team.core.ProjectSetCapability;
+import org.eclipse.team.core.RepositoryProvider;
 import org.eclipse.team.core.RepositoryProviderType;
+import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
@@ -35,4 +48,83 @@
         public ProjectSetCapability getProjectSetCapability() {
                 return new SVNProjectSetCapability();
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.RepositoryProviderType#metaFilesDetected(org.eclipse.core
+ */
+ public void metaFilesDetected(IProject project, IContainer[] containers) {
+ for (int i = 0; i < containers.length; i++) {
+ IContainer container = containers[i];
+ // Is this new Project created as a sub folder to a already managed parent folder?
+ if (container.getType() == IContainer.PROJECT){
+ File file = container.getLocation().append("../.svn").toFile(); //$NON-NLS-1$
+ if (file != null &&
+ file.exists() && file.isDirectory()){
+ try{
+ String canonical = file.getCanonicalPath();
+ System.err.println("Addable project detected: " + canonical);
+ Job j = new AddJob(project);
+ j.setRule(project);
+ j.setPriority(Job.SHORT);
+ j.schedule();
+ }catch(IOException ioe){
+ System.err.println("Tried to add bad path: "+file.getPath());
+ }
+ }
+ }
+ }
+ }
+ private static class AddJob extends Job{
+ final IProject project;
+ AddJob(IProject project){
+ super("Adding project "+project.getName()+" resource svn");
+ this.project = project;
+ }
+ public IStatus run(IProgressMonitor monitor) {
+ return runInWorkspace(monitor);
+ }
+ public IStatus runInWorkspace(IProgressMonitor monitor) {
+ if (!project.isAccessible()){
+ System.err.println("Rescheduling job since it's not accessible");
+ schedule(1000);
+ return Status.OK_STATUS;
+ }
+ System.err.println("Starting "+getName());
+ monitor.beginTask(null, IProgressMonitor.UNKNOWN);
+ try {
+ SVNProviderPlugin plugin = SVNProviderPlugin.getPlugin();
+ SVNClientManager svnClientManager = plugin.getSVNClientManager();
+ ISVNClientAdapter client = svnClientManager.createSVNClient();
+ File file = project.getLocation().toFile();
+ client.addDirectory(file, false);
+ RepositoryProvider.map(project, SVNProviderPlugin.getTypeId());
+ SVNTeamProvider provider = (SVNTeamProvider) RepositoryProvider
+ .getProvider(project, SVNProviderPlugin.getTypeId());
+ plugin.getStatusCacheManager().refreshStatus(project, IResource.DEPTH_INFINITE);
+ //Doesn't work since status == ADDED, that means it's !hasRemote()
+ //SVNWorkspaceRoot.setSharing(project, new SubProgressMonitor(monitor, 1000));
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.err.println("Exception running addables: " + e);
+ } finally {
+ monitor.done();
+ }
+ return Status.OK_STATUS;
+ }
+ }
Index: core/plugin.xml
--- core/plugin.xml (revision 1293)
+++ core/plugin.xml (working copy)
@@ -41,7 +41,8 @@
- id="org.tigris.subversion.subclipse.core.svnnature">
+ id="org.tigris.subversion.subclipse.core.svnnature"
+ metaFilePaths=".project">
Received on Thu Mar 17 07:49:04 2005

This is an archived mail posted to the Subclipse Dev mailing list.