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