Exemplo n.º 1
0
    public FormValidation doCheckUrl(
        @AncestorInPath Item project,
        @QueryParameter String credentialsId,
        @QueryParameter String value)
        throws IOException, InterruptedException {

      if (project == null || !project.hasPermission(Item.CONFIGURE)) {
        return FormValidation.ok();
      }

      String url = Util.fixEmptyAndTrim(value);
      if (url == null) return FormValidation.error("Please enter repository url.");

      // get git executable on master
      final EnvVars environment = new EnvVars(EnvVars.masterEnvVars);

      GitClient git =
          Git.with(TaskListener.NULL, environment)
              .using(GitTool.getDefaultInstallation().getGitExe())
              .getClient();
      if (credentialsId != null) {
        StandardCredentials credentials = lookupCredentials(project, credentialsId, url);
        if (credentials != null) git.addDefaultCredentials(credentials);
      }

      // attempt to connect the provided URL
      try {
        git.getHeadRev(url, "HEAD");
      } catch (GitException e) {
        return FormValidation.error(Messages.UserRemoteConfig_FailedToConnect(e.getMessage()));
      }

      return FormValidation.ok();
    }
Exemplo n.º 2
0
 public ListBoxModel doFillCredentialsIdItems(
     @AncestorInPath Item project, @QueryParameter String url) {
   if (project == null || !project.hasPermission(Item.CONFIGURE)) {
     return new StandardListBoxModel();
   }
   return new StandardListBoxModel()
       .withEmptySelection()
       .withMatching(
           GitClient.CREDENTIALS_MATCHER,
           CredentialsProvider.lookupCredentials(
               StandardCredentials.class,
               project,
               ACL.SYSTEM,
               GitURIRequirementsBuilder.fromUri(url).build()));
 }