Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-10-24 02:25:05 -0400
committerEike Stepper2010-10-24 02:25:05 -0400
commit63e7b2e5636cc9501e3a720ed01805eff8845756 (patch)
treee1053ea937f4f7224f846be487f89ca186f70e4c /plugins/org.eclipse.emf.cdo.workspace.efs
parent6ca1b6430519471e1c386ff2f236d72e920a41c1 (diff)
downloadcdo-63e7b2e5636cc9501e3a720ed01805eff8845756.tar.gz
cdo-63e7b2e5636cc9501e3a720ed01805eff8845756.tar.xz
cdo-63e7b2e5636cc9501e3a720ed01805eff8845756.zip
[327405] Provide an offline CDOWorkspace with Checkout/Update/Commit workflows
https://bugs.eclipse.org/bugs/show_bug.cgi?id=327405
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.workspace.efs')
-rw-r--r--plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/efs/CDOWorkspaceFSUtil.java77
-rw-r--r--plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/AbstractResourceNodeStore.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceFileSystem.java61
-rw-r--r--plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceStore.java40
4 files changed, 156 insertions, 38 deletions
diff --git a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/efs/CDOWorkspaceFSUtil.java b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/efs/CDOWorkspaceFSUtil.java
index 87b3099a45..972740693b 100644
--- a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/efs/CDOWorkspaceFSUtil.java
+++ b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/efs/CDOWorkspaceFSUtil.java
@@ -11,10 +11,11 @@
package org.eclipse.emf.cdo.workspace.efs;
import org.eclipse.emf.cdo.location.ICheckoutSource;
+import org.eclipse.emf.cdo.location.IRepositoryLocation;
+import org.eclipse.emf.cdo.location.IRepositoryLocationManager;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
-import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory;
import org.eclipse.emf.cdo.workspace.CDOWorkspace;
import org.eclipse.emf.cdo.workspace.CDOWorkspaceBase;
import org.eclipse.emf.cdo.workspace.CDOWorkspaceUtil;
@@ -25,6 +26,7 @@ import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.IDBConnectionProvider;
import org.eclipse.net4j.db.h2.H2Adapter;
+import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.resources.IProject;
@@ -41,6 +43,8 @@ import org.h2.jdbcx.JdbcDataSource;
import javax.sql.DataSource;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
@@ -53,6 +57,17 @@ public final class CDOWorkspaceFSUtil
{
}
+ public static CDOWorkspace open(String projectName, File projectFolder) throws Exception
+ {
+ IDBStore local = creatLocalStore(projectFolder);
+ CDOWorkspaceBase base = createWorkspaceBase(new File(projectFolder, "base"));
+
+ IRepositoryLocation remote = readRepositoryLocation(projectFolder);
+
+ CDOWorkspace workspace = CDOWorkspaceUtil.open(local, base, remote);
+ return workspace;
+ }
+
public static void checkout(ICheckoutSource checkoutSource, String projectName, IProgressMonitor monitor)
throws Exception
{
@@ -79,21 +94,17 @@ public final class CDOWorkspaceFSUtil
private static URI checkout(ICheckoutSource checkoutSource, String projectName, File projectFolder) throws Exception
{
- IMappingStrategy mappingStrategy = CDODBUtil.createHorizontalMappingStrategy(false);
- IDBAdapter dbAdapter = createLocalAdapter();
- IDBConnectionProvider dbConnectionProvider = DBUtil.createConnectionProvider(createLocalDataSource(new File(
- projectFolder, "local")));
- IDBStore local = CDODBUtil.createStore(mappingStrategy, dbAdapter, dbConnectionProvider);
-
+ IDBStore local = creatLocalStore(projectFolder);
CDOWorkspaceBase base = createWorkspaceBase(new File(projectFolder, "base"));
- CDOSessionConfigurationFactory remote = checkoutSource.getRepositoryLocation();
+ IRepositoryLocation remote = checkoutSource.getRepositoryLocation();
+ writeRepositoryLocation(projectFolder, remote);
+
String branchPath = checkoutSource.getBranchPath();
long timeStamp = checkoutSource.getTimeStamp();
CDOWorkspace workspace = CDOWorkspaceUtil.checkout(local, base, remote, branchPath, timeStamp);
CDOWorkspaceStore store = getFileSystem().addWorkspaceStore(projectName, workspace);
-
return store.toURI();
}
@@ -102,6 +113,16 @@ public final class CDOWorkspaceFSUtil
return (CDOWorkspaceFileSystem)EFS.getFileSystem(CDOWorkspaceFileSystem.SCHEME);
}
+ private static IDBStore creatLocalStore(File projectFolder)
+ {
+ IMappingStrategy mappingStrategy = CDODBUtil.createHorizontalMappingStrategy(false);
+ IDBAdapter dbAdapter = createLocalAdapter();
+ IDBConnectionProvider dbConnectionProvider = DBUtil.createConnectionProvider(createLocalDataSource(new File(
+ projectFolder, "local")));
+ IDBStore local = CDODBUtil.createStore(mappingStrategy, dbAdapter, dbConnectionProvider);
+ return local;
+ }
+
private static IDBAdapter createLocalAdapter()
{
return new H2Adapter();
@@ -109,10 +130,11 @@ public final class CDOWorkspaceFSUtil
private static DataSource createLocalDataSource(File folder)
{
+ folder.mkdirs();
String path = folder.getAbsolutePath().replace('\\', '/');
JdbcDataSource dataSource = new JdbcDataSource();
- dataSource.setURL("jdbc:h2:" + path);
+ dataSource.setURL("jdbc:h2:" + path + "/db");
return dataSource;
}
@@ -121,4 +143,39 @@ public final class CDOWorkspaceFSUtil
folder.mkdirs();
return CDOWorkspaceUtil.createFolderWorkspaceBase(folder);
}
+
+ private static File getRemotePropertiesFile(File projectFolder)
+ {
+ return new File(projectFolder, "remote.properties");
+ }
+
+ private static void writeRepositoryLocation(File projectFolder, IRepositoryLocation remote) throws IOException
+ {
+ FileOutputStream out = null;
+
+ try
+ {
+ out = new FileOutputStream(getRemotePropertiesFile(projectFolder));
+ remote.write(out);
+ }
+ finally
+ {
+ IOUtil.close(out);
+ }
+ }
+
+ private static IRepositoryLocation readRepositoryLocation(File projectFolder) throws IOException
+ {
+ FileInputStream in = null;
+
+ try
+ {
+ in = new FileInputStream(getRemotePropertiesFile(projectFolder));
+ return IRepositoryLocationManager.INSTANCE.addRepositoryLocation(in);
+ }
+ finally
+ {
+ IOUtil.close(in);
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/AbstractResourceNodeStore.java b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/AbstractResourceNodeStore.java
index b471dac4c8..03bf640fb0 100644
--- a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/AbstractResourceNodeStore.java
+++ b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/AbstractResourceNodeStore.java
@@ -89,6 +89,11 @@ public abstract class AbstractResourceNodeStore extends AbstractFileStore
@Override
public abstract AbstractResourceNodeStore getParent();
+ protected CDOView getView()
+ {
+ return getWorkspaceStore().getView();
+ }
+
protected abstract CDOResourceNode getResourceNode(CDOView view);
protected abstract boolean isDirectory(CDOResourceNode node);
@@ -117,7 +122,7 @@ public abstract class AbstractResourceNodeStore extends AbstractFileStore
{
view = openView(transactional);
RESULT result = run(view);
- if (view instanceof CDOTransaction)
+ if (transactional)
{
CDOTransaction transaction = (CDOTransaction)view;
transaction.commit();
@@ -131,7 +136,10 @@ public abstract class AbstractResourceNodeStore extends AbstractFileStore
}
finally
{
- IOUtil.close(view);
+ if (transactional)
+ {
+ IOUtil.close(view);
+ }
}
}
@@ -149,10 +157,8 @@ public abstract class AbstractResourceNodeStore extends AbstractFileStore
private CDOView openView(boolean transactional)
{
- CDOView view;
CDOWorkspace workspace = getWorkspaceStore().getWorkspace();
- view = transactional ? workspace.openTransaction() : workspace.openView();
- return view;
+ return transactional ? workspace.openTransaction() : getView();
}
private CDOResourceNode getResourceNode(CDOView view)
diff --git a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceFileSystem.java b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceFileSystem.java
index 630de4e923..a42b71a2cb 100644
--- a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceFileSystem.java
+++ b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceFileSystem.java
@@ -15,11 +15,14 @@ import org.eclipse.emf.cdo.workspace.CDOWorkspace;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.filesystem.provider.FileSystem;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IPath;
import java.io.File;
@@ -39,10 +42,20 @@ public class CDOWorkspaceFileSystem extends FileSystem implements IResourceChang
private static CDOWorkspaceFileSystem instance;
+ /**
+ * Maps {@link IProject} name to {@link IFileStore}.
+ */
private Map<String, CDOWorkspaceStore> workspaceStores = new HashMap<String, CDOWorkspaceStore>();
+ /**
+ * <code>true</code> if this {@link CDOWorkspaceFileSystem} is registered as an {@link IResourceChangeListener} with
+ * the {@link IWorkspace}, <code>false</code> otherwise.
+ */
private boolean workspaceListenerRegistered;
+ /**
+ * Called once by the {@link IExtensionRegistry}.
+ */
public CDOWorkspaceFileSystem()
{
instance = this;
@@ -88,29 +101,47 @@ public class CDOWorkspaceFileSystem extends FileSystem implements IResourceChang
IResourceDelta delta = event.getDelta();
if (delta != null)
{
- for (IResourceDelta projectDelta : delta.getAffectedChildren())
+ IResourceDelta[] deltas = delta.getAffectedChildren();
+ projectsChanged(deltas);
+ }
+ }
+
+ private void projectsChanged(IResourceDelta[] deltas)
+ {
+ for (IResourceDelta delta : deltas)
+ {
+ int kind = delta.getKind();
+ boolean removed = kind == IResourceDelta.REMOVED;
+ if (!removed)
{
- if (projectDelta.getKind() == IResourceDelta.REMOVED)
+ int flags = delta.getFlags();
+ if ((flags & IResourceDelta.OPEN) != 0)
{
- String name = projectDelta.getFullPath().segment(0);
+ IProject project = (IProject)delta.getResource();
+ removed = !project.isOpen();
+ }
+ }
- CDOWorkspaceStore store;
- synchronized (workspaceStores)
- {
- store = workspaceStores.remove(name);
+ if (removed)
+ {
+ String name = delta.getFullPath().segment(0);
- if (workspaceStores.isEmpty())
- {
- ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
- workspaceListenerRegistered = false;
- }
- }
+ CDOWorkspaceStore store;
+ synchronized (workspaceStores)
+ {
+ store = workspaceStores.remove(name);
- if (store != null)
+ if (workspaceStores.isEmpty())
{
- store.dispose();
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ workspaceListenerRegistered = false;
}
}
+
+ if (store != null)
+ {
+ store.dispose();
+ }
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceStore.java b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceStore.java
index ec9b29f049..caa00da76c 100644
--- a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceStore.java
+++ b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceStore.java
@@ -14,8 +14,10 @@ import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.cdo.workspace.CDOWorkspace;
+import org.eclipse.emf.cdo.workspace.efs.CDOWorkspaceFSUtil;
import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.emf.ecore.EObject;
@@ -42,6 +44,8 @@ public final class CDOWorkspaceStore extends AbstractResourceNodeStore
private CDOWorkspace workspace;
+ private CDOView view;
+
public CDOWorkspaceStore(String name, File location)
{
this.name = name;
@@ -68,6 +72,18 @@ public final class CDOWorkspaceStore extends AbstractResourceNodeStore
this.workspace = workspace;
}
+ private CDOWorkspace openWorkspace()
+ {
+ try
+ {
+ return CDOWorkspaceFSUtil.open(name, location);
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
@Override
public AbstractResourceNodeStore getParent()
{
@@ -118,8 +134,11 @@ public final class CDOWorkspaceStore extends AbstractResourceNodeStore
public void dispose()
{
- // TODO: implement CDOWorkspaceStore.dispose()
- throw new UnsupportedOperationException();
+ if (view != null)
+ {
+ IOUtil.close(view);
+ view = null;
+ }
}
@Override
@@ -129,6 +148,17 @@ public final class CDOWorkspaceStore extends AbstractResourceNodeStore
}
@Override
+ protected synchronized CDOView getView()
+ {
+ if (view == null)
+ {
+ view = workspace.openView();
+ }
+
+ return view;
+ }
+
+ @Override
protected CDOResourceNode getResourceNode(CDOView view)
{
return view.getRootResource();
@@ -155,10 +185,4 @@ public final class CDOWorkspaceStore extends AbstractResourceNodeStore
}
}
}
-
- private CDOWorkspace openWorkspace()
- {
- // TODO: implement CDOWorkspaceStore.openWorkspace()
- throw new UnsupportedOperationException();
- }
}

Back to the top