KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > TeamPlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.core;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.util.*;
16 import java.util.ArrayList JavaDoc;
17 import java.util.List JavaDoc;
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 /**
26  * <code>TeamPlugin</code> is the plug-in runtime class for the Team
27  * resource management plugin.
28  * <p>
29  *
30  * @see Team
31  * @see RepositoryProvider
32  *
33  * @since 2.0
34  */

35 final public class TeamPlugin extends Plugin {
36
37     // The id of the core team plug-in
38
public static final String JavaDoc ID = "org.eclipse.team.core"; //$NON-NLS-1$
39

40     // The id of the providers extension point
41
public static final String JavaDoc PROVIDER_EXTENSION = "repository-provider-type"; //$NON-NLS-1$
42

43     // The id of the file types extension point
44
public static final String JavaDoc FILE_TYPES_EXTENSION = "fileTypes"; //$NON-NLS-1$
45

46     // The id of the global ignore extension point
47
public static final String JavaDoc IGNORE_EXTENSION = "ignore"; //$NON-NLS-1$
48
// The id of the project set extension point
49
public static final String JavaDoc PROJECT_SET_EXTENSION = "projectSets"; //$NON-NLS-1$
50
// The id of the repository extension point
51
public static final String JavaDoc REPOSITORY_EXTENSION = "repository"; //$NON-NLS-1$
52
// The id of the default file modification vaidator extension point
53
public static final String JavaDoc DEFAULT_FILE_MODIFICATION_VALIDATOR_EXTENSION = "defaultFileModificationValidator"; //$NON-NLS-1$
54

55     // The id used to associate a provider with a project
56
public final static QualifiedName PROVIDER_PROP_KEY =
57         new QualifiedName("org.eclipse.team.core", "repository"); //$NON-NLS-1$ //$NON-NLS-2$
58

59     // The one and only plug-in instance
60
private static TeamPlugin plugin;
61
62     /**
63      * Constructs a plug-in runtime class.
64      */

65     public TeamPlugin() {
66         super();
67         plugin = this;
68     }
69     
70     /**
71      * @see Plugin#start(BundleContext)
72      */

73     public void start(BundleContext context) throws Exception JavaDoc {
74         super.start(context);
75         Team.startup();
76     }
77     
78     /**
79      * @see Plugin#stop(BundleContext)
80      */

81     public void stop(BundleContext context) throws Exception JavaDoc {
82         try {
83             Team.shutdown();
84             ResourceVariantCache.shutdown();
85         } finally {
86             super.stop(context);
87         }
88     }
89     
90     /**
91      * Returns the Team plug-in.
92      *
93      * @return the single instance of this plug-in runtime class
94      */

95     public static TeamPlugin getPlugin() {
96         return plugin;
97     }
98     
99     /**
100      * Log the given exception alloing with the provided message and severity indicator
101      */

102     public static void log(int severity, String JavaDoc message, Throwable JavaDoc e) {
103         plugin.getLog().log(new Status(severity, ID, 0, message, e));
104     }
105     
106     /**
107      * Log the given CoreException in a manner that will include the stacktrace of
108      * the exception in the log.
109      */

110     public static void log(CoreException e) {
111         log(e.getStatus().getSeverity(), e.getMessage(), e);
112     }
113     
114     /*
115      * Static helper methods for creating exceptions
116      */

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 JavaDoc getCharset(String JavaDoc name, InputStream JavaDoc stream) throws IOException JavaDoc {
123         IContentDescription description = getContentDescription(name, stream);
124         return description == null ? null : description.getCharset();
125
126     }
127     public static IContentDescription getContentDescription(String JavaDoc name, InputStream JavaDoc stream) throws IOException JavaDoc {
128         // tries to obtain a description for this file contents
129
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 JavaDoc e) {
137                     // Ignore exceptions on close
138
}
139         }
140     }
141     
142     public static RepositoryProviderType getAliasType(String JavaDoc 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 JavaDoc aliasId = configElements[j].getAttribute("canImportId"); //$NON-NLS-1$
150
if (aliasId != null && aliasId.equals(id)) {
151                         String JavaDoc extensionId = configElements[j].getAttribute("id"); //$NON-NLS-1$
152
if (extensionId != null) {
153                             return RepositoryProviderType.getProviderType(extensionId);
154                         }
155                     }
156                 }
157             }
158         }
159         return null;
160     }
161     
162     public static IPath[] getMetaFilePaths(String JavaDoc 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 JavaDoc extensionId = configElements[j].getAttribute("id"); //$NON-NLS-1$
170
String JavaDoc metaFilePaths = configElements[j].getAttribute("metaFilePaths"); //$NON-NLS-1$
171
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 JavaDoc metaFilePaths) {
182         List JavaDoc result = new ArrayList JavaDoc();
183         StringTokenizer t = new StringTokenizer(metaFilePaths, ","); //$NON-NLS-1$
184
while (t.hasMoreTokens()) {
185             String JavaDoc 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