KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > CVSProviderPlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.ccvs.core;
12  
13 import java.io.*;
14 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.Collections JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.eclipse.core.resources.*;
22 import org.eclipse.core.runtime.*;
23 import org.eclipse.core.runtime.preferences.InstanceScope;
24 import org.eclipse.jsch.core.IJSchService;
25 import org.eclipse.osgi.util.NLS;
26 import org.eclipse.team.core.Team;
27 import org.eclipse.team.core.TeamException;
28 import org.eclipse.team.internal.ccvs.core.client.Command;
29 import org.eclipse.team.internal.ccvs.core.client.ConsoleListeners;
30 import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption;
31 import org.eclipse.team.internal.ccvs.core.client.Command.QuietOption;
32 import org.eclipse.team.internal.ccvs.core.client.listeners.IConsoleListener;
33 import org.eclipse.team.internal.ccvs.core.mapping.CVSActiveChangeSetCollector;
34 import org.eclipse.team.internal.ccvs.core.resources.FileModificationManager;
35 import org.eclipse.team.internal.ccvs.core.util.*;
36 import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager;
37 import org.osgi.framework.BundleContext;
38 import org.osgi.util.tracker.ServiceTracker;
39
40 public class CVSProviderPlugin extends Plugin {
41     
42     // preference names
43
public static final String JavaDoc READ_ONLY = "cvs.read.only"; //$NON-NLS-1$
44
public static final String JavaDoc ENABLE_WATCH_ON_EDIT = "cvs.watch.on.edit"; //$NON-NLS-1$
45

46     // external command to run for ext connection method
47
public static final String JavaDoc DEFAULT_CVS_RSH = "ssh"; //$NON-NLS-1$
48
// external command parameters
49
public static final String JavaDoc DEFAULT_CVS_RSH_PARAMETERS = "-l {user} {host}"; //$NON-NLS-1$
50
// remote command to run for ext connection method
51
public static final String JavaDoc DEFAULT_CVS_SERVER = "cvs"; //$NON-NLS-1$
52
// determines if empty directories received from the server should be pruned.
53
public static final boolean DEFAULT_PRUNE = true;
54     // determines if the user is prompted for confirmation before moving tags during a tag operation.
55
public static final boolean DEFAULT_CONFIRM_MOVE_TAG = true;
56     // determines if new directories should be discovered during update.
57
public static final boolean DEFAULT_FETCH = true;
58     // communication timeout with the server
59
public static final int DEFAULT_TIMEOUT = 60;
60     // file transfer compression level (0 - 9)
61
public static final int DEFAULT_COMPRESSION_LEVEL = 0;
62     // default text keyword substitution mode
63
public static final KSubstOption DEFAULT_TEXT_KSUBST_OPTION = Command.KSUBST_TEXT_EXPAND;
64
65     // cvs plugin extension points and ids
66
public static final String JavaDoc ID = "org.eclipse.team.cvs.core"; //$NON-NLS-1$
67

68     public static final QualifiedName CVS_WORKSPACE_SUBSCRIBER_ID = new QualifiedName("org.eclipse.team.cvs.ui.cvsworkspace-participant", "syncparticipant"); //$NON-NLS-1$ //$NON-NLS-2$
69
public static final String JavaDoc PT_AUTHENTICATOR = "authenticator"; //$NON-NLS-1$
70
public static final String JavaDoc PT_CONNECTIONMETHODS = "connectionmethods"; //$NON-NLS-1$
71
public static final String JavaDoc PT_FILE_MODIFICATION_VALIDATOR = "filemodificationvalidator"; //$NON-NLS-1$
72

73     private QuietOption quietness;
74     private int compressionLevel = DEFAULT_COMPRESSION_LEVEL;
75     private KSubstOption defaultTextKSubstOption = DEFAULT_TEXT_KSUBST_OPTION;
76     private boolean usePlatformLineend = true;
77     private int communicationsTimeout = DEFAULT_TIMEOUT;
78     private boolean pruneEmptyDirectories = DEFAULT_PRUNE;
79     private boolean fetchAbsentDirectories = DEFAULT_FETCH;
80     private boolean replaceUnmanaged = true;
81     private boolean repositoriesAreBinary = false;
82     private String JavaDoc cvsRshCommand = DEFAULT_CVS_RSH;
83     private String JavaDoc cvsRshParameters = DEFAULT_CVS_RSH_PARAMETERS;
84     private String JavaDoc cvsServer = DEFAULT_CVS_SERVER;
85     private boolean determineVersionEnabled = true;
86     
87     private static volatile CVSProviderPlugin instance;
88     
89     // CVS specific resource delta listeners
90
private BuildCleanupListener addDeleteMoveListener;
91     private FileModificationManager fileModificationManager;
92     private SyncFileChangeListener metaFileSyncListener;
93
94     private static final String JavaDoc REPOSITORIES_STATE_FILE = ".cvsProviderState"; //$NON-NLS-1$
95
// version numbers for the state file (a positive number indicates version 1)
96
private static final int REPOSITORIES_STATE_FILE_VERSION_2 = -1;
97     private static List JavaDoc decoratorEnablementListeners = new ArrayList JavaDoc();
98     
99     private CVSWorkspaceSubscriber cvsWorkspaceSubscriber;
100     
101     /**
102      * The identifier for the CVS nature
103      * (value <code>"org.eclipse.team.cvs.core.nature"</code>).
104      * The presence of this nature on a project indicates that it is
105      * CVS-capable.
106      *
107      * @see org.eclipse.core.resources.IProject#hasNature
108      */

109     private static final String JavaDoc NATURE_ID = ID + ".cvsnature"; //$NON-NLS-1$
110

111     // File used to idicate if the workbench was shut down properly or not
112
private static final String JavaDoc CRASH_INDICATION_FILE = ".running"; //$NON-NLS-1$
113
private boolean crash;
114
115     private boolean autoShareOnImport;
116     private boolean useProxy;
117
118     public static final String JavaDoc PROXY_TYPE_HTTP = "HTTP"; //$NON-NLS-1$
119
public static final String JavaDoc PROXY_TYPE_SOCKS5 = "SOCKS5"; //$NON-NLS-1$
120
public static final String JavaDoc HTTP_DEFAULT_PORT = "80"; //$NON-NLS-1$
121
public static final String JavaDoc SOCKS5_DEFAULT_PORT = "1080"; //$NON-NLS-1$
122

123     private String JavaDoc proxyType;
124     private String JavaDoc proxyHost;
125     private String JavaDoc proxyPort;
126     private boolean useProxyAuth;
127     
128     private CVSActiveChangeSetCollector changeSetManager;
129     private ServiceTracker tracker;
130
131     private static final String JavaDoc INFO_PROXY_USER = "org.eclipse.team.cvs.core.proxy.user"; //$NON-NLS-1$
132
private static final String JavaDoc INFO_PROXY_PASS = "org.eclipse.team.cvs.core.proxy.pass"; //$NON-NLS-1$
133

134     private static final URL JavaDoc FAKE_URL;
135     static {
136         URL JavaDoc temp = null;
137         try {
138             temp = new URL JavaDoc("http://org.eclipse.team.cvs.proxy.auth");//$NON-NLS-1$
139
} catch (MalformedURLException JavaDoc e) {
140             // Should never fail
141
}
142         FAKE_URL = temp;
143     }
144     
145     
146     public synchronized CVSWorkspaceSubscriber getCVSWorkspaceSubscriber() {
147         if (cvsWorkspaceSubscriber == null) {
148             cvsWorkspaceSubscriber = new CVSWorkspaceSubscriber(
149                     CVS_WORKSPACE_SUBSCRIBER_ID,
150                     CVSMessages.CVSProviderPlugin_20);
151         }
152         return cvsWorkspaceSubscriber;
153     }
154
155     /**
156      * Constructor for CVSProviderPlugin.
157      * @param descriptor
158      */

159     public CVSProviderPlugin() {
160         super();
161         instance = this;
162     }
163     
164     /**
165      * Convenience method for logging CoreExceptions to the plugin log
166      */

167     public static void log(CoreException e) {
168         log(e.getStatus().getSeverity(), e.getMessage(), e);
169     }
170     
171     /**
172      * Log the given exception along with the provided message and severity indicator
173      */

174     public static void log(int severity, String JavaDoc message, Throwable JavaDoc e) {
175         log(new Status(severity, ID, 0, message, e));
176     }
177     
178     /**
179      * Log the given status. Do not use this method for the IStatus from a CoreException.
180      * Use<code>log(CoreException)</code> instead so the stack trace is not lost.
181      */

182     public static void log(IStatus status) {
183         getPlugin().getLog().log(status);
184     }
185
186     /**
187      * Returns the singleton plug-in instance.
188      *
189      * @return the plugin instance
190      */

191     public static CVSProviderPlugin getPlugin() {
192         return instance;
193     }
194     
195     /**
196      * Answers the repository provider type id for the cvs plugin
197      */

198     public static String JavaDoc getTypeId() {
199         return NATURE_ID;
200     }
201     
202     /**
203      * Sets the file transfer compression level. (if supported)
204      * Valid levels are: 0 (disabled), 1 (worst/fastest) - 9 (best/slowest)
205      */

206     public void setCompressionLevel(int level) {
207         compressionLevel = level;
208     }
209
210     /**
211      * Gets the file transfer compression level.
212      */

213     public int getCompressionLevel() {
214         return compressionLevel;
215     }
216     
217     /**
218      * Sets the default keyword substitution mode for text files.
219      */

220     public void setDefaultTextKSubstOption(KSubstOption ksubst) {
221         defaultTextKSubstOption = ksubst;
222     }
223
224
225     /**
226      * Gets the default keyword substitution mode for text files.
227      */

228     public KSubstOption getDefaultTextKSubstOption() {
229         return defaultTextKSubstOption;
230     }
231
232     /**
233      * Should the CVS adapter prune empty directories
234      */

235     public boolean getPruneEmptyDirectories() {
236         return pruneEmptyDirectories;
237     }
238
239     /**
240      * Set whether the CVS adapter should prune empty directories
241      */

242     public void setPruneEmptyDirectories(boolean prune) {
243         pruneEmptyDirectories = prune;
244     }
245
246     /**
247      * Get the communications timeout value in seconds
248      */

249     public int getTimeout() {
250         return communicationsTimeout;
251     }
252     
253     /**
254      * Set the timeout value for communications to a value in seconds.
255      * The value must be greater than or equal 0. If is it 0, there is no timeout.
256      */

257     public void setTimeout(int timeout) {
258         this.communicationsTimeout = Math.max(0, timeout);
259     }
260     
261     /**
262      * Set the quietness option to use with cvs commands.
263      * Can be "", "-q" or "-Q"
264      */

265     public void setQuietness(QuietOption option) {
266             this.quietness = option;
267     }
268
269     /**
270      * Get the quietness option for commands
271      */

272     public QuietOption getQuietness() {
273         return quietness;
274     }
275     
276     /**
277      * Set the console listener for commands.
278      * @param consoleListener the listener
279      */

280     public void setConsoleListener(IConsoleListener consoleListener) {
281         ConsoleListeners.getInstance().addListener(consoleListener);
282     }
283     
284     /**
285      * @see Plugin#start(BundleContext)
286      */

287     public void start(BundleContext context) throws Exception JavaDoc {
288         super.start(context);
289
290         // load the state which includes the known repositories
291
loadOldState();
292         crash = createCrashFile();
293         
294         // Initialize CVS change listeners. Note that the report type is important.
295
IWorkspace workspace = ResourcesPlugin.getWorkspace();
296         addDeleteMoveListener = new BuildCleanupListener();
297         fileModificationManager = new FileModificationManager();
298         metaFileSyncListener = new SyncFileChangeListener();
299         workspace.addResourceChangeListener(addDeleteMoveListener, IResourceChangeEvent.POST_BUILD);
300         workspace.addResourceChangeListener(metaFileSyncListener, IResourceChangeEvent.POST_CHANGE);
301         workspace.addResourceChangeListener(fileModificationManager, IResourceChangeEvent.POST_CHANGE);
302         
303         getCVSWorkspaceSubscriber();
304         
305         // Must load the change set manager on startup since it listens to deltas
306
getChangeSetManager();
307         
308         tracker = new ServiceTracker(getBundle().getBundleContext(), IJSchService.class.getName(), null);
309         tracker.open();
310     }
311     
312     /**
313      * @see Plugin#stop(BundleContext)
314      */

315     public void stop(BundleContext context) throws Exception JavaDoc {
316         try {
317             savePluginPreferences();
318             
319             // remove listeners
320
IWorkspace workspace = ResourcesPlugin.getWorkspace();
321             workspace.removeResourceChangeListener(metaFileSyncListener);
322             workspace.removeResourceChangeListener(fileModificationManager);
323             workspace.removeResourceChangeListener(addDeleteMoveListener);
324             
325             // remove all of this plugin's save participants. This is easier than having
326
// each class that added itself as a participant to have to listen to shutdown.
327
workspace.removeSaveParticipant(this);
328             
329             getChangeSetManager().dispose();
330             
331             tracker.close();
332             
333             deleteCrashFile();
334         } finally {
335             super.stop(context);
336         }
337     }
338         
339     /**
340      * @see org.eclipse.core.runtime.Plugin#initializeDefaultPluginPreferences()
341      */

342     protected void initializeDefaultPluginPreferences(){
343         Preferences store = getPluginPreferences();
344         store.setDefault(READ_ONLY, false);
345         store.setDefault(ENABLE_WATCH_ON_EDIT, false);
346     }
347     
348     /**
349      * Gets the cvsRshCommand.
350      * @return Returns a String
351      */

352     public String JavaDoc getCvsRshCommand() {
353         return cvsRshCommand;
354     }
355
356     /**
357      * Sets the cvsRshCommand.
358      * @param cvsRshCommand The cvsRshCommand to set
359      */

360     public void setCvsRshCommand(String JavaDoc cvsRshCommand) {
361         this.cvsRshCommand = cvsRshCommand;
362     }
363
364     /**
365      * Returns the cvsRshParameters.
366      * @return String
367      */

368     public String JavaDoc getCvsRshParameters() {
369         return cvsRshParameters;
370     }
371
372     /**
373      * Sets the cvsRshParameters.
374      * @param cvsRshParameters The cvsRshParameters to set
375      */

376     public void setCvsRshParameters(String JavaDoc cvsRshParameters) {
377         this.cvsRshParameters = cvsRshParameters;
378     }
379     
380     /**
381      * Gets the cvsServer.
382      * @return Returns a String
383      */

384     public String JavaDoc getCvsServer() {
385         return cvsServer;
386     }
387
388     /**
389      * Sets the cvsServer.
390      * @param cvsServer The cvsServer to set
391      */

392     public void setCvsServer(String JavaDoc cvsServer) {
393         this.cvsServer = cvsServer;
394     }
395
396     /**
397      * Gets the etchAbsentDirectories.
398      * @return Returns a boolean
399      */

400     public boolean getFetchAbsentDirectories() {
401         return fetchAbsentDirectories;
402     }
403
404     public boolean getRepositoriesAreBinary() {
405         return repositoriesAreBinary;
406     }
407     
408     /**
409      * Sets the fetchAbsentDirectories.
410      * @param etchAbsentDirectories The etchAbsentDirectories to set
411      */

412     public void setFetchAbsentDirectories(boolean fetchAbsentDirectories) {
413         this.fetchAbsentDirectories = fetchAbsentDirectories;
414     }
415     
416     public void setRepositoriesAreBinary(boolean binary) {
417         repositoriesAreBinary = binary;
418     }
419     
420     public static void broadcastDecoratorEnablementChanged(final boolean enabled) {
421         ICVSDecoratorEnablementListener[] listeners;
422         synchronized(decoratorEnablementListeners) {
423             listeners = (ICVSDecoratorEnablementListener[]) decoratorEnablementListeners.toArray(new ICVSDecoratorEnablementListener[decoratorEnablementListeners.size()]);
424         }
425         for (int i = 0; i < listeners.length; i++) {
426             final ICVSDecoratorEnablementListener listener = listeners[i];
427             ISafeRunnable code = new ISafeRunnable() {
428                 public void run() throws Exception JavaDoc {
429                     listener.decoratorEnablementChanged(enabled);
430                 }
431                 public void handleException(Throwable JavaDoc e) {
432                     // don't log the exception....it is already being logged in Platform#run
433
}
434             };
435             Platform.run(code);
436         }
437     }
438     
439     /**
440      * Gets the replaceUnmanaged.
441      * @return Returns a boolean
442      */

443     public boolean isReplaceUnmanaged() {
444         return replaceUnmanaged;
445     }
446
447     /**
448      * Sets the replaceUnmanaged.
449      * @param replaceUnmanaged The replaceUnmanaged to set
450      */

451     public void setReplaceUnmanaged(boolean replaceUnmanaged) {
452         this.replaceUnmanaged = replaceUnmanaged;
453     }
454
455         
456     /**
457      * Register to receive notification of repository creation and disposal
458      */

459     public void addRepositoryListener(ICVSListener listener) {
460         KnownRepositories.getInstance().addRepositoryListener(listener);
461     }
462     
463     /**
464      * Register to receive notification of enablement of sync info decoration requirements. This
465      * can be useful for providing lazy initialization of caches that are only required for decorating
466      * resource with CVS information.
467      */

468     public void addDecoratorEnablementListener(ICVSDecoratorEnablementListener listener) {
469         synchronized(decoratorEnablementListeners) {
470             decoratorEnablementListeners.add(listener);
471         }
472     }
473     
474     /**
475      * De-register a listener
476      */

477     public void removeRepositoryListener(ICVSListener listener) {
478         KnownRepositories.getInstance().removeRepositoryListener(listener);
479     }
480     
481     /**
482      * De-register the decorator enablement listener.
483      */

484     public void removeDecoratorEnablementListener(ICVSDecoratorEnablementListener listener) {
485         synchronized(decoratorEnablementListeners) {
486             decoratorEnablementListeners.remove(listener);
487         }
488     }
489     
490     /**
491      * Return a list of the know repository locations. This is left
492      * here to isolate the RelEng tools plugin from changes in CVS core.
493      */

494     public ICVSRepositoryLocation[] getKnownRepositories() {
495         return KnownRepositories.getInstance().getRepositories();
496     }
497
498     private void loadOldState() {
499         try {
500             IPath pluginStateLocation = CVSProviderPlugin.getPlugin().getStateLocation().append(REPOSITORIES_STATE_FILE);
501             File file = pluginStateLocation.toFile();
502             if (file.exists()) {
503                 try {
504                     DataInputStream dis = new DataInputStream(new FileInputStream(file));
505                     readOldState(dis);
506                     dis.close();
507                     // The file is no longer needed as the state is
508
// persisted in the user settings
509
file.delete();
510                 } catch (IOException e) {
511                     throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, CVSMessages.CVSProvider_ioException, e));
512                 }
513             }
514         } catch (TeamException e) {
515             Util.logError(CVSMessages.CVSProvider_errorLoading, e);
516         }
517     }
518     
519     private void readOldState(DataInputStream dis) throws IOException, CVSException {
520         KnownRepositories instance = KnownRepositories.getInstance();
521         int count = dis.readInt();
522         if (count >= 0) {
523             // this is the version 1 format of the state file
524
for (int i = 0; i < count; i++) {
525                 ICVSRepositoryLocation location = instance.getRepository(dis.readUTF());
526                 instance.addRepository(location, false /* no need to broadcast on startup */);
527             }
528         } else if (count == REPOSITORIES_STATE_FILE_VERSION_2) {
529             count = dis.readInt();
530             for (int i = 0; i < count; i++) {
531                 ICVSRepositoryLocation location = instance.getRepository(dis.readUTF());
532                 instance.addRepository(location, false /* no need to broadcast on startup */);
533                 // Read the next field which is no longer used
534
dis.readUTF();
535             }
536         } else {
537             Util.logError(NLS.bind(CVSMessages.CVSProviderPlugin_unknownStateFileVersion, new String JavaDoc[] { new Integer JavaDoc(count).toString() }), null);
538         }
539     }
540         
541     public static boolean isText(IFile file) {
542         if (CVSProviderPlugin.getPlugin().getRepositoriesAreBinary()) return false;
543         return Team.getFileContentManager().getType(file) == Team.TEXT;
544     }
545     
546     /**
547      * Gets the determineVersionEnabled.
548      * @return boolean
549      */

