1 | package org.apache.maven.continuum.release.executors; |
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.continuum.release.ContinuumReleaseException; |
23 | import org.apache.maven.continuum.release.ContinuumReleaseManager; |
24 | import org.apache.maven.continuum.release.tasks.ReleaseProjectTask; |
25 | import org.apache.maven.settings.MavenSettingsBuilder; |
26 | import org.apache.maven.settings.Settings; |
27 | import org.apache.maven.shared.release.ReleaseManager; |
28 | import org.apache.maven.shared.release.ReleaseResult; |
29 | import org.codehaus.plexus.taskqueue.Task; |
30 | import org.codehaus.plexus.taskqueue.execution.TaskExecutionException; |
31 | import org.codehaus.plexus.util.xml.pull.XmlPullParserException; |
32 | |
33 | import java.io.IOException; |
34 | |
35 | /** |
36 | * @author Edwin Punzalan |
37 | * @version $Id: AbstractReleaseTaskExecutor.java 729313 2008-12-24 13:41:11Z olamy $ |
38 | */ |
39 | public abstract class AbstractReleaseTaskExecutor |
40 | implements ReleaseTaskExecutor |
41 | { |
42 | /** |
43 | * @plexus.requirement |
44 | */ |
45 | protected ContinuumReleaseManager continuumReleaseManager; |
46 | |
47 | /** |
48 | * @plexus.requirement |
49 | */ |
50 | protected ReleaseManager releaseManager; |
51 | |
52 | /** |
53 | * @plexus.requirement |
54 | */ |
55 | private MavenSettingsBuilder settingsBuilder; |
56 | |
57 | protected Settings settings; |
58 | |
59 | private long startTime; |
60 | |
61 | public void executeTask( Task task ) |
62 | throws TaskExecutionException |
63 | { |
64 | ReleaseProjectTask releaseTask = (ReleaseProjectTask) task; |
65 | |
66 | setUp( releaseTask ); |
67 | |
68 | execute( releaseTask ); |
69 | } |
70 | |
71 | protected void setUp( ReleaseProjectTask releaseTask ) |
72 | throws TaskExecutionException |
73 | { |
74 | //actual release execution start time |
75 | setStartTime( System.currentTimeMillis() ); |
76 | |
77 | try |
78 | { |
79 | //make sure settings is re-read each time |
80 | settings = getSettings(); |
81 | } |
82 | catch ( ContinuumReleaseException e ) |
83 | { |
84 | ReleaseResult result = createReleaseResult(); |
85 | |
86 | result.appendError( e ); |
87 | |
88 | continuumReleaseManager.getReleaseResults().put( releaseTask.getReleaseId(), result ); |
89 | |
90 | releaseTask.getListener().error( e.getMessage() ); |
91 | |
92 | throw new TaskExecutionException( "Failed to build reactor projects.", e ); |
93 | } |
94 | } |
95 | |
96 | protected abstract void execute( ReleaseProjectTask releaseTask ) |
97 | throws TaskExecutionException; |
98 | |
99 | private Settings getSettings() |
100 | throws ContinuumReleaseException |
101 | { |
102 | try |
103 | { |
104 | settings = settingsBuilder.buildSettings( false ); |
105 | } |
106 | catch ( IOException e ) |
107 | { |
108 | throw new ContinuumReleaseException( "Failed to get Maven Settings.", e ); |
109 | } |
110 | catch ( XmlPullParserException e ) |
111 | { |
112 | throw new ContinuumReleaseException( "Failed to get Maven Settings.", e ); |
113 | } |
114 | |
115 | return settings; |
116 | } |
117 | |
118 | protected ReleaseResult createReleaseResult() |
119 | { |
120 | ReleaseResult result = new ReleaseResult(); |
121 | |
122 | result.setStartTime( getStartTime() ); |
123 | |
124 | result.setEndTime( System.currentTimeMillis() ); |
125 | |
126 | return result; |
127 | } |
128 | |
129 | protected long getStartTime() |
130 | { |
131 | return startTime; |
132 | } |
133 | |
134 | protected void setStartTime( long startTime ) |
135 | { |
136 | this.startTime = startTime; |
137 | } |
138 | } |