Esempio n. 1
0
  /** @tests java.lang.Package#getPackage(java.lang.String) */
  public void test_getPackageLjava_lang_String() {
    assertSame(
        "Package getPackage failed for java.lang",
        Package.getPackage("java.lang"),
        Package.getPackage("java.lang"));

    assertSame(
        "Package getPackage failed for java.lang",
        Package.getPackage("java.lang"),
        Object.class.getPackage());
  }
  /** Add Karaf core features URL in the default repositories set */
  private void appendKarafCoreFeaturesDescriptors() {
    if (repositories == null) {
      repositories = new ArrayList<String>();
    }
    if (karafVersion == null) {
      Package p = Package.getPackage("org.apache.karaf.tooling.features");
      karafVersion = p.getImplementationVersion();
    }
    String karafCoreStandardFeaturesUrl =
        String.format(KARAF_CORE_STANDARD_FEATURE_URL, karafVersion);
    String karafCoreEnterpriseFeaturesUrl =
        String.format(KARAF_CORE_ENTERPRISE_FEATURE_URL, karafVersion);

    try {
      resolve(karafCoreStandardFeaturesUrl);
      repositories.add(karafCoreStandardFeaturesUrl);
    } catch (Exception e) {
      warn("Can't add " + karafCoreStandardFeaturesUrl + " in the default repositories set");
    }

    try {
      resolve(karafCoreEnterpriseFeaturesUrl);
      repositories.add(karafCoreEnterpriseFeaturesUrl);
    } catch (Exception e) {
      warn("Can't add " + karafCoreStandardFeaturesUrl + " in the default repositories set");
    }
  }
Esempio n. 3
0
 public Package getMinecraftPackage() {
   try {
     if (this.minecraft == null) {
       return Package.getPackage(
           "net.minecraft.server."
               + Bukkit.getServer()
                   .getClass()
                   .getPackage()
                   .getName()
                   .replace(".", ",")
                   .split(",")[3]);
     } else {
       return this.minecraft;
     }
   } catch (Exception ex) {
     this.getServer()
         .getConsoleSender()
         .sendMessage(
             ChatWriter.pluginMessage(
                 ChatColor.RED
                     + Main._l(
                         "errors.packagenotfound",
                         ImmutableMap.of("package", "minecraft server"))));
     return null;
   }
 }
  /** @see DATAJPA-472 */
  @Test
  public void shouldSupportFindAllWithPageableAndEntityWithIdClass() throws Exception {

    if (Package.getPackage("org.hibernate.cfg").getImplementationVersion().startsWith("4.1.")) {

      // we expect this test to fail on 4.1.x - due to a bug in hibernate - remove as soon as 4.1.x
      // fixes the issue.
      expectedException.expect(InvalidDataAccessApiUsageException.class);
      expectedException.expectMessage("No supertype found");
    }

    IdClassExampleDepartment dep = new IdClassExampleDepartment();
    dep.setName("TestDepartment");
    dep.setDepartmentId(-1);

    IdClassExampleEmployee emp = new IdClassExampleEmployee();
    emp.setDepartment(dep);
    emp = employeeRepositoryWithIdClass.save(emp);

    Page<IdClassExampleEmployee> page =
        employeeRepositoryWithIdClass.findAll(new PageRequest(0, 10));

    assertThat(page, is(notNullValue()));
    assertThat(page.getTotalElements(), is(1L));
  }
  static {
    // Put JOGL version information into system properties to
    // assist in debugging.
    Package joglPackage = Package.getPackage("javax.media.opengl");
    System.setProperty("jogl.specification.version", joglPackage.getSpecificationVersion());
    System.setProperty("jogl.implementation.version", joglPackage.getImplementationVersion());

    ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
  }
Esempio n. 6
0
  /** Construct a new instance of the manager */
  public USBManager() {
    deviceListInit = false;

    // See if we even have the system available. Not always the case. If
    // we don't disable the device list loading straight away.
    deviceListInit = Package.getPackage("net.java.games.input") == null;

    devices = new ArrayList<InputDevice>();
    deviceListeners = new ArrayList<DeviceListener>();
  }
Esempio n. 7
0
  private static boolean initJUELSupportsMethodExpression() {
    final Package juelPackage = Package.getPackage("de.odysseus.el");
    if (juelPackage == null) {
      return false;
    }

    final String juelVersion = juelPackage.getImplementationVersion();
    if (juelVersion == null) {
      return false;
    }

    return Hacks.isSameOrHigherVersion(juelVersion, Hacks.JUEL_MINIMUM_METHOD_EXPRESSION_VERSION);
  }
