本文整理汇总了Java中org.sonar.api.batch.fs.InputFile.Type类的典型用法代码示例。如果您正苦于以下问题:Java Type类的具体用法?Java Type怎么用?Java Type使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Type类属于org.sonar.api.batch.fs.InputFile包,在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
@CheckForNull
SonarLintInputFile create(ClientInputFile inputFile) {
SonarLintInputFile defaultInputFile = new SonarLintInputFile(inputFile);
defaultInputFile.setType(inputFile.isTest() ? Type.TEST : Type.MAIN);
if (inputFile.language() != null) {
LOG.debug("Language of file '{}' is set to '{}'", inputFile.getPath(), inputFile.language());
defaultInputFile.setLanguage(inputFile.language());
} else {
defaultInputFile.setLanguage(langDetection.language(defaultInputFile));
}
Charset charset = inputFile.getCharset();
InputStream stream;
try {
stream = inputFile.inputStream();
} catch (IOException e) {
throw new IllegalStateException("Failed to open a stream on file: " + inputFile.getPath(), e);
}
defaultInputFile.init(fileMetadata.readMetadata(stream, charset != null ? charset : Charset.defaultCharset(), inputFile.getPath()));
return defaultInputFile;
}
示例2: testExecute
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
@Test
public void testExecute() {
// Sensor context
final SensorContextTester sensorContext = SensorContextTester.create(new File("."));
addFile(sensorContext, "/packagea/package-info.java", "java", Type.MAIN);
addFile(sensorContext, "/packagea/ClassA.java", "java", Type.MAIN);
addFile(sensorContext, "/packageb/package-info.java", "java", Type.TEST);
addFile(sensorContext, "/packageb/ClassB.java", "java", Type.TEST);
addFile(sensorContext, "/packagec/ClassC.pas", "pascal", Type.MAIN);
// Execute
final PackagesSensor subject = new PackagesSensor();
subject.execute(sensorContext);
// Check counts
checkMetrics(sensorContext, "moduleKey:/packagea/package-info.java", 1, 1);
checkMetrics(sensorContext, "moduleKey:/packagea/ClassA.java", null, 1);
checkMetrics(sensorContext, "moduleKey:/packageb/package-info.java", null, null);
checkMetrics(sensorContext, "moduleKey:/packageb/ClassB.java", null, null);
checkMetrics(sensorContext, "moduleKey:/packagec/ClassC.pas", null, null);
}
示例3: JavaPropertiesSquidSensor
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
public JavaPropertiesSquidSensor(FileSystem fileSystem, CheckFactory checkFactory, @Nullable CustomJavaPropertiesRulesDefinition[] customRulesDefinition) {
this.fileSystem = fileSystem;
this.charset = Charset.forName("ISO-8859-1");
this.mainFilePredicate = fileSystem.predicates().and(
fileSystem.predicates().hasType(InputFile.Type.MAIN),
fileSystem.predicates().hasLanguage(JavaPropertiesLanguage.KEY));
this.parser = JavaPropertiesParserBuilder.createParser(charset);
this.checks = JavaPropertiesChecks.createJavaPropertiesChecks(checkFactory)
.addChecks(GenericJavaPropertiesRulesDefinition.GENERIC_REPOSITORY_KEY, GenericJavaPropertiesRulesDefinition.getChecks())
.addChecks(SonarScannerJavaPropertiesRulesDefinition.SONAR_SCANNER_REPOSITORY_KEY, SonarScannerJavaPropertiesRulesDefinition.getChecks())
.addCustomChecks(customRulesDefinition);
}
示例4: sensor_descriptor
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
@Test
public void sensor_descriptor() {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
createSensor().describe(descriptor);
assertThat(descriptor.name()).isEqualTo("1C 7.7 sensor");
assertThat(descriptor.languages()).containsOnly("1c 7.7");
assertThat(descriptor.type()).isEqualTo(Type.MAIN);
}
示例5: buildModel
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
@Override
protected Model<Location> buildModel(final SensorContext context) {
// Result
final Model<Location> model = new Model<>();
final ModelCreatingTreeVisitor visitor = new ModelCreatingTreeVisitor(model);
// Read all source files
final ActionParser<Tree> parser = JavaParser.createParser();
final JavaClasspath javaClassPath = new JavaClasspath(settings, context.fileSystem());
final FileSystem fs = context.fileSystem();
// Scan only main files for the 'current' language.
final FilePredicate filesToScan = fs.predicates().and(fs.predicates().hasType(Type.MAIN),
fs.predicates().hasLanguage(LANGUAGE));
for (final InputFile file : fs.inputFiles(filesToScan)) {
// Parse source
LOGGER.debug("Analyzing source file: {}", file.relativePath());
try {
visitor.on(file);
final Tree tree = parser.parse(file.contents());
// Create semantic model
LOGGER.debug("Creating semantic model ...");
SemanticModel.createFor((CompilationUnitTree) tree, javaClassPath.getElements());
// Read into model
LOGGER.debug("Reading model ...");
tree.accept(visitor);
} catch (final IOException e) {
LOGGER.warn("Could not read contents for {}", file.relativePath(), e);
}
}
return model;
}
示例6: describe
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.onlyOnLanguage(CssLanguage.KEY)
.name("CSS Analyzer Sensor")
.onlyOnFileType(Type.MAIN);
}
示例7: describe
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.onlyOnLanguage(LessLanguage.KEY)
.name("Less Analyzer Sensor")
.onlyOnFileType(Type.MAIN);
}
示例8: describe
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.onlyOnLanguage(ScssLanguage.KEY)
.name("SCSS Analyzer Sensor")
.onlyOnFileType(Type.MAIN);
}
示例9: shouldExecuteOnProject
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
@Override
public boolean shouldExecuteOnProject(Project project) {
final FilePredicates predicates = fileSystem.predicates();
final Iterable<File> mainFiles = fileSystem
.files(predicates.and(predicates.hasLanguage(CheckstyleConstants.JAVA_KEY),
predicates.hasType(Type.MAIN)));
final boolean mainFilesIsEmpty = !mainFiles.iterator().hasNext();
return !mainFilesIsEmpty
&& !profile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY)
.isEmpty();
}
示例10: execute
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
@Override
public void execute(final SensorContext context) {
final FileSystem fileSystem = context.fileSystem();
final FilePredicates predicates = fileSystem.predicates();
for (final InputFile inputFile : context.fileSystem().inputFiles(
predicates.and(predicates.hasLanguage(Rules.LANGUAGE_JAVA), predicates.hasType(Type.MAIN)))) {
if (inputFile.relativePath().endsWith("/package-info.java")) {
addMetric(context, inputFile, PackagesMetrics.PACKAGE_INFO_COUNT);
}
addMetric(context, inputFile, PackagesMetrics.JAVA_COUNT);
}
}
示例11: addFile
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
private void addFile(final SensorContextTester sensorContext, final String name, final String language,
final Type type) {
final DefaultInputFile file = new DefaultInputFile("moduleKey", name);
file.setLanguage(language);
file.setType(type);
sensorContext.fileSystem().add(file);
}
示例12: describe
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.onlyOnLanguage(PerlLanguage.KEY)
.name("Perl Sensor")
.onlyOnFileType(Type.MAIN);
}
示例13: execute
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
@Override
public void execute(SensorContext context) {
FileSystem fileSystem = context.fileSystem();
FilePredicate mainFilePredicate = fileSystem.predicates().and(
fileSystem.predicates().hasType(InputFile.Type.MAIN),
fileSystem.predicates().hasLanguage(PerlLanguage.KEY));
List<InputFile> inputFiles = new ArrayList<>();
fileSystem.inputFiles(mainFilePredicate).forEach(inputFiles::add);
for (InputFile inputFile : inputFiles) {
this.analyseFile(inputFile, fileSystem.encoding(), context);
}
}
示例14: describe
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
.onlyOnLanguage(PerlLanguage.KEY)
.name("Perl Test::Harness Sensor")
.onlyOnFileType(Type.TEST);
}
示例15: getUnitTestInputFile
import org.sonar.api.batch.fs.InputFile.Type; //导入依赖的package包/类
/**
* Gets the file pointed by the report.
*
* @param report the unit test report
*/
private InputFile getUnitTestInputFile(String filePath) {
return fileSystem.inputFile(fileSystem.predicates().and(
filePredicates.hasPath(filePath),
filePredicates.hasType(InputFile.Type.TEST),
filePredicates.hasLanguage(PerlLanguage.KEY)));
}