com.marvelution.jira.plugins.sonar.upgrade.SonarAssociationsUpgradeTask 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 org.apache.log4j.Logger;
import com.atlassian.sal.api.message.Message;
import com.atlassian.sal.api.upgrade.PluginUpgradeTask;
import com.marvelution.jira.plugins.sonar.DefaultSonarAssociationImpl;
import com.marvelution.jira.plugins.sonar.service.SonarAssociation;
import com.marvelution.jira.plugins.sonar.service.SonarAssociationManager;
import com.marvelution.jira.plugins.sonar.service.SonarPropertyManager;
import com.opensymphony.module.propertyset.PropertySet;
/**
* {@link PluginUpgradeTask} to upgrade the Sonar Associations to the new model
*
* @author Mark Rekveld
*
* @since 3.0.0
*/
public class SonarAssociationsUpgradeTask implements PluginUpgradeTask {
private final Logger logger = Logger.getLogger(SonarAssociationsUpgradeTask.class);
private final SonarAssociationManager associationManager;
private final PropertySet propertySet;
/**
* Constructor
*
* @param associationManager the {@link SonarAssociationManager} implementation
* @param propertyManager the {@link SonarPropertyManager} implementation
*/
public SonarAssociationsUpgradeTask(SonarAssociationManager associationManager,
SonarPropertyManager propertyManager) {
this.associationManager = associationManager;
propertySet = propertyManager.getPropertySet();
}
/**
* {@inheritDoc}
*/
@Override
public Collection doUpgrade() throws Exception {
if (!propertySet.getKeys("sonar.association.").isEmpty() && !propertySet.exists("sonar.association.nextId")) {
logger.info("There might be associations that need upgrading... Checking them now.");
final Collection> keys = propertySet.getKeys("sonar.association.");
for (Object entry : keys) {
final String key = (String) entry;
if (key.startsWith("sonar.association.") && key.endsWith(".projectId")) {
final SonarAssociation association = new DefaultSonarAssociationImpl();
final Long projectId = propertySet.getLong(key);
logger.info("Found Association for project with Id: " + projectId);
association.setProjectId(projectId);
association.setSonarServer(propertySet.getString("sonar.association." + projectId + ".server"));
association.setSonarProject(propertySet.getString("sonar.association." + projectId
+ ".projectKey"));
propertySet.remove(key);
associationManager.put(association);
logger.info("Upgraded Association for project with Id: " + projectId + " to the new association");
} else {
propertySet.remove(key);
}
}
return null;
} else {
return null;
}
}
/**
* {@inheritDoc}
*/
@Override
public int getBuildNumber() {
return 2;
}
/**
* {@inheritDoc}
*/
@Override
public String getPluginKey() {
return "com.marvelution.jira.plugins.sonar";
}
/**
* {@inheritDoc}
*/
@Override
public String getShortDescription() {
return "UpgradeTask to convert the Soanr Associations to the new Model";
}
}