Esempio n. 8
0
  private boolean getIsSpigot() {
    try {
      Package spigotPackage = Package.getPackage("org.spigotmc");
      if (spigotPackage == null) {
        return false;
      }

      return true;
    } catch (Exception e) {
      // nope
    }

    return false;
  }
  public static String getPackageVersion(final Package lookupPackage) {
    if (lookupPackage == null) {
      return null;
    }

    String specVersion = lookupPackage.getSpecificationVersion();
    if (specVersion != null) {
      return specVersion;
    } else {
      // search in parent package
      String normalizedPackageName = normalizePackageName(lookupPackage.getName());
      String nextPackageName = getNextPackage(normalizedPackageName);
      return getPackageVersion(Package.getPackage(nextPackageName));
    }
  }
Esempio n. 10
0
  /** Looks to the default plug-in directory location to initialize this store */
  public void initializeOrUpdateStore() {

    try {
      List<PackageInfo> list = PackageInfoPeerClassFinder.findPackageInfo();
      for (PackageInfo pi : list) {
        for (String className : pi.getClassList()) {

          try {
            // If we don't have the class
            Class<?> o = Class.forName(className);
            if (o == null) {
              throw new Exception("Class not available");
            }
          } catch (NoClassDefFoundError ncdfe) {
            // By Design: gobbling up this error to reduce the
            // non-needed noise upon startup. If there is a real
            // issue, then it will bubble up somewhere else.
          } catch (Exception e) {
            // Explicitly load classes from packages that have
            // package-info
            try {
              ClassLoader.getSystemClassLoader().loadClass(className);
            } catch (java.lang.NoClassDefFoundError ncdfe) {
              // By Design: gobbling up this error to reduce the
              // non-needed noise upon startup. If there is a real
              // issue, then it will bubble up somewhere else.
            }
          }

          Package packageItem = Package.getPackage(pi.getName());
          if (null != packageItem.getAnnotation(MockeyRequestInspector.class)) {
            Class<?> x = doesThisImplementIRequestInspector(className);
            if (x != null && !this.reqInspectorClassNameList.contains(x)) {
              this.reqInspectorClassNameList.add(x);
              logger.debug("Plugin added: " + className);
            }
          }
        }
      }

    } catch (Exception e) {
      logger.error("Found a Mockey.jar, but unable read mockey jar", e);
    }
  }
Esempio n. 11
0
  static {
    String version = "unknown";
    int major = 0;
    int minor = 0;
    try {
      Package p = Package.getPackage(MetaDataSupport.class.getPackage().getName());
      if (p != null) {
        version = p.getImplementationVersion();
        Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+).*");
        Matcher m = pattern.matcher(version);
        if (m.matches()) {
          major = Integer.parseInt(m.group(1));
          minor = Integer.parseInt(m.group(2));
        }
      }
    } catch (Throwable e) {
      LOG.trace("Problem generating primary version details", e);

      InputStream in = null;
      String path = MetaDataSupport.class.getPackage().getName().replace(".", "/");
      if ((in = MetaDataSupport.class.getResourceAsStream("/" + path + "/version.txt")) != null) {
        try {
          BufferedReader reader =
              new BufferedReader(new InputStreamReader(in, StandardCharsets.US_ASCII));
          version = reader.readLine();
          Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+).*");
          Matcher m = pattern.matcher(version);
          if (m.matches()) {
            major = Integer.parseInt(m.group(1));
            minor = Integer.parseInt(m.group(2));
          }
          reader.close();
        } catch (Throwable err) {
          LOG.trace("Problem generating fallback version details", err);
        }
      }
    }

    PROVIDER_VERSION = version;
    PROVIDER_MAJOR_VERSION = major;
    PROVIDER_MINOR_VERSION = minor;
  }
  /** Validates the manifest. */
  public static void validateManifest(String manifestName, Manifest manifest)
      throws ConfigException {
    Attributes attr = manifest.getMainAttributes();
    if (attr == null) return;

    String extList = attr.getValue("Extension-List");
    if (extList == null) return;

    Pattern pattern = Pattern.compile("[, \t]+");
    String[] split = pattern.split(extList);

    for (int i = 0; i < split.length; i++) {
      String ext = split[i];

      String name = attr.getValue(ext + "-Extension-Name");
      if (name == null) continue;

      Package pkg = Package.getPackage(name);

      if (pkg == null) {
        log.warning(L.l("package {0} is missing.  {1} requires package {0}.", name, manifestName));
        continue;
      }

      String version = attr.getValue(ext + "-Specification-Version");

      if (version == null) continue;

      if (pkg.getSpecificationVersion() == null || pkg.getSpecificationVersion().equals("")) {
        log.warning(
            L.l(
                "installed {0} is not compatible with version `{1}'.  {2} requires version {1}.",
                name, version, manifestName));
      } else if (!pkg.isCompatibleWith(version)) {
        log.warning(
            L.l(
                "installed {0} is not compatible with version `{1}'.  {2} requires version {1}.",
                name, version, manifestName));
      }
    }
  }
