コード例 #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
 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();
   }
 }