Author: hboutemy
Date: Sun Jan 17 16:17:34 2016
New Revision: 1725099

URL: http://svn.apache.org/viewvc?rev=1725099&view=rev
Log:
[DOXIASITETOOLS-145] do parent POM interpolation only with Maven2: Maven 3 
doesn't suffer from this issue

Modified:
    
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
    
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java

Modified: 
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java?rev=1725099&r1=1725098&r2=1725099&view=diff
==============================================================================
--- 
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
 (original)
+++ 
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
 Sun Jan 17 16:17:34 2016
@@ -34,6 +34,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Properties;
 import java.util.StringTokenizer;
 
 import org.apache.commons.io.FilenameUtils;
@@ -43,6 +44,7 @@ import org.apache.maven.artifact.reposit
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import 
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.doxia.site.decoration.Banner;
@@ -518,6 +520,12 @@ public class DefaultSiteTool
         checkNotNull( "reactorProjects", reactorProjects );
         checkNotNull( "localRepository", localRepository );
 
+        if ( isMaven3OrMore() )
+        {
+            // no need to make voodoo with Maven 3: job already done
+            return aProject.getParent();
+        }
+
         MavenProject parentProject = null;
 
         MavenProject origParent = aProject.getParent();
@@ -1427,4 +1435,37 @@ public class DefaultSiteTool
             throw new IllegalArgumentException( "The parameter '" + name + "' 
cannot be null." );
         }
     }
+
+    /**
+     * Check the current Maven version to see if it's Maven 3.0 or newer.
+     */
+    private static boolean isMaven3OrMore()
+    {
+        return new DefaultArtifactVersion( getMavenVersion() 
).getMajorVersion() >= 3;
+    }
+
+    private static String getMavenVersion()
+    {
+        // This relies on the fact that MavenProject is the in core classloader
+        // and that the core classloader is for the maven-core artifact
+        // and that should have a pom.properties file
+        // if this ever changes, we will have to revisit this code.
+        final Properties properties = new Properties();
+        final String corePomProperties = 
"META-INF/maven/org.apache.maven/maven-core/pom.properties";
+        final InputStream in = 
MavenProject.class.getClassLoader().getResourceAsStream( corePomProperties );
+       try
+        {
+            properties.load( in );
+        }
+        catch ( IOException ioe )
+        {
+            return "";
+        }
+        finally
+        {
+            IOUtil.close( in );
+        }
+
+        return properties.getProperty( "version" ).trim();
+    }
 }

Modified: 
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java?rev=1725099&r1=1725098&r2=1725099&view=diff
==============================================================================
--- 
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
 (original)
+++ 
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
 Sun Jan 17 16:17:34 2016
@@ -190,12 +190,12 @@ public interface SiteTool
     String getRelativePath( String to, String from );
 
     /**
-     * Returns the parent POM with interpolated URLs. Attempts to source this 
value from the
+     * Returns the parent POM with interpolated URLs.
+     * If called from Maven 3, just returns <code>project.getParent()</code>, 
which is already
+     * interpolated. But when called from Maven 2, attempts to source this 
value from the
      * <code>reactorProjects</code> parameters if available (reactor env model 
attributes
      * are interpolated), or if the reactor is unavailable (-N) resorts to the
      * <code>project.getParent().getUrl()</code> value which will NOT have 
been interpolated.
-     * <p/>
-     * TODO: once bug is fixed in Maven proper, remove this.
      *
      * @param aProject a Maven project, not null.
      * @param reactorProjects the Maven reactor projects, not null.


Reply via email to