Esempio n. 13
0
 /** Finds the editor message bundle for the supplied class. */
 protected static String findMessageBundle(Class<?> clazz) {
   EditorMessageBundle annotation = clazz.getAnnotation(EditorMessageBundle.class);
   if (annotation != null) {
     return annotation.value();
   }
   Class<?> eclazz = clazz.getEnclosingClass();
   if (eclazz != null) {
     return getMessageBundle(eclazz);
   }
   String name = clazz.getName();
   int idx;
   while ((idx = name.lastIndexOf('.')) != -1) {
     name = name.substring(0, idx);
     Package pkg = Package.getPackage(name);
     if (pkg != null) {
       annotation = pkg.getAnnotation(EditorMessageBundle.class);
       if (annotation != null) {
         return annotation.value();
       }
     }
   }
   return EditorMessageBundle.DEFAULT;
 }
Esempio n. 14
0
  static void pkgInfo(ClassLoader classLoader, String pkgName, String className) {

    try {
      classLoader.loadClass(pkgName + "." + className);

      Package p = Package.getPackage(pkgName);
      if (p == null) {
        System.err.println("WARNING: Package.getPackage(" + pkgName + ") is null");
      } else {
        if (devPhase && debug) {
          System.err.println(p);
          System.err.println("Specification Title = " + p.getSpecificationTitle());
          System.err.println("Specification Vendor = " + p.getSpecificationVendor());
          System.err.println("Specification Version = " + p.getSpecificationVersion());
          System.err.println("Implementation Vendor = " + p.getImplementationVendor());
          System.err.println("Implementation Version = " + p.getImplementationVersion());
        } else if (devPhase) System.err.println(", Java 3D " + p.getImplementationVersion() + ".");
      }
    } catch (ClassNotFoundException e) {
      System.err.println("Unable to load " + pkgName);
    }

    // 	System.err.println();
  }
Esempio n. 15
0
 public PackageEx(String pkgName) {
   pack = Package.getPackage(pkgName);
 }
 public void registerPackage(String name) {
   name = Package.getPackage(name).getName();
   if (!mPackages.contains(name)) {
     mPackages.add(name);
   }
 }
Esempio n. 17
0
public final class SdcctPackages {
  public static final String ROOT_NAME = "gov.hhs.onc.sdcct";
  public static final Package ROOT = Package.getPackage(ROOT_NAME);

  public static final String BEANS_NAME = ROOT_NAME + ".beans";
  public static final Package BEANS = Package.getPackage(BEANS_NAME);
  public static final String BEANS_IMPL_NAME =
      BEANS_NAME + ClassUtils.PACKAGE_SEPARATOR + SdcctClassUtils.IMPL_PKG_NAME;
  public static final Package BEANS_IMPL = Package.getPackage(BEANS_IMPL_NAME);

  public static final String FHIR_NAME = ROOT_NAME + ".fhir";
  public static final Package FHIR = Package.getPackage(FHIR_NAME);
  public static final String FHIR_IMPL_NAME =
      FHIR_NAME + ClassUtils.PACKAGE_SEPARATOR + SdcctClassUtils.IMPL_PKG_NAME;
  public static final Package FHIR_IMPL = Package.getPackage(FHIR_IMPL_NAME);

  public static final String FHIR_XHTML_NAME = FHIR_NAME + ".xhtml";
  public static final Package FHIR_XHTML = Package.getPackage(FHIR_XHTML_NAME);
  public static final String FHIR_XHTML_IMPL_NAME =
      FHIR_XHTML_NAME + ClassUtils.PACKAGE_SEPARATOR + SdcctClassUtils.IMPL_PKG_NAME;
  public static final Package FHIR_XHTML_IMPL = Package.getPackage(FHIR_XHTML_IMPL_NAME);

  public static final String RFD_NAME = ROOT_NAME + ".rfd";
  public static final Package RFD = Package.getPackage(RFD_NAME);
  public static final String RFD_IMPL_NAME =
      RFD_NAME + ClassUtils.PACKAGE_SEPARATOR + SdcctClassUtils.IMPL_PKG_NAME;
  public static final Package RFD_IMPL = Package.getPackage(RFD_IMPL_NAME);

  public static final String SCHEMATRON_NAME = ROOT_NAME + ".schematron";
  public static final Package SCHEMATRON = Package.getPackage(SCHEMATRON_NAME);
  public static final String SCHEMATRON_IMPL_NAME =
      SCHEMATRON_NAME + ClassUtils.PACKAGE_SEPARATOR + SdcctClassUtils.IMPL_PKG_NAME;
  public static final Package SCHEMATRON_IMPL = Package.getPackage(SCHEMATRON_IMPL_NAME);

  public static final String SCHEMATRON_SVRL_NAME = SCHEMATRON_NAME + ".svrl";
  public static final Package SCHEMATRON_SVRL = Package.getPackage(SCHEMATRON_SVRL_NAME);
  public static final String SCHEMATRON_SVRL_IMPL_NAME =
      SCHEMATRON_SVRL_NAME + ClassUtils.PACKAGE_SEPARATOR + SdcctClassUtils.IMPL_PKG_NAME;
  public static final Package SCHEMATRON_SVRL_IMPL = Package.getPackage(SCHEMATRON_SVRL_IMPL_NAME);

  public static final String SDC_NAME = ROOT_NAME + ".sdc";
  public static final Package SDC = Package.getPackage(SDC_NAME);
  public static final String SDC_IMPL_NAME =
      SDC_NAME + ClassUtils.PACKAGE_SEPARATOR + SdcctClassUtils.IMPL_PKG_NAME;
  public static final Package SDC_IMPL = Package.getPackage(SDC_IMPL_NAME);

  private SdcctPackages() {}
}
    public void init(GLAutoDrawable glAutoDrawable) {
      StringBuilder sb = new StringBuilder();

      sb.append(gov.nasa.worldwind.Version.getVersion() + "\n");

      sb.append("\nSystem Properties\n");
      sb.append("Processors: " + Runtime.getRuntime().availableProcessors() + "\n");
      sb.append("Free memory: " + Runtime.getRuntime().freeMemory() + " bytes\n");
      sb.append("Max memory: " + Runtime.getRuntime().maxMemory() + " bytes\n");
      sb.append("Total memory: " + Runtime.getRuntime().totalMemory() + " bytes\n");

      for (Map.Entry prop : System.getProperties().entrySet()) {
        sb.append(prop.getKey() + " = " + prop.getValue() + "\n");
      }

      GL gl = glAutoDrawable.getGL();

      sb.append("\nOpenGL Values\n");

      String oglVersion = gl.glGetString(GL.GL_VERSION);
      sb.append("OpenGL version: " + oglVersion + "\n");

      String oglVendor = gl.glGetString(GL.GL_VENDOR);
      sb.append("OpenGL vendor: " + oglVendor + "\n");

      String oglRenderer = gl.glGetString(GL.GL_RENDERER);
      sb.append("OpenGL renderer: " + oglRenderer + "\n");

      int[] intVals = new int[2];
      for (Attr attr : attrs) {
        sb.append(attr.name).append(": ");

        if (attr.attr instanceof Integer) {
          gl.glGetIntegerv((Integer) attr.attr, intVals, 0);
          sb.append(intVals[0]).append(intVals[1] > 0 ? ", " + intVals[1] : "");
        }

        sb.append("\n");
      }

      String extensionString = gl.glGetString(GL.GL_EXTENSIONS);
      String[] extensions = extensionString.split(" ");
      sb.append("Extensions\n");
      for (String ext : extensions) {
        sb.append("    " + ext + "\n");
      }

      sb.append("\nJOGL Values\n");
      String pkgName = "javax.media.opengl";
      try {
        getClass().getClassLoader().loadClass(pkgName + ".GL");

        Package p = Package.getPackage(pkgName);
        if (p == null) {
          sb.append("WARNING: Package.getPackage(" + pkgName + ") is null\n");
        } else {
          sb.append(p + "\n");
          sb.append("Specification Title = " + p.getSpecificationTitle() + "\n");
          sb.append("Specification Vendor = " + p.getSpecificationVendor() + "\n");
          sb.append("Specification Version = " + p.getSpecificationVersion() + "\n");
          sb.append("Implementation Vendor = " + p.getImplementationVendor() + "\n");
          sb.append("Implementation Version = " + p.getImplementationVersion() + "\n");
        }
      } catch (ClassNotFoundException e) {
        sb.append("Unable to load " + pkgName + "\n");
      }

      this.outputArea.setText(sb.toString());
    }
