View Javadoc

1   package org.apache.maven.shared.release.phase;
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 org.apache.maven.model.Model;
23  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
24  import org.apache.maven.project.MavenProject;
25  import org.codehaus.plexus.PlexusTestCase;
26  import org.codehaus.plexus.util.ReaderFactory;
27  
28  import java.io.File;
29  import java.util.ArrayList;
30  import java.util.Iterator;
31  import java.util.List;
32  
33  /**
34   * @author Edwin Punzalan
35   */
36  public abstract class AbstractBackupPomsPhaseTest
37      extends PlexusTestCase
38  {
39      private final String pomFilename = "pom.xml";
40  
41      protected final String releaseBackupSuffix = ".releaseBackup";
42  
43      protected ReleasePhase phase;
44  
45      protected void setUp()
46          throws Exception
47      {
48          super.setUp();
49  
50          phase = getReleasePhase();
51      }
52  
53      abstract ReleasePhase getReleasePhase()
54          throws Exception;
55  
56      protected List<MavenProject> getReactorProjects( String projectPath )
57          throws Exception
58      {
59          List<MavenProject> reactorProjects = new ArrayList<MavenProject>();
60  
61          File pomFile = new File( projectPath, pomFilename );
62  
63          MavenProject mainProject = createMavenProject( pomFile );
64  
65          reactorProjects.add( mainProject );
66  
67          for( Iterator modules = mainProject.getModel().getModules().iterator(); modules.hasNext(); )
68          {
69              String module = modules.next().toString();
70  
71              File modulePom = new File( projectPath + "/" + module, pomFilename );
72  
73              MavenProject subproject = createMavenProject( modulePom );
74  
75              reactorProjects.add( subproject );
76          }
77  
78          return reactorProjects;
79      }
80  
81      private MavenProject createMavenProject( File pomFile )
82          throws Exception
83      {
84          MavenXpp3Reader reader = new MavenXpp3Reader();
85  
86          Model model = reader.read( ReaderFactory.newXmlReader( pomFile ) );
87  
88          MavenProject project = new MavenProject( model );
89  
90          project.setFile( pomFile );
91  
92          return project;
93      }
94  
95  }