• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MessageException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.sonar.api.utils.MessageException的典型用法代码示例。如果您正苦于以下问题:Java MessageException类的具体用法?Java MessageException怎么用?Java MessageException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MessageException类属于org.sonar.api.utils包,在下文中一共展示了MessageException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:26,代码来源:PluginInfo.java


示例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;
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:21,代码来源:LanguageDetection.java


示例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();
}
 
开发者ID:sonar-perl,项目名称:sonar-perl,代码行数:17,代码来源:PerlCriticRulesDefinition.java


示例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());
  }
}
 
开发者ID:SonarSource,项目名称:sonar-github,代码行数:21,代码来源:PullRequestFacade.java


示例5: properFailureIfNotAGitProject

import org.sonar.api.utils.MessageException; //导入依赖的package包/类
@Test
public void properFailureIfNotAGitProject() throws IOException {
  File projectDir = temp.newFolder();
  javaUnzip(new File("test-repos/dummy-git.zip"), projectDir);

  JGitBlameCommand jGitBlameCommand = new JGitBlameCommand(new PathResolver());

  File baseDir = new File(projectDir, "dummy-git");

  // Delete .git
  FileUtils.forceDelete(new File(baseDir, ".git"));

  DefaultFileSystem fs = new DefaultFileSystem(baseDir);
  when(input.fileSystem()).thenReturn(fs);
  DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA).build();
  fs.add(inputFile);

  BlameOutput blameResult = mock(BlameOutput.class);
  when(input.filesToBlame()).thenReturn(Arrays.<InputFile>asList(inputFile));

  thrown.expect(MessageException.class);
  thrown.expectMessage("Not inside a Git work tree: ");

  jGitBlameCommand.blame(input, blameResult);
}
 
开发者ID:SonarSource,项目名称:sonar-scm-git,代码行数:26,代码来源:JGitBlameCommandTest.java


示例6: 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;
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:12,代码来源:DefaultSensorStorage.java


示例7: fail_when_jar_is_not_a_plugin

import org.sonar.api.utils.MessageException; //导入依赖的package包/类
@Test
public void fail_when_jar_is_not_a_plugin() throws IOException {
  // this JAR has a manifest but is not a plugin
  File jarRootDir = temp.newFolder();
  FileUtils.write(new File(jarRootDir, "META-INF/MANIFEST.MF"), "Build-Jdk: 1.6.0_15");
  Path jar = temp.newFile().toPath();
  ZipUtils.zipDir(jarRootDir, jar.toFile());

  expectedException.expect(MessageException.class);
  expectedException.expectMessage("File is not a plugin. Please delete it and restart: " + jar.toAbsolutePath());

  PluginInfo.create(jar);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:14,代码来源:PluginInfoTest.java


示例8: fail_if_conflicting_language_suffix

import org.sonar.api.utils.MessageException; //导入依赖的package包/类
@Test
public void fail_if_conflicting_language_suffix() throws Exception {
  LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));
  LanguageDetection detection = new LanguageDetection(languages);
  try {
    detection.language(newInputFile("abc.xhtml"));
    fail();
  } catch (MessageException e) {
    assertThat(e.getMessage())
      .contains("Language of file 'abc.xhtml' can not be decided as the file matches patterns of both ")
      .contains("web: file:**/*.xhtml")
      .contains("xml: file:**/*.xhtml");
  }
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:15,代码来源:LanguageDetectionTest.java


示例9: 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;
}
 
开发者ID:sonar-perl,项目名称:sonar-perl,代码行数:14,代码来源:PerlCriticRulesDefinition.java


示例10: 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);
    }
}
 
开发者ID:gabrie-allaigre,项目名称:sonar-gitlab-plugin,代码行数:8,代码来源:CommitIssuePostJob.java


示例11: 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);
    }
}
 
开发者ID:gabrie-allaigre,项目名称:sonar-gitlab-plugin,代码行数:15,代码来源:AbstractCommentBuilder.java


示例12: testCommitAnalysisWithNewIssues2

