1   package org.apache.maven.project.inheritance.t12scm;
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  
24  import org.apache.maven.project.MavenProject;
25  import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
26  
27  /**
28   * Verifies SCM inheritance uses modules statement from parent.
29   *
30   * @author jdcasey
31   * @version $Id: ProjectInheritanceTest.java 770390 2009-04-30 18:49:42Z jvanzyl $
32   */
33  public class ProjectInheritanceTest
34      extends AbstractProjectInheritanceTestCase
35  {
36      // ----------------------------------------------------------------------
37      //
38      // p1 inherits from p0
39      // p0 inhertis from super model
40      //
41      // or we can show it graphically as:
42      //
43      // p1 ---> p0 --> super model
44      //
45      // ----------------------------------------------------------------------
46  
47      public void testScmInfoCalculatedCorrectlyOnParentAndChildRead()
48          throws Exception
49      {
50          File localRepo = getLocalRepositoryPath();
51  
52          File pom0 = new File( localRepo, "p0/pom.xml" );
53          File pom0Basedir = pom0.getParentFile();
54          File pom1 = new File( pom0Basedir, "modules/p1/pom.xml" );
55  
56          // load the child project, which inherits from p0...
57          MavenProject project0 = getProject( pom0 );
58          MavenProject project1 = getProject( pom1 );
59  
60          System.out.println( "\n\n" );
61          System.out.println( "Parent SCM URL is: " + project0.getScm().getUrl() );
62          System.out.println( "Child SCM URL is: " + project1.getScm().getUrl() );
63          System.out.println();
64          System.out.println( "Parent SCM connection is: " + project0.getScm().getConnection() );
65          System.out.println( "Child SCM connection is: " + project1.getScm().getConnection() );
66          System.out.println();
67          System.out.println( "Parent SCM developer connection is: "
68                              + project0.getScm().getDeveloperConnection() );
69          System.out.println( "Child SCM developer connection is: "
70                              + project1.getScm().getDeveloperConnection() );
71  
72          assertEquals( project1.getScm().getUrl(), project0.getScm().getUrl() + "/modules/p1" );
73          assertEquals( project1.getScm().getConnection(), project0.getScm().getConnection()
74                                                           + "/modules/p1" );
75          assertEquals( project1.getScm().getDeveloperConnection(), project0.getScm()
76                                                                            .getDeveloperConnection()
77                                                                    + "/modules/p1" );
78      }
79  
80      public void testScmInfoCalculatedCorrectlyOnChildOnlyRead()
81          throws Exception
82      {
83          File localRepo = getLocalRepositoryPath();
84  
85          File pom1 = new File( localRepo, "p0/modules/p1/pom.xml" );
86  
87          // load the child project, which inherits from p0...
88          MavenProject project1 = getProject( pom1 );
89  
90          System.out.println( "\n\n" );
91          System.out.println( "Child SCM URL is: " + project1.getScm().getUrl() );
92          System.out.println( "Child SCM connection is: " + project1.getScm().getConnection() );
93          System.out.println( "Child SCM developer connection is: "
94                              + project1.getScm().getDeveloperConnection() );
95  
96          assertEquals( "http://host/viewer?path=/p0/modules/p1", project1.getScm().getUrl() );
97          assertEquals( "scm:svn:http://host/p0/modules/p1", project1.getScm().getConnection() );
98          assertEquals( "scm:svn:https://host/p0/modules/p1", project1.getScm().getDeveloperConnection() );
99      }
100 
101 //    public void testScmInfoCalculatedCorrectlyOnChildReadFromLocalRepository()
102 //        throws Exception
103 //    {
104 //        File localRepo = getLocalRepositoryPath();
105 //
106 //        ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.class );
107 //        Artifact artifact = factory.createProjectArtifact( "maven", "p1", "1.0" );
108 //
109 //        ArtifactRepositoryFactory repoFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.class );
110 //        ArtifactRepository localArtifactRepo = repoFactory.createLocalRepository( localRepo );
111 //
112 //        MavenProject project1 = getProjectBuilder().buildFromRepository( artifact, Collections.EMPTY_LIST, localArtifactRepo );
113 //
114 //        System.out.println( "\n\n" );
115 //        System.out.println( "Child SCM URL is: " + project1.getScm().getUrl() );
116 //        System.out.println( "Child SCM connection is: " + project1.getScm().getConnection() );
117 //        System.out.println( "Child SCM developer connection is: "
118 //                            + project1.getScm().getDeveloperConnection() );
119 //
120 //        assertEquals( project1.getScm().getUrl(), "http://host/viewer?path=/p0/modules/p1" );
121 //        assertEquals( project1.getScm().getConnection(), "scm:svn:http://host/p0/modules/p1" );
122 //        assertEquals( project1.getScm().getDeveloperConnection(),
123 //                      "scm:svn:https://host/p0/modules/p1" );
124 //    }
125 
126 }