diff options
author | John Eblen | 2012-07-30 21:04:04 +0000 |
---|---|---|
committer | John Eblen | 2012-07-30 21:04:04 +0000 |
commit | 90b584e969c45b13fc0c0b91d719e5b2c80150ec (patch) | |
tree | eded428c1fa6edb38e76e0dbf40b7670857042fc /rdt/org.eclipse.ptp.rdt.sync.git.core | |
parent | 2015e43f78ce872e7203e62bfdcf78063716c1e1 (diff) | |
download | org.eclipse.ptp-90b584e969c45b13fc0c0b91d719e5b2c80150ec.tar.gz org.eclipse.ptp-90b584e969c45b13fc0c0b91d719e5b2c80150ec.tar.xz org.eclipse.ptp-90b584e969c45b13fc0c0b91d719e5b2c80150ec.zip |
Fix bug 386267 - Unable to import synchronized projects to a different workspace
Part 2 of 2
Gracefully handle missing connections
1) Add MissingConnectionException
2) Add dialog to handle missing connections
3) Change handling of missing connections at various points
Diffstat (limited to 'rdt/org.eclipse.ptp.rdt.sync.git.core')
4 files changed, 85 insertions, 42 deletions
diff --git a/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/GitRemoteSyncConnection.java b/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/GitRemoteSyncConnection.java index a44e04b0c..4b63b9e6f 100644 --- a/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/GitRemoteSyncConnection.java +++ b/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/GitRemoteSyncConnection.java @@ -62,6 +62,8 @@ import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.QuotedString; +import org.eclipse.ptp.rdt.sync.core.BuildScenario; +import org.eclipse.ptp.rdt.sync.core.MissingConnectionException; import org.eclipse.ptp.rdt.sync.core.RDTSyncCorePlugin; import org.eclipse.ptp.rdt.sync.core.RemoteExecutionException; import org.eclipse.ptp.rdt.sync.core.RemoteSyncException; @@ -88,10 +90,9 @@ public class GitRemoteSyncConnection { public static final String gitDir = ".ptp-sync"; //$NON-NLS-1$ private static final String gitCommand = "git --git-dir=" + gitDir + " --work-tree=."; //$NON-NLS-1$ //$NON-NLS-2$ private static final String remotePushBranch = "ptp-push"; //$NON-NLS-1$ - private final IRemoteConnection connection; - private SyncFileFilter fileFilter; private final String localDirectory; - private final String remoteDirectory; + private final BuildScenario buildScenario; + private SyncFileFilter fileFilter; private Git git; private TransportGitSsh transport; private final IProject project; @@ -112,16 +113,18 @@ public class GitRemoteSyncConnection { * on problems building the remote repository. Specific * exception nested. Upon such an exception, the instance is * invalid and should not be used. + * @throws MissingConnectionException + * when connection missing. In this case, the instance is + * also invalid. */ - public GitRemoteSyncConnection(IProject proj, IRemoteConnection conn, String localDir, String remoteDir, SyncFileFilter filter, - IProgressMonitor monitor) throws RemoteSyncException { + public GitRemoteSyncConnection(IProject proj, String localDir, BuildScenario bs, SyncFileFilter filter, + IProgressMonitor monitor) throws RemoteSyncException, MissingConnectionException { SubMonitor subMon = SubMonitor.convert(monitor, 10); try { project = proj; - connection = conn; - fileFilter = filter; localDirectory = localDir; - remoteDirectory = remoteDir; + buildScenario = bs; + fileFilter = filter; // Build repo, creating it if it is not already present. try { @@ -187,8 +190,11 @@ public class GitRemoteSyncConnection { * which can leave the repo in a partial state. For example, if * the repo is created but the initial commit fails. TODO: * Consider evaluating the output of "git init". + * @throws MissingConnectionException + * on missing connection. */ - private Git buildRepo(IProgressMonitor monitor) throws IOException, RemoteExecutionException, RemoteSyncException { + private Git buildRepo(IProgressMonitor monitor) throws IOException, RemoteExecutionException, RemoteSyncException, + MissingConnectionException { final SubMonitor subMon = SubMonitor.convert(monitor, 100); subMon.subTask(Messages.GitRemoteSyncConnection_building_repo); try { @@ -227,7 +233,8 @@ public class GitRemoteSyncConnection { // Create remote directory if necessary. try { - CommandRunner.createRemoteDirectory(connection, remoteDirectory, subMon.newChild(5)); + CommandRunner.createRemoteDirectory(buildScenario.getRemoteConnection(), buildScenario.getLocation(project), + subMon.newChild(5)); } catch (final CoreException e) { throw new RemoteSyncException(e); } @@ -261,16 +268,18 @@ public class GitRemoteSyncConnection { * @throws IOException * @throws RemoteExecutionException * @throws RemoteSyncException + * @throws MissingConnectionException * @return whether this repo already existed */ - private boolean doRemoteInit(IProgressMonitor monitor) throws IOException, RemoteExecutionException, RemoteSyncException { + private boolean doRemoteInit(IProgressMonitor monitor) throws IOException, RemoteExecutionException, RemoteSyncException, + MissingConnectionException { SubMonitor subMon = SubMonitor.convert(monitor, 10); try { String command = "git --git-dir=" + gitDir + " init"; //$NON-NLS-1$ //$NON-NLS-2$ CommandResults commandResults = null; try { - commandResults = CommandRunner.executeRemoteCommand(connection, command, remoteDirectory, subMon.newChild(10)); + commandResults = this.executeRemoteCommand(command, subMon.newChild(10)); } catch (final InterruptedException e) { throw new RemoteExecutionException(e); } catch (RemoteConnectionException e) { @@ -308,7 +317,8 @@ public class GitRemoteSyncConnection { * * @return whether there are changes to be committed. */ - private boolean prepareRemoteForCommit(IProgressMonitor monitor, boolean includeUntrackedFiles) throws RemoteSyncException { + private boolean prepareRemoteForCommit(IProgressMonitor monitor, boolean includeUntrackedFiles) throws RemoteSyncException, + MissingConnectionException { SubMonitor subMon = SubMonitor.convert(monitor, 100); try { Set<String> filesToAdd = new HashSet<String>(); @@ -345,7 +355,7 @@ public class GitRemoteSyncConnection { /* * Do a "git commit" on the remote host */ - private void commitRemoteFiles(IProgressMonitor monitor) throws RemoteSyncException { + private void commitRemoteFiles(IProgressMonitor monitor) throws RemoteSyncException, MissingConnectionException { SubMonitor subMon = SubMonitor.convert(monitor, 10); subMon.subTask(Messages.GitRemoteSyncConnection_committing_remote); try { @@ -353,7 +363,7 @@ public class GitRemoteSyncConnection { CommandResults commandResults = null; try { - commandResults = CommandRunner.executeRemoteCommand(connection, command, remoteDirectory, subMon.newChild(10)); + commandResults = this.executeRemoteCommand(command, subMon.newChild(10)); } catch (final InterruptedException e) { throw new RemoteSyncException(e); } catch (RemoteConnectionException e) { @@ -361,6 +371,7 @@ public class GitRemoteSyncConnection { } catch (IOException e) { throw new RemoteSyncException(e); } + if (commandResults.getExitCode() != 0) { throw new RemoteSyncException(Messages.GRSC_GitCommitFailure + commandResults.getStderr()); } @@ -375,7 +386,7 @@ public class GitRemoteSyncConnection { * Do a "git rm <Files>" on the remote host */ private void deleteRemoteFiles(Set<String> filesToDelete, IProgressMonitor monitor) throws IOException, - RemoteExecutionException, RemoteSyncException { + RemoteExecutionException, RemoteSyncException, MissingConnectionException { SubMonitor subMon = SubMonitor.convert(monitor, 10); try { while (!filesToDelete.isEmpty()) { @@ -391,7 +402,7 @@ public class GitRemoteSyncConnection { CommandResults commandResults = null; try { - commandResults = CommandRunner.executeRemoteCommand(connection, commandList, remoteDirectory, subMon.newChild(10)); + commandResults = this.executeRemoteCommand(commandList, subMon.newChild(10)); } catch (final InterruptedException e) { throw new RemoteExecutionException(e); } catch (RemoteConnectionException e) { @@ -416,7 +427,7 @@ public class GitRemoteSyncConnection { * Do a "git add <Files>" on the remote host */ private void addRemoteFiles(Set<String> filesToAdd, IProgressMonitor monitor) throws IOException, RemoteExecutionException, - RemoteSyncException { + RemoteSyncException, MissingConnectionException { SubMonitor subMon = SubMonitor.convert(monitor, filesToAdd.size()); subMon.subTask(Messages.GitRemoteSyncConnection_adding_files); try { @@ -433,8 +444,7 @@ public class GitRemoteSyncConnection { CommandResults commandResults = null; try { - commandResults = CommandRunner.executeRemoteCommand(connection, commandList, remoteDirectory, - subMon.newChild(10)); + commandResults = this.executeRemoteCommand(commandList, subMon.newChild(10)); } catch (final InterruptedException e) { throw new RemoteExecutionException(e); } catch (RemoteConnectionException e) { @@ -457,7 +467,8 @@ public class GitRemoteSyncConnection { * deleted from the git index. */ private void getRemoteFileStatus(Set<String> filesToAdd, Set<String> filesToDelete, IProgressMonitor monitor, - boolean includeUntrackedFiles) throws IOException, RemoteExecutionException, RemoteSyncException { + boolean includeUntrackedFiles) throws IOException, RemoteExecutionException, RemoteSyncException, + MissingConnectionException { SubMonitor subMon = SubMonitor.convert(monitor, 10); subMon.subTask(Messages.GitRemoteSyncConnection_getting_remote_file_status); try { @@ -470,7 +481,7 @@ public class GitRemoteSyncConnection { CommandResults commandResults = null; try { - commandResults = CommandRunner.executeRemoteCommand(connection, command, remoteDirectory, subMon.newChild(10)); + commandResults = this.executeRemoteCommand(command, subMon.newChild(10)); } catch (final InterruptedException e) { throw new RemoteExecutionException(e); } catch (RemoteConnectionException e) { @@ -555,6 +566,7 @@ public class GitRemoteSyncConnection { commandList.add(command); try { + IRemoteConnection connection = buildScenario.getRemoteConnection(); if (!connection.isOpen()) { connection.open(null); } @@ -563,6 +575,8 @@ public class GitRemoteSyncConnection { throw new TransportException(uri, e.getMessage(), e); } catch (RemoteConnectionException e) { throw new TransportException(uri, e.getMessage(), e); + } catch (MissingConnectionException e) { + throw new TransportException(uri, Messages.GitRemoteSyncConnection_3 + e.getConnectionName(), e); } } @@ -618,7 +632,8 @@ public class GitRemoteSyncConnection { .setHost("none") //$NON-NLS-1$ // .setPass("") .setScheme("ssh") //$NON-NLS-1$ - .setPath(remoteDirectory + "/" + gitDir); //$NON-NLS-1$ //Should use remote path seperator but first 315720 has to be fixed + .setPath(buildScenario.getLocation(project) + "/" + gitDir); //$NON-NLS-1$ // Should use remote path seperator but + // first 315720 has to be fixed } public void close() { @@ -773,9 +788,10 @@ public class GitRemoteSyncConnection { /** * @return the connection (IRemoteConnection) + * @throws MissingConnectionException */ - public IRemoteConnection getConnection() { - return connection; + public IRemoteConnection getConnection() throws MissingConnectionException { + return buildScenario.getRemoteConnection(); } /** @@ -789,7 +805,7 @@ public class GitRemoteSyncConnection { * @return the remoteDirectory */ public String getRemoteDirectory() { - return remoteDirectory; + return buildScenario.getLocation(project); } /** @@ -823,7 +839,7 @@ public class GitRemoteSyncConnection { CommandResults mergeResults; final String command = gitCommand + " merge " + remotePushBranch; //$NON-NLS-1$ - mergeResults = CommandRunner.executeRemoteCommand(connection, command, remoteDirectory, subMon.newChild(5)); + mergeResults = this.executeRemoteCommand(command, subMon.newChild(5)); if (mergeResults.getExitCode() != 0) { throw new RemoteSyncException(new RemoteExecutionException(Messages.GRSC_GitMergeFailure @@ -838,6 +854,8 @@ public class GitRemoteSyncConnection { throw new RemoteSyncException(e); } catch (GitAPIException e) { throw new RemoteSyncException(e); + } catch (MissingConnectionException e) { + // nothing to do } } finally { if (monitor != null) { @@ -902,6 +920,8 @@ public class GitRemoteSyncConnection { throw new RemoteSyncException(e); } catch (GitAPIException e) { throw new RemoteSyncException(e); + } catch (MissingConnectionException e) { + // nothing to do } finally { if (monitor != null) { monitor.done(); @@ -987,8 +1007,7 @@ public class GitRemoteSyncConnection { // final String command = gitCommand + " merge --ff-only " + remotePushBranch; //$NON-NLS-1$ final String command = gitCommand + " merge " + remotePushBranch; //$NON-NLS-1$ - mergeResults = CommandRunner.executeRemoteCommand(connection, command, remoteDirectory, subMon.newChild(5)); - + mergeResults = this.executeRemoteCommand(command, subMon.newChild(5)); if (mergeResults.getExitCode() != 0) { throw new RemoteSyncException(new RemoteExecutionException(Messages.GRSC_GitMergeFailure + mergeResults.getStderr())); @@ -1002,6 +1021,8 @@ public class GitRemoteSyncConnection { throw new RemoteSyncException(e); } catch (GitAPIException e) { throw new RemoteSyncException(e); + } catch (MissingConnectionException e) { + // nothing to do } finally { if (monitor != null) { monitor.done(); @@ -1112,4 +1133,18 @@ public class GitRemoteSyncConnection { refreshWorkspaceThread.start(); return refreshWorkspaceThread; } + + private CommandResults executeRemoteCommand(String command, SubMonitor monitor) throws RemoteSyncException, IOException, + InterruptedException, RemoteConnectionException, MissingConnectionException { + IRemoteConnection conn = buildScenario.getRemoteConnection(); + String remoteDirectory = buildScenario.getLocation(project); + return CommandRunner.executeRemoteCommand(conn, command, remoteDirectory, monitor); + } + + private CommandResults executeRemoteCommand(List<String> command, SubMonitor monitor) throws RemoteSyncException, IOException, + InterruptedException, RemoteConnectionException, MissingConnectionException { + IRemoteConnection conn = buildScenario.getRemoteConnection(); + String remoteDirectory = buildScenario.getLocation(project); + return CommandRunner.executeRemoteCommand(conn, command, remoteDirectory, monitor); + } }
\ No newline at end of file diff --git a/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/GitServiceProvider.java b/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/GitServiceProvider.java index 9478ac82e..422e9e309 100644 --- a/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/GitServiceProvider.java +++ b/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/GitServiceProvider.java @@ -33,6 +33,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.ptp.rdt.sync.core.BuildScenario; +import org.eclipse.ptp.rdt.sync.core.MissingConnectionException; import org.eclipse.ptp.rdt.sync.core.RemoteSyncException; import org.eclipse.ptp.rdt.sync.core.RemoteSyncMergeConflictException; import org.eclipse.ptp.rdt.sync.core.SyncFileFilter; @@ -43,7 +44,6 @@ import org.eclipse.ptp.rdt.sync.git.core.messages.Messages; import org.eclipse.ptp.remote.core.IRemoteConnection; import org.eclipse.ptp.remote.core.IRemoteServices; import org.eclipse.ptp.remote.core.PTPRemoteCorePlugin; -import org.eclipse.ptp.remote.core.exception.RemoteConnectionException; import org.eclipse.ptp.services.core.ServiceProvider; public class GitServiceProvider extends ServiceProvider implements ISyncServiceProvider { @@ -362,13 +362,16 @@ public class GitServiceProvider extends ServiceProvider implements ISyncServiceP if (buildScenario == null) { throw new RuntimeException(Messages.GitServiceProvider_3 + project.getName()); } + GitRemoteSyncConnection fSyncConnection = this.getSyncConnection(project, buildScenario, fileFilter, progress); if (fSyncConnection == null) { - throw new RemoteSyncException(Messages.GitServiceProvider_5); - } - // Open remote connection if necessary - if (buildScenario.getRemoteConnection().isOpen() == false) { - buildScenario.getRemoteConnection().open(progress.newChild(10)); + // Should never happen + if (buildScenario.getSyncProvider() == null) { + throw new RemoteSyncException(Messages.GitServiceProvider_5); + // Happens whenever connection does not exist + } else { + return; + } } // This synchronization operation will include all tasks up to current syncTaskId @@ -391,8 +394,6 @@ public class GitServiceProvider extends ServiceProvider implements ISyncServiceP } finishedSyncTaskId = willFinishTaskId; // TODO: review exception handling - } catch (RemoteConnectionException e) { - throw new RemoteSyncException(e); } finally { syncLock.unlock(); } @@ -410,9 +411,9 @@ public class GitServiceProvider extends ServiceProvider implements ISyncServiceP } } - // Return appropriate sync connection or null for scenarios with no sync provider. Creates a new connection if necessary. - // This function must properly maintain the map of connections and also remember to set the file filter (always, not just for - // new connections). + // Return appropriate sync connection or null for scenarios with no sync provider or if the connection is missing. + // Creates a new sync connection if necessary. This function must properly maintain the map of connections and also remember to set + // the file filter (always, not just for new connections). // TODO: Create progress monitor if passed monitor is null. private synchronized GitRemoteSyncConnection getSyncConnection(IProject project, BuildScenario buildScenario, SyncFileFilter fileFilter, SubMonitor progress) throws RemoteSyncException { @@ -421,8 +422,13 @@ public class GitServiceProvider extends ServiceProvider implements ISyncServiceP } ProjectAndScenario pas = new ProjectAndScenario(project, buildScenario); if (!syncConnectionMap.containsKey(pas)) { - syncConnectionMap.put(pas, new GitRemoteSyncConnection(project, buildScenario.getRemoteConnection(), - project.getLocation().toString(), buildScenario.getLocation(project), fileFilter, progress)); + try { + GitRemoteSyncConnection grsc = new GitRemoteSyncConnection(project, project.getLocation().toString(), buildScenario, + fileFilter, progress); + syncConnectionMap.put(pas, grsc); + } catch (MissingConnectionException e) { + return null; + } } GitRemoteSyncConnection fSyncConnection = syncConnectionMap.get(pas); fSyncConnection.setFileFilter(fileFilter); diff --git a/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/messages/Messages.java b/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/messages/Messages.java index 3f45d3ffc..80f09504b 100644 --- a/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/messages/Messages.java +++ b/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/messages/Messages.java @@ -31,6 +31,7 @@ public class Messages extends NLS { public static String GitRemoteSyncConnection_0; public static String GitRemoteSyncConnection_1; public static String GitRemoteSyncConnection_2; + public static String GitRemoteSyncConnection_3; public static String GitRemoteSyncConnection_adding_files; public static String GitRemoteSyncConnection_building_repo; public static String GitRemoteSyncConnection_committing_remote; diff --git a/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/messages/messages.properties b/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/messages/messages.properties index 50379649e..fe7b41488 100644 --- a/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/messages/messages.properties +++ b/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/rdt/sync/git/core/messages/messages.properties @@ -25,6 +25,7 @@ GSP_SyncTaskName=Synchronization GitRemoteSyncConnection_0=Unable to refresh workspace GitRemoteSyncConnection_1=Synchronizing... GitRemoteSyncConnection_2=Merge conflict +GitRemoteSyncConnection_3=Missing connection: GitRemoteSyncConnection_adding_files=Adding files to repository... GitRemoteSyncConnection_building_repo=Building repository... GitRemoteSyncConnection_committing_remote=Committing remote files... |