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 java.io.File;
23  import java.util.Map;
24  
25  import org.apache.continuum.release.config.ContinuumReleaseDescriptor;
26  import org.apache.continuum.utils.shell.ShellCommandHelper;
27  import org.apache.maven.continuum.installation.InstallationService;
28  import org.apache.maven.shared.release.ReleaseExecutionException;
29  import org.apache.maven.shared.release.ReleaseResult;
30  import org.apache.maven.shared.release.config.ReleaseDescriptor;
31  import org.apache.maven.shared.release.phase.AbstractRunGoalsPhase;
32  import org.codehaus.plexus.util.StringUtils;
33  
34  /**
35   * @author <a href="mailto:ctan@apache.org">Maria Catherine Tan</a>
36   */
37  public abstract class AbstractContinuumRunGoalsPhase
38      extends AbstractRunGoalsPhase
39  {
40      /**
41       * @plexus.requirement
42       */
43      private ShellCommandHelper shellCommandHelper;
44  
45      /**
46       * @plexus.requirement
47       */
48      private InstallationService installationService;
49  
50      public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, File workingDirectory,
51                                    String additionalArguments )
52          throws ReleaseExecutionException
53      {
54          ReleaseResult result = new ReleaseResult();
55          
56          try
57          {
58              String goals = getGoals( releaseDescriptor );
59              if ( !StringUtils.isEmpty( goals ) )
60              {
61                  Map<String, String> environments = null;
62  
63                  String executable = null;
64  
65                  if ( releaseDescriptor instanceof ContinuumReleaseDescriptor )
66                  {
67                      environments = ( (ContinuumReleaseDescriptor) releaseDescriptor ).getEnvironments();
68  
69                      executable = ( (ContinuumReleaseDescriptor) releaseDescriptor).getExecutable();
70                  }
71  
72                  shellCommandHelper.executeGoals( determineWorkingDirectory( workingDirectory,
73                                                                              releaseDescriptor.getScmRelativePathProjectDirectory() ),
74                                                   executable, goals, releaseDescriptor.isInteractive(), additionalArguments, result, 
75                                                   environments );
76              }
77          }
78          catch ( Exception e )
79          {
80              throw new ReleaseExecutionException( result.getOutput(), e );
81          }
82  
83          result.setResultCode( ReleaseResult.SUCCESS );
84  
85          return result;
86      }
87  }