550     public boolean isDetermineVersionEnabled() {
551         return determineVersionEnabled;
552     }
553
554     /**
555      * Sets the determineVersionEnabled.
556      * @param determineVersionEnabled The determineVersionEnabled to set
557      */

558     public void setDetermineVersionEnabled(boolean determineVersionEnabled) {
559         this.determineVersionEnabled = determineVersionEnabled;
560     }
561     
562     /**
563      * Returns the fileModificationManager.
564      * @return FileModificationManager
565      */

566     public FileModificationManager getFileModificationManager() {
567         return fileModificationManager;
568     }
569
570     /**
571      * @return boolean
572      */

573     public boolean isWatchEditEnabled() {
574         return getPluginPreferences().getBoolean(CVSProviderPlugin.READ_ONLY);
575     }
576
577     public void setDebugProtocol(boolean value) {
578         Policy.DEBUG_CVS_PROTOCOL = value;
579     }
580     
581     public boolean isDebugProtocol() {
582         return Policy.DEBUG_CVS_PROTOCOL;
583     }
584
585     /*
586      * Create the crash indicator file. This method returns true if the file
587      * already existed, indicating that a crash occurred on the last invokation of
588      * the platform.
589      */

590     private boolean createCrashFile() {
591         IPath pluginStateLocation = CVSProviderPlugin.getPlugin().getStateLocation();
592         File crashFile = pluginStateLocation.append(CRASH_INDICATION_FILE).toFile();
593         if (crashFile.exists()) {
594             return true;
595         }
596         try {
597             crashFile.createNewFile();
598         } catch (IOException e) {
599             CVSProviderPlugin.log(IStatus.ERROR, e.getMessage(), e);
600         }
601         return false;
602     }
603     
604     private void deleteCrashFile() {
605         IPath pluginStateLocation = CVSProviderPlugin.getPlugin().getStateLocation();
606         File crashFile = pluginStateLocation.append(CRASH_INDICATION_FILE).toFile();
607         crashFile.delete();
608     }
609     
610     public boolean crashOnLastRun() {
611         return crash;
612     }
613     
614     /**
615      * Return the CVS preferences node in the instance scope
616      */