Esempio n. 19
0
  public static void main(String[] args) {

    if (args.length < 1) {
      try {
        Package p = Package.getPackage("dmg.cells.nucleus");
        if (p != null) {
          String tmp = p.getSpecificationTitle();
          System.out.println("SpecificationTitle:   " + (tmp == null ? "(Unknown)" : tmp));
          tmp = p.getSpecificationVendor();
          System.out.println("SpecificationVendor:  " + (tmp == null ? "(Unknown)" : tmp));
          tmp = p.getSpecificationVersion();
          System.out.println("SpecificationVersion: " + (tmp == null ? "(Unknown)" : tmp));
        }
      } catch (Exception ee) {
      }
      System.out.println("USAGE : <domainName> [options]");
      System.out.println(
          "         -telnet  \"<telnetPort> [-acm=acm] " + "[-localOk] [-passwd=<passwd>]\"");
      System.out.println("         -tunnel(2)  <tunnelPort>");
      System.out.println("         -connect(2) <host> <port>");
      System.out.println("         -routed");
      System.out.println("         -batch <fileName>");
      System.out.println("         -boot  <bootDomain>");
      System.out.println("         -spy   <spyListenPort>");
      System.out.println("         -ic    <interruptHandlerClass>");
      System.out.println("         -param <key>=<value> [...]");
      System.out.println("         -acm   <userDbRoot>");
      System.out.println("         -connectDomain   <domainName>");
      System.out.println("         -accept");
      System.out.println("         -lm [<hostname>] <portNumber> [options]");
      System.out.println("              Options : /noclient /noboot /strict=yes|no");
      System.out.println("         -debug [full]");
      System.out.println("         -cp <cellPrinterCellName>");
      System.exit(1);
    }
    //
    // split the rest of the arguments into rows and columns
    // according to the requests
    //
    int state = IDLE;
    Vector<String> columns = null;
    Vector<String[]> rowVec = new Vector<>();
    for (int pos = 1; pos < args.length; ) {
      switch (state) {
        case IDLE:
          if (args[pos].charAt(0) == '-') {
            columns = new Vector<>();
            columns.addElement(args[pos]);
            state = ASSEMBLE;
          }
          pos++;
          break;
        case ASSEMBLE:
          if (args[pos].charAt(0) == '-') {
            String[] col = new String[columns.size()];
            columns.copyInto(col);
            rowVec.addElement(col);
            state = IDLE;
          } else {
            columns.addElement(args[pos++]);
          }
          break;
      }
    }
    if (state == ASSEMBLE) {
      String[] col = new String[columns.size()];
      columns.copyInto(col);
      rowVec.addElement(col);
    }
    Hashtable<String, String[]> argHash = new Hashtable<>();
    for (int i = 0; i < rowVec.size(); i++) {
      String[] el = rowVec.elementAt(i);
      argHash.put(el[0], el);
    }
    /*
    Enumeration e = argHash.keys() ;
    for( ; e.hasMoreElements() ; ){
       String key = (String) e.nextElement() ;
       String []ar  = (String []) argHash.get( key ) ;
       System.out.print( key+" : " ) ;
       for( int j = 0 ; j < ar.length ; j++ )
          System.out.print( ar[j]+"," ) ;
       System.out.println("");
    }
    */
    //
    //
    SystemCell systemCell;
    try {
      //
      // start the system cell
      //
      systemCell = new SystemCell(args[0]);
      String[] tmp;
      //
      if (argHash.get("-version") != null) {
        Package p = Package.getPackage("dmg.cells.nucleus");
        System.out.println(p.toString());
        System.exit(0);
      }
      //
      //
      if (((tmp = argHash.get("-param")) != null) && (tmp.length > 1)) {

        String[][] parameters = getParameter(tmp);

        Map<String, Object> dict = systemCell.getDomainContext();

        for (String[] parameter : parameters) {
          dict.put(parameter[0], parameter[1]);
        }
      }

      if ((tmp = argHash.get("-debug")) != null) {

        _log.info("Starting DebugSequence");
        List<String> v = new ArrayList<>();
        if ((tmp.length > 1) && (tmp[1].equals("full"))) {
          v.add("set printout CellGlue all");
          v.add("set printout default all");
        } else {
          v.add("set printout default 3");
        }
        String[] commands = new String[v.size()];
        new BatchCell("debug", v.toArray(commands));
      }
      if ((tmp = argHash.get("-cp")) != null) {

        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < tmp.length; i++) {
          sb.append(" ");
          if (tmp[i].startsWith("/")) {
            sb.append("-").append(tmp[i].substring(1));
          } else {
            sb.append(tmp[i]);
          }
        }
        String a = sb.toString();

        _log.info("Loading new CellPrinter " + a);
        List<String> v = new ArrayList<>();
        v.add("load cellprinter " + a);

        String[] commands = new String[v.size()];
        new BatchCell("cellprinter", v.toArray(commands));
      }
      if (argHash.get("-routed") != null) {
        _log.info("Starting Routing Manager");
        new RoutingManager("RoutingMgr", "up0");
      }

      if (((tmp = argHash.get("-lm")) != null) && (tmp.length > 1)) {
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < tmp.length; i++) {
          sb.append(" ");
          if (tmp[i].startsWith("/")) {
            sb.append("-").append(tmp[i].substring(1));
          } else {
            sb.append(tmp[i]);
          }
        }
        String a = sb.toString();
        _log.info("Installing LocationManager '" + a + "'");
        new LocationManager("lm", a);
        new RoutingManager("RoutingMgr", "");
      }

      if (argHash.get("-silent") != null) {

        _log.info("Starting Silent Sequence");
        List<String> v = new ArrayList<>();
        v.add("set printout CellGlue none");
        v.add("set printout default none");
        String[] commands = new String[v.size()];
        new BatchCell("silent", v.toArray(commands));
      }

      if (((tmp = argHash.get("-telnet")) != null) && (tmp.length > 1)) {

        StringBuilder sb = new StringBuilder();
        //
        // the port number class and protocol
        //
        sb.append(tmp[1]).append(" dmg.cells.services.StreamLoginCell").append(" -prot=telnet ");
        //
        // and possible options
        //
        for (int i = 3; i < tmp.length; i++) {

          sb.append(" -").append(tmp[i]);
        }

        _log.info("Starting LoginManager (telnet) on " + sb.toString());
        new LoginManager("tlm", sb.toString());
      }
      if (((tmp = argHash.get("-tunnel2")) != null) && (tmp.length > 1)) {

        StringBuilder sb = new StringBuilder();
        //
        // the port number class and protocol
        //
        sb.append(tmp[1]).append(" dmg.cells.network.RetryTunnel2").append(" -prot=raw ");
        //
        // and possible options
        //
        for (int i = 3; i < tmp.length; i++) {

          sb.append(" -").append(tmp[i]);
        }

        _log.info("Starting RetryTunnel2 (raw) on " + sb.toString());
        new LoginManager("down", sb.toString());
      }
      if (((tmp = argHash.get("-connect")) != null) && (tmp.length > 2)) {

        _log.info("Starting RetryTunnel on " + tmp[1] + " " + tmp[2]);
        new RetryTunnel("up0", tmp[1] + " " + tmp[2]);
      }
      if (((tmp = argHash.get("-connect2")) != null) && (tmp.length > 2)) {

        _log.info("Starting RetryTunnel2 on " + tmp[1] + " " + tmp[2]);
        new RetryTunnel2("up0", tmp[1] + " " + tmp[2]);
      }
      if (((tmp = argHash.get("-connectDomain")) != null) && (tmp.length > 1)) {

        _log.info("Starting LocationMgrTunnel on " + tmp[1]);
        new LocationManagerConnector("upD", "-lm=lm " + "-domain=" + tmp[1]);
      }
      if (((tmp = argHash.get("-acm")) != null) && (tmp.length > 1)) {

        _log.info("Starting UserMgrCell on " + tmp[1]);
        new UserMgrCell("acm", tmp[1]);
      }
      if (((tmp = argHash.get("-tunnel")) != null) && (tmp.length > 1)) {

        _log.info("Starting RetryTunnel on " + tmp[1]);
        new GNLCell("down", "dmg.cells.network.RetryTunnel " + tmp[1]);
      }
      if (((tmp = argHash.get("-accept")) != null) && (tmp.length > 0)) {

        _log.info("Starting LocationMgrTunnel(listen)");
        new LoginManager("downD", "0 dmg.cells.network.LocationMgrTunnel " + "-prot=raw -lm=lm");
      }
      if (((tmp = argHash.get("-boot")) != null) && (tmp.length > 1)) {

        _log.info("Starting BootSequence for Domain " + tmp[1]);
        List<String> v = new ArrayList<>();
        v.add("onerror shutdown");
        v.add("set context bootDomain " + tmp[1]);
        v.add("waitfor context Ready ${bootDomain}");
        v.add("copy context://${bootDomain}/${thisDomain}Setup context:bootStrap");
        v.add("exec context bootStrap");
        v.add("# exit");
        String[] commands = new String[v.size()];

        new BatchCell("boot", v.toArray(commands));
      }
      if (((tmp = argHash.get("-spy")) != null) && (tmp.length > 1)) {

        _log.info("Starting TopologyManager ");
        new TopoCell("topo", "");
        _log.info("Starting Spy Listener on " + tmp[1]);
        new LoginManager("Spy", tmp[1] + " dmg.cells.services.ObjectLoginCell" + " -prot=raw");
      }
      if (((tmp = argHash.get("-batch")) != null) && (tmp.length > 1)) {

        _log.info("Starting BatchCell on " + tmp[1]);
        new BatchCell("batch", tmp[1]);
      }
      if (((tmp = argHash.get("-ic")) != null) && (tmp.length > 1)) {

        _log.info("Installing interruptHandlerClass " + tmp[1]);
        systemCell.enableInterrupts(tmp[1]);
      }
    } catch (Exception e) {
      _log.error(e.toString(), e);
    }
  }
