Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 173314 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/releng/tools/MapEntry.java (-107 / +81 lines)
Lines 1-28 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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 * 
8
 * Contributors:
8
 * Contributors:
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
13
import java.util.*;
13
import java.util.*;
14
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.Path;
14
import org.eclipse.core.runtime.Path;
17
import org.eclipse.team.internal.ccvs.core.*;
15
import org.eclipse.team.internal.ccvs.core.CVSTag;
18
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
19
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
20
16
21
/**
17
/**
22
 * This class provides access to information stored in RelEng map files
18
 * This class provides access to information stored in RelEng map files
23
 */
19
 */
24
public class MapEntry {
20
public class MapEntry {
25
	
21
26
	private static final String KEY_TAG = "tag"; //$NON-NLS-1$
22
	private static final String KEY_TAG = "tag"; //$NON-NLS-1$
27
	private static final String KEY_PATH = "path"; //$NON-NLS-1$
23
	private static final String KEY_PATH = "path"; //$NON-NLS-1$
28
	private static final String KEY_CVSROOT = "cvsRoot"; //$NON-NLS-1$
24
	private static final String KEY_CVSROOT = "cvsRoot"; //$NON-NLS-1$
Lines 35-79 Link Here
35
	private OrderedMap arguments = new OrderedMap();
31
	private OrderedMap arguments = new OrderedMap();
36
	private boolean legacy = false;
32
	private boolean legacy = false;
37
	private String version;
33
	private String version;
34
	private MapFile file;
38
35
39
	public static void main (String[] args)  {
36
	public static void main(String[] args) {
40
		// For testing only
37
		// For testing only
41
		
38
42
		String[] strings = {
39
		String[] strings = { //
43
			"",
40
		"", //
44
			" ",
41
				" ", //
45
			"type",
42
				"type", //
46
			"type@",
43
				"type@", //
47
			"type@id",
44
				"type@id", //
48
			"type@id=",
45
				"type@id=", //
49
			"type@id=tag,",
46
				"type@id=tag,", //
50
			"type@id=tag, connectString",
47
				"type@id=tag, connectString", //
51
			"type@id=tag, connectString,",
48
				"type@id=tag, connectString,", //
52
			"type@id=tag, connectString,password",
49
				"type@id=tag, connectString,password", //
53
			"type@id=tag, connectString,password,",
50
				"type@id=tag, connectString,password,", //
54
			"type@id=tag, connectString,password,moduleName",
51
				"type@id=tag, connectString,password,moduleName", //
55
			"type@id=tag, connectString,,moduleName",
52
				"type@id=tag, connectString,,moduleName", //
56
			"!***************  FEATURE CONTRIBUTION  ******************************************************",
53
				"!***************  FEATURE CONTRIBUTION  ******************************************************", //
57
			"@",
54
				"@", //
58
			"=",
55
				"=", //
59
			",,,",
56
				",,,", //
60
			"@=,,,,",
57
				"@=,,,,", //
61
			"type@id,version=CVS,tag=myTag,cvsRoot=myCvsRoot,password=password,path=myPath",
58
				"type@id,version=CVS,tag=myTag,cvsRoot=myCvsRoot,password=password,path=myPath", //
62
		};
59
		};
63
		
60
64
		for (int i = 0; i < strings.length; i++) {
61
		for (int i = 0; i < strings.length; i++) {
65
			String string = strings[i];
62
			String string = strings[i];
66
			MapEntry anEntry = new MapEntry(string);
63
			MapEntry anEntry = new MapEntry(string, null);
67
64
68
			System.out.println("-----------------------------------------------");
65
			System.out.println("-----------------------------------------------");
69
			System.out.println("input: " + string);
66
			System.out.println("input: " + string);
70
			System.out.println("map string: " + anEntry.getMapString());
67
			System.out.println("map string: " + anEntry.getMapString());
71
//			System.out.println(anEntry.getReferenceString());
68
			//			System.out.println(anEntry.getReferenceString());
72
			anEntry.display();
69
			anEntry.display();
73
		}
70
		}
74
		
71
75
	}
72
	}
76
	
73
77
	/**
74
	/**
78
	 * 
75
	 * 
79
	 */
76
	 */
Lines 89-116 Link Here
89
		System.out.println("Password: " + getPassword());
86
		System.out.println("Password: " + getPassword());
90
		System.out.println("CVS Module: " + getCVSModule());
87
		System.out.println("CVS Module: " + getCVSModule());
91
	}
88
	}
92
	
89
93
	public MapEntry(String entryLine) {
90
	/*
91
	 * Return a new MapEntry object based on the given line from a Map
92
	 * file. If the line isn't a valid entry (comment, unknown fetch type, etc)
93
	 * then return null.
94
	 */
95
	public static MapEntry parse(String line, MapFile file) {
96
		MapEntry result = new MapEntry(line, file);
97
		return result.isValid() ? result : null;
98
	}
99
100
	private MapEntry(String entryLine, MapFile file) {
101
		this.file = file;
94
		init(entryLine);
102
		init(entryLine);
95
	}
103
	}
96
104
105
	public MapFile getFile() {
106
		return file;
107
	}
108
97
	/**
109
	/**
98
	 * Parse a map file entry line
110
	 * Parse a map file entry line
99
	 * @param entryLine
111
	 * @param entryLine
100
	 */	
112
	 */
101
	private void init(String entryLine) {
113
	private void init(String entryLine) {
102
		valid = false;
114
		valid = false;
103
	
115
104
		// Type	
116
		// Type	
105
		int start = 0;
117
		int start = 0;
106
		int end = entryLine.indexOf('@');
118
		int end = entryLine.indexOf('@');
107
		if (end == -1)  return;
119
		if (end == -1)
120
			return;
108
		type = entryLine.substring(start, end).trim();
121
		type = entryLine.substring(start, end).trim();
109
		
122
110
		// Project Name
123
		// Project Name
111
		start = end + 1;
124
		start = end + 1;
112
		end = entryLine.indexOf('=', start);
125
		end = entryLine.indexOf('=', start);
113
		if (end == -1) return;
126
		if (end == -1)
127
			return;
114
		id = entryLine.substring(start, end).trim();
128
		id = entryLine.substring(start, end).trim();
115
		// we have a version that we have to strip off
129
		// we have a version that we have to strip off
116
		int comma = id.indexOf(',');
130
		int comma = id.indexOf(',');
Lines 134-146 Link Here
134
	 */
148
	 */
135
	private OrderedMap populate(String[] entries) {
149
	private OrderedMap populate(String[] entries) {
136
		OrderedMap result = new OrderedMap();
150
		OrderedMap result = new OrderedMap();
137
		for (int i=0; i<entries.length; i++) {
151
		for (int i = 0; i < entries.length; i++) {
138
			String entry = entries[i];
152
			String entry = entries[i];
139
			int index = entry.indexOf('=');
153
			int index = entry.indexOf('=');
140
			if (index == -1) {
154
			if (index == -1) {
141
				// we only handle CVS entries
155
				if (RelEngPlugin.isValidFetchCommand(entry)) {
142
				if (i == 0 && "CVS".equalsIgnoreCase(entry)) 
156
					// we only handle CVS entries
143
					continue;
157
					if (i == 0 && "CVS".equalsIgnoreCase(entry))
158
						continue;
159
					// if we have GET or something then just return
160
					return result;
161
				}
144
				// legacy story...
162
				// legacy story...
145
				return legacyPopulate(entries);
163
				return legacyPopulate(entries);
146
			}
164
			}
Lines 151-157 Link Here
151
		result.toString();
169
		result.toString();
152
		return result;
170
		return result;
153
	}
171
	}
154
	
172
155
	private OrderedMap legacyPopulate(String[] entries) {
173
	private OrderedMap legacyPopulate(String[] entries) {
156
		legacy = true;
174
		legacy = true;
157
		OrderedMap result = new OrderedMap();
175
		OrderedMap result = new OrderedMap();
Lines 161-171 Link Here
161
			result.put(KEY_TAG, entries[0]);
179
			result.put(KEY_TAG, entries[0]);
162
			// Repo Connect String
180
			// Repo Connect String
163
			result.put(KEY_CVSROOT, entries[1]);
181
			result.put(KEY_CVSROOT, entries[1]);
164
			
182
165
			// Optional Password.
183
			// Optional Password.
166
			if (entries.length >= 3)
184
			if (entries.length >= 3)
167
				result.put(KEY_PASSWORD, entries[2]);
185
				result.put(KEY_PASSWORD, entries[2]);
168
			
186
169
			// Optional CVS Module Name
187
			// Optional CVS Module Name
170
			if (entries.length >= 4)
188
			if (entries.length >= 4)
171
				result.put(KEY_PATH, entries[3]);
189
				result.put(KEY_PATH, entries[3]);
Lines 203-214 Link Here
203
		String value = (String) arguments.get(KEY_TAG);
221
		String value = (String) arguments.get(KEY_TAG);
204
		return value == null ? EMPTY_STRING : value;
222
		return value == null ? EMPTY_STRING : value;
205
	}
223
	}
206
	
224
207
	public CVSTag getTag() {
225
	public CVSTag getTag() {
208
		if (getTagName().equals("HEAD")) return CVSTag.DEFAULT;
226
		if (getTagName().equals("HEAD"))
227
			return CVSTag.DEFAULT;
209
		return new CVSTag(getTagName(), CVSTag.VERSION);
228
		return new CVSTag(getTagName(), CVSTag.VERSION);
210
	}
229
	}
211
	
230
212
	public String getPassword() {
231
	public String getPassword() {
213
		String value = (String) arguments.get(KEY_PASSWORD);
232
		String value = (String) arguments.get(KEY_PASSWORD);
214
		return value == null ? EMPTY_STRING : value;
233
		return value == null ? EMPTY_STRING : value;
Lines 218-228 Link Here
218
		return id;
237
		return id;
219
	}
238
	}
220
239
221
	private String internalGetCVSModule()  {
240
	private String internalGetCVSModule() {
222
		String module = (String) arguments.get(KEY_PATH);
241
		String module = (String) arguments.get(KEY_PATH);
223
		return module == null ? id : module;
242
		return module == null ? id : module;
224
	}
243
	}
225
	
244
226
	public String getCVSModule() {
245
	public String getCVSModule() {
227
		String value = (String) arguments.get(KEY_PATH);
246
		String value = (String) arguments.get(KEY_PATH);
228
		return value == null ? EMPTY_STRING : value;
247
		return value == null ? EMPTY_STRING : value;
Lines 240-248 Link Here
240
	public boolean isValid() {
259
	public boolean isValid() {
241
		return valid;
260
		return valid;
242
	}
261
	}
243
	
262
244
	public String getReferenceString()  {
263
	public String getReferenceString() {
245
		if (!isValid()) return null;
264
		if (!isValid())
265
			return null;
246
		// This is the format used by the CVS IProjectSerializer
266
		// This is the format used by the CVS IProjectSerializer
247
		String projectName = new Path(internalGetCVSModule()).lastSegment();
267
		String projectName = new Path(internalGetCVSModule()).lastSegment();
248
		return "1.0," + getRepo() + "," + internalGetCVSModule() + "," + projectName + "," + getTagName();
268
		return "1.0," + getRepo() + "," + internalGetCVSModule() + "," + projectName + "," + getTagName();
Lines 278-284 Link Here
278
		}
298
		}
279
		result.append('=');
299
		result.append('=');
280
		result.append("CVS");
300
		result.append("CVS");
281
		for (Iterator iter = arguments.keys().iterator(); iter.hasNext(); ) {
301
		for (Iterator iter = arguments.keys().iterator(); iter.hasNext();) {
282
			String key = (String) iter.next();
302
			String key = (String) iter.next();
283
			String value = (String) arguments.get(key);
303
			String value = (String) arguments.get(key);
284
			if (value != null && value.length() > 0)
304
			if (value != null && value.length() > 0)
Lines 293-299 Link Here
293
	public String getVersion() {
313
	public String getVersion() {
294
		return version;
314
		return version;
295
	}
315
	}
296
	
316
297
	public void setPassword(String password) {
317
	public void setPassword(String password) {
298
		arguments.put(KEY_PASSWORD, password);
318
		arguments.put(KEY_PASSWORD, password);
299
	}
319
	}
Lines 321-327 Link Here
321
	public void setValid(boolean valid) {
341
	public void setValid(boolean valid) {
322
		this.valid = valid;
342
		this.valid = valid;
323
	}
343
	}
324
	
344
325
	public String toString() {
345
	public String toString() {
326
		return "Entry: " + getMapString();
346
		return "Entry: " + getMapString();
327
	}
347
	}
Lines 331-384 Link Here
331
	 */
351
	 */
332
	public boolean equals(Object obj) {
352
	public boolean equals(Object obj) {
333
		if (obj instanceof MapEntry) {
353
		if (obj instanceof MapEntry) {
334
			return ((MapEntry)obj).getMapString().equals(getMapString());
354
			return ((MapEntry) obj).getMapString().equals(getMapString());
335
		}
355
		}
336
		return super.equals(obj);
356
		return super.equals(obj);
337
	}
357
	}
338
	
339
	/**
340
	 * Return true if this map entry is mapped to the given CVS module
341
	 * @param moduleName
342
	 */
343
	public boolean isMappedTo(String moduleName) {
344
		IPath entryPath = new Path(internalGetCVSModule());
345
		IPath modulePath = new Path(moduleName);
346
		if (entryPath.segmentCount() != modulePath.segmentCount()) return false;
347
		for (int i = 0; i < entryPath.segmentCount(); i++) {
348
			if (!entryPath.segment(i).equals(modulePath.segment(i))) {
349
				return false;
350
			}
351
		}
352
		return true;
353
	}
354
355
	/**
356
	 * Return <code>true</code> if the entry is mapped to the given project
357
	 * and <code>false</code> otherwise.
358
	 */
359
	public boolean isMappedTo(IProject project) {
360
		String moduleName;
361
		try {
362
			moduleName = getCVSModule(project);
363
			if (moduleName == null) return false;
364
			return isMappedTo(moduleName);
365
		} catch (CVSException e) {
366
			RelEngPlugin.getDefault().getLog().log(e.getStatus());
367
			return false;
368
		}
369
	}
370
	
371
	/**
372
	 * Get the remote CVS module for the project or <code>null</code>
373
	 * if the project is not a CVS project.
374
	 */
375
	private String getCVSModule(IProject project) throws CVSException {
376
		ICVSFolder folder = CVSWorkspaceRoot.getCVSFolderFor(project);
377
		FolderSyncInfo info = folder.getFolderSyncInfo();
378
		if (info == null) {
379
			return null;
380
		}
381
		return info.getRepository();
382
	}
383
384
}
358
}
(-)src/org/eclipse/releng/tools/MapContentDocument.java (-26 / +27 lines)
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 10-22 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.releng.tools;
11
package org.eclipse.releng.tools;
12
12
13
import java.io.BufferedInputStream;
13
import java.io.*;
14
import java.io.BufferedReader;
15
import java.io.ByteArrayInputStream;
16
import java.io.IOException;
17
import java.io.InputStream;
18
import java.io.InputStreamReader;
19
20
import org.eclipse.compare.IStreamContentAccessor;
14
import org.eclipse.compare.IStreamContentAccessor;
21
import org.eclipse.compare.ITypedElement;
15
import org.eclipse.compare.ITypedElement;
22
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.IProject;
Lines 25-38 Link Here
25
import org.eclipse.team.internal.ccvs.core.CVSException;
19
import org.eclipse.team.internal.ccvs.core.CVSException;
26
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
20
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
27
21
28
22
/*
29
public class MapContentDocument implements ITypedElement, IStreamContentAccessor{
23
 * TODO Its a shame that we use Strings here and it isn't backed by real MapEntry objects
24
 * but in order to do this we need to make changes outside of the MapEntryRegistry and then
25
 * commit them once the user commits the map file changes to the file-system.
26
 */
27
public class MapContentDocument implements ITypedElement, IStreamContentAccessor {
30
	private MapFile mapFile;
28
	private MapFile mapFile;
31
	private String oldContents = "";
29
	private String oldContents = "";
32
	private String newContents = "";
30
	private String newContents = "";
33
31
34
	public MapContentDocument(MapFile aMapFile) {
32
	public MapContentDocument(MapFile aMapFile) {
35
		mapFile = aMapFile;	
33
		mapFile = aMapFile;
36
		initialize();
34
		initialize();
37
	}
35
	}
38
36
Lines 40-62 Link Here
40
	 * Update the tag associated with the given project in the new contents.
38
	 * Update the tag associated with the given project in the new contents.
41
	 */
39
	 */
42
	public void updateTag(IProject project, String tag) throws CVSException {
40
	public void updateTag(IProject project, String tag) throws CVSException {
43
		InputStream inputStream = new BufferedInputStream(
41
		MapEntry realEntry = mapFile.getMapEntry(project);
44
				new ByteArrayInputStream(newContents.getBytes()));
42
		if (realEntry == null)
43
			return;
44
		String mapString = realEntry.getMapString();
45
		InputStream inputStream = new BufferedInputStream(new ByteArrayInputStream(newContents.getBytes()));
45
		boolean match = false;
46
		boolean match = false;
46
		StringBuffer buffer = new StringBuffer();
47
		StringBuffer buffer = new StringBuffer();
47
		try {
48
		try {
48
			BufferedReader aReader = new BufferedReader(new InputStreamReader(
49
			BufferedReader aReader = new BufferedReader(new InputStreamReader(inputStream));
49
					inputStream));
50
			String aLine = aReader.readLine();
50
			String aLine = aReader.readLine();
51
			while (aLine != null) {
51
			while (aLine != null) {
52
				if (aLine.trim().length() != 0 && !aLine.startsWith("!")) {
52
				if (aLine.trim().length() != 0 && !aLine.startsWith("!")) {
53
					// Found a possible match
53
					// Found a possible match
54
					MapEntry entry = new MapEntry(aLine);
54
					MapEntry entry = MapEntry.parse(aLine, mapFile);
55
					if (!entry.isValid()) {
55
					if (entry != null && mapString.equals(entry.getMapString())) {
56
						throw new CVSException("Malformed map file line: "
57
								+ aLine);
58
					}
59
					if (entry.isMappedTo(project)) {
60
						// Now for sure we have a match. Replace the line.
56
						// Now for sure we have a match. Replace the line.
61
						entry.setTagName(tag);
57
						entry.setTagName(tag);
62
						aLine = entry.getMapString();
58
						aLine = entry.getMapString();
Lines 69-76 Link Here
69
					buffer.append(System.getProperty("line.separator")); //$NON-NLS-1$
65
					buffer.append(System.getProperty("line.separator")); //$NON-NLS-1$
70
				}
66
				}
71
			}
67
			}
72
		} catch (CoreException e) {
73
			throw CVSException.wrapException(e);
74
		} catch (IOException e) {
68
		} catch (IOException e) {
75
			throw CVSException.wrapException(e);
69
			throw CVSException.wrapException(e);
76
		} finally {
70
		} finally {
Lines 78-83 Link Here
78
				try {
72
				try {
79
					inputStream.close();
73
					inputStream.close();
80
				} catch (IOException e) {
74
				} catch (IOException e) {
75
					// ignore
81
				}
76
				}
82
			}
77
			}
83
		}
78
		}
Lines 85-93 Link Here
85
			newContents = buffer.toString();
80
			newContents = buffer.toString();
86
		}
81
		}
87
	}
82
	}
83
88
	public boolean isChanged() {
84
	public boolean isChanged() {
89
		return !(oldContents.equals(newContents));
85
		return !(oldContents.equals(newContents));
90
	}
86
	}
87
91
	/*
88
	/*
92
	 * (non-Javadoc)
89
	 * (non-Javadoc)
93
	 * 
90
	 * 
Lines 96-101 Link Here
96
	public String getName() {
93
	public String getName() {
97
		return mapFile.getFile().getName();
94
		return mapFile.getFile().getName();
98
	}
95
	}
96
99
	/*
97
	/*
100
	 * (non-Javadoc)
98
	 * (non-Javadoc)
101
	 * 
99
	 * 
Lines 104-109 Link Here
104
	public Image getImage() {
102
	public Image getImage() {
105
		return null;
103
		return null;
106
	}
104
	}
105
107
	/*
106
	/*
108
	 * (non-Javadoc)
107
	 * (non-Javadoc)
109
	 * 
108
	 * 
Lines 112-117 Link Here
112
	public String getType() {
111
	public String getType() {
113
		return mapFile.getFile().getFileExtension();
112
		return mapFile.getFile().getFileExtension();
114
	}
113
	}
114
115
	/*
115
	/*
116
	 * (non-Javadoc)
116
	 * (non-Javadoc)
117
	 * 
117
	 * 
Lines 120-139 Link Here
120
	public InputStream getContents() throws CoreException {
120
	public InputStream getContents() throws CoreException {
121
		return new ByteArrayInputStream(getNewContent().getBytes());
121
		return new ByteArrayInputStream(getNewContent().getBytes());
122
	}
122
	}
123
123
	public MapFile getMapFile() {
124
	public MapFile getMapFile() {
124
		return mapFile;
125
		return mapFile;
125
	}
126
	}
126
	
127
127
	private String getNewContent() {
128
	private String getNewContent() {
128
		return newContents;
129
		return newContents;
129
	}
130
	}
131
130
	private void initialize() {
132
	private void initialize() {
131
		InputStream inputStream;
133
		InputStream inputStream;
132
		StringBuffer buffer = new StringBuffer();
134
		StringBuffer buffer = new StringBuffer();
133
		try {
135
		try {
134
			inputStream = mapFile.getFile().getContents();
136
			inputStream = mapFile.getFile().getContents();
135
			BufferedReader aReader = new BufferedReader(new InputStreamReader(
137
			BufferedReader aReader = new BufferedReader(new InputStreamReader(inputStream));
136
					inputStream));
137
			String aLine = aReader.readLine();
138
			String aLine = aReader.readLine();
138
			while (aLine != null) {
139
			while (aLine != null) {
139
				buffer.append(aLine);
140
				buffer.append(aLine);
(-)src/org/eclipse/releng/tools/MapFile.java (-67 / +116 lines)
Lines 1-58 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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 * 
8
 * Contributors:
8
 * Contributors:
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
13
import java.io.BufferedReader;
13
import java.io.*;
14
import java.io.IOException;
15
import java.io.InputStream;
16
import java.io.InputStreamReader;
17
import java.util.*;
14
import java.util.*;
15
import org.eclipse.core.resources.*;
16
import org.eclipse.core.runtime.*;
18
17
19
import org.eclipse.core.resources.IFile;
18
/*
20
import org.eclipse.core.resources.IProject;
19
 * This class represents a build submission map file in the workspace.
21
import org.eclipse.core.resources.ResourcesPlugin;
20
 */
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.Status;
25
26
public class MapFile {
21
public class MapFile {
27
	
22
28
	public static final String MAP_FILE_EXTENSION = "map";
23
	public static final String MAP_FILE_EXTENSION = "map";
29
	
24
30
	protected IFile file;
25
	protected IFile file;
31
	protected MapEntry[] entries;
26
	// entries in the files...mixed Strings and MapEntry
32
	
27
	protected List entries = new ArrayList();
33
	public MapFile(IFile aFile) throws CoreException {
28
	private MapProject project;
34
		file = aFile;
29
30
	/*
31
	 * Constructor for the class. Create a new map file on the given
32
	 * workspace file with the specified parent project.
33
	 */
34
	public MapFile(MapProject project, IFile aFile) throws CoreException {
35
		this.project = project;
36
		this.file = aFile;
35
		loadEntries();
37
		loadEntries();
36
	}
38
	}
37
	
39
38
	public IFile getFile(){
40
	/*
41
	 * Return the workspace file associated with this map file.
42
	 */
43
	public IFile getFile() {
39
		return file;
44
		return file;
40
	}
45
	}
41
	
46
47
	/*
48
	 * Return this map file's parent project.
49
	 */
50
	public MapProject getProject() {
51
		return project;
52
	}
53
54
	/*
55
	 * Load this map file's contents. Populate the entry list.
56
	 */
42
	protected void loadEntries() throws CoreException {
57
	protected void loadEntries() throws CoreException {
43
		InputStream inputStream = null;
58
		InputStream inputStream = null;
44
		List list = new ArrayList();		
45
46
		try {
59
		try {
47
			inputStream = file.getContents();
60
			inputStream = file.getContents();
48
			BufferedReader aReader = new BufferedReader(new InputStreamReader(
61
			BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
49
					inputStream));
62
			String lline = reader.readLine();
50
			String aLine = aReader.readLine();
63
			while (lline != null) {
51
			while (aLine != null) {
64
				MapEntry entry = MapEntry.parse(lline, this);
52
				if (isMapLine(aLine)) {
65
				entries.add(entry == null ? (Object) lline : entry);
53
					list.add(new MapEntry(aLine));
66
				lline = reader.readLine();
54
				}
55
				aLine = aReader.readLine();
56
			}
67
			}
57
		} catch (IOException e) {
68
		} catch (IOException e) {
58
			throw new CoreException(new Status(IStatus.ERROR, RelEngPlugin.ID, 0, "An I/O Error occurred process map file " + file.getFullPath().toString(), e));
69
			throw new CoreException(new Status(IStatus.ERROR, RelEngPlugin.ID, 0, "An I/O Error occurred process map file " + file.getFullPath().toString(), e));
Lines 65-117 Link Here
65
				}
76
				}
66
			}
77
			}
67
		}
78
		}
68
69
		this.entries = (MapEntry[]) list.toArray(new MapEntry[list.size()]);
70
	}
71
	
72
	private boolean isMapLine(String line) {
73
		if (line.trim().length() == 0) return false;
74
		if (line.startsWith("!")) return false;
75
		return true;
76
	}
77
	
78
	public boolean contains(IProject project){
79
		for(int j = 0;j < entries.length; j++){
80
			if (entries[j].isMappedTo(project)){
81
				return true;
82
			}
83
		}
84
		return false;
85
	}
86
87
	public MapEntry getMapEntry(IProject project) {
88
		for(int j = 0;j < entries.length; j++){
89
			if (entries[j].isMappedTo(project)){
90
				return entries[j];
91
			}
92
		}
93
		return null;
94
	}
79
	}
95
80
81
	/*
82
	 * Return a boolean value indicating whether or not this map file
83
	 * contains a valid map file entry for the given project.
84
	 */
85
	public boolean contains(IProject workspaceProject) {
86
		return getMapEntry(workspaceProject) != null;
87
	}
88
89
	/*
90
	 * Return the map entry for the given project, or null
91
	 * if there isn't a match. Note that it only returns an entry
92
	 * if it is a member of this map file. Clients wishing to find 
93
	 * any entry on any file should call the same method on MapProject.
94
	 */
95
	public MapEntry getMapEntry(IProject workspaceProject) {
96
		MapEntry entry = project.getMapEntry(workspaceProject);
97
		return entry == null || !entry.getFile().equals(this) ? null : entry;
98
	}
99
100
	/*
101
	 * Return an array of accessible workspace projects for this map file.
102
	 */
96
	public IProject[] getAccessibleProjects() {
103
	public IProject[] getAccessibleProjects() {
97
		Set list = new HashSet();
104
		Set list = new HashSet();
98
		IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
105
		IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
99
		if(entries == null || entries.length ==0) return null;
106
		if (entries == null || entries.size() == 0)
107
			return null;
100
		for (int i = 0; i < projects.length; i++) {
108
		for (int i = 0; i < projects.length; i++) {
101
			IProject project = projects[i];
109
			IProject workspaceProject = projects[i];
102
			if (project.isAccessible()) {
110
			if (workspaceProject.isAccessible()) {
103
				for (int j = 0; j < entries.length; j++){
111
				MapEntry entry = getMapEntry(workspaceProject);
104
					if (entries[j].isMappedTo(project)) {
112
				if (entry != null)
105
						list.add(project);
113
					list.add(workspaceProject);
106
					}
107
				}
108
			}
114
			}
109
		}
115
		}
110
		return (IProject[])list.toArray(new IProject[list.size()]);
116
		return (IProject[]) list.toArray(new IProject[list.size()]);
111
	}
117
	}
112
118
119
	/* (non-Javadoc)
120
	 * @see java.lang.Object#equals(java.lang.Object)
121
	 */
122
	public boolean equals(Object obj) {
123
		if (!(obj instanceof MapFile))
124
			return false;
125
		return getFile().equals(((MapFile) obj).getFile());
126
	}
127
128
	/* (non-Javadoc)
129
	 * @see java.lang.Object#hashCode()
130
	 */
131
	public int hashCode() {
132
		return file.hashCode();
133
	}
134
135
	/*
136
	 * Return the simple name of this map file's workspace file.
137
	 */
113
	public String getName() {
138
	public String getName() {
114
		return file.getName();
139
		return file.getName();
115
	}
140
	}
116
141
142
	/*
143
	 * Return the list of entries for this map file. The resulting list
144
	 * may contain both String and MapEntry entries.
145
	 */
146
	public List getEntries() {
147
		return entries;
148
	}
149
150
	/*
151
	 * Return a string representation of this map file.
152
	 */
153
	public String getContents() {
154
		StringBuffer buffer = new StringBuffer();
155
		for (Iterator iter = entries.iterator(); iter.hasNext();) {
156
			Object obj = iter.next();
157
			if (obj instanceof String)
158
				buffer.append(obj);
159
			else
160
				buffer.append(((MapEntry) obj).getMapString());
161
			if (iter.hasNext())
162
				buffer.append(System.getProperty("line.separator")); //$NON-NLS-1$
163
		}
164
		return buffer.toString();
165
	}
117
}
166
}
(-)src/org/eclipse/releng/tools/RelEngPlugin.java (-9 / +30 lines)
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 8-24 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
12
package org.eclipse.releng.tools;
11
package org.eclipse.releng.tools;
13
12
14
import java.util.MissingResourceException;
13
import java.util.*;
15
import java.util.ResourceBundle;
16
17
import org.eclipse.core.resources.IWorkspace;
14
import org.eclipse.core.resources.IWorkspace;
18
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.*;
20
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.Status;
22
import org.eclipse.ui.plugin.AbstractUIPlugin;
17
import org.eclipse.ui.plugin.AbstractUIPlugin;
23
18
24
/**
19
/**
Lines 36-41 Link Here
36
	private static RelEngPlugin plugin;
31
	private static RelEngPlugin plugin;
37
	//Resource bundle.
32
	//Resource bundle.
38
	private ResourceBundle resourceBundle;
33
	private ResourceBundle resourceBundle;
34
	private static Set fetchCommands;
39
	
35
	
40
	/**
36
	/**
41
	 * The constructor.
37
	 * The constructor.
Lines 121-127 Link Here
121
		}
117
		}
122
		return plugin;
118
		return plugin;
123
	}
119
	}
124
	
120
121
	/*
122
	 * Return true if the given string is a valid fetch command
123
	 * and false otherwise. CVS and GET come with Eclipse by default.
124
	 */
125
	public static boolean isValidFetchCommand(String command) {
126
		if (fetchCommands == null) {
127
			IExtensionPoint extpt = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.pde.build.fetchFactories");
128
			if (extpt == null)
129
				return false;
130
			fetchCommands = new HashSet();
131
			IExtension[] extensions = extpt.getExtensions();
132
			for (int i=0; i<extensions.length; i++) {
133
				IExtension ext = extensions[i];
134
				IConfigurationElement[] configs = ext.getConfigurationElements();
135
				for (int j=0; j<configs.length; j++) {
136
					IConfigurationElement config = configs[j];
137
					String id = config.getAttribute("id");
138
					if (id != null)
139
						fetchCommands.add(id);
140
				}
141
			}
142
		}
143
		return fetchCommands.contains(command);
144
	}
145
125
	/**
146
	/**
126
	 * The following code is a sample of how to assign a
147
	 * The following code is a sample of how to assign a
127
	 * RelEng nature to a project.  This only ever needed
148
	 * RelEng nature to a project.  This only ever needed
(-)src/org/eclipse/releng/tools/LoadMap.java (-12 / +13 lines)
Lines 1-10 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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
Lines 69-80 Link Here
69
		List allStrings = new ArrayList();
69
		List allStrings = new ArrayList();
70
		for (int i = 0; i < mapFiles.length; i++) {
70
		for (int i = 0; i < mapFiles.length; i++) {
71
			IResource resource = mapFiles[i];
71
			IResource resource = mapFiles[i];
72
			String[] referenceStrings = readReferenceStrings((IFile)resource);
72
			String[] referenceStrings = readReferenceStrings((IFile) resource);
73
			allStrings.addAll(Arrays.asList(referenceStrings));
73
			allStrings.addAll(Arrays.asList(referenceStrings));
74
		}
74
		}
75
		return (String[]) allStrings.toArray(new String[allStrings.size()]);
75
		return (String[]) allStrings.toArray(new String[allStrings.size()]);
76
	}
76
	}
77
	
77
78
	/**
78
	/**
79
	 * Method readReferenceStrings.
79
	 * Method readReferenceStrings.
80
	 * @param file
80
	 * @param file
Lines 88-97 Link Here
88
				String line = reader.readLine();
88
				String line = reader.readLine();
89
				List references = new ArrayList();
89
				List references = new ArrayList();
90
				while (line != null) {
90
				while (line != null) {
91
					String referenceString = new MapEntry(line).getReferenceString();
91
					MapEntry entry = MapEntry.parse(line, null);
92
					if (referenceString != null)  {
92
					if (entry != null && entry.getReferenceString() != null)
93
						references.add(referenceString);
93
						references.add(entry.getReferenceString());
94
					}
95
					line = reader.readLine();
94
					line = reader.readLine();
96
				}
95
				}
97
				return (String[]) references.toArray(new String[references.size()]);
96
				return (String[]) references.toArray(new String[references.size()]);
Lines 103-119 Link Here
103
		}
102
		}
104
	}
103
	}
105
104
106
107
	/**
105
	/**
108
	 * @see org.eclipse.team.internal.ui.actions.TeamAction#isEnabled()
106
	 * @see org.eclipse.team.internal.ui.actions.TeamAction#isEnabled()
109
	 */
107
	 */
110
	public boolean isEnabled() {
108
	public boolean isEnabled() {
111
		IResource[] resources = getSelectedResources();
109
		IResource[] resources = getSelectedResources();
112
		if (resources.length == 0) return false;
110
		if (resources.length == 0)
111
			return false;
113
		for (int i = 0; i < resources.length; i++) {
112
		for (int i = 0; i < resources.length; i++) {
114
			IResource resource = resources[i];
113
			IResource resource = resources[i];
115
			if (resource.getType() != IResource.FILE) return false;
114
			if (resource.getType() != IResource.FILE)
116
			if (!resource.getFileExtension().equals("map")) return false;
115
				return false;
116
			if (!resource.getFileExtension().equals("map"))
117
				return false;
117
		}
118
		}
118
		return true;
119
		return true;
119
	}
120
	}
(-)src/org/eclipse/releng/tools/MapProject.java (-88 / +129 lines)
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
}
(-)META-INF/MANIFEST.MF (-1 lines)
Lines 3-9 Link Here
3
Bundle-Name: RelEng Plug-in
3
Bundle-Name: RelEng Plug-in
4
Bundle-SymbolicName: org.eclipse.releng.tools; singleton:=true
4
Bundle-SymbolicName: org.eclipse.releng.tools; singleton:=true
5
Bundle-Version: 3.3.0.qualifier
5
Bundle-Version: 3.3.0.qualifier
6
Bundle-ClassPath: tools.jar
7
Bundle-Activator: org.eclipse.releng.tools.RelEngPlugin
6
Bundle-Activator: org.eclipse.releng.tools.RelEngPlugin
8
Bundle-Vendor: Eclipse.org
7
Bundle-Vendor: Eclipse.org
9
Bundle-Localization: plugin
8
Bundle-Localization: plugin
(-)build.properties (-3 / +5 lines)
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 8-17 Link Here
8
# Contributors:
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
10
###############################################################################
11
source.tools.jar = src/
11
source..=src/
12
bin.includes = plugin.xml,\
12
bin.includes = plugin.xml,\
13
               *.jar,\
