コード例 #1
0
 @SuppressWarnings("resource")
 private InitStep loadInitStep(Path jar) {
   try {
     URLClassLoader pluginLoader =
         new URLClassLoader(
             new URL[] {jar.toUri().toURL()}, InitPluginStepsLoader.class.getClassLoader());
     try (JarFile jarFile = new JarFile(jar.toFile())) {
       Attributes jarFileAttributes = jarFile.getManifest().getMainAttributes();
       String initClassName = jarFileAttributes.getValue("Gerrit-InitStep");
       if (initClassName == null) {
         return null;
       }
       @SuppressWarnings("unchecked")
       Class<? extends InitStep> initStepClass =
           (Class<? extends InitStep>) pluginLoader.loadClass(initClassName);
       return getPluginInjector(jar).getInstance(initStepClass);
     } catch (ClassCastException e) {
       ui.message(
           "WARN: InitStep from plugin %s does not implement %s (Exception: %s)\n",
           jar.getFileName(), InitStep.class.getName(), e.getMessage());
       return null;
     } catch (NoClassDefFoundError e) {
       ui.message(
           "WARN: Failed to run InitStep from plugin %s (Missing class: %s)\n",
           jar.getFileName(), e.getMessage());
       return null;
     }
   } catch (Exception e) {
     ui.message(
         "WARN: Cannot load and get plugin init step for %s (Exception: %s)\n",
         jar, e.getMessage());
     return null;
   }
 }
コード例 #2
0
ファイル: InitAdminUser.java プロジェクト: netroby/gerrit
 private String readEmail(String defaultEmail) {
   String email = ui.readString(defaultEmail, "email");
   if (email != null && !EmailValidator.getInstance().isValid(email)) {
     ui.message("error: invalid email address\n");
     return readEmail(defaultEmail);
   }
   return email;
 }
コード例 #3
0
ファイル: InitAdminUser.java プロジェクト: netroby/gerrit
  @Override
  public void postRun() throws Exception {
    AuthType authType = flags.cfg.getEnum(AuthType.values(), "auth", null, "type", null);
    if (authType != AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT) {
      return;
    }

    try (ReviewDb db = dbFactory.open()) {
      if (db.accounts().anyAccounts().toList().isEmpty()) {
        ui.header("Gerrit Administrator");
        if (ui.yesno(true, "Create administrator user")) {
          Account.Id id = new Account.Id(db.nextAccountId());
          String username = ui.readString("admin", "username");
          String name = ui.readString("Administrator", "name");
          String httpPassword = ui.readString("secret", "HTTP password");
          AccountSshKey sshKey = readSshKey(id);
          String email = readEmail(sshKey);

          AccountExternalId extUser =
              new AccountExternalId(
                  id, new AccountExternalId.Key(AccountExternalId.SCHEME_USERNAME, username));
          if (!Strings.isNullOrEmpty(httpPassword)) {
            extUser.setPassword(httpPassword);
          }
          db.accountExternalIds().insert(Collections.singleton(extUser));

          if (email != null) {
            AccountExternalId extMailto =
                new AccountExternalId(
                    id, new AccountExternalId.Key(AccountExternalId.SCHEME_MAILTO, email));
            extMailto.setEmailAddress(email);
            db.accountExternalIds().insert(Collections.singleton(extMailto));
          }

          Account a = new Account(id, TimeUtil.nowTs());
          a.setFullName(name);
          a.setPreferredEmail(email);
          db.accounts().insert(Collections.singleton(a));

          AccountGroupMember m =
              new AccountGroupMember(new AccountGroupMember.Key(id, new AccountGroup.Id(1)));
          db.accountGroupMembers().insert(Collections.singleton(m));

          if (sshKey != null) {
            db.accountSshKeys().insert(Collections.singleton(sshKey));
          }
        }
      }
    }
  }
コード例 #4
0
ファイル: InitAdminUser.java プロジェクト: netroby/gerrit
 private AccountSshKey readSshKey(Account.Id id) throws IOException {
   String defaultPublicSshKeyFile = "";
   Path defaultPublicSshKeyPath = Paths.get(System.getProperty("user.home"), ".ssh", "id_rsa.pub");
   if (Files.exists(defaultPublicSshKeyPath)) {
     defaultPublicSshKeyFile = defaultPublicSshKeyPath.toString();
   }
   String publicSshKeyFile = ui.readString(defaultPublicSshKeyFile, "public SSH key file");
   return !Strings.isNullOrEmpty(publicSshKeyFile) ? createSshKey(id, publicSshKeyFile) : null;
 }
コード例 #5
0
 private List<Path> scanJarsInPluginsDirectory() {
   if (pluginsDir == null || !Files.isDirectory(pluginsDir)) {
     return Collections.emptyList();
   }
   DirectoryStream.Filter<Path> filter =
       new DirectoryStream.Filter<Path>() {
         @Override
         public boolean accept(Path entry) throws IOException {
           return entry.getFileName().toString().endsWith(".jar") && Files.isRegularFile(entry);
         }
       };
   try (DirectoryStream<Path> paths = Files.newDirectoryStream(pluginsDir, filter)) {
     return Ordering.natural().sortedCopy(paths);
   } catch (IOException e) {
     ui.message("WARN: Cannot list %s: %s", pluginsDir.toAbsolutePath(), e.getMessage());
     return Collections.emptyList();
   }
 }
コード例 #6
0
  @Override
  public void run() {
    ui.header("Email Delivery");

    final String hostname = sendemail.string("SMTP server hostname", "smtpServer", "localhost");

    sendemail.string("SMTP server port", "smtpServerPort", "(default)", true);

    final Encryption enc =
        sendemail.select("SMTP encryption", "smtpEncryption", Encryption.NONE, true);

    String username = null;
    if (Files.exists(site.gerrit_config)) {
      username = sendemail.get("smtpUser");
    } else if ((enc != null && enc != Encryption.NONE) || !isLocal(hostname)) {
      username = username();
    }
    sendemail.string("SMTP username", "smtpUser", username);
    sendemail.password("smtpUser", "smtpPass");
  }