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

org.sonar.api.batch.AbstractSumChildrenDecorator Maven / Gradle / Ivy

/*
 * SonarQube, open source software quality management tool.
 * Copyright (C) 2008-2014 SonarSource
 * mailto:contact AT sonarsource DOT com
 *
 * SonarQube is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * SonarQube is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.api.batch;

import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;

import java.util.List;

/**
 * Sum measures of child resources.
 *
 * @since 1.10
 */
public abstract class AbstractSumChildrenDecorator implements Decorator {


  /**
   * Each metric is used individually. There are as many generated measures than metrics.
   * 

*

Important : annotations are not inherited, so you have to copy the @DependedUpon annotation * when implementing this method.

* * @return not null list of metrics */ @DependedUpon public abstract List generatesMetrics(); /** * {@inheritDoc} */ public boolean shouldExecuteOnProject(Project project) { return true; } /** * @return whether it should save zero if no child measures */ protected abstract boolean shouldSaveZeroIfNoChildMeasures(); /** * {@inheritDoc} */ public void decorate(Resource resource, DecoratorContext context) { if (!shouldDecorateResource(resource)) { return; } for (Metric metric : generatesMetrics()) { if (context.getMeasure(metric) == null) { Double sum = MeasureUtils.sum(shouldSaveZeroIfNoChildMeasures(), context.getChildrenMeasures(metric)); if (sum != null) { context.saveMeasure(new Measure(metric, sum)); } } } } /** * @return whether the resource should be decorated or not */ public boolean shouldDecorateResource(Resource resource) { return true; } @Override public String toString() { return getClass().getSimpleName(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy