View Javadoc

1   package org.apache.continuum.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.continuum.release.config.ContinuumReleaseDescriptor;
23  import org.apache.continuum.utils.shell.ShellCommandHelper;
24  import org.apache.maven.continuum.installation.InstallationService;
25  import org.apache.maven.shared.release.ReleaseExecutionException;
26  import org.apache.maven.shared.release.ReleaseFailureException;
27  import org.apache.maven.shared.release.ReleaseResult;
28  import org.apache.maven.shared.release.config.ReleaseDescriptor;
29  import org.apache.maven.shared.release.env.ReleaseEnvironment;
30  import org.apache.maven.shared.release.phase.AbstractRunGoalsPhase;
31  import org.codehaus.plexus.util.StringUtils;
32  
33  import java.io.File;
34  import java.util.List;
35  import java.util.Map;
36  
37  /**
38   * @author <a href="mailto:ctan@apache.org">Maria Catherine Tan</a>
39   */
40  public abstract class AbstractContinuumRunGoalsPhase
41      extends AbstractRunGoalsPhase
42  {
43      /**
44       * @plexus.requirement
45       */
46      private ShellCommandHelper shellCommandHelper;
47  
48      /**
49       * @plexus.requirement
50       */
51      private InstallationService installationService;
52  
53      /**
54       * TODO olamy use maven-invoker with an installation (jdk, mvn path, env var)
55       */
56      public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, File workingDirectory,
57                                    String additionalArguments )
58          throws ReleaseExecutionException
59      {
60          ReleaseResult result = new ReleaseResult();
61  
62          try
63          {
64              String goals = getGoals( releaseDescriptor );
65              if ( !StringUtils.isEmpty( goals ) )
66              {
67                  Map<String, String> environments = null;
68  
69                  String executable = null;
70  
71                  if ( releaseDescriptor instanceof ContinuumReleaseDescriptor )
72                  {
73                      environments = ( (ContinuumReleaseDescriptor) releaseDescriptor ).getEnvironments();
74  
75                      executable = ( (ContinuumReleaseDescriptor) releaseDescriptor ).getExecutable();
76                  }
77                  shellCommandHelper.executeGoals( determineWorkingDirectory( workingDirectory,
78                                                                              releaseDescriptor.getScmRelativePathProjectDirectory() ),
79                                                   executable, goals, releaseDescriptor.isInteractive(),
80                                                   additionalArguments, result, environments );
81              }
82          }
83          catch ( Exception e )
84          {
85              throw new ReleaseExecutionException( result.getOutput(), e );
86          }
87  
88          result.setResultCode( ReleaseResult.SUCCESS );
89  
90          return result;
91      }
92  
93      @Override
94      public ReleaseResult execute( ReleaseDescriptor arg0, ReleaseEnvironment arg1, File arg2, String arg3 )
95          throws ReleaseExecutionException
96      {
97          return super.execute( arg0, arg1, arg2, arg3 );
98      }
99  
100     public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
101                                   List reactorProjects )
102         throws ReleaseExecutionException, ReleaseFailureException
103     {
104 
105         return execute( releaseDescriptor, new File( releaseDescriptor.getWorkingDirectory() ),
106                         releaseDescriptor.getAdditionalArguments() );
107     }
108 
109     public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
110                                    List reactorProjects )
111         throws ReleaseExecutionException, ReleaseFailureException
112     {
113         return execute( releaseDescriptor, new File( releaseDescriptor.getWorkingDirectory() ),
114                         releaseDescriptor.getAdditionalArguments() );
115     }
116 }