Search in sources :

Example 1 with IVMInstall

use of org.eclipse.jdt.launching.IVMInstall in project jop by jop-devel.

the class JOPizer method createJOPizeLaunchConfiguration.

private ILaunchConfiguration createJOPizeLaunchConfiguration(String programArguments) throws CoreException {
    String configName = "JOPize";
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
    ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
    for (ILaunchConfiguration config : configs) {
        if (config.getName().equals(configName)) {
            config.delete();
            break;
        }
    }
    ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, configName);
    IVMInstall defaultVMInstall = JavaRuntime.getDefaultVMInstall();
    Map attributes = workingCopy.getAttributes();
    attributes.put(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "com.jopdesign.build.JOPizer");
    attributes.put(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, programArguments);
    IPreferenceStore prefs = JOPUIPlugin.getDefault().getPreferenceStore();
    String jopHome = prefs.getString(IJOPLaunchConfigurationConstants.ATTR_JOP_HOME);
    IPath jopTools = new Path(jopHome).append(new Path("java/tools/dist/lib/jop-tools.jar"));
    IRuntimeClasspathEntry jopToolsEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(jopTools);
    jopToolsEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
    IPath jopClasses = new Path(jopHome).append(new Path("java/target/dist/lib/classes.zip"));
    IRuntimeClasspathEntry jopClassesEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(jopClasses);
    jopClassesEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
    // IClasspathEntry jreEntry = JavaRuntime.getDefaultJREContainerEntry();
    List<String> classpath = new ArrayList<String>();
    classpath.add(jopToolsEntry.getMemento());
    classpath.add(jopClassesEntry.getMemento());
    // classpath.add(jreEntry.get)
    attributes.put(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath);
    attributes.put(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
    attributes.put(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "-Dmgci=false");
    workingCopy.setAttributes(attributes);
    System.err.printf("> %s%n", workingCopy.toString());
    return workingCopy;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) IVMInstall(org.eclipse.jdt.launching.IVMInstall) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Map(java.util.Map)

Example 2 with IVMInstall

use of org.eclipse.jdt.launching.IVMInstall in project tdi-studio-se by Talend.

the class Tools method searchJdkRootDirectory.

/**
     * Searches the JDK root directory.
     * 
     * @return The JDK root directory, or empty string if not found
     */
private String searchJdkRootDirectory() {
    // search from the JREs that are specified on preference page
    for (IVMInstallType type : JavaRuntime.getVMInstallTypes()) {
        for (IVMInstall install : type.getVMInstalls()) {
            String jdkRootDirectory = install.getInstallLocation().getPath();
            if (null == validateJdkRootDirectory(jdkRootDirectory)) {
                Activator.log(IStatus.INFO, NLS.bind(Messages.jdkRootDirectoryFoundMsg, jdkRootDirectory), new Exception());
                return jdkRootDirectory;
            }
        }
    }
    // search at the same directory as current JRE
    String javaHome = System.getProperty(JAVA_HOME_PROPERTY_KEY);
    for (File directory : getPossibleJdkRootDirectory(javaHome)) {
        String path = directory.getPath();
        if (null == validateJdkRootDirectory(path)) {
            Activator.log(IStatus.INFO, NLS.bind(Messages.jdkRootDirectoryFoundMsg, path), new Exception());
            return path;
        }
    }
    Activator.log(IStatus.WARNING, Messages.jdkRootDirectoryNotFoundMsg, new Exception());
    //$NON-NLS-1$
    return "";
}
Also used : IVMInstall(org.eclipse.jdt.launching.IVMInstall) IVMInstallType(org.eclipse.jdt.launching.IVMInstallType) File(java.io.File) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 3 with IVMInstall

use of org.eclipse.jdt.launching.IVMInstall in project sling by apache.

the class DefaultJavaVMInstall method before.

@Override
protected void before() throws Throwable {
    if (JavaRuntime.getDefaultVMInstall() != null) {
        return;
    }
    String jreHome = System.getProperty("java.home");
    File installLocation = new File(jreHome);
    final IVMInstallType vmInstallType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
    // find an unused VM id
    String id = null;
    do {
        id = String.valueOf(System.currentTimeMillis());
    } while (vmInstallType.findVMInstall(id) != null);
    VMStandin newVm = new VMStandin(vmInstallType, id);
    newVm.setName("Default-VM");
    newVm.setInstallLocation(installLocation);
    IVMInstall realVm = newVm.convertToRealVM();
    JavaRuntime.setDefaultVMInstall(realVm, new NullProgressMonitor());
    // wait for the default vm reconfiguration to settle
    // TODO - find something to poll agains rather than sleeping blindly
    Thread.sleep(5000);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IVMInstall(org.eclipse.jdt.launching.IVMInstall) IVMInstallType(org.eclipse.jdt.launching.IVMInstallType) File(java.io.File) VMStandin(org.eclipse.jdt.launching.VMStandin)

Aggregations

IVMInstall (org.eclipse.jdt.launching.IVMInstall)3 File (java.io.File)2 IVMInstallType (org.eclipse.jdt.launching.IVMInstallType)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 IPath (org.eclipse.core.runtime.IPath)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)1 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)1 ILaunchManager (org.eclipse.debug.core.ILaunchManager)1 IRuntimeClasspathEntry (org.eclipse.jdt.launching.IRuntimeClasspathEntry)1 VMStandin (org.eclipse.jdt.launching.VMStandin)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 JvmCoreException (org.talend.designer.runtime.visualization.JvmCoreException)1