import org.sonar.api.utils.MessageException; //导入依赖的package包/类
@Test
public void testCommitAnalysisWithNewIssues2() {
    settings.setProperty(GitLabPlugin.GITLAB_ONLY_ISSUE_FROM_COMMIT_FILE, false);
    settings.setProperty(GitLabPlugin.GITLAB_STATUS_NOTIFICATION_MODE, StatusNotificationsMode.EXIT_CODE.getMeaning());
    settings.setProperty(GitLabPlugin.GITLAB_DISABLE_GLOBAL_COMMENT, true);

    DefaultInputFile inputFile1 = new DefaultInputFile("foo", "src/Foo.php");
    PostJobIssue newIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.BLOCKER, true, "msg1");
    Mockito.when(commitFacade.getGitLabUrl(null, inputFile1, 1)).thenReturn("http://gitlab/blob/abc123/src/Foo.php#L1");

    PostJobIssue lineNotVisible = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 2, Severity.BLOCKER, true, "msg2");
    Mockito.when(commitFacade.getGitLabUrl(null, inputFile1, 2)).thenReturn("http://gitlab/blob/abc123/src/Foo.php#L2");

    DefaultInputFile inputFile2 = new DefaultInputFile("foo", "src/Foo2.php");
    PostJobIssue fileNotInPR = Utils.newMockedIssue("foo:src/Foo2.php", inputFile2, 1, Severity.BLOCKER, true, "msg3");

    PostJobIssue notNewIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.BLOCKER, false, "msg");

    PostJobIssue issueOnDir = Utils.newMockedIssue("foo:src", Severity.BLOCKER, true, "msg4");

    PostJobIssue issueOnProject = Utils.newMockedIssue("foo", Severity.BLOCKER, true, "msg");

    PostJobIssue globalIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, null, Severity.BLOCKER, true, "msg5");

    Mockito.when(context.issues()).thenReturn(Arrays.asList(newIssue, globalIssue, issueOnProject, issueOnDir, fileNotInPR, lineNotVisible, notNewIssue));
    Mockito.when(commitFacade.hasFile(inputFile1)).thenReturn(true);
    Mockito.when(commitFacade.getRevisionForLine(inputFile1, 1)).thenReturn(null);

    Assertions.assertThatThrownBy(() -> commitIssuePostJob.execute(context)).isInstanceOf(MessageException.class);

    Mockito.verify(commitFacade, Mockito.never()).addGlobalComment(Mockito.contains("SonarQube analysis reported 6 issues"));
    Mockito.verify(commitFacade, Mockito.never()).createOrUpdateSonarQubeStatus("failed", "SonarQube reported 6 issues, with 6 blocker");
}
 
开发者ID:gabrie-allaigre,项目名称:sonar-gitlab-plugin,代码行数:34,代码来源:CommitIssuePostJobTest.java


示例13: shouldFailIfNotPreview

import org.sonar.api.utils.MessageException; //导入依赖的package包/类
@Test
public void shouldFailIfNotPreview() {
    settings.setProperty(GitLabPlugin.GITLAB_COMMIT_SHA, "1");

    thrown.expect(MessageException.class);
    thrown.expectMessage("The GitLab plugin is only intended to be used in preview or issues mode. Please set 'sonar.analysis.mode'.");

    commitProjectBuilder.build(null);
}
 
开发者ID:gabrie-allaigre,项目名称:sonar-gitlab-plugin,代码行数:10,代码来源:CommitProjectBuilderTest.java


示例14: 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 + "'.");
}
 
开发者ID:SonarSource,项目名称:sonar-github,代码行数:11,代码来源:GitHubPluginConfiguration.java


示例15: shouldFailIfNotPreview

import org.sonar.api.utils.MessageException; //导入依赖的package包/类
@Test
public void shouldFailIfNotPreview() {
  settings.setProperty(GitHubPlugin.GITHUB_PULL_REQUEST, "1");

  thrown.expect(MessageException.class);
  thrown.expectMessage("The GitHub plugin is only intended to be used in preview or issues mode. Please set 'sonar.analysis.mode'.");

  pullRequestProjectBuilder.build(null);
}
 
开发者ID:SonarSource,项目名称:sonar-github,代码行数:10,代码来源:PullRequestProjectBuilderTest.java


示例16: 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;
}
 
开发者ID:SonarSource,项目名称:sonar-scm-git,代码行数:11,代码来源:GitScmProvider.java


示例17: 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;
}
 
开发者ID:SonarSource,项目名称:sonar-scm-svn,代码行数:12,代码来源:SvnConfiguration.java


示例18: 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");
    }
  }
}
 
开发者ID:SonarSource,项目名称:sonar-lits,代码行数:11,代码来源:IssuesChecker.java


示例19: 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;
}
 
开发者ID:SonarSource,项目名称:sonar-lits,代码行数:12,代码来源:IssuesChecker.java


示例20: path_must_be_specified

import org.sonar.api.utils.MessageException; //导入依赖的package包/类
@Test
public void path_must_be_specified() {
  Settings settings = new Settings();
  thrown.expect(MessageException.class);
  thrown.expectMessage("Missing property 'dump.old'");
  new IssuesChecker(settings, profile);
}
 
开发者ID:SonarSource,项目名称:sonar-lits,代码行数:8,代码来源:IssuesCheckerTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RawText类代码示例发布时间:2022-05-23
下一篇:
Java FileScanner类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap