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


Java MessageException类代码示例

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


MessageException类属于org.sonar.api.utils包,在下文中一共展示了MessageException类的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;
}
 
开发者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


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