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