当前位置: 首页>>代码示例>>Java>>正文


Java DefaultInputFile.initMetadata方法代码示例

本文整理汇总了Java中org.sonar.api.batch.fs.internal.DefaultInputFile.initMetadata方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultInputFile.initMetadata方法的具体用法?Java DefaultInputFile.initMetadata怎么用?Java DefaultInputFile.initMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.sonar.api.batch.fs.internal.DefaultInputFile的用法示例。


在下文中一共展示了DefaultInputFile.initMetadata方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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());

}
 
开发者ID:gretard,项目名称:sonar-ps-plugin,代码行数:24,代码来源:ScriptAnalyzerSensorTest.java

示例2: 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());

}
 
开发者ID:gretard,项目名称:sonar-ps-plugin,代码行数:22,代码来源:TokenizerSensorTest.java

示例3: 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());

}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:25,代码来源:HighlightingSensorTest.java

示例4: 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());

}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:20,代码来源:AntlrMeasurerTest.java

示例5: run

import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Test
public void run() throws IOException {
	TemporaryFolder folder = new TemporaryFolder();
	folder.create();
	Settings settings = new Settings();
	settings.setProperty(Constants.PLUGIN_SKIP_CUSTOM_RULES, false);
	String dirPath = "..\\grammars\\tsql";
	File dir = new File(dirPath);
	Collection<File> files = FileUtils.listFiles(dir, new String[] { "sql" }, true);
	SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
	for (File f : files) {
		String tempName = f.getName() + System.nanoTime();
		File dest = folder.newFile(tempName);
		FileUtils.copyFile(f, dest);

		DefaultInputFile file1 = new DefaultInputFile("test", tempName);
		file1.initMetadata(new String(Files.readAllBytes(f.toPath())));
		file1.setLanguage(TSQLLanguage.KEY);
		ctxTester.fileSystem().add(file1);

	}
	HighlightingSensor sensor = new HighlightingSensor(settings);
	sensor.execute(ctxTester);
	Collection<Issue> issues = ctxTester.allIssues();
	// System.out.println(files.size() + " " + issues.size() + " " + took);
	Assert.assertEquals(97, issues.size());

}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:29,代码来源:PluginRulesVerifierTest.java

示例6: getUselessWrapperClassForFile

import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
public static PhpFile getUselessWrapperClassForFile(String fileName) {
	File file = new File(fileName);
	DefaultInputFile inputFile = new DefaultInputFile("moduleKey", file.getName())
		.setModuleBaseDir(file.getParentFile().toPath())
		.setCharset(Charset.defaultCharset());

	try {
		inputFile.initMetadata(new String(Files.readAllBytes(file.toPath()), Charset.defaultCharset()));
	} catch (IOException e) {
		throw new IllegalStateException("Failed to create test file from: " + file.getAbsolutePath());
	}

	return CompatibilityHelper.phpFile(inputFile, SensorContextTester.create(new File("")));
}
 
开发者ID:Wikia,项目名称:sonar-php-rules,代码行数:15,代码来源:TestHelper.java

示例7: testHighlighting

import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Test
public void testHighlighting() throws Throwable {

	File baseFile0 = temp.newFile("customRulesSample", "xml");

	FileUtils.copyURLToFile(getClass().getResource("/customRulesSample.xml"), baseFile0);

	Settings settings = new Settings();
	settings.setProperty(Constants.PLUGIN_CUSTOM_RULES_PATH, baseFile0.getAbsolutePath());
	settings.setProperty(Constants.PLUGIN_CUSTOM_RULES_PREFIX, "customRulesSample");

	File baseFile = folder.newFile("test.sql");

	FileUtils.copyURLToFile(getClass().getResource("/testFiles/scriptExample.sql"), baseFile);

	DefaultInputFile file1 = new DefaultInputFile("test", "test.sql");

	file1.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));
	file1.setLanguage(TSQLLanguage.KEY);

	DefaultInputFile file2 = new DefaultInputFile("test", "test.php");
	file2.setLanguage("php");
	SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
	ctxTester.fileSystem().add(file1);
	ctxTester.fileSystem().add(file2);
	HighlightingSensor sensor = new HighlightingSensor(settings);
	sensor.execute(ctxTester);
	Collection<Issue> issues = ctxTester.allIssues();

	Assert.assertEquals(3, issues.size());
	Assert.assertEquals(0, ctxTester.highlightingTypeAt("test:test.sql", 0, 0).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(16, ctxTester.cpdTokens("test:test.sql").size());

}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:37,代码来源:HighlightingSensorTest.java

示例8: testAdd

import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Test
public void testAdd() throws Throwable {

	SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());

	File baseFile = folder.newFile("test.sql");

	FileUtils.copyURLToFile(getClass().getResource("/testFiles/TestTable.sql"), baseFile);

	DefaultInputFile ti = new DefaultInputFile("test", "test.sql");
	ti.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));
	ctxTester.fileSystem().add(ti);

	final TsqlIssue issue = new TsqlIssue();
	issue.setFilePath(ti.absolutePath());
	issue.setLine(2);
	issue.setType("test");
	issue.setDescription("test123");
	IIssuesProvider provider = new IIssuesProvider() {

		@Override
		public TsqlIssue[] getIssues(String baseDir) {
			return new TsqlIssue[] {

					issue };
		}

	};
	Settings settings = new Settings();
	BaseTsqlSensor sensor = new BaseTsqlSensor(settings, provider, "test") {
	};
	sensor.execute(ctxTester);
	Assert.assertEquals(1, ctxTester.allIssues().size());
}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:35,代码来源:BaseTsqlSensorTest.java

示例9: testAddLine0

import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Test
public void testAddLine0() throws Throwable {

	SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());

	File baseFile = folder.newFile("test.sql");

	FileUtils.copyURLToFile(getClass().getResource("/testFiles/TestTable.sql"), baseFile);

	DefaultInputFile ti = new DefaultInputFile("test", "test.sql");
	ti.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));

	ctxTester.fileSystem().add(ti);

	final TsqlIssue issue = new TsqlIssue();
	issue.setFilePath(ti.absolutePath());
	issue.setLine(0);
	issue.setType("test");
	issue.setDescription("test123");
	IIssuesProvider provider = new IIssuesProvider() {

		@Override
		public TsqlIssue[] getIssues(String baseDir) {
			return new TsqlIssue[] {

					issue };
		}

	};
	Settings settings = new Settings();
	BaseTsqlSensor sensor = new BaseTsqlSensor(settings, provider, "test") {
	};
	sensor.execute(ctxTester);
	Assert.assertEquals(0, ctxTester.allIssues().size());
}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:36,代码来源:BaseTsqlSensorTest.java

示例10: testAddDescNull

import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Test
public void testAddDescNull() throws Throwable {

	SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());

	File baseFile = folder.newFile("test.sql");

	FileUtils.copyURLToFile(getClass().getResource("/testFiles/TestTable.sql"), baseFile);

	DefaultInputFile ti = new DefaultInputFile("test", "test.sql");
	ti.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));

	ctxTester.fileSystem().add(ti);

	final TsqlIssue issue = new TsqlIssue();
	issue.setFilePath(ti.absolutePath());
	issue.setLine(1);
	issue.setType("test");
	IIssuesProvider provider = new IIssuesProvider() {

		@Override
		public TsqlIssue[] getIssues(String baseDir) {
			return new TsqlIssue[] {

					issue };
		}

	};
	Settings settings = new Settings();
	BaseTsqlSensor sensor = new BaseTsqlSensor(settings, provider, "test") {
	};
	sensor.execute(ctxTester);
	Assert.assertEquals(1, ctxTester.allIssues().size());
}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:35,代码来源:BaseTsqlSensorTest.java

示例11: compareWithDefaultInputFile

import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Test
public void compareWithDefaultInputFile() throws IOException {
	String s = "select " + "*" + "from dbo.test\r\nselect 1";
	File ff = folder.newFile("test.sql");
	FileUtils.write(ff, s);
	DefaultInputFile f = new DefaultInputFile("test", "test.sql");
	f.initMetadata(s);
	f.setLanguage(TSQLLanguage.KEY);
	
	AntrlResult result = Antlr4Utils.getFull(s);
	SourceLinesProvider p = new SourceLinesProvider();
	SourceLine[] lines = p.getLines(new FileInputStream(ff), Charset.defaultCharset());
	FillerRequest file = new FillerRequest(null, null, result.getTree(), lines);
	for (SourceLine l : lines) {
		System.out.println(l);
	}
	for (Token t : result.getStream().getTokens()) {
		if (t.getType() == Token.EOF) {
			continue;
		}
		int[] start = file.getLineAndColumn(t.getStartIndex());
		int[] end = file.getLineAndColumn(t.getStopIndex());
		TextPointer p1 = f.newPointer(t.getStartIndex());
		TextPointer p2 = f.newPointer(t.getStopIndex());
		Assert.assertNotNull(start);
		Assert.assertNotNull(end);
		Assert.assertEquals(p1.line(), start[0]);
		Assert.assertEquals(p1.lineOffset(), start[1]);
		Assert.assertEquals(p2.line(), end[0]);
		Assert.assertEquals(p2.lineOffset(), end[1]);
	}
}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:33,代码来源:AntrlFileTest.java

示例12: should_parse_file_with_its_own_encoding

import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的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);
}
 
开发者ID:SonarSource,项目名称:sonar-xml,代码行数:32,代码来源:XmlHighlightingTest.java

示例13: createInputFile

import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
private DefaultInputFile createInputFile(String name) {
  DefaultInputFile defaultInputFile = new DefaultInputFile("modulekey", name)
    .setModuleBaseDir(Paths.get("src/test/resources"))
    .setType(InputFile.Type.MAIN)
    .setLanguage(Xml.KEY)
    .setCharset(StandardCharsets.UTF_8);
  defaultInputFile.initMetadata(new FileMetadata().readMetadata(defaultInputFile.file(), StandardCharsets.UTF_8));
  return defaultInputFile;
}
 
开发者ID:SonarSource,项目名称:sonar-xml,代码行数:10,代码来源:XmlSensorTest.java

示例14: should_analyze_file_with_its_own_encoding

import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的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);
}
 
开发者ID:SonarSource,项目名称:sonar-xml,代码行数:41,代码来源:XmlSensorTest.java


注:本文中的org.sonar.api.batch.fs.internal.DefaultInputFile.initMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。