diff options
author | Eike Stepper | 2010-10-18 10:07:27 +0000 |
---|---|---|
committer | Eike Stepper | 2010-10-18 10:07:27 +0000 |
commit | 6e584140d4942669e1bc4a6d9b0684b2a421060e (patch) | |
tree | 04745a4c2ad89772bfecffc9e0538bc4179151c7 | |
parent | 8a60628572ccb8cc0776d7f37b4e60ec4e11d61a (diff) | |
download | cdo-6e584140d4942669e1bc4a6d9b0684b2a421060e.tar.gz cdo-6e584140d4942669e1bc4a6d9b0684b2a421060e.tar.xz cdo-6e584140d4942669e1bc4a6d9b0684b2a421060e.zip |
[327405] Provide an offline CDOWorkspace with Checkout/Update/Commit workflows
https://bugs.eclipse.org/bugs/show_bug.cgi?id=327405
11 files changed, 311 insertions, 75 deletions
diff --git a/plugins/org.eclipse.emf.cdo.efs/src/org/eclipse/emf/cdo/internal/efs/bundle/OM.java b/plugins/org.eclipse.emf.cdo.efs/src/org/eclipse/emf/cdo/internal/efs/bundle/OM.java index 0c7627f51a..f857bbc2ba 100644 --- a/plugins/org.eclipse.emf.cdo.efs/src/org/eclipse/emf/cdo/internal/efs/bundle/OM.java +++ b/plugins/org.eclipse.emf.cdo.efs/src/org/eclipse/emf/cdo/internal/efs/bundle/OM.java @@ -55,7 +55,7 @@ public abstract class OM /** * @author Eike Stepper */ - public static final class Activator extends OSGiActivator.WithConfig implements IResourceChangeListener + public static final class Activator extends OSGiActivator.WithState implements IResourceChangeListener { public Activator() { @@ -64,14 +64,19 @@ public abstract class OM @SuppressWarnings("unchecked") @Override - protected void doStartWithConfig(Object config) throws Exception + protected void doStartWithState(Object state) throws Exception { - projectNames.putAll((Map<URI, String>)config); + Map<URI, String> names = (Map<URI, String>)state; + if (names != null) + { + projectNames.putAll(names); + } + ResourcesPlugin.getWorkspace().addResourceChangeListener(this); } @Override - protected Object doStopWithConfig() throws Exception + protected Object doStopWithState() throws Exception { ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); return projectNames; diff --git a/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/BranchCheckoutSource.java b/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/BranchCheckoutSource.java new file mode 100644 index 0000000000..55cd6abafd --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/BranchCheckoutSource.java @@ -0,0 +1,114 @@ +/** + * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.internal.location; + +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.location.ICheckoutSource; +import org.eclipse.emf.cdo.location.IRepositoryLocation; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.session.CDOSessionConfiguration; + +import org.eclipse.net4j.util.container.Container; +import org.eclipse.net4j.util.io.IOUtil; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Eike Stepper + */ +public class BranchCheckoutSource extends Container<BranchCheckoutSource> implements ICheckoutSource +{ + private BranchCheckoutSource parent; + + private String name; + + private List<BranchCheckoutSource> subBranches; + + public BranchCheckoutSource(BranchCheckoutSource parent, String name) + { + this.parent = parent; + this.name = name; + activate(); + } + + public IRepositoryLocation getRepositoryLocation() + { + return parent.getRepositoryLocation(); + } + + public String getBranchPath() + { + if (parent != null) + { + return parent.getBranchPath() + "/" + name; + } + + return name; + } + + public long getTimeStamp() + { + return CDOBranchPoint.UNSPECIFIED_DATE; + } + + public BranchCheckoutSource[] getElements() + { + if (subBranches == null) + { + subBranches = new ArrayList<BranchCheckoutSource>(); + CDOSessionConfiguration config = getRepositoryLocation().createSessionConfiguration(); + CDOSession session = config.openSession(); + + try + { + CDOBranch[] branches = session.getBranchManager().getBranch(getBranchPath()).getBranches(); + for (CDOBranch branch : branches) + { + subBranches.add(new BranchCheckoutSource(this, branch.getName())); + } + } + finally + { + IOUtil.close(session); + } + } + + return subBranches.toArray(new BranchCheckoutSource[subBranches.size()]); + } + + @Override + public String toString() + { + return name; + } + + /** + * @author Eike Stepper + */ + public static class Main extends BranchCheckoutSource + { + private IRepositoryLocation location; + + public Main(IRepositoryLocation location) + { + super(null, CDOBranch.MAIN_BRANCH_NAME); + this.location = location; + } + + @Override + public IRepositoryLocation getRepositoryLocation() + { + return location; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/RepositoryLocation.java b/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/RepositoryLocation.java index edb084f02e..251ca96a29 100644 --- a/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/RepositoryLocation.java +++ b/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/RepositoryLocation.java @@ -10,20 +10,20 @@ */ package org.eclipse.emf.cdo.internal.location; +import org.eclipse.emf.cdo.location.ICheckoutSource; import org.eclipse.emf.cdo.location.IRepositoryLocation; import org.eclipse.emf.cdo.net4j.CDONet4jUtil; import org.eclipse.emf.cdo.session.CDOSessionConfiguration; import org.eclipse.net4j.connector.IConnector; import org.eclipse.net4j.util.ObjectUtil; +import org.eclipse.net4j.util.container.Container; import org.eclipse.net4j.util.container.IPluginContainer; -import java.io.Serializable; - /** * @author Eike Stepper */ -public class RepositoryLocation implements IRepositoryLocation, Serializable +public class RepositoryLocation extends Container<ICheckoutSource> implements IRepositoryLocation { private static final long serialVersionUID = 1L; @@ -35,6 +35,8 @@ public class RepositoryLocation implements IRepositoryLocation, Serializable private String repositoryName; + private ICheckoutSource[] elements = { new BranchCheckoutSource.Main(this) }; + public RepositoryLocation() { } @@ -46,6 +48,7 @@ public class RepositoryLocation implements IRepositoryLocation, Serializable this.connectorType = connectorType; this.connectorDescription = connectorDescription; this.repositoryName = repositoryName; + activate(); } public RepositoryLocationManager getManager() @@ -68,6 +71,11 @@ public class RepositoryLocation implements IRepositoryLocation, Serializable return repositoryName; } + public ICheckoutSource[] getElements() + { + return elements; + } + public CDOSessionConfiguration createSessionConfiguration() { org.eclipse.emf.cdo.net4j.CDOSessionConfiguration config = CDONet4jUtil.createSessionConfiguration(); diff --git a/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/RepositoryLocationManager.java b/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/RepositoryLocationManager.java index fd6ec8e4dd..4fad33c905 100644 --- a/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/RepositoryLocationManager.java +++ b/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/RepositoryLocationManager.java @@ -15,15 +15,13 @@ import org.eclipse.emf.cdo.location.IRepositoryLocationManager; import org.eclipse.net4j.util.container.Container; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; /** * @author Eike Stepper */ -public class RepositoryLocationManager extends Container<IRepositoryLocation> implements IRepositoryLocationManager, - Serializable +public class RepositoryLocationManager extends Container<IRepositoryLocation> implements IRepositoryLocationManager { private static final long serialVersionUID = 1L; @@ -51,8 +49,8 @@ public class RepositoryLocationManager extends Container<IRepositoryLocation> im String repositoryName) { RepositoryLocation location = new RepositoryLocation(this, connectorType, connectorDescription, repositoryName); - boolean added; + boolean added; synchronized (repositoryLocations) { added = repositoryLocations.add(location); @@ -79,4 +77,25 @@ public class RepositoryLocationManager extends Container<IRepositoryLocation> im fireElementRemovedEvent(location); } } + + // @Override + // protected void doActivate() throws Exception + // { + // super.doActivate(); + // for (IRepositoryLocation location : repositoryLocations) + // { + // LifecycleUtil.activate(location); + // } + // } + // + // @Override + // protected void doDeactivate() throws Exception + // { + // for (IRepositoryLocation location : repositoryLocations) + // { + // LifecycleUtil.deactivate(location); + // } + // + // super.doDeactivate(); + // } } diff --git a/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/bundle/OM.java b/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/bundle/OM.java index a4b4a8b1fd..72e89595e9 100644 --- a/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/bundle/OM.java +++ b/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/internal/location/bundle/OM.java @@ -11,6 +11,7 @@ package org.eclipse.emf.cdo.internal.location.bundle; import org.eclipse.emf.cdo.internal.location.RepositoryLocationManager; +import org.eclipse.emf.cdo.location.IRepositoryLocation; import org.eclipse.emf.cdo.location.IRepositoryLocationManager; import org.eclipse.net4j.util.om.OMBundle; @@ -19,6 +20,9 @@ import org.eclipse.net4j.util.om.OSGiActivator; import org.eclipse.net4j.util.om.log.OMLogger; import org.eclipse.net4j.util.om.trace.OMTracer; +import java.util.ArrayList; +import java.util.List; + /** * The <em>Operations & Maintenance</em> class of this bundle. * @@ -44,7 +48,7 @@ public abstract class OM /** * @author Eike Stepper */ - public static final class Activator extends OSGiActivator.WithConfig + public static final class Activator extends OSGiActivator.WithState { public Activator() { @@ -52,15 +56,33 @@ public abstract class OM } @Override - protected void doStartWithConfig(Object config) throws Exception + protected void doStartWithState(Object state) throws Exception { - repositoryLocationManager = (RepositoryLocationManager)config; + @SuppressWarnings("unchecked") + List<List<String>> locations = (List<List<String>>)state; + if (locations != null) + { + for (List<String> location : locations) + { + repositoryLocationManager.addRepositoryLocation(location.get(0), location.get(1), location.get(2)); + } + } } @Override - protected Object doStopWithConfig() throws Exception + protected Object doStopWithState() throws Exception { - return repositoryLocationManager; + List<List<String>> locations = new ArrayList<List<String>>(); + for (IRepositoryLocation location : repositoryLocationManager.getRepositoryLocations()) + { + List<String> list = new ArrayList<String>(); + list.add(location.getConnectorType()); + list.add(location.getConnectorDescription()); + list.add(location.getRepositoryName()); + locations.add(list); + } + + return locations; } } } diff --git a/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/location/ICheckoutSource.java b/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/location/ICheckoutSource.java new file mode 100644 index 0000000000..63854209a4 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/location/ICheckoutSource.java @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.location; + +/** + * @author Eike Stepper + */ +public interface ICheckoutSource +{ + public IRepositoryLocation getRepositoryLocation(); + + public String getBranchPath(); + + public long getTimeStamp(); +} diff --git a/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/location/IRepositoryLocation.java b/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/location/IRepositoryLocation.java index 0c06e5cff0..897ab93160 100644 --- a/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/location/IRepositoryLocation.java +++ b/plugins/org.eclipse.emf.cdo.location/src/org/eclipse/emf/cdo/location/IRepositoryLocation.java @@ -12,11 +12,13 @@ package org.eclipse.emf.cdo.location; import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory; +import org.eclipse.net4j.util.container.IContainer; + /** * @author Eike Stepper * @since 4.0 */ -public interface IRepositoryLocation extends CDOSessionConfigurationFactory +public interface IRepositoryLocation extends IContainer<ICheckoutSource>, CDOSessionConfigurationFactory { public String getConnectorType(); diff --git a/plugins/org.eclipse.emf.cdo.ui.location/src/org/eclipse/emf/cdo/ui/internal/location/RepositoryLocationsView.java b/plugins/org.eclipse.emf.cdo.ui.location/src/org/eclipse/emf/cdo/ui/internal/location/RepositoryLocationsView.java index 4776fa37f3..c6b49132ee 100644 --- a/plugins/org.eclipse.emf.cdo.ui.location/src/org/eclipse/emf/cdo/ui/internal/location/RepositoryLocationsView.java +++ b/plugins/org.eclipse.emf.cdo.ui.location/src/org/eclipse/emf/cdo/ui/internal/location/RepositoryLocationsView.java @@ -11,6 +11,7 @@ package org.eclipse.emf.cdo.ui.internal.location; import org.eclipse.emf.cdo.location.IRepositoryLocationManager; +import org.eclipse.emf.cdo.ui.internal.location.bundle.OM; import org.eclipse.net4j.util.container.IContainer; import org.eclipse.net4j.util.ui.views.ContainerItemProvider; @@ -76,11 +77,23 @@ public class RepositoryLocationsView extends ContainerView @Override public void run() { - NewRepositoryLocationDialog dialog = new NewRepositoryLocationDialog(getSite().getShell()); - if (dialog.open() == NewRepositoryLocationDialog.OK) + try { - IRepositoryLocationManager.INSTANCE.addRepositoryLocation(dialog.getConnectorType(), - dialog.getConnectorDescription(), dialog.getRepositoryName()); + NewRepositoryLocationDialog dialog = new NewRepositoryLocationDialog(getSite().getShell()); + if (dialog.open() == NewRepositoryLocationDialog.OK) + { + String connectorType = dialog.getConnectorType(); + String connectorDescription = dialog.getConnectorDescription(); + String repositoryName = dialog.getRepositoryName(); + + IRepositoryLocationManager.INSTANCE + .addRepositoryLocation(connectorType, connectorDescription, repositoryName); + } + } + catch (RuntimeException ex) + { + OM.LOG.error(ex); + throw ex; } } } diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/JVMConnectorWizard.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/JVMConnectorWizard.java index e7ee1c3ae8..884d9e86c4 100644 --- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/JVMConnectorWizard.java +++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/container/JVMConnectorWizard.java @@ -16,15 +16,20 @@ import org.eclipse.net4j.util.ui.container.ElementWizard; import org.eclipse.net4j.util.ui.container.ElementWizardFactory; import org.eclipse.spi.net4j.ConnectorFactory; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; /** * @author Eike Stepper * @author Martin Fluegge * @since 4.0 */ -public class JVMConnectorWizard extends ElementWizard +public class JVMConnectorWizard extends ElementWizard implements ModifyListener { + private Text acceptorNameText; + public JVMConnectorWizard() { } @@ -32,7 +37,21 @@ public class JVMConnectorWizard extends ElementWizard @Override protected void create(Composite parent) { - addText(parent, "Acceptor Name:"); + acceptorNameText = addText(parent, "Acceptor Name:"); + acceptorNameText.addModifyListener(this); + } + + public void modifyText(ModifyEvent e) + { + String acceptorName = acceptorNameText.getText(); + if (acceptorName.length() == 0) + { + setValidationError(acceptorNameText, "Acceptor name is empty."); + return; + } + + setResultDescription(acceptorName); + setValidationOK(); } /** diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java index 24dc3a6bb5..fcdb99516d 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIActivator.java @@ -12,7 +12,7 @@ package org.eclipse.net4j.util.ui; import org.eclipse.net4j.util.om.OMBundle; import org.eclipse.net4j.util.om.OSGiActivator; -import org.eclipse.net4j.util.om.OSGiActivator.ConfigHandler; +import org.eclipse.net4j.util.om.OSGiActivator.StateHandler; import org.eclipse.ui.plugin.AbstractUIPlugin; @@ -113,24 +113,24 @@ public class UIActivator extends AbstractUIPlugin * @author Eike Stepper * @since 3.1 */ - public static abstract class WithConfig extends UIActivator + public static abstract class WithState extends UIActivator { - private ConfigHandler handler = new ConfigHandler(getOMBundle()) + private StateHandler handler = new StateHandler(getOMBundle()) { @Override - protected void startWithConfig(Object config) throws Exception + protected void startWithState(Object state) throws Exception { - doStartWithConfig(config); + doStartWithState(state); } @Override - protected Object stopWithConfig() throws Exception + protected Object stopWithState() throws Exception { - return doStopWithConfig(); + return doStopWithState(); } }; - public WithConfig(OMBundle bundle) + public WithState(OMBundle bundle) { super(bundle); } @@ -147,8 +147,8 @@ public class UIActivator extends AbstractUIPlugin handler.stop(); } - protected abstract void doStartWithConfig(Object config) throws Exception; + protected abstract void doStartWithState(Object state) throws Exception; - protected abstract Object doStopWithConfig() throws Exception; + protected abstract Object doStopWithState() throws Exception; } } diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OSGiActivator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OSGiActivator.java index 6941b78050..3c4f7c210c 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OSGiActivator.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/OSGiActivator.java @@ -183,47 +183,53 @@ public abstract class OSGiActivator implements BundleActivator * @author Eike Stepper * @since 3.1 */ - public static abstract class ConfigHandler + public static abstract class StateHandler { private OSGiBundle bundle; - public ConfigHandler(OMBundle bundle) + public StateHandler(OMBundle bundle) { this.bundle = (OSGiBundle)bundle; } public final void start() throws Exception { - File configFile = bundle.getConfigFile(); - if (!configFile.exists()) + Object state = null; + File stateFile = getStateFile(); + if (stateFile.exists()) { - startWithConfig(null); - return; - } - - FileInputStream fis = null; + FileInputStream fis = null; - try - { - fis = new FileInputStream(configFile); - ObjectInputStream ois = new ObjectInputStream(fis) + try { - @Override - protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException + fis = new FileInputStream(stateFile); + ObjectInputStream ois = new ObjectInputStream(fis) { - String className = desc.getName(); - return bundle.getAccessor().getClassLoader().loadClass(className); - } - }; - - Object config = ois.readObject(); - IOUtil.close(ois); - startWithConfig(config); - } - finally - { - IOUtil.close(fis); + @Override + protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException + { + String className = desc.getName(); + return bundle.getAccessor().getClassLoader().loadClass(className); + } + }; + + state = ois.readObject(); + IOUtil.close(ois); + } + catch (Exception ex) + { + OM.LOG.error(ex); + IOUtil.close(fis); + fis = null; + stateFile.delete(); + } + finally + { + IOUtil.close(fis); + } } + + startWithState(state); } public final void stop() throws Exception @@ -232,12 +238,12 @@ public abstract class OSGiActivator implements BundleActivator try { - Object config = stopWithConfig(); + Object state = stopWithState(); - File configFile = bundle.getConfigFile(); - fos = new FileOutputStream(configFile); + File stateFile = getStateFile(); + fos = new FileOutputStream(stateFile); ObjectOutputStream oos = new ObjectOutputStream(fos); - oos.writeObject(config); + oos.writeObject(state); IOUtil.close(oos); } finally @@ -246,33 +252,38 @@ public abstract class OSGiActivator implements BundleActivator } } - protected abstract void startWithConfig(Object config) throws Exception; + private File getStateFile() + { + return new File(bundle.getStateLocation(), "state.bin"); + } + + protected abstract void startWithState(Object state) throws Exception; - protected abstract Object stopWithConfig() throws Exception; + protected abstract Object stopWithState() throws Exception; } /** * @author Eike Stepper * @since 3.1 */ - public static abstract class WithConfig extends OSGiActivator + public static abstract class WithState extends OSGiActivator { - private ConfigHandler handler = new ConfigHandler(getOMBundle()) + private StateHandler handler = new StateHandler(getOMBundle()) { @Override - protected void startWithConfig(Object config) throws Exception + protected void startWithState(Object state) throws Exception { - doStartWithConfig(config); + doStartWithState(state); } @Override - protected Object stopWithConfig() throws Exception + protected Object stopWithState() throws Exception { - return doStopWithConfig(); + return doStopWithState(); } }; - public WithConfig(OMBundle bundle) + public WithState(OMBundle bundle) { super(bundle); } @@ -289,8 +300,8 @@ public abstract class OSGiActivator implements BundleActivator handler.stop(); } - protected abstract void doStartWithConfig(Object config) throws Exception; + protected abstract void doStartWithState(Object state) throws Exception; - protected abstract Object doStopWithConfig() throws Exception; + protected abstract Object doStopWithState() throws Exception; } } |