Skip to main content
summaryrefslogtreecommitdiffstats
blob: 20df10c4d821038837742696b12fe57eb5dacbf6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.operations;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
import org.eclipse.team.internal.ccvs.ui.Policy;

/**
 * Operation which checks for the existance of the .project file (or .vcm_meta file) 
 * in a remote folder. The operation can be run using the <code>hasMetaFile</code>
 * static method of by executing the operation and then checking <code>metaFileExists</code>
 */
public class HasProjectMetaFileOperation extends CVSOperation {

	private ICVSRemoteFolder remoteFolder;
	private boolean metaFileExists;
	
	public static boolean hasMetaFile(Shell shell, ICVSRemoteFolder remoteFolder) throws CVSException, InterruptedException {
		HasProjectMetaFileOperation op = new HasProjectMetaFileOperation(shell, remoteFolder);
		op.run();
		return op.metaFileExists();
	}
	
	public HasProjectMetaFileOperation(Shell shell, ICVSRemoteFolder remoteFolder) {
		super(shell);
		this.remoteFolder = remoteFolder;
	}
	
	/*
	 * Return true if the provided remote folder contains a valid meta-file 
	 * (i.e. .project or the older .vcm_meta file).
	 */
	private boolean hasMetaFile(ICVSRemoteFolder folder, IProgressMonitor monitor) throws CVSException {
		
		// make a copy of the folder so that we will not effect the original folder when we refetch the members
		// TODO: this is a strange thing to need to do. We shold fix this.
		folder = (ICVSRemoteFolder)folder.forTag(remoteFolder.getTag());

		try {
			folder.members(monitor);
		} catch (TeamException e) {
			throw CVSException.wrapException(e);
		}
		// Check for the existance of the .project file
		try {
			folder.getFile(".project"); //$NON-NLS-1$
			return true;
		} catch (TeamException e) {
			// We couldn't retrieve the meta file so assume it doesn't exist
		}
		// If the above failed, look for the old .vcm_meta file
		try {
			folder.getFile(".vcm_meta"); //$NON-NLS-1$
			return true;
		} catch (TeamException e) {
			// We couldn't retrieve the meta file so assume it doesn't exist
		}
		return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
	 */
	public void execute(IProgressMonitor monitor) throws CVSException, InterruptedException {
		metaFileExists = hasMetaFile(remoteFolder, monitor);
	}
	
	/**
	 * Return true if the meta file exists remotely. This method should only be invoked
	 * after the operation has been executed;
	 * @return
	 */
	public boolean metaFileExists() {
		return metaFileExists;
	}

	protected String getTaskName() {
		return Policy.bind("HasProjectMetaFile.taskName"); //$NON-NLS-1$
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#canRunAsJob()
	 */
	public boolean canRunAsJob() {
		// This operation should never be run in the background.
		return false;
	}

}

Back to the top