コード例 #1
0
  /**
   * Matches to something like: (ATOM:ATOM/NUMBER)(WHITESPACES)(SOMETHING NOT
   * WHITESPACES)(:WHITESPACES)(NUMBER,NUMBER-NUMBER,NUMBER) like: game:start/0
   * /home/dev/project/erlang/game.erl: 4,1-5,12 means: 'application name':'function name'/'number
   * of parameters' 'URL to the file': 'starting row','starting col'-'ending row','ending col'
   */
  public ViolationReport refactorErl(Project project, RulesProfile profile) {
    ViolationReport report = new ViolationReport();
    List<ActiveRule> activeRules = profile.getActiveRulesByRepository("Erlang");

    /** Read refactorErl results */
    File basedir =
        new File(
            project.getFileSystem().getBasedir()
                + File.separator
                + ((Erlang) project.getLanguage()).getEunitFolder());
    LOG.debug("Parsing refactorErl reports from folder {}", basedir.getAbsolutePath());

    String refactorErlPattern = ((Erlang) project.getLanguage()).getRefactorErlFilenamePattern();

    String[] list = getFileNamesByPattern(basedir, refactorErlPattern);

    if (list.length == 0) {
      LOG.warn("no file matches to : ", refactorErlPattern);
      return report;
    }

    for (String file : list) {
      try {
        List<ViolationReportUnit> units = readRefactorErlReportUnits(basedir, file);
        for (ViolationReportUnit refactorErlReportUnit : units) {
          ActiveRule activeRule =
              ActiveRuleFilter.getActiveRuleByRuleName(
                  activeRules, refactorErlReportUnit.getMetricKey());
          if (activeRule != null
              && ViolationUtil.checkIsValid(activeRule, refactorErlReportUnit.getMetricValue())) {
            refactorErlReportUnit.setDescription(
                ViolationUtil.getMessageForMetric(
                    activeRule, refactorErlReportUnit.getMetricValue()));
            /** Replace key coming from activeProfile because it contains the name originaly */
            refactorErlReportUnit.setMetricKey(activeRule.getRuleKey());
            report.addUnit(refactorErlReportUnit);
          }
        }
      } catch (FileNotFoundException e) {
      } catch (IOException e) {
      }
    }
    return report;
  }
コード例 #2
0
  @Before
  public void init() {
    project = mock(Project.class);
    ProjectFileSystem pfs = mock(ProjectFileSystem.class);

    // Don't pollute current working directory
    when(pfs.getSonarWorkingDirectory()).thenReturn(new File("target"));

    File baseDir = DelphiUtils.getResource(ROOT_NAME);

    when(project.getLanguage()).thenReturn(DelphiLanguage.instance);
    when(project.getFileSystem()).thenReturn(pfs);
    when(project.getLanguageKey()).thenReturn(DelphiLanguage.KEY);

    when(pfs.getBasedir()).thenReturn(baseDir);

    File srcFile = DelphiUtils.getResource(TEST_FILE);
    List<File> sourceFiles = new ArrayList<File>();
    sourceFiles.add(srcFile);

    when(pfs.getSourceFiles(DelphiLanguage.instance)).thenReturn(sourceFiles);

    sensor = new DelphiPmdSensor(new DebugRuleFinder());
  }
コード例 #3
0
 public boolean shouldExecuteOnProject(Project project) {
   return project.getLanguage().equals(Drools.INSTANCE);
 }
コード例 #4
0
 /** {@inheritDoc} */
 public boolean shouldExecuteOnProject(Project project) {
   return isEnabled(project) && language.equals(project.getLanguage());
 }
コード例 #5
0
ファイル: PhpPmdSensor.java プロジェクト: bracki/sonar-php
 /**
  * Should execute on project.
  *
  * @param project the project
  * @return true, if should execute on project
  * @see org.sonar.api.batch.CheckProject#shouldExecuteOnProject(org.sonar.api .resources.Project)
  */
 public boolean shouldExecuteOnProject(Project project) {
   return getConfiguration(project).isShouldRun() && Php.INSTANCE.equals(project.getLanguage());
 }