Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 59427 Details for
Bug 173314
[relengtool] Update tools to handle multiple versions of plug-ins in map files
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch for releng.tools
patch.txt (text/plain), 49.89 KB, created by
DJ Houghton
on 2007-02-20 17:59:05 EST
(
hide
)
Description:
patch for releng.tools
Filename:
MIME Type:
Creator:
DJ Houghton
Created:
2007-02-20 17:59:05 EST
Size:
49.89 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.releng.tools >Index: src/org/eclipse/releng/tools/MapEntry.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.releng.tools/src/org/eclipse/releng/tools/MapEntry.java,v >retrieving revision 1.5 >diff -u -r1.5 MapEntry.java >--- src/org/eclipse/releng/tools/MapEntry.java 7 Feb 2007 19:09:00 -0000 1.5 >+++ src/org/eclipse/releng/tools/MapEntry.java 20 Feb 2007 22:56:47 -0000 >@@ -1,28 +1,24 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 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.releng.tools; > > import java.util.*; >-import org.eclipse.core.resources.IProject; >-import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.Path; >-import org.eclipse.team.internal.ccvs.core.*; >-import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; >-import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; >+import org.eclipse.team.internal.ccvs.core.CVSTag; > > /** > * This class provides access to information stored in RelEng map files > */ > public class MapEntry { >- >+ > private static final String KEY_TAG = "tag"; //$NON-NLS-1$ > private static final String KEY_PATH = "path"; //$NON-NLS-1$ > private static final String KEY_CVSROOT = "cvsRoot"; //$NON-NLS-1$ >@@ -35,45 +31,46 @@ > private OrderedMap arguments = new OrderedMap(); > private boolean legacy = false; > private String version; >+ private MapFile file; > >- public static void main (String[] args) { >+ public static void main(String[] args) { > // For testing only >- >- String[] strings = { >- "", >- " ", >- "type", >- "type@", >- "type@id", >- "type@id=", >- "type@id=tag,", >- "type@id=tag, connectString", >- "type@id=tag, connectString,", >- "type@id=tag, connectString,password", >- "type@id=tag, connectString,password,", >- "type@id=tag, connectString,password,moduleName", >- "type@id=tag, connectString,,moduleName", >- "!*************** FEATURE CONTRIBUTION ******************************************************", >- "@", >- "=", >- ",,,", >- "@=,,,,", >- "type@id,version=CVS,tag=myTag,cvsRoot=myCvsRoot,password=password,path=myPath", >+ >+ String[] strings = { // >+ "", // >+ " ", // >+ "type", // >+ "type@", // >+ "type@id", // >+ "type@id=", // >+ "type@id=tag,", // >+ "type@id=tag, connectString", // >+ "type@id=tag, connectString,", // >+ "type@id=tag, connectString,password", // >+ "type@id=tag, connectString,password,", // >+ "type@id=tag, connectString,password,moduleName", // >+ "type@id=tag, connectString,,moduleName", // >+ "!*************** FEATURE CONTRIBUTION ******************************************************", // >+ "@", // >+ "=", // >+ ",,,", // >+ "@=,,,,", // >+ "type@id,version=CVS,tag=myTag,cvsRoot=myCvsRoot,password=password,path=myPath", // > }; >- >+ > for (int i = 0; i < strings.length; i++) { > String string = strings[i]; >- MapEntry anEntry = new MapEntry(string); >+ MapEntry anEntry = new MapEntry(string, null); > > System.out.println("-----------------------------------------------"); > System.out.println("input: " + string); > System.out.println("map string: " + anEntry.getMapString()); >-// System.out.println(anEntry.getReferenceString()); >+ // System.out.println(anEntry.getReferenceString()); > anEntry.display(); > } >- >+ > } >- >+ > /** > * > */ >@@ -89,28 +86,45 @@ > System.out.println("Password: " + getPassword()); > System.out.println("CVS Module: " + getCVSModule()); > } >- >- public MapEntry(String entryLine) { >+ >+ /* >+ * Return a new MapEntry object based on the given line from a Map >+ * file. If the line isn't a valid entry (comment, unknown fetch type, etc) >+ * then return null. >+ */ >+ public static MapEntry parse(String line, MapFile file) { >+ MapEntry result = new MapEntry(line, file); >+ return result.isValid() ? result : null; >+ } >+ >+ private MapEntry(String entryLine, MapFile file) { >+ this.file = file; > init(entryLine); > } > >+ public MapFile getFile() { >+ return file; >+ } >+ > /** > * Parse a map file entry line > * @param entryLine >- */ >+ */ > private void init(String entryLine) { > valid = false; >- >+ > // Type > int start = 0; > int end = entryLine.indexOf('@'); >- if (end == -1) return; >+ if (end == -1) >+ return; > type = entryLine.substring(start, end).trim(); >- >+ > // Project Name > start = end + 1; > end = entryLine.indexOf('=', start); >- if (end == -1) return; >+ if (end == -1) >+ return; > id = entryLine.substring(start, end).trim(); > // we have a version that we have to strip off > int comma = id.indexOf(','); >@@ -134,13 +148,17 @@ > */ > private OrderedMap populate(String[] entries) { > OrderedMap result = new OrderedMap(); >- for (int i=0; i<entries.length; i++) { >+ for (int i = 0; i < entries.length; i++) { > String entry = entries[i]; > int index = entry.indexOf('='); > if (index == -1) { >- // we only handle CVS entries >- if (i == 0 && "CVS".equalsIgnoreCase(entry)) >- continue; >+ if (RelEngPlugin.isValidFetchCommand(entry)) { >+ // we only handle CVS entries >+ if (i == 0 && "CVS".equalsIgnoreCase(entry)) >+ continue; >+ // if we have GET or something then just return >+ return result; >+ } > // legacy story... > return legacyPopulate(entries); > } >@@ -151,7 +169,7 @@ > result.toString(); > return result; > } >- >+ > private OrderedMap legacyPopulate(String[] entries) { > legacy = true; > OrderedMap result = new OrderedMap(); >@@ -161,11 +179,11 @@ > result.put(KEY_TAG, entries[0]); > // Repo Connect String > result.put(KEY_CVSROOT, entries[1]); >- >+ > // Optional Password. > if (entries.length >= 3) > result.put(KEY_PASSWORD, entries[2]); >- >+ > // Optional CVS Module Name > if (entries.length >= 4) > result.put(KEY_PATH, entries[3]); >@@ -203,12 +221,13 @@ > String value = (String) arguments.get(KEY_TAG); > return value == null ? EMPTY_STRING : value; > } >- >+ > public CVSTag getTag() { >- if (getTagName().equals("HEAD")) return CVSTag.DEFAULT; >+ if (getTagName().equals("HEAD")) >+ return CVSTag.DEFAULT; > return new CVSTag(getTagName(), CVSTag.VERSION); > } >- >+ > public String getPassword() { > String value = (String) arguments.get(KEY_PASSWORD); > return value == null ? EMPTY_STRING : value; >@@ -218,11 +237,11 @@ > return id; > } > >- private String internalGetCVSModule() { >+ private String internalGetCVSModule() { > String module = (String) arguments.get(KEY_PATH); > return module == null ? id : module; > } >- >+ > public String getCVSModule() { > String value = (String) arguments.get(KEY_PATH); > return value == null ? EMPTY_STRING : value; >@@ -240,9 +259,10 @@ > public boolean isValid() { > return valid; > } >- >- public String getReferenceString() { >- if (!isValid()) return null; >+ >+ public String getReferenceString() { >+ if (!isValid()) >+ return null; > // This is the format used by the CVS IProjectSerializer > String projectName = new Path(internalGetCVSModule()).lastSegment(); > return "1.0," + getRepo() + "," + internalGetCVSModule() + "," + projectName + "," + getTagName(); >@@ -278,7 +298,7 @@ > } > result.append('='); > result.append("CVS"); >- for (Iterator iter = arguments.keys().iterator(); iter.hasNext(); ) { >+ for (Iterator iter = arguments.keys().iterator(); iter.hasNext();) { > String key = (String) iter.next(); > String value = (String) arguments.get(key); > if (value != null && value.length() > 0) >@@ -293,7 +313,7 @@ > public String getVersion() { > return version; > } >- >+ > public void setPassword(String password) { > arguments.put(KEY_PASSWORD, password); > } >@@ -321,7 +341,7 @@ > public void setValid(boolean valid) { > this.valid = valid; > } >- >+ > public String toString() { > return "Entry: " + getMapString(); > } >@@ -331,54 +351,8 @@ > */ > public boolean equals(Object obj) { > if (obj instanceof MapEntry) { >- return ((MapEntry)obj).getMapString().equals(getMapString()); >+ return ((MapEntry) obj).getMapString().equals(getMapString()); > } > return super.equals(obj); > } >- >- /** >- * Return true if this map entry is mapped to the given CVS module >- * @param moduleName >- */ >- public boolean isMappedTo(String moduleName) { >- IPath entryPath = new Path(internalGetCVSModule()); >- IPath modulePath = new Path(moduleName); >- if (entryPath.segmentCount() != modulePath.segmentCount()) return false; >- for (int i = 0; i < entryPath.segmentCount(); i++) { >- if (!entryPath.segment(i).equals(modulePath.segment(i))) { >- return false; >- } >- } >- return true; >- } >- >- /** >- * Return <code>true</code> if the entry is mapped to the given project >- * and <code>false</code> otherwise. >- */ >- public boolean isMappedTo(IProject project) { >- String moduleName; >- try { >- moduleName = getCVSModule(project); >- if (moduleName == null) return false; >- return isMappedTo(moduleName); >- } catch (CVSException e) { >- RelEngPlugin.getDefault().getLog().log(e.getStatus()); >- return false; >- } >- } >- >- /** >- * Get the remote CVS module for the project or <code>null</code> >- * if the project is not a CVS project. >- */ >- private String getCVSModule(IProject project) throws CVSException { >- ICVSFolder folder = CVSWorkspaceRoot.getCVSFolderFor(project); >- FolderSyncInfo info = folder.getFolderSyncInfo(); >- if (info == null) { >- return null; >- } >- return info.getRepository(); >- } >- > } >Index: src/org/eclipse/releng/tools/MapContentDocument.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.releng.tools/src/org/eclipse/releng/tools/MapContentDocument.java,v >retrieving revision 1.3 >diff -u -r1.3 MapContentDocument.java >--- src/org/eclipse/releng/tools/MapContentDocument.java 1 Dec 2005 21:16:42 -0000 1.3 >+++ src/org/eclipse/releng/tools/MapContentDocument.java 20 Feb 2007 22:56:47 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 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 >@@ -10,13 +10,7 @@ > *******************************************************************************/ > package org.eclipse.releng.tools; > >-import java.io.BufferedInputStream; >-import java.io.BufferedReader; >-import java.io.ByteArrayInputStream; >-import java.io.IOException; >-import java.io.InputStream; >-import java.io.InputStreamReader; >- >+import java.io.*; > import org.eclipse.compare.IStreamContentAccessor; > import org.eclipse.compare.ITypedElement; > import org.eclipse.core.resources.IProject; >@@ -25,14 +19,18 @@ > import org.eclipse.team.internal.ccvs.core.CVSException; > import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; > >- >-public class MapContentDocument implements ITypedElement, IStreamContentAccessor{ >+/* >+ * TODO Its a shame that we use Strings here and it isn't backed by real MapEntry objects >+ * but in order to do this we need to make changes outside of the MapEntryRegistry and then >+ * commit them once the user commits the map file changes to the file-system. >+ */ >+public class MapContentDocument implements ITypedElement, IStreamContentAccessor { > private MapFile mapFile; > private String oldContents = ""; > private String newContents = ""; > > public MapContentDocument(MapFile aMapFile) { >- mapFile = aMapFile; >+ mapFile = aMapFile; > initialize(); > } > >@@ -40,23 +38,21 @@ > * Update the tag associated with the given project in the new contents. > */ > public void updateTag(IProject project, String tag) throws CVSException { >- InputStream inputStream = new BufferedInputStream( >- new ByteArrayInputStream(newContents.getBytes())); >+ MapEntry realEntry = mapFile.getMapEntry(project); >+ if (realEntry == null) >+ return; >+ String mapString = realEntry.getMapString(); >+ InputStream inputStream = new BufferedInputStream(new ByteArrayInputStream(newContents.getBytes())); > boolean match = false; > StringBuffer buffer = new StringBuffer(); > try { >- BufferedReader aReader = new BufferedReader(new InputStreamReader( >- inputStream)); >+ BufferedReader aReader = new BufferedReader(new InputStreamReader(inputStream)); > String aLine = aReader.readLine(); > while (aLine != null) { > if (aLine.trim().length() != 0 && !aLine.startsWith("!")) { > // Found a possible match >- MapEntry entry = new MapEntry(aLine); >- if (!entry.isValid()) { >- throw new CVSException("Malformed map file line: " >- + aLine); >- } >- if (entry.isMappedTo(project)) { >+ MapEntry entry = MapEntry.parse(aLine, mapFile); >+ if (entry != null && mapString.equals(entry.getMapString())) { > // Now for sure we have a match. Replace the line. > entry.setTagName(tag); > aLine = entry.getMapString(); >@@ -69,8 +65,6 @@ > buffer.append(System.getProperty("line.separator")); //$NON-NLS-1$ > } > } >- } catch (CoreException e) { >- throw CVSException.wrapException(e); > } catch (IOException e) { > throw CVSException.wrapException(e); > } finally { >@@ -78,6 +72,7 @@ > try { > inputStream.close(); > } catch (IOException e) { >+ // ignore > } > } > } >@@ -85,9 +80,11 @@ > newContents = buffer.toString(); > } > } >+ > public boolean isChanged() { > return !(oldContents.equals(newContents)); > } >+ > /* > * (non-Javadoc) > * >@@ -96,6 +93,7 @@ > public String getName() { > return mapFile.getFile().getName(); > } >+ > /* > * (non-Javadoc) > * >@@ -104,6 +102,7 @@ > public Image getImage() { > return null; > } >+ > /* > * (non-Javadoc) > * >@@ -112,6 +111,7 @@ > public String getType() { > return mapFile.getFile().getFileExtension(); > } >+ > /* > * (non-Javadoc) > * >@@ -120,20 +120,21 @@ > public InputStream getContents() throws CoreException { > return new ByteArrayInputStream(getNewContent().getBytes()); > } >+ > public MapFile getMapFile() { > return mapFile; > } >- >+ > private String getNewContent() { > return newContents; > } >+ > private void initialize() { > InputStream inputStream; > StringBuffer buffer = new StringBuffer(); > try { > inputStream = mapFile.getFile().getContents(); >- BufferedReader aReader = new BufferedReader(new InputStreamReader( >- inputStream)); >+ BufferedReader aReader = new BufferedReader(new InputStreamReader(inputStream)); > String aLine = aReader.readLine(); > while (aLine != null) { > buffer.append(aLine); >Index: src/org/eclipse/releng/tools/MapFile.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.releng.tools/src/org/eclipse/releng/tools/MapFile.java,v >retrieving revision 1.4 >diff -u -r1.4 MapFile.java >--- src/org/eclipse/releng/tools/MapFile.java 7 Feb 2007 19:09:00 -0000 1.4 >+++ src/org/eclipse/releng/tools/MapFile.java 20 Feb 2007 22:56:47 -0000 >@@ -1,58 +1,69 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 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.releng.tools; > >-import java.io.BufferedReader; >-import java.io.IOException; >-import java.io.InputStream; >-import java.io.InputStreamReader; >+import java.io.*; > import java.util.*; >+import org.eclipse.core.resources.*; >+import org.eclipse.core.runtime.*; > >-import org.eclipse.core.resources.IFile; >-import org.eclipse.core.resources.IProject; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Status; >- >+/* >+ * This class represents a build submission map file in the workspace. >+ */ > public class MapFile { >- >+ > public static final String MAP_FILE_EXTENSION = "map"; >- >+ > protected IFile file; >- protected MapEntry[] entries; >- >- public MapFile(IFile aFile) throws CoreException { >- file = aFile; >+ // entries in the files...mixed Strings and MapEntry >+ protected List entries = new ArrayList(); >+ private MapProject project; >+ >+ /* >+ * Constructor for the class. Create a new map file on the given >+ * workspace file with the specified parent project. >+ */ >+ public MapFile(MapProject project, IFile aFile) throws CoreException { >+ this.project = project; >+ this.file = aFile; > loadEntries(); > } >- >- public IFile getFile(){ >+ >+ /* >+ * Return the workspace file associated with this map file. >+ */ >+ public IFile getFile() { > return file; > } >- >+ >+ /* >+ * Return this map file's parent project. >+ */ >+ public MapProject getProject() { >+ return project; >+ } >+ >+ /* >+ * Load this map file's contents. Populate the entry list. >+ */ > protected void loadEntries() throws CoreException { > InputStream inputStream = null; >- List list = new ArrayList(); >- > try { > inputStream = file.getContents(); >- BufferedReader aReader = new BufferedReader(new InputStreamReader( >- inputStream)); >- String aLine = aReader.readLine(); >- while (aLine != null) { >- if (isMapLine(aLine)) { >- list.add(new MapEntry(aLine)); >- } >- aLine = aReader.readLine(); >+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); >+ String lline = reader.readLine(); >+ while (lline != null) { >+ MapEntry entry = MapEntry.parse(lline, this); >+ entries.add(entry == null ? (Object) lline : entry); >+ lline = reader.readLine(); > } > } catch (IOException e) { > throw new CoreException(new Status(IStatus.ERROR, RelEngPlugin.ID, 0, "An I/O Error occurred process map file " + file.getFullPath().toString(), e)); >@@ -65,53 +76,91 @@ > } > } > } >- >- this.entries = (MapEntry[]) list.toArray(new MapEntry[list.size()]); >- } >- >- private boolean isMapLine(String line) { >- if (line.trim().length() == 0) return false; >- if (line.startsWith("!")) return false; >- return true; >- } >- >- public boolean contains(IProject project){ >- for(int j = 0;j < entries.length; j++){ >- if (entries[j].isMappedTo(project)){ >- return true; >- } >- } >- return false; >- } >- >- public MapEntry getMapEntry(IProject project) { >- for(int j = 0;j < entries.length; j++){ >- if (entries[j].isMappedTo(project)){ >- return entries[j]; >- } >- } >- return null; > } > >+ /* >+ * Return a boolean value indicating whether or not this map file >+ * contains a valid map file entry for the given project. >+ */ >+ public boolean contains(IProject workspaceProject) { >+ return getMapEntry(workspaceProject) != null; >+ } >+ >+ /* >+ * Return the map entry for the given project, or null >+ * if there isn't a match. Note that it only returns an entry >+ * if it is a member of this map file. Clients wishing to find >+ * any entry on any file should call the same method on MapProject. >+ */ >+ public MapEntry getMapEntry(IProject workspaceProject) { >+ MapEntry entry = project.getMapEntry(workspaceProject); >+ return entry == null || !entry.getFile().equals(this) ? null : entry; >+ } >+ >+ /* >+ * Return an array of accessible workspace projects for this map file. >+ */ > public IProject[] getAccessibleProjects() { > Set list = new HashSet(); > IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); >- if(entries == null || entries.length ==0) return null; >+ if (entries == null || entries.size() == 0) >+ return null; > for (int i = 0; i < projects.length; i++) { >- IProject project = projects[i]; >- if (project.isAccessible()) { >- for (int j = 0; j < entries.length; j++){ >- if (entries[j].isMappedTo(project)) { >- list.add(project); >- } >- } >+ IProject workspaceProject = projects[i]; >+ if (workspaceProject.isAccessible()) { >+ MapEntry entry = getMapEntry(workspaceProject); >+ if (entry != null) >+ list.add(workspaceProject); > } > } >- return (IProject[])list.toArray(new IProject[list.size()]); >+ return (IProject[]) list.toArray(new IProject[list.size()]); > } > >+ /* (non-Javadoc) >+ * @see java.lang.Object#equals(java.lang.Object) >+ */ >+ public boolean equals(Object obj) { >+ if (!(obj instanceof MapFile)) >+ return false; >+ return getFile().equals(((MapFile) obj).getFile()); >+ } >+ >+ /* (non-Javadoc) >+ * @see java.lang.Object#hashCode() >+ */ >+ public int hashCode() { >+ return file.hashCode(); >+ } >+ >+ /* >+ * Return the simple name of this map file's workspace file. >+ */ > public String getName() { > return file.getName(); > } > >+ /* >+ * Return the list of entries for this map file. The resulting list >+ * may contain both String and MapEntry entries. >+ */ >+ public List getEntries() { >+ return entries; >+ } >+ >+ /* >+ * Return a string representation of this map file. >+ */ >+ public String getContents() { >+ StringBuffer buffer = new StringBuffer(); >+ for (Iterator iter = entries.iterator(); iter.hasNext();) { >+ Object obj = iter.next(); >+ if (obj instanceof String) >+ buffer.append(obj); >+ else >+ buffer.append(((MapEntry) obj).getMapString()); >+ if (iter.hasNext()) >+ buffer.append(System.getProperty("line.separator")); //$NON-NLS-1$ >+ } >+ return buffer.toString(); >+ } > } >Index: src/org/eclipse/releng/tools/RelEngPlugin.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.releng.tools/src/org/eclipse/releng/tools/RelEngPlugin.java,v >retrieving revision 1.5 >diff -u -r1.5 RelEngPlugin.java >--- src/org/eclipse/releng/tools/RelEngPlugin.java 1 Dec 2005 21:16:42 -0000 1.5 >+++ src/org/eclipse/releng/tools/RelEngPlugin.java 20 Feb 2007 22:56:47 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 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 >@@ -8,17 +8,12 @@ > * Contributors: > * IBM Corporation - initial API and implementation > *******************************************************************************/ >- > package org.eclipse.releng.tools; > >-import java.util.MissingResourceException; >-import java.util.ResourceBundle; >- >+import java.util.*; > import org.eclipse.core.resources.IWorkspace; > import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.*; > import org.eclipse.ui.plugin.AbstractUIPlugin; > > /** >@@ -36,6 +31,7 @@ > private static RelEngPlugin plugin; > //Resource bundle. > private ResourceBundle resourceBundle; >+ private static Set fetchCommands; > > /** > * The constructor. >@@ -121,7 +117,32 @@ > } > return plugin; > } >- >+ >+ /* >+ * Return true if the given string is a valid fetch command >+ * and false otherwise. CVS and GET come with Eclipse by default. >+ */ >+ public static boolean isValidFetchCommand(String command) { >+ if (fetchCommands == null) { >+ IExtensionPoint extpt = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.pde.build.fetchFactories"); >+ if (extpt == null) >+ return false; >+ fetchCommands = new HashSet(); >+ IExtension[] extensions = extpt.getExtensions(); >+ for (int i=0; i<extensions.length; i++) { >+ IExtension ext = extensions[i]; >+ IConfigurationElement[] configs = ext.getConfigurationElements(); >+ for (int j=0; j<configs.length; j++) { >+ IConfigurationElement config = configs[j]; >+ String id = config.getAttribute("id"); >+ if (id != null) >+ fetchCommands.add(id); >+ } >+ } >+ } >+ return fetchCommands.contains(command); >+ } >+ > /** > * The following code is a sample of how to assign a > * RelEng nature to a project. This only ever needed >Index: src/org/eclipse/releng/tools/LoadMap.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.releng.tools/src/org/eclipse/releng/tools/LoadMap.java,v >retrieving revision 1.7 >diff -u -r1.7 LoadMap.java >--- src/org/eclipse/releng/tools/LoadMap.java 21 Jun 2006 19:11:25 -0000 1.7 >+++ src/org/eclipse/releng/tools/LoadMap.java 20 Feb 2007 22:56:47 -0000 >@@ -1,10 +1,10 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 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 > *******************************************************************************/ >@@ -69,12 +69,12 @@ > List allStrings = new ArrayList(); > for (int i = 0; i < mapFiles.length; i++) { > IResource resource = mapFiles[i]; >- String[] referenceStrings = readReferenceStrings((IFile)resource); >+ String[] referenceStrings = readReferenceStrings((IFile) resource); > allStrings.addAll(Arrays.asList(referenceStrings)); > } > return (String[]) allStrings.toArray(new String[allStrings.size()]); > } >- >+ > /** > * Method readReferenceStrings. > * @param file >@@ -88,10 +88,9 @@ > String line = reader.readLine(); > List references = new ArrayList(); > while (line != null) { >- String referenceString = new MapEntry(line).getReferenceString(); >- if (referenceString != null) { >- references.add(referenceString); >- } >+ MapEntry entry = MapEntry.parse(line, null); >+ if (entry != null && entry.getReferenceString() != null) >+ references.add(entry.getReferenceString()); > line = reader.readLine(); > } > return (String[]) references.toArray(new String[references.size()]); >@@ -103,17 +102,19 @@ > } > } > >- > /** > * @see org.eclipse.team.internal.ui.actions.TeamAction#isEnabled() > */ > public boolean isEnabled() { > IResource[] resources = getSelectedResources(); >- if (resources.length == 0) return false; >+ if (resources.length == 0) >+ return false; > for (int i = 0; i < resources.length; i++) { > IResource resource = resources[i]; >- if (resource.getType() != IResource.FILE) return false; >- if (!resource.getFileExtension().equals("map")) return false; >+ if (resource.getType() != IResource.FILE) >+ return false; >+ if (!resource.getFileExtension().equals("map")) >+ return false; > } > return true; > } >Index: src/org/eclipse/releng/tools/MapProject.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.releng.tools/src/org/eclipse/releng/tools/MapProject.java,v >retrieving revision 1.7 >diff -u -r1.7 MapProject.java >--- src/org/eclipse/releng/tools/MapProject.java 24 Aug 2006 15:24:33 -0000 1.7 >+++ src/org/eclipse/releng/tools/MapProject.java 20 Feb 2007 22:56:47 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 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 >@@ -9,9 +9,9 @@ > * IBM Corporation - initial API and implementation > *******************************************************************************/ > package org.eclipse.releng.tools; >+ > import java.lang.reflect.InvocationTargetException; > import java.util.*; >- > import org.eclipse.core.resources.*; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >@@ -21,20 +21,25 @@ > import org.eclipse.team.internal.ccvs.ui.operations.CommitOperation; > import org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation; > >+/* >+ * This class represents a workspace project which contains map files. >+ */ > public class MapProject implements IResourceChangeListener { >- >+ > private static MapProject mapProject = null; > private IProject project; > private MapFile[] mapFiles; >- >+ private MapEntryRegistry registry; >+ > /** >- * Return the default map project (org.eclipse.releng) or >+ * Return the default map project (<em>org.eclipse.releng</em>) or > * <code>null</code> if the project does not exist or there > * is an error processing it. If there is an error, it > * will be logged. >- * @return the default map project >+ * >+ * @return the default map project or <code>null</code> > */ >- public static MapProject getDefaultMapProject(){ >+ public static MapProject getDefaultMapProject() { > if (mapProject == null) { > IProject project = getProjectFromWorkspace(); > try { >@@ -43,10 +48,12 @@ > RelEngPlugin.log(e); > } > } >- > return mapProject; > } >- >+ >+ /* >+ * Return the workspace project for the org.eclipse.releng project. >+ */ > private static IProject getProjectFromWorkspace() { > IWorkspace workspace = ResourcesPlugin.getWorkspace(); > IWorkspaceRoot root = workspace.getRoot(); >@@ -54,148 +61,176 @@ > return project; > } > >+ /* >+ * Create a new map project based on the given workspace project. >+ */ > public MapProject(IProject p) throws CoreException { > this.project = p; > ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); > loadMapFiles(); >+ this.registry = new MapEntryRegistry(); >+ this.registry.add(this); >+ } >+ >+ public MapEntryRegistry getRegistry() { >+ return registry; > } > >+ /* >+ * Return the workspace project represented by this map project. >+ */ > public IProject getProject() { > return project; > } >- >- public void setProject(IProject p){ >- this.project = p; >- } >- >- private MapFile getMapFile(IProject p){ >- for (int i = 0; i< mapFiles.length; i++){ >- if (mapFiles[i].contains(p)) { >- return mapFiles[i]; >- } >- } >- return null; >+ >+ /* >+ * Return the map file which contains the entry for this project. >+ */ >+ private MapFile getMapFile(IProject p) { >+ MapEntry entry = getMapEntry(p); >+ return entry == null ? null : entry.getFile(); > } >- >- /** >- * Return the MapEntry for the given project >- * @param string >- * @param string1 >+ >+ /* >+ * Return the MapEntry for the given project. Do a lookup in the registry. > */ > public MapEntry getMapEntry(IProject p) { >- MapFile file = getMapFile(p); >- if (file != null) { >- return file.getMapEntry(p); >- } >- return null; >+ return registry.get(p); > } > >+ /* >+ * Return a boolean value indicating whether or not the map files >+ * have been loaded for this project. In our case this is always true >+ * as long as the corresponding workspace project is accessible. >+ * >+ */ > public boolean mapsAreLoaded() { >- return project.exists(); >+ return project.isAccessible(); > } >- >- public MapFile[] getValidMapFiles(){ >+ >+ /* >+ * Return an array of the valid map files in this project. >+ */ >+ public MapFile[] getValidMapFiles() { > List list = new ArrayList(); >- for (int i = 0; i <mapFiles.length; i++){ >- IProject[] projects = mapFiles[i].getAccessibleProjects(); >- if( projects!= null && projects.length > 0){ >+ for (int i = 0; i < mapFiles.length; i++) { >+ IProject[] projects = mapFiles[i].getAccessibleProjects(); >+ if (projects != null && projects.length > 0) { > list.add(mapFiles[i]); > } > } >- return (MapFile[])list.toArray(new MapFile[list.size()]); >+ return (MapFile[]) list.toArray(new MapFile[list.size()]); >+ } >+ >+ public MapFile[] getMapFiles() { >+ return mapFiles; > } >- >+ > /** >+ * Update the map file entry for the given workspace project, with the specified tag. >+ * > * @param aProject The map entry of the specified project will be changed to the specified tag > * @param tag The specified tag >- * @return returns if no map file having such a map entry is found > */ > public void updateFile(IProject aProject, String tag) throws CoreException { > MapFile aFile = getMapFile(aProject); >- if (aFile == null)return; >+ if (aFile == null) >+ return; > MapContentDocument changed = new MapContentDocument(aFile); > changed.updateTag(aProject, tag); > if (changed.isChanged()) { >- aFile.getFile().setContents(changed.getContents(), IFile.KEEP_HISTORY, null); >+ aFile.getFile().setContents(changed.getContents(), IResource.KEEP_HISTORY, null); > } > } >- >- public void commitMapProject(String comment, IProgressMonitor monitor) throws CoreException{ >+ >+ /* >+ * Commit our changes to CVS. >+ */ >+ public void commitMapProject(String comment, IProgressMonitor monitor) throws CoreException { > try { >- new CommitOperation(null, RepositoryProviderOperation.asResourceMappers(new IResource[] { project }), new Command.LocalOption[0], comment).run(monitor); >+ new CommitOperation(null, RepositoryProviderOperation.asResourceMappers(new IResource[] {project}), new Command.LocalOption[0], comment).run(monitor); > } catch (InvocationTargetException e) { > throw TeamException.asTeamException(e); > } catch (InterruptedException e) { > // Ignore; > } > } >- >- public MapFile[] getMapFilesFor(IProject[] projects){ >- Set alist = new HashSet(); >- for(int i = 0; i<projects.length; i++){ >+ >+ /* >+ * Return an array with the map files for the given projects. >+ */ >+ public MapFile[] getMapFilesFor(IProject[] projects) { >+ Set alist = new HashSet(); >+ for (int i = 0; i < projects.length; i++) { > MapFile aMapFile = getMapFile(projects[i]); > alist.add(aMapFile); > } >- return (MapFile[])alist.toArray(new MapFile[alist.size()]); >+ return (MapFile[]) alist.toArray(new MapFile[alist.size()]); > } > > /** > * Get the tags for the given projects. If no tag is found > * for whatever reason, HEAD is used. >+ * > * @param projects >- * @return > */ >- public CVSTag[] getTagsFor(IProject[] projects){ >- if(projects == null || projects.length == 0)return null; >+ public CVSTag[] getTagsFor(IProject[] projects) { >+ if (projects == null || projects.length == 0) >+ return null; > CVSTag[] tags = new CVSTag[projects.length]; >- for (int i = 0; i < tags.length; i++){ >+ for (int i = 0; i < tags.length; i++) { > MapEntry entry = getMapEntry(projects[i]); >- if (entry == null) tags[i] = CVSTag.DEFAULT; >- else tags[i] = entry.getTag(); >+ if (entry == null) >+ tags[i] = CVSTag.DEFAULT; >+ else >+ tags[i] = entry.getTag(); > } > return tags; > } >+ > /** >- * Deregister the IResourceChangeListner. It is reserved for use in the future. It is never called >- * for now >+ * Unregister the IResourceChangeListner. It is reserved for use in the future. It is never called >+ * for now. > */ >- public void dispose(){ >+ public void dispose() { > ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); > } >- >+ > /** > * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent) > */ > public void resourceChanged(IResourceChangeEvent event) { > IResourceDelta root = event.getDelta(); >- >+ > //TODO: Need to add code to handle map project deletion, addition and rename > IResourceDelta folderDelta = root.findMember(getMapFolder().getFullPath()); >- if (folderDelta == null) return; >- >+ if (folderDelta == null) >+ return; >+ > //Handle map files deletion, addition and rename > IResourceDelta[] deltas = folderDelta.getAffectedChildren(); >- if(deltas == null || deltas.length == 0) return; >+ if (deltas == null || deltas.length == 0) >+ return; > for (int i = 0; i < deltas.length; i++) { > IResourceDelta delta = deltas[i]; >- if(delta.getResource().getType() == IResource.FILE){ >- try{ >- IFile aFile = (IFile)(delta.getResource()); >+ if (delta.getResource().getType() == IResource.FILE) { >+ try { >+ IFile aFile = (IFile) (delta.getResource()); > MapFile mFile = null; >- if(isMapFile(aFile)){ >+ if (isMapFile(aFile)) { > // Handle content change >- if(delta.getKind() == IResourceDelta.CHANGED){ >+ if (delta.getKind() == IResourceDelta.CHANGED) { > mFile = getMapFileFor(aFile); >- mFile.loadEntries(); >+ mFile.loadEntries(); > } > //Handle deletion. We cannot simply remove the map file directly bacause we have to call > //getMapFileFor(IFile) in order to do so. But the IFile is already deleted. So we have to > //reconstuct the map files. >- if(delta.getKind() == IResourceDelta.REMOVED ){ >+ if (delta.getKind() == IResourceDelta.REMOVED) { > loadMapFiles(); > } > // Handle addition >- if(delta.getKind() == IResourceDelta.ADDED ){ >+ if (delta.getKind() == IResourceDelta.ADDED) { > mFile = getMapFileFor(aFile); > addMapFile(mFile); > } >@@ -207,12 +242,13 @@ > } > } > >- private IFolder getMapFolder(){ >+ private IFolder getMapFolder() { > return getProject().getFolder(RelEngPlugin.MAP_FOLDER); > } >+ > private void loadMapFiles() throws CoreException { > IFolder folder = project.getFolder(RelEngPlugin.MAP_FOLDER); >- if(!folder.exists()) { >+ if (!folder.exists()) { > mapFiles = new MapFile[0]; > return; > } >@@ -221,34 +257,39 @@ > List list = new ArrayList(); > for (int i = 0; i < resource.length; i++) { > //In case there are some sub folders >- if(resource[i].getType() == IResource.FILE){ >+ if (resource[i].getType() == IResource.FILE) { > IFile file = (IFile) resource[i]; >- if(isMapFile(file)){ >- list.add(new MapFile(file)); >+ if (isMapFile(file)) { >+ list.add(new MapFile(this, file)); > } > } > } >- mapFiles = (MapFile[])list.toArray(new MapFile[list.size()]); >+ mapFiles = (MapFile[]) list.toArray(new MapFile[list.size()]); > } else { > mapFiles = new MapFile[0]; > } > } >- >- private MapFile getMapFileFor(IFile file) throws CoreException{ >- for(int i = 0; i < mapFiles.length; i++){ >+ >+ private MapFile getMapFileFor(IFile file) throws CoreException { >+ for (int i = 0; i < mapFiles.length; i++) { > if (mapFiles[i].getFile().equals(file)) > return mapFiles[i]; > } >- return new MapFile(file); >+ return new MapFile(this, file); > } >- private void addMapFile(MapFile aFile){ >+ >+ private void addMapFile(MapFile aFile) { > Set set = new HashSet(Arrays.asList(mapFiles)); > set.add(aFile); >- mapFiles = (MapFile[])set.toArray(new MapFile[set.size()]); >+ mapFiles = (MapFile[]) set.toArray(new MapFile[set.size()]); > } >- private boolean isMapFile(IFile aFile){ >- String extension = aFile.getFileExtension(); >- //In case file has no extension name or is not validate map file >- return ( extension != null && extension.equals(MapFile.MAP_FILE_EXTENSION)); >+ >+ /* >+ * Return a boolean value indicating whether or not the given >+ * file is a valid map file. >+ */ >+ private boolean isMapFile(IFile file) { >+ // for now just validate based on file extension >+ return MapFile.MAP_FILE_EXTENSION.equals(file.getFileExtension()); > } > } >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.releng.tools/META-INF/MANIFEST.MF,v >retrieving revision 1.4 >diff -u -r1.4 MANIFEST.MF >--- META-INF/MANIFEST.MF 14 Sep 2006 13:19:33 -0000 1.4 >+++ META-INF/MANIFEST.MF 20 Feb 2007 22:56:47 -0000 >@@ -3,7 +3,6 @@ > Bundle-Name: RelEng Plug-in > Bundle-SymbolicName: org.eclipse.releng.tools; singleton:=true > Bundle-Version: 3.3.0.qualifier >-Bundle-ClassPath: tools.jar > Bundle-Activator: org.eclipse.releng.tools.RelEngPlugin > Bundle-Vendor: Eclipse.org > Bundle-Localization: plugin >Index: build.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.releng.tools/build.properties,v >retrieving revision 1.5 >diff -u -r1.5 build.properties >--- build.properties 1 Dec 2005 21:16:42 -0000 1.5 >+++ build.properties 20 Feb 2007 22:56:47 -0000 >@@ -1,5 +1,5 @@ > ############################################################################### >-# Copyright (c) 2000, 2005 IBM Corporation and others. >+# Copyright (c) 2000, 2007 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 >@@ -8,10 +8,12 @@ > # Contributors: > # IBM Corporation - initial API and implementation > ############################################################################### >-source.tools.jar = src/ >+source..=src/ > bin.includes = plugin.xml,\ >- *.jar,\ >+ .,\ > about.html,\ > icons/,\ > plugin.properties,\ > META-INF/ >+output.. = bin/ >+src.includes=about.html >\ No newline at end of file >Index: src/org/eclipse/releng/tools/MapEntryRegistry.java >=================================================================== >RCS file: src/org/eclipse/releng/tools/MapEntryRegistry.java >diff -N src/org/eclipse/releng/tools/MapEntryRegistry.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/releng/tools/MapEntryRegistry.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,223 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 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.releng.tools; >+ >+import java.io.IOException; >+import java.util.*; >+import org.eclipse.core.resources.*; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.osgi.util.ManifestElement; >+import org.osgi.framework.*; >+ >+/* >+ * This class represents a registry of map entries from a map file. Clients are >+ * able to do look-ups based on workspace projects and get back the map entry >+ * that corresponds to their project. >+ */ >+public class MapEntryRegistry { >+ >+ // the registry >+ private Map registry = new HashMap(); >+ >+ /* >+ * Internal class which represents a key in the registry. >+ */ >+ static class Key { >+ IProject project; >+ Version version; >+ >+ /* >+ * Constructor for the class. The project must be valid >+ * but the version can be null. >+ */ >+ public Key(IProject project, Version version) { >+ super(); >+ if (project == null) >+ throw new IllegalArgumentException("Project cannot be null."); >+ this.project = project; >+ this.version = version; >+ } >+ >+ /* (non-Javadoc) >+ * @see java.lang.Object#equals(java.lang.Object) >+ */ >+ public boolean equals(Object obj) { >+ if (!(obj instanceof Key)) >+ return false; >+ Key other = (Key) obj; >+ if (!project.equals(other.project)) >+ return false; >+ if (version == null) >+ return other.version == null; >+ return version.equals(other.version); >+ } >+ >+ /* (non-Javadoc) >+ * @see java.lang.Object#hashCode() >+ */ >+ public int hashCode() { >+ return project.hashCode() + (version == null ? 0 : version.hashCode()); >+ } >+ >+ } >+ >+ /* >+ * Store the given project and version pair in this registry with its map file entry. >+ */ >+ private void put(IProject project, Version version, MapEntry entry) { >+ registry.put(new Key(project, version), entry); >+ } >+ >+ /* >+ * Add the contents of the given map file to this registry. >+ */ >+ public void add(MapProject mapProject) { >+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); >+ MapFile[] files = mapProject.getMapFiles(); >+ for (int i = 0; i < files.length; i++) { >+ MapFile file = files[i]; >+ List entries = file.getEntries(); >+ for (Iterator iter = entries.iterator(); iter.hasNext();) { >+ Object obj = iter.next(); >+ if (!(obj instanceof MapEntry)) >+ continue; >+ MapEntry entry = (MapEntry) obj; >+ String id = entry.getId(); >+ IProject project = root.getProject(id); >+ if (!project.isAccessible()) >+ continue; >+ String versionString = entry.getVersion(); >+ Version version = versionString == null ? null : new Version(versionString); >+ put(project, version, entry); >+ } >+ } >+ } >+ >+ /* >+ * Return the map file entry for the given map file line. Return null >+ * if there is no match. >+ */ >+ public MapEntry get(String line) { >+ for (Iterator iter = registry.entrySet().iterator(); iter.hasNext();) { >+ MapEntry entry = (MapEntry) iter.next(); >+ if (entry.getMapString().equals(MapEntry.parse(line, null).getMapString())) >+ return entry; >+ } >+ return null; >+ } >+ >+ /* >+ * Return the map file entry for the given workspace project. >+ */ >+ public MapEntry get(IProject project) { >+ MapEntry[] entries = getAll(project); >+ if (entries == null || entries.length == 0) >+ return null; >+ if (entries.length == 1) >+ return entries[0]; >+ >+ // get the version from the project >+ Version projectVersion = getVersion(project); >+ if (projectVersion == null) >+ return null; >+ // check for an exact match, also keep track if we have a null version entry >+ MapEntry nullEntry = null; >+ for (int i = 0; i < entries.length; i++) { >+ Version entryVersion = entries[i].getVersion() == null ? null : new Version(entries[i].getVersion()); >+ // we have an exact match >+ if (projectVersion.equals(entryVersion)) >+ return entries[i]; >+ if (entryVersion == null) >+ nullEntry = entries[i]; >+ } >+ // we didn't have an exact match but there was an entry in the file >+ // with a null version so return it >+ if (nullEntry != null) >+ return nullEntry; >+ // otherwise try and guess the best version >+ return bestMatch(projectVersion, entries); >+ } >+ >+ /* >+ * Try and determine the version of the given project by looking >+ * in its manifest file. >+ */ >+ private Version getVersion(IProject project) { >+ // sort and pick the best based on version >+ // get the version from the project >+ IFile manifest = project.getFile(new Path("META-INF/MANIFEST.MF")); >+ // we can't find the manifest file so we can't determine the version in the workspace >+ // TODO we could try and parse the plugin.xml if one exists >+ if (!manifest.exists()) >+ return null; >+ String versionString = null; >+ try { >+ Map map = ManifestElement.parseBundleManifest(manifest.getContents(), null); >+ versionString = (String) map.get(Constants.BUNDLE_VERSION); >+ } catch (IOException e) { >+ e.printStackTrace(); >+ return null; >+ } catch (BundleException e) { >+ e.printStackTrace(); >+ return null; >+ } catch (CoreException e) { >+ e.printStackTrace(); >+ return null; >+ } >+ if (versionString == null) >+ return null; >+ Version projectVersion = new Version(versionString); >+ // TODO for now we strip off the qualifier >+ return new Version(projectVersion.getMajor(), projectVersion.getMinor(), projectVersion.getMicro(), null); >+ } >+ >+ /* >+ * Return the best map file entry match for the given version. >+ */ >+ private MapEntry bestMatch(Version version, MapEntry[] entries) { >+ MapEntry result = null; >+ Version resultVersion = null; >+ for (int i = 0; i < entries.length; i++) { >+ MapEntry entry = entries[i]; >+ String versionString = entry.getVersion(); >+ if (versionString == null) >+ return entry; >+ Version entryVersion = new Version(versionString); >+ // we require at least... >+ int comparison = entryVersion.compareTo(version); >+ if (comparison < 0) >+ continue; >+ // we should have already handled the equals case but >+ // in case we didn't... >+ if (comparison == 0) >+ return entry; >+ // grab the latest version >+ if (result == null || entryVersion.compareTo(resultVersion) > 0) { >+ result = entry; >+ resultVersion = entryVersion; >+ continue; >+ } >+ } >+ return result; >+ } >+ >+ /* >+ * Return all of the map file entries registered for the given project. >+ */ >+ private MapEntry[] getAll(IProject project) { >+ List result = new ArrayList(); >+ for (Iterator iter = registry.keySet().iterator(); iter.hasNext();) { >+ Key key = (Key) iter.next(); >+ if (key.project.equals(project)) >+ result.add(registry.get(key)); >+ } >+ return (MapEntry[]) result.toArray(new MapEntry[result.size()]); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 173314
:
59426
|
59427
|
60567
|
60569
|
63633
|
63634