OpenEdgeCPDSensor implements Sensor { @Override public void execute(SensorContext context) { if ((context.runtime().getProduct() == SonarProduct.SONARLINT) || !settings.useSimpleCPD()) return; settings.init(); IRefactorSessionEnv sessions = settings.getProparseSessions(); for (InputFile file : context.fileSystem().inputFiles( context.fileSystem().predicates().hasLanguage(Constants.LANGUAGE_KEY))) { LOG.debug("CPD on {}", file); IProparseEnvironment session = sessions.getSession(file.relativePath()); try { processFile(context, session, file); } catch (UncheckedIOException | ProparseRuntimeException caught) { if (caught.getCause() instanceof XCodedFileException) { LOG.error("Unable to process xcode'd file '{}", file); } else { LOG.error("Unable to lex file '{}'", file, caught); } } } } OpenEdgeCPDSensor(OpenEdgeSettings settings); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context); static void processTokenSource(InputFile file, NewCpdTokens cpdTokens, TokenSource stream);  }
@Test public void testCPDSensor() throws Exception { MapSettings settings = new MapSettings(); 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); OpenEdgeCPDSensor sensor = new OpenEdgeCPDSensor(oeSettings); sensor.execute(context); assertNotNull(context.cpdTokens(BASEDIR + ":" + FILE3)); assertEquals(context.cpdTokens(BASEDIR + ":" + FILE3).size(), 14); assertNotNull(context.cpdTokens(BASEDIR + ":" + CLASS1)); assertEquals(context.cpdTokens(BASEDIR + ":" + CLASS1).size(), 19); assertNotNull(context.cpdTokens(BASEDIR + ":" + FILE4)); assertEquals(context.cpdTokens(BASEDIR + ":" + FILE4).size(), 2); }
@Test public void testCPDSensor02() throws Exception { SensorContextTester context = TestProjectSensorContext.createContext(); OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); OpenEdgeCPDSensor sensor = new OpenEdgeCPDSensor(oeSettings); sensor.execute(context); assertNull(context.cpdTokens(BASEDIR + ":" + FILE3)); assertNull(context.cpdTokens(BASEDIR + ":" + CLASS1)); assertNull(context.cpdTokens(BASEDIR + ":" + FILE4)); }