1 19 20 package org.netbeans.modules.subversion; 21 22 23 import java.util.regex.Pattern ; 24 import java.util.*; 25 import java.util.prefs.Preferences ; 26 import org.netbeans.modules.subversion.options.AnnotationExpression; 27 import org.netbeans.modules.subversion.ui.repository.RepositoryConnection; 28 import org.openide.util.NbPreferences; 29 import org.netbeans.modules.versioning.util.TableSorter; 30 import org.netbeans.modules.versioning.util.Utils; 31 32 37 public class SvnModuleConfig { 38 39 public static final String PROP_IGNORED_FILEPATTERNS = "ignoredFilePatterns"; public static final String PROP_COMMIT_EXCLUSIONS = "commitExclusions"; public static final String PROP_DEFAULT_VALUES = "defaultValues"; public static final String PROP_TEXT_ANNOTATIONS_FORMAT = "textAnnotations"; public static final String KEY_EXECUTABLE_BINARY = "svnExecBinary"; public static final String KEY_ANNOTATION_FORMAT = "annotationFormat"; 46 private static final String RECENT_URL = "repository.recentURL"; private static final String SHOW_CHECKOUT_COMPLETED = "checkoutCompleted.showCheckoutCompleted"; 49 private static final String URL_EXP = "annotator.urlExp"; private static final String ANNOTATION_EXP = "annotator.annotationExp"; 52 public static final String TEXT_ANNOTATIONS_FORMAT_DEFAULT = "{DEFAULT}"; 54 private static final SvnModuleConfig INSTANCE = new SvnModuleConfig(); 55 56 public static SvnModuleConfig getDefault() { 57 return INSTANCE; 58 } 59 60 private Set<String > exclusions; 61 62 64 public Preferences getPreferences() { 65 return NbPreferences.forModule(SvnModuleConfig.class); 66 } 67 68 public boolean getShowCheckoutCompleted() { 69 return getPreferences().getBoolean(SHOW_CHECKOUT_COMPLETED, true); 70 } 71 72 public Pattern [] getIgnoredFilePatterns() { 73 return getDefaultFilePatterns(); 74 } 75 76 public boolean isExcludedFromCommit(String path) { 77 return getCommitExclusions().contains(path); 78 } 79 80 83 public void addExclusionPaths(Collection<String > paths) { 84 Set<String > exclusions = getCommitExclusions(); 85 if (exclusions.addAll(paths)) { 86 Utils.put(getPreferences(), PROP_COMMIT_EXCLUSIONS, new ArrayList<String >(exclusions)); 87 } 88 } 89 90 93 public void removeExclusionPaths(Collection<String > paths) { 94 Set<String > exclusions = getCommitExclusions(); 95 if (exclusions.removeAll(paths)) { 96 Utils.put(getPreferences(), PROP_COMMIT_EXCLUSIONS, new ArrayList<String >(exclusions)); 97 } 98 } 99 100 public String getExecutableBinaryPath() { 101 return (String ) getPreferences().get(KEY_EXECUTABLE_BINARY, ""); 102 } 103 104 public void setExecutableBinaryPath(String path) { 105 getPreferences().put(KEY_EXECUTABLE_BINARY, path); 106 } 107 108 public String getAnnotationFormat() { 109 return (String ) getPreferences().get(KEY_ANNOTATION_FORMAT, getDefaultAnnotationFormat()); 110 } 111 112 public String getDefaultAnnotationFormat() { 113 return "[{" + Annotator.ANNOTATION_STATUS + "} {" + Annotator.ANNOTATION_FOLDER + "}]"; 114 } 115 116 public void setAnnotationFormat(String annotationFormat) { 117 getPreferences().put(KEY_ANNOTATION_FORMAT, annotationFormat); 118 } 119 120 public void setShowCheckoutCompleted(boolean bl) { 121 getPreferences().putBoolean(SHOW_CHECKOUT_COMPLETED, bl); 122 } 123 124 public RepositoryConnection getRepositoryConnection(String url) { 125 List<RepositoryConnection> rcs = getRecentUrls(); 126 for (Iterator<RepositoryConnection> it = rcs.iterator(); it.hasNext();) { 127 RepositoryConnection rc = it.next(); 128 if(url.equals(rc.getUrl())) { 129 return rc; 130 } 131 } 132 return null; 133 } 134 135 public void insertRecentUrl(RepositoryConnection rc) { 136 Preferences prefs = getPreferences(); 137 138 List<String > urlValues = Utils.getStringList(prefs, RECENT_URL); 139 for (Iterator<String > it = urlValues.iterator(); it.hasNext();) { 140 String rcOldString = it.next(); 141 RepositoryConnection rcOld = RepositoryConnection.parse(rcOldString); 142 if(rcOld.equals(rc)) { 143 Utils.removeFromArray(prefs, RECENT_URL, rcOldString); 144 } 145 } 146 Utils.insert(prefs, RECENT_URL, RepositoryConnection.getString(rc), -1); 147 } 148 149 public void setRecentUrls(List<RepositoryConnection> recentUrls) { 150 List<String > urls = new ArrayList<String >(recentUrls.size()); 151 152 int idx = 0; 153 for (Iterator<RepositoryConnection> it = recentUrls.iterator(); it.hasNext();) { 154 idx++; 155 RepositoryConnection rc = it.next(); 156 urls.add(RepositoryConnection.getString(rc)); 157 } 158 Preferences prefs = getPreferences(); 159 Utils.put(prefs, RECENT_URL, urls); 160 } 161 162 public List<RepositoryConnection> getRecentUrls() { 163 Preferences prefs = getPreferences(); 164 List<String > urls = Utils.getStringList(prefs, RECENT_URL); 165 List<RepositoryConnection> ret = new ArrayList<RepositoryConnection>(urls.size()); 166 for (Iterator<String > it = urls.iterator(); it.hasNext();) { 167 RepositoryConnection rc = RepositoryConnection.parse(it.next()); 168 ret.add(rc); 169 } 170 return ret; 171 } 172 173 public void setAnnotationExpresions(List<AnnotationExpression> exps) { 174 List<String > urlExp = new ArrayList<String >(exps.size()); 175 List<String > annotationExp = new ArrayList<String >(exps.size()); 176 177 int idx = 0; 178 for (Iterator<AnnotationExpression> it = exps.iterator(); it.hasNext();) { 179 idx++; 180 AnnotationExpression exp = it.next(); 181 urlExp.add(exp.getUrlExp()); 182 annotationExp.add(exp.getAnnotationExp()); 183 } 184 185 Preferences prefs = getPreferences(); 186 Utils.put(prefs, URL_EXP, urlExp); 187 Utils.put(prefs, ANNOTATION_EXP, annotationExp); 188 } 189 190 public List<AnnotationExpression> getAnnotationExpresions() { 191 Preferences prefs = getPreferences(); 192 List<String > urlExp = Utils.getStringList(prefs, URL_EXP); 193 List<String > annotationExp = Utils.getStringList(prefs, ANNOTATION_EXP); 194 195 List<AnnotationExpression> ret = new ArrayList<AnnotationExpression>(urlExp.size()); 196 for (int i = 0; i < urlExp.size(); i++) { 197 ret.add(new AnnotationExpression(urlExp.get(i), annotationExp.get(i))); 198 } 199 if(ret.size() < 1) { 200 ret = getDefaultAnnotationExpresions(); 201 } 202 return ret; 203 } 204 205 public List<AnnotationExpression> getDefaultAnnotationExpresions() { 206 List<AnnotationExpression> ret = new ArrayList<AnnotationExpression>(1); 207 ret.add(new AnnotationExpression(".*/(branches|tags)/(.+?)/.*", "\\2")); 208 return ret; 209 } 210 211 213 private TableSorter importTableSorter; 214 private TableSorter commitTableSorter; 215 216 public TableSorter getImportTableSorter() { 217 return importTableSorter; 218 } 219 220 public void setImportTableSorter(TableSorter sorter) { 221 importTableSorter = sorter; 222 } 223 224 public TableSorter getCommitTableSorter() { 225 return commitTableSorter; 226 } 227 228 public void setCommitTableSorter(TableSorter sorter) { 229 commitTableSorter = sorter; 230 } 231 232 234 private synchronized Set<String > getCommitExclusions() { 235 if (exclusions == null) { 236 exclusions = new HashSet<String >(Utils.getStringList(getPreferences(), PROP_COMMIT_EXCLUSIONS)); 237 } 238 return exclusions; 239 } 240 241 private static Pattern [] getDefaultFilePatterns() { 242 return new Pattern [] { 243 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"), }; 268 } 269 } 270 | Popular Tags |