617     public org.osgi.service.prefs.Preferences getInstancePreferences() {
618         return new InstanceScope().getNode(getBundle().getSymbolicName());
619     }
620     
621     /**
622      * @return Returns the usePlatformLineend.
623      */

624     public boolean isUsePlatformLineend() {
625         return usePlatformLineend;
626     }
627     /**
628      * @param usePlatformLineend The usePlatformLineend to set.
629      */

630     public void setUsePlatformLineend(boolean usePlatformLineend) {
631         this.usePlatformLineend = usePlatformLineend;
632     }
633
634     public void setAutoshareOnImport(boolean autoShareOnImport) {
635         this.autoShareOnImport = autoShareOnImport;
636     }
637
638     public boolean isAutoshareOnImport() {
639         return autoShareOnImport;
640     }
641
642     /**
643      * @return Returns the watchOnEdit.
644      */

645     public boolean isWatchOnEdit() {
646         return getPluginPreferences().getBoolean(CVSProviderPlugin.ENABLE_WATCH_ON_EDIT);
647     }
648     
649     // proxy configuration
650

651     public void setUseProxy(boolean useProxy) {
652       this.useProxy = useProxy;
653     }
654
655     public boolean isUseProxy() {
656         return this.useProxy;
657     }
658
659     public void setProxyType(String JavaDoc proxyType) {
660         this.proxyType = proxyType;
661     }
662     
663     public String JavaDoc getProxyType() {
664         return this.proxyType;
665     }
666
667     public void setProxyHost(String JavaDoc proxyHost) {
668         this.proxyHost = proxyHost;
669     }
670     
671     public String JavaDoc getProxyHost() {
672         return this.proxyHost;
673     }
674
675     public void setProxyPort(String JavaDoc proxyPort) {
676         this.proxyPort = proxyPort;
677     }
678     
679     public String JavaDoc getProxyPort() {
680         return this.proxyPort;
681     }
682
683     public void setUseProxyAuth(boolean useProxyAuth) {
684         this.useProxyAuth = useProxyAuth;
685     }
686
687     public boolean isUseProxyAuth() {
688         return this.useProxyAuth;
689     }
690     
691     public String JavaDoc getProxyUser() {
692         Object JavaDoc user = getAuthInfo().get(INFO_PROXY_USER);
693         return user==null ? "" : (String JavaDoc) user; //$NON-NLS-1$
694
}
695     
696     public String JavaDoc getProxyPassword() {
697         Object JavaDoc pass = getAuthInfo().get(INFO_PROXY_PASS);
698         return pass==null ? "" : (String JavaDoc) pass; //$NON-NLS-1$
699
}
700     
701     private Map JavaDoc getAuthInfo() {
702       // Retrieve username and password from keyring.
703
Map JavaDoc authInfo = Platform.getAuthorizationInfo(FAKE_URL, "proxy", ""); //$NON-NLS-1$ //$NON-NLS-2$
704
return authInfo!=null ? authInfo : Collections.EMPTY_MAP;
705     }
706
707     public void setProxyAuth(String JavaDoc proxyUser, String JavaDoc proxyPass) {
708         Map JavaDoc authInfo = getAuthInfo();
709         if (authInfo.size()==0) {
710             authInfo = new java.util.HashMap JavaDoc(4);
711         }
712         if (proxyUser != null) {
713             authInfo.put(INFO_PROXY_USER, proxyUser);
714         }
715         if (proxyPass != null) {
716             authInfo.put(INFO_PROXY_PASS, proxyPass);
717         }
718         try {
719             Platform.addAuthorizationInfo(FAKE_URL, "proxy", "", authInfo); //$NON-NLS-1$ //$NON-NLS-2$
720
} catch (CoreException e) {
721             // We should probably wrap the CoreException here!
722
CVSProviderPlugin.log(e);
723         }
724     }
725     
726     public synchronized ActiveChangeSetManager getChangeSetManager() {
727         if (changeSetManager == null) {
728             changeSetManager = new CVSActiveChangeSetCollector(CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber());
729         }
730         return changeSetManager;
731     }
732     
733     public IJSchService getJSchService() {
734         return (IJSchService)tracker.getService();
735     }
736     
737 }
738
Popular Tags