View Javadoc

1   package org.apache.maven.continuum.execution.shell;
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.execution.AbstractBuildExecutor;
23  import org.apache.maven.continuum.execution.ContinuumBuildExecutionResult;
24  import org.apache.maven.continuum.execution.ContinuumBuildExecutor;
25  import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
26  import org.apache.maven.continuum.execution.ContinuumBuildExecutorException;
27  import org.apache.maven.continuum.installation.InstallationService;
28  import org.apache.maven.continuum.model.project.BuildDefinition;
29  import org.apache.maven.continuum.model.project.Project;
30  import org.apache.maven.continuum.model.scm.ScmResult;
31  import org.apache.maven.continuum.model.system.Installation;
32  import org.apache.maven.continuum.model.system.Profile;
33  import org.codehaus.plexus.util.StringUtils;
34  
35  import java.io.File;
36  import java.util.Collections;
37  import java.util.HashMap;
38  import java.util.List;
39  import java.util.Map;
40  
41  /**
42   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
43   * @version $Id: ShellBuildExecutor.java 1372260 2012-08-13 04:29:09Z brett $
44   */
45  public class ShellBuildExecutor
46      extends AbstractBuildExecutor
47      implements ContinuumBuildExecutor
48  {
49      // ----------------------------------------------------------------------
50      //
51      // ----------------------------------------------------------------------
52  
53      public static final String CONFIGURATION_EXECUTABLE = "executable";
54  
55      public static final String ID = ContinuumBuildExecutorConstants.SHELL_BUILD_EXECUTOR;
56  
57      // ----------------------------------------------------------------------
58      //
59      // ----------------------------------------------------------------------
60  
61      public ShellBuildExecutor()
62      {
63          super( ID, false );
64      }
65  
66      // ----------------------------------------------------------------------
67      // ContinuumBuilder implementation
68      // ----------------------------------------------------------------------
69  
70      public synchronized ContinuumBuildExecutionResult build( Project project, BuildDefinition buildDefinition,
71                                                               File buildOutput, List<Project> projectsWithCommonScmRoot,
72                                                               String projectScmRootUrl )
73          throws ContinuumBuildExecutorException
74      {
75          // TODO: this should be validated earlier?
76          String executable = getBuildFileForProject( project, buildDefinition );
77  
78          return executeShellCommand( project, executable, buildDefinition.getArguments(), buildOutput, getEnvironments(
79              buildDefinition ), null, null );
80      }
81  
82      protected Map<String, String> getEnvironments( BuildDefinition buildDefinition )
83      {
84          Profile profile = buildDefinition.getProfile();
85          if ( profile == null )
86          {
87              return Collections.EMPTY_MAP;
88          }
89          Map<String, String> envVars = new HashMap<String, String>();
90          String javaHome = getJavaHomeValue( buildDefinition );
91          if ( !StringUtils.isEmpty( javaHome ) )
92          {
93              envVars.put( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), javaHome );
94          }
95          Installation builder = profile.getBuilder();
96          if ( builder != null )
97          {
98              envVars.put( builder.getVarName(), builder.getVarValue() );
99          }
100         envVars.putAll( getEnvironmentVariables( buildDefinition ) );
101         return envVars;
102 
103     }
104 
105     public void updateProjectFromCheckOut( File workingDirectory, Project project, BuildDefinition buildDefinition,
106                                            ScmResult scmResult )
107         throws ContinuumBuildExecutorException
108     {
109     }
110 }