Coverage Report - org.apache.maven.scm.provider.clearcase.util.ClearCaseUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
ClearCaseUtil
69 %
18/26
100 %
6/6
2,4
 
 1  
 package org.apache.maven.scm.provider.clearcase.util;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  * http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 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  
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
 34  
  * @version $Id: ClearCaseUtil.java 1134992 2011-06-12 21:54:27Z godin $
 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  
                 // nop
 89  
             }
 90  0
             catch ( IOException e )
 91  
             {
 92  
                 // nop
 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  
 }