OpenEdgeProparseSensor implements Sensor { @Override public void execute(SensorContext context) { if (settings.skipProparseSensor()) return; settings.init(); components.initializeLicense(context); components.initializeChecks(context); for (Map.Entry<ActiveRule, OpenEdgeProparseCheck> entry : components.getProparseRules().entrySet()) { ruleTime.put(entry.getKey().ruleKey().toString(), 0L); } IRefactorSessionEnv sessions = settings.getProparseSessions(); FilePredicates predicates = context.fileSystem().predicates(); long totFiles = StreamSupport.stream(context.fileSystem().inputFiles( predicates.and(predicates.hasLanguage(Constants.LANGUAGE_KEY), predicates.hasType(Type.MAIN))).spliterator(), false).count(); long prevMessage = System.currentTimeMillis(); for (InputFile file : context.fileSystem().inputFiles( predicates.and(predicates.hasLanguage(Constants.LANGUAGE_KEY), predicates.hasType(Type.MAIN)))) { LOG.debug("Parsing {}", file); numFiles++; if (System.currentTimeMillis() - prevMessage > 30000L) { prevMessage = System.currentTimeMillis(); LOG.info("{}/{} - Current file: {}", numFiles, totFiles, file.relativePath()); } IProparseEnvironment session = sessions.getSession(file.relativePath()); if (settings.isIncludeFile(file.filename())) { parseIncludeFile(context, file, session); } else { parseMainFile(context, file, session); } if (context.isCancelled()) { LOG.info("Analysis cancelled..."); return; } } executeAnalytics(context); logStatistics(); generateProparseDebugIndex(); } OpenEdgeProparseSensor(OpenEdgeSettings settings, OpenEdgeComponents components); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context);  }
@Test public void testCPDPreprocessorExpansion() throws Exception { MapSettings settings = new MapSettings(); settings.setProperty(Constants.CPD_ANNOTATIONS, "Generated,rssw.lang.Generated"); settings.setProperty(Constants.CPD_METHODS, "TEST3"); settings.setProperty(Constants.CPD_PROCEDURES, "adm-create-objects"); SensorContextTester context = TestProjectSensorContext.createContext(); context.setSettings(settings); OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); OpenEdgeComponents components = new OpenEdgeComponents(OpenEdgePluginTest.SERVER, null, null); OpenEdgeProparseSensor sensor = new OpenEdgeProparseSensor(oeSettings, components); sensor.execute(context); assertNotNull(context.cpdTokens(BASEDIR + ":" + FILE3)); assertEquals(context.cpdTokens(BASEDIR + ":" + FILE3).size(), 7); assertNotNull(context.cpdTokens(BASEDIR + ":" + CLASS1)); assertEquals(context.cpdTokens(BASEDIR + ":" + CLASS1).size(), 11); assertNotNull(context.cpdTokens(BASEDIR + ":" + FILE4)); assertEquals(context.cpdTokens(BASEDIR + ":" + FILE4).size(), 2); }
@Test public void testCPDPreprocessorExpansion02() throws Exception { MapSettings settings = new MapSettings(); settings.setProperty(Constants.CPD_ANNOTATIONS, "Generated,rssw.lang.Generated"); settings.setProperty(Constants.CPD_METHODS, "TEST3"); settings.setProperty(Constants.CPD_PROCEDURES, "adm-create-objects"); settings.setProperty(Constants.USE_SIMPLE_CPD, true); SensorContextTester context = TestProjectSensorContext.createContext(); context.setSettings(settings); OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); OpenEdgeComponents components = new OpenEdgeComponents(OpenEdgePluginTest.SERVER, null, null); OpenEdgeProparseSensor sensor = new OpenEdgeProparseSensor(oeSettings, components); sensor.execute(context); assertNull(context.cpdTokens(BASEDIR + ":" + FILE3)); assertNull(context.cpdTokens(BASEDIR + ":" + CLASS1)); assertNull(context.cpdTokens(BASEDIR + ":" + FILE4)); }
@Test public void testRules() throws Exception { SensorContextTester context = TestProjectSensorContext.createContext(); ActiveRulesBuilder rulesBuilder = new ActiveRulesBuilder(); rulesBuilder.addRule(new NewActiveRule.Builder().setRuleKey( RuleKey.of(Constants.STD_REPOSITORY_KEY, ClumsySyntax.class.getCanonicalName())).setLanguage( Constants.LANGUAGE_KEY).build()); context.setActiveRules(rulesBuilder.build()); OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); OpenEdgeComponents components = new OpenEdgeComponents(OpenEdgePluginTest.SERVER, new CheckRegistration[] {new BasicChecksRegistration()}, null); OpenEdgeProparseSensor sensor = new OpenEdgeProparseSensor(oeSettings, components); sensor.execute(context); assertEquals(components.getProparseRules().size(), 1); }
@Test public void testListing() throws Exception { SensorContextTester context = TestProjectSensorContext.createContext(); OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); OpenEdgeComponents components = new OpenEdgeComponents(OpenEdgePluginTest.SERVER, null, null); OpenEdgeProparseSensor sensor = new OpenEdgeProparseSensor(oeSettings, components); sensor.execute(context); assertEquals(context.measure(BASEDIR + ":" + FILE1, OpenEdgeMetrics.NUM_TRANSACTIONS_KEY).value(), 1, "Wrong number of transactions"); assertEquals(context.measure(BASEDIR + ":" + FILE2, OpenEdgeMetrics.NUM_TRANSACTIONS_KEY).value(), 0, "Wrong number of transactions"); }
@Test public void testProparseError() throws Exception { SensorContextTester context = TestProjectSensorContext.createContext(); OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); OpenEdgeComponents components = new OpenEdgeComponents(OpenEdgePluginTest.SERVER, null, null); OpenEdgeProparseSensor sensor = new OpenEdgeProparseSensor(oeSettings, components); sensor.execute(context); assertEquals(context.allAnalysisErrors().size(), 0); assertEquals(context.allIssues().size(), 1); Issue issue = context.allIssues().iterator().next(); assertEquals(issue.ruleKey().rule(), OpenEdgeRulesDefinition.PROPARSE_ERROR_RULEKEY); }
@Test public void testProparseErrorSonarLint() throws Exception { SensorContextTester context = TestProjectSensorContext.createContext(); context.setRuntime(OpenEdgePluginTest.SONARLINT_RUNTIME); OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARLINT_RUNTIME, OpenEdgePluginTest.SERVER); OpenEdgeComponents components = new OpenEdgeComponents(OpenEdgePluginTest.SERVER, null, null); OpenEdgeProparseSensor sensor = new OpenEdgeProparseSensor(oeSettings, components); sensor.execute(context); assertEquals(context.allIssues().size(), 0); assertEquals(context.allAnalysisErrors().size(), 1); }
@Test public void testNoProparseError() throws Exception { MapSettings settings = new MapSettings(); settings.setProperty("sonar.oe.proparse.recover", true); SensorContextTester context = TestProjectSensorContext.createContext(); context.setSettings(settings); OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); OpenEdgeComponents components = new OpenEdgeComponents(OpenEdgePluginTest.SERVER, null, null); OpenEdgeProparseSensor sensor = new OpenEdgeProparseSensor(oeSettings, components); sensor.execute(context); assertEquals(context.allAnalysisErrors().size(), 0); assertEquals(context.allIssues().size(), 0); }