View Javadoc

1   package org.apache.maven.shared.release.exec;
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.shared.release.ReleaseResult;
23  import org.apache.maven.shared.release.env.DefaultReleaseEnvironment;
24  import org.apache.maven.shared.release.env.ReleaseEnvironment;
25  import org.codehaus.plexus.logging.LogEnabled;
26  import org.codehaus.plexus.logging.Logger;
27  import org.codehaus.plexus.util.StringUtils;
28  
29  import java.io.File;
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  public abstract class AbstractMavenExecutor
34      implements MavenExecutor, LogEnabled
35  {
36  
37      private Logger logger;
38  
39      protected AbstractMavenExecutor()
40      {
41      }
42  
43      /** {@inheritDoc} */
44      public void executeGoals( File workingDirectory, String goals, boolean interactive, String additionalArguments,
45                                String pomFileName, ReleaseResult result )
46          throws MavenExecutorException
47      {
48          executeGoals( workingDirectory, goals, new DefaultReleaseEnvironment(), interactive, additionalArguments, pomFileName, result );
49      }
50  
51      /** {@inheritDoc} */
52      public void executeGoals( File workingDirectory, String goals, boolean interactive, String additionalArguments,
53                                ReleaseResult result )
54          throws MavenExecutorException
55      {
56          executeGoals( workingDirectory, goals, new DefaultReleaseEnvironment(), interactive, additionalArguments, result );
57      }
58  
59      /** {@inheritDoc} */
60      public void executeGoals( File workingDirectory, String goals, ReleaseEnvironment releaseEnvironment,
61                                boolean interactive, String arguments, ReleaseResult result )
62          throws MavenExecutorException
63      {
64          executeGoals( workingDirectory, goals, releaseEnvironment, interactive, arguments, null, result );
65      }
66  
67      /** {@inheritDoc} */
68      public void executeGoals( File workingDirectory, String goals, ReleaseEnvironment releaseEnvironment,
69                                boolean interactive, String additionalArguments, String pomFileName, ReleaseResult result )
70          throws MavenExecutorException
71      {
72          List<String> goalsList = new ArrayList<String>();
73          if ( goals != null )
74          {
75              // accept both space and comma, so the old way still work
76              // also accept line separators, so that goal lists can be spread
77              // across multiple lines in the POM.
78              String[] tokens = StringUtils.split( goals, ", \n\r\t" );
79  
80              for ( int i = 0; i < tokens.length; ++i )
81              {
82                  goalsList.add( tokens[i] );
83              }
84          }
85          executeGoals( workingDirectory, goalsList, releaseEnvironment, interactive, additionalArguments, pomFileName, result );
86      }
87  
88      protected abstract void executeGoals( File workingDirectory, List<String> goals, ReleaseEnvironment releaseEnvironment,
89                                boolean interactive, String additionalArguments, String pomFileName, ReleaseResult result )
90          throws MavenExecutorException;
91  
92  
93      protected final Logger getLogger()
94      {
95          return logger;
96      }
97  
98      /** {@inheritDoc} */
99      public void enableLogging( Logger logger )
100     {
101         this.logger = logger;
102     }
103 }