1 | |
package org.apache.maven.scm.provider.svn.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.svn.settings.Settings; |
23 | |
import org.apache.maven.scm.providers.svn.settings.io.xpp3.SvnXpp3Reader; |
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 SvnUtil |
36 | |
{ |
37 | |
protected static final String SVN_SETTINGS_FILENAME = "svn-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 | |
private static Settings settings; |
44 | |
|
45 | |
private SvnUtil() |
46 | 0 | { |
47 | 0 | } |
48 | |
|
49 | |
public static Settings getSettings() |
50 | |
{ |
51 | 0 | if (settings == null) |
52 | |
{ |
53 | 0 | settings = readSettings(); |
54 | |
} |
55 | 0 | return settings; |
56 | |
} |
57 | |
|
58 | |
public static Settings readSettings() |
59 | |
{ |
60 | 0 | File settingsFile = getSettingsFile(); |
61 | |
|
62 | 0 | if ( settingsFile.exists() ) |
63 | |
{ |
64 | 0 | SvnXpp3Reader reader = new SvnXpp3Reader(); |
65 | |
try |
66 | |
{ |
67 | 0 | return reader.read( ReaderFactory.newXmlReader( settingsFile ) ); |
68 | |
} |
69 | 0 | catch ( FileNotFoundException e ) |
70 | |
{ |
71 | |
|
72 | |
} |
73 | 0 | catch ( IOException e ) |
74 | |
{ |
75 | |
|
76 | |
} |
77 | 0 | catch ( XmlPullParserException e ) |
78 | |
{ |
79 | 0 | String message = settingsFile.getAbsolutePath() + " isn't well formed. SKIPPED." + e.getMessage(); |
80 | |
|
81 | 0 | System.err.println( message ); |
82 | 0 | } |
83 | |
} |
84 | |
|
85 | 0 | return new Settings(); |
86 | |
} |
87 | |
|
88 | |
public static void setSettingsDirectory( File directory ) |
89 | |
{ |
90 | 0 | settingsDirectory = directory; |
91 | 0 | settings = readSettings(); |
92 | 0 | } |
93 | |
|
94 | |
public static File getSettingsFile() |
95 | |
{ |
96 | 0 | return new File( settingsDirectory, SVN_SETTINGS_FILENAME ); |
97 | |
} |
98 | |
} |