1 | |
package org.apache.maven.scm.provider.cvslib.util; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.scm.providers.cvslib.settings.Settings; |
23 | |
import org.apache.maven.scm.providers.cvslib.settings.io.xpp3.CvsXpp3Reader; |
24 | |
import org.codehaus.plexus.util.ReaderFactory; |
25 | |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; |
26 | |
|
27 | |
import java.io.File; |
28 | |
import java.io.FileNotFoundException; |
29 | |
import java.io.IOException; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class CvsUtil |
36 | |
{ |
37 | |
protected static final String CVS_SETTINGS_FILENAME = "cvs-settings.xml"; |
38 | |
|
39 | 0 | public static final File DEFAULT_SETTINGS_DIRECTORY = new File( System.getProperty( "user.home" ), ".scm" ); |
40 | |
|
41 | 0 | private static File settingsDirectory = DEFAULT_SETTINGS_DIRECTORY; |
42 | |
|
43 | |
|
44 | |
public static Settings settings;; |
45 | |
|
46 | |
private CvsUtil() |
47 | 0 | { |
48 | |
|
49 | 0 | } |
50 | |
|
51 | |
public static Settings getSettings() |
52 | |
{ |
53 | 0 | if ( settings == null ) |
54 | |
{ |
55 | 0 | settings = readSettings(); |
56 | |
} |
57 | 0 | return settings; |
58 | |
} |
59 | |
|
60 | |
public static Settings readSettings() |
61 | |
{ |
62 | 0 | File settingsFile = getSettingsFile(); |
63 | |
|
64 | 0 | if ( settingsFile.exists() ) |
65 | |
{ |
66 | 0 | CvsXpp3Reader reader = new CvsXpp3Reader(); |
67 | |
try |
68 | |
{ |
69 | 0 | return reader.read( ReaderFactory.newXmlReader( settingsFile ) ); |
70 | |
} |
71 | 0 | catch ( FileNotFoundException e ) |
72 | |
{ |
73 | |
|
74 | |
} |
75 | 0 | catch ( IOException e ) |
76 | |
{ |
77 | |
|
78 | |
} |
79 | 0 | catch ( XmlPullParserException e ) |
80 | |
{ |
81 | 0 | String message = settingsFile.getAbsolutePath() + " isn't well formed. SKIPPED." + e.getMessage(); |
82 | |
|
83 | 0 | System.err.println( message ); |
84 | 0 | } |
85 | |
} |
86 | |
|
87 | 0 | return new Settings(); |
88 | |
} |
89 | |
|
90 | |
public static void setSettingsDirectory( File directory ) |
91 | |
{ |
92 | 0 | settingsDirectory = directory; |
93 | 0 | settings = readSettings(); |
94 | 0 | } |
95 | |
|
96 | |
public static File getSettingsFile() |
97 | |
{ |
98 | 0 | return new File( settingsDirectory, CVS_SETTINGS_FILENAME ); |
99 | |
} |
100 | |
} |