# HG changeset patch # User Vladimir Kvashin # Date 1419499826 -10800 # Node ID b77be39cfd19b354bdf9e7c3f07dac44a1d79811 # Parent 549146e5cae0fd9b727f5180248ba6d6998561f2 More methods in VCSFileProxySupport (fixing #249070 Support VCS for full remote project ) diff -r 549146e5cae0 -r b77be39cfd19 dlight.remote.impl/src/org/netbeans/modules/remote/impl/fileoperations/spi/RemoteVcsSupportUtil.java --- a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fileoperations/spi/RemoteVcsSupportUtil.java Wed Dec 24 18:11:48 2014 +0300 +++ b/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fileoperations/spi/RemoteVcsSupportUtil.java Thu Dec 25 12:30:26 2014 +0300 @@ -46,6 +46,9 @@ import java.io.InterruptedIOException; import java.net.ConnectException; import java.nio.channels.InterruptedByTimeoutException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import org.netbeans.modules.dlight.libs.common.PathUtilities; import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; @@ -55,7 +58,7 @@ import org.netbeans.modules.remote.impl.fs.RemoteFileSystem; import org.netbeans.modules.remote.impl.fs.RemoteFileSystemTransport; import org.netbeans.modules.remote.impl.fs.RemoteFileSystemUtils; -import org.netbeans.modules.remote.spi.FileSystemProvider; +import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; /** @@ -208,4 +211,60 @@ return 0; // TODO: should it be -1? } } + + public static boolean renameToImpl(RemoteFileSystem fileSystem, String from, String to) throws IOException { + List exceptions = new ArrayList(); + try { + RemoteFileSystemTransport.move(fileSystem.getExecutionEnvironment(), from, to); + return true; + } catch (InterruptedException ex) { + InterruptedIOException iioex = new InterruptedIOException(); + iioex.initCause(ex); + throw iioex; + } catch (CancellationException ex) { + InterruptedIOException iioex = new InterruptedIOException(); + iioex.initCause(ex); + throw iioex; + } catch (ExecutionException ex) { + throw new IOException(ex); + } + } + + public static boolean copyToImpl(RemoteFileSystem fileSystem, String from, String to) throws IOException { + List exceptions = new ArrayList(); + try { + RemoteFileSystemTransport.copy(fileSystem.getExecutionEnvironment(), from, to, exceptions); + return true; + } catch (InterruptedException ex) { + InterruptedIOException iioex = new InterruptedIOException(); + iioex.initCause(ex); + throw iioex; + } catch (CancellationException ex) { + InterruptedIOException iioex = new InterruptedIOException(); + iioex.initCause(ex); + throw iioex; + } catch (ExecutionException ex) { + throw new IOException(ex); + } + } + + public static boolean renameTo(FileSystem fileSystem, String from, String to) throws IOException { + if (fileSystem instanceof RemoteFileSystem) { + return renameToImpl((RemoteFileSystem) fileSystem, from, to); + } else { + return false; // TODO: should we thriow? + } + } + + public static boolean copyTo(FileSystem fileSystem, String from, String to) throws IOException { + if (fileSystem instanceof RemoteFileSystem) { + return copyToImpl((RemoteFileSystem) fileSystem, from, to); + } else { + return false; // TODO: should we thriow? + } + } + + public static FileObject generateTemporaryFile(FileSystem fileSystem, String path, String name) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } } diff -r 549146e5cae0 -r b77be39cfd19 remotefs.versioning.api/src/org/netbeans/modules/remotefs/versioning/api/RemoteVcsSupport.java --- a/remotefs.versioning.api/src/org/netbeans/modules/remotefs/versioning/api/RemoteVcsSupport.java Wed Dec 24 18:11:48 2014 +0300 +++ b/remotefs.versioning.api/src/org/netbeans/modules/remotefs/versioning/api/RemoteVcsSupport.java Thu Dec 25 12:30:26 2014 +0300 @@ -173,6 +173,31 @@ } return 0; } + + public static VCSFileProxy generateTemporaryFile(VCSFileProxy file, String name) throws Exception { + RemoteVcsSupportImplementation impl = getImpl(); + if (impl != null) { + return impl.generateTemporaryFile(file, name); + } + throw new IllegalStateException("No provider found for " + //NOI18N + RemoteVcsSupportImplementation.class.getName()); + } + + public static boolean copyFile(VCSFileProxy from, VCSFileProxy to) throws IOException { + RemoteVcsSupportImplementation impl = getImpl(); + if (impl != null) { + return impl.copyFile(from, to); + } + return false; + } + + public static boolean renameTo(VCSFileProxy from, VCSFileProxy to) throws IOException { + RemoteVcsSupportImplementation impl = getImpl(); + if (impl != null) { + return impl.renameTo(from, to); + } + return false; + } public static String getFileSystemKey(FileSystem proxy) { RemoteVcsSupportImplementation impl = getImpl(); diff -r 549146e5cae0 -r b77be39cfd19 remotefs.versioning.api/src/org/netbeans/modules/remotefs/versioning/spi/RemoteVcsSupportImplementation.java --- a/remotefs.versioning.api/src/org/netbeans/modules/remotefs/versioning/spi/RemoteVcsSupportImplementation.java Wed Dec 24 18:11:48 2014 +0300 +++ b/remotefs.versioning.api/src/org/netbeans/modules/remotefs/versioning/spi/RemoteVcsSupportImplementation.java Thu Dec 25 12:30:26 2014 +0300 @@ -88,4 +88,10 @@ public String toString(VCSFileProxy proxy); public VCSFileProxy fromString(String proxy); + + public boolean renameTo(VCSFileProxy from, VCSFileProxy to) throws IOException ; + + public boolean copyFile(VCSFileProxy from, VCSFileProxy to) throws IOException ; + + public VCSFileProxy generateTemporaryFile(VCSFileProxy file, String name) throws IOException ; } diff -r 549146e5cae0 -r b77be39cfd19 remotefs.versioning/src/org/netbeans/modules/remotefs/versioning/impl/RemoteVcsSupportImpl.java --- a/remotefs.versioning/src/org/netbeans/modules/remotefs/versioning/impl/RemoteVcsSupportImpl.java Wed Dec 24 18:11:48 2014 +0300 +++ b/remotefs.versioning/src/org/netbeans/modules/remotefs/versioning/impl/RemoteVcsSupportImpl.java Thu Dec 25 12:30:26 2014 +0300 @@ -42,7 +42,9 @@ package org.netbeans.modules.remotefs.versioning.impl; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -61,9 +63,11 @@ import org.netbeans.modules.remote.spi.FileSystemProvider; import org.netbeans.modules.remotefs.versioning.spi.RemoteVcsSupportImplementation; import org.netbeans.modules.versioning.core.api.VCSFileProxy; +import org.netbeans.modules.versioning.core.filesystems.VCSFileProxyOperations; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; import org.openide.util.Utilities; import org.openide.util.lookup.ServiceProvider; @@ -287,6 +291,45 @@ } @Override + public boolean renameTo(VCSFileProxy from, VCSFileProxy to) throws IOException { + File fromFile = from.toFile(); + if (fromFile != null) { + File toFile = to.toFile(); + assert toFile != null; + Files.move(fromFile.toPath(), toFile.toPath()); + return true; + } + FileSystem fs = getFileSystem(from); + assert fs.equals(getFileSystem(to)); + return RemoteVcsSupportUtil.renameTo(fs, from.getPath(), to.getPath()); + } + + @Override + public boolean copyFile(VCSFileProxy from, VCSFileProxy to) throws IOException { + File fromFile = from.toFile(); + if (fromFile != null) { + File toFile = to.toFile(); + assert toFile != null; + Files.copy(fromFile.toPath(), toFile.toPath()); + return true; + } + FileSystem fs = getFileSystem(from); + assert fs.equals(getFileSystem(to)); + return RemoteVcsSupportUtil.copyTo(fs, from.getPath(), to.getPath()); + } + + @Override + public VCSFileProxy generateTemporaryFile(VCSFileProxy proxy, String name) throws IOException { + File file = proxy.toFile(); + if (file != null) { + File tempFile = File.createTempFile(name, "", file); //NOI18N + return VCSFileProxy.createFileProxy(tempFile); + } + FileObject fo = RemoteVcsSupportUtil.generateTemporaryFile(getFileSystem(proxy), proxy.getPath(), name); + return VCSFileProxy.createFileProxy(fo); + } + + @Override public String getFileSystemKey(FileSystem fs) { return FileSystemProvider.toUrl(fs, ""); //NOI18N } diff -r 549146e5cae0 -r b77be39cfd19 subversion.remote/src/org/netbeans/modules/subversion/remote/util/VCSFileProxySupport.java --- a/subversion.remote/src/org/netbeans/modules/subversion/remote/util/VCSFileProxySupport.java Wed Dec 24 18:11:48 2014 +0300 +++ b/subversion.remote/src/org/netbeans/modules/subversion/remote/util/VCSFileProxySupport.java Thu Dec 25 12:30:26 2014 +0300 @@ -276,7 +276,12 @@ } public static VCSFileProxy generateTemporaryFile(VCSFileProxy file, String name) { - throw new UnsupportedOperationException(); + try { + return RemoteVcsSupport.generateTemporaryFile(file, name); + } catch (Exception ex) { + ex.printStackTrace(); + return null; // TODO: should it throw exception instead? + } } public static VCSFileProxy createTempFile(VCSFileProxy file, String prefix, String suffix, boolean deleteOnExit) throws IOException { @@ -308,12 +313,17 @@ } } - public static boolean renameTo(VCSFileProxy from, VCSFileProxy to){ - throw new UnsupportedOperationException(); + public static boolean renameTo(VCSFileProxy from, VCSFileProxy to) { + try { + return RemoteVcsSupport.renameTo(from, to); + } catch (IOException ex) { + ex.printStackTrace(); + return false; + } } public static boolean copyFile(VCSFileProxy from, VCSFileProxy to) throws IOException { - throw new UnsupportedOperationException(); + return RemoteVcsSupport.copyFile(from, to); } /**