Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e6c148d5d7e5cf8035a62d2202cb80bfc328a41b (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
/*******************************************************************************
 * Copyright (c) 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.operations;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
import org.eclipse.ui.IWorkbenchPart;

public class WorkspaceFileDiffOperation extends FileDiffOperation {

	public WorkspaceFileDiffOperation(IWorkbenchPart part, ResourceMapping[] mappings, LocalOption[] options, File file, boolean isMultiPatch, boolean includeFullPathInformation, IPath patchRoot) {
		super(part, mappings, options, file, isMultiPatch, includeFullPathInformation, patchRoot);
	}
	
	protected void copyFile() throws CVSException {
		
		IWorkspaceRoot root =ResourcesPlugin.getWorkspace().getRoot();
		String filePath = this.file.getPath();
		IFile finalFile = root.getFileForLocation(new Path(filePath));
		if(finalFile == null) {
			throw new CVSException("File '" + filePath + "' can not be found in workspace."); //$NON-NLS-1$ //$NON-NLS-2$ 
		}
		InputStream fileInputStream = null;
		try {
			fileInputStream = new BufferedInputStream(new FileInputStream(tempFile));
			if(!finalFile.exists()) {
				finalFile.create(fileInputStream, IResource.FORCE , null);
			} else {
				finalFile.setContents(fileInputStream, IResource.FORCE, null);
			}	
		} catch (FileNotFoundException e) {
			throw CVSException.wrapException(e); 
		} catch (CoreException e) {
			throw CVSException.wrapException(e); 
		}
		finally{
			if (fileInputStream != null) {
				try {
					fileInputStream.close();
				} catch (IOException e) {
					// Ignore
				} finally {					
					if (tempFile != null)
						tempFile.delete();
				}
			}
	    }
	}

}

Back to the top