Search in sources :

Example 1 with FileBasedJavaVersion

use of net.technicpack.launchercore.launch.java.version.FileBasedJavaVersion in project LauncherV3 by TechnicPack.

the class OptionsDialog method selectOtherVersion.

protected void selectOtherVersion() {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    final String osJavaName = new File(OperatingSystem.getJavaDir()).getName();
    chooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            if (f.isDirectory())
                return true;
            return (f.getName().equals(osJavaName));
        }

        @Override
        public String getDescription() {
            return resources.getString("launcheroptions.java.filter", osJavaName);
        }
    });
    int result = chooser.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile() == null || !chooser.getSelectedFile().exists() || !chooser.getSelectedFile().canExecute()) {
            JOptionPane.showMessageDialog(this, resources.getString("launcheroptions.java.badfile"));
            return;
        }
        FileBasedJavaVersion chosenJava = new FileBasedJavaVersion(chooser.getSelectedFile());
        if (!chosenJava.verify()) {
            JOptionPane.showMessageDialog(this, resources.getString("launcheroptions.java.badfile"));
            return;
        }
        IJavaVersion existingVersion = javaVersions.getVersion(chosenJava.getVersionNumber(), chosenJava.is64Bit());
        if (existingVersion.getJavaPath() != null) {
            JOptionPane.showMessageDialog(this, resources.getString("launcheroptions.java.versionexists"));
            return;
        }
        fileJavaSource.addVersion(chosenJava);
        javaVersions.addVersion(chosenJava);
        javaVersions.selectVersion(chosenJava.getVersionNumber(), chosenJava.is64Bit());
        JavaVersionItem item = new JavaVersionItem(chosenJava, resources);
        versionSelect.addItem(item);
        versionSelect.setSelectedItem(item);
        settings.setJavaVersion(chosenJava.getVersionNumber());
        settings.setJavaBitness(chosenJava.is64Bit());
        settings.save();
    }
}
Also used : JavaVersionItem(net.technicpack.ui.listitems.javaversion.JavaVersionItem) FileFilter(javax.swing.filechooser.FileFilter) FileBasedJavaVersion(net.technicpack.launchercore.launch.java.version.FileBasedJavaVersion) File(java.io.File) IJavaVersion(net.technicpack.launchercore.launch.java.IJavaVersion)

Example 2 with FileBasedJavaVersion

use of net.technicpack.launchercore.launch.java.version.FileBasedJavaVersion in project LauncherV3 by TechnicPack.

the class MacInstalledJavaSource method enumerateVersions.

@Override
public void enumerateVersions(JavaVersionRepository repository) {
    repository.addVersion(new FileBasedJavaVersion(new File(getMacJava("1.6"))));
    repository.addVersion(new FileBasedJavaVersion(new File(getMacJava("1.7"))));
    repository.addVersion(new FileBasedJavaVersion(new File(getMacJava("1.8"))));
    repository.addVersion(new FileBasedJavaVersion(new File("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java")));
    enumerateJavaHome(repository);
}
Also used : FileBasedJavaVersion(net.technicpack.launchercore.launch.java.version.FileBasedJavaVersion) File(java.io.File)

Example 3 with FileBasedJavaVersion

use of net.technicpack.launchercore.launch.java.version.FileBasedJavaVersion in project LauncherV3 by TechnicPack.

the class MacInstalledJavaSource method enumerateJavaHome.

private void enumerateJavaHome(JavaVersionRepository repository) {
    String output = Utils.getProcessOutput("/usr/libexec/java_home", "-V");
    if (output == null || output.isEmpty())
        return;
    for (String line : output.split("\\r?\\n")) {
        // Output is:
        // Matching Java Virtual Machines (N):
        // <version> (<arch>) "<vendor>" - "<runtime name>" <path>
        // <path> always starts with /Library/
        int pathIndex = line.indexOf("/Library/");
        if (pathIndex < 0)
            continue;
        String path = line.substring(pathIndex).trim();
        repository.addVersion(new FileBasedJavaVersion(new File(path + File.separator + "bin" + File.separator + "java")));
    }
}
Also used : FileBasedJavaVersion(net.technicpack.launchercore.launch.java.version.FileBasedJavaVersion) File(java.io.File)

Example 4 with FileBasedJavaVersion

use of net.technicpack.launchercore.launch.java.version.FileBasedJavaVersion in project LauncherV3 by TechnicPack.

the class WinRegistryJavaSource method enumerateRegistryForBitness.

private void enumerateRegistryForBitness(JavaVersionRepository repository, String bitness, String keyPath, String keyName) {
    String output = Utils.getProcessOutput("reg", "query", "HKEY_LOCAL_MACHINE\\" + keyPath, "/f", keyName, "/t", "REG_SZ", "/s", "/reg:" + bitness);
    if (output == null || output.isEmpty())
        return;
    // Split reg query response into lines
    for (String line : output.split("\\r?\\n")) {
        // Reg query is a response that's like
        // Key Path
        // Key Name          Type            Value
        // We want to grab all the values that were returned and parse them into java home paths.
        // The type is always REG_SZ because that's what we searched for, so we find the type & expect the value to be afterward
        int typeIndex = line.indexOf("REG_SZ");
        if (typeIndex < 0)
            continue;
        typeIndex += "REG_SZ".length();
        String path = line.substring(typeIndex).trim();
        repository.addVersion(new FileBasedJavaVersion(new File(path + File.separator + "bin" + File.separator + "javaw.exe")));
    }
}
Also used : FileBasedJavaVersion(net.technicpack.launchercore.launch.java.version.FileBasedJavaVersion) File(java.io.File)

Aggregations

File (java.io.File)4 FileBasedJavaVersion (net.technicpack.launchercore.launch.java.version.FileBasedJavaVersion)4 FileFilter (javax.swing.filechooser.FileFilter)1 IJavaVersion (net.technicpack.launchercore.launch.java.IJavaVersion)1 JavaVersionItem (net.technicpack.ui.listitems.javaversion.JavaVersionItem)1