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