1 19 20 package org.netbeans.modules.versioning.system.cvss; 21 22 import java.util.regex.Pattern ; 23 import java.util.*; 24 import java.lang.String ; 25 import java.util.prefs.Preferences ; 26 import java.io.File ; 27 28 import org.openide.util.NbPreferences; 29 import org.netbeans.modules.versioning.util.Utils; 30 import org.netbeans.modules.versioning.util.FileCollection; 31 import org.netbeans.lib.cvsclient.CVSRoot; 32 33 38 public class CvsModuleConfig { 39 40 public static final String PROP_IGNORED_FILEPATTERNS = "ignoredFilePatterns"; public static final String PROP_COMMIT_EXCLUSIONS = "commitExclusions"; public static final String PROP_SEARCHHISTORY_FETCHTAGS = "searchHistory.fetchTags"; public static final String PROP_EXCLUDE_NEW_FILES = "excludeNewFiles"; public static final String ROOTS_CONFIG = "rootsConfig"; public static final String PROP_ANNOTATIONS_VISIBLE = "textAnnotationsVisible"; public static final String PROP_ANNOTATIONS_FORMAT = "annotationsFormat"; private static final String PROP_WRAP_COMMIT_MESSAGE_LENGTH = "wrapCommitMessageLength"; 49 public static final String DEFAULT_ANNOTATIONS_FORMAT = "[{status}; {tag}]"; 50 51 private static final String FIELD_SEPARATOR = "<~>"; 52 53 private static final CvsModuleConfig INSTANCE = new CvsModuleConfig(); 54 55 public static CvsModuleConfig getDefault() { 56 return INSTANCE; 57 } 58 59 private FileCollection excludedFiles; 60 61 private Map<String , RootSettings> rootsMap; 62 63 64 public CvsModuleConfig() { 65 excludedFiles = new FileCollection(); 66 excludedFiles.load(getPreferences(), PROP_COMMIT_EXCLUSIONS); 67 } 68 69 72 public int getWrapCommitMessagelength() { 73 return getPreferences().getInt(PROP_WRAP_COMMIT_MESSAGE_LENGTH, 0); 74 } 75 76 79 public void setWrapCommitMessagelength(int length) { 80 if (length < 0) throw new IllegalArgumentException (); 81 getPreferences().putInt(PROP_WRAP_COMMIT_MESSAGE_LENGTH, length); 82 } 83 84 public Pattern [] getIgnoredFilePatterns() { 85 return getDefaultFilePatterns(); 86 } 87 88 public boolean isExcludedFromCommit(File file) { 89 return excludedFiles.contains(file); 90 } 91 92 95 public void addExclusion(File file) { 96 excludedFiles.add(file); 97 excludedFiles.save(getPreferences(), PROP_COMMIT_EXCLUSIONS); 98 } 99 100 103 public void removeExclusion(File file) { 104 excludedFiles.remove(file); 105 excludedFiles.save(getPreferences(), PROP_COMMIT_EXCLUSIONS); 106 } 107 108 110 public synchronized boolean hasExtSettingsFor(CVSRoot root) { 111 assert "ext".equals(root.getMethod()); Map<String , RootSettings> rootsMap = getRootsMap(); 113 String rootString = root.toString(); 114 RootSettings rootSettings = (RootSettings) rootsMap.get(rootString); 115 if (rootSettings != null) { 116 ExtSettings extSettings = rootSettings.extSettings; 117 return extSettings != null; 118 } 119 return false; 120 } 121 122 128 public synchronized ExtSettings getExtSettingsFor(CVSRoot root) { 129 assert "ext".equals(root.getMethod()); Map<String , RootSettings> rootsMap = getRootsMap(); 131 String rootString = root.toString(); 132 RootSettings rootSettings = (RootSettings) rootsMap.get(rootString); 133 if (rootSettings != null) { 134 ExtSettings extSettings = rootSettings.extSettings; 135 if (extSettings != null) { 136 if (extSettings.extUseInternalSsh == false && extSettings.extCommand == null) { 137 extSettings.extCommand = System.getenv("CVS_RSH"); } 139 return extSettings; 140 } 141 } 142 143 ExtSettings defaults = new ExtSettings(); 145 defaults.extRememberPassword = false; 146 defaults.extCommand = System.getenv("CVS_RSH"); defaults.extUseInternalSsh = true; 148 defaults.extPassword = null; 149 return defaults; 150 } 151 152 public synchronized void setExtSettingsFor(CVSRoot root, ExtSettings extSettings) { 153 assert "ext".equals(root.getMethod()); Map<String , RootSettings> map = getRootsMap(); 155 String key = root.toString(); 156 RootSettings settings = (RootSettings) map.get(key); 157 if (settings == null) { 158 settings = new RootSettings(); 159 } 160 settings.extSettings = extSettings; 161 map.put(key, settings); 162 163 storeRootsMap(); 164 } 165 166 private Map<String , RootSettings> getRootsMap() { 167 if (rootsMap == null) { 168 rootsMap = loadRootsMap(); 169 } 170 return rootsMap; 171 } 172 173 private Map<String , RootSettings> loadRootsMap() { 174 List<String > smap = Utils.getStringList(getPreferences(), "cvsRootSettings"); 175 Map<String , RootSettings> map = new HashMap<String , RootSettings>(smap.size()); 176 for (String s : smap) { 177 String [] fields = s.split(FIELD_SEPARATOR); 178 if (fields.length >= 8) { 179 RootSettings rs = new RootSettings(); 181 map.put(fields[0], rs); 182 if (fields.length >= 11) { 183 ExtSettings es = new ExtSettings(); 184 rs.extSettings = es; 185 es.extUseInternalSsh = Boolean.valueOf(fields[8]); 186 es.extRememberPassword = Boolean.valueOf(fields[9]); 187 es.extCommand = fields[10]; 188 if (fields.length >= 12) { 189 es.extPassword = fields[11]; 190 } 191 } 192 } else { 193 if (fields.length >= 4) { 194 RootSettings rs = new RootSettings(); 195 map.put(fields[0], rs); 196 ExtSettings es = new ExtSettings(); 197 rs.extSettings = es; 198 es.extUseInternalSsh = Boolean.valueOf(fields[1]); 199 es.extRememberPassword = Boolean.valueOf(fields[2]); 200 es.extCommand = fields[3]; 201 if (fields.length >= 5) { 202 es.extPassword = fields[4]; 203 } 204 } 205 } 206 } 207 return map; 208 } 209 210 private void storeRootsMap() { 211 List<String > smap = new ArrayList<String >(); 212 for (Map.Entry<String , RootSettings> entry : rootsMap.entrySet()) { 213 StringBuffer es = new StringBuffer (100); 214 es.append(entry.getKey()); 215 RootSettings settings = entry.getValue(); 216 if (settings.extSettings != null) { 217 es.append(FIELD_SEPARATOR); 218 es.append(settings.extSettings.extUseInternalSsh); 219 es.append(FIELD_SEPARATOR); 220 es.append(settings.extSettings.extRememberPassword); 221 es.append(FIELD_SEPARATOR); 222 es.append(settings.extSettings.extCommand); 223 if (settings.extSettings.extRememberPassword) { 224 es.append(FIELD_SEPARATOR); 225 es.append(settings.extSettings.extPassword); 226 } 227 } 228 smap.add(es.toString()); 229 } 230 Utils.put(getPreferences(), "cvsRootSettings", smap); 231 } 232 233 238 public Preferences getPreferences() { 239 return NbPreferences.forModule(CvsModuleConfig.class); 240 } 241 242 244 private Pattern [] getDefaultFilePatterns() { 245 return new Pattern [] { 246 Pattern.compile("cvslog\\..*"), Pattern.compile("\\.make\\.state"), Pattern.compile("\\.nse_depinfo"), Pattern.compile(".*~"), Pattern.compile("#.*"), Pattern.compile("\\.#.*"), Pattern.compile(",.*"), Pattern.compile("_\\$.*"), Pattern.compile(".*\\$"), Pattern.compile(".*\\.old"), Pattern.compile(".*\\.bak"), Pattern.compile(".*\\.BAK"), Pattern.compile(".*\\.orig"), Pattern.compile(".*\\.rej"), Pattern.compile(".*\\.del-.*"), Pattern.compile(".*\\.a"), Pattern.compile(".*\\.olb"), Pattern.compile(".*\\.o"), Pattern.compile(".*\\.obj"), Pattern.compile(".*\\.so"), Pattern.compile(".*\\.exe"), Pattern.compile(".*\\.Z"), Pattern.compile(".*\\.elc"), Pattern.compile(".*\\.ln"), }; 271 } 272 273 276 private final static class RootSettings { 277 278 private ExtSettings extSettings; 279 } 280 281 282 public final static class ExtSettings { 283 284 public boolean extUseInternalSsh; 285 286 287 public boolean extRememberPassword; 288 289 290 public String extPassword; 291 292 293 public String extCommand; 294 } 295 } 296 297 | Popular Tags |