KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > SvnModuleConfig


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.subversion;
21
22
23 import java.util.regex.Pattern JavaDoc;
24 import java.util.*;
25 import java.util.prefs.Preferences JavaDoc;
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 /**
33  * Stores Subversion module configuration.
34  *
35  * @author Maros Sandor
36  */

37 public class SvnModuleConfig {
38     
39     public static final String JavaDoc PROP_IGNORED_FILEPATTERNS = "ignoredFilePatterns"; // NOI18N
40
public static final String JavaDoc PROP_COMMIT_EXCLUSIONS = "commitExclusions"; // NOI18N
41
public static final String JavaDoc PROP_DEFAULT_VALUES = "defaultValues"; // NOI18N
42
public static final String JavaDoc PROP_TEXT_ANNOTATIONS_FORMAT = "textAnnotations"; // NOI18N
43
public static final String JavaDoc KEY_EXECUTABLE_BINARY = "svnExecBinary"; // NOI18N
44
public static final String JavaDoc KEY_ANNOTATION_FORMAT = "annotationFormat"; // NOI18N
45

46     private static final String JavaDoc RECENT_URL = "repository.recentURL"; // NOI18N
47
private static final String JavaDoc SHOW_CHECKOUT_COMPLETED = "checkoutCompleted.showCheckoutCompleted"; // NOI18N
48

49     private static final String JavaDoc URL_EXP = "annotator.urlExp"; // NOI18N
50
private static final String JavaDoc ANNOTATION_EXP = "annotator.annotationExp"; // NOI18N
51

52     public static final String JavaDoc TEXT_ANNOTATIONS_FORMAT_DEFAULT = "{DEFAULT}"; // NOI18N
53

54     private static final SvnModuleConfig INSTANCE = new SvnModuleConfig();
55     
56     public static SvnModuleConfig getDefault() {
57         return INSTANCE;
58     }
59     
60     private Set<String JavaDoc> exclusions;
61
62     // properties ~~~~~~~~~~~~~~~~~~~~~~~~~
63

64     public Preferences JavaDoc 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 JavaDoc [] getIgnoredFilePatterns() {
73         return getDefaultFilePatterns();
74     }
75     
76     public boolean isExcludedFromCommit(String JavaDoc path) {
77         return getCommitExclusions().contains(path);
78     }
79     
80     /**
81      * @param paths collection of paths, of File.getAbsolutePath()
82      */

83     public void addExclusionPaths(Collection<String JavaDoc> paths) {
84         Set<String JavaDoc> exclusions = getCommitExclusions();
85         if (exclusions.addAll(paths)) {
86             Utils.put(getPreferences(), PROP_COMMIT_EXCLUSIONS, new ArrayList<String JavaDoc>(exclusions));
87         }
88     }
89
90     /**
91      * @param paths collection of paths, File.getAbsolutePath()
92      */

93     public void removeExclusionPaths(Collection<String JavaDoc> paths) {
94         Set<String JavaDoc> exclusions = getCommitExclusions();
95         if (exclusions.removeAll(paths)) {
96             Utils.put(getPreferences(), PROP_COMMIT_EXCLUSIONS, new ArrayList<String JavaDoc>(exclusions));
97         }
98     }
99
100     public String JavaDoc getExecutableBinaryPath() {
101         return (String JavaDoc) getPreferences().get(KEY_EXECUTABLE_BINARY, "");
102     }
103     
104     public void setExecutableBinaryPath(String JavaDoc path) {
105         getPreferences().put(KEY_EXECUTABLE_BINARY, path);
106     }
107
108     public String JavaDoc getAnnotationFormat() {
109         return (String JavaDoc) getPreferences().get(KEY_ANNOTATION_FORMAT, getDefaultAnnotationFormat());
110     }
111     
112     public String JavaDoc getDefaultAnnotationFormat() {
113         return "[{" + Annotator.ANNOTATION_STATUS + "} {" + Annotator.ANNOTATION_FOLDER + "}]";
114     }
115
116     public void setAnnotationFormat(String JavaDoc 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 JavaDoc 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 JavaDoc prefs = getPreferences();
137         
138         List<String JavaDoc> urlValues = Utils.getStringList(prefs, RECENT_URL);
139         for (Iterator<String JavaDoc> it = urlValues.iterator(); it.hasNext();) {
140             String JavaDoc 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 JavaDoc> urls = new ArrayList<String JavaDoc>(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 JavaDoc prefs = getPreferences();
159         Utils.put(prefs, RECENT_URL, urls);
160     }
161     
162     public List<RepositoryConnection> getRecentUrls() {
163         Preferences JavaDoc prefs = getPreferences();
164         List<String JavaDoc> urls = Utils.getStringList(prefs, RECENT_URL);
165         List<RepositoryConnection> ret = new ArrayList<RepositoryConnection>(urls.size());
166         for (Iterator<String JavaDoc> 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 JavaDoc> urlExp = new ArrayList<String JavaDoc>(exps.size());
175         List<String JavaDoc> annotationExp = new ArrayList<String JavaDoc>(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 JavaDoc 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 JavaDoc prefs = getPreferences();
192         List<String JavaDoc> urlExp = Utils.getStringList(prefs, URL_EXP);
193         List<String JavaDoc> 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     // TODO: persist state
212

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     // private methods ~~~~~~~~~~~~~~~~~~
233

234     private synchronized Set<String JavaDoc> getCommitExclusions() {
235         if (exclusions == null) {
236             exclusions = new HashSet<String JavaDoc>(Utils.getStringList(getPreferences(), PROP_COMMIT_EXCLUSIONS));
237         }
238         return exclusions;
239     }
240     
241     private static Pattern JavaDoc[] getDefaultFilePatterns() {
242         return new Pattern JavaDoc [] {
243                         Pattern.compile("cvslog\\..*"), // NOI18N
244
Pattern.compile("\\.make\\.state"), // NOI18N
245
Pattern.compile("\\.nse_depinfo"), // NOI18N
246
Pattern.compile(".*~"), // NOI18N
247
Pattern.compile("#.*"), // NOI18N
248
Pattern.compile("\\.#.*"), // NOI18N
249
Pattern.compile(",.*"), // NOI18N
250
Pattern.compile("_\\$.*"), // NOI18N
251
Pattern.compile(".*\\$"), // NOI18N
252
Pattern.compile(".*\\.old"), // NOI18N
253
Pattern.compile(".*\\.bak"), // NOI18N
254
Pattern.compile(".*\\.BAK"), // NOI18N
255
Pattern.compile(".*\\.orig"), // NOI18N
256
Pattern.compile(".*\\.rej"), // NOI18N
257
Pattern.compile(".*\\.del-.*"), // NOI18N
258
Pattern.compile(".*\\.a"), // NOI18N
259
Pattern.compile(".*\\.olb"), // NOI18N
260
Pattern.compile(".*\\.o"), // NOI18N
261
Pattern.compile(".*\\.obj"), // NOI18N
262
Pattern.compile(".*\\.so"), // NOI18N
263
Pattern.compile(".*\\.exe"), // NOI18N
264
Pattern.compile(".*\\.Z"), // NOI18N
265
Pattern.compile(".*\\.elc"), // NOI18N
266
Pattern.compile(".*\\.ln"), // NOI18N
267
};
268     }
269 }
270
Popular Tags