13
               .,\
14
               about.html,\
14
               about.html,\
15
               icons/,\
15
               icons/,\
16
               plugin.properties,\
16
               plugin.properties,\
17
               META-INF/
17
               META-INF/
18
output.. = bin/
19
src.includes=about.html
(-)src/org/eclipse/releng/tools/MapEntryRegistry.java (+223 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: IBM Corporation - initial API and implementation
8
 ******************************************************************************/
9
package org.eclipse.releng.tools;
10
11
import java.io.IOException;
12
import java.util.*;
13
import org.eclipse.core.resources.*;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.Path;
16
import org.eclipse.osgi.util.ManifestElement;
17
import org.osgi.framework.*;
18
19
/*
20
 * This class represents a registry of map entries from a map file. Clients are
21
 * able to do look-ups based on workspace projects and get back the map entry 
22
 * that corresponds to their project.
23
 */
24
public class MapEntryRegistry {
25
26
	// the registry
27
	private Map registry = new HashMap();
28
29
	/*
30
	 * Internal class which represents a key in the registry.
31
	 */
32
	static class Key {
33
		IProject project;
34
		Version version;
35
36
		/*
37
		 * Constructor for the class. The project must be valid
38
		 * but the version can be null.
39
		 */
40
		public Key(IProject project, Version version) {
41
			super();
42
			if (project == null)
43
				throw new IllegalArgumentException("Project cannot be null.");
44
			this.project = project;
45
			this.version = version;
46
		}
47
48
		/* (non-Javadoc)
49
		 * @see java.lang.Object#equals(java.lang.Object)
50
		 */
51
		public boolean equals(Object obj) {
52
			if (!(obj instanceof Key))
53
				return false;
54
			Key other = (Key) obj;
55
			if (!project.equals(other.project))
56
				return false;
57
			if (version == null)
58
				return other.version == null;
59
			return version.equals(other.version);
60
		}
61
62
		/* (non-Javadoc)
63
		 * @see java.lang.Object#hashCode()
64
		 */
65
		public int hashCode() {
66
			return project.hashCode() + (version == null ? 0 : version.hashCode());
67
		}
68
69
	}
70
71
	/*
72
	 * Store the given project and version pair in this registry with its map file entry.
73
	 */
74
	private void put(IProject project, Version version, MapEntry entry) {
75
		registry.put(new Key(project, version), entry);
76
	}
77
78
	/*
79
	 * Add the contents of the given map file to this registry.
80
	 */
81
	public void add(MapProject mapProject) {
82
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
83
		MapFile[] files = mapProject.getMapFiles();
84
		for (int i = 0; i < files.length; i++) {
85
			MapFile file = files[i];
86
			List entries = file.getEntries();
87
			for (Iterator iter = entries.iterator(); iter.hasNext();) {
88
				Object obj = iter.next();
89
				if (!(obj instanceof MapEntry))
90
					continue;
91
				MapEntry entry = (MapEntry) obj;
92
				String id = entry.getId();
93
				IProject project = root.getProject(id);
94
				if (!project.isAccessible())
95
					continue;
96
				String versionString = entry.getVersion();
97
				Version version = versionString == null ? null : new Version(versionString);
98
				put(project, version, entry);
99
			}
100
		}
101
	}
102
103
	/*
104
	 * Return the map file entry for the given map file line. Return null
105
	 * if there is no match.
106
	 */
107
	public MapEntry get(String line) {
108
		for (Iterator iter = registry.entrySet().iterator(); iter.hasNext();) {
109
			MapEntry entry = (MapEntry) iter.next();
110
			if (entry.getMapString().equals(MapEntry.parse(line, null).getMapString()))
111
				return entry;
112
		}
113
		return null;
114
	}
115
116
	/*
117
	 * Return the map file entry for the given workspace project.
118
	 */
119
	public MapEntry get(IProject project) {
120
		MapEntry[] entries = getAll(project);
121
		if (entries == null || entries.length == 0)
122
			return null;
123
		if (entries.length == 1)
124
			return entries[0];
125
126
		// get the version from the project
127
		Version projectVersion = getVersion(project);
128
		if (projectVersion == null)
129
			return null;
130
		// check for an exact match, also keep track if we have a null version entry
131
		MapEntry nullEntry = null;
132
		for (int i = 0; i < entries.length; i++) {
133
			Version entryVersion = entries[i].getVersion() == null ? null : new Version(entries[i].getVersion());
134
			// we have an exact match
135
			if (projectVersion.equals(entryVersion))
136
				return entries[i];
137
			if (entryVersion == null)
138
				nullEntry = entries[i];
139
		}
140
		// we didn't have an exact match but there was an entry in the file
141
		// with a null version so return it
142
		if (nullEntry != null)
143
			return nullEntry;
144
		// otherwise try and guess the best version
145
		return bestMatch(projectVersion, entries);
146
	}
147
148
	/*
149
	 * Try and determine the version of the given project by looking
150
	 * in its manifest file.
151
	 */
152
	private Version getVersion(IProject project) {
153
		// sort and pick the best based on version
154
		// get the version from the project
155
		IFile manifest = project.getFile(new Path("META-INF/MANIFEST.MF"));
156
		// we can't find the manifest file so we can't determine the version in the workspace
157
		// TODO we could try and parse the plugin.xml if one exists
158
		if (!manifest.exists())
159
			return null;
160
		String versionString = null;
161
		try {
162
			Map map = ManifestElement.parseBundleManifest(manifest.getContents(), null);
163
			versionString = (String) map.get(Constants.BUNDLE_VERSION);
164
		} catch (IOException e) {
165
			e.printStackTrace();
166
			return null;
167
		} catch (BundleException e) {
168
			e.printStackTrace();
169
			return null;
170
		} catch (CoreException e) {
171
			e.printStackTrace();
172
			return null;
173
		}
174
		if (versionString == null)
175
			return null;
176
		Version projectVersion = new Version(versionString);
177
		// TODO for now we strip off the qualifier
178
		return new Version(projectVersion.getMajor(), projectVersion.getMinor(), projectVersion.getMicro(), null);
179
	}
180
181
	/*
182
	 * Return the best map file entry match for the given version.
183
	 */
184
	private MapEntry bestMatch(Version version, MapEntry[] entries) {
185
		MapEntry result = null;
186
		Version resultVersion = null;
187
		for (int i = 0; i < entries.length; i++) {
188
			MapEntry entry = entries[i];
189
			String versionString = entry.getVersion();
190
			if (versionString == null)
191
				return entry;
192
			Version entryVersion = new Version(versionString);
193
			// we require at least...
194
			int comparison = entryVersion.compareTo(version);
195
			if (comparison < 0)
196
				continue;
197
			// we should have already handled the equals case but
198
			// in case we didn't...
199
			if (comparison == 0)
200
				return entry;
201
			// grab the latest version
202
			if (result == null || entryVersion.compareTo(resultVersion) > 0) {
203
				result = entry;
204
				resultVersion = entryVersion;
205
				continue;
206
			}
207
		}
208
		return result;
209
	}
210
211
	/*
212
	 * Return all of the map file entries registered for the given project.
213
	 */
214
	private MapEntry[] getAll(IProject project) {
215
		List result = new ArrayList();
216
		for (Iterator iter = registry.keySet().iterator(); iter.hasNext();) {
217
			Key key = (Key) iter.next();
218
			if (key.project.equals(project))
219
				result.add(registry.get(key));
220
		}
221
		return (MapEntry[]) result.toArray(new MapEntry[result.size()]);
222
	}
223
}

Return to bug 173314