001/*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
019 */
020package org.sonar.plugins.squid.bridges;
021
022import com.google.common.collect.Lists;
023import org.sonar.api.batch.SensorContext;
024import org.sonar.api.checks.CheckFactory;
025import org.sonar.api.checks.NoSonarFilter;
026import org.sonar.squid.Squid;
027
028import java.util.ArrayList;
029import java.util.List;
030
031public final class BridgeFactory {
032
033  private BridgeFactory() {
034    // only static methods
035  }
036
037  private static List<Bridge> create(NoSonarFilter noSonarFilter, boolean skipPackageDesignAnalysis) {
038    ArrayList<Bridge> result = Lists.newArrayList(
039        new CopyBasicMeasuresBridge(),
040        new PackagesBridge(),
041        new PublicUndocumentedApiBridge(),
042        new NoSonarFilterLoader(noSonarFilter),
043        new ChidamberKemererBridge(),
044        new RobertCMartinBridge(),
045        new Lcom4BlocksBridge(),
046        new ChecksBridge());
047    if (!skipPackageDesignAnalysis) {
048      result.add(new DesignBridge());
049    }
050    return result;
051  }
052
053  public static List<Bridge> create(boolean bytecodeScanned, boolean skipPackageDesignAnalysis, SensorContext context, CheckFactory checkFactory,
054                                    ResourceIndex resourceIndex, Squid squid, NoSonarFilter noSonarFilter) {
055    List<Bridge> result = new ArrayList<Bridge>();
056    for (Bridge bridge : create(noSonarFilter, skipPackageDesignAnalysis)) {
057      bridge.setCheckFactory(checkFactory);
058      if (!bridge.needsBytecode() || bytecodeScanned) {
059        bridge.setContext(context);
060        bridge.setSquid(squid);
061        bridge.setResourceIndex(resourceIndex);
062        result.add(bridge);
063      }
064    }
065    return result;
066  }
067}