EMMA Coverage Report (generated Sun Sep 18 11:34:27 PHT 2011)
[all classes][org.apache.maven.continuum.execution.maven.m1]

COVERAGE SUMMARY FOR SOURCE FILE [MavenOneBuildExecutor.java]

nameclass, %method, %block, %line, %
MavenOneBuildExecutor.java100% (1/1)67%  (4/6)15%  (37/242)25%  (13/53)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MavenOneBuildExecutor100% (1/1)67%  (4/6)15%  (37/242)25%  (13/53)
build (Project, BuildDefinition, File): ContinuumBuildExecutionResult 0%   (0/1)0%   (0/133)0%   (0/22)
getEnvironments (BuildDefinition): Map 0%   (0/1)0%   (0/47)0%   (0/12)
updateProjectFromCheckOut (File, Project, BuildDefinition): void 100% (1/1)50%  (25/50)57%  (8/14)
MavenOneBuildExecutor (): void 100% (1/1)100% (5/5)100% (2/2)
getMetadataHelper (): MavenOneMetadataHelper 100% (1/1)100% (3/3)100% (1/1)
setMetadataHelper (MavenOneMetadataHelper): void 100% (1/1)100% (4/4)100% (2/2)

1package org.apache.maven.continuum.execution.maven.m1;
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 
22import java.io.File;
23import java.util.Collections;
24import java.util.Enumeration;
25import java.util.HashMap;
26import java.util.Map;
27import java.util.Properties;
28 
29import org.apache.continuum.model.repository.LocalRepository;
30import org.apache.maven.continuum.execution.AbstractBuildExecutor;
31import org.apache.maven.continuum.execution.ContinuumBuildExecutionResult;
32import org.apache.maven.continuum.execution.ContinuumBuildExecutor;
33import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
34import org.apache.maven.continuum.execution.ContinuumBuildExecutorException;
35import org.apache.maven.continuum.installation.InstallationService;
36import org.apache.maven.continuum.model.project.BuildDefinition;
37import org.apache.maven.continuum.model.project.Project;
38import org.apache.maven.continuum.model.system.Installation;
39import org.apache.maven.continuum.model.system.Profile;
40import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
41import org.codehaus.plexus.util.StringUtils;
42 
43/**
44 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
45 * @version $Id: MavenOneBuildExecutor.java 764863 2009-04-14 16:28:12Z evenisse $
46 */
47public class MavenOneBuildExecutor
48    extends AbstractBuildExecutor
49    implements ContinuumBuildExecutor
50{
51    public final static String CONFIGURATION_GOALS = "goals";
52 
53    public final static String ID = ContinuumBuildExecutorConstants.MAVEN_ONE_BUILD_EXECUTOR;
54 
55    /**
56     * @plexus.requirement
57     */
58    private MavenOneMetadataHelper metadataHelper;
59 
60    // ----------------------------------------------------------------------
61    //
62    // ----------------------------------------------------------------------
63 
64    public MavenOneBuildExecutor()
65    {
66        super( ID, true );
67    }
68 
69    public MavenOneMetadataHelper getMetadataHelper()
70    {
71        return metadataHelper;
72    }
73 
74    public void setMetadataHelper( MavenOneMetadataHelper metadataHelper )
75    {
76        this.metadataHelper = metadataHelper;
77    }
78 
79    // ----------------------------------------------------------------------
80    // Builder Implementation
81    // ----------------------------------------------------------------------
82 
83    public ContinuumBuildExecutionResult build( Project project, BuildDefinition buildDefinition, File buildOutput )
84        throws ContinuumBuildExecutorException
85    {
86        String executable =
87            getInstallationService().getExecutorConfigurator( InstallationService.MAVEN1_TYPE ).getExecutable();
88 
89        StringBuffer arguments = new StringBuffer();
90 
91        String buildFile = getBuildFileForProject( project, buildDefinition );
92 
93        if ( !StringUtils.isEmpty( buildFile ) && !"project.xml".equals( buildFile ) )
94        {
95            arguments.append( "-p " ).append( buildFile ).append( " " );
96        }
97 
98        arguments.append( StringUtils.clean( buildDefinition.getArguments() ) ).append( " " );
99 
100        Properties props = getContinuumSystemProperties( project );
101        for ( Enumeration itr = props.propertyNames(); itr.hasMoreElements(); )
102        {
103            String name = (String) itr.nextElement();
104            String value = props.getProperty( name );
105            arguments.append( "\"-D" ).append( name ).append( "=" ).append( value ).append( "\" " );
106        }
107 
108        // append -Dmaven.repo.local if project group has a local repository
109        LocalRepository repository = project.getProjectGroup().getLocalRepository();
110        if ( repository != null )
111        {
112            arguments.append( "\"-Dmaven.repo.local=" ).append( StringUtils.clean( repository.getLocation() ) ).append(
113                "\" " );
114        }
115 
116        arguments.append( StringUtils.clean( buildDefinition.getGoals() ) );
117 
118        Map<String, String> environments = getEnvironments( buildDefinition );
119        String m1Home = environments.get( getInstallationService().getEnvVar( InstallationService.MAVEN1_TYPE ) );
120        if ( StringUtils.isNotEmpty( m1Home ) )
121        {
122            executable = m1Home + File.separator + "bin" + File.separator + executable;
123            setResolveExecutable( false );
124        }
125 
126        return executeShellCommand( project, executable, arguments.toString(), buildOutput, environments );
127    }
128 
129    protected Map<String, String> getEnvironments( BuildDefinition buildDefinition )
130    {
131        Profile profile = buildDefinition.getProfile();
132        if ( profile == null )
133        {
134            return Collections.EMPTY_MAP;
135        }
136        Map<String, String> envVars = new HashMap<String, String>();
137        String javaHome = getJavaHomeValue( buildDefinition );
138        if ( !StringUtils.isEmpty( javaHome ) )
139        {
140            envVars.put( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), javaHome );
141        }
142        Installation builder = profile.getBuilder();
143        if ( builder != null )
144        {
145            envVars.put( getInstallationService().getEnvVar( InstallationService.MAVEN1_TYPE ), builder.getVarValue() );
146        }
147        envVars.putAll( getEnvironmentVariables( buildDefinition ) );
148        return envVars;
149 
150    }
151 
152    public void updateProjectFromCheckOut( File workingDirectory, Project project, BuildDefinition buildDefinition )
153        throws ContinuumBuildExecutorException
154    {
155        File projectXmlFile = null;
156 
157        if ( buildDefinition != null )
158        {
159            String buildFile = StringUtils.clean( buildDefinition.getBuildFile() );
160 
161            if ( !StringUtils.isEmpty( buildFile ) )
162            {
163                projectXmlFile = new File( workingDirectory, buildFile );
164            }
165        }
166 
167        if ( projectXmlFile == null )
168        {
169            projectXmlFile = new File( workingDirectory, "project.xml" );
170        }
171 
172        if ( !projectXmlFile.exists() )
173        {
174            throw new ContinuumBuildExecutorException( "Could not find Maven project descriptor." );
175        }
176 
177        try
178        {
179            metadataHelper.mapMetadata( new ContinuumProjectBuildingResult(), projectXmlFile, project );
180        }
181        catch ( MavenOneMetadataHelperException e )
182        {
183            throw new ContinuumBuildExecutorException( "Error while mapping metadata.", e );
184        }
185    }
186}

[all classes][org.apache.maven.continuum.execution.maven.m1]
EMMA 2.0.5312 (C) Vladimir Roubtsov