Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-09-07 15:28:26 +0000
committerEike Stepper2012-09-07 15:28:26 +0000
commit3d0843880e6b3fd11a55da1980af4f74e0406975 (patch)
tree498f302a6645b7042a55c5010dee212f10edd734 /plugins/org.eclipse.emf.cdo.transfer/src
parente1d1095477205cff8cf522e7127fcfa2d88b769b (diff)
downloadcdo-3d0843880e6b3fd11a55da1980af4f74e0406975.tar.gz
cdo-3d0843880e6b3fd11a55da1980af4f74e0406975.tar.xz
cdo-3d0843880e6b3fd11a55da1980af4f74e0406975.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/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/FileSystemTransferSystem.java53
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java29
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferElement.java14
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java11
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/TransferTest.java6
6 files changed, 70 insertions, 45 deletions
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/FileSystemTransferSystem.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/FileSystemTransferSystem.java
index fe255280a1..29abe67eaa 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/FileSystemTransferSystem.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/FileSystemTransferSystem.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.cdo.spi.transfer;
import org.eclipse.emf.cdo.transfer.CDOTransferElement;
import org.eclipse.emf.cdo.transfer.CDOTransferSystem;
+import org.eclipse.net4j.util.io.IORuntimeException;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.emf.common.util.URI;
@@ -68,24 +69,40 @@ public class FileSystemTransferSystem extends CDOTransferSystem
}
@Override
- public void createFolder(IPath path) throws IOException
+ public CDOTransferElement getElement(URI uri)
+ {
+ if (uri.isFile())
+ {
+ return getElement(uri.path());
+ }
+
+ return null;
+ }
+
+ @Override
+ public void createFolder(IPath path)
{
File file = getFile(path);
mkDir(file);
}
@Override
- public void createBinary(IPath path, InputStream source) throws IOException
+ public void createBinary(IPath path, InputStream source)
{
File file = getFile(path);
mkParent(file);
- OutputStream target = new FileOutputStream(file);
+ OutputStream target = null;
try
{
+ target = new FileOutputStream(file);
IOUtil.copy(source, target);
}
+ catch (IOException ex)
+ {
+ throw new IORuntimeException();
+ }
finally
{
IOUtil.close(target);
@@ -93,17 +110,22 @@ public class FileSystemTransferSystem extends CDOTransferSystem
}
@Override
- public void createText(IPath path, InputStream source, String encoding) throws IOException
+ public void createText(IPath path, InputStream source, String encoding)
{
File file = getFile(path);
mkParent(file);
- Writer target = new FileWriter(file);
+ Writer target = null;
try
{
+ target = new FileWriter(file);
IOUtil.copyCharacter(new InputStreamReader(source, encoding), target);
}
+ catch (IOException ex)
+ {
+ throw new IORuntimeException();
+ }
finally
{
IOUtil.close(target);
@@ -121,7 +143,7 @@ public class FileSystemTransferSystem extends CDOTransferSystem
return new File(path.toOSString());
}
- protected void mkParent(File file) throws IOException
+ protected void mkParent(File file)
{
File parent = file.getParentFile();
if (parent != null)
@@ -130,20 +152,20 @@ public class FileSystemTransferSystem extends CDOTransferSystem
}
}
- protected void mkDir(File file) throws IOException
+ protected void mkDir(File file)
{
if (file.exists())
{
if (!file.isDirectory())
{
- throw new IOException("Not a folder " + file);
+ throw new IORuntimeException("Not a folder " + file);
}
}
else
{
if (!file.mkdirs())
{
- throw new IOException("Could not create folder " + file);
+ throw new IORuntimeException("Could not create folder " + file);
}
}
}
@@ -180,7 +202,7 @@ public class FileSystemTransferSystem extends CDOTransferSystem
}
@Override
- protected CDOTransferElement[] doGetChildren() throws IOException
+ protected CDOTransferElement[] doGetChildren()
{
File[] children = file.listFiles();
CDOTransferElement[] result = new Element[children.length];
@@ -195,9 +217,16 @@ public class FileSystemTransferSystem extends CDOTransferSystem
}
@Override
- protected InputStream doOpenInputStream() throws IOException
+ protected InputStream doOpenInputStream()
{
- return new FileInputStream(file);
+ try
+ {
+ return new FileInputStream(file);
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java
index 83f4fbb283..b876f40751 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java
@@ -30,7 +30,6 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
-import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
@@ -134,23 +133,23 @@ public class CDOTransfer implements INotifier
return result;
}
- public CDOTransferMapping map(IPath sourcePath) throws IOException
+ public CDOTransferMapping map(IPath sourcePath)
{
CDOTransferElement source = sourceSystem.getElement(sourcePath);
return map(source);
}
- public CDOTransferMapping map(String sourcePath) throws IOException
+ public CDOTransferMapping map(String sourcePath)
{
return map(new Path(sourcePath));
}
- public CDOTransferMapping map(CDOTransferElement source) throws IOException
+ public CDOTransferMapping map(CDOTransferElement source)
{
return map(source, rootMapping);
}
- protected CDOTransferMapping map(CDOTransferElement source, CDOTransferMapping parent) throws IOException
+ protected CDOTransferMapping map(CDOTransferElement source, CDOTransferMapping parent)
{
CDOTransferMapping mapping = mappings.get(source);
if (mapping == null)
@@ -175,7 +174,7 @@ public class CDOTransfer implements INotifier
mapping.getChildren();
}
- protected CDOTransferMapping createMapping(CDOTransferElement source, CDOTransferMapping parent) throws IOException
+ protected CDOTransferMapping createMapping(CDOTransferElement source, CDOTransferMapping parent)
{
return new CDOTransferMappingImpl(this, source, parent);
}
@@ -217,14 +216,14 @@ public class CDOTransfer implements INotifier
}
}
- public void perform() throws IOException
+ public void perform()
{
validate(rootMapping);
perform(rootMapping);
modelTransferContext.save();
}
- protected void perform(CDOTransferMapping mapping) throws IOException
+ protected void perform(CDOTransferMapping mapping)
{
CDOTransferType transferType = mapping.getTransferType();
if (transferType == CDOTransferType.FOLDER)
@@ -246,7 +245,7 @@ public class CDOTransfer implements INotifier
}
}
- protected void performFolder(CDOTransferMapping mapping) throws IOException
+ protected void performFolder(CDOTransferMapping mapping)
{
if (mapping.getStatus() == CDOTransferMapping.Status.NEW)
{
@@ -259,12 +258,12 @@ public class CDOTransfer implements INotifier
}
}
- protected void performModel(CDOTransferMapping mapping) throws IOException
+ protected void performModel(CDOTransferMapping mapping)
{
modelTransferContext.perform(mapping);
}
- protected void performBinary(CDOTransferMapping mapping) throws IOException
+ protected void performBinary(CDOTransferMapping mapping)
{
IPath path = mapping.getFullPath();
InputStream source = mapping.getSource().openInputStream();
@@ -279,7 +278,7 @@ public class CDOTransfer implements INotifier
}
}
- protected void performText(CDOTransferMapping mapping, String encoding) throws IOException
+ protected void performText(CDOTransferMapping mapping, String encoding)
{
IPath path = mapping.getFullPath();
InputStream source = mapping.getSource().openInputStream();
@@ -619,7 +618,7 @@ public class CDOTransfer implements INotifier
return sourceResourceSet.getResource(uri, true);
}
- protected Resource getTargetResource(CDOTransferMapping mapping) throws IOException
+ protected Resource getTargetResource(CDOTransferMapping mapping)
{
IPath path = mapping.getFullPath();
ResourceSet targetResourceSet = getTargetResourceSet();
@@ -659,7 +658,7 @@ public class CDOTransfer implements INotifier
return registry.getFactory(uri) != null;
}
- protected void perform(CDOTransferMapping mapping) throws IOException
+ protected void perform(CDOTransferMapping mapping)
{
Resource sourceResource = getSourceResource(mapping);
Resource targetResource = getTargetResource(mapping);
@@ -671,7 +670,7 @@ public class CDOTransfer implements INotifier
contents.addAll(targetContents);
}
- protected void save() throws IOException
+ protected void save()
{
for (Resource resource : elementResources.values())
{
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferElement.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferElement.java
index 477f4c81c0..1192904a9b 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferElement.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferElement.java
@@ -71,7 +71,7 @@ public abstract class CDOTransferElement
return system.getElement(path.removeLastSegments(1));
}
- public final CDOTransferElement[] getChildren() throws IOException
+ public final CDOTransferElement[] getChildren()
{
if (isDirectory())
{
@@ -81,18 +81,18 @@ public abstract class CDOTransferElement
return NO_CHILDREN;
}
- public final CDOTransferElement getChild(IPath path) throws IOException
+ public final CDOTransferElement getChild(IPath path)
{
IPath childPath = getPath().append(path.makeRelative());
return system.getElement(childPath);
}
- public final CDOTransferElement getChild(String path) throws IOException
+ public final CDOTransferElement getChild(String path)
{
return getChild(new Path(path));
}
- public final InputStream openInputStream() throws IOException
+ public final InputStream openInputStream()
{
checkNotDirectory();
return doOpenInputStream();
@@ -156,11 +156,11 @@ public abstract class CDOTransferElement
return getPath().toString();
}
- protected abstract CDOTransferElement[] doGetChildren() throws IOException;
+ protected abstract CDOTransferElement[] doGetChildren();
- protected abstract InputStream doOpenInputStream() throws IOException;
+ protected abstract InputStream doOpenInputStream();
- private void checkNotDirectory() throws IOException
+ private void checkNotDirectory()
{
if (isDirectory())
{
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java
index 8c995778e2..336f169d94 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java
@@ -15,7 +15,6 @@ import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -39,7 +38,6 @@ class CDOTransferMappingImpl implements CDOTransferMapping
private IPath relativePath;
public CDOTransferMappingImpl(CDOTransfer transfer, CDOTransferElement source, CDOTransferMapping parent)
- throws IOException
{
this.transfer = transfer;
this.source = source;
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java
index b7aba10e8d..747b19f08a 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java
@@ -17,7 +17,6 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
-import java.io.IOException;
import java.io.InputStream;
/**
@@ -64,15 +63,17 @@ public abstract class CDOTransferSystem
public abstract CDOTransferElement getElement(IPath path);
- public abstract void createFolder(IPath path) throws IOException;
+ public abstract CDOTransferElement getElement(URI uri);
- public Resource createModel(ResourceSet resourceSet, IPath path) throws IOException
+ public abstract void createFolder(IPath path);
+
+ public Resource createModel(ResourceSet resourceSet, IPath path)
{
URI uri = getURI(path);
return resourceSet.createResource(uri);
}
- public abstract void createBinary(IPath path, InputStream source) throws IOException;
+ public abstract void createBinary(IPath path, InputStream source);
- public abstract void createText(IPath path, InputStream source, String encoding) throws IOException;
+ public abstract void createText(IPath path, InputStream source, String encoding);
}
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/TransferTest.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/TransferTest.java
index d3a41c90d5..e31b3a77e3 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/TransferTest.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/TransferTest.java
@@ -14,8 +14,6 @@ import org.eclipse.emf.cdo.spi.transfer.FileSystemTransferSystem;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
-import java.io.IOException;
-
/**
* @author Eike Stepper
* @since 4.2
@@ -24,7 +22,7 @@ public class TransferTest
{
public static final CDOTransferSystem FILE_SYSTEM = new FileSystemTransferSystem();
- public static void main(String[] args) throws IOException
+ public static void main(String[] args) throws Exception
{
CDOTransfer transfer = createTransfer();
dump(transfer.getRootMapping());
@@ -34,7 +32,7 @@ public class TransferTest
transfer.perform();
}
- public static CDOTransfer createTransfer() throws IOException
+ public static CDOTransfer createTransfer()
{
CDOTransfer transfer = new CDOTransfer(FILE_SYSTEM, FILE_SYSTEM);
transfer.getRootMapping().setRelativePath("C:/develop/transfer");

Back to the top