Beispiel #1
0
  /**
   * Find mod classes in the class path and enumerated mod files list
   *
   * @param classPathEntries Java class path split into string entries
   * @return map of classes to load
   */
  private HashMap<String, Class> findModClasses(
      String[] classPathEntries, LinkedList<File> modFiles) {
    // To try to avoid loading the same mod multiple times if it appears in more than one entry in
    // the class path, we index
    // the mods by name and hopefully match only a single instance of a particular mod
    HashMap<String, Class> modsToLoad = new HashMap<String, Class>();

    try {
      logger.info("Searching protection domain code source...");

      File packagePath =
          new File(LiteLoader.class.getProtectionDomain().getCodeSource().getLocation().toURI());
      LinkedList<Class> modClasses =
          getSubclassesFor(packagePath, Minecraft.class.getClassLoader(), LiteMod.class, "LiteMod");

      for (Class mod : modClasses) {
        modsToLoad.put(mod.getSimpleName(), mod);
      }

      if (modClasses.size() > 0)
        logger.info(String.format("Found %s potential matches", modClasses.size()));
    } catch (Throwable th) {
      logger.warning("Error loading from local class path: " + th.getMessage());
    }

    // Search through the class path and find mod classes
    for (String classPathPart : classPathEntries) {
      logger.info(String.format("Searching %s...", classPathPart));

      File packagePath = new File(classPathPart);
      LinkedList<Class> modClasses =
          getSubclassesFor(packagePath, Minecraft.class.getClassLoader(), LiteMod.class, "LiteMod");

      for (Class mod : modClasses) {
        modsToLoad.put(mod.getSimpleName(), mod);
      }

      if (modClasses.size() > 0)
        logger.info(String.format("Found %s potential matches", modClasses.size()));
    }

    // Search through mod files and find mod classes
    for (File modFile : modFiles) {
      logger.info(String.format("Searching %s...", modFile.getAbsolutePath()));

      LinkedList<Class> modClasses =
          getSubclassesFor(modFile, Minecraft.class.getClassLoader(), LiteMod.class, "LiteMod");

      for (Class mod : modClasses) {
        modsToLoad.put(mod.getSimpleName(), mod);
      }

      if (modClasses.size() > 0)
        logger.info(String.format("Found %s potential matches", modClasses.size()));
    }

    return modsToLoad;
  }
  private static void convertProtocolToAsciidocTable(Properties props, Class<Protocol> clazz)
      throws Exception {
    boolean isUnsupported = clazz.isAnnotationPresent(Unsupported.class);
    if (isUnsupported) return;

    Map<String, String> nameToDescription = new TreeMap<>();

    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
      if (field.isAnnotationPresent(Property.class)) {
        String property = field.getName();
        Property annotation = field.getAnnotation(Property.class);
        String desc = annotation.description();
        nameToDescription.put(property, desc);
      }
    }

    // iterate methods
    Method[] methods = clazz.getDeclaredMethods();
    for (Method method : methods) {
      if (method.isAnnotationPresent(Property.class)) {

        Property annotation = method.getAnnotation(Property.class);
        String desc = annotation.description();

        if (desc == null || desc.isEmpty()) desc = "n/a";

        String name = annotation.name();
        if (name.length() < 1) {
          name = Util.methodNameToAttributeName(method.getName());
        }
        nameToDescription.put(name, desc);
      }
    }

    // do we have more than one property (superclass Protocol has only one property (stats))
    if (nameToDescription.isEmpty()) return;

    List<String[]> rows = new ArrayList<>(nameToDescription.size() + 1);
    rows.add(new String[] {"Name", "Description"});
    for (Map.Entry<String, String> entry : nameToDescription.entrySet())
      rows.add(new String[] {entry.getKey(), entry.getValue()});

    String tmp =
        createAsciidocTable(
            rows,
            clazz.getSimpleName(),
            "[align=\"left\",width=\"90%\",cols=\"2,10\",options=\"header\"]");
    props.put(clazz.getSimpleName(), tmp);
  }
  /**
   * Prints a report for a failed test.
   *
   * <p>The test name is printed. If the main test failed, then the reason for the failure is
   * printed. The task being performed during the failure is shown, if there was one. If the failure
   * was not a timeout, the stack trace is shown as well. If the cleanup task failed, a description
   * of the error and a stack trace are printed.
   *
   * @param stream Stream to receive the formatted test report.
   */
  void print(PrintStream stream) {
    // Do nothing if the test was successful.
    if (successful()) return;

    // Print report header.
    stream.println("failed test:    " + test_class.getSimpleName());

    // If the main test failed, print the reason, and optionally the task
    // message and a stack trace.
    if (stop_cause != null) {
      stream.println("reason:         " + stop_cause.getMessage());

      if (task != null) stream.println("task:           " + task);

      if (!(stop_cause instanceof Timeout)) {
        stream.println("stack trace:    ");
        stop_cause.printStackTrace(stream);
      }
    }

    // If cleanup failed, print the reason and a stack trace.
    if (cleanup_stop_cause != null) {
      stream.println("cleanup failed: " + cleanup_stop_cause.getMessage());
      cleanup_stop_cause.printStackTrace(stream);
    }
  }
 /**
  * Log task mapped.
  *
  * @param log Logger.
  * @param clazz Task class.
  * @param nodes Mapped nodes.
  */
 public static void logMapped(
     @Nullable IgniteLogger log, Class<?> clazz, Collection<ClusterNode> nodes) {
   log0(
       log,
       U.currentTimeMillis(),
       String.format("[%s]: MAPPED: %s", clazz.getSimpleName(), U.toShortString(nodes)));
 }
  /**
   * Log finished.
   *
   * @param log Logger.
   * @param clazz Class.
   * @param start Start time.
   */
  public static void logFinish(@Nullable IgniteLogger log, Class<?> clazz, long start) {
    final long end = U.currentTimeMillis();

    log0(
        log,
        end,
        String.format(
            "[%s]: FINISHED, duration: %s", clazz.getSimpleName(), formatDuration(end - start)));
  }
  /**
   * Log message.
   *
   * @param log Logger.
   * @param msg Message to log.
   * @param clazz class.
   * @param start start time.
   * @return Time when message was logged.
   */
  public static long log(@Nullable IgniteLogger log, String msg, Class<?> clazz, long start) {
    final long end = U.currentTimeMillis();

    log0(
        log,
        end,
        String.format(
            "[%s]: %s, duration: %s", clazz.getSimpleName(), msg, formatDuration(end - start)));

    return end;
  }
