]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5931 Cleanup
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 15 Jan 2015 16:34:58 +0000 (17:34 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Thu, 15 Jan 2015 16:38:48 +0000 (17:38 +0100)
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java
sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java
sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerOptimizer.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/scan2/IssueCache.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/scan2/SensorsExecutor.java
sonar-batch/src/main/java/org/sonar/batch/sensor/AnalyzerOptimizer.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java
sonar-batch/src/test/java/org/sonar/batch/scan2/AnalyzerOptimizerTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java [new file with mode: 0644]

index e0a0e34851434e997f41210dce3063f03636b9f5..37cb0c5aa694434d2cfa7be0fb3e6b7e03166921 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.batch.bootstrap;
 
+import org.sonar.batch.sensor.AnalyzerOptimizer;
+
 import com.google.common.collect.Lists;
 import org.apache.commons.lang.ClassUtils;
 import org.sonar.api.batch.CheckProject;
@@ -28,7 +30,6 @@ import org.sonar.api.batch.sensor.SensorContext;
 import org.sonar.api.platform.ComponentContainer;
 import org.sonar.api.resources.Project;
 import org.sonar.batch.scan.SensorWrapper;
-import org.sonar.batch.scan2.AnalyzerOptimizer;
 import org.sonar.batch.sensor.DefaultSensorContext;
 
 import javax.annotation.Nullable;
index a7af5621465deba27635ac40ff352f3737f926fe..a2d9f3a165f70b4955d95d2ef0df75fc1568b878 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.batch.scan;
 
+import org.sonar.batch.sensor.AnalyzerOptimizer;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.BatchComponent;
@@ -95,7 +97,6 @@ import org.sonar.batch.scan.filesystem.ProjectFileSystemAdapter;
 import org.sonar.batch.scan.filesystem.StatusDetectionFactory;
 import org.sonar.batch.scan.maven.MavenPluginsConfigurator;
 import org.sonar.batch.scan.report.JsonReport;
-import org.sonar.batch.scan2.AnalyzerOptimizer;
 import org.sonar.batch.sensor.DefaultSensorContext;
 import org.sonar.batch.sensor.DefaultSensorStorage;
 import org.sonar.batch.sensor.coverage.CoverageExclusions;
index c316078f71451ea3f9a484b621617a9053b67a47..8884bef521f2074000d64d3a94f9721bc23f5a01 100644 (file)
  */
 package org.sonar.batch.scan;
 
+import org.sonar.batch.sensor.AnalyzerOptimizer;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.batch.sensor.Sensor;
 import org.sonar.api.batch.sensor.SensorContext;
 import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
 import org.sonar.api.resources.Project;
-import org.sonar.batch.scan2.AnalyzerOptimizer;
 
 public class SensorWrapper implements org.sonar.api.batch.Sensor {
 
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerOptimizer.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerOptimizer.java
deleted file mode 100644 (file)
index c149a7a..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.batch.scan2;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.BatchComponent;
-import org.sonar.api.batch.fs.FilePredicate;
-import org.sonar.api.batch.fs.FileSystem;
-import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
-import org.sonar.api.config.Settings;
-
-public class AnalyzerOptimizer implements BatchComponent {
-
-  private static final Logger LOG = LoggerFactory.getLogger(AnalyzerOptimizer.class);
-
-  private final FileSystem fs;
-  private final ActiveRules activeRules;
-  private final Settings settings;
-
-  public AnalyzerOptimizer(FileSystem fs, ActiveRules activeRules, Settings settings) {
-    this.fs = fs;
-    this.activeRules = activeRules;
-    this.settings = settings;
-  }
-
-  /**
-   * Decide if the given Analyzer should be executed.
-   */
-  public boolean shouldExecute(DefaultSensorDescriptor descriptor) {
-    if (!fsCondition(descriptor)) {
-      LOG.debug("'{}' skipped because there is no related file in current project", descriptor.name());
-      return false;
-    }
-    if (!activeRulesCondition(descriptor)) {
-      LOG.debug("'{}' skipped because there is no related rule activated in the quality profile", descriptor.name());
-      return false;
-    }
-    if (!settingsCondition(descriptor)) {
-      LOG.debug("'{}' skipped because one of the required properties is missing", descriptor.name());
-      return false;
-    }
-    return true;
-  }
-
-  private boolean settingsCondition(DefaultSensorDescriptor descriptor) {
-    if (!descriptor.properties().isEmpty()) {
-      for (String propertyKey : descriptor.properties()) {
-        if (!settings.hasKey(propertyKey)) {
-          return false;
-        }
-      }
-    }
-    return true;
-  }
-
-  private boolean activeRulesCondition(DefaultSensorDescriptor descriptor) {
-    if (!descriptor.ruleRepositories().isEmpty()) {
-      for (String repoKey : descriptor.ruleRepositories()) {
-        if (!activeRules.findByRepository(repoKey).isEmpty()) {
-          return true;
-        }
-      }
-      return false;
-    }
-    return true;
-  }
-
-  private boolean fsCondition(DefaultSensorDescriptor descriptor) {
-    if (!descriptor.languages().isEmpty() || descriptor.type() != null) {
-      FilePredicate langPredicate = descriptor.languages().isEmpty() ? fs.predicates().all() : fs.predicates().hasLanguages(descriptor.languages());
-
-      FilePredicate typePredicate = descriptor.type() == null ? fs.predicates().all() : fs.predicates().hasType(descriptor.type());
-      return fs.hasFiles(fs.predicates().and(langPredicate, typePredicate));
-    }
-    return true;
-  }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/IssueCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/IssueCache.java
deleted file mode 100644 (file)
index 5de18c1..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.batch.scan2;
-
-import org.sonar.api.BatchComponent;
-import org.sonar.api.batch.sensor.issue.internal.DefaultIssue;
-import org.sonar.batch.index.Cache;
-import org.sonar.batch.index.Caches;
-import org.sonar.batch.scan.filesystem.InputPathCache;
-
-/**
- * Shared issues among all project modules
- */
-public class IssueCache implements BatchComponent {
-
-  // project key -> resource key -> issue key -> issue
-  private final Cache<DefaultIssue> cache;
-
-  public IssueCache(Caches caches, InputPathCache inputPathCache) {
-    caches.registerValueCoder(DefaultIssue.class, new DefaultIssueValueCoder(inputPathCache));
-    cache = caches.createCache("issues");
-  }
-
-  public Iterable<DefaultIssue> byComponent(String projectKey, String resourceKey) {
-    return cache.values(projectKey, resourceKey);
-  }
-
-  public Iterable<DefaultIssue> all() {
-    return cache.values();
-  }
-
-  public IssueCache put(String projectKey, String resourceKey, DefaultIssue issue) {
-    cache.put(projectKey, resourceKey, issue.key(), issue);
-    return this;
-  }
-
-  public Iterable<DefaultIssue> byModule(String projectKey) {
-    return cache.values(projectKey);
-  }
-
-}
index ea872c4c1bfb5c11dfa7c34a5758ae393dd2375d..dc68e4d41f4c0512b1fe04bef4e09c8f7e18b994 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.batch.scan2;
 
+import org.sonar.batch.sensor.AnalyzerOptimizer;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.BatchComponent;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/AnalyzerOptimizer.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/AnalyzerOptimizer.java
new file mode 100644 (file)
index 0000000..ed085a7
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * 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.batch.sensor;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.batch.fs.FilePredicate;
+import org.sonar.api.batch.fs.FileSystem;
+import org.sonar.api.batch.rule.ActiveRules;
+import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
+import org.sonar.api.config.Settings;
+
+public class AnalyzerOptimizer implements BatchComponent {
+
+  private static final Logger LOG = LoggerFactory.getLogger(AnalyzerOptimizer.class);
+
+  private final FileSystem fs;
+  private final ActiveRules activeRules;
+  private final Settings settings;
+
+  public AnalyzerOptimizer(FileSystem fs, ActiveRules activeRules, Settings settings) {
+    this.fs = fs;
+    this.activeRules = activeRules;
+    this.settings = settings;
+  }
+
+  /**
+   * Decide if the given Analyzer should be executed.
+   */
+  public boolean shouldExecute(DefaultSensorDescriptor descriptor) {
+    if (!fsCondition(descriptor)) {
+      LOG.debug("'{}' skipped because there is no related file in current project", descriptor.name());
+      return false;
+    }
+    if (!activeRulesCondition(descriptor)) {
+      LOG.debug("'{}' skipped because there is no related rule activated in the quality profile", descriptor.name());
+      return false;
+    }
+    if (!settingsCondition(descriptor)) {
+      LOG.debug("'{}' skipped because one of the required properties is missing", descriptor.name());
+      return false;
+    }
+    return true;
+  }
+
+  private boolean settingsCondition(DefaultSensorDescriptor descriptor) {
+    if (!descriptor.properties().isEmpty()) {
+      for (String propertyKey : descriptor.properties()) {
+        if (!settings.hasKey(propertyKey)) {
+          return false;
+        }
+      }
+    }
+    return true;
+  }
+
+  private boolean activeRulesCondition(DefaultSensorDescriptor descriptor) {
+    if (!descriptor.ruleRepositories().isEmpty()) {
+      for (String repoKey : descriptor.ruleRepositories()) {
+        if (!activeRules.findByRepository(repoKey).isEmpty()) {
+          return true;
+        }
+      }
+      return false;
+    }
+    return true;
+  }
+
+  private boolean fsCondition(DefaultSensorDescriptor descriptor) {
+    if (!descriptor.languages().isEmpty() || descriptor.type() != null) {
+      FilePredicate langPredicate = descriptor.languages().isEmpty() ? fs.predicates().all() : fs.predicates().hasLanguages(descriptor.languages());
+
+      FilePredicate typePredicate = descriptor.type() == null ? fs.predicates().all() : fs.predicates().hasType(descriptor.type());
+      return fs.hasFiles(fs.predicates().and(langPredicate, typePredicate));
+    }
+    return true;
+  }
+
+}
index 1509a65ffeae93807c7e263b3bc0e5d0e464df8e..f6979d924c67967ced1ccda379e185b698c6c2a2 100644 (file)
  */
 package org.sonar.batch.bootstrap;
 
+import org.sonar.batch.sensor.AnalyzerOptimizer;
+
 import org.junit.Test;
 import org.sonar.api.BatchExtension;
 import org.sonar.api.batch.Sensor;
 import org.sonar.api.platform.ComponentContainer;
 import org.sonar.api.resources.Project;
-import org.sonar.batch.scan2.AnalyzerOptimizer;
 import org.sonar.batch.sensor.DefaultSensorContext;
 
 import java.util.Collection;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan2/AnalyzerOptimizerTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan2/AnalyzerOptimizerTest.java
deleted file mode 100644 (file)
index b056715..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 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.batch.scan2;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultFileSystem;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
-import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
-import org.sonar.api.config.Settings;
-import org.sonar.api.rule.RuleKey;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class AnalyzerOptimizerTest {
-
-  DefaultFileSystem fs = new DefaultFileSystem();
-
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-  private AnalyzerOptimizer optimizer;
-
-  private Settings settings;
-
-  @Before
-  public void prepare() {
-    settings = new Settings();
-    optimizer = new AnalyzerOptimizer(fs, new ActiveRulesBuilder().build(), settings);
-  }
-
-  @Test
-  public void should_run_analyzer_with_no_metadata() throws Exception {
-    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
-
-    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
-  }
-
-  @Test
-  public void should_optimize_on_language() throws Exception {
-    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
-      .onlyOnLanguages("java", "php");
-    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
-
-    fs.add(new DefaultInputFile("foo", "src/Foo.java").setLanguage("java"));
-    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
-  }
-
-  @Test
-  public void should_optimize_on_type() throws Exception {
-    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
-      .onlyOnFileType(InputFile.Type.MAIN);
-    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
-
-    fs.add(new DefaultInputFile("foo", "tests/FooTest.java").setType(InputFile.Type.TEST));
-    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
-
-    fs.add(new DefaultInputFile("foo", "src/Foo.java").setType(InputFile.Type.MAIN));
-    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
-  }
-
-  @Test
-  public void should_optimize_on_both_type_and_language() throws Exception {
-    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
-      .onlyOnLanguages("java", "php")
-      .onlyOnFileType(InputFile.Type.MAIN);
-    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
-
-    fs.add(new DefaultInputFile("foo", "tests/FooTest.java").setLanguage("java").setType(InputFile.Type.TEST));
-    fs.add(new DefaultInputFile("foo", "src/Foo.cbl").setLanguage("cobol").setType(InputFile.Type.MAIN));
-    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
-
-    fs.add(new DefaultInputFile("foo", "src/Foo.java").setLanguage("java").setType(InputFile.Type.MAIN));
-    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
-  }
-
-  @Test
-  public void should_optimize_on_repository() throws Exception {
-    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
-      .createIssuesForRuleRepositories("squid");
-    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
-
-    ActiveRules activeRules = new ActiveRulesBuilder()
-      .create(RuleKey.of("repo1", "foo"))
-      .activate()
-      .build();
-    optimizer = new AnalyzerOptimizer(fs, activeRules, settings);
-
-    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
-
-    activeRules = new ActiveRulesBuilder()
-      .create(RuleKey.of("repo1", "foo"))
-      .activate()
-      .create(RuleKey.of("squid", "rule"))
-      .activate()
-      .build();
-    optimizer = new AnalyzerOptimizer(fs, activeRules, settings);
-    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
-  }
-
-  @Test
-  public void should_optimize_on_settings() throws Exception {
-    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
-      .requireProperty("sonar.foo.reportPath");
-    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
-
-    settings.setProperty("sonar.foo.reportPath", "foo");
-    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
-  }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java
new file mode 100644 (file)
index 0000000..fb8e564
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * 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.batch.sensor;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.internal.DefaultFileSystem;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.rule.ActiveRules;
+import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
+import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
+import org.sonar.api.config.Settings;
+import org.sonar.api.rule.RuleKey;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AnalyzerOptimizerTest {
+
+  DefaultFileSystem fs = new DefaultFileSystem();
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+  private AnalyzerOptimizer optimizer;
+
+  private Settings settings;
+
+  @Before
+  public void prepare() {
+    settings = new Settings();
+    optimizer = new AnalyzerOptimizer(fs, new ActiveRulesBuilder().build(), settings);
+  }
+
+  @Test
+  public void should_run_analyzer_with_no_metadata() throws Exception {
+    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
+
+    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
+  }
+
+  @Test
+  public void should_optimize_on_language() throws Exception {
+    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
+      .onlyOnLanguages("java", "php");
+    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
+
+    fs.add(new DefaultInputFile("foo", "src/Foo.java").setLanguage("java"));
+    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
+  }
+
+  @Test
+  public void should_optimize_on_type() throws Exception {
+    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
+      .onlyOnFileType(InputFile.Type.MAIN);
+    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
+
+    fs.add(new DefaultInputFile("foo", "tests/FooTest.java").setType(InputFile.Type.TEST));
+    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
+
+    fs.add(new DefaultInputFile("foo", "src/Foo.java").setType(InputFile.Type.MAIN));
+    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
+  }
+
+  @Test
+  public void should_optimize_on_both_type_and_language() throws Exception {
+    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
+      .onlyOnLanguages("java", "php")
+      .onlyOnFileType(InputFile.Type.MAIN);
+    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
+
+    fs.add(new DefaultInputFile("foo", "tests/FooTest.java").setLanguage("java").setType(InputFile.Type.TEST));
+    fs.add(new DefaultInputFile("foo", "src/Foo.cbl").setLanguage("cobol").setType(InputFile.Type.MAIN));
+    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
+
+    fs.add(new DefaultInputFile("foo", "src/Foo.java").setLanguage("java").setType(InputFile.Type.MAIN));
+    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
+  }
+
+  @Test
+  public void should_optimize_on_repository() throws Exception {
+    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
+      .createIssuesForRuleRepositories("squid");
+    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
+
+    ActiveRules activeRules = new ActiveRulesBuilder()
+      .create(RuleKey.of("repo1", "foo"))
+      .activate()
+      .build();
+    optimizer = new AnalyzerOptimizer(fs, activeRules, settings);
+
+    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
+
+    activeRules = new ActiveRulesBuilder()
+      .create(RuleKey.of("repo1", "foo"))
+      .activate()
+      .create(RuleKey.of("squid", "rule"))
+      .activate()
+      .build();
+    optimizer = new AnalyzerOptimizer(fs, activeRules, settings);
+    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
+  }
+
+  @Test
+  public void should_optimize_on_settings() throws Exception {
+    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
+      .requireProperty("sonar.foo.reportPath");
+    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
+
+    settings.setProperty("sonar.foo.reportPath", "foo");
+    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
+  }
+}