Esempio n. 20
0
 /** @tests java.lang.Package#hashCode() */
 public void test_hashCode() {
   Package p1 = Package.getPackage("java.lang");
   if (p1 != null) {
     assertEquals(p1.hashCode(), "java.lang".hashCode());
   }
 }
	@SuppressWarnings("static-access")
	public static void main(String[] args) {
		try {
			final String vers = System.getProperty("java.version");
			final String requiredJVM = "1.5.0";
			final Package self = Package
					.getPackage("org.openscience.jchempaint");
			String version = GT._("Could not determine JCP version");
			if (self != null) {
				version = JCPPropertyHandler.getInstance(true).getVersion();
			}
			if (vers.compareTo(requiredJVM) < 0) {
				System.err
						.println(GT
								._("WARNING: JChemPaint {0} must be run with a Java VM version {1} or higher.",
										new String[] { version, requiredJVM }));
				System.err.println(GT._("Your JVM version is {0}", vers));
				System.exit(1);
			}

			final Options options = new Options();
			options.addOption("h", "help", false, GT._("gives this help page"));
			options.addOption("v", "version", false,
					GT._("gives JChemPaints version number"));
			options.addOption("d", "debug", false,
					"switches on various debug options");
			options.addOption(OptionBuilder.withArgName("property=value")
					.hasArg().withValueSeparator()
					.withDescription(GT._("supported options are given below"))
					.create("D"));

			CommandLine line = null;
			try {
				final CommandLineParser parser = new PosixParser();
				line = parser.parse(options, args);
			} catch (final UnrecognizedOptionException exception) {
				System.err.println(exception.getMessage());
				System.exit(-1);
			} catch (final ParseException exception) {
				System.err.println("Unexpected exception: "
						+ exception.toString());
			}

			if (line.hasOption("v")) {
				System.out.println("JChemPaint v." + version + "\n");
				System.exit(0);
			}

			if (line.hasOption("h")) {
				System.out.println("JChemPaint v." + version + "\n");

				final HelpFormatter formatter = new HelpFormatter();
				formatter.printHelp("JChemPaint", options);

				// now report on the -D options
				System.out.println();
				System.out
						.println("The -D options are as follows (defaults in parathesis):");
				System.out.println("  cdk.debugging     [true|false] (false)");
				System.out.println("  cdk.debug.stdout  [true|false] (false)");
				System.out
						.println("  user.language     [ar|ca|cs|de|en|es|hu|nb|nl|pl|pt|ru|th] (en)");
				System.out
						.println("  user.language     [ar|ca|cs|de|hu|nb|nl|pl|pt_BR|ru|th] (EN)");

				System.exit(0);
			}
			boolean debug = false;
			if (line.hasOption("d")) {
				debug = true;
			}

			// Set Look&Feel
			final Properties props = JCPPropertyHandler.getInstance(true)
					.getJCPProperties();
			try {
				UIManager.setLookAndFeel(props.getProperty("LookAndFeelClass"));
			} catch (final Throwable e) {
				final String sys = UIManager.getSystemLookAndFeelClassName();
				UIManager.setLookAndFeel(sys);
				props.setProperty("LookAndFeelClass", sys);
			}

			// Language
			props.setProperty("General.language",
					System.getProperty("user.language", "en"));

			// Process command line arguments
			String modelFilename = "";
			args = line.getArgs();
			if (args.length > 0) {
				modelFilename = args[0];
				final File file = new File(modelFilename);
				if (!file.exists()) {
					System.err.println(GT._("File does not exist") + ": "
							+ modelFilename);
					System.exit(-1);
				}
				showInstance(file, null, null, debug);
			} else {
				showEmptyInstance(debug);
			}

		} catch (final Throwable t) {
			System.err.println("uncaught exception: " + t);
			t.printStackTrace(System.err);
		}
	}
