Search in sources :

Example 1 with JVM

use of aQute.jpm.lib.JVM in project bnd by bndtools.

the class JPMTest method testVM.

public void testVM() throws Exception {
    File tmp = new File("tmp");
    IO.delete(tmp);
    tmp.mkdirs();
    File home = new File(tmp, "home");
    File bin = new File(tmp, "bin");
    System.setProperty("jpm.intest", "true");
    JustAnotherPackageManager jpm = new JustAnotherPackageManager(new ReporterAdapter(), null, home, bin);
    SortedSet<JVM> vms = jpm.getVMs();
    assertNotNull(vms);
    assertTrue(vms.size() >= 1);
    System.out.println(vms);
    File f = IO.getFile("~/jdk1.8");
    if (f.isDirectory()) {
        JVM jvm = jpm.addVm(f);
        assertNotNull(jvm);
    }
}
Also used : JVM(aQute.jpm.lib.JVM) JustAnotherPackageManager(aQute.jpm.lib.JustAnotherPackageManager) ReporterAdapter(aQute.libg.reporter.ReporterAdapter) File(java.io.File)

Example 2 with JVM

use of aQute.jpm.lib.JVM in project bnd by bndtools.

the class MacOS method getJVM.

@Override
public JVM getJVM(File vmdir) throws Exception {
    if (!vmdir.isDirectory()) {
        return null;
    }
    File contents = new File(vmdir, "Contents");
    if (!contents.isDirectory()) {
        logger.debug("Found a directory {}, but it does not have the expected Contents directory", vmdir);
        return null;
    }
    File plist = new File(contents, "Info.plist");
    if (!plist.isFile()) {
        logger.debug("The VM in {} has no Info.plist with the necessary details", vmdir);
        return null;
    }
    File home = new File(contents, "Home");
    String error = verifyVM(home);
    if (error != null) {
        reporter.error("Invalid vm directory for MacOS %s: %s", vmdir, error);
        return null;
    }
    DocumentBuilder db = dbf.newDocumentBuilder();
    try {
        Document doc = db.parse(plist);
        XPath xp = xpf.newXPath();
        Node versionNode = (Node) xp.evaluate("//dict/key[text()='JVMVersion']", doc, XPathConstants.NODE);
        Node platformVersionNode = (Node) xp.evaluate("//dict/key[text()='JVMPlatformVersion']", doc, XPathConstants.NODE);
        Node vendorNode = (Node) xp.evaluate("//dict/key[text()='JVMVendor']", doc, XPathConstants.NODE);
        Node capabilitiesNode = (Node) xp.evaluate("//dict/key[text()='JVMCapabilities']", doc, XPathConstants.NODE);
        JVM jvm = new JVM();
        jvm.name = vmdir.getName();
        jvm.path = home.getCanonicalPath();
        jvm.platformRoot = vmdir.getCanonicalPath();
        jvm.version = getSiblingValue(versionNode);
        jvm.platformVersion = getSiblingValue(platformVersionNode);
        jvm.vendor = getSiblingValue(vendorNode);
        return jvm;
    } catch (Exception e) {
        logger.debug("Could not parse the Info.plist in {}", vmdir, e);
        throw e;
    }
}
Also used : XPath(javax.xml.xpath.XPath) JVM(aQute.jpm.lib.JVM) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) File(java.io.File) IOException(java.io.IOException)

Aggregations

JVM (aQute.jpm.lib.JVM)2 File (java.io.File)2 JustAnotherPackageManager (aQute.jpm.lib.JustAnotherPackageManager)1 ReporterAdapter (aQute.libg.reporter.ReporterAdapter)1 IOException (java.io.IOException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 XPath (javax.xml.xpath.XPath)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1