1 11 package org.eclipse.team.internal.core; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 import java.util.*; 16 import java.util.ArrayList ; 17 import java.util.List ; 18 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.core.runtime.content.IContentDescription; 21 import org.eclipse.core.runtime.content.IContentTypeManager; 22 import org.eclipse.team.core.*; 23 import org.osgi.framework.BundleContext; 24 25 35 final public class TeamPlugin extends Plugin { 36 37 public static final String ID = "org.eclipse.team.core"; 40 public static final String PROVIDER_EXTENSION = "repository-provider-type"; 43 public static final String FILE_TYPES_EXTENSION = "fileTypes"; 46 public static final String IGNORE_EXTENSION = "ignore"; public static final String PROJECT_SET_EXTENSION = "projectSets"; public static final String REPOSITORY_EXTENSION = "repository"; public static final String DEFAULT_FILE_MODIFICATION_VALIDATOR_EXTENSION = "defaultFileModificationValidator"; 55 public final static QualifiedName PROVIDER_PROP_KEY = 57 new QualifiedName("org.eclipse.team.core", "repository"); 59 private static TeamPlugin plugin; 61 62 65 public TeamPlugin() { 66 super(); 67 plugin = this; 68 } 69 70 73 public void start(BundleContext context) throws Exception { 74 super.start(context); 75 Team.startup(); 76 } 77 78 81 public void stop(BundleContext context) throws Exception { 82 try { 83 Team.shutdown(); 84 ResourceVariantCache.shutdown(); 85 } finally { 86 super.stop(context); 87 } 88 } 89 90 95 public static TeamPlugin getPlugin() { 96 return plugin; 97 } 98 99 102 public static void log(int severity, String message, Throwable e) { 103 plugin.getLog().log(new Status(severity, ID, 0, message, e)); 104 } 105 106 110 public static void log(CoreException e) { 111 log(e.getStatus().getSeverity(), e.getMessage(), e); 112 } 113 114 117 public static TeamException wrapException(CoreException e) { 118 IStatus status = e.getStatus(); 119 return new TeamException(new Status(status.getSeverity(), ID, status.getCode(), status.getMessage(), e)); 120 } 121 122 public static String getCharset(String name, InputStream stream) throws IOException { 123 IContentDescription description = getContentDescription(name, stream); 124 return description == null ? null : description.getCharset(); 125 126 } 127 public static IContentDescription getContentDescription(String name, InputStream stream) throws IOException { 128 IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); 130 try { 131 return contentTypeManager.getDescriptionFor(stream, name, IContentDescription.ALL); 132 } finally { 133 if (stream != null) 134 try { 135 stream.close(); 136 } catch (IOException e) { 137 } 139 } 140 } 141 142 public static RepositoryProviderType getAliasType(String id) { 143 IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(TeamPlugin.ID, TeamPlugin.REPOSITORY_EXTENSION); 144 if (extension != null) { 145 IExtension[] extensions = extension.getExtensions(); 146 for (int i = 0; i < extensions.length; i++) { 147 IConfigurationElement [] configElements = extensions[i].getConfigurationElements(); 148 for (int j = 0; j < configElements.length; j++) { 149 String aliasId = configElements[j].getAttribute("canImportId"); if (aliasId != null && aliasId.equals(id)) { 151 String extensionId = configElements[j].getAttribute("id"); if (extensionId != null) { 153 return RepositoryProviderType.getProviderType(extensionId); 154 } 155 } 156 } 157 } 158 } 159 return null; 160 } 161 162 public static IPath[] getMetaFilePaths(String id) { 163 IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(TeamPlugin.ID, TeamPlugin.REPOSITORY_EXTENSION); 164 if (extension != null) { 165 IExtension[] extensions = extension.getExtensions(); 166 for (int i = 0; i < extensions.length; i++) { 167 IConfigurationElement [] configElements = extensions[i].getConfigurationElements(); 168 for (int j = 0; j < configElements.length; j++) { 169 String extensionId = configElements[j].getAttribute("id"); String metaFilePaths = configElements[j].getAttribute("metaFilePaths"); if (extensionId != null && extensionId.equals(id) && metaFilePaths != null) { 172 return getPaths(metaFilePaths); 173 174 } 175 } 176 } 177 } 178 return null; 179 } 180 181 private static IPath[] getPaths(String metaFilePaths) { 182 List result = new ArrayList (); 183 StringTokenizer t = new StringTokenizer(metaFilePaths, ","); while (t.hasMoreTokens()) { 185 String next = t.nextToken(); 186 IPath path = new Path(null, next); 187 result.add(path); 188 } 189 return (IPath[]) result.toArray(new IPath[result.size()]); 190 } 191 192 } 193 | Popular Tags |