本文整理汇总了Java中org.sonar.api.batch.fs.internal.DefaultInputFile类的典型用法代码示例。如果您正苦于以下问题:Java DefaultInputFile类的具体用法?Java DefaultInputFile怎么用?Java DefaultInputFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultInputFile类属于org.sonar.api.batch.fs.internal包,在下文中一共展示了DefaultInputFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: key
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
@Test
public void key() {
FilePredicate predicate = new AdditionalFilePredicates.KeyPredicate("struts:Action.java");
DefaultInputFile inputFile = new TestInputFileBuilder("struts", "Action.java").build();
assertThat(predicate.apply(inputFile)).isTrue();
inputFile = new TestInputFileBuilder("struts", "Filter.java").build();
assertThat(predicate.apply(inputFile)).isFalse();
}
示例2: testExecute
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
@Test
public void testExecute() throws IOException {
Context t = new RulesDefinition.Context();
ScriptAnalyzerRulesDefinition def = new ScriptAnalyzerRulesDefinition();
def.define(t);
File baseFile = folder.newFile("test.ps1");
FileUtils.copyURLToFile(getClass().getResource("/testFiles/test.ps1"), baseFile);
DefaultFileSystem fs = new DefaultFileSystem(folder.getRoot());
DefaultInputFile ti = new DefaultInputFile("test", "test.ps1");
ti.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));
fs.add(ti);
SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
ScriptAnalyzerSensor s = new ScriptAnalyzerSensor(fs, temp);
s.execute(ctxTester);
Assert.assertEquals(4, ctxTester.allIssues().size());
}
示例3: testExecute
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
@Test
public void testExecute() throws IOException, InterruptedException {
File baseFile = folder.newFile("test.ps1");
FileUtils.copyURLToFile(getClass().getResource("/testFiles/test.ps1"), baseFile);
DefaultFileSystem fs = new DefaultFileSystem(folder.getRoot());
DefaultInputFile ti = new DefaultInputFile("test", "test.ps1");
ti.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));
ti.setLanguage(PowershellLanguage.KEY);
fs.add(ti);
SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
ctxTester.setFileSystem(fs);
TokenizerSensor s = new TokenizerSensor(new Settings(), temp);
s.execute(ctxTester);
Assert.assertEquals(16, ctxTester.cpdTokens("test:test.ps1").size());
Assert.assertEquals(1, ctxTester.highlightingTypeAt("test:test.ps1", 1, 5).size());
}
示例4: setUp
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot());
fileSystem.setEncoding(Charsets.UTF_8);
file = tempFolder.newFile();
inputFile = new DefaultInputFile("moduleKey", file.getName())
.setLanguage("less")
.setType(InputFile.Type.MAIN);
fileSystem.add(inputFile);
sensorContext = SensorContextTester.create(tempFolder.getRoot());
sensorContext.setFileSystem(fileSystem);
visitorContext = mock(TreeVisitorContext.class);
highlighterVisitor = new LessSyntaxHighlighterVisitor(sensorContext);
when(visitorContext.getFile()).thenReturn(file);
}
示例5: setUp
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot());
fileSystem.setEncoding(Charsets.UTF_8);
file = tempFolder.newFile();
inputFile = new DefaultInputFile("moduleKey", file.getName())
.setLanguage("scss")
.setType(InputFile.Type.MAIN);
fileSystem.add(inputFile);
sensorContext = SensorContextTester.create(tempFolder.getRoot());
sensorContext.setFileSystem(fileSystem);
visitorContext = mock(TreeVisitorContext.class);
highlighterVisitor = new ScssSyntaxHighlighterVisitor(sensorContext);
when(visitorContext.getFile()).thenReturn(file);
}
示例6: setUp
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot());
fileSystem.setEncoding(Charsets.UTF_8);
file = tempFolder.newFile();
inputFile = new DefaultInputFile("moduleKey", file.getName())
.setLanguage("css")
.setType(InputFile.Type.MAIN);
fileSystem.add(inputFile);
sensorContext = SensorContextTester.create(tempFolder.getRoot());
sensorContext.setFileSystem(fileSystem);
visitorContext = mock(TreeVisitorContext.class);
highlighterVisitor = new CssSyntaxHighlighterVisitor(sensorContext);
when(visitorContext.getFile()).thenReturn(file);
}
示例7: setUp
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
private void setUp(String fileName) {
File moduleBaseDir = new File("src/test/resources/metrics/");
context = SensorContextTester.create(moduleBaseDir);
DefaultInputFile inputFile = new DefaultInputFile("moduleKey", fileName)
.setModuleBaseDir(moduleBaseDir.toPath())
.setLanguage("css")
.setType(InputFile.Type.MAIN);
context.fileSystem().add(inputFile);
context.fileSystem().setEncoding(Charsets.UTF_8);
CssMetricsVisitor metricsVisitor = new CssMetricsVisitor(context, mock(NoSonarFilter.class));
TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class);
when(treeVisitorContext.getFile()).thenReturn(inputFile.file());
when(treeVisitorContext.getTopTree()).thenReturn(CssParser.createParser(Charsets.UTF_8).parse(inputFile.file()));
metricsVisitor.scanTree(treeVisitorContext);
}
示例8: setUp
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
private void setUp(String fileName) {
File moduleBaseDir = new File("src/test/resources/metrics/");
context = SensorContextTester.create(moduleBaseDir);
DefaultInputFile inputFile = new DefaultInputFile("moduleKey", fileName)
.setModuleBaseDir(moduleBaseDir.toPath())
.setLanguage("less")
.setType(InputFile.Type.MAIN);
context.fileSystem().add(inputFile);
context.fileSystem().setEncoding(Charsets.UTF_8);
LessMetricsVisitor metricsVisitor = new LessMetricsVisitor(context, mock(NoSonarFilter.class));
TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class);
when(treeVisitorContext.getFile()).thenReturn(inputFile.file());
when(treeVisitorContext.getTopTree()).thenReturn(LessParser.createParser(Charsets.UTF_8).parse(inputFile.file()));
metricsVisitor.scanTree(treeVisitorContext);
}
示例9: setUp
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
private void setUp(String fileName) {
File moduleBaseDir = new File("src/test/resources/metrics/");
context = SensorContextTester.create(moduleBaseDir);
DefaultInputFile inputFile = new DefaultInputFile("moduleKey", fileName)
.setModuleBaseDir(moduleBaseDir.toPath())
.setLanguage("scss")
.setType(InputFile.Type.MAIN);
context.fileSystem().add(inputFile);
context.fileSystem().setEncoding(Charsets.UTF_8);
ScssMetricsVisitor metricsVisitor = new ScssMetricsVisitor(context, mock(NoSonarFilter.class));
TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class);
when(treeVisitorContext.getFile()).thenReturn(inputFile.file());
when(treeVisitorContext.getTopTree()).thenReturn(ScssParser.createParser(Charsets.UTF_8).parse(inputFile.file()));
metricsVisitor.scanTree(treeVisitorContext);
}
示例10: setUp
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot());
fileSystem.setEncoding(Charsets.UTF_8);
file = tempFolder.newFile();
inputFile = new DefaultInputFile("moduleKey", file.getName())
.setLanguage("css")
.setType(InputFile.Type.MAIN);
fileSystem.add(inputFile);
sensorContext = SensorContextTester.create(tempFolder.getRoot());
sensorContext.setFileSystem(fileSystem);
visitorContext = mock(TreeVisitorContext.class);
cpdVisitor = new CpdVisitor(sensorContext);
when(visitorContext.getFile()).thenReturn(file);
}
示例11: test_symbolrefs_get_imported
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
@Test
public void test_symbolrefs_get_imported() throws FileNotFoundException {
SensorContextTester tester = SensorContextTester.create(TEST_DATA_DIR);
DefaultInputFile inputFile = new DefaultInputFile("dummyKey", TEST_FILE_PATH)
.initMetadata(new FileMetadata().readMetadata(new FileReader(TEST_FILE)));
tester.fileSystem().add(inputFile);
File protobuf = new File(TEST_DATA_DIR, SYMBOLREFS_OUTPUT_PROTOBUF_NAME);
assertThat(protobuf.isFile()).withFailMessage("no such file: " + protobuf).isTrue();
new SymbolRefsImporter(tester, f -> true).accept(protobuf.toPath());
// a symbol is defined at this location, and referenced at 3 other locations
assertThat(tester.referencesForSymbolAt(inputFile.key(), 25, 34)).hasSize(3);
// ... other similar examples ...
assertThat(tester.referencesForSymbolAt(inputFile.key(), 25, 43)).hasSize(3);
assertThat(tester.referencesForSymbolAt(inputFile.key(), 56, 30)).hasSize(1);
assertThat(tester.referencesForSymbolAt(inputFile.key(), 56, 37)).hasSize(1);
}
示例12: test_issues_get_imported
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
@Test
public void test_issues_get_imported() throws FileNotFoundException {
SensorContextTester tester = SensorContextTester.create(TEST_DATA_DIR);
DefaultInputFile inputFile = new DefaultInputFile("dummyKey", TEST_FILE_PATH)
.initMetadata(new FileMetadata().readMetadata(new FileReader(TEST_FILE)));
tester.fileSystem().add(inputFile);
File protobuf = new File(TEST_DATA_DIR, ISSUES_OUTPUT_PROTOBUF_NAME);
assertThat(protobuf.isFile()).withFailMessage("no such file: " + protobuf).isTrue();
new IssuesImporter(tester, "dummy", f -> true).accept(protobuf.toPath());
Collection<Issue> issues = tester.allIssues();
assertThat(issues).hasSize(6);
assertThat(issues.stream().map(p -> p.ruleKey().rule()).collect(Collectors.toList()))
.containsOnly("S1186", "S1172", "S1118", "S101", "S101", "S105");
TextRange exactLocation = issues.stream().filter(i -> i.ruleKey().rule().equals("S1186")).findFirst().get().primaryLocation().textRange();
assertThat(exactLocation.start().line() != exactLocation.end().line() || exactLocation.start().lineOffset() != exactLocation.end().lineOffset()).isTrue();
exactLocation = issues.stream().filter(i -> i.ruleKey().rule().equals("S105")).findFirst().get().primaryLocation().textRange();
assertThat(exactLocation).isNull();
}
示例13: setUp
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot());
fileSystem.setEncoding(Charsets.UTF_8);
file = tempFolder.newFile();
inputFile = new DefaultInputFile("moduleKey", file.getName())
.setLanguage("gherkin")
.setType(InputFile.Type.MAIN);
fileSystem.add(inputFile);
sensorContext = SensorContextTester.create(tempFolder.getRoot());
sensorContext.setFileSystem(fileSystem);
visitorContext = mock(TreeVisitorContext.class);
highlighterVisitor = new SyntaxHighlighterVisitor(sensorContext);
when(visitorContext.getFile()).thenReturn(file);
}
示例14: testHighlighting2
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
@Test
public void testHighlighting2() throws Throwable {
Settings settings = new Settings();
File baseFile = folder.newFile("test.sql");
FileUtils.write(baseFile, "SELECT * FROM dbo.test");
DefaultInputFile file1 = new DefaultInputFile("test", "test.sql");
file1.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));
file1.setLanguage(TSQLLanguage.KEY);
SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
ctxTester.fileSystem().add(file1);
HighlightingSensor sensor = new HighlightingSensor(settings);
sensor.execute(ctxTester);
Assert.assertEquals(1, ctxTester.highlightingTypeAt("test:test.sql", 1, 5).size());
Assert.assertEquals(0, ctxTester.highlightingTypeAt("test:test.sql", 2, 0).size());
Assert.assertEquals(0, ctxTester.highlightingTypeAt("test:test.sql", 5, 0).size());
Assert.assertEquals(1, ctxTester.cpdTokens("test:test.sql").size());
}
示例15: test
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入依赖的package包/类
@Test
public void test() throws IOException {
String s = "/** comment **/\r\n" + "select\r\n" + "11\n" + "--aaa\r\n";
File ff = folder.newFile("test.sql");
FileUtils.write(ff, s);
DefaultInputFile f = new DefaultInputFile("test", "test.sql");
f.initMetadata(s);
f.setLanguage(TSQLLanguage.KEY);
SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
ctxTester.fileSystem().add(f);
AntrlResult result = Antlr4Utils.getFull(s);
AntlrMeasurer m = new AntlrMeasurer();
SourceLine[] lines = new SourceLinesProvider().getLines(new FileInputStream(ff), Charset.defaultCharset());
m.fill(ctxTester, new FillerRequest(f, result.getStream(), result.getTree(), lines));
Assert.assertEquals(2, ctxTester.measure("test:test.sql", CoreMetrics.NCLOC).value().intValue());
Assert.assertEquals(2, ctxTester.measure("test:test.sql", CoreMetrics.COMMENT_LINES).value().intValue());
}