View | Details | Raw Unified | Return to bug 19691 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/core/Team.java (-77 / +69 lines)
Lines 26-31 Link Here
26
import java.util.Iterator;
26
import java.util.Iterator;
27
import java.util.List;
27
import java.util.List;
28
import java.util.Map;
28
import java.util.Map;
29
import java.util.NoSuchElementException;
30
import java.util.StringTokenizer;
29
31
30
import org.eclipse.core.resources.IFile;
32
import org.eclipse.core.resources.IFile;
31
import org.eclipse.core.resources.IProject;
33
import org.eclipse.core.resources.IProject;
Lines 44-49 Link Here
44
import org.eclipse.core.runtime.IProgressMonitor;
46
import org.eclipse.core.runtime.IProgressMonitor;
45
import org.eclipse.core.runtime.IStatus;
47
import org.eclipse.core.runtime.IStatus;
46
import org.eclipse.core.runtime.MultiStatus;
48
import org.eclipse.core.runtime.MultiStatus;
49
import org.eclipse.core.runtime.Preferences;
47
import org.eclipse.core.runtime.Status;
50
import org.eclipse.core.runtime.Status;
48
import org.eclipse.team.internal.core.Policy;
51
import org.eclipse.team.internal.core.Policy;
49
import org.eclipse.team.internal.core.StringMatcher;
52
import org.eclipse.team.internal.core.StringMatcher;
Lines 57-62 Link Here
57
 */
60
 */
58
public final class Team {
61
public final class Team {
59
	
62
	
63
	public static final String PREF_TEAM_IGNORES = "ignore_files"; //$NON-NLS-1$
64
	public static final String PREF_TEAM_SEPARATOR = ";"; //$NON-NLS-1$
60
	public static final Status OK_STATUS = new Status(Status.OK, TeamPlugin.ID, Status.OK, Policy.bind("ok"), null); //$NON-NLS-1$
65
	public static final Status OK_STATUS = new Status(Status.OK, TeamPlugin.ID, Status.OK, Policy.bind("ok"), null); //$NON-NLS-1$
61
	
66
	
62
	// File type constants
67
	// File type constants
Lines 67-80 Link Here
67
	// File name of the persisted file type information
72
	// File name of the persisted file type information
68
	private static final String STATE_FILE = ".fileTypes"; //$NON-NLS-1$
73
	private static final String STATE_FILE = ".fileTypes"; //$NON-NLS-1$
69
	
74
	
70
	// File name of the persisted global ignore patterns
71
	private final static String GLOBALIGNORE_FILE = ".globalIgnores"; //$NON-NLS-1$
72
73
	// Keys: file extensions. Values: Integers
75
	// Keys: file extensions. Values: Integers
74
	private static Hashtable fileTypes;
76
	private static Hashtable fileTypes;
75
77
76
	// The ignore list that is read at startup from the persisted file
78
	// The ignore list that is read at startup from the persisted file
77
	private static Map globalIgnore;
79
	private static Map globalIgnore, pluginIgnore;
78
80
79
	private static class FileTypeInfo implements IFileTypeInfo {
81
	private static class FileTypeInfo implements IFileTypeInfo {
80
		private String extension;
82
		private String extension;
Lines 249-254 Link Here
249
		for (int i = 0; i < patterns.length; i++) {
251
		for (int i = 0; i < patterns.length; i++) {
250
			globalIgnore.put(patterns[i], new Boolean(enabled[i]));
252
			globalIgnore.put(patterns[i], new Boolean(enabled[i]));
251
		}
253
		}
254
		// Now set into preferences
255
		StringBuffer buf = new StringBuffer();
256
		Iterator e = globalIgnore.keySet().iterator();
257
		while (e.hasNext()) {
258
			String pattern = (String)e.next();
259
			boolean isCustom = (!pluginIgnore.containsKey(pattern)) ||
260
				!((Boolean)pluginIgnore.get(pattern)).equals((Boolean)globalIgnore.get(pattern));
261
			if (isCustom) {
262
				buf.append(pattern);
263
				buf.append(PREF_TEAM_SEPARATOR);
264
				boolean en = ((Boolean)globalIgnore.get(pattern)).booleanValue();
265
				buf.append(en);
266
				buf.append(PREF_TEAM_SEPARATOR);
267
			}
268
			
269
		}
270
		TeamPlugin.getPlugin().getPluginPreferences().setValue(PREF_TEAM_IGNORES, buf.toString());
252
	}
271
	}
253
	
272
	
254
	/*
273
	/*
Lines 434-439 Link Here
434
	 * Reads the ignores currently defined by extensions.
453
	 * Reads the ignores currently defined by extensions.
435
	 */
454
	 */
436
	private static void initializePluginIgnores() {
455
	private static void initializePluginIgnores() {
456
		pluginIgnore = new Hashtable();
437
		TeamPlugin plugin = TeamPlugin.getPlugin();
457
		TeamPlugin plugin = TeamPlugin.getPlugin();
438
		if (plugin != null) {
458
		if (plugin != null) {
439
			IExtensionPoint extension = plugin.getDescriptor().getExtensionPoint(TeamPlugin.IGNORE_EXTENSION);
459
			IExtensionPoint extension = plugin.getDescriptor().getExtensionPoint(TeamPlugin.IGNORE_EXTENSION);
Lines 447-452 Link Here
447
							String selected = configElements[j].getAttribute("selected"); //$NON-NLS-1$
467
							String selected = configElements[j].getAttribute("selected"); //$NON-NLS-1$
448
							boolean enabled = selected != null && selected.equalsIgnoreCase("true"); //$NON-NLS-1$
468
							boolean enabled = selected != null && selected.equalsIgnoreCase("true"); //$NON-NLS-1$
449
							// if this ignore doesn't already exist, add it to the global list
469
							// if this ignore doesn't already exist, add it to the global list
470
							pluginIgnore.put(pattern, new Boolean(enabled));
450
							if (!globalIgnore.containsKey(pattern)) {
471
							if (!globalIgnore.containsKey(pattern)) {
451
								globalIgnore.put(pattern, new Boolean(enabled));
472
								globalIgnore.put(pattern, new Boolean(enabled));
452
							}
473
							}
Lines 456-545 Link Here
456
			}		
477
			}		
457
		}
478
		}
458
	}
479
	}
459
	
480
460
	/*
481
	/*
461
	 * IGNORE
482
	 * IGNORE
462
	 * 
483
	 * 
463
	 * Save global ignore file
484
	 * Reads global ignore preferences and populates globalIgnore
464
	 */
485
	 */
465
	private static void saveIgnoreState() throws TeamException {
486
	private static void readIgnoreState() throws TeamException {
466
		// save global ignore list to disk
487
		if (readBackwardCompatibleIgnoreState()) return;
467
		IPath pluginStateLocation = TeamPlugin.getPlugin().getStateLocation();
488
		Preferences pref = TeamPlugin.getPlugin().getPluginPreferences();
468
		File tempFile = pluginStateLocation.append(GLOBALIGNORE_FILE + ".tmp").toFile(); //$NON-NLS-1$
489
		if (!pref.contains(PREF_TEAM_IGNORES)) return;
469
		File stateFile = pluginStateLocation.append(GLOBALIGNORE_FILE).toFile();
490
		String prefIgnores = pref.getString(PREF_TEAM_IGNORES);
491
		StringTokenizer tok = new StringTokenizer(prefIgnores, PREF_TEAM_SEPARATOR);
492
		String pattern, enabled;
470
		try {
493
		try {
471
			DataOutputStream dos = new DataOutputStream(new FileOutputStream(tempFile));
494
			while (true) {
472
			try {
495
				pattern = tok.nextToken();
473
				writeIgnoreState(dos);
496
				if (pattern.length()==0) return;
474
			} finally {
497
				enabled = tok.nextToken();
475
				dos.close();
498
				globalIgnore.put(pattern, new Boolean(enabled));
476
			}
499
			} 
477
			if (stateFile.exists() & !stateFile.delete())
500
		} catch (NoSuchElementException e) {
478
				throw new TeamException(new Status(IStatus.ERROR, TeamPlugin.ID, 0, Policy.bind("Team.couldNotDelete", stateFile.getAbsolutePath()), null)); //$NON-NLS-1$
501
			return;
479
			if (!tempFile.renameTo(stateFile))
480
				throw new TeamException(new Status(IStatus.ERROR, TeamPlugin.ID, 0, Policy.bind("Team.couldNotRename", tempFile.getAbsolutePath(), stateFile.getAbsolutePath()), null)); //$NON-NLS-1$
481
		} catch (IOException ex) {
482
			throw new TeamException(new Status(IStatus.ERROR, TeamPlugin.ID, 0, Policy.bind("Team.writeError", stateFile.getAbsolutePath()), ex)); //$NON-NLS-1$
483
		}
484
	}
485
	
486
	/*
487
	 * IGNORE
488
	 * 
489
	 * Write the global ignores to the stream
490
	 */
491
	private static void writeIgnoreState(DataOutputStream dos) throws IOException {
492
		// write the global ignore list
493
		if (globalIgnore == null) getAllIgnores();
494
		int ignoreLength = globalIgnore.size();
495
		dos.writeInt(ignoreLength);
496
		Iterator e = globalIgnore.keySet().iterator();
497
		while (e.hasNext()) {
498
			String pattern = (String)e.next();
499
			boolean enabled = ((Boolean)globalIgnore.get(pattern)).booleanValue();
500
			dos.writeUTF(pattern);
501
			dos.writeBoolean(enabled);
502
		}
502
		}
503
	}
503
	}
