001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.provider.svn.util; 020 021import java.io.File; 022import java.io.IOException; 023 024import org.apache.maven.scm.providers.svn.settings.Settings; 025import org.apache.maven.scm.providers.svn.settings.io.xpp3.SvnXpp3Reader; 026import org.codehaus.plexus.util.ReaderFactory; 027import org.codehaus.plexus.util.xml.pull.XmlPullParserException; 028 029/** 030 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 031 * 032 */ 033public class SvnUtil { 034 protected static final String SVN_SETTINGS_FILENAME = "svn-settings.xml"; 035 036 public static final File DEFAULT_SETTINGS_DIRECTORY = new File(System.getProperty("user.home"), ".scm"); 037 038 private static File settingsDirectory = DEFAULT_SETTINGS_DIRECTORY; 039 040 private static Settings settings; 041 042 private SvnUtil() {} 043 044 public static Settings getSettings() { 045 if (settings == null) { 046 settings = readSettings(); 047 } 048 return settings; 049 } 050 051 public static Settings readSettings() { 052 File settingsFile = getSettingsFile(); 053 054 if (settingsFile.exists()) { 055 SvnXpp3Reader reader = new SvnXpp3Reader(); 056 try { 057 return reader.read(ReaderFactory.newXmlReader(settingsFile)); 058 } catch (IOException e) { 059 // Nothing to do 060 } catch (XmlPullParserException e) { 061 String message = settingsFile.getAbsolutePath() + " isn't well formed. SKIPPED." + e.getMessage(); 062 063 System.err.println(message); 064 } 065 } 066 067 return new Settings(); 068 } 069 070 public static void setSettingsDirectory(File directory) { 071 settingsDirectory = directory; 072 settings = readSettings(); 073 } 074 075 public static File getSettingsFile() { 076 return new File(settingsDirectory, SVN_SETTINGS_FILENAME); 077 } 078}