You are viewing a plain text version of this content. The canonical link for it is here.
Posted to npanday-commits@incubator.apache.org by br...@apache.org on 2013/03/04 13:57:49 UTC

svn commit: r1452308 - in /incubator/npanday/trunk/dotnet/assemblies: NPanday.ProjectImporter/Engine/src/main/csharp/Converter/Algorithms/AbstractPomConverter.cs NPanday.Utils/src/main/csharp/PathUtility.cs

Author: brett
Date: Mon Mar  4 13:57:49 2013
New Revision: 1452308

URL: http://svn.apache.org/r1452308
Log:
[NPANDAY-578] relativize paths within the project

Primarily for packages downloaded using NuGet, this will make libraries a little more portable
if they continue to use the system path.

Modified:
    incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/Converter/Algorithms/AbstractPomConverter.cs
    incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/PathUtility.cs

Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/Converter/Algorithms/AbstractPomConverter.cs
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/Converter/Algorithms/AbstractPomConverter.cs?rev=1452308&r1=1452307&r2=1452308&view=diff
==============================================================================
--- incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/Converter/Algorithms/AbstractPomConverter.cs (original)
+++ incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/Converter/Algorithms/AbstractPomConverter.cs Mon Mar  4 13:57:49 2013
@@ -1042,6 +1042,16 @@ namespace NPanday.ProjectImporter.Conver
             }
             else
             {
+                // if it is in the project, we still consider it non-portable because packaging plugins will exclude system dependencies
+                // however, we can adjust the path to be a bit more portable across different checkouts
+                // first, check if the library is somewhere inside the solution (mainPomFile is top-most POM)
+                string projectRoot = new DirectoryInfo(mainPomFile).Parent.FullName;
+                if (PathUtility.IsSubdirectoryOf(projectRoot, path))
+                {
+                    // if so, adjust path to be relative to this project's POM file
+                    path = "${basedir}\\" + PathUtility.MakeRelative(projectDigest.FullDirectoryName + "\\", path);
+                    refDependency.systemPath = path;
+                }
                 log.WarnFormat("Adding non-portable reference to POM: {0}", path);
             }
 

Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/PathUtility.cs
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/PathUtility.cs?rev=1452308&r1=1452307&r2=1452308&view=diff
==============================================================================
--- incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/PathUtility.cs (original)
+++ incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/PathUtility.cs Mon Mar  4 13:57:49 2013
@@ -87,5 +87,29 @@ namespace NPanday.Utils
         {
             return new DirectoryInfo(Path.Combine(projectRoot.FullName, DefaultBuildDirectoryName));
         }
+
+        public static bool IsSubdirectoryOf(string basedir, string path)
+        {
+            basedir = new DirectoryInfo(basedir).FullName;
+
+            DirectoryInfo p = new DirectoryInfo(path);
+            do
+            {
+                if (p.Parent.FullName == basedir)
+                {
+                    return true;
+                }
+                p = p.Parent;
+            }
+            while (p.Parent != null);
+
+            return false;
+        }
+
+        public static string MakeRelative(string basedir, string path)
+        {
+            Uri relativeUri = new Uri(basedir).MakeRelativeUri(new Uri(path));
+            return Uri.UnescapeDataString(relativeUri.ToString()).Replace('/', Path.DirectorySeparatorChar);
+        }
     }
 }
\ No newline at end of file