1 package org.apache.maven.plugin.reactor;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Arrays;
24 import java.util.List;
25
26 import org.apache.maven.plugin.AbstractMojo;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugin.MojoFailureException;
29 import org.apache.maven.project.MavenProject;
30 import org.apache.maven.project.ProjectSorter;
31 import org.apache.maven.shared.invoker.Invoker;
32
33
34
35
36
37
38
39
40
41 public class ResumeMojo
42 extends AbstractMojo
43 {
44
45
46
47
48 List collectedProjects;
49
50
51
52
53
54 File baseDir;
55
56
57
58
59 String continueFromGroup;
60
61
62
63
64
65
66 String continueFromProject;
67
68
69
70
71
72
73 File continueFromFolder;
74
75
76
77
78
79 String goals;
80
81
82
83
84 Invoker invoker;
85
86
87
88
89
90 boolean printOnly = false;
91
92
93
94
95 SimpleInvoker simpleInvoker;
96
97 public void execute()
98 throws MojoExecutionException, MojoFailureException
99 {
100 if ( "null".equals( continueFromProject ) )
101 {
102 continueFromProject = null;
103 }
104 if ( new File( "null" ).equals( continueFromFolder ) )
105 {
106 continueFromFolder = null;
107 }
108 if ( continueFromFolder == null && continueFromProject == null )
109 {
110 throw new MojoFailureException("You must specify either a folder or a project with -Dfrom=baz/bar or -DfromArtifact=com.mycompany:foo (groupId is optional)");
111 }
112 if (continueFromFolder != null && continueFromProject != null )
113 {
114 throw new MojoFailureException("You can't specify both a folder (" + continueFromFolder + ") and an artifact (" + continueFromProject + ")");
115 }
116 if ( continueFromFolder != null && !continueFromFolder.exists() )
117 {
118 throw new MojoFailureException("Folder doesn't exist: " + continueFromFolder.getAbsolutePath() );
119 }
120 String[] reactorIncludes;
121 try
122 {
123
124 if (collectedProjects.size() == 0) {
125 throw new NonReactorException();
126 }
127 ProjectSorter ps = new ProjectSorter( collectedProjects );
128
129 List sortedProjects = ps.getSortedProjects();
130
131 String projectName = null;
132 if ( continueFromProject != null)
133 {
134 projectName = continueFromProject;
135 if ( projectName.indexOf(':') != -1 ) {
136 int index = continueFromProject.indexOf(':');
137 continueFromGroup = continueFromProject.substring( 0, index );
138 projectName = continueFromProject.substring( index+1 );
139 }
140 }
141
142 boolean found = false;
143 int i = 0;
144 for (; i < sortedProjects.size(); i++) {
145 MavenProject mp = (MavenProject) sortedProjects.get( i );
146 if ( continueFromFolder == null )
147 {
148 if ( continueFromGroup.equals( mp.getGroupId() ) && projectName.equals( mp.getArtifactId() ) )
149 {
150 found = true;
151 break;
152 }
153 } else {
154 if ( continueFromFolder.equals( mp.getFile().getParentFile() ) )
155 {
156 found = true;
157 break;
158 }
159 }
160 }
161
162 if (!found) throw new MissingProjectException(continueFromGroup + ":" + projectName);
163
164
165 reactorIncludes = new String[sortedProjects.size() - i];
166 for ( int j = i; j < sortedProjects.size(); j++ )
167 {
168 MavenProject mp = (MavenProject) sortedProjects.get( j );
169 String path = RelativePather.getRelativePath( baseDir, mp.getFile() );
170 reactorIncludes[j- i] = path;
171 }
172 }
173 catch (MojoFailureException e) {
174 throw e;
175 }
176 catch ( Exception e )
177 {
178 throw new MojoExecutionException( "Problem generating dependency tree", e );
179 }
180
181 simpleInvoker.runReactor( reactorIncludes, Arrays.asList( goals.split( "," ) ), invoker, printOnly, getLog() );
182
183 }
184 }