View Javadoc

1   package org.apache.continuum.buildagent.build.execution.ant;
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.Enumeration;
24  import java.util.Map;
25  import java.util.Properties;
26  
27  import org.apache.continuum.buildagent.build.execution.AbstractBuildExecutor;
28  import org.apache.continuum.buildagent.build.execution.ContinuumAgentBuildCancelledException;
29  import org.apache.continuum.buildagent.build.execution.ContinuumAgentBuildExecutionResult;
30  import org.apache.continuum.buildagent.build.execution.ContinuumAgentBuildExecutor;
31  import org.apache.continuum.buildagent.build.execution.ContinuumAgentBuildExecutorException;
32  import org.apache.continuum.buildagent.installation.BuildAgentInstallationService;
33  import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
34  import org.apache.maven.continuum.model.project.BuildDefinition;
35  import org.apache.maven.continuum.model.project.Project;
36  import org.codehaus.plexus.util.StringUtils;
37  
38  public class AntBuildExecutor
39      extends AbstractBuildExecutor   
40      implements ContinuumAgentBuildExecutor
41  {
42      public static final String CONFIGURATION_EXECUTABLE = "executable";
43  
44      public static final String CONFIGURATION_TARGETS = "targets";
45  
46      public static final String ID = ContinuumBuildExecutorConstants.ANT_BUILD_EXECUTOR;
47  
48      protected AntBuildExecutor()
49      {
50          super( ID, true );
51      }
52  
53      public ContinuumAgentBuildExecutionResult build( Project project, BuildDefinition buildDefinition, 
54                                                       File buildOutput, Map<String, String> environments,
55                                                       String localRepository )
56          throws ContinuumAgentBuildExecutorException, ContinuumAgentBuildCancelledException
57      {
58          String executable = getBuildAgentInstallationService().getExecutorConfigurator( BuildAgentInstallationService.ANT_TYPE )
59              .getExecutable();
60  
61          StringBuffer arguments = new StringBuffer();
62      
63          String buildFile = getBuildFileForProject( buildDefinition );
64      
65          if ( !StringUtils.isEmpty( buildFile ) )
66          {
67              arguments.append( "-f " ).append( buildFile ).append( " " );
68          }
69      
70          arguments.append( StringUtils.clean( buildDefinition.getArguments() ) ).append( " " );
71      
72          Properties props = getContinuumSystemProperties( project );
73          for ( Enumeration itr = props.propertyNames(); itr.hasMoreElements(); )
74          {
75              String name = (String) itr.nextElement();
76              String value = props.getProperty( name );
77              arguments.append( "\"-D" ).append( name ).append( "=" ).append( value ).append( "\" " );
78          }
79  
80          arguments.append( StringUtils.clean( buildDefinition.getGoals() ) );
81  
82          String antHome = null;
83  
84          if ( environments != null )
85          {
86              antHome = environments.get( getBuildAgentInstallationService().getEnvVar( BuildAgentInstallationService.ANT_TYPE ) );
87          }
88  
89          if ( StringUtils.isNotEmpty( antHome ) )
90          {
91              executable = antHome + File.separator + "bin" + File.separator + executable;
92              setResolveExecutable( false );
93          }
94  
95          return executeShellCommand( project, executable, arguments.toString(), buildOutput, environments );
96      }
97  
98      public void updateProjectFromWorkingDirectory( File workingDirectory, Project project,
99                                                     BuildDefinition buildDefinition )
100         throws ContinuumAgentBuildExecutorException
101     {
102         // nothing to do here
103     }
104 }