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.IOException;
29
30
31
32
33
34 public class SvnUtil
35 {
36 protected static final String SVN_SETTINGS_FILENAME = "svn-settings.xml";
37
38 public static final File DEFAULT_SETTINGS_DIRECTORY = new File( System.getProperty( "user.home" ), ".scm" );
39
40 private static File settingsDirectory = DEFAULT_SETTINGS_DIRECTORY;
41
42 private static Settings settings;
43
44 private SvnUtil()
45 {
46 }
47
48 public static Settings getSettings()
49 {
50 if ( settings == null )
51 {
52 settings = readSettings();
53 }
54 return settings;
55 }
56
57 public static Settings readSettings()
58 {
59 File settingsFile = getSettingsFile();
60
61 if ( settingsFile.exists() )
62 {
63 SvnXpp3Reader reader = new SvnXpp3Reader();
64 try
65 {
66 return reader.read( ReaderFactory.newXmlReader( settingsFile ) );
67 }
68 catch ( IOException e )
69 {
70
71 }
72 catch ( XmlPullParserException e )
73 {
74 String message = settingsFile.getAbsolutePath() + " isn't well formed. SKIPPED." + e.getMessage();
75
76 System.err.println( message );
77 }
78 }
79
80 return new Settings();
81 }
82
83 public static void setSettingsDirectory( File directory )
84 {
85 settingsDirectory = directory;
86 settings = readSettings();
87 }
88
89 public static File getSettingsFile()
90 {
91 return new File( settingsDirectory, SVN_SETTINGS_FILENAME );
92 }
93 }