package org.apache.maven.continuum.web.action;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.maven.continuum.ContinuumException;
import org.apache.maven.continuum.web.util.StateGenerator;
import org.apache.maven.continuum.configuration.ConfigurationException;
import org.apache.maven.continuum.model.project.BuildResult;
import org.apache.maven.continuum.model.project.Project;
import org.codehaus.plexus.util.FileUtils;

import javax.servlet.jsp.PageContext;

import com.opensymphony.webwork.ServletActionContext;

/**
 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
 * @version $Id$
 *
 * @plexus.component
 *   role="com.opensymphony.xwork.Action"
 *   role-hint="buildResult"
 */
public class BuildResultAction
    extends ContinuumActionSupport
{
    private BuildResult buildResult;

    private int buildId;

    private int projectId;

    private int projectGroupId;

    private String projectName;

    private List changeSet;

    private boolean hasSurefireResults;

    private String buildOutput;

    private String state;

    public String execute()
        throws ContinuumException, ConfigurationException, IOException
    {
        //todo get this working for other types of test case rendering other then just surefire
        // check if there are surefire results to display
        Project project = getContinuum().getProject( getProjectId() );
        hasSurefireResults = FileUtils.fileExists( project.getWorkingDirectory() + "/target/surefire-reports" );

        buildResult = getContinuum().getBuildResult( getBuildId() );

        changeSet = getContinuum().getChangesSinceLastSuccess( getProjectId(), getBuildId() );

        File buildOutputFile = getContinuum().getConfiguration().getBuildOutputFile( getBuildId(), getProjectId() );

        if ( buildOutputFile.exists() )
        {
            buildOutput = FileUtils.fileRead( buildOutputFile );
        }

        state = StateGenerator.generate( buildResult.getState(), ServletActionContext.getRequest().getContextPath() );

        return SUCCESS;
    }


    public int getBuildId()
    {
        return buildId;
    }

    public void setBuildId( int buildId )
    {
        this.buildId = buildId;
    }

    public int getProjectId()
    {
        return projectId;
    }

    public void setProjectId( int projectId )
    {
        this.projectId = projectId;
    }

    public String getProjectName()
    {
        return projectName;
    }

    public void setProjectName( String projectName )
    {
        this.projectName = projectName;
    }

    public int getProjectGroupId()
    {
        return projectGroupId;
    }

    public void setProjectGroupId( int projectGroupId )
    {
        this.projectGroupId = projectGroupId;
    }

    public BuildResult getBuildResult()
    {
        return buildResult;
    }

    public List getChangesSinceLastSuccess()
    {
        return changeSet;
    }

    public boolean isHasSurefireResults()
    {
        return hasSurefireResults;
    }

    public void setHasSurefireResults( boolean hasSurefireResults )
    {
        this.hasSurefireResults = hasSurefireResults;
    }

    public String getBuildOutput()
    {
        return buildOutput;
    }

    public String getState()
    {
        return state;
    }

}

@@ -1621,16 +1621,46 @@
 pport%0A%7B%0A
+    private Project project;%0A%0A
     priv
@@ -1688,16 +1688,16 @@
 Result;%0A
-
 %0A    pri
@@ -1747,41 +1747,8 @@
 d;%0A%0A
-    private int projectGroupId;%0A%0A
     
@@ -2173,24 +2173,16 @@
         
-Project 
 project 
@@ -3048,32 +3048,101 @@
 buildId;%0A    %7D%0A%0A
+    public Project getProject()%0A    %7B%0A        return project;%0A    %7D%0A%0A
     public int g
@@ -3416,32 +3416,32 @@
 ectName )%0A    %7B%0A
+
         this.pro
@@ -3475,202 +3475,8 @@
  %7D%0A%0A
-    public int getProjectGroupId()%0A    %7B%0A        return projectGroupId;%0A    %7D%0A%0A    public void setProjectGroupId( int projectGroupId )%0A    %7B%0A        this.projectGroupId = projectGroupId;%0A    %7D%0A%0A
     

Fix projectGroupId param from build result page