504
	
504
505
	/*
505
	/*
506
	 * IGNORE
506
	 * For backward compatibility, we still look at if we have .globalIgnores
507
	 * 
508
	 * Reads the global ignore file
509
	 */
507
	 */
510
	private static void readIgnoreState() throws TeamException {
508
	private static boolean readBackwardCompatibleIgnoreState() throws TeamException {
511
		// read saved repositories list and ignore list from disk, only if the file exists
509
		String GLOBALIGNORE_FILE = ".globalIgnores"; //$NON-NLS-1$
512
		IPath pluginStateLocation = TeamPlugin.getPlugin().getStateLocation().append(GLOBALIGNORE_FILE);
510
		IPath pluginStateLocation = TeamPlugin.getPlugin().getStateLocation().append(GLOBALIGNORE_FILE);
513
		File f = pluginStateLocation.toFile();
511
		File f = pluginStateLocation.toFile();
514
		if(f.exists()) {
512
		if (!f.exists()) return false;
513
		try {
514
			DataInputStream dis = new DataInputStream(new FileInputStream(f));
515
			try {
515
			try {
516
				DataInputStream dis = new DataInputStream(new FileInputStream(f));
516
				int ignoreCount = 0;
517
				try {
517
				try {
518
					globalIgnore = new Hashtable(11);
518
					ignoreCount = dis.readInt();
519
					int ignoreCount = 0;
519
				} catch (EOFException e) {
520
					try {
520
					// Ignore the exception, it will occur if there are no ignore
521
						ignoreCount = dis.readInt();
521
					// patterns stored in the provider state file.
522
					} catch (EOFException e) {
522
					return false;
523
						// Ignore the exception, it will occur if there are no ignore
524
						// patterns stored in the provider state file.
525
						return;
526
					}
527
					for (int i = 0; i < ignoreCount; i++) {
528
						String pattern = dis.readUTF();
529
						boolean enabled = dis.readBoolean();
530
						globalIgnore.put(pattern, new Boolean(enabled));
531
					}
532
				} finally {
533
					dis.close();
534
				}
523
				}
535
			} catch (FileNotFoundException e) {
524
				for (int i = 0; i < ignoreCount; i++) {
536
				// not a fatal error, there just happens not to be any state to read
525
					String pattern = dis.readUTF();
537
			} catch (IOException ex) {
526
					boolean enabled = dis.readBoolean();
538
				throw new TeamException(new Status(IStatus.ERROR, TeamPlugin.ID, 0, Policy.bind("Team.readError"), ex));			 //$NON-NLS-1$
527
					globalIgnore.put(pattern, new Boolean(enabled));
528
				}
529
			} finally {
530
				dis.close();
539
			}
531
			}
532
			f.delete();
533
		} catch (FileNotFoundException e) {
534
			// not a fatal error, there just happens not to be any state to read
535
		} catch (IOException ex) {
536
			throw new TeamException(new Status(IStatus.ERROR, TeamPlugin.ID, 0, Policy.bind("Team.readError"), ex));			 //$NON-NLS-1$
540
		}
537
		}
538
		return true;
541
	}
539
	}
542
543
	/**
540
	/**
544
	 * Initialize the registry, restoring its state.
541
	 * Initialize the registry, restoring its state.
545
	 * 
542
	 * 
Lines 575-586 Link Here
575
	 */	
572
	 */	
576
	public static void shutdown() {
573
	public static void shutdown() {
577
		saveTextState();
574
		saveTextState();
578
		try {
575
		TeamPlugin.getPlugin().savePluginPreferences();
579
			// make sure that we update our state on disk
580
			saveIgnoreState();
581
		} catch (TeamException ex) {
582
			TeamPlugin.log(IStatus.WARNING, Policy.bind("TeamPlugin_setting_global_ignore_7"), ex); //$NON-NLS-1$
583
		}
584
	}
576
	}
585
	public static IProjectSetSerializer getProjectSetSerializer(String id) {
577
	public static IProjectSetSerializer getProjectSetSerializer(String id) {
586
		TeamPlugin plugin = TeamPlugin.getPlugin();
578
		TeamPlugin plugin = TeamPlugin.getPlugin();

Return to bug 19691