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

COVERAGE SUMMARY FOR SOURCE FILE [AddMavenTwoProjectAction.java]

nameclass, %method, %block, %line, %
AddMavenTwoProjectAction.java0%   (0/1)0%   (0/8)0%   (0/145)0%   (0/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AddMavenTwoProjectAction0%   (0/1)0%   (0/8)0%   (0/145)0%   (0/39)
AddMavenTwoProjectAction (): void 0%   (0/1)0%   (0/3)0%   (0/1)
doExecute (String, int, boolean, boolean): ContinuumProjectBuildingResult 0%   (0/1)0%   (0/121)0%   (0/29)
getM2PomFile (): File 0%   (0/1)0%   (0/3)0%   (0/1)
getM2PomUrl (): String 0%   (0/1)0%   (0/3)0%   (0/1)
isNonRecursiveProject (): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
setM2PomFile (File): void 0%   (0/1)0%   (0/4)0%   (0/2)
setM2PomUrl (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
setNonRecursiveProject (boolean): void 0%   (0/1)0%   (0/4)0%   (0/2)

1package org.apache.maven.continuum.web.action;
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.io.FileNotFoundException;
24import java.io.FileReader;
25import java.io.IOException;
26import java.util.List;
27 
28import org.apache.continuum.web.util.AuditLog;
29import org.apache.continuum.web.util.AuditLogConstants;
30import org.apache.maven.continuum.ContinuumException;
31import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
32import org.apache.maven.model.Model;
33import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
34import org.codehaus.plexus.util.StringUtils;
35import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
36 
37/**
38 * Add a Maven 2 project to Continuum.
39 *
40 * @author Nick Gonzalez
41 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
42 * @version $Id: AddMavenTwoProjectAction.java 781924 2009-06-05 06:42:54Z ctan $
43 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="addMavenTwoProject"
44 */
45public class AddMavenTwoProjectAction
46    extends AddMavenProjectAction
47{
48    // TODO: remove this part once uploading of an m2 project with modules is supported ( CONTINUUM-1098 )
49    public static final String ERROR_UPLOADING_M2_PROJECT_WITH_MODULES = "add.m2.project.upload.modules.error";
50 
51    public static final String ERROR_READING_POM_EXCEPTION_MESSAGE = "Error reading POM";
52 
53    public static final String FILE_SCHEME = "file:/";
54 
55    private boolean nonRecursiveProject;
56 
57    protected ContinuumProjectBuildingResult doExecute( String pomUrl, int selectedProjectGroup, boolean checkProtocol,
58                                                        boolean scmUseCache )
59        throws ContinuumException
60    {
61        ContinuumProjectBuildingResult result = null;
62 
63        // TODO: remove this part once uploading of an m2 project with modules is supported ( CONTINUUM-1098 )
64        if ( !checkProtocol )
65        {
66            MavenXpp3Reader m2pomReader = new MavenXpp3Reader();
67 
68            try
69            {
70                String filePath = pomUrl;
71 
72                if ( !filePath.startsWith( FILE_SCHEME + "/" ) && filePath.startsWith( FILE_SCHEME ) )
73                {
74                    //Little hack for linux (CONTINUUM-1169)
75                    filePath = StringUtils.replace( filePath, FILE_SCHEME, FILE_SCHEME + "/" );
76                }
77 
78                if ( filePath.startsWith( FILE_SCHEME ) )
79                {
80                    filePath = filePath.substring( FILE_SCHEME.length() );
81                }
82 
83                Model model = m2pomReader.read( new FileReader( filePath ) );
84 
85                List modules = model.getModules();
86 
87                if ( modules != null && modules.size() != 0 )
88                {
89                    result = new ContinuumProjectBuildingResult();
90                    result.addError( ERROR_UPLOADING_M2_PROJECT_WITH_MODULES );
91                }
92            }
93            catch ( FileNotFoundException e )
94            {
95                throw new ContinuumException( ERROR_READING_POM_EXCEPTION_MESSAGE, e );
96            }
97            catch ( IOException e )
98            {
99                throw new ContinuumException( ERROR_READING_POM_EXCEPTION_MESSAGE, e );
100            }
101            catch ( XmlPullParserException e )
102            {
103                throw new ContinuumException( ERROR_READING_POM_EXCEPTION_MESSAGE, e );
104            }
105        }
106 
107        if ( result == null )
108        {
109            result = getContinuum().addMavenTwoProject( pomUrl, selectedProjectGroup, checkProtocol, scmUseCache,
110                                                        !this.isNonRecursiveProject(),
111                                                        this.getBuildDefinitionTemplateId() );
112        }
113 
114        AuditLog event = new AuditLog( hidePasswordInUrl( pomUrl ), AuditLogConstants.ADD_M2_PROJECT );
115        event.setCategory( AuditLogConstants.PROJECT );
116        event.setCurrentUser( getPrincipal() );
117 
118        if ( result == null || result.hasErrors() )
119        {
120            event.setAction( AuditLogConstants.ADD_M2_PROJECT_FAILED );
121        }
122 
123        event.log();
124        return result;
125    }
126 
127    /**
128     * @deprecated Use {@link #getPomFile()} instead
129     */
130    public File getM2PomFile()
131    {
132        return getPomFile();
133    }
134 
135    /**
136     * @deprecated Use {@link #setPomFile(File)} instead
137     */
138    public void setM2PomFile( File pomFile )
139    {
140        setPomFile( pomFile );
141    }
142 
143    /**
144     * @deprecated Use {@link #getPomUrl()} instead
145     */
146    public String getM2PomUrl()
147    {
148        return getPomUrl();
149    }
150 
151    /**
152     * @deprecated Use {@link #setPomUrl(String)} instead
153     */
154    public void setM2PomUrl( String pomUrl )
155    {
156        setPomUrl( pomUrl );
157    }
158 
159    public boolean isNonRecursiveProject()
160    {
161        return nonRecursiveProject;
162    }
163 
164    public void setNonRecursiveProject( boolean nonRecursiveProject )
165    {
166        this.nonRecursiveProject = nonRecursiveProject;
167    }
168}

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