1 package org.apache.maven.shared.release.phase;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.ArtifactUtils;
23 import org.apache.maven.project.MavenProject;
24 import org.apache.maven.scm.manager.NoSuchScmProviderException;
25 import org.apache.maven.scm.repository.ScmRepositoryException;
26 import org.apache.maven.shared.release.ReleaseExecutionException;
27 import org.apache.maven.shared.release.ReleaseFailureException;
28 import org.apache.maven.shared.release.ReleaseResult;
29 import org.apache.maven.shared.release.config.ReleaseDescriptor;
30 import org.apache.maven.shared.release.env.ReleaseEnvironment;
31 import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
32 import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
33 import org.codehaus.plexus.util.StringUtils;
34
35 import java.util.List;
36
37
38
39
40
41
42 public class CheckPomPhase
43 extends AbstractReleasePhase
44 {
45
46
47
48
49 private boolean scmRequired = true;
50
51
52
53
54 private boolean snapshotsRequired = true;
55
56 private ScmRepositoryConfigurator scmRepositoryConfigurator;
57
58 @Override
59 public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
60 List<MavenProject> reactorProjects )
61 throws ReleaseExecutionException, ReleaseFailureException
62 {
63 ReleaseResult result = new ReleaseResult();
64
65
66 if ( scmRequired )
67 {
68 if ( StringUtils.isEmpty( releaseDescriptor.getScmSourceUrl() ) )
69 {
70 throw new ReleaseFailureException(
71 "Missing required setting: scm connection or developerConnection must be specified." );
72 }
73
74 try
75 {
76 scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor,
77 releaseEnvironment.getSettings() );
78 }
79 catch ( ScmRepositoryException e )
80 {
81 throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages() );
82 }
83 catch ( NoSuchScmProviderException e )
84 {
85 throw new ReleaseFailureException(
86 "The provider given in the SCM URL could not be found: " + e.getMessage() );
87 }
88 }
89
90 boolean containsSnapshotProjects = false;
91
92 for ( MavenProject project : reactorProjects )
93 {
94 if ( ArtifactUtils.isSnapshot( project.getVersion() ) )
95 {
96 containsSnapshotProjects = true;
97
98 break;
99 }
100 }
101
102 if ( snapshotsRequired && !containsSnapshotProjects && !releaseDescriptor.isBranchCreation() )
103 {
104 throw new ReleaseFailureException( "You don't have a SNAPSHOT project in the reactor projects list." );
105 }
106
107 result.setResultCode( ReleaseResult.SUCCESS );
108
109 return result;
110 }
111
112 @Override
113 public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
114 List<MavenProject> reactorProjects )
115 throws ReleaseExecutionException, ReleaseFailureException
116 {
117
118 return execute( releaseDescriptor, releaseEnvironment, reactorProjects );
119 }
120 }