|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
* nexB Inc. - implementation of patch for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=84808 |
| 11 |
*******************************************************************************/ |
| 12 |
package org.eclipse.team.internal.ccvs.ui.operations; |
| 13 |
|
| 14 |
import java.io.IOException; |
| 15 |
import java.io.InputStream; |
| 16 |
import java.lang.reflect.InvocationTargetException; |
| 17 |
|
| 18 |
import org.eclipse.core.resources.IProjectDescription; |
| 19 |
import org.eclipse.core.resources.IWorkspace; |
| 20 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 21 |
import org.eclipse.core.runtime.CoreException; |
| 22 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 23 |
import org.eclipse.team.core.TeamException; |
| 24 |
import org.eclipse.team.internal.ccvs.core.CVSException; |
| 25 |
import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile; |
| 26 |
import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder; |
| 27 |
import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; |
| 28 |
import org.eclipse.ui.IWorkbenchPart; |
| 29 |
|
| 30 |
/** |
| 31 |
* Operation which retrieves a .project file in a remote folder. The operation |
| 32 |
* can be run using the <code>getProjectDescription</code> static method |
| 33 |
* static method or by executing the operation and then checking <code>getProjectDescription()</code> |
| 34 |
*/ |
| 35 |
public class FetchProjectDescriptionOperation extends CVSOperation { |
| 36 |
|
| 37 |
private ICVSRemoteFolder remoteFolder; |
| 38 |
private IProjectDescription projectDescription; |
| 39 |
|
| 40 |
public static IProjectDescription getProjectDescription(IWorkbenchPart part, ICVSRemoteFolder remoteFolder) |
| 41 |
throws InvocationTargetException, InterruptedException { |
| 42 |
FetchProjectDescriptionOperation op = new FetchProjectDescriptionOperation(part, remoteFolder); |
| 43 |
op.run(); |
| 44 |
return op.getProjectDescription(); |
| 45 |
} |
| 46 |
|
| 47 |
public FetchProjectDescriptionOperation(IWorkbenchPart part, ICVSRemoteFolder remoteFolder) { |
| 48 |
super(part); |
| 49 |
this.remoteFolder = remoteFolder; |
| 50 |
} |
| 51 |
|
| 52 |
/* |
| 53 |
* Return a Stream containing the .project file or null if retrieval failed |
| 54 |
*/ |
| 55 |
private IProjectDescription fetchRemoteProjectDescription(ICVSRemoteFolder folder, IProgressMonitor monitor) throws CVSException { |
| 56 |
|
| 57 |
// make a copy of the folder so that we will not effect the original |
| 58 |
// folder when we refetch the members |
| 59 |
// TODO: this is a strange thing to need to do. We should fix this. |
| 60 |
// Note: This behavior was inherited from HasProjectMetaFileOperation |
| 61 |
folder = (ICVSRemoteFolder) folder.forTag(remoteFolder.getTag()); |
| 62 |
|
| 63 |
try { |
| 64 |
folder.members(monitor); |
| 65 |
} catch (TeamException e) { |
| 66 |
throw CVSException.wrapException(e); |
| 67 |
} |
| 68 |
// Check for the existance of the .project file |
| 69 |
// and attempt to create an IProjectDescription of it. |
| 70 |
InputStream in = null; |
| 71 |
try { |
| 72 |
ICVSRemoteFile remote = (ICVSRemoteFile) folder.getFile(".project"); //$NON-NLS-1$ |
| 73 |
in = remote.getContents(monitor); |
| 74 |
if (in == null || monitor.isCanceled()) { |
| 75 |
return null; |
| 76 |
} |
| 77 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 78 |
IProjectDescription projectDesc = workspace.loadProjectDescription(in); |
| 79 |
return projectDesc; |
| 80 |
} catch (TeamException e) { |
| 81 |
// We couldn't retrieve the project meta file so assume it doesn't exist |
| 82 |
} catch (CoreException e) { |
| 83 |
// We couldn't read the project description, so assume the |
| 84 |
// metafile is not a metafile, or is incorrect |
| 85 |
// which i as if it does not exist |
| 86 |
} finally { |
| 87 |
try { |
| 88 |
if (in != null) |
| 89 |
in.close(); |
| 90 |
} catch (IOException e) { |
| 91 |
// ignore |
| 92 |
} |
| 93 |
} |
| 94 |
return null; |
| 95 |
} |
| 96 |
|
| 97 |
/* |
| 98 |
* (non-Javadoc) |
| 99 |
* @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#execute(org.eclipse.core.runtime.IProgressMonitor) |
| 100 |
*/ |
| 101 |
public void execute(IProgressMonitor monitor) throws CVSException, InterruptedException { |
| 102 |
projectDescription= fetchRemoteProjectDescription(remoteFolder, monitor); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Return the project description containing the remote project meta information |
| 107 |
* if the .project file was properly retrieved or null if not. |
| 108 |
* This method should only be invoked after the operation has been executed; |
| 109 |
*/ |
| 110 |
public IProjectDescription getProjectDescription() { |
| 111 |
return projectDescription; |
| 112 |
} |
| 113 |
|
| 114 |
protected String getTaskName() { |
| 115 |
return CVSUIMessages.FetchProjectDescription_taskName; //$NON-NLS-1$ |
| 116 |
} |
| 117 |
|
| 118 |
/* |
| 119 |
* (non-Javadoc) |
| 120 |
* @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#canRunAsJob() |
| 121 |
*/ |
| 122 |
public boolean canRunAsJob() { |
| 123 |
// This operation should never be run in the background. |
| 124 |
return false; |
| 125 |
} |
| 126 |
} |