All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.marvelution.jira.plugins.sonar.upgrade.SonarTabPanelLayoutUpgradeTask Maven / Gradle / Ivy

/*
 * Licensed to Marvelution under one or more contributor license 
 * agreements.  See the NOTICE file distributed with this work 
 * for additional information regarding copyright ownership.
 * Marvelution 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.
 */

package com.marvelution.jira.plugins.sonar.upgrade;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.Logger;

import com.atlassian.sal.api.message.Message;
import com.atlassian.sal.api.upgrade.PluginUpgradeTask;
import com.marvelution.jira.plugins.sonar.service.SonarPanelLayoutManager;

/**
 * {@link PluginUpgradeTask} to create an initial Sonar Tab Panel layout
 * 
 * @author Mark Rekveld
 */
public class SonarTabPanelLayoutUpgradeTask implements PluginUpgradeTask {

	public static final Set LEFT_COLUMN_GADGETS = new HashSet();

	public static final Set RIGHT_COLUMN_GADGETS = new HashSet();

	static {
		// Populate default left column gadgets
		LEFT_COLUMN_GADGETS.add("loc");
		LEFT_COLUMN_GADGETS.add("comments");
		LEFT_COLUMN_GADGETS.add("violations");
		LEFT_COLUMN_GADGETS.add("coverage");
		// Populate default right column gadgets
		RIGHT_COLUMN_GADGETS.add("treemap");
		RIGHT_COLUMN_GADGETS.add("complexity");
	}

	private final Logger logger = Logger.getLogger(SonarTabPanelLayoutUpgradeTask.class);

	private final SonarPanelLayoutManager layoutManager;

	/**
	 * Constructor
	 * 
	 * @param layoutManager the {@link SonarPanelLayoutManager} implementation
	 */
	public SonarTabPanelLayoutUpgradeTask(SonarPanelLayoutManager layoutManager) {
		this.layoutManager = layoutManager;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Collection doUpgrade() throws Exception {
		if (layoutManager.getNumberOfColumn() == 0) {
			logger.info("Currently no Layout is configured... Adding the default configuration.");
			layoutManager.put(0, LEFT_COLUMN_GADGETS);
			layoutManager.put(0, RIGHT_COLUMN_GADGETS);
		} else {
			logger.info("There are already " + layoutManager.getNumberOfColumn()
				+ " columns configured in the layout. Skipping configuration of the default layout.");
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public int getBuildNumber() {
		return 1;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getPluginKey() {
		return "com.marvelution.jira.plugins.sonar";
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getShortDescription() {
		return "UpgradeTask to create the initial Sonar Tab Panel Layout";
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy