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 org.apache.continuum.buildagent.build.execution.AbstractBuildExecutor;
23  import org.apache.continuum.buildagent.build.execution.ContinuumAgentBuildCancelledException;
24  import org.apache.continuum.buildagent.build.execution.ContinuumAgentBuildExecutionResult;
25  import org.apache.continuum.buildagent.build.execution.ContinuumAgentBuildExecutor;
26  import org.apache.continuum.buildagent.build.execution.ContinuumAgentBuildExecutorException;
27  import org.apache.continuum.buildagent.installation.BuildAgentInstallationService;
28  import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
29  import org.apache.maven.continuum.model.project.BuildDefinition;
30  import org.apache.maven.continuum.model.project.Project;
31  import org.codehaus.plexus.util.StringUtils;
32  
33  import java.io.File;
34  import java.util.Enumeration;
35  import java.util.Map;
36  import java.util.Properties;
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, File buildOutput,
54                                                       Map<String, String> environments, String localRepository )
55          throws ContinuumAgentBuildExecutorException, ContinuumAgentBuildCancelledException
56      {
57          String executable = getBuildAgentInstallationService().getExecutorConfigurator(
58              BuildAgentInstallationService.ANT_TYPE ).getExecutable();
59  
60          StringBuffer arguments = new StringBuffer();
61  
62          String buildFile = getBuildFileForProject( buildDefinition );
63  
64          if ( !StringUtils.isEmpty( buildFile ) )
65          {
66              arguments.append( "-f " ).append( buildFile ).append( " " );
67          }
68  
69          arguments.append( StringUtils.clean( buildDefinition.getArguments() ) ).append( " " );
70  
71          Properties props = getContinuumSystemProperties( project );
72          for ( Enumeration itr = props.propertyNames(); itr.hasMoreElements(); )
73          {
74              String name = (String) itr.nextElement();
75              String value = props.getProperty( name );
76              arguments.append( "\"-D" ).append( name ).append( "=" ).append( value ).append( "\" " );
77          }
78  
79          arguments.append( StringUtils.clean( buildDefinition.getGoals() ) );
80  
81          String antHome = null;
82  
83          if ( environments != null )
84          {
85              antHome = environments.get( getBuildAgentInstallationService().getEnvVar(
86                  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 }