Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-09-06 11:47:08 +0000
committerEike Stepper2012-09-06 11:47:08 +0000
commitcfdef9afcf736cd872cd784647c25c52b653a7bb (patch)
tree07c9bb370e7cea69c0eb8e06737a74bd70d534f7 /plugins/org.eclipse.emf.cdo.transfer.workspace/src
parent3224388d98796036d49cc879878e418aef6e6d5d (diff)
downloadcdo-cfdef9afcf736cd872cd784647c25c52b653a7bb.tar.gz
cdo-cfdef9afcf736cd872cd784647c25c52b653a7bb.tar.xz
cdo-cfdef9afcf736cd872cd784647c25c52b653a7bb.zip
388928: Develop a resource transfer framework
https://bugs.eclipse.org/bugs/show_bug.cgi?id=388928
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.transfer.workspace/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/internal/workspace/bundle/OM.java44
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/workspace/WorkspaceTransferSystem.java221
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/workspace/package-info.java17
3 files changed, 282 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/internal/workspace/bundle/OM.java b/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/internal/workspace/bundle/OM.java
new file mode 100644
index 0000000000..34c9182cfa
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/internal/workspace/bundle/OM.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2004 - 2012 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.transfer.internal.workspace.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.OSGiActivator;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.trace.OMTracer;
+
+/**
+ * The <em>Operations & Maintenance</em> class of this bundle.
+ *
+ * @author Eike Stepper
+ */
+public abstract class OM
+{
+ public static final String BUNDLE_ID = "org.eclipse.emf.cdo.transfer.workspace"; //$NON-NLS-1$
+
+ public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
+
+ public static final OMLogger LOG = BUNDLE.logger();
+
+ public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class Activator extends OSGiActivator
+ {
+ public Activator()
+ {
+ super(BUNDLE);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/workspace/WorkspaceTransferSystem.java b/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/workspace/WorkspaceTransferSystem.java
new file mode 100644
index 0000000000..b5357cebbd
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/workspace/WorkspaceTransferSystem.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2004 - 2012 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.transfer.workspace;
+
+import org.eclipse.emf.cdo.transfer.CDOTransferElement;
+import org.eclipse.emf.cdo.transfer.CDOTransferSystem;
+
+import org.eclipse.net4j.util.WrappedException;
+
+import org.eclipse.emf.common.util.URI;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+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 java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @author Eike Stepper
+ * @since 4.2
+ */
+public class WorkspaceTransferSystem extends CDOTransferSystem
+{
+ public static final String TYPE = "workspace";
+
+ private static final IWorkspaceRoot ROOT = ResourcesPlugin.getWorkspace().getRoot();
+
+ public WorkspaceTransferSystem()
+ {
+ super(false);
+ }
+
+ @Override
+ public String getType()
+ {
+ return TYPE;
+ }
+
+ public String getDefaultEncoding()
+ {
+ try
+ {
+ return ROOT.getDefaultCharset();
+ }
+ catch (CoreException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ @Override
+ public URI getURI(IPath path)
+ {
+ return URI.createPlatformResourceURI(path.toString(), true);
+ }
+
+ @Override
+ public CDOTransferElement getElement(IPath path)
+ {
+ IResource resource = ROOT.findMember(path);
+ if (resource.exists())
+ {
+ return new Element(this, resource);
+ }
+
+ return null;
+ }
+
+ @Override
+ public void createFolder(IPath path) throws IOException
+ {
+ try
+ {
+ IFolder folder = ROOT.getFolder(path);
+ folder.create(true, true, null);
+ }
+ catch (CoreException ex)
+ {
+ throw new IOException(ex);
+ }
+ }
+
+ @Override
+ public void createBinary(IPath path, InputStream source) throws IOException
+ {
+ try
+ {
+ IFile file = ROOT.getFile(path);
+ file.create(source, true, null);
+ }
+ catch (CoreException ex)
+ {
+ throw new IOException(ex);
+ }
+ }
+
+ @Override
+ public void createText(IPath path, InputStream source, String encoding) throws IOException
+ {
+ try
+ {
+ IFile file = ROOT.getFile(path);
+ file.create(source, true, null);
+ file.setCharset(encoding, null);
+ }
+ catch (CoreException ex)
+ {
+ throw new IOException(ex);
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Workspace";
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static class Element extends CDOTransferElement
+ {
+ private IResource resource;
+
+ public Element(CDOTransferSystem system, IResource resource)
+ {
+ super(system);
+ this.resource = resource;
+ }
+
+ @Override
+ public Object getNativeObject()
+ {
+ return resource;
+ }
+
+ @Override
+ public IPath getPath()
+ {
+ return resource.getFullPath();
+ }
+
+ @Override
+ public boolean isDirectory()
+ {
+ return resource instanceof IContainer;
+ }
+
+ @Override
+ protected CDOTransferElement[] doGetChildren() throws IOException
+ {
+ try
+ {
+ IResource[] children = ((IContainer)resource).members();
+ CDOTransferElement[] result = new Element[children.length];
+
+ for (int i = 0; i < children.length; i++)
+ {
+ IResource child = children[i];
+ result[i] = new Element(getSystem(), child);
+ }
+
+ return result;
+ }
+ catch (CoreException ex)
+ {
+ throw new IOException(ex);
+ }
+ }
+
+ @Override
+ protected InputStream doOpenInputStream() throws IOException
+ {
+ try
+ {
+ return ((IFile)resource).getContents();
+ }
+ catch (CoreException ex)
+ {
+ throw new IOException(ex);
+ }
+ }
+
+ // @Override
+ // protected OutputStream doOpenOutputStream() throws IOException
+ // {
+ // return new ByteArrayOutputStream()
+ // {
+ // @Override
+ // public void close() throws IOException
+ // {
+ // if (resource.exists())
+ // {
+ // try
+ // {
+ // ((IFile)resource).setContents(new ByteArrayInputStream(toByteArray()), true, true, null);
+ // }
+ // catch (CoreException ex)
+ // {
+ // throw new IOException(ex);
+ // }
+ // }
+ // }
+ // };
+ // }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/workspace/package-info.java b/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/workspace/package-info.java
new file mode 100644
index 0000000000..6c09ada99a
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/workspace/package-info.java
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2004 - 2012 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
+ */
+
+/**
+ * Client concepts for dealing with transfers of {@link org.eclipse.emf.cdo.eresource.CDOResourceLeaf resources}
+ * between {@link org.eclipse.emf.cdo.transfer.CDOTransferSystem systems}.
+ */
+package org.eclipse.emf.cdo.transfer.workspace;
+

Back to the top