|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 9-17
Link Here
|
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.releng.tools; |
11 |
package org.eclipse.releng.tools; |
|
|
12 |
|
| 12 |
import java.lang.reflect.InvocationTargetException; |
13 |
import java.lang.reflect.InvocationTargetException; |
| 13 |
import java.util.*; |
14 |
import java.util.*; |
| 14 |
|
|
|
| 15 |
import org.eclipse.core.resources.*; |
15 |
import org.eclipse.core.resources.*; |
| 16 |
import org.eclipse.core.runtime.CoreException; |
16 |
import org.eclipse.core.runtime.CoreException; |
| 17 |
import org.eclipse.core.runtime.IProgressMonitor; |
17 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
Lines 21-40
Link Here
|
| 21 |
import org.eclipse.team.internal.ccvs.ui.operations.CommitOperation; |
21 |
import org.eclipse.team.internal.ccvs.ui.operations.CommitOperation; |
| 22 |
import org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation; |
22 |
import org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation; |
| 23 |
|
23 |
|
|
|
24 |
/* |
| 25 |
* This class represents a workspace project which contains map files. |
| 26 |
*/ |
| 24 |
public class MapProject implements IResourceChangeListener { |
27 |
public class MapProject implements IResourceChangeListener { |
| 25 |
|
28 |
|
| 26 |
private static MapProject mapProject = null; |
29 |
private static MapProject mapProject = null; |
| 27 |
private IProject project; |
30 |
private IProject project; |
| 28 |
private MapFile[] mapFiles; |
31 |
private MapFile[] mapFiles; |
| 29 |
|
32 |
private MapEntryRegistry registry; |
|
|
33 |
|
| 30 |
/** |
34 |
/** |
| 31 |
* Return the default map project (org.eclipse.releng) or |
35 |
* Return the default map project (<em>org.eclipse.releng</em>) or |
| 32 |
* <code>null</code> if the project does not exist or there |
36 |
* <code>null</code> if the project does not exist or there |
| 33 |
* is an error processing it. If there is an error, it |
37 |
* is an error processing it. If there is an error, it |
| 34 |
* will be logged. |
38 |
* will be logged. |
| 35 |
* @return the default map project |
39 |
* |
|
|
40 |
* @return the default map project or <code>null</code> |
| 36 |
*/ |
41 |
*/ |
| 37 |
public static MapProject getDefaultMapProject(){ |
42 |
public static MapProject getDefaultMapProject() { |
| 38 |
if (mapProject == null) { |
43 |
if (mapProject == null) { |
| 39 |
IProject project = getProjectFromWorkspace(); |
44 |
IProject project = getProjectFromWorkspace(); |
| 40 |
try { |
45 |
try { |
|
Lines 43-52
Link Here
|
| 43 |
RelEngPlugin.log(e); |
48 |
RelEngPlugin.log(e); |
| 44 |
} |
49 |
} |
| 45 |
} |
50 |
} |
| 46 |
|
|
|
| 47 |
return mapProject; |
51 |
return mapProject; |
| 48 |
} |
52 |
} |
| 49 |
|
53 |
|
|
|
54 |
/* |
| 55 |
* Return the workspace project for the org.eclipse.releng project. |
| 56 |
*/ |
| 50 |
private static IProject getProjectFromWorkspace() { |
57 |
private static IProject getProjectFromWorkspace() { |
| 51 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
58 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 52 |
IWorkspaceRoot root = workspace.getRoot(); |
59 |
IWorkspaceRoot root = workspace.getRoot(); |
|
Lines 54-201
Link Here
|
| 54 |
return project; |
61 |
return project; |
| 55 |
} |
62 |
} |
| 56 |
|
63 |
|
|
|
64 |
/* |
| 65 |
* Create a new map project based on the given workspace project. |
| 66 |
*/ |
| 57 |
public MapProject(IProject p) throws CoreException { |
67 |
public MapProject(IProject p) throws CoreException { |
| 58 |
this.project = p; |
68 |
this.project = p; |
| 59 |
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); |
69 |
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); |
| 60 |
loadMapFiles(); |
70 |
loadMapFiles(); |
|
|
71 |
this.registry = new MapEntryRegistry(); |
| 72 |
this.registry.add(this); |
| 73 |
} |
| 74 |
|
| 75 |
public MapEntryRegistry getRegistry() { |
| 76 |
return registry; |
| 61 |
} |
77 |
} |
| 62 |
|
78 |
|
|
|
79 |
/* |
| 80 |
* Return the workspace project represented by this map project. |
| 81 |
*/ |
| 63 |
public IProject getProject() { |
82 |
public IProject getProject() { |
| 64 |
return project; |
83 |
return project; |
| 65 |
} |
84 |
} |
| 66 |
|
85 |
|
| 67 |
public void setProject(IProject p){ |
86 |
/* |
| 68 |
this.project = p; |
87 |
* Return the map file which contains the entry for this project. |
| 69 |
} |
88 |
*/ |
| 70 |
|
89 |
private MapFile getMapFile(IProject p) { |
| 71 |
private MapFile getMapFile(IProject p){ |
90 |
MapEntry entry = getMapEntry(p); |
| 72 |
for (int i = 0; i< mapFiles.length; i++){ |
91 |
return entry == null ? null : entry.getFile(); |
| 73 |
if (mapFiles[i].contains(p)) { |
|
|
| 74 |
return mapFiles[i]; |
| 75 |
} |
| 76 |
} |
| 77 |
return null; |
| 78 |
} |
92 |
} |
| 79 |
|
93 |
|
| 80 |
/** |
94 |
/* |
| 81 |
* Return the MapEntry for the given project |
95 |
* Return the MapEntry for the given project. Do a lookup in the registry. |
| 82 |
* @param string |
|
|
| 83 |
* @param string1 |
| 84 |
*/ |
96 |
*/ |
| 85 |
public MapEntry getMapEntry(IProject p) { |
97 |
public MapEntry getMapEntry(IProject p) { |
| 86 |
MapFile file = getMapFile(p); |
98 |
return registry.get(p); |
| 87 |
if (file != null) { |
|
|
| 88 |
return file.getMapEntry(p); |
| 89 |
} |
| 90 |
return null; |
| 91 |
} |
99 |
} |
| 92 |
|
100 |
|
|
|
101 |
/* |
| 102 |
* Return a boolean value indicating whether or not the map files |
| 103 |
* have been loaded for this project. In our case this is always true |
| 104 |
* as long as the corresponding workspace project is accessible. |
| 105 |
* |
| 106 |
*/ |
| 93 |
public boolean mapsAreLoaded() { |
107 |
public boolean mapsAreLoaded() { |
| 94 |
return project.exists(); |
108 |
return project.isAccessible(); |
| 95 |
} |
109 |
} |
| 96 |
|
110 |
|
| 97 |
public MapFile[] getValidMapFiles(){ |
111 |
/* |
|
|
112 |
* Return an array of the valid map files in this project. |
| 113 |
*/ |
| 114 |
public MapFile[] getValidMapFiles() { |
| 98 |
List list = new ArrayList(); |
115 |
List list = new ArrayList(); |
| 99 |
for (int i = 0; i <mapFiles.length; i++){ |
116 |
for (int i = 0; i < mapFiles.length; i++) { |
| 100 |
IProject[] projects = mapFiles[i].getAccessibleProjects(); |
117 |
IProject[] projects = mapFiles[i].getAccessibleProjects(); |
| 101 |
if( projects!= null && projects.length > 0){ |
118 |
if (projects != null && projects.length > 0) { |
| 102 |
list.add(mapFiles[i]); |
119 |
list.add(mapFiles[i]); |
| 103 |
} |
120 |
} |
| 104 |
} |
121 |
} |
| 105 |
return (MapFile[])list.toArray(new MapFile[list.size()]); |
122 |
return (MapFile[]) list.toArray(new MapFile[list.size()]); |
|
|
123 |
} |
| 124 |
|
| 125 |
public MapFile[] getMapFiles() { |
| 126 |
return mapFiles; |
| 106 |
} |
127 |
} |
| 107 |
|
128 |
|
| 108 |
/** |
129 |
/** |
|
|
130 |
* Update the map file entry for the given workspace project, with the specified tag. |
| 131 |
* |
| 109 |
* @param aProject The map entry of the specified project will be changed to the specified tag |
132 |
* @param aProject The map entry of the specified project will be changed to the specified tag |
| 110 |
* @param tag The specified tag |
133 |
* @param tag The specified tag |
| 111 |
* @return returns if no map file having such a map entry is found |
|
|
| 112 |
*/ |
134 |
*/ |
| 113 |
public void updateFile(IProject aProject, String tag) throws CoreException { |
135 |
public void updateFile(IProject aProject, String tag) throws CoreException { |
| 114 |
MapFile aFile = getMapFile(aProject); |
136 |
MapFile aFile = getMapFile(aProject); |
| 115 |
if (aFile == null)return; |
137 |
if (aFile == null) |
|
|
138 |
return; |
| 116 |
MapContentDocument changed = new MapContentDocument(aFile); |
139 |
MapContentDocument changed = new MapContentDocument(aFile); |
| 117 |
changed.updateTag(aProject, tag); |
140 |
changed.updateTag(aProject, tag); |
| 118 |
if (changed.isChanged()) { |
141 |
if (changed.isChanged()) { |
| 119 |
aFile.getFile().setContents(changed.getContents(), IFile.KEEP_HISTORY, null); |
142 |
aFile.getFile().setContents(changed.getContents(), IResource.KEEP_HISTORY, null); |
| 120 |
} |
143 |
} |
| 121 |
} |
144 |
} |
| 122 |
|
145 |
|
| 123 |
public void commitMapProject(String comment, IProgressMonitor monitor) throws CoreException{ |
146 |
/* |
|
|
147 |
* Commit our changes to CVS. |
| 148 |
*/ |
| 149 |
public void commitMapProject(String comment, IProgressMonitor monitor) throws CoreException { |
| 124 |
try { |
150 |
try { |
| 125 |
new CommitOperation(null, RepositoryProviderOperation.asResourceMappers(new IResource[] { project }), new Command.LocalOption[0], comment).run(monitor); |
151 |
new CommitOperation(null, RepositoryProviderOperation.asResourceMappers(new IResource[] {project}), new Command.LocalOption[0], comment).run(monitor); |
| 126 |
} catch (InvocationTargetException e) { |
152 |
} catch (InvocationTargetException e) { |
| 127 |
throw TeamException.asTeamException(e); |
153 |
throw TeamException.asTeamException(e); |
| 128 |
} catch (InterruptedException e) { |
154 |
} catch (InterruptedException e) { |
| 129 |
// Ignore; |
155 |
// Ignore; |
| 130 |
} |
156 |
} |
| 131 |
} |
157 |
} |
| 132 |
|
158 |
|
| 133 |
public MapFile[] getMapFilesFor(IProject[] projects){ |
159 |
/* |
| 134 |
Set alist = new HashSet(); |
160 |
* Return an array with the map files for the given projects. |
| 135 |
for(int i = 0; i<projects.length; i++){ |
161 |
*/ |
|
|
162 |
public MapFile[] getMapFilesFor(IProject[] projects) { |
| 163 |
Set alist = new HashSet(); |
| 164 |
for (int i = 0; i < projects.length; i++) { |
| 136 |
MapFile aMapFile = getMapFile(projects[i]); |
165 |
MapFile aMapFile = getMapFile(projects[i]); |
| 137 |
alist.add(aMapFile); |
166 |
alist.add(aMapFile); |
| 138 |
} |
167 |
} |
| 139 |
return (MapFile[])alist.toArray(new MapFile[alist.size()]); |
168 |
return (MapFile[]) alist.toArray(new MapFile[alist.size()]); |
| 140 |
} |
169 |
} |
| 141 |
|
170 |
|
| 142 |
/** |
171 |
/** |
| 143 |
* Get the tags for the given projects. If no tag is found |
172 |
* Get the tags for the given projects. If no tag is found |
| 144 |
* for whatever reason, HEAD is used. |
173 |
* for whatever reason, HEAD is used. |
|
|
174 |
* |
| 145 |
* @param projects |
175 |
* @param projects |
| 146 |
* @return |
|
|
| 147 |
*/ |
176 |
*/ |
| 148 |
public CVSTag[] getTagsFor(IProject[] projects){ |
177 |
public CVSTag[] getTagsFor(IProject[] projects) { |
| 149 |
if(projects == null || projects.length == 0)return null; |
178 |
if (projects == null || projects.length == 0) |
|
|
179 |
return null; |
| 150 |
CVSTag[] tags = new CVSTag[projects.length]; |
180 |
CVSTag[] tags = new CVSTag[projects.length]; |
| 151 |
for (int i = 0; i < tags.length; i++){ |
181 |
for (int i = 0; i < tags.length; i++) { |
| 152 |
MapEntry entry = getMapEntry(projects[i]); |
182 |
MapEntry entry = getMapEntry(projects[i]); |
| 153 |
if (entry == null) tags[i] = CVSTag.DEFAULT; |
183 |
if (entry == null) |
| 154 |
else tags[i] = entry.getTag(); |
184 |
tags[i] = CVSTag.DEFAULT; |
|
|
185 |
else |
| 186 |
tags[i] = entry.getTag(); |
| 155 |
} |
187 |
} |
| 156 |
return tags; |
188 |
return tags; |
| 157 |
} |
189 |
} |
|
|
190 |
|
| 158 |
/** |
191 |
/** |
| 159 |
* Deregister the IResourceChangeListner. It is reserved for use in the future. It is never called |
192 |
* Unregister the IResourceChangeListner. It is reserved for use in the future. It is never called |
| 160 |
* for now |
193 |
* for now. |
| 161 |
*/ |
194 |
*/ |
| 162 |
public void dispose(){ |
195 |
public void dispose() { |
| 163 |
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); |
196 |
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); |
| 164 |
} |
197 |
} |
| 165 |
|
198 |
|
| 166 |
/** |
199 |
/** |
| 167 |
* @see IResourceChangeListener#resourceChanged(IResourceChangeEvent) |
200 |
* @see IResourceChangeListener#resourceChanged(IResourceChangeEvent) |
| 168 |
*/ |
201 |
*/ |
| 169 |
public void resourceChanged(IResourceChangeEvent event) { |
202 |
public void resourceChanged(IResourceChangeEvent event) { |
| 170 |
IResourceDelta root = event.getDelta(); |
203 |
IResourceDelta root = event.getDelta(); |
| 171 |
|
204 |
|
| 172 |
//TODO: Need to add code to handle map project deletion, addition and rename |
205 |
//TODO: Need to add code to handle map project deletion, addition and rename |
| 173 |
IResourceDelta folderDelta = root.findMember(getMapFolder().getFullPath()); |
206 |
IResourceDelta folderDelta = root.findMember(getMapFolder().getFullPath()); |
| 174 |
if (folderDelta == null) return; |
207 |
if (folderDelta == null) |
| 175 |
|
208 |
return; |
|
|
209 |
|
| 176 |
//Handle map files deletion, addition and rename |
210 |
//Handle map files deletion, addition and rename |
| 177 |
IResourceDelta[] deltas = folderDelta.getAffectedChildren(); |
211 |
IResourceDelta[] deltas = folderDelta.getAffectedChildren(); |
| 178 |
if(deltas == null || deltas.length == 0) return; |
212 |
if (deltas == null || deltas.length == 0) |
|
|
213 |
return; |
| 179 |
for (int i = 0; i < deltas.length; i++) { |
214 |
for (int i = 0; i < deltas.length; i++) { |
| 180 |
IResourceDelta delta = deltas[i]; |
215 |
IResourceDelta delta = deltas[i]; |
| 181 |
if(delta.getResource().getType() == IResource.FILE){ |
216 |
if (delta.getResource().getType() == IResource.FILE) { |
| 182 |
try{ |
217 |
try { |
| 183 |
IFile aFile = (IFile)(delta.getResource()); |
218 |
IFile aFile = (IFile) (delta.getResource()); |
| 184 |
MapFile mFile = null; |
219 |
MapFile mFile = null; |
| 185 |
if(isMapFile(aFile)){ |
220 |
if (isMapFile(aFile)) { |
| 186 |
// Handle content change |
221 |
// Handle content change |
| 187 |
if(delta.getKind() == IResourceDelta.CHANGED){ |
222 |
if (delta.getKind() == IResourceDelta.CHANGED) { |
| 188 |
mFile = getMapFileFor(aFile); |
223 |
mFile = getMapFileFor(aFile); |
| 189 |
mFile.loadEntries(); |
224 |
mFile.loadEntries(); |
| 190 |
} |
225 |
} |
| 191 |
//Handle deletion. We cannot simply remove the map file directly bacause we have to call |
226 |
//Handle deletion. We cannot simply remove the map file directly bacause we have to call |
| 192 |
//getMapFileFor(IFile) in order to do so. But the IFile is already deleted. So we have to |
227 |
//getMapFileFor(IFile) in order to do so. But the IFile is already deleted. So we have to |
| 193 |
//reconstuct the map files. |
228 |
//reconstuct the map files. |
| 194 |
if(delta.getKind() == IResourceDelta.REMOVED ){ |
229 |
if (delta.getKind() == IResourceDelta.REMOVED) { |
| 195 |
loadMapFiles(); |
230 |
loadMapFiles(); |
| 196 |
} |
231 |
} |
| 197 |
// Handle addition |
232 |
// Handle addition |
| 198 |
if(delta.getKind() == IResourceDelta.ADDED ){ |
233 |
if (delta.getKind() == IResourceDelta.ADDED) { |
| 199 |
mFile = getMapFileFor(aFile); |
234 |
mFile = getMapFileFor(aFile); |
| 200 |
addMapFile(mFile); |
235 |
addMapFile(mFile); |
| 201 |
} |
236 |
} |
|
Lines 207-218
Link Here
|
| 207 |
} |
242 |
} |
| 208 |
} |
243 |
} |
| 209 |
|
244 |
|
| 210 |
private IFolder getMapFolder(){ |
245 |
private IFolder getMapFolder() { |
| 211 |
return getProject().getFolder(RelEngPlugin.MAP_FOLDER); |
246 |
return getProject().getFolder(RelEngPlugin.MAP_FOLDER); |
| 212 |
} |
247 |
} |
|
|
248 |
|
| 213 |
private void loadMapFiles() throws CoreException { |
249 |
private void loadMapFiles() throws CoreException { |
| 214 |
IFolder folder = project.getFolder(RelEngPlugin.MAP_FOLDER); |
250 |
IFolder folder = project.getFolder(RelEngPlugin.MAP_FOLDER); |
| 215 |
if(!folder.exists()) { |
251 |
if (!folder.exists()) { |
| 216 |
mapFiles = new MapFile[0]; |
252 |
mapFiles = new MapFile[0]; |
| 217 |
return; |
253 |
return; |
| 218 |
} |
254 |
} |
|
Lines 221-254
Link Here
|
| 221 |
List list = new ArrayList(); |
257 |
List list = new ArrayList(); |
| 222 |
for (int i = 0; i < resource.length; i++) { |
258 |
for (int i = 0; i < resource.length; i++) { |
| 223 |
//In case there are some sub folders |
259 |
//In case there are some sub folders |
| 224 |
if(resource[i].getType() == IResource.FILE){ |
260 |
if (resource[i].getType() == IResource.FILE) { |
| 225 |
IFile file = (IFile) resource[i]; |
261 |
IFile file = (IFile) resource[i]; |
| 226 |
if(isMapFile(file)){ |
262 |
if (isMapFile(file)) { |
| 227 |
list.add(new MapFile(file)); |
263 |
list.add(new MapFile(this, file)); |
| 228 |
} |
264 |
} |
| 229 |
} |
265 |
} |
| 230 |
} |
266 |
} |
| 231 |
mapFiles = (MapFile[])list.toArray(new MapFile[list.size()]); |
267 |
mapFiles = (MapFile[]) list.toArray(new MapFile[list.size()]); |
| 232 |
} else { |
268 |
} else { |
| 233 |
mapFiles = new MapFile[0]; |
269 |
mapFiles = new MapFile[0]; |
| 234 |
} |
270 |
} |
| 235 |
} |
271 |
} |
| 236 |
|
272 |
|
| 237 |
private MapFile getMapFileFor(IFile file) throws CoreException{ |
273 |
private MapFile getMapFileFor(IFile file) throws CoreException { |
| 238 |
for(int i = 0; i < mapFiles.length; i++){ |
274 |
for (int i = 0; i < mapFiles.length; i++) { |
| 239 |
if (mapFiles[i].getFile().equals(file)) |
275 |
if (mapFiles[i].getFile().equals(file)) |
| 240 |
return mapFiles[i]; |
276 |
return mapFiles[i]; |
| 241 |
} |
277 |
} |
| 242 |
return new MapFile(file); |
278 |
return new MapFile(this, file); |
| 243 |
} |
279 |
} |
| 244 |
private void addMapFile(MapFile aFile){ |
280 |
|
|
|
281 |
private void addMapFile(MapFile aFile) { |
| 245 |
Set set = new HashSet(Arrays.asList(mapFiles)); |
282 |
Set set = new HashSet(Arrays.asList(mapFiles)); |
| 246 |
set.add(aFile); |
283 |
set.add(aFile); |
| 247 |
mapFiles = (MapFile[])set.toArray(new MapFile[set.size()]); |
284 |
mapFiles = (MapFile[]) set.toArray(new MapFile[set.size()]); |
| 248 |
} |
285 |
} |
| 249 |
private boolean isMapFile(IFile aFile){ |
286 |
|
| 250 |
String extension = aFile.getFileExtension(); |
287 |
/* |
| 251 |
//In case file has no extension name or is not validate map file |
288 |
* Return a boolean value indicating whether or not the given |
| 252 |
return ( extension != null && extension.equals(MapFile.MAP_FILE_EXTENSION)); |
289 |
* file is a valid map file. |
|
|
290 |
*/ |
| 291 |
private boolean isMapFile(IFile file) { |
| 292 |
// for now just validate based on file extension |
| 293 |
return MapFile.MAP_FILE_EXTENSION.equals(file.getFileExtension()); |
| 253 |
} |
294 |
} |
| 254 |
} |
295 |
} |