Beispiel #7
0
 public void registerEntity(
     Class<? extends Entity> cls,
     String name,
     int id,
     int updateFrequency,
     boolean sendVelocityUpdates) {
   System.out.printf(
       "%s: BaseMod.registerEntity: %s, \"%s\", %s\n",
       getClass().getSimpleName(), cls.getSimpleName(), name, id);
   EntityRegistry.registerModEntity(
       cls, name, id, /*base*/ this, 256, updateFrequency, sendVelocityUpdates);
 }
 private String readVersionFromManifest(Class<?> api) throws IOException {
   String className = api.getSimpleName() + ".class";
   URL resource = api.getResource(className);
   log.trace("get resource for {} -> {} -> {}", new Object[] {className, pathOf(api), resource});
   if (resource == null) return null;
   String version = null;
   String classPath = resource.toString();
   if (classPath.startsWith("jar:"))
     version = version(classPath.substring(0, classPath.lastIndexOf("!") + 1));
   if (version == null && classPath.endsWith(pathOf(api) + ".class"))
     version = version(classPath.substring(0, classPath.length() - pathOf(api).length() - 7));
   if (version == null && classPath.contains("/WEB-INF/"))
     version = version(classPath.substring(0, classPath.lastIndexOf("/WEB-INF/")));
   log.debug("version {} for {} from {}.", version, api, classPath);
   return version;
 }
  protected static void convertUnsupportedToAsciidocTable(
      Properties props, List<Class<?>> clazzes, String title)
      throws ParserConfigurationException, TransformerException {
    List<String[]> rows = new ArrayList<>(clazzes.size() + 1);
    rows.add(new String[] {"Package", "Class"}); // add column titles first
    for (Class<?> clazz : clazzes)
      rows.add(new String[] {clazz.getPackage().getName(), clazz.getSimpleName()});

    String tmp =
        createAsciidocTable(rows, title, "[align=\"left\",width=\"50%\",options=\"header\"]");

    // do we have more than one property (superclass Protocol has only one property (stats))
    if (clazzes.size() > 1) {
      props.put(title, tmp);
    }
  }
 /** Mimics SimpleXML's naming for classes without {@link Root#name()}. */
 private static String getClassName(Class<?> type) {
   if (type.isArray()) type = type.getComponentType();
   final String name = type.getSimpleName();
   if (type.isPrimitive()) return name;
   else return Introspector.decapitalize(name);
 }
Beispiel #11
0
 @Override
 public String toString() {
   return toString(joinClass == null ? null : joinClass.getSimpleName()).toString();
 }
Beispiel #12
0
 /**
  * Returns the name of the specified class.
  *
  * @param o object
  * @return class name
  */
 public static String name(final Class<?> o) {
   return o.getSimpleName();
 }
Beispiel #13
0
 private static String index(Class<? extends Scanner> scannerClass) {
   return scannerClass.getSimpleName();
 }
Beispiel #14
0
 public String toString() {
   return String.format(
       "FMTest name=%s codec=%s feature=%s file=%s",
       name, codec.getSimpleName(), feature.getSimpleName(), associatedFile);
 }
 /**
  * Log start.
  *
  * @param log Logger.
  * @param clazz Class.
  * @param start Start time.
  */
 public static void logStart(@Nullable IgniteLogger log, Class<?> clazz, long start) {
   log0(log, start, "[" + clazz.getSimpleName() + "]: STARTED");
 }