maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r656802 - in /maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src: main/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtils.java test/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtilsTest.java
Date Thu, 15 May 2008 19:29:52 GMT
Author: evenisse
Date: Thu May 15 12:29:52 2008
New Revision: 656802

URL: http://svn.apache.org/viewvc?rev=656802&view=rev
Log:
[SCM-338] Fix NPE when using vssDirectory system property
Submitted by : Allan Lang

Added:
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src/test/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtilsTest.java
  (with props)
Modified:
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src/main/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtils.java

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src/main/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtils.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src/main/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtils.java?rev=656802&r1=656801&r2=656802&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src/main/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtils.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src/main/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtils.java
Thu May 15 12:29:52 2008
@@ -45,6 +45,8 @@
 public class VssCommandLineUtils
     implements VssConstants  // FIXME extend CommandLineUtils
 {
+    private static File scmConfDir = new File( System.getProperty( "user.home" ), ".scm"
);
+
     public static void addFiles( Commandline cl, ScmFileSet fileSet )
     {
         Iterator it = fileSet.getFileList().iterator();
@@ -107,8 +109,7 @@
     public static final Settings getSettings()
     {
         Settings settings = null;
-        File scmUserHome = new File( System.getProperty( "user.home" ), ".scm" );
-        File settingsFile = new File( scmUserHome, "vss-settings.xml" );
+        File settingsFile = new File( scmConfDir, "vss-settings.xml" );
         if ( settingsFile.exists() )
         {
             VssXpp3Reader reader = new VssXpp3Reader();
@@ -134,11 +135,25 @@
         String vssDirectory = System.getProperty( "vssDirectory" );
         if ( StringUtils.isNotEmpty( vssDirectory ) )
         {
+            if ( settings == null )
+            {
+                settings = new Settings();
+            }
             settings.setVssDirectory( vssDirectory );
         }
         return settings;
     }
 
+    protected static final File getScmConfDir()
+    {
+        return scmConfDir;
+    }
+
+    protected static final void setScmConfDir( File directory )
+    {
+        scmConfDir = directory;
+    }
+
     public static final String getSsDir()
     {
         String ssDir = "";

Added: maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src/test/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src/test/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtilsTest.java?rev=656802&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src/test/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtilsTest.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src/test/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtilsTest.java
Thu May 15 12:29:52 2008
@@ -0,0 +1,162 @@
+package org.apache.maven.scm.provider.vss.commands;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.ScmTestCase;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * @author Allan Lang
+ * @version $Id$
+ */
+public class VssCommandLineUtilsTest
+    extends ScmTestCase
+{
+
+    private static final String VSS_DIRECTORY_PROPERTY = "vssDirectory";
+
+    //private ScmManager scmManager;
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        //scmManager = getScmManager();
+    }
+
+    public void testGetSettings()
+        throws IOException
+    {
+        /*
+         * If we have a genuine settings file, take a copy of this first Create
+         * the test settings file Check getSettings from file Delete the test
+         * settings file Check getSettings without file Check getSettings with
+         * system property Re-instate original settings file, if existing
+         *
+         */
+
+        final String vssInstallPath = "c:\\wherever";
+        final String vssInstallPathAlt = "c:\\somewhere";
+        final String settingsXml =
+            "<vss-settings><Settings><vssDirectory>" + vssInstallPath +
"</vssDirectory></Settings></vss-settings>";
+        final String settingsFilename = "vss-settings.xml";
+        final String backupFilename = settingsFilename + ".backup";
+        boolean preExistingScmFolder = false;
+        boolean preExistingSettings = false;
+
+        /*
+         * Create a backup of the current settings file, if one exists
+         */
+        File scmUserHome = new File( getTestFile( "target/vssdir" ), ".scm" );
+        if ( scmUserHome.exists() )
+        {
+            preExistingScmFolder = true;
+            File settingsFile = new File( scmUserHome, settingsFilename );
+            if ( settingsFile.exists() )
+            {
+                preExistingSettings = true;
+                settingsFile.renameTo( new File( scmUserHome, backupFilename ) );
+            }
+        }
+        else
+        {
+            scmUserHome.mkdirs();
+        }
+
+        /*
+         * Create the test settings file
+         */
+        File testSettings = new File( scmUserHome, settingsFilename );
+        FileOutputStream fos = new FileOutputStream( testSettings );
+        fos.write( settingsXml.getBytes() );
+        fos.flush();
+        fos.close();
+        fos = null;
+
+        /*
+         * Validate that setting from settings file is returned correctly
+         */
+        VssCommandLineUtils.setScmConfDir( scmUserHome );
+        assertEquals( vssInstallPath, VssCommandLineUtils.getSettings().getVssDirectory()
);
+
+        /*
+         * Validate that setting is overridden by system property
+         */
+        System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathAlt );
+        assertEquals( vssInstallPathAlt, VssCommandLineUtils.getSettings().getVssDirectory()
);
+
+        /*
+         * Delete the test settings file
+         */
+        testSettings.delete();
+
+        /*
+         * Validate that setting is still equal to system property
+         */
+        assertEquals( vssInstallPathAlt, VssCommandLineUtils.getSettings().getVssDirectory()
);
+
+        /*
+         * Re-instate the original settings file, if one existed
+         */
+        if ( preExistingSettings )
+        {
+            File backup = new File( scmUserHome, backupFilename );
+            backup.renameTo( new File( scmUserHome, settingsFilename ) );
+        }
+
+        if ( !preExistingScmFolder )
+        {
+            scmUserHome.delete();
+        }
+
+    }
+
+    public void testGetSsDir()
+    {
+        final String vssInstallPathWindowsStyle = "c:\\vss\\bin";
+        final String vssInstallPathUnixStyle = "c:/vss/bin";
+        final String targetValue = "c:/vss/bin/";
+
+        // Windows style test
+        System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathWindowsStyle );
+        assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
+
+        // Unix style test
+        System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathUnixStyle );
+        assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
+
+        // Windows style with folder indicator
+        System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathWindowsStyle + "\\" );
+        assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
+
+        // Unix style with folder indicator
+        System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathUnixStyle + "/" );
+        assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
+
+        // Unix style with Windows style folder indicator
+        System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathUnixStyle + "\\" );
+        assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
+
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src/test/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-provider-vss/src/test/java/org/apache/maven/scm/provider/vss/commands/VssCommandLineUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message