Esempio n. 22
0
 public Object readResolve() {
   return inPackage(Package.getPackage(packageName));
 }
/**
 * Collection of utility methods that are useful for dealing with version information retrieved from
 * reading jar files or package loaded by the class manager. Some methods also help comparing
 * version information. The method getJHotDrawVersion() can be used to retrieve the current version
 * of JHotDraw as loaded by the class manager.
 *
 * @author Wolfram Kaiser
 * @version <$CURRENT_VERSION$>
 */
public class VersionManagement {
  public static String JHOTDRAW_COMPONENT = "CH.ifa.draw/";
  public static String JHOTDRAW_JAR = "jhotdraw.jar";

  public static Package[] packages = {
    Package.getPackage("CH.ifa.draw.applet"),
    Package.getPackage("CH.ifa.draw.application"),
    Package.getPackage("CH.ifa.draw.contrib"),
    Package.getPackage("CH.ifa.draw.figures"),
    Package.getPackage("CH.ifa.draw.framework"),
    Package.getPackage("CH.ifa.draw.standard"),
    Package.getPackage("CH.ifa.draw.util")
  };

  /**
   * Return the version of the main package of the framework. A version number is available if there
   * is a corresponding version entry in the JHotDraw jar file for the framework package.
   */
  public static String getJHotDrawVersion() {
    // look for the framework main package
    Package pack = packages[4];
    return pack.getSpecificationVersion();
  }

  /** */
  public static String getPackageVersion(final Package lookupPackage) {
    if (lookupPackage == null) {
      return null;
    }

    String specVersion = lookupPackage.getSpecificationVersion();
    if (specVersion != null) {
      return specVersion;
    } else {
      // search in parent package
      String normalizedPackageName = normalizePackageName(lookupPackage.getName());
      String nextPackageName = getNextPackage(normalizedPackageName);
      return getPackageVersion(Package.getPackage(nextPackageName));
    }
  }

  /**
   * Check whether a given application version is compatible with the version of JHotDraw currently
   * loaded in the Java VM. A version number is available if there is a corresponding version entry
   * in the JHotDraw jar file for the framework package.
   */
  public static boolean isCompatibleVersion(String compareVersionString) {
    //		Package pack = VersionManagement.class.getPackage();
    Package pack = packages[4];
    if (compareVersionString == null) {
      return pack.getSpecificationVersion() == null;
    } else {
      return pack.isCompatibleWith(compareVersionString);
    }
  }

  /**
   * Read the version information from a file with a given file name. The file must be a jar
   * manifest file and all its entries are searched for package names and their specification
   * version information. All information is collected in a map for later lookup of package names
   * and their versions.
   *
   * @param versionFileName name of the jar file containing version information
   */
  public static String readVersionFromFile(String applicationName, String versionFileName) {
    try {
      FileInputStream fileInput = new FileInputStream(versionFileName);
      Manifest manifest = new Manifest();
      manifest.read(fileInput);

      Map entries = manifest.getEntries();
      // Now write out the pre-entry attributes
      Iterator entryIterator = entries.entrySet().iterator();
      while (entryIterator.hasNext()) {
        Map.Entry currentEntry = (Map.Entry) entryIterator.next();
        String packageName = currentEntry.getKey().toString();
        packageName = normalizePackageName(packageName);
        Attributes attributes = (Attributes) currentEntry.getValue();
        String packageSpecVersion = attributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
        packageSpecVersion = extractVersionInfo(packageSpecVersion);
        return packageSpecVersion;
      }
    } catch (IOException exception) {
      exception.printStackTrace();
    }

    // no version found
    return null;
  }

  /**
   * Get the super package of a package specifier. The super package is the package specifier
   * without the latest package name, e.g. the next package for "org.jhotdraw.tools" would be
   * "org.jhotdraw".
   *
   * @param searchPackage package specifier
   * @return next package if one is available, null otherwise
   */
  public static String getNextPackage(String searchPackage) {
    if (searchPackage == null) {
      return null;
    }

    int foundNextPackage = searchPackage.lastIndexOf('.');
    if (foundNextPackage > 0) {
      return searchPackage.substring(0, foundNextPackage);
    } else {
      return null;
    }
  }

  /**
   * A package name is normalized by replacing all path delimiters by "." to retrieve a valid
   * standardized package specifier used in package declarations in Java source files.
   *
   * @param toBeNormalized package name to be normalized
   * @return normalized package name
   */
  public static String normalizePackageName(String toBeNormalized) {
    // first, replace the standard package delimiter used in jars
    String replaced = toBeNormalized.replace('/', '.');
    // then, replace the default path separator in case this one was used as well
    replaced = replaced.replace(File.pathSeparatorChar, '.');
    if (replaced.endsWith(".")) {
      int lastSeparator = replaced.lastIndexOf('.');
      return replaced.substring(0, lastSeparator);
    } else {
      return replaced;
    }
  }

  /**
   * Get the version information specified in a jar manifest file without any leading or trailing
   * "\"".
   *
   * @param versionString a version string with possibly leading or trailing "\""
   * @return stripped version information
   */
  public static String extractVersionInfo(String versionString) {
    // guarding conditions
    if (versionString == null) {
      return null;
    }
    if (versionString.length() == 0) {
      return "";
    }

    int startIndex = versionString.indexOf("\"");
    if (startIndex < 0) {
      startIndex = 0;
    } else {
      // start from next character
      startIndex++;
    }

    int endIndex = versionString.lastIndexOf("\"");
    if (endIndex < 0) {
      endIndex = versionString.length();
    }

    return versionString.substring(startIndex, endIndex);
  }
}