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