示例#1
0
 private static String getUnmigrationCommandLine(File jenkinsHome) {
   StringBuilder cp = new StringBuilder();
   for (Class<?> c :
       new Class<?>[] {
         RunIdMigrator.class, /* TODO how to calculate transitive dependencies automatically? */
         Charsets.class,
         WriterOutputStream.class,
         BuildException.class,
         FastDateFormat.class
       }) {
     URL location = c.getProtectionDomain().getCodeSource().getLocation();
     String locationS = location.toString();
     if (location.getProtocol().equals("file")) {
       try {
         locationS = new File(location.toURI()).getAbsolutePath();
       } catch (URISyntaxException x) {
         // never mind
       }
     }
     if (cp.length() > 0) {
       cp.append(File.pathSeparator);
     }
     cp.append(locationS);
   }
   return String.format(
       "java -classpath \"%s\" %s \"%s\"", cp, RunIdMigrator.class.getName(), jenkinsHome);
 }
示例#2
0
 public static Class findFunctionClass(String name) {
   if (name == null) return null;
   if (name.indexOf('.') < 0) // consider as full qualified name
   name = FUNCTIONS_PACKAGE + name;
   try {
     return Class.forName(name);
   } catch (Error er) {
     // too bad
     logger.severe("Function class " + name + " " + er);
   } catch (Exception ex) {
     logger.severe("Function class " + name + " not found or " + ex);
   }
   return null;
 }
示例#3
0
 /**
  * @param classOf a target class to find method
  * @param name of method
  * @param paramPattern represents a pattern of parameters, can be list or array of the same type,
  *     if parameter is an array of some class then method with one array of this type searched, if
  *     it's a single class than method with list of parameters of this class searched
  * @return Method if found, and null if not.
  */
 public Method getMethod(Class classOf, String name, Class paramPattern) {
   if (classOf == null) return null;
   Class[] callParamClasses = null;
   if (paramPattern.isArray()) {
     callParamClasses = new Class[1];
     Arrays.fill(callParamClasses, paramPattern);
   } else {
     callParamClasses = new Class[parameters.size()];
     Arrays.fill(callParamClasses, (Class) paramPattern);
   }
   try {
     return classOf.getDeclaredMethod(name, callParamClasses);
   } catch (NoSuchMethodException nsm) {
     if (logger.isLoggable(Level.FINEST))
       logger.finest(
           "Method '"
               + name
               + "' with "
               + callParamClasses.length
               + ", or variable parameters not found, last exception: "
               + nsm);
   }
   return null;
 }