001 package org.apache.maven.project.inheritance.t12scm;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.io.File;
023
024 import org.apache.maven.project.MavenProject;
025 import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
026
027 /**
028 * Verifies SCM inheritance uses modules statement from parent.
029 *
030 * @author jdcasey
031 */
032 public class ProjectInheritanceTest
033 extends AbstractProjectInheritanceTestCase
034 {
035 // ----------------------------------------------------------------------
036 //
037 // p1 inherits from p0
038 // p0 inhertis from super model
039 //
040 // or we can show it graphically as:
041 //
042 // p1 ---> p0 --> super model
043 //
044 // ----------------------------------------------------------------------
045
046 public void testScmInfoCalculatedCorrectlyOnParentAndChildRead()
047 throws Exception
048 {
049 File localRepo = getLocalRepositoryPath();
050
051 File pom0 = new File( localRepo, "p0/pom.xml" );
052 File pom0Basedir = pom0.getParentFile();
053 File pom1 = new File( pom0Basedir, "modules/p1/pom.xml" );
054
055 // load the child project, which inherits from p0...
056 MavenProject project0 = getProject( pom0 );
057 MavenProject project1 = getProject( pom1 );
058
059 System.out.println( "\n\n" );
060 System.out.println( "Parent SCM URL is: " + project0.getScm().getUrl() );
061 System.out.println( "Child SCM URL is: " + project1.getScm().getUrl() );
062 System.out.println();
063 System.out.println( "Parent SCM connection is: " + project0.getScm().getConnection() );
064 System.out.println( "Child SCM connection is: " + project1.getScm().getConnection() );
065 System.out.println();
066 System.out.println( "Parent SCM developer connection is: "
067 + project0.getScm().getDeveloperConnection() );
068 System.out.println( "Child SCM developer connection is: "
069 + project1.getScm().getDeveloperConnection() );
070
071 assertEquals( project1.getScm().getUrl(), project0.getScm().getUrl() + "/modules/p1" );
072 assertEquals( project1.getScm().getConnection(), project0.getScm().getConnection()
073 + "/modules/p1" );
074 assertEquals( project1.getScm().getDeveloperConnection(), project0.getScm()
075 .getDeveloperConnection()
076 + "/modules/p1" );
077 }
078
079 public void testScmInfoCalculatedCorrectlyOnChildOnlyRead()
080 throws Exception
081 {
082 File localRepo = getLocalRepositoryPath();
083
084 File pom1 = new File( localRepo, "p0/modules/p1/pom.xml" );
085
086 // load the child project, which inherits from p0...
087 MavenProject project1 = getProject( pom1 );
088
089 System.out.println( "\n\n" );
090 System.out.println( "Child SCM URL is: " + project1.getScm().getUrl() );
091 System.out.println( "Child SCM connection is: " + project1.getScm().getConnection() );
092 System.out.println( "Child SCM developer connection is: "
093 + project1.getScm().getDeveloperConnection() );
094
095 assertEquals( "http://host/viewer?path=/p0/modules/p1", project1.getScm().getUrl() );
096 assertEquals( "scm:svn:http://host/p0/modules/p1", project1.getScm().getConnection() );
097 assertEquals( "scm:svn:https://host/p0/modules/p1", project1.getScm().getDeveloperConnection() );
098 }
099
100 // public void testScmInfoCalculatedCorrectlyOnChildReadFromLocalRepository()
101 // throws Exception
102 // {
103 // File localRepo = getLocalRepositoryPath();
104 //
105 // ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.class );
106 // Artifact artifact = factory.createProjectArtifact( "maven", "p1", "1.0" );
107 //
108 // ArtifactRepositoryFactory repoFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.class );
109 // ArtifactRepository localArtifactRepo = repoFactory.createLocalRepository( localRepo );
110 //
111 // MavenProject project1 = getProjectBuilder().buildFromRepository( artifact, Collections.EMPTY_LIST, localArtifactRepo );
112 //
113 // System.out.println( "\n\n" );
114 // System.out.println( "Child SCM URL is: " + project1.getScm().getUrl() );
115 // System.out.println( "Child SCM connection is: " + project1.getScm().getConnection() );
116 // System.out.println( "Child SCM developer connection is: "
117 // + project1.getScm().getDeveloperConnection() );
118 //
119 // assertEquals( project1.getScm().getUrl(), "http://host/viewer?path=/p0/modules/p1" );
120 // assertEquals( project1.getScm().getConnection(), "scm:svn:http://host/p0/modules/p1" );
121 // assertEquals( project1.getScm().getDeveloperConnection(),
122 // "scm:svn:https://host/p0/modules/p1" );
123 // }
124
125 }