You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.7 KiB
91 lines
2.7 KiB
/*
|
|
* Copyright (c) 2023 - 2024. KeyWare.Co.Ltd All rights reserved.
|
|
* 项目名称:C++ 信息安全性设计准则
|
|
* 项目描述:用于检查C++源代码的安全性设计准则的Sonarqube插件
|
|
* 版权说明:本软件属北京关键科技股份有限公司所有,在未获得北京关键科技股份有限公司正式授权情况下,任何企业和个人,不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
|
|
*/
|
|
package com.keyware.sonar.cxx;
|
|
|
|
import com.google.common.base.Splitter;
|
|
import com.google.common.collect.Iterables;
|
|
import org.sonar.api.config.Configuration;
|
|
import org.sonar.api.config.PropertyDefinition;
|
|
import org.sonar.api.resources.AbstractLanguage;
|
|
import org.sonar.api.resources.Qualifiers;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
public class CxxLanguage extends AbstractLanguage {
|
|
|
|
/**
|
|
* cxx language key
|
|
*/
|
|
public static final String KEY = "cxx";
|
|
|
|
/**
|
|
* cxx language name
|
|
*/
|
|
public static final String NAME = "CXX";
|
|
|
|
/**
|
|
* Key of the file suffix parameter
|
|
*/
|
|
public static final String FILE_SUFFIXES_KEY = "sonar.cxx.file.suffixes";
|
|
|
|
/**
|
|
* Default cxx files knows suffixes
|
|
*/
|
|
public static final String DEFAULT_FILE_SUFFIXES = ".cxx,.cpp,.cc,.c,.hxx,.hpp,.hh,.h";
|
|
|
|
/**
|
|
* Settings of the plugin.
|
|
*/
|
|
private final Configuration config;
|
|
|
|
public CxxLanguage(Configuration config) {
|
|
super(KEY, NAME);
|
|
this.config = config;
|
|
}
|
|
|
|
public static List<PropertyDefinition> properties() {
|
|
return Collections.unmodifiableList(Arrays.asList(
|
|
PropertyDefinition.builder(FILE_SUFFIXES_KEY)
|
|
.defaultValue(DEFAULT_FILE_SUFFIXES)
|
|
.name("File suffixes")
|
|
.multiValues(true)
|
|
.description(
|
|
"List of suffixes for files to analyze (e.g. `.cxx,.cpp,.cc,.c,.hxx,.hpp,.hh,.h`)."
|
|
+ " In the SonarQube UI, enter one file suffixe per field."
|
|
+ " To turn off the CXX language, set the first entry to `-`."
|
|
)
|
|
.category("CXX")
|
|
.subCategory("(1) General")
|
|
.onQualifiers(Qualifiers.PROJECT)
|
|
.build()
|
|
));
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*
|
|
* @see AbstractLanguage#getFileSuffixes()
|
|
*/
|
|
@Override
|
|
public String[] getFileSuffixes() {
|
|
String[] suffixes = Arrays.stream(config.getStringArray(FILE_SUFFIXES_KEY))
|
|
.filter(s -> s != null && !s.trim().isEmpty()).toArray(String[]::new);
|
|
if (suffixes.length == 0) {
|
|
suffixes = Iterables.toArray(Splitter.on(',').split(DEFAULT_FILE_SUFFIXES), String.class);
|
|
}
|
|
if ("-".equals(suffixes[0])) {
|
|
suffixes = new String[]{"disabled"};
|
|
}
|
|
return suffixes;
|
|
}
|
|
|
|
}
|
|
|