本文整理汇总了Java中org.sonar.api.utils.MessageException.of方法的典型用法代码示例。如果您正苦于以下问题:Java MessageException.of方法的具体用法?Java MessageException.of怎么用?Java MessageException.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sonar.api.utils.MessageException
的用法示例。
在下文中一共展示了MessageException.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
@VisibleForTesting
static PluginInfo create(Path jarPath, PluginManifest manifest) {
if (StringUtils.isBlank(manifest.getKey())) {
throw MessageException.of(String.format("File is not a plugin. Please delete it and restart: %s", jarPath.toAbsolutePath()));
}
PluginInfo info = new PluginInfo(manifest.getKey());
info.setJarFile(jarPath.toFile());
info.setName(manifest.getName());
info.setMainClass(manifest.getMainClass());
info.setVersion(Version.create(manifest.getVersion()));
// optional fields
info.setUseChildFirstClassLoader(manifest.isUseChildFirstClassLoader());
info.setBasePlugin(manifest.getBasePlugin());
info.setImplementationBuild(manifest.getImplementationBuild());
info.setSonarLintSupported(manifest.isSonarLintSupported());
String[] requiredPlugins = manifest.getRequirePlugins();
if (requiredPlugins != null) {
for (String s : requiredPlugins) {
info.addRequiredPlugin(RequiredPlugin.parse(s));
}
}
return info;
}
示例2: language
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
@CheckForNull
String language(InputFile inputFile) {
String detectedLanguage = null;
for (String languageKey : languagesToConsider) {
if (isCandidateForLanguage(inputFile, languageKey)) {
if (detectedLanguage == null) {
detectedLanguage = languageKey;
} else {
// Language was already forced by another pattern
throw MessageException.of(MessageFormat.format("Language of file ''{0}'' can not be decided as the file matches patterns of both {1} and {2}",
inputFile.relativePath(), getDetails(detectedLanguage), getDetails(languageKey)));
}
}
}
if (detectedLanguage != null) {
LOG.debug("Language of file '{}' is detected to be '{}'", inputFile.absolutePath(), detectedLanguage);
return detectedLanguage;
}
return null;
}
示例3: defineRulesForLanguage
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
private void defineRulesForLanguage(Context context, String repositoryKey, String repositoryName,
String languageKey) {
NewRepository repository = context.createRepository(repositoryKey, languageKey).setName(repositoryName);
try(InputStream rulesXml = this.getClass().getResourceAsStream(rulesDefinitionFilePath())) {
if (rulesXml != null) {
RulesDefinitionXmlLoader rulesLoader = new RulesDefinitionXmlLoader();
rulesLoader.load(repository, rulesXml, StandardCharsets.UTF_8.name());
addRemediationCost(repository.rules());
}
} catch (IOException e) {
throw MessageException.of("Unable to load rules defintion", e);
}
repository.done();
}
示例4: init
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
public void init(int pullRequestNumber, File projectBaseDir) {
initGitBaseDir(projectBaseDir);
try {
GitHub github;
if (config.isProxyConnectionEnabled()) {
github = new GitHubBuilder().withProxy(config.getHttpProxy()).withEndpoint(config.endpoint()).withOAuthToken(config.oauth()).build();
} else {
github = new GitHubBuilder().withEndpoint(config.endpoint()).withOAuthToken(config.oauth()).build();
}
setGhRepo(github.getRepository(config.repository()));
setPr(ghRepo.getPullRequest(pullRequestNumber));
LOG.info("Starting analysis of pull request: " + pr.getHtmlUrl());
myself = github.getMyself().getLogin();
loadExistingReviewComments();
patchPositionMappingByFile = mapPatchPositionsToLines(pr);
} catch (IOException e) {
LOG.debug("Unable to perform GitHub WS operation", e);
throw MessageException.of("Unable to perform GitHub WS operation: " + e.getMessage());
}
}
示例5: validateRule
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
private DefaultRule validateRule(Issue issue) {
RuleKey ruleKey = issue.ruleKey();
Rule rule = rules.find(ruleKey);
if (rule == null) {
throw MessageException.of(String.format("The rule '%s' does not exist.", ruleKey));
}
if (Strings.isNullOrEmpty(rule.name()) && Strings.isNullOrEmpty(issue.primaryLocation().message())) {
throw MessageException.of(String.format("The rule '%s' has no name and the related issue has no message.", ruleKey));
}
return (DefaultRule) rule;
}
示例6: getCostByRule
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
private static Map<String, String> getCostByRule() {
Map<String, String> result = new HashMap<>();
try (InputStream stream = PerlCriticRulesDefinition.class.getResourceAsStream(COST_FILE_CSV);
Stream< String>lines = new BufferedReader(new InputStreamReader(stream)).lines()) {
lines //
.skip(1) // header line
.forEach(line -> PerlCriticRulesDefinition.completeCost(line, result));
} catch (IOException e) {
throw MessageException.of("Unable to load rules remediation function/factor", e);
}
return result;
}
示例7: notificationCommitStatus
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
private void notificationCommitStatus(String status, String message) {
if ("failed".equals(status)) {
throw MessageException.of(message);
} else {
LOG.info(message);
}
}
示例8: buildFreemarkerComment
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
private String buildFreemarkerComment() {
Configuration cfg = new Configuration(Configuration.getVersion());
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setLogTemplateExceptions(false);
try (StringWriter sw = new StringWriter()) {
new Template(templateName, template, cfg).process(createContext(), sw);
return StringEscapeUtils.unescapeHtml4(sw.toString());
} catch (IOException | TemplateException e) {
LOG.error("Failed to create template {}", templateName, e);
throw MessageException.of("Failed to create template " + templateName);
}
}
示例9: repository
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
public String repository() {
if (settings.hasKey(GitHubPlugin.GITHUB_REPO)) {
return repoFromProp();
}
if (isNotBlank(settings.getString(CoreProperties.LINKS_SOURCES_DEV)) || isNotBlank(settings.getString(CoreProperties.LINKS_SOURCES))) {
return repoFromScmProps();
}
throw MessageException.of("Unable to determine GitHub repository name for this project. Please provide it using property '" + GitHubPlugin.GITHUB_REPO
+ "' or configure property '" + CoreProperties.LINKS_SOURCES + "'.");
}
示例10: getVerifiedRepositoryBuilder
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
static RepositoryBuilder getVerifiedRepositoryBuilder(Path basedir) {
RepositoryBuilder builder = new RepositoryBuilder()
.findGitDir(basedir.toFile())
.setMustExist(true);
if (builder.getGitDir() == null) {
throw MessageException.of("Not inside a Git work tree: " + basedir);
}
return builder;
}
示例11: privateKey
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
@CheckForNull
public File privateKey() {
if (settings.hasKey(PRIVATE_KEY_PATH_PROP_KEY)) {
File privateKeyFile = new File(settings.getString(PRIVATE_KEY_PATH_PROP_KEY));
if (!privateKeyFile.exists() || !privateKeyFile.isFile() || !privateKeyFile.canRead()) {
throw MessageException.of("Unable to read private key from '" + privateKeyFile + "'");
}
return privateKeyFile;
}
return null;
}
示例12: IssuesChecker
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
public IssuesChecker(Settings settings, RulesProfile profile) {
oldDumpFile = getFile(settings, LITSPlugin.OLD_DUMP_PROPERTY);
newDumpFile = getFile(settings, LITSPlugin.NEW_DUMP_PROPERTY);
differencesFile = getFile(settings, LITSPlugin.DIFFERENCES_PROPERTY);
for (ActiveRule activeRule : profile.getActiveRules()) {
if (!activeRule.getSeverity().toString().equals(Severity.INFO)) {
throw MessageException.of("Rule '" + activeRule.getRepositoryKey() + ":" + activeRule.getRuleKey() + "' must be declared with severity INFO");
}
}
}
示例13: getFile
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
private static File getFile(Settings settings, String property) {
String path = settings.getString(property);
if (path == null) {
throw MessageException.of("Missing property '" + property + "'");
}
File file = new File(path);
if (!file.isAbsolute()) {
throw MessageException.of("Path must be absolute - check property '" + property + "'" );
}
return file;
}
示例14: checkMode
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
private void checkMode() {
if (!mode.isIssues()) {
throw MessageException.of("The GitLab plugin is only intended to be used in preview or issues mode. Please set '" + CoreProperties.ANALYSIS_MODE + "'.");
}
}
示例15: checkMode
import org.sonar.api.utils.MessageException; //导入方法依赖的package包/类
private void checkMode() {
if (!mode.isIssues()) {
throw MessageException.of("The GitHub plugin is only intended to be used in preview or issues mode. Please set '" + CoreProperties.ANALYSIS_MODE + "'.");
}
}