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 public static final File DEFAULT_SETTINGS_DIRECTORY = new File( System.getProperty( "user.home" ), ".scm" );
42
43 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 private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( RESOURCE_FILENAME );
48
49 private static Settings settings;
50
51 private ClearCaseUtil()
52 {
53 }
54
55 public static String getLocalizedResource( String key )
56 {
57 return RESOURCE_BUNDLE.getString( key );
58 }
59
60 public static Settings getSettings()
61 {
62 if ( settings == null )
63 {
64 settings = readSettings();
65 }
66 return settings;
67 }
68
69 public static Settings readSettings()
70 {
71 File settingsFile = new File( settingsDirectory, CLEARCASE_SETTINGS_FILENAME );
72
73 if ( !settingsFile.exists() )
74 {
75 File scmGlobalDir = new File( System.getProperty( "maven.home" ), "conf" );
76 settingsFile = new File( scmGlobalDir, CLEARCASE_SETTINGS_FILENAME );
77 }
78
79 if ( settingsFile.exists() )
80 {
81 ClearcaseXpp3Reader reader = new ClearcaseXpp3Reader();
82 try
83 {
84 return reader.read( ReaderFactory.newXmlReader( settingsFile ) );
85 }
86 catch ( FileNotFoundException e )
87 {
88
89 }
90 catch ( IOException e )
91 {
92
93 }
94 catch ( XmlPullParserException e )
95 {
96 String message = settingsFile.getAbsolutePath() + " isn't well formed. SKIPPED." + e.getMessage();
97
98 System.out.println( message );
99 }
100 }
101
102 return new Settings();
103 }
104
105 public static void setSettingsDirectory( File directory )
106 {
107 settingsDirectory = directory;
108 settings = readSettings();
109 }
110 }