/**
 * Copyright (C) 2012 White Source Ltd.
 *
 * Licensed 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.
 */
package org.whitesource.teamcity.server;

import jetbrains.buildServer.serverSide.SBuild;
import jetbrains.buildServer.serverSide.SBuildServer;
import jetbrains.buildServer.serverSide.artifacts.BuildArtifact;
import jetbrains.buildServer.serverSide.artifacts.BuildArtifacts;
import jetbrains.buildServer.serverSide.artifacts.BuildArtifactsViewMode;
import jetbrains.buildServer.web.openapi.PagePlaces;
import jetbrains.buildServer.web.openapi.ViewLogTab;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Setup a tab for the policy check report.
 *
 * @author Edo.Shor
 */
public class PolicyCheckReportTab extends ViewLogTab {

    /* --- Static members --- */

    private static final String TAB_TITLE = "White Source";
    private static final String TAB_CODE = "whitesourceReportTab";
    private static final String TAB_BASEPATH = "whitesource.zip";
    private static final String TAB_STARTPAGE = "index.html";

    /* --- Constructors --- */

    /**
     * Constructor
     *
     * @param pagePlaces
     * @param server
     */
    public PolicyCheckReportTab(@NotNull PagePlaces pagePlaces, @NotNull SBuildServer server) {
        super(TAB_TITLE, TAB_CODE, pagePlaces, server);
        setIncludeUrl("/artifactsViewer.jsp");
    }

    /* --- Concrete implementation methods --- */

    @Override
    protected void fillModel(Map model, HttpServletRequest request, @Nullable SBuild build) {
        model.put("basePath", TAB_BASEPATH);
        model.put("startPage", TAB_STARTPAGE);
    }

    /* --- Overridden methods --- */

    @Override
    public boolean isAvailable(@NotNull HttpServletRequest request) {
        boolean available = false;

        SBuild build = getBuild(request);
        if (build != null) {
            BuildArtifacts artifacts = build.getArtifacts(BuildArtifactsViewMode.VIEW_ALL);
            BuildArtifact artifact = artifacts.getArtifact(TAB_BASEPATH);
            available = artifact != null && !artifact.isDirectory();
        }

        return available;
    }
}

@@ -1074,16 +1074,76 @@
 ogTab;%0D%0A
+import jetbrains.buildServer.web.reportTabs.ReportTabUtil;%0D%0A
 import o
@@ -1634,24 +1634,25 @@
 ing TAB_
-BASEPATH
+STARTPAGE
  = %22whit
@@ -1666,61 +1666,9 @@
 .zip
-%22;%0D%0A    private static final String TAB_STARTPAGE = %22
+!
 inde
@@ -2204,63 +2204,50 @@
 ut(%22
-basePath%22, TAB_BASEPATH);%0D%0A        model.put(%22s
+startPage%22, ReportTabUtil.prepareS
 tartPage
 %22, T
@@ -2242,19 +2242,23 @@
 tartPage
-%22, 
+ForWeb(
 TAB_STAR
@@ -2263,16 +2263,17 @@
 ARTPAGE)
+)
 ;%0D%0A    %7D
@@ -2336,21 +2336,24 @@
 e%0D%0A    p
-ublic
+rotected
  boolean
@@ -2404,399 +2404,135 @@
 uest
-) %7B%0D%0A        boolean available = false;%0D%0A%0D%0A        SBuild build = getBuild(request);%0D%0A        if (build != null) %7B%0D%0A            BuildArtifacts artifacts = build.getArtifacts(BuildArtifactsViewMode.VIEW_ALL);%0D%0A            BuildArtifact artifact = artifacts.getArtifact(TAB_BASEPATH);%0D%0A            available = artifact != null && !artifact.isDirectory();%0D%0A        %7D%0D%0A%0D%0A        return available
+, @NotNull SBuild build) %7B%0D%0A        return super.isAvailable(request, build) && ReportTabUtil.isAvailable(build, TAB_STARTPAGE)
 ;%0D%0A 

Use v7.0+ style for report tab