本文整理汇总了Java中org.sonar.api.batch.fs.internal.DefaultFileSystem.setEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultFileSystem.setEncoding方法的具体用法?Java DefaultFileSystem.setEncoding怎么用?Java DefaultFileSystem.setEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sonar.api.batch.fs.internal.DefaultFileSystem
的用法示例。
在下文中一共展示了DefaultFileSystem.setEncoding方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.sonar.api.batch.fs.internal.DefaultFileSystem; //导入方法依赖的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);
}
示例2: setUp
import org.sonar.api.batch.fs.internal.DefaultFileSystem; //导入方法依赖的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);
}
示例3: setUp
import org.sonar.api.batch.fs.internal.DefaultFileSystem; //导入方法依赖的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);
}
示例4: setUp
import org.sonar.api.batch.fs.internal.DefaultFileSystem; //导入方法依赖的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);
}
示例5: setUp
import org.sonar.api.batch.fs.internal.DefaultFileSystem; //导入方法依赖的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);
}
示例6: setUp
import org.sonar.api.batch.fs.internal.DefaultFileSystem; //导入方法依赖的package包/类
private void setUp(Charset charset) throws IOException {
this.charset = charset;
DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot());
fileSystem.setEncoding(charset);
file = tempFolder.newFile();
inputFile = new DefaultInputFile("moduleKey", file.getName())
.setLanguage("jproperties")
.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);
}
示例7: setUp
import org.sonar.api.batch.fs.internal.DefaultFileSystem; //导入方法依赖的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("json")
.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);
}
示例8: createFileSystem
import org.sonar.api.batch.fs.internal.DefaultFileSystem; //导入方法依赖的package包/类
protected DefaultFileSystem createFileSystem() {
File workDir;
try {
workDir = temporaryFolder.newFolder("temp");
} catch (IOException e) {
throw new RuntimeException(e);
}
DefaultFileSystem fs = new DefaultFileSystem();
fs.setEncoding(Charset.defaultCharset());
fs.setWorkDir(workDir);
return fs;
}
示例9: createFileSystem
import org.sonar.api.batch.fs.internal.DefaultFileSystem; //导入方法依赖的package包/类
protected DefaultFileSystem createFileSystem() {
File workDir = temporaryFolder.newFolder("temp");
DefaultFileSystem fs = new DefaultFileSystem(workDir);
fs.setEncoding(Charset.defaultCharset());
fs.setWorkDir(workDir);
return fs;
}
示例10: getFirstHighlightingData
import org.sonar.api.batch.fs.internal.DefaultFileSystem; //导入方法依赖的package包/类
private HighlightingData getFirstHighlightingData(String filename) throws IOException {
File file = new File("src/test/resources/highlighting/" + filename);
DefaultInputFile inputFile = new DefaultInputFile("modulekey", filename)
.setModuleBaseDir(file.getParentFile().toPath())
.setType(InputFile.Type.MAIN)
.setLanguage(Xml.KEY)
.setCharset(StandardCharsets.UTF_8);
DefaultFileSystem localFS = new DefaultFileSystem(new File(file.getParent()));
localFS.setEncoding(StandardCharsets.UTF_8);
localFS.add(inputFile).setWorkDir(tmpFolder.newFolder());
XmlFile xmlFile = new XmlFile(wrap(inputFile), localFS);
return new XMLHighlighting(xmlFile).getHighlightingData().get(0);
}
示例11: should_parse_file_with_its_own_encoding
import org.sonar.api.batch.fs.internal.DefaultFileSystem; //导入方法依赖的package包/类
@Test
public void should_parse_file_with_its_own_encoding() throws IOException, XMLStreamException {
Charset fileSystemCharset = StandardCharsets.UTF_8;
Charset fileCharset = StandardCharsets.UTF_16;
Path moduleBaseDir = tmpFolder.newFolder().toPath();
SensorContextTester context = SensorContextTester.create(moduleBaseDir);
DefaultFileSystem fileSystem = new DefaultFileSystem(moduleBaseDir);
fileSystem.setEncoding(fileSystemCharset);
context.setFileSystem(fileSystem);
String filename = "utf16.xml";
try (BufferedWriter writer = Files.newBufferedWriter(moduleBaseDir.resolve(filename), fileCharset)) {
writer.write("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?>\n");
writer.write("<tag></tag>");
}
String modulekey = "modulekey";
DefaultInputFile defaultInputFile = new DefaultInputFile(modulekey, filename)
.setModuleBaseDir(moduleBaseDir)
.setType(InputFile.Type.MAIN)
.setLanguage(Xml.KEY)
.setCharset(fileCharset);
defaultInputFile.initMetadata(new FileMetadata().readMetadata(defaultInputFile.file(), fileCharset));
fileSystem.add(defaultInputFile);
XmlFile xmlFile = new XmlFile(wrap(defaultInputFile), fileSystem);
List<HighlightingData> highlightingData = new XMLHighlighting(xmlFile).getHighlightingData();
assertThat(highlightingData).hasSize(11);
}
示例12: should_analyze_file_with_its_own_encoding
import org.sonar.api.batch.fs.internal.DefaultFileSystem; //导入方法依赖的package包/类
@Test
public void should_analyze_file_with_its_own_encoding() throws IOException {
Charset fileSystemCharset = StandardCharsets.UTF_8;
Charset fileCharset = StandardCharsets.UTF_16;
Path moduleBaseDir = temporaryFolder.newFolder().toPath();
SensorContextTester context = SensorContextTester.create(moduleBaseDir);
DefaultFileSystem fileSystem = new DefaultFileSystem(moduleBaseDir);
fileSystem.setEncoding(fileSystemCharset);
context.setFileSystem(fileSystem);
String filename = "utf16.xml";
try (BufferedWriter writer = Files.newBufferedWriter(moduleBaseDir.resolve(filename), fileCharset)) {
writer.write("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?>\n");
writer.write("<tag></tag>");
}
String modulekey = "modulekey";
DefaultInputFile defaultInputFile = new DefaultInputFile(modulekey, filename)
.setModuleBaseDir(moduleBaseDir)
.setType(InputFile.Type.MAIN)
.setLanguage(Xml.KEY)
.setCharset(fileCharset);
defaultInputFile.initMetadata(new FileMetadata().readMetadata(defaultInputFile.file(), fileCharset));
fileSystem.add(defaultInputFile);
ActiveRules activeRules = new ActiveRulesBuilder()
.create(ruleKey)
.activate()
.build();
CheckFactory checkFactory = new CheckFactory(activeRules);
FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(mock(FileLinesContext.class));
sensor = new XmlSensor(fileSystem, checkFactory, fileLinesContextFactory);
sensor.analyse(context);
String componentKey = modulekey + ":" + filename;
assertThat(context.measure(componentKey, CoreMetrics.NCLOC).value()).isEqualTo(2);
}