Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 201758 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/debug/ui/jres/VMLibraryBlock.java (-90 / +105 lines)
Lines 21-34 Link Here
21
import org.eclipse.core.runtime.Status;
21
import org.eclipse.core.runtime.Status;
22
import org.eclipse.jdt.core.IClasspathEntry;
22
import org.eclipse.jdt.core.IClasspathEntry;
23
import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
23
import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
24
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
24
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
25
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
25
import org.eclipse.jdt.internal.debug.ui.SWTFactory;
26
import org.eclipse.jdt.internal.debug.ui.SWTFactory;
26
import org.eclipse.jdt.internal.debug.ui.jres.LibraryContentProvider.SubElement;
27
import org.eclipse.jdt.internal.debug.ui.jres.LibraryContentProvider.SubElement;
28
import org.eclipse.jdt.internal.launching.EEVMType;
27
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
29
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
28
import org.eclipse.jdt.launching.IVMInstall;
30
import org.eclipse.jdt.launching.IVMInstall;
29
import org.eclipse.jdt.launching.IVMInstallType;
30
import org.eclipse.jdt.launching.JavaRuntime;
31
import org.eclipse.jdt.launching.JavaRuntime;
31
import org.eclipse.jdt.launching.LibraryLocation;
32
import org.eclipse.jdt.launching.LibraryLocation;
33
import org.eclipse.jdt.launching.VMStandin;
32
import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess;
34
import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess;
33
import org.eclipse.jface.dialogs.IDialogSettings;
35
import org.eclipse.jface.dialogs.IDialogSettings;
34
import org.eclipse.jface.viewers.DoubleClickEvent;
36
import org.eclipse.jface.viewers.DoubleClickEvent;
Lines 44-57 Link Here
44
import org.eclipse.swt.layout.GridData;
46
import org.eclipse.swt.layout.GridData;
45
import org.eclipse.swt.widgets.Button;
47
import org.eclipse.swt.widgets.Button;
46
import org.eclipse.swt.widgets.Composite;
48
import org.eclipse.swt.widgets.Composite;
47
import org.eclipse.swt.widgets.Control;
48
import org.eclipse.swt.widgets.FileDialog;
49
import org.eclipse.swt.widgets.FileDialog;
49
 
50
 
50
/**
51
/**
51
 * Control used to edit the libraries associated with a VM install
52
 * Control used to edit the libraries associated with a VM install
52
 */
53
 */
53
public class VMLibraryBlock implements SelectionListener, ISelectionChangedListener {
54
public class VMLibraryBlock extends AbstractVMInstallPage implements SelectionListener, ISelectionChangedListener {
54
	
55
55
	/**
56
	/**
56
	 * Attribute name for the last path used to open a file/directory chooser
57
	 * Attribute name for the last path used to open a file/directory chooser
57
	 * dialog.
58
	 * dialog.
Lines 64-76 Link Here
64
	protected static final String DIALOG_SETTINGS_PREFIX = "VMLibraryBlock"; //$NON-NLS-1$
65
	protected static final String DIALOG_SETTINGS_PREFIX = "VMLibraryBlock"; //$NON-NLS-1$
65
	
66
	
66
	protected boolean fInCallback = false;
67
	protected boolean fInCallback = false;
67
	protected IVMInstall fVmInstall;
68
	protected VMStandin fVmInstall;
68
	protected IVMInstallType fVmInstallType;
69
	protected File fHome;
70
	
69
	
71
	//widgets
70
	//widgets
72
	protected LibraryContentProvider fLibraryContentProvider;
71
	protected LibraryContentProvider fLibraryContentProvider;
73
	protected AddVMDialog fDialog = null;
74
	protected TreeViewer fLibraryViewer;
72
	protected TreeViewer fLibraryViewer;
75
	private Button fUpButton;
73
	private Button fUpButton;
76
	private Button fDownButton;
74
	private Button fDownButton;
Lines 81-98 Link Here
81
	protected Button fDefaultButton;
79
	protected Button fDefaultButton;
82
	
80
	
83
	/**
81
	/**
84
	 * Constructor for VMLibraryBlock.
82
	 * Constructs a new wizard page with the given name.
83
	 * 
84
	 * @param pageName page name
85
	 */
85
	 */
86
	public VMLibraryBlock(AddVMDialog dialog) {
86
	VMLibraryBlock() {
87
		fDialog = dialog;
87
		super("JRE System Libraries");
88
	}
88
	}	
89
89
90
	/**
90
	/* (non-Javadoc)
91
	 * Creates and returns the source lookup control.
91
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
92
	 * 
93
	 * @param parent the parent widget of this control
94
	 */
92
	 */
95
	public Control createControl(Composite parent) {
93
	public void createControl(Composite parent) {
96
		Font font = parent.getFont();
94
		Font font = parent.getFont();
97
		
95
		
98
		Composite comp = SWTFactory.createComposite(parent, font, 2, 1, GridData.FILL_BOTH, 0, 0);
96
		Composite comp = SWTFactory.createComposite(parent, font, 2, 1, GridData.FILL_BOTH, 0, 0);
Lines 132-193 Link Here
132
		fDefaultButton = SWTFactory.createPushButton(pathButtonComp, JREMessages.VMLibraryBlock_9, JREMessages.VMLibraryBlock_15, null);
130
		fDefaultButton = SWTFactory.createPushButton(pathButtonComp, JREMessages.VMLibraryBlock_9, JREMessages.VMLibraryBlock_15, null);
133
		fDefaultButton.addSelectionListener(this);
131
		fDefaultButton.addSelectionListener(this);
134
		
132
		
135
		return comp;
133
		setControl(comp);
136
	}
134
	}
137
135
138
	/**
136
	/**
139
	 * The "default" button has been toggled
137
	 * The "default" button has been toggled
140
	 */
138
	 */
141
	public void restoreDefaultLibraries() {
139
	private void restoreDefaultLibraries() {
142
		LibraryLocation[] libs = null;
140
		LibraryLocation[] libs = null;
143
		File installLocation = getHomeDirectory();
141
		File installLocation = null;
144
		if (installLocation == null) {
142
		if (fVmInstall != null) {
145
			libs = new LibraryLocation[0];
143
			if (EEVMType.ID_EE_VM_TYPE.equals(fVmInstall.getVMInstallType().getId())) {
146
		} else {
144
				File definitionFile = EEVMType.getDefinitionFile(fVmInstall);
147
			libs = getVMInstallType().getDefaultLibraryLocations(installLocation);
145
				if (definitionFile != null) {
146
					libs = EEVMType.getLibraryLocations(definitionFile);
147
				} else {
148
					libs = new LibraryLocation[0];
149
				}
150
			} else {
151
				installLocation = fVmInstall.getInstallLocation();
152
				if (installLocation == null) {
153
					libs = new LibraryLocation[0];
154
				} else {
155
					libs = fVmInstall.getVMInstallType().getDefaultLibraryLocations(installLocation);
156
				}
157
			}
148
		}
158
		}
149
		fLibraryContentProvider.setLibraries(libs);
159
		fLibraryContentProvider.setLibraries(libs);
150
		update();
160
		update();
151
	}
161
	}
152
	
162
	
153
	/**
163
	/**
154
	 * Initializes this control based on the settings in the given
155
	 * vm install and type.
156
	 * 
157
	 * @param vm vm or <code>null</code> if none
158
	 * @param type type of vm install
159
	 */
160
	public void initializeFrom(IVMInstall vm, IVMInstallType type) {
161
		fVmInstall = vm;
162
		fVmInstallType = type;
163
		if (vm != null) {
164
			setHomeDirectory(vm.getInstallLocation());
165
			fLibraryContentProvider.setLibraries(JavaRuntime.getLibraryLocations(getVMInstall()));
166
		}
167
		update();
168
	}
169
	
170
	/**
171
	 * Sets the home directory of the VM Install the user has chosen
172
	 */
173
	public void setHomeDirectory(File file) {
174
		fHome = file;
175
	}
176
	
177
	/**
178
	 * Returns the home directory
179
	 */
180
	protected File getHomeDirectory() {
181
		return fHome;
182
	}
183
	
184
	/**
185
	 * Updates buttons and status based on current libraries
164
	 * Updates buttons and status based on current libraries
186
	 */
165
	 */
187
	public void update() {
166
	private void update() {
188
		updateButtons();
167
		updateButtons();
189
		IStatus status = Status.OK_STATUS;
168
		IStatus status = Status.OK_STATUS;
190
		if (fLibraryContentProvider.getLibraries().length == 0) { // && !isDefaultSystemLibrary()) {
169
		if (fLibraryContentProvider.getLibraries().length == 0) {
191
			status = new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), IJavaDebugUIConstants.INTERNAL_ERROR, "Libraries cannot be empty.", null); //$NON-NLS-1$
170
			status = new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), IJavaDebugUIConstants.INTERNAL_ERROR, "Libraries cannot be empty.", null); //$NON-NLS-1$
192
		}
171
		}
193
		LibraryStandin[] standins = fLibraryContentProvider.getStandins();
172
		LibraryStandin[] standins = fLibraryContentProvider.getStandins();
Lines 198-218 Link Here
198
				break;
177
				break;
199
			}
178
			}
200
		}
179
		}
201
		fDialog.setSystemLibraryStatus(status);
180
		if (status.isOK()) {
202
		fDialog.updateStatusLine();
181
			setErrorMessage(null);
203
	}
182
			setPageComplete(true);
204
	
205
	/**
206
	 * Saves settings in the given working copy
207
	 */
208
	public void performApply(IVMInstall vm) {
209
		if (isDefaultLocations(vm)) {
210
			vm.setLibraryLocations(null);
211
		} else {
183
		} else {
212
			LibraryLocation[] libs = fLibraryContentProvider.getLibraries();
184
			setErrorMessage(status.getMessage());
213
			vm.setLibraryLocations(libs);
185
			setPageComplete(false);
214
		}		
186
		}
215
	}	
187
		// must force since this page is a 'sub-page' and may not be considered the current page
188
		if (getContainer().getCurrentPage() != this) {
189
			getContainer().updateMessage();
190
			getContainer().updateButtons();
191
		}
192
	}
216
	
193
	
217
	/**
194
	/**
218
	 * Determines if the current libraries displayed to the user are the default location
195
	 * Determines if the current libraries displayed to the user are the default location
Lines 228-234 Link Here
228
		}
205
		}
229
		File installLocation = vm.getInstallLocation();
206
		File installLocation = vm.getInstallLocation();
230
		if (installLocation != null) {
207
		if (installLocation != null) {
231
			LibraryLocation[] def = getVMInstallType().getDefaultLibraryLocations(installLocation);
208
			LibraryLocation[] def = vm.getVMInstallType().getDefaultLibraryLocations(installLocation);
232
			if (def.length == libraryLocations.length) {
209
			if (def.length == libraryLocations.length) {
233
				for (int i = 0; i < def.length; i++) {
210
				for (int i = 0; i < def.length; i++) {
234
					if (!def[i].equals(libraryLocations[i])) {
211
					if (!def[i].equals(libraryLocations[i])) {
Lines 240-263 Link Here
240
		}
217
		}
241
		return false;
218
		return false;
242
	}
219
	}
243
	
244
	/**
245
	 * Returns the vm install associated with this library block.
246
	 * 
247
	 * @return vm install
248
	 */
249
	protected IVMInstall getVMInstall() {
250
		return fVmInstall;
251
	}	
252
	
253
	/**
254
	 * Returns the vm install type associated with this library block.
255
	 * 
256
	 * @return vm install
257
	 */
258
	protected IVMInstallType getVMInstallType() {
259
		return fVmInstallType;
260
	}
261
220
262
	/* (non-Javadoc)
221
	/* (non-Javadoc)
263
	 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
222
	 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
Lines 409-412 Link Here
409
		fJavadocButton.setEnabled(!selection.isEmpty() && (allJavadoc || allRoots));
368
		fJavadocButton.setEnabled(!selection.isEmpty() && (allJavadoc || allRoots));
410
		fSourceButton.setEnabled(!selection.isEmpty() && (allSource || allRoots));
369
		fSourceButton.setEnabled(!selection.isEmpty() && (allSource || allRoots));
411
	}
370
	}
371
372
	/* (non-Javadoc)
373
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#finish()
374
	 */
375
	public boolean finish() {
376
		if (fVmInstall != null) {
377
			if (isDefaultLocations(fVmInstall)) {
378
				fVmInstall.setLibraryLocations(null);
379
			} else {
380
				LibraryLocation[] libs = fLibraryContentProvider.getLibraries();
381
				fVmInstall.setLibraryLocations(libs);
382
			}
383
		}
384
		return true;
385
	}
386
387
	/* (non-Javadoc)
388
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#getSelection()
389
	 */
390
	public VMStandin getSelection() {
391
		return fVmInstall;
392
	}
393
394
	/* (non-Javadoc)
395
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#setSelection(org.eclipse.jdt.launching.VMStandin)
396
	 */
397
	public void setSelection(VMStandin vm) {
398
		super.setSelection(vm);
399
		LibraryLocation[] libraryLocations = null;
400
		if (vm == null) {
401
			libraryLocations = new LibraryLocation[0];
402
		} else {
403
			libraryLocations = JavaRuntime.getLibraryLocations(vm);
404
		}
405
		fVmInstall = vm;
406
		fLibraryContentProvider.setLibraries(libraryLocations);
407
	}
408
409
	/* (non-Javadoc)
410
	 * @see org.eclipse.jdt.launching.IVMInstallChangedListener#defaultVMInstallChanged(org.eclipse.jdt.launching.IVMInstall, org.eclipse.jdt.launching.IVMInstall)
411
	 */
412
	public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
413
	}
414
415
	/* (non-Javadoc)
416
	 * @see org.eclipse.jdt.launching.IVMInstallChangedListener#vmAdded(org.eclipse.jdt.launching.IVMInstall)
417
	 */
418
	public void vmAdded(IVMInstall vm) {
419
	}
420
421
	/* (non-Javadoc)
422
	 * @see org.eclipse.jdt.launching.IVMInstallChangedListener#vmRemoved(org.eclipse.jdt.launching.IVMInstall)
423
	 */
424
	public void vmRemoved(IVMInstall vm) {
425
	}
426
		
412
}
427
}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryContentProvider.java (-1 / +3 lines)
Lines 142-148 Link Here
142
		for (int i = 0; i < libs.length; i++) {
142
		for (int i = 0; i < libs.length; i++) {
143
			fLibraries[i] = new LibraryStandin(libs[i]);
143
			fLibraries[i] = new LibraryStandin(libs[i]);
144
		}
144
		}
145
		fViewer.refresh();
145
		if (fViewer != null) {
146
			fViewer.refresh();
147
		}
146
	}
148
	}
147
149
148
	/**
150
	/**
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/InstalledJREsBlock.java (-20 / +42 lines)
Lines 56-61 Link Here
56
import org.eclipse.jface.viewers.Viewer;
56
import org.eclipse.jface.viewers.Viewer;
57
import org.eclipse.jface.viewers.ViewerComparator;
57
import org.eclipse.jface.viewers.ViewerComparator;
58
import org.eclipse.jface.window.Window;
58
import org.eclipse.jface.window.Window;
59
import org.eclipse.jface.wizard.WizardDialog;
59
import org.eclipse.swt.SWT;
60
import org.eclipse.swt.SWT;
60
import org.eclipse.swt.events.KeyAdapter;
61
import org.eclipse.swt.events.KeyAdapter;
61
import org.eclipse.swt.events.KeyEvent;
62
import org.eclipse.swt.events.KeyEvent;
Lines 129-134 Link Here
129
	// happen very quickly
130
	// happen very quickly
130
	private static String fgLastUsedID;	
131
	private static String fgLastUsedID;	
131
	
132
	
133
	/**
134
	 * VM install type id for OSX VMs
135
	 */
136
	public static final String MACOSX_VM_TYPE_ID = "org.eclipse.jdt.internal.launching.macosx.MacOSXType"; //$NON-NLS-1$
137
	
132
	/** 
138
	/** 
133
	 * Content provider to show a list of JREs
139
	 * Content provider to show a list of JREs
134
	 */ 
140
	 */ 
Lines 357-373 Link Here
357
        ArrayList newEntries = new ArrayList();
363
        ArrayList newEntries = new ArrayList();
358
        while (it.hasNext()) {
364
        while (it.hasNext()) {
359
            IVMInstall selectedVM = (IVMInstall) it.next();
365
            IVMInstall selectedVM = (IVMInstall) it.next();
360
361
            // duplicate & add vm
366
            // duplicate & add vm
362
            VMStandin standin = new VMStandin(selectedVM, createUniqueId(selectedVM.getVMInstallType()));
367
            VMStandin standin = new VMStandin(selectedVM, createUniqueId(selectedVM.getVMInstallType()));
363
            standin.setName(generateName(selectedVM.getName()));
368
            standin.setName(generateName(selectedVM.getName()));
364
            AddVMDialog dialog = new AddVMDialog(this, getShell(), JavaRuntime.getVMInstallTypes(), standin);
369
			EditVMInstallWizard wizard = new EditVMInstallWizard(standin, (IVMInstall[]) fVMs.toArray(new IVMInstall[fVMs.size()]));
365
            dialog.setTitle(JREMessages.InstalledJREsBlock_18);
370
			WizardDialog dialog = new VMWizardDialog(getShell(), wizard);
366
            if (dialog.open() != Window.OK) {
371
			if (dialog.open() == Window.OK) {
367
                return;
372
				VMStandin result = wizard.getResult();
368
            }
373
				if (result != null) {
369
            newEntries.add(standin);
374
					// add the new VM
370
            fVMs.add(standin);
375
					fVMs.add(result);
376
					fVMList.refresh();
377
					fVMList.setSelection(new StructuredSelection(result));
378
				}
379
			}
371
        }
380
        }
372
        fVMList.refresh();
381
        fVMList.refresh();
373
        fVMList.setSelection(new StructuredSelection(newEntries.toArray()));
382
        fVMList.setSelection(new StructuredSelection(newEntries.toArray()));
Lines 543-557 Link Here
543
	}
552
	}
544
	
553
	
545
	/**
554
	/**
546
	 * Bring up a dialog that lets the user create a new VM definition.
555
	 * Bring up a wizard that lets the user create a new VM definition.
547
	 */
556
	 */
548
	private void addVM() {
557
	private void addVM() {
549
		AddVMDialog dialog= new AddVMDialog(this, getShell(), JavaRuntime.getVMInstallTypes(), null);
558
		AddVMInstallWizard wizard = new AddVMInstallWizard((IVMInstall[]) fVMs.toArray(new IVMInstall[fVMs.size()]));
550
		dialog.setTitle(JREMessages.InstalledJREsBlock_7); 
559
		WizardDialog dialog = new VMWizardDialog(getShell(), wizard);
551
		if (dialog.open() != Window.OK) {
560
		if (dialog.open() == Window.OK) {
552
			return;
561
			VMStandin result = wizard.getResult();
562
			if (result != null) {
563
				fVMs.add(result);
564
				fVMList.refresh();
565
				fVMList.setSelection(new StructuredSelection(result));
566
			}
553
		}
567
		}
554
		fVMList.refresh();
555
	}
568
	}
556
	
569
	
557
	/**
570
	/**
Lines 580-586 Link Here
580
	 */
593
	 */
581
	private void editVM() {
594
	private void editVM() {
582
		IStructuredSelection selection= (IStructuredSelection)fVMList.getSelection();
595
		IStructuredSelection selection= (IStructuredSelection)fVMList.getSelection();
583
		IVMInstall vm= (IVMInstall)selection.getFirstElement();
596
		VMStandin vm= (VMStandin)selection.getFirstElement();
584
		if (vm == null) {
597
		if (vm == null) {
585
			return;
598
			return;
586
		}
599
		}
Lines 588-600 Link Here
588
			VMDetailsDialog dialog= new VMDetailsDialog(getShell(), vm);
601
			VMDetailsDialog dialog= new VMDetailsDialog(getShell(), vm);
589
			dialog.open();
602
			dialog.open();
590
		} else {
603
		} else {
591
			AddVMDialog dialog= new AddVMDialog(this, getShell(), JavaRuntime.getVMInstallTypes(), vm);
604
			EditVMInstallWizard wizard = new EditVMInstallWizard(vm, (IVMInstall[]) fVMs.toArray(new IVMInstall[fVMs.size()]));
592
			dialog.setTitle(JREMessages.InstalledJREsBlock_8); 
605
			WizardDialog dialog = new VMWizardDialog(getShell(), wizard);
593
			if (dialog.open() != Window.OK) {
606
			if (dialog.open() == Window.OK) {
594
				return;
607
				VMStandin result = wizard.getResult();
608
				if (result != null) {
609
					// replace with the edited VM
610
					int index = fVMs.indexOf(vm);
611
					fVMs.remove(index);
612
					fVMs.add(index, result);
613
					fVMList.refresh();
614
					fVMList.setSelection(new StructuredSelection(result));
615
				}
595
			}
616
			}
596
			fVMList.refresh(vm);
597
		}
617
		}
618
		
619
		
598
	}
620
	}
599
	
621
	
600
	/**
622
	/**
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/MacVMSearch.java (-1 / +1 lines)
Lines 91-97 Link Here
91
		IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
91
		IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
92
		for (int i = 0; i < types.length; i++) {
92
		for (int i = 0; i < types.length; i++) {
93
			IVMInstallType installType = types[i];
93
			IVMInstallType installType = types[i];
94
			if (installType.getId().equals(AddVMDialog.MACOSX_VM_TYPE_ID)) {
94
			if (installType.getId().equals(InstalledJREsBlock.MACOSX_VM_TYPE_ID)) {
95
				return installType;
95
				return installType;
96
			}
96
			}
97
		}
97
		}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/JREMessages.properties (-4 / +4 lines)
Lines 58-74 Link Here
58
JREsPreferencePage_14=Conflicting compliance settings can be changed on the <a>Compiler</a> page.
58
JREsPreferencePage_14=Conflicting compliance settings can be changed on the <a>Compiler</a> page.
59
59
60
addVMDialog_duplicateName=The JRE name is already in use.
60
addVMDialog_duplicateName=The JRE name is already in use.
61
addVMDialog_enterLocation=Enter the location of the JRE.
61
addVMDialog_enterLocation=Enter the home directory of the JRE.
62
addVMDialog_enterName=Enter a name for the JRE.
62
addVMDialog_enterName=Enter a name for the JRE.
63
addVMDialog_jreHome=&JRE location:
63
addVMDialog_jreHome=&JRE home:
64
addVMDialog_jreName=JRE &name:
64
addVMDialog_jreName=JRE &name:
65
addVMDialog_jreType=JRE &type:
65
addVMDialog_jreType=JRE &type:
66
addVMDialog_locationNotExists=The location does not exist.
66
addVMDialog_locationNotExists=The home directory does not exist.
67
addVMDialog_pickJRERootDialog_message=Select the root directory of the JRE installation:
67
addVMDialog_pickJRERootDialog_message=Select the root directory of the JRE installation:
68
AddVMDialog_JRE_system_libraries__1=JRE system libraries:
68
AddVMDialog_JRE_system_libraries__1=JRE system libraries:
69
AddVMDialog_JRE_name_must_be_a_valid_file_name___0__1=JRE name must be a valid file name: {0}
69
AddVMDialog_JRE_name_must_be_a_valid_file_name___0__1=JRE name must be a valid file name: {0}
70
AddVMDialog_21=Definition &File...
70
AddVMDialog_21=Definition &File...
71
AddVMDialog_22=H&ome Directory...
71
AddVMDialog_22=Direct&ory...
72
AddVMDialog_23=Default &VM Arguments:
72
AddVMDialog_23=Default &VM Arguments:
73
73
74
JREsUpdater_0=Save VM Definitions
74
JREsUpdater_0=Save VM Definitions
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java (-659 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.debug.ui.jres;
12
13
14
import java.io.File;
15
import java.io.IOException;
16
import java.net.URL;
17
import java.util.Arrays;
18
import java.util.Comparator;
19
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.ResourcesPlugin;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.Path;
25
import org.eclipse.core.runtime.Platform;
26
import org.eclipse.debug.core.DebugPlugin;
27
import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds;
28
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
29
import org.eclipse.jdt.internal.debug.ui.SWTFactory;
30
import org.eclipse.jdt.internal.debug.ui.StatusInfo;
31
import org.eclipse.jdt.internal.launching.StandardVMType;
32
import org.eclipse.jdt.launching.AbstractVMInstallType;
33
import org.eclipse.jdt.launching.IVMInstall;
34
import org.eclipse.jdt.launching.IVMInstall2;
35
import org.eclipse.jdt.launching.IVMInstallType;
36
import org.eclipse.jdt.launching.VMStandin;
37
import org.eclipse.jface.dialogs.IDialogConstants;
38
import org.eclipse.jface.dialogs.IDialogSettings;
39
import org.eclipse.jface.dialogs.StatusDialog;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.custom.BusyIndicator;
42
import org.eclipse.swt.events.ModifyEvent;
43
import org.eclipse.swt.events.ModifyListener;
44
import org.eclipse.swt.events.SelectionEvent;
45
import org.eclipse.swt.events.SelectionListener;
46
import org.eclipse.swt.graphics.Point;
47
import org.eclipse.swt.layout.GridData;
48
import org.eclipse.swt.layout.GridLayout;
49
import org.eclipse.swt.widgets.Button;
50
import org.eclipse.swt.widgets.Combo;
51
import org.eclipse.swt.widgets.Composite;
52
import org.eclipse.swt.widgets.Control;
53
import org.eclipse.swt.widgets.DirectoryDialog;
54
import org.eclipse.swt.widgets.FileDialog;
55
import org.eclipse.swt.widgets.Shell;
56
import org.eclipse.swt.widgets.Text;
57
import org.eclipse.ui.PlatformUI;
58
59
import com.ibm.icu.text.MessageFormat;
60
61
/**
62
 * Provides the Add VM dialog
63
 */
64
public class AddVMDialog extends StatusDialog {
65
	
66
	/**
67
	 * VM install type id for OSX VMs
68
	 */
69
	public static final String MACOSX_VM_TYPE_ID = "org.eclipse.jdt.internal.launching.macosx.MacOSXType"; //$NON-NLS-1$
70
	
71
	private IAddVMDialogRequestor fRequestor;
72
	private IVMInstall fEditedVM;
73
	private IVMInstallType[] fVMTypes;
74
	private IVMInstallType fSelectedVMType;
75
	private Combo fVMCombo;
76
	private Text fVMName;
77
	private Text fVMArgs;
78
	private Text fJRERoot;
79
	private Button fFileButton;
80
	private VMLibraryBlock fLibraryBlock;
81
// the VM install's javadoc location
82
	private URL fJavadocLocation = null;
83
	private boolean fAutoDetectAttributes = false;
84
	private IStatus[] fStatus;
85
	private int fPrevIndex = -1;
86
		
87
	/**
88
	 * Constructor
89
	 * @param requestor dialog validation requester
90
	 * @param shell the parent shell 
91
	 * @param vmInstallTypes the types of VM installs
92
	 * @param editedVM the editedVM
93
	 */
94
	public AddVMDialog(IAddVMDialogRequestor requestor, Shell shell, IVMInstallType[] vmInstallTypes, IVMInstall editedVM) {
95
		super(shell);
96
		setShellStyle(getShellStyle() | SWT.RESIZE);
97
		fRequestor = requestor;
98
		fStatus = new IStatus[5];
99
		for (int i= 0; i < fStatus.length; i++) {
100
			fStatus[i] = new StatusInfo();
101
		}
102
		fVMTypes = vmInstallTypes;
103
		sortVMTypes();
104
		int typeIndex = 0;
105
		if (Platform.OS_MACOSX.equals(Platform.getOS())) {
106
			// select OSX VM type by default
107
			for (int i = 0; i < fVMTypes.length; i++) {
108
				IVMInstallType type = fVMTypes[i];
109
				if (type.getId().equals(MACOSX_VM_TYPE_ID)) {
110
					typeIndex = i;
111
					break;
112
				}
113
			}
114
		}
115
		fSelectedVMType = editedVM != null ? editedVM.getVMInstallType() : vmInstallTypes[typeIndex];
116
		fEditedVM = editedVM;
117
	//only detect the javadoc location if not already set
118
		fAutoDetectAttributes = fEditedVM == null || fEditedVM.getJavadocLocation() == null;
119
	}
120
121
	/**
122
	 * This method is used to sort the array of VM install types, placing 
123
	 * the 'Standard VM' type first, if it exists
124
	 * 
125
	 * @since 3.3.0
126
	 */
127
	private void sortVMTypes() {
128
		Comparator compare = new Comparator() {
129
			public int compare(Object o1, Object o2) {
130
				if(o1 instanceof IVMInstallType && o2 instanceof IVMInstallType) {
131
					return ((IVMInstallType) o1).getName().compareTo(((IVMInstallType) o2).getName());
132
				}
133
				return 0;
134
			}
135
		};
136
		//first find the 'Standard VM' and set it at position 0
137
		for(int i = 0; i < fVMTypes.length; i++) {
138
			if(fVMTypes[i].getId().equals("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType")) { //$NON-NLS-1$
139
				if(i > 0) {
140
					IVMInstallType tmp = fVMTypes[0];
141
					fVMTypes[0] = fVMTypes[i];
142
					fVMTypes[i] = tmp;
143
					break;
144
				}
145
				else {
146
					break;
147
				}
148
			}
149
		}
150
		if(fVMTypes[0].getId().equals("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType")) { //$NON-NLS-1$
151
			Arrays.sort(fVMTypes, 1, fVMTypes.length, compare);
152
		}
153
		else {
154
			Arrays.sort(fVMTypes, compare);
155
		}
156
	}
157
	
158
	/* (non-Javadoc)
159
	 * @see org.eclipse.jface.dialogs.StatusDialog#configureShell(org.eclipse.swt.widgets.Shell)
160
	 */
161
	protected void configureShell(Shell newShell) {
162
		super.configureShell(newShell);
163
		PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaDebugHelpContextIds.EDIT_JRE_DIALOG);
164
	}		
165
	
166
	/**
167
	 * Returns the VM name from the text control
168
	 * @return
169
	 */
170
	protected String getVMName() {
171
		return fVMName.getText();
172
	}
173
		
174
	/**
175
	 * Returns the installation location as a file from the JRE root text control
176
	 * @return the installation location as a file
177
	 */
178
	protected File getInstallLocation() {
179
		return new File(fJRERoot.getText());
180
	}
181
		
182
	/* (non-Javadoc)
183
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
184
	 */
185
	protected Control createDialogArea(Composite ancestor) {
186
		Composite parent = (Composite)super.createDialogArea(ancestor);
187
		((GridLayout)parent.getLayout()).numColumns = 3;
188
	//VM type
189
		SWTFactory.createLabel(parent, JREMessages.addVMDialog_jreType, 1);
190
		fVMCombo = SWTFactory.createCombo(parent, SWT.READ_ONLY, 2, getVMTypeNames());
191
	// VM location
192
		SWTFactory.createLabel(parent, JREMessages.addVMDialog_jreHome, 1);
193
		fJRERoot = SWTFactory.createSingleText(parent, 2);
194
		Composite buttons = SWTFactory.createComposite(parent, parent.getFont(), 2, 4, GridData.HORIZONTAL_ALIGN_END, 0, 0);
195
		Button folders = SWTFactory.createPushButton(buttons, JREMessages.AddVMDialog_22, null);
196
		GridData data = (GridData) folders.getLayoutData();
197
		data.horizontalAlignment = GridData.END;
198
		fFileButton = SWTFactory.createPushButton(buttons, JREMessages.AddVMDialog_21, null);
199
		data = (GridData) fFileButton.getLayoutData();
200
		data.horizontalAlignment = GridData.END;
201
	//VM name
202
		SWTFactory.createLabel(parent, JREMessages.addVMDialog_jreName, 1);
203
		fVMName = SWTFactory.createSingleText(parent, 2);
204
	//VM arguments
205
		SWTFactory.createLabel(parent, JREMessages.AddVMDialog_23, 1);
206
		fVMArgs = SWTFactory.createSingleText(parent, 2);
207
	//VM libraries block 
208
		SWTFactory.createLabel(parent, JREMessages.AddVMDialog_JRE_system_libraries__1, 3);
209
		fLibraryBlock = new VMLibraryBlock(this);
210
		Control block = fLibraryBlock.createControl(parent);
211
		GridData gd = new GridData(GridData.FILL_BOTH);
212
		gd.horizontalSpan = 3;
213
		block.setLayoutData(gd);
214
	
215
	//initialize the fields
216
		initializeFields();
217
		
218
	//add the listeners now to prevent them from monkeying with initialized settings
219
		fVMCombo.addSelectionListener(new SelectionListener() {
220
			public void widgetDefaultSelected(SelectionEvent e) {}
221
			public void widgetSelected(SelectionEvent e) {
222
				updateVMType();
223
			}
224
		});
225
		fVMName.addModifyListener(new ModifyListener() {
226
			public void modifyText(ModifyEvent e) {
227
				validateVMName();
228
				updateStatusLine();	
229
			}
230
		});
231
		fJRERoot.addModifyListener(new ModifyListener() {
232
			public void modifyText(ModifyEvent e) {
233
				validateJRELocation();
234
				updateStatusLine();
235
			}
236
		});
237
		folders.addSelectionListener(new SelectionListener() {
238
			public void widgetDefaultSelected(SelectionEvent e) {}
239
			public void widgetSelected(SelectionEvent e) {
240
				DirectoryDialog dialog = new DirectoryDialog(getShell());
241
				File file = new File(fJRERoot.getText());
242
				String text = fJRERoot.getText();
243
				if (file.isFile()) {
244
					text = file.getParentFile().getAbsolutePath();
245
				}
246
				dialog.setFilterPath(text);
247
				dialog.setMessage(JREMessages.addVMDialog_pickJRERootDialog_message); 
248
				String newPath = dialog.open();
249
				if (newPath != null) {
250
					fJRERoot.setText(newPath);
251
				}
252
			}
253
		});
254
		fFileButton.addSelectionListener(new SelectionListener() {
255
			public void widgetDefaultSelected(SelectionEvent e) {}
256
			public void widgetSelected(SelectionEvent e) {
257
				FileDialog dialog = new FileDialog(getShell());
258
				dialog.setFilterExtensions(new String[]{"*.ee"}); //$NON-NLS-1$
259
				dialog.setFilterPath(fJRERoot.getText());
260
				String newPath = dialog.open();
261
				if (newPath != null) {
262
					fJRERoot.setText(newPath);
263
				}
264
			}
265
		});		
266
		applyDialogFont(parent);
267
		return parent;
268
	}
269
	
270
	/**
271
	 * Updates the JRE location status and initializes the library block
272
	 */
273
	private void updateVMType() {
274
		int selIndex = fVMCombo.getSelectionIndex();
275
		if (selIndex == fPrevIndex) {
276
			return;
277
		}
278
		fPrevIndex = selIndex;
279
		if (selIndex >= 0 && selIndex < fVMTypes.length) {
280
			fSelectedVMType= fVMTypes[selIndex];
281
		}
282
		validateJRELocation();
283
		fLibraryBlock.initializeFrom(fEditedVM, fSelectedVMType);
284
		updateFileButton();
285
		updateStatusLine();
286
	}	
287
	
288
	/**
289
	 * Updates enabled state of the "Definition File..." button.
290
	 */
291
	private void updateFileButton() {
292
		fFileButton.setEnabled(fSelectedVMType.getId().equals(StandardVMType.ID_STANDARD_VM_TYPE));
293
	}
294
	
295
	/* (non-Javadoc)
296
	 * @see org.eclipse.jface.dialogs.StatusDialog#create()
297
	 */
298
	public void create() {
299
		super.create();
300
		if (fJRERoot.getText().length() == 0) {
301
			fJRERoot.setFocus();
302
		} else {
303
			fVMName.setFocus();
304
		}
305
		selectVMType();  
306
	}
307
	
308
	/**
309
	 * Returns the VM type names
310
	 * @return an array of strings with the names of the applicable VMs
311
	 */
312
	private String[] getVMTypeNames() {
313
		String[] names =  new String[fVMTypes.length];
314
		for (int i = 0; i < fVMTypes.length; i++) {
315
			names[i]= fVMTypes[i].getName();
316
		}
317
		return names;
318
	}
319
	
320
	/**
321
	 * Selects the corresponding VM for fSelectedVMType
322
	 */
323
	private void selectVMType() {
324
		for (int i= 0; i < fVMTypes.length; i++) {
325
			if (fSelectedVMType == fVMTypes[i]) {
326
				if(i < fVMCombo.getItemCount()) {
327
					fVMCombo.select(i);
328
					return;
329
				}
330
			}
331
		}
332
	}
333
	
334
	/**
335
	 * Initialize the dialogs fields
336
	 */
337
	private void initializeFields() {
338
		if (fEditedVM == null) {
339
			fVMName.setText(""); //$NON-NLS-1$
340
			fJRERoot.setText(""); //$NON-NLS-1$
341
			fLibraryBlock.initializeFrom(null, fSelectedVMType);
342
			fVMArgs.setText(""); //$NON-NLS-1$	
343
		} else {
344
			fVMCombo.setEnabled(false);
345
			fVMName.setText(fEditedVM.getName());
346
			fJRERoot.setText(fEditedVM.getInstallLocation().getAbsolutePath());
347
			fLibraryBlock.initializeFrom(fEditedVM, fSelectedVMType);
348
			if (fEditedVM instanceof IVMInstall2) {
349
				IVMInstall2 vm2 = (IVMInstall2) fEditedVM;
350
				String vmArgs = vm2.getVMArgs();
351
				if (vmArgs != null) {
352
					fVMArgs.setText(vmArgs);
353
				}
354
			} else {
355
				String[] vmArgs = fEditedVM.getVMArguments();
356
				if (vmArgs != null) {
357
					StringBuffer buffer = new StringBuffer();
358
					int length= vmArgs.length;
359
					if (length > 0) {
360
						buffer.append(vmArgs[0]);
361
						for (int i = 1; i < length; i++) {
362
							buffer.append(' ').append(vmArgs[i]);
363
						}
364
					}
365
					fVMArgs.setText(buffer.toString());
366
				}				
367
			}
368
		}
369
		updateFileButton();
370
		validateVMName();
371
		updateStatusLine();
372
	}
373
	
374
	/**
375
	 * Validates the JRE location
376
	 * @return the status after validating the JRE location
377
	 */
378
	private IStatus validateJRELocation() {
379
		String locationName = fJRERoot.getText();
380
		IStatus s = null;
381
		File file = null;
382
		if (locationName.length() == 0) {
383
			s = new StatusInfo(IStatus.INFO, JREMessages.addVMDialog_enterLocation); 
384
		} 
385
		else {
386
			file = new File(locationName);
387
			if (!file.exists()) {
388
				s = new StatusInfo(IStatus.ERROR, JREMessages.addVMDialog_locationNotExists); 
389
			} 
390
			else {
391
				final IStatus[] temp = new IStatus[1];
392
				final File tempFile = file; 
393
				Runnable r = new Runnable() {
394
					public void run() {
395
						temp[0] = fSelectedVMType.validateInstallLocation(tempFile);
396
					}
397
				};
398
				BusyIndicator.showWhile(getShell().getDisplay(), r);
399
				s = temp[0];
400
			}
401
		}
402
		if (s.isOK()) {
403
			fLibraryBlock.setHomeDirectory(file);
404
			String name = fVMName.getText();
405
			if (name == null || name.trim().length() == 0) {
406
				// auto-generate VM name
407
				if (file.isFile()) {
408
					String fileName = file.getName();
409
					int index = fileName.lastIndexOf(".ee"); //$NON-NLS-1$
410
					if (index > 0) {
411
						fileName = fileName.substring(0, index);
412
					}
413
					fVMName.setText(fileName);
414
				} else {
415
					try {
416
						String genName = null;
417
						IPath path = new Path(file.getCanonicalPath());
418
						int segs = path.segmentCount();
419
						if (segs == 1) {
420
							genName = path.segment(0);
421
						} 
422
						else if (segs >= 2) {
423
							String last = path.lastSegment();
424
							if ("jre".equalsIgnoreCase(last)) { //$NON-NLS-1$
425
								genName = path.segment(segs - 2);
426
							} 
427
							else {
428
								genName = last;
429
							}
430
						}
431
						if (genName != null) {
432
							fVMName.setText(genName);
433
						}
434
					} catch (IOException e) {}
435
				}
436
			}
437
		} else {
438
			fLibraryBlock.setHomeDirectory(null);
439
		}
440
		fLibraryBlock.restoreDefaultLibraries();
441
		detectJavadocLocation();
442
		fStatus[1] = s;
443
		return s;
444
	}
445
	
446
	/**
447
	 * Auto-detects the default javadoc location
448
	 */
449
	private void detectJavadocLocation() {
450
		if (fAutoDetectAttributes) {
451
			if (fSelectedVMType instanceof AbstractVMInstallType) {
452
				AbstractVMInstallType type = (AbstractVMInstallType)fSelectedVMType;
453
				fJavadocLocation = type.getDefaultJavadocLocation(getInstallLocation());
454
				String args = type.getDefaultVMArguments(getInstallLocation());
455
				if (args != null) {
456
					fVMArgs.setText(args);
457
				}
458
			}
459
		} else {
460
			fJavadocLocation = fEditedVM.getJavadocLocation();
461
		}
462
	}
463
464
	/**
465
	 * Validates the entered name of the VM
466
	 * @return the status of the name validation
467
	 */
468
	private IStatus validateVMName() {
469
		StatusInfo status= new StatusInfo();
470
		String name= fVMName.getText();
471
		if (name == null || name.trim().length() == 0) {
472
			status.setInfo(JREMessages.addVMDialog_enterName); 
473
		} else {
474
			if (fRequestor.isDuplicateName(name) && (fEditedVM == null || !name.equals(fEditedVM.getName()))) {
475
				status.setError(JREMessages.addVMDialog_duplicateName); 
476
			} else {
477
				IStatus s = ResourcesPlugin.getWorkspace().validateName(name, IResource.FILE);
478
				if (!s.isOK()) {
479
					status.setError(MessageFormat.format(JREMessages.AddVMDialog_JRE_name_must_be_a_valid_file_name___0__1, new String[]{s.getMessage()})); 
480
				}
481
			}
482
		}
483
		fStatus[0] = status;
484
		return status;
485
	}
486
	
487
	/**
488
	 * Updates the status line to show/hide messages to the user 
489
	 */
490
	protected void updateStatusLine() {
491
		IStatus max= null;
492
		for (int i = 0; i < fStatus.length; i++) {
493
			IStatus curr = fStatus[i];
494
			if (curr.matches(IStatus.ERROR)) {
495
				updateStatus(curr);
496
				return;
497
			}
498
			if (max == null || curr.getSeverity() > max.getSeverity()) {
499
				max = curr;
500
			}
501
		}
502
		updateStatus(max);
503
	}
504
	
505
	/**
506
	 * Returns the URL for the javadoc location
507
	 * @return the URL for the javadoc location
508
	 */
509
	protected URL getURL() {
510
		return fJavadocLocation;
511
	}
512
	
513
	/* (non-Javadoc)
514
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
515
	 */
516
	protected void okPressed() {
517
		if (fEditedVM == null) {
518
			IVMInstall vm = new VMStandin(fSelectedVMType, createUniqueId(fSelectedVMType));
519
			setFieldValuesToVM(vm);
520
			fRequestor.vmAdded(vm);
521
		} else {
522
			setFieldValuesToVM(fEditedVM);
523
		}
524
		super.okPressed();
525
	}
526
	
527
	/**
528
	 * Creates a unique name for the VMInstallType
529
	 * @param vmType the vm install type
530
	 * @return a unique name
531
	 */
532
	private String createUniqueId(IVMInstallType vmType) {
533
		String id = null;
534
		do {
535
			id = String.valueOf(System.currentTimeMillis());
536
		} while (vmType.findVMInstall(id) != null);
537
		return id;
538
	}
539
	
540
	/**
541
	 * initialize fields to the specified VM
542
	 * @param vm the VM to initialize from
543
	 */
544
	protected void setFieldValuesToVM(IVMInstall vm) {
545
		File dir = new File(fJRERoot.getText());
546
		try {
547
			vm.setInstallLocation(dir.getCanonicalFile());
548
		} 
549
		catch (IOException e) {
550
			vm.setInstallLocation(dir.getAbsoluteFile());
551
		}
552
		vm.setName(fVMName.getText());
553
		vm.setJavadocLocation(getURL());
554
		
555
		String argString = fVMArgs.getText().trim();
556
		if (vm instanceof IVMInstall2) {
557
			IVMInstall2 vm2 = (IVMInstall2) vm;
558
			if (argString != null && argString.length() > 0) {
559
				vm2.setVMArgs(argString);			
560
			} 
561
			else {
562
				vm2.setVMArgs(null);
563
			}
564
		} 
565
		else {
566
			if (argString != null && argString.length() > 0) {
567
				vm.setVMArguments(DebugPlugin.parseArguments(argString));			
568
			} 
569
			else {
570
				vm.setVMArguments(null);
571
			}			
572
		}
573
		fLibraryBlock.performApply(vm);
574
	}
575
	
576
	/**
577
	 * returns an absolute file or an empty file if the path is either null or zero length
578
	 * @param path the path to the file
579
	 * @return a new file
580
	 */
581
	protected File getAbsoluteFileOrEmpty(String path) {
582
		if (path == null || path.length() == 0) {
583
			return new File(""); //$NON-NLS-1$
584
		}
585
		return new File(path).getAbsoluteFile();
586
	}
587
	
588
	/**
589
	 * @return the status of the system library 
590
	 */
591
	protected IStatus getSystemLibraryStatus() {
592
		return fStatus[3];
593
	}
594
	
595
	/**
596
	 * Allows the VM page to set the status of the current system library
597
	 * @param status the specified status
598
	 */
599
	protected void setSystemLibraryStatus(IStatus status) {
600
		fStatus[3] = status;
601
	}
602
	
603
	/**
604
	 * Updates the status of the OK button to reflect the given status.
605
	 * Subclasses may override this method to update additional buttons.
606
	 * @param status the status.
607
	 */
608
	protected void updateButtonsEnableState(IStatus status) {
609
		Button ok = getButton(IDialogConstants.OK_ID);
610
		if (ok != null && !ok.isDisposed())
611
			ok.setEnabled(status.getSeverity() == IStatus.OK);
612
	}	
613
	
614
	/**
615
	 * Returns the name of the section that this dialog stores its settings in
616
	 * 
617
	 * @return String
618
	 */
619
	protected String getDialogSettingsSectionName() {
620
		return "ADD_VM_DIALOG_SECTION"; //$NON-NLS-1$
621
	}
622
	
623
	 /* (non-Javadoc)
624
     * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
625
     */
626
    protected IDialogSettings getDialogBoundsSettings() {
627
    	 IDialogSettings settings = JDIDebugUIPlugin.getDefault().getDialogSettings();
628
         IDialogSettings section = settings.getSection(getDialogSettingsSectionName());
629
         if (section == null) {
630
             section = settings.addNewSection(getDialogSettingsSectionName());
631
         } 
632
         return section;
633
    }
634
    
635
	/* (non-Javadoc)
636
	 * @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
637
	 */
638
	protected Point getInitialSize() {
639
		IDialogSettings settings = getDialogBoundsSettings();
640
		if(settings != null) {
641
			try {
642
				int width = settings.getInt("DIALOG_WIDTH"); //$NON-NLS-1$
643
				int height = settings.getInt("DIALOG_HEIGHT"); //$NON-NLS-1$
644
				if(width > 0 & height > 0) {
645
					return new Point(width, height);
646
				}
647
			}
648
			catch (NumberFormatException nfe) {
649
				return new Point(500, 570);
650
			}
651
		}
652
		return new Point(500, 570);
653
	}
654
655
	protected void setButtonLayoutData(Button button) {
656
		super.setButtonLayoutData(button);
657
	}
658
    
659
}
(-)plugin.xml (+8 lines)
Lines 5-10 Link Here
5
    
5
    
6
<!-- Extensions Points -->
6
<!-- Extensions Points -->
7
   <extension-point id="vmInstallTypePage" name="%vmInstallTypePage" schema="schema/vmInstallTypePage.exsd"/>
7
   <extension-point id="vmInstallTypePage" name="%vmInstallTypePage" schema="schema/vmInstallTypePage.exsd"/>
8
   <extension-point id="vmInstallPages" name="VM Install Page" schema="schema/vmInstallPages.exsd"/>
8
9
9
<!-- Extensions -->
10
<!-- Extensions -->
10
   <extension
11
   <extension
Lines 3369-3372 Link Here
3369
          targetId="org.eclipse.jdt.ui.javaCode">
3370
          targetId="org.eclipse.jdt.ui.javaCode">
3370
    </hyperlinkDetector>
3371
    </hyperlinkDetector>
3371
 </extension>
3372
 </extension>
3373
 <extension
3374
       point="org.eclipse.jdt.debug.ui.vmInstallPages">
3375
    <vmInstallPage
3376
          class="org.eclipse.jdt.internal.debug.ui.jres.EEVMPage"
3377
          vmInstallType="org.eclipse.jdt.launching.EEVMType">
3378
    </vmInstallPage>
3379
 </extension>
3372
</plugin>
3380
</plugin>
(-)ui/org/eclipse/jdt/debug/ui/IJavaDebugUIConstants.java (+8 lines)
Lines 32-37 Link Here
32
	public static final String EXTENSION_POINT_VM_INSTALL_TYPE_PAGE = "vmInstallTypePage"; //$NON-NLS-1$
32
	public static final String EXTENSION_POINT_VM_INSTALL_TYPE_PAGE = "vmInstallTypePage"; //$NON-NLS-1$
33
33
34
	/**
34
	/**
35
	 * Extension point identifier for contributions of a wizard page that for a VMInstallType
36
	 * (value <code>"vmInstallPages"</code>).
37
	 * 
38
	 * @since 3.4
39
	 */
40
	public static final String EXTENSION_POINT_VM_INSTALL_PAGES = "vmInstallPages"; //$NON-NLS-1$
41
	
42
	/**
35
	 * Display view identifier (value <code>"org.eclipse.jdt.debug.ui.DisplayView"</code>).
43
	 * Display view identifier (value <code>"org.eclipse.jdt.debug.ui.DisplayView"</code>).
36
	 */
44
	 */
37
	public static final String ID_DISPLAY_VIEW= PLUGIN_ID + ".DisplayView"; //$NON-NLS-1$
45
	public static final String ID_DISPLAY_VIEW= PLUGIN_ID + ".DisplayView"; //$NON-NLS-1$
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMInstallWizard.java (+77 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.debug.ui.jres;
12
13
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
14
import org.eclipse.jdt.launching.IVMInstall;
15
import org.eclipse.jdt.launching.VMStandin;
16
import org.eclipse.jface.wizard.IWizardPage;
17
18
/**
19
 * @since 3.4
20
 */
21
public class AddVMInstallWizard extends VMInstallWizard {
22
	
23
	private IWizardPage fTypePage = null;
24
	
25
	private VMStandin fResult = null;
26
27
	/**
28
	 * Constructs a wizard to add a new VM install.
29
	 * 
30
	 * @param currentInstalls curretly existing VMs, used for name validation
31
	 */
32
	public AddVMInstallWizard(IVMInstall[] currentInstalls) {
33
		super(null, currentInstalls);
34
		setForcePreviousAndNextButtons(true);
35
		setWindowTitle("Add JRE");
36
	}
37
38
	/* (non-Javadoc)
39
	 * @see org.eclipse.jface.wizard.Wizard#addPages()
40
	 */
41
	public void addPages() {
42
		fTypePage = new VMTypePage();
43
		addPage(fTypePage);
44
	}
45
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.jdt.internal.debug.ui.jres.VMInstallWizard#getResult()
48
	 */
49
	protected VMStandin getResult() {
50
		return fResult;
51
	}
52
53
	/* (non-Javadoc)
54
	 * @see org.eclipse.jdt.internal.debug.ui.jres.VMInstallWizard#canFinish()
55
	 */
56
	public boolean canFinish() {
57
		IWizardPage currentPage = getContainer().getCurrentPage();
58
		return currentPage != fTypePage && super.canFinish() && currentPage.isPageComplete();
59
	}
60
61
	/* (non-Javadoc)
62
	 * @see org.eclipse.jdt.internal.debug.ui.jres.VMInstallWizard#performFinish()
63
	 */
64
	public boolean performFinish() {
65
		IWizardPage currentPage = getContainer().getCurrentPage();
66
		if (currentPage instanceof AbstractVMInstallPage) {
67
			AbstractVMInstallPage page = (AbstractVMInstallPage) currentPage;
68
			boolean finish = page.finish();
69
			fResult = page.getSelection();
70
			return finish;
71
		}
72
		return false;
73
	}
74
75
	
76
	
77
}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/VMTypePage.java (+202 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.debug.ui.jres;
12
13
import java.util.HashSet;
14
import java.util.Iterator;
15
import java.util.Set;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.core.runtime.IExtensionPoint;
20
import org.eclipse.core.runtime.Platform;
21
import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
22
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
23
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
24
import org.eclipse.jdt.internal.debug.ui.JavaDebugImages;
25
import org.eclipse.jdt.internal.debug.ui.SWTFactory;
26
import org.eclipse.jdt.internal.launching.StandardVMType;
27
import org.eclipse.jdt.launching.IVMInstallType;
28
import org.eclipse.jdt.launching.JavaRuntime;
29
import org.eclipse.jdt.launching.VMStandin;
30
import org.eclipse.jface.util.IPropertyChangeListener;
31
import org.eclipse.jface.viewers.ArrayContentProvider;
32
import org.eclipse.jface.viewers.CheckStateChangedEvent;
33
import org.eclipse.jface.viewers.CheckboxTableViewer;
34
import org.eclipse.jface.viewers.ICheckStateListener;
35
import org.eclipse.jface.viewers.LabelProvider;
36
import org.eclipse.jface.viewers.ViewerComparator;
37
import org.eclipse.jface.wizard.IWizardPage;
38
import org.eclipse.jface.wizard.WizardPage;
39
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.graphics.Image;
41
import org.eclipse.swt.layout.GridData;
42
import org.eclipse.swt.layout.GridLayout;
43
import org.eclipse.swt.widgets.Composite;
44
45
/**
46
 * Wizard page used to select a VM type.
47
 * 
48
 * @since 3.4
49
 */
50
public class VMTypePage extends WizardPage {
51
	
52
	private CheckboxTableViewer fTypesViewer;
53
	
54
	private AbstractVMInstallPage fStandardPage;
55
	
56
	private AbstractVMInstallPage fNextPage;
57
	
58
	/**
59
	 * Keep track of pages created, so we can dispose of them.
60
	 */
61
	private Set fPages = new HashSet();
62
	
63
	/**
64
	 * Label provider for VM types
65
	 */
66
	private class TypeLabelProvider extends LabelProvider {
67
68
		/* (non-Javadoc)
69
		 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
70
		 */
71
		public String getText(Object element) {
72
			if (element instanceof IVMInstallType) {
73
				IVMInstallType type = (IVMInstallType) element;
74
				return type.getName();
75
			}
76
			return super.getText(element);
77
		}
78
		
79
	}
80
	
81
	/**
82
	 * Constructs a VM type selection page
83
	 */
84
	public VMTypePage() {
85
		super("Select JRE Type");
86
		setDescription("Select the type of installed JRE to add.");
87
		setTitle("Add Installed JRE");
88
	}
89
	
90
	
91
	/* (non-Javadoc)
92
	 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
93
	 */
94
	public void dispose() {
95
		super.dispose();
96
		Iterator iterator = fPages.iterator();
97
		while (iterator.hasNext()) {
98
			AbstractVMInstallPage page = (AbstractVMInstallPage)iterator.next();
99
			page.removePropertyChangeListener((IPropertyChangeListener) getWizard());
100
			page.dispose();
101
		}
102
	}
103
104
105
	/* (non-Javadoc)
106
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
107
	 */
108
	public void createControl(Composite parent) {
109
		Composite composite = new Composite(parent, SWT.NONE);
110
		GridLayout layout = new GridLayout();
111
		layout.numColumns = 1;
112
		composite.setLayout(layout);
113
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
114
		
115
		SWTFactory.createLabel(composite, "Installed JRE &Types:", 1);
116
		
117
		fTypesViewer = CheckboxTableViewer.newCheckList(composite, SWT.SINGLE | SWT.BORDER);
118
		GridData data = new GridData(GridData.FILL_BOTH);
119
        data.heightHint = 250;
120
        data.widthHint = 300;
121
        fTypesViewer.getTable().setLayoutData(data);
122
        fTypesViewer.setContentProvider(new ArrayContentProvider());
123
        fTypesViewer.setLabelProvider(new TypeLabelProvider());
124
		fTypesViewer.setComparator(new ViewerComparator());
125
		fTypesViewer.addCheckStateListener(new ICheckStateListener() {
126
			public void checkStateChanged(CheckStateChangedEvent event) {
127
				if (event.getChecked()) {
128
					// only check one element
129
					fTypesViewer.setCheckedElements(new Object[]{event.getElement()});
130
					setPageComplete(true);
131
					updateNextPage();
132
				} else {
133
					setPageComplete(false);
134
				}
135
			}
136
		});
137
		fTypesViewer.setInput(JavaRuntime.getVMInstallTypes());
138
		setControl(composite);
139
		
140
		fStandardPage = new StandardVMPage();
141
		fStandardPage.setWizard(getWizard());
142
		fNextPage = fStandardPage;
143
		fTypesViewer.setChecked(JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE), true);
144
		updateNextPage();
145
	}
146
	
147
	/* (non-Javadoc)
148
	 * @see org.eclipse.jface.dialogs.IDialogPage#getImage()
149
	 */
150
	public Image getImage() {
151
		return JavaDebugImages.get(JavaDebugImages.IMG_WIZBAN_LIBRARY);
152
	}	
153
	
154
	/* (non-Javadoc)
155
	 * @see org.eclipse.jface.wizard.WizardPage#getNextPage()
156
	 */
157
	public IWizardPage getNextPage() {
158
		return fNextPage;
159
	}
160
	
161
	private void updateNextPage() {
162
		if (isPageComplete()) {
163
			Object[] checkedElements = fTypesViewer.getCheckedElements();
164
			if (checkedElements.length == 1) {
165
				IVMInstallType installType = (IVMInstallType)checkedElements[0];
166
				AbstractVMInstallPage page = getPage(installType);
167
				page.addPropertyChangeListener((IPropertyChangeListener) getWizard());
168
				VMStandin standin = new VMStandin(installType, StandardVMPage.createUniqueId(installType));
169
				standin.setName("");
170
				page.setSelection(standin);
171
				fNextPage = page;
172
				fPages.add(page);
173
			}
174
		}		
175
	}
176
	
177
	/**
178
	 * Returns a page to use for editing a VM install type
179
	 * 
180
	 * @param type
181
	 * @return
182
	 */
183
	private AbstractVMInstallPage getPage(IVMInstallType type) {
184
		IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(JDIDebugUIPlugin.getUniqueIdentifier(), IJavaDebugUIConstants.EXTENSION_POINT_VM_INSTALL_PAGES);
185
		IConfigurationElement[] infos= extensionPoint.getConfigurationElements();
186
		for (int i = 0; i < infos.length; i++) {
187
			IConfigurationElement element = infos[i];
188
			String id = element.getAttribute("vmInstallType"); //$NON-NLS-1$
189
			if (type.getId().equals(id)) {
190
				try {
191
					AbstractVMInstallPage page = (AbstractVMInstallPage) element.createExecutableExtension("class");
192
					page.setWizard(getWizard());
193
					return page;
194
				} catch (CoreException e) {
195
					JDIDebugUIPlugin.log(e);
196
				}
197
			}
198
		}
199
		return fStandardPage;
200
	}
201
202
}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/StandardVMPage.java (+423 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.debug.ui.jres;
12
13
import java.io.File;
14
import java.io.IOException;
15
import java.net.URL;
16
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Path;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.debug.core.DebugPlugin;
22
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
23
import org.eclipse.jdt.internal.debug.ui.JavaDebugImages;
24
import org.eclipse.jdt.internal.debug.ui.SWTFactory;
25
import org.eclipse.jdt.internal.debug.ui.StatusInfo;
26
import org.eclipse.jdt.launching.AbstractVMInstallType;
27
import org.eclipse.jdt.launching.IVMInstall;
28
import org.eclipse.jdt.launching.IVMInstall2;
29
import org.eclipse.jdt.launching.IVMInstallType;
30
import org.eclipse.jdt.launching.VMStandin;
31
import org.eclipse.jface.dialogs.Dialog;
32
import org.eclipse.jface.dialogs.IMessageProvider;
33
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.custom.BusyIndicator;
35
import org.eclipse.swt.events.ModifyEvent;
36
import org.eclipse.swt.events.ModifyListener;
37
import org.eclipse.swt.events.SelectionEvent;
38
import org.eclipse.swt.events.SelectionListener;
39
import org.eclipse.swt.graphics.Image;
40
import org.eclipse.swt.layout.GridData;
41
import org.eclipse.swt.layout.GridLayout;
42
import org.eclipse.swt.widgets.Button;
43
import org.eclipse.swt.widgets.Composite;
44
import org.eclipse.swt.widgets.Control;
45
import org.eclipse.swt.widgets.DirectoryDialog;
46
import org.eclipse.swt.widgets.Text;
47
48
/**
49
 * Page used to edit a standard VM.
50
 * 
51
 * @since 3.4
52
 */
53
public class StandardVMPage extends AbstractVMInstallPage {
54
	
55
	// VM being edited or created
56
	private VMStandin fVM;
57
	private Text fVMName;
58
	private Text fVMArgs;
59
	private Text fJRERoot;
60
	private VMLibraryBlock fLibraryBlock;
61
// the VM install's javadoc location
62
	private URL fJavadocLocation = null;
63
	private boolean fAutoDetectAttributes = false;
64
	private IStatus[] fFieldStatus = new IStatus[1];
65
	
66
	/**
67
	 * 
68
	 */
69
	public StandardVMPage() {
70
		super("Add Standard VM");
71
		for (int i = 0; i < fFieldStatus.length; i++) {
72
			fFieldStatus[i] = Status.OK_STATUS;
73
		}
74
	}
75
	
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.jface.dialogs.IDialogPage#getImage()
78
	 */
79
	public Image getImage() {
80
		return JavaDebugImages.get(JavaDebugImages.IMG_WIZBAN_LIBRARY);
81
	}	
82
83
	/* (non-Javadoc)
84
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
85
	 */
86
	public void createControl(Composite p) {
87
		// create a composite with standard margins and spacing
88
		Composite composite = new Composite(p, SWT.NONE);
89
		GridLayout layout = new GridLayout();
90
		layout.numColumns = 3;
91
		composite.setLayout(layout);
92
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
93
		
94
	// VM location
95
		SWTFactory.createLabel(composite, JREMessages.addVMDialog_jreHome, 1);
96
		fJRERoot = SWTFactory.createSingleText(composite, 1);
97
		Button folders = SWTFactory.createPushButton(composite, JREMessages.AddVMDialog_22, null);
98
		GridData data = (GridData) folders.getLayoutData();
99
		data.horizontalAlignment = GridData.END;
100
	//VM name
101
		SWTFactory.createLabel(composite, JREMessages.addVMDialog_jreName, 1);
102
		fVMName = SWTFactory.createSingleText(composite, 2);
103
	//VM arguments
104
		SWTFactory.createLabel(composite, JREMessages.AddVMDialog_23, 1);
105
		fVMArgs = SWTFactory.createSingleText(composite, 2);
106
	//VM libraries block 
107
		SWTFactory.createLabel(composite, JREMessages.AddVMDialog_JRE_system_libraries__1, 3);
108
		fLibraryBlock = new VMLibraryBlock();
109
		fLibraryBlock.setWizard(getWizard());
110
		fLibraryBlock.createControl(composite);
111
		Control libControl = fLibraryBlock.getControl();
112
		GridData gd = new GridData(GridData.FILL_BOTH);
113
		gd.horizontalSpan = 3;
114
		libControl.setLayoutData(gd);
115
		
116
	
117
	//add the listeners now to prevent them from monkeying with initialized settings
118
		fVMName.addModifyListener(new ModifyListener() {
119
			public void modifyText(ModifyEvent e) {
120
				validateVMName();
121
			}
122
		});
123
		fJRERoot.addModifyListener(new ModifyListener() {
124
			public void modifyText(ModifyEvent e) {
125
				validateJRELocation();
126
			}
127
		});
128
		folders.addSelectionListener(new SelectionListener() {
129
			public void widgetDefaultSelected(SelectionEvent e) {}
130
			public void widgetSelected(SelectionEvent e) {
131
				DirectoryDialog dialog = new DirectoryDialog(getShell());
132
				File file = new File(fJRERoot.getText());
133
				String text = fJRERoot.getText();
134
				if (file.isFile()) {
135
					text = file.getParentFile().getAbsolutePath();
136
				}
137
				dialog.setFilterPath(text);
138
				dialog.setMessage(JREMessages.addVMDialog_pickJRERootDialog_message); 
139
				String newPath = dialog.open();
140
				if (newPath != null) {
141
					fJRERoot.setText(newPath);
142
				}
143
			}
144
		});
145
		Dialog.applyDialogFont(composite);
146
		setControl(composite);
147
		initializeFields();
148
	}	
149
	
150
	/**
151
	 * Validates the JRE location
152
	 * @return the status after validating the JRE location
153
	 */
154
	private void validateJRELocation() {
155
		String locationName = fJRERoot.getText();
156
		IStatus s = null;
157
		File file = null;
158
		if (locationName.length() == 0) {
159
			s = new StatusInfo(IStatus.INFO, JREMessages.addVMDialog_enterLocation); 
160
		} 
161
		else {
162
			file = new File(locationName);
163
			if (!file.exists()) {
164
				s = new StatusInfo(IStatus.ERROR, JREMessages.addVMDialog_locationNotExists); 
165
			} 
166
			else {
167
				final IStatus[] temp = new IStatus[1];
168
				final File tempFile = file; 
169
				Runnable r = new Runnable() {
170
					public void run() {
171
						temp[0] = fVM.getVMInstallType().validateInstallLocation(tempFile);
172
					}
173
				};
174
				BusyIndicator.showWhile(getShell().getDisplay(), r);
175
				s = temp[0];
176
			}
177
		}
178
		if (file != null) {
179
			fVM.setInstallLocation(file);
180
		}
181
		if (s.isOK()) {
182
			String name = fVMName.getText();
183
			if (name == null || name.trim().length() == 0) {
184
				// auto-generate VM name
185
				if (file.isFile()) {
186
					String fileName = file.getName();
187
					int index = fileName.lastIndexOf(".ee"); //$NON-NLS-1$
188
					if (index > 0) {
189
						fileName = fileName.substring(0, index);
190
					}
191
					fVMName.setText(fileName);
192
				} else {
193
					try {
194
						String genName = null;
195
						IPath path = new Path(file.getCanonicalPath());
196
						int segs = path.segmentCount();
197
						if (segs == 1) {
198
							genName = path.segment(0);
199
						} 
200
						else if (segs >= 2) {
201
							String last = path.lastSegment();
202
							if ("jre".equalsIgnoreCase(last)) { //$NON-NLS-1$
203
								genName = path.segment(segs - 2);
204
							} 
205
							else {
206
								genName = last;
207
							}
208
						}
209
						if (genName != null) {
210
							fVMName.setText(genName);
211
						}
212
					} catch (IOException e) {}
213
				}
214
			}
215
		}
216
		detectJavadocLocation();
217
		setJRELocationStatus(s);
218
		fLibraryBlock.setSelection(fVM);
219
		updatePageStatus();
220
	}
221
	
222
	/**
223
	 * Auto-detects the default javadoc location
224
	 */
225
	private void detectJavadocLocation() {
226
		if (fAutoDetectAttributes) {
227
			IVMInstallType type = fVM.getVMInstallType();
228
			if (type instanceof AbstractVMInstallType) {
229
				AbstractVMInstallType atype = (AbstractVMInstallType)type;
230
				fJavadocLocation = atype.getDefaultJavadocLocation(getInstallLocation());
231
				String args = atype.getDefaultVMArguments(getInstallLocation());
232
				if (args != null) {
233
					fVMArgs.setText(args);
234
				}
235
			}
236
		} else {
237
			fJavadocLocation = fVM.getJavadocLocation();
238
		}
239
	}
240
	
241
	/**
242
	 * Returns the installation location as a file from the JRE root text control
243
	 * @return the installation location as a file
244
	 */
245
	protected File getInstallLocation() {
246
		return new File(fJRERoot.getText());
247
	}	
248
249
	/**
250
	 * Validates the entered name of the VM
251
	 * @return the status of the name validation
252
	 */
253
	private void validateVMName() {
254
		fireNameChange(fVMName.getText());
255
	}
256
	
257
	/* (non-Javadoc)
258
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#finish()
259
	 */
260
	public boolean finish() {
261
		setFieldValuesToVM(fVM);
262
		fLibraryBlock.finish();
263
		return true;
264
	}
265
266
	/* (non-Javadoc)
267
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#getSelection()
268
	 */
269
	public VMStandin getSelection() {
270
		return fVM;
271
	}
272
	
273
	/* (non-Javadoc)
274
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#setSelection(org.eclipse.jdt.launching.VMStandin)
275
	 */
276
	public void setSelection(VMStandin vm) {
277
		super.setSelection(vm);
278
		fVM = vm;
279
		fAutoDetectAttributes = vm.getJavadocLocation() == null;
280
		setTitle("Define Installed JRE");
281
		setDescription("Specify attributes for an installed JRE");
282
	}
283
	
284
	/**
285
	 * initialize fields to the specified VM
286
	 * @param vm the VM to initialize from
287
	 */
288
	protected void setFieldValuesToVM(IVMInstall vm) {
289
		File dir = new File(fJRERoot.getText());
290
		try {
291
			vm.setInstallLocation(dir.getCanonicalFile());
292
		} 
293
		catch (IOException e) {
294
			vm.setInstallLocation(dir.getAbsoluteFile());
295
		}
296
		vm.setName(fVMName.getText());
297
		vm.setJavadocLocation(getURL());
298
		
299
		String argString = fVMArgs.getText().trim();
300
		if (vm instanceof IVMInstall2) {
301
			IVMInstall2 vm2 = (IVMInstall2) vm;
302
			if (argString != null && argString.length() > 0) {
303
				vm2.setVMArgs(argString);			
304
			} 
305
			else {
306
				vm2.setVMArgs(null);
307
			}
308
		} 
309
		else {
310
			if (argString != null && argString.length() > 0) {
311
				vm.setVMArguments(DebugPlugin.parseArguments(argString));			
312
			} 
313
			else {
314
				vm.setVMArguments(null);
315
			}			
316
		}
317
	}
318
	
319
	/**
320
	 * Returns the URL for the javadoc location
321
	 * @return the URL for the javadoc location
322
	 */
323
	protected URL getURL() {
324
		return fJavadocLocation;
325
	}
326
	
327
	/**
328
	 * Creates a unique name for the VMInstallType
329
	 * @param vmType the vm install type
330
	 * @return a unique name
331
	 */
332
	protected static String createUniqueId(IVMInstallType vmType) {
333
		String id = null;
334
		do {
335
			id = String.valueOf(System.currentTimeMillis());
336
		} while (vmType.findVMInstall(id) != null);
337
		return id;
338
	}	
339
	
340
	/**
341
	 * Initialize the dialogs fields
342
	 */
343
	private void initializeFields() {
344
		fLibraryBlock.setSelection(fVM);
345
		fVMName.setText(fVM.getName());
346
		File installLocation = fVM.getInstallLocation();
347
		if (installLocation != null) {
348
			fJRERoot.setText(installLocation.getAbsolutePath());
349
		}
350
		if (fVM instanceof IVMInstall2) {
351
			IVMInstall2 vm2 = (IVMInstall2) fVM;
352
			String vmArgs = vm2.getVMArgs();
353
			if (vmArgs != null) {
354
				fVMArgs.setText(vmArgs);
355
			}
356
		} else {
357
			String[] vmArgs = fVM.getVMArguments();
358
			if (vmArgs != null) {
359
				StringBuffer buffer = new StringBuffer();
360
				int length= vmArgs.length;
361
				if (length > 0) {
362
					buffer.append(vmArgs[0]);
363
					for (int i = 1; i < length; i++) {
364
						buffer.append(' ').append(vmArgs[i]);
365
					}
366
				}
367
				fVMArgs.setText(buffer.toString());
368
			}				
369
		}
370
		validateVMName();
371
		validateJRELocation();
372
	}	
373
	
374
	/**
375
	 * Sets the status of the JRE location field.
376
	 * 
377
	 * @param status JRE location status
378
	 */
379
	private void setJRELocationStatus(IStatus status) {
380
		fFieldStatus[0] = status;
381
	}
382
	
383
	private void updatePageStatus() {
384
		IStatus max = Status.OK_STATUS;
385
		for (int i = 0; i < fFieldStatus.length; i++) {
386
			IStatus status = fFieldStatus[i];
387
			if (status.getSeverity() > max.getSeverity()) {
388
				max = status;
389
			}
390
		}
391
		if (max.isOK()) {
392
			setMessage(null, IMessageProvider.NONE);
393
			setPageComplete(true);
394
		} else {
395
			setStatusMessage(max);
396
			setPageComplete(false);
397
		}
398
	}
399
400
	/* (non-Javadoc)
401
	 * @see org.eclipse.jface.dialogs.DialogPage#getErrorMessage()
402
	 */
403
	public String getErrorMessage() {
404
		String message = super.getErrorMessage();
405
		if (message == null) {
406
			return fLibraryBlock.getErrorMessage();
407
		}
408
		return message;
409
	}
410
411
	/* (non-Javadoc)
412
	 * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
413
	 */
414
	public boolean isPageComplete() {
415
		boolean complete = super.isPageComplete();
416
		if (complete) {
417
			return fLibraryBlock.isPageComplete();
418
		}
419
		return complete;
420
	}
421
	
422
	
423
}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/VMInstallWizard.java (+130 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.debug.ui.jres;
12
13
import org.eclipse.core.resources.IResource;
14
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.Status;
17
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
18
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
19
import org.eclipse.jdt.launching.IVMInstall;
20
import org.eclipse.jdt.launching.VMStandin;
21
import org.eclipse.jface.util.IPropertyChangeListener;
22
import org.eclipse.jface.util.PropertyChangeEvent;
23
import org.eclipse.jface.wizard.Wizard;
24
25
import com.ibm.icu.text.MessageFormat;
26
27
/**
28
 * 
29
 */
30
public abstract class VMInstallWizard extends Wizard implements IPropertyChangeListener {
31
	
32
	private IStatus fNameStatus = Status.OK_STATUS;
33
	
34
	private VMStandin fEditVM;
35
	private IVMInstall[] fInstalls;
36
	
37
	/**
38
	 * Constructs a new wizard to add/edit a vm install.
39
	 * 
40
	 * @param editVM the VM being edited, or <code>null</code> if none
41
	 * @param currentInstalls current VM installs used to validate name changes
42
	 */
43
	public VMInstallWizard(VMStandin editVM, IVMInstall[] currentInstalls) {
44
		fEditVM = editVM;
45
		fInstalls = currentInstalls;
46
	}
47
	
48
	/**
49
	 * Returns the VM to edit, or <code>null</code> if creating a VM
50
	 * 
51
	 * @return vm to edit or <code>null</code>
52
	 */
53
	protected VMStandin getVMInstall() {
54
		return fEditVM;
55
	}
56
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
59
	 */
60
	public void propertyChange(PropertyChangeEvent event) {
61
		if (AbstractVMInstallPage.P_JRE_NAME.equals(event.getProperty())) {
62
			fNameStatus = Status.OK_STATUS;
63
			String name = (String) event.getNewValue();
64
			if (name == null || name.trim().length() == 0) {
65
				fNameStatus = new Status(IStatus.INFO, JDIDebugUIPlugin.getUniqueIdentifier(), JREMessages.addVMDialog_enterName);
66
			} else {
67
				if (isDuplicateName(name)) {
68
					fNameStatus = new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), JREMessages.addVMDialog_duplicateName); 
69
				} else {
70
					IStatus s = ResourcesPlugin.getWorkspace().validateName(name, IResource.FILE);
71
					if (!s.isOK()) {
72
						fNameStatus = new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), MessageFormat.format(JREMessages.AddVMDialog_JRE_name_must_be_a_valid_file_name___0__1, new String[]{s.getMessage()})); 
73
					}
74
				}
75
			}
76
		}	
77
		getContainer().updateMessage();
78
		getContainer().updateButtons();
79
	}
80
	
81
	/**
82
	 * Returns whether the name is already in use by an existing VM
83
	 * 
84
	 * @param name new name
85
	 * @return whether the name is already in use
86
	 */
87
	private boolean isDuplicateName(String name) {
88
		for (int i = 0; i < fInstalls.length; i++) {
89
			IVMInstall vm = fInstalls[i];
90
			if (name.equals(vm.getName())) {
91
				// don't consider VM being edited
92
				if (!vm.equals(fEditVM)) {
93
					return true;
94
				}
95
			}
96
		}
97
		return false;
98
	}
99
100
	/**
101
	 * Returns a status describing the status of the current name of the VM being edited/created.
102
	 * 
103
	 * @return status
104
	 */
105
	protected IStatus getNameStatus() {
106
		return fNameStatus;
107
	}
108
109
	/* (non-Javadoc)
110
	 * @see org.eclipse.jface.wizard.Wizard#canFinish()
111
	 */
112
	public boolean canFinish() {
113
		return getNameStatus().isOK() && super.canFinish();
114
	}
115
	
116
	/**
117
	 * Returns the resulting VM after edit or creation or <code>null</code> if none.
118
	 * 
119
	 * @return resulting VM
120
	 */
121
	protected abstract VMStandin getResult();
122
123
	/* (non-Javadoc)
124
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
125
	 */
126
	public boolean performFinish() {
127
		return getResult() != null;
128
	}
129
130
}
(-)ui/org/eclipse/jdt/debug/ui/launchConfigurations/AbstractVMInstallPage.java (+175 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.debug.ui.launchConfigurations;
12
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.core.runtime.ListenerList;
15
import org.eclipse.jdt.launching.VMStandin;
16
import org.eclipse.jface.dialogs.IMessageProvider;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.jface.wizard.IWizardPage;
21
import org.eclipse.jface.wizard.WizardPage;
22
23
/**
24
 * A wizard page used to edit the attributes of an installed JRE. A page is 
25
 * provided by JDT to edit standard JREs, but clients may contribute a custom
26
 * page for a VM install type if required.
27
 * 
28
 * @since 3.4
29
 */
30
public abstract class AbstractVMInstallPage extends WizardPage {
31
	
32
	/**
33
     * Property name constant (value <code>"org.eclipse.jdt.debug.ui.jre.name"</code>)
34
     * for a JRE's name.
35
	 */
36
	public static final String P_JRE_NAME = "org.eclipse.jdt.debug.ui.jre.name"; //$NON-NLS-1$	
37
	
38
	/**
39
	 * Name of the original VM being edited, or <code>null</code> if none.
40
	 */
41
	private String fOriginalName = null;
42
	
43
	/**
44
	 * Property change listeners
45
	 */
46
	private ListenerList fListeners = new ListenerList();
47
		
48
	/**
49
	 * Constructs a new page with the given page name.
50
	 * 
51
	 * @param pageName the name of the page
52
	 */
53
	protected AbstractVMInstallPage(String pageName) {
54
		super(pageName);
55
	}
56
57
	/**
58
     * Creates a new wizard page with the given name, title, and image.
59
     *
60
     * @param pageName the name of the page
61
     * @param title the title for this wizard page,
62
     *   or <code>null</code> if none
63
     * @param titleImage the image descriptor for the title of this wizard page,
64
     *   or <code>null</code> if none
65
     */
66
	protected AbstractVMInstallPage(String pageName, String title, ImageDescriptor titleImage) {
67
		super(pageName, title, titleImage);
68
	}
69
70
	/**
71
	 * Adds the specified property change listener to this page. Listeners
72
	 * are notified when the properties defined by this interface change.
73
	 * For example, when the name of a JRE changes.
74
	 * <p>
75
	 * Has no effect if an identical listener is already registered.
76
	 * </p>
77
	 * @param listener property change listener
78
	 */
79
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
80
		fListeners.add(listener);
81
	}
82
83
	/**
84
	 * Called when the VM install page wizard is closed by selecting 
85
	 * the finish button. Implementers typically override this method to 
86
	 * store the page result (new/changed vm install returned in 
87
	 * getSelection) into its model.
88
	 * 
89
	 * @return if the operation was successful. Only when returned
90
	 * <code>true</code>, the wizard will close.
91
	 */
92
	public abstract boolean finish();
93
	
94
	/**
95
	 * Returns the edited or created VM install. This method
96
	 * may return <code>null</code> if no VM install exists.
97
	 * 
98
	 * @return the edited or created VM install.
99
	 */
100
	public abstract VMStandin getSelection();
101
102
	/**
103
	 * Removes the specified property change listener.
104
	 * <p>
105
	 * Has no effect if the listener is not already registered.
106
	 * </p>
107
	 * @param listener property change listener
108
	 */
109
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
110
		fListeners.remove(listener);
111
	}
112
113
	/**
114
	 * Sets the VM install to be edited. 
115
	 * 
116
	 * @param vm the VM install to edit
117
	 */
118
	public void setSelection(VMStandin vm) {
119
		fOriginalName = vm.getName();
120
	}
121
	
122
	/**
123
	 * Fires a name change event specifying the new name.
124
	 * 
125
	 * @param newName
126
	 */
127
	protected void fireNameChange(String newName) {
128
		fireChangeEvent(new PropertyChangeEvent(this, P_JRE_NAME, fOriginalName, newName));
129
	}
130
	
131
	/**
132
	 * Fires the event to all listeners.
133
	 * 
134
	 * @param event event to fire
135
	 */
136
	protected void fireChangeEvent(PropertyChangeEvent event) {
137
		Object[] listeners = fListeners.getListeners();
138
		for (int i = 0; i < listeners.length; i++) {
139
			IPropertyChangeListener listener = (IPropertyChangeListener) listeners[i];
140
			listener.propertyChange(event);
141
		}
142
	}
143
144
	/* (non-Javadoc)
145
	 * @see org.eclipse.jface.wizard.WizardPage#getNextPage()
146
	 */
147
	public IWizardPage getNextPage() {
148
		return null;
149
	}
150
	
151
	/**
152
	 * Sets this page's message based on the status severity.
153
	 * 
154
	 * @param status status with message and severity
155
	 */
156
	protected void setStatusMessage(IStatus status) {
157
		if (status.isOK()) {
158
			setMessage(status.getMessage());
159
		} else {
160
			switch (status.getSeverity()) {
161
			case IStatus.ERROR:
162
				setMessage(status.getMessage(), IMessageProvider.ERROR);
163
				break;
164
			case IStatus.INFO:
165
				setMessage(status.getMessage(), IMessageProvider.INFORMATION);
166
				break;
167
			case IStatus.WARNING:
168
				setMessage(status.getMessage(), IMessageProvider.WARNING);
169
				break;
170
			default:
171
				break;
172
			}
173
		}
174
	}	
175
}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/EEVMPage.java (+410 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.debug.ui.jres;
12
13
import java.io.File;
14
import java.io.IOException;
15
import java.net.URL;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.debug.core.DebugPlugin;
21
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
22
import org.eclipse.jdt.internal.debug.ui.JavaDebugImages;
23
import org.eclipse.jdt.internal.debug.ui.SWTFactory;
24
import org.eclipse.jdt.internal.debug.ui.StatusInfo;
25
import org.eclipse.jdt.launching.AbstractVMInstallType;
26
import org.eclipse.jdt.launching.IVMInstall;
27
import org.eclipse.jdt.launching.IVMInstall2;
28
import org.eclipse.jdt.launching.IVMInstallType;
29
import org.eclipse.jdt.launching.JavaRuntime;
30
import org.eclipse.jdt.launching.VMStandin;
31
import org.eclipse.jface.dialogs.Dialog;
32
import org.eclipse.jface.dialogs.IMessageProvider;
33
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.custom.BusyIndicator;
35
import org.eclipse.swt.events.ModifyEvent;
36
import org.eclipse.swt.events.ModifyListener;
37
import org.eclipse.swt.events.SelectionEvent;
38
import org.eclipse.swt.events.SelectionListener;
39
import org.eclipse.swt.graphics.Image;
40
import org.eclipse.swt.layout.GridData;
41
import org.eclipse.swt.layout.GridLayout;
42
import org.eclipse.swt.widgets.Button;
43
import org.eclipse.swt.widgets.Composite;
44
import org.eclipse.swt.widgets.Control;
45
import org.eclipse.swt.widgets.FileDialog;
46
import org.eclipse.swt.widgets.Text;
47
48
/**
49
 * Page used to edit an 'EE' VM.
50
 * 
51
 * @since 3.4
52
 */
53
public class EEVMPage extends AbstractVMInstallPage {
54
	
55
	// VM being edited or created
56
	private VMStandin fVM;
57
	private Text fVMName;
58
	private Text fVMArgs;
59
	private Text fEEFile;
60
	private VMLibraryBlock fLibraryBlock;
61
// the VM install's javadoc location
62
	private URL fJavadocLocation = null;
63
	private boolean fAutoDetectAttributes = false;
64
	private IStatus[] fFieldStatus = new IStatus[1];
65
	
66
	/**
67
	 * 
68
	 */
69
	public EEVMPage() {
70
		super("Add EE VM");
71
		for (int i = 0; i < fFieldStatus.length; i++) {
72
			fFieldStatus[i] = Status.OK_STATUS;
73
		}
74
	}
75
	
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.jface.dialogs.IDialogPage#getImage()
78
	 */
79
	public Image getImage() {
80
		return JavaDebugImages.get(JavaDebugImages.IMG_WIZBAN_LIBRARY);
81
	}	
82
83
	/* (non-Javadoc)
84
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
85
	 */
86
	public void createControl(Composite p) {
87
		// create a composite with standard margins and spacing
88
		Composite composite = new Composite(p, SWT.NONE);
89
		GridLayout layout = new GridLayout();
90
		layout.numColumns = 3;
91
		composite.setLayout(layout);
92
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
93
		
94
	// VM location
95
		SWTFactory.createLabel(composite, "&Definition File:", 1);
96
		fEEFile = SWTFactory.createSingleText(composite, 1);
97
		Button folders = SWTFactory.createPushButton(composite, "F&ile...", null);
98
		GridData data = (GridData) folders.getLayoutData();
99
		data.horizontalAlignment = GridData.END;
100
	//VM name
101
		SWTFactory.createLabel(composite, JREMessages.addVMDialog_jreName, 1);
102
		fVMName = SWTFactory.createSingleText(composite, 2);
103
	//VM arguments
104
		SWTFactory.createLabel(composite, JREMessages.AddVMDialog_23, 1);
105
		fVMArgs = SWTFactory.createSingleText(composite, 2);
106
	//VM libraries block 
107
		SWTFactory.createLabel(composite, JREMessages.AddVMDialog_JRE_system_libraries__1, 3);
108
		fLibraryBlock = new VMLibraryBlock();
109
		fLibraryBlock.setWizard(getWizard());
110
		fLibraryBlock.createControl(composite);
111
		Control libControl = fLibraryBlock.getControl();
112
		GridData gd = new GridData(GridData.FILL_BOTH);
113
		gd.horizontalSpan = 3;
114
		libControl.setLayoutData(gd);
115
		
116
	
117
	//add the listeners now to prevent them from monkeying with initialized settings
118
		fVMName.addModifyListener(new ModifyListener() {
119
			public void modifyText(ModifyEvent e) {
120
				validateVMName();
121
			}
122
		});
123
		fEEFile.addModifyListener(new ModifyListener() {
124
			public void modifyText(ModifyEvent e) {
125
				validateDefinitionFile();
126
			}
127
		});
128
		folders.addSelectionListener(new SelectionListener() {
129
			public void widgetDefaultSelected(SelectionEvent e) {}
130
			public void widgetSelected(SelectionEvent e) {
131
				FileDialog dialog = new FileDialog(getShell());
132
				dialog.setFilterExtensions(new String[]{"*.ee"}); //$NON-NLS-1$
133
				File file = new File(fEEFile.getText());
134
				String text = fEEFile.getText();
135
				if (file.isFile()) {
136
					text = file.getParentFile().getAbsolutePath();
137
				}
138
				dialog.setFileName(text); 
139
				String newPath = dialog.open();
140
				if (newPath != null) {
141
					fEEFile.setText(newPath);
142
				}
143
			}
144
		});
145
		Dialog.applyDialogFont(composite);
146
		setControl(composite);
147
		initializeFields();
148
	}	
149
	
150
	/**
151
	 * Validates the JRE location
152
	 * @return the status after validating the JRE location
153
	 */
154
	private void validateDefinitionFile() {
155
		String locationName = fEEFile.getText();
156
		IStatus s = null;
157
		File file = null;
158
		if (locationName.length() == 0) {
159
			s = new StatusInfo(IStatus.INFO, "Enter definition file"); 
160
		} 
161
		else {
162
			file = new File(locationName);
163
			if (!file.exists()) {
164
				s = new StatusInfo(IStatus.ERROR, "Definition file does not exist"); 
165
			} 
166
			else {
167
				final IStatus[] temp = new IStatus[1];
168
				final VMStandin[] vm = new VMStandin[1];
169
				final File tempFile = file; 
170
				Runnable r = new Runnable() {
171
					public void run() {
172
						try {
173
							vm[0] = JavaRuntime.createVMFromDefinitionFile(tempFile, fVM.getName(), fVM.getId());
174
							temp[0] = Status.OK_STATUS;
175
						} catch (CoreException e) {
176
							temp[0] = e.getStatus();
177
						}
178
					}
179
				};
180
				BusyIndicator.showWhile(getShell().getDisplay(), r);
181
				s = temp[0];
182
				if (s.isOK()) {
183
					fVM = vm[0];
184
				}
185
			}
186
		}
187
		if (s.isOK()) {
188
			String name = fVMName.getText();
189
			if (name == null || name.trim().length() == 0) {
190
				// auto-generate VM name
191
				String fileName = file.getName();
192
				int index = fileName.lastIndexOf("."); //$NON-NLS-1$
193
				if (index > 0) {
194
					fileName = fileName.substring(0, index);
195
				}
196
				fVMName.setText(fileName);
197
			}
198
		}
199
		detectJavadocLocation();
200
		setJRELocationStatus(s);
201
		fLibraryBlock.setSelection(fVM);
202
		String args = fVM.getVMArgs();
203
		if (args != null) {
204
			fVMArgs.setText(args);
205
		}
206
		updatePageStatus();
207
	}
208
	
209
	/**
210
	 * Auto-detects the default javadoc location
211
	 */
212
	private void detectJavadocLocation() {
213
		if (fAutoDetectAttributes) {
214
			IVMInstallType type = fVM.getVMInstallType();
215
			if (type instanceof AbstractVMInstallType) {
216
				AbstractVMInstallType atype = (AbstractVMInstallType)type;
217
				fJavadocLocation = atype.getDefaultJavadocLocation(getInstallLocation());
218
				String args = atype.getDefaultVMArguments(getInstallLocation());
219
				if (args != null) {
220
					fVMArgs.setText(args);
221
				}
222
			}
223
		} else {
224
			fJavadocLocation = fVM.getJavadocLocation();
225
		}
226
	}
227
	
228
	/**
229
	 * Returns the installation location as a file from the JRE root text control
230
	 * @return the installation location as a file
231
	 */
232
	protected File getInstallLocation() {
233
		return new File(fEEFile.getText());
234
	}	
235
236
	/**
237
	 * Validates the entered name of the VM
238
	 * @return the status of the name validation
239
	 */
240
	private void validateVMName() {
241
		fireNameChange(fVMName.getText());
242
	}
243
	
244
	/* (non-Javadoc)
245
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#finish()
246
	 */
247
	public boolean finish() {
248
		setFieldValuesToVM(fVM);
249
		fLibraryBlock.finish();
250
		return true;
251
	}
252
253
	/* (non-Javadoc)
254
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#getSelection()
255
	 */
256
	public VMStandin getSelection() {
257
		return fVM;
258
	}
259
	
260
	/* (non-Javadoc)
261
	 * @see org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage#setSelection(org.eclipse.jdt.launching.VMStandin)
262
	 */
263
	public void setSelection(VMStandin vm) {
264
		super.setSelection(vm);
265
		fVM = vm;
266
		fAutoDetectAttributes = vm.getJavadocLocation() == null;
267
		setTitle("Define Installed JRE");
268
		setDescription("Specify attributes for an installed JRE");
269
	}
270
	
271
	/**
272
	 * initialize fields to the specified VM
273
	 * @param vm the VM to initialize from
274
	 */
275
	protected void setFieldValuesToVM(IVMInstall vm) {
276
		File dir = new File(fEEFile.getText());
277
		try {
278
			vm.setInstallLocation(dir.getCanonicalFile());
279
		} 
280
		catch (IOException e) {
281
			vm.setInstallLocation(dir.getAbsoluteFile());
282
		}
283
		vm.setName(fVMName.getText());
284
		vm.setJavadocLocation(getURL());
285
		
286
		String argString = fVMArgs.getText().trim();
287
		if (vm instanceof IVMInstall2) {
288
			IVMInstall2 vm2 = (IVMInstall2) vm;
289
			if (argString != null && argString.length() > 0) {
290
				vm2.setVMArgs(argString);			
291
			} 
292
			else {
293
				vm2.setVMArgs(null);
294
			}
295
		} 
296
		else {
297
			if (argString != null && argString.length() > 0) {
298
				vm.setVMArguments(DebugPlugin.parseArguments(argString));			
299
			} 
300
			else {
301
				vm.setVMArguments(null);
302
			}			
303
		}
304
	}
305
	
306
	/**
307
	 * Returns the URL for the javadoc location
308
	 * @return the URL for the javadoc location
309
	 */
310
	protected URL getURL() {
311
		return fJavadocLocation;
312
	}
313
	
314
	/**
315
	 * Creates a unique name for the VMInstallType
316
	 * @param vmType the vm install type
317
	 * @return a unique name
318
	 */
319
	protected static String createUniqueId(IVMInstallType vmType) {
320
		String id = null;
321
		do {
322
			id = String.valueOf(System.currentTimeMillis());
323
		} while (vmType.findVMInstall(id) != null);
324
		return id;
325
	}	
326
	
327
	/**
328
	 * Initialize the dialogs fields
329
	 */
330
	private void initializeFields() {
331
		fLibraryBlock.setSelection(fVM);
332
		fVMName.setText(fVM.getName());
333
//		String eePath = fVM.getAttribute(EEVMInstall.ATTR_DEFINITION_FILE);
334
//		if (eePath != null) {
335
//			fEEFile.setText(eePath);
336
//		}
337
		if (fVM instanceof IVMInstall2) {
338
			IVMInstall2 vm2 = (IVMInstall2) fVM;
339
			String vmArgs = vm2.getVMArgs();
340
			if (vmArgs != null) {
341
				fVMArgs.setText(vmArgs);
342
			}
343
		} else {
344
			String[] vmArgs = fVM.getVMArguments();
345
			if (vmArgs != null) {
346
				StringBuffer buffer = new StringBuffer();
347
				int length= vmArgs.length;
348
				if (length > 0) {
349
					buffer.append(vmArgs[0]);
350
					for (int i = 1; i < length; i++) {
351
						buffer.append(' ').append(vmArgs[i]);
352
					}
353
				}
354
				fVMArgs.setText(buffer.toString());
355
			}				
356
		}
357
		validateVMName();
358
		validateDefinitionFile();
359
	}	
360
	
361
	/**
362
	 * Sets the status of the JRE location field.
363
	 * 
364
	 * @param status JRE location status
365
	 */
366
	private void setJRELocationStatus(IStatus status) {
367
		fFieldStatus[0] = status;
368
	}
369
	
370
	private void updatePageStatus() {
371
		IStatus max = Status.OK_STATUS;
372
		for (int i = 0; i < fFieldStatus.length; i++) {
373
			IStatus status = fFieldStatus[i];
374
			if (status.getSeverity() > max.getSeverity()) {
375
				max = status;
376
			}
377
		}
378
		if (max.isOK()) {
379
			setMessage(null, IMessageProvider.NONE);
380
			setPageComplete(true);
381
		} else {
382
			setStatusMessage(max);
383
			setPageComplete(false);
384
		}
385
	}
386
387
	/* (non-Javadoc)
388
	 * @see org.eclipse.jface.dialogs.DialogPage#getErrorMessage()
389
	 */
390
	public String getErrorMessage() {
391
		String message = super.getErrorMessage();
392
		if (message == null) {
393
			return fLibraryBlock.getErrorMessage();
394
		}
395
		return message;
396
	}
397
398
	/* (non-Javadoc)
399
	 * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
400
	 */
401
	public boolean isPageComplete() {
402
		boolean complete = super.isPageComplete();
403
		if (complete) {
404
			return fLibraryBlock.isPageComplete();
405
		}
406
		return complete;
407
	}
408
	
409
	
410
}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/VMWizardDialog.java (+54 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.debug.ui.jres;
12
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.jface.dialogs.IMessageProvider;
15
import org.eclipse.jface.wizard.WizardDialog;
16
import org.eclipse.swt.widgets.Shell;
17
18
/**
19
 * @since 3.4
20
 */
21
public class VMWizardDialog extends WizardDialog {
22
23
	/**
24
	 * @param parentShell
25
	 * @param newWizard
26
	 */
27
	public VMWizardDialog(Shell parentShell, VMInstallWizard newWizard) {
28
		super(parentShell, newWizard);
29
	}
30
31
	public void updateMessage() {
32
		VMInstallWizard wizard = (VMInstallWizard) getWizard();
33
		IStatus status = wizard.getNameStatus();
34
		if (status.isOK()) {
35
			super.updateMessage();
36
		} else {
37
			switch (status.getSeverity()) {
38
			case IStatus.ERROR:
39
				setMessage(status.getMessage(), IMessageProvider.ERROR);
40
				break;
41
			case IStatus.INFO:
42
				setMessage(status.getMessage(), IMessageProvider.INFORMATION);
43
				break;
44
			case IStatus.WARNING:
45
				setMessage(status.getMessage(), IMessageProvider.WARNING);
46
				break;
47
			default:
48
				break;
49
			}
50
		}
51
	}
52
53
	
54
}
(-)ui/org/eclipse/jdt/internal/debug/ui/jres/EditVMInstallWizard.java (+81 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.debug.ui.jres;
12
13
import org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage;
14
import org.eclipse.jdt.launching.IVMInstall;
15
import org.eclipse.jdt.launching.VMStandin;
16
17
/**
18
 * @since 3.4
19
 */
20
public class EditVMInstallWizard extends VMInstallWizard {
21
	
22
	private AbstractVMInstallPage fEditPage;
23
	
24
	/**
25
	 * Constructs a wizard to edit the given vm.
26
	 * 
27
	 * @param vm vm to edit
28
	 * @param allVMs all VMs being edited
29
	 */
30
	public EditVMInstallWizard(VMStandin vm, IVMInstall[] allVMs) {
31
		super(vm, allVMs);
32
		setWindowTitle("Edit JRE");
33
	}
34
	
35
	/* (non-Javadoc)
36
	 * @see org.eclipse.jface.wizard.Wizard#dispose()
37
	 */
38
	public void dispose() {
39
		fEditPage.removePropertyChangeListener(this);
40
		super.dispose();
41
	}
42
43
44
45
	/* (non-Javadoc)
46
	 * @see org.eclipse.jface.wizard.Wizard#addPages()
47
	 */
48
	public void addPages() {
49
		fEditPage = getEditPage();
50
		fEditPage.setSelection(new VMStandin(getVMInstall()));
51
		fEditPage.addPropertyChangeListener(this);
52
		addPage(fEditPage);
53
	}
54
55
	/**
56
	 * @return
57
	 */
58
	private AbstractVMInstallPage getEditPage() {
59
		// TODO: based on extension
60
		return new StandardVMPage();
61
	}
62
63
	/* (non-Javadoc)
64
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
65
	 */
66
	public boolean performFinish() {
67
		if (fEditPage.finish()) {
68
			return super.performFinish();
69
		}
70
		return false;
71
	}
72
73
	/* (non-Javadoc)
74
	 * @see org.eclipse.jdt.internal.debug.ui.jres.VMInstallWizard#getResult()
75
	 */
76
	protected VMStandin getResult() {
77
		return fEditPage.getSelection();
78
	}
79
80
	
81
}
(-)schema/vmInstallPages.exsd (+121 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.jdt.debug.ui">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.jdt.debug.ui" id="vmInstallPages" name="VM Install Pages"/>
7
      </appInfo>
8
      <documentation>
9
         This extension point allows a wizard page to be contributed for VM installs that require custom editing controls.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <complexType>
15
         <sequence minOccurs="1" maxOccurs="unbounded">
16
            <element ref="vmInstallPage"/>
17
         </sequence>
18
         <attribute name="point" type="string" use="required">
19
            <annotation>
20
               <documentation>
21
                  
22
               </documentation>
23
            </annotation>
24
         </attribute>
25
         <attribute name="id" type="string">
26
            <annotation>
27
               <documentation>
28
                  
29
               </documentation>
30
            </annotation>
31
         </attribute>
32
         <attribute name="name" type="string">
33
            <annotation>
34
               <documentation>
35
                  
36
               </documentation>
37
               <appInfo>
38
                  <meta.attribute translatable="true"/>
39
               </appInfo>
40
            </annotation>
41
         </attribute>
42
      </complexType>
43
   </element>
44
45
   <element name="vmInstallPage">
46
      <annotation>
47
         <documentation>
48
            Contributes a wizard page for a specific VM install type.
49
         </documentation>
50
      </annotation>
51
      <complexType>
52
         <attribute name="vmInstallType" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  Specifies the VM install type this wizard page is to be used for. Unique identifier corresponding to an &lt;code&gt;IVMInstallType&lt;/code&gt;&apos;s id.
56
               </documentation>
57
            </annotation>
58
         </attribute>
59
         <attribute name="class" type="string" use="required">
60
            <annotation>
61
               <documentation>
62
                  Wizard page implementation. Must be a subclass of &lt;code&gt;org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage&lt;/code&gt;.
63
               </documentation>
64
               <appInfo>
65
                  <meta.attribute kind="java" basedOn="org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage:"/>
66
               </appInfo>
67
            </annotation>
68
         </attribute>
69
      </complexType>
70
   </element>
71
72
   <annotation>
73
      <appInfo>
74
         <meta.section type="since"/>
75
      </appInfo>
76
      <documentation>
77
         3.4
78
      </documentation>
79
   </annotation>
80
81
   <annotation>
82
      <appInfo>
83
         <meta.section type="examples"/>
84
      </appInfo>
85
      <documentation>
86
         [Enter extension point usage example here.]
87
      </documentation>
88
   </annotation>
89
90
   <annotation>
91
      <appInfo>
92
         <meta.section type="apiInfo"/>
93
      </appInfo>
94
      <documentation>
95
         A wizard page must be a subclass of &lt;code&gt;org.eclipse.jdt.debug.ui.launchConfigurations.AbstractVMInstallPage&lt;/code&gt;.
96
      </documentation>
97
   </annotation>
98
99
   <annotation>
100
      <appInfo>
101
         <meta.section type="implementation"/>
102
      </appInfo>
103
      <documentation>
104
         JDT provides a default implementation of a wizard page for VMs that do not contribute one.
105
      </documentation>
106
   </annotation>
107
108
   <annotation>
109
      <appInfo>
110
         <meta.section type="copyright"/>
111
      </appInfo>
112
      <documentation>
113
         Copyright (c) 2007 IBM Corporation and others.&lt;br&gt;
114
All rights reserved. This program and the accompanying materials are made 
115
available under the terms of the Eclipse Public License v1.0 which 
116
accompanies this distribution, and is available at 
117
&lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
118
      </documentation>
119
   </annotation>
120
121
</schema>
(-)tests/org/eclipse/jdt/debug/tests/core/EEDefinitionTests.java (-27 / +43 lines)
Lines 12-24 Link Here
12
12
13
import java.io.File;
13
import java.io.File;
14
14
15
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Path;
18
import org.eclipse.core.runtime.Path;
18
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.jdt.debug.testplugin.JavaTestPlugin;
20
import org.eclipse.jdt.debug.testplugin.JavaTestPlugin;
20
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
21
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
21
import org.eclipse.jdt.internal.launching.StandardVMType;
22
import org.eclipse.jdt.internal.launching.EEVMType;
22
import org.eclipse.jdt.launching.IVMInstall;
23
import org.eclipse.jdt.launching.IVMInstall;
23
import org.eclipse.jdt.launching.IVMInstallType;
24
import org.eclipse.jdt.launching.IVMInstallType;
24
import org.eclipse.jdt.launching.JavaRuntime;
25
import org.eclipse.jdt.launching.JavaRuntime;
Lines 46-71 Link Here
46
	}
47
	}
47
	
48
	
48
	/**
49
	/**
49
	 * Tests that the EE file is a valid install location
50
	 * Tests that the EE file is a valid file
50
	 */
51
	 */
51
	public void testValidateInstallLocation() {
52
	public void testValidateDefinitionFile() {
52
		File file = getEEFile();
53
		File file = getEEFile();
53
		IVMInstallType vmType = getStandardVMInstallType();
54
		assertNotNull("Missing EE file", file);
54
		assertNotNull("Missing EE file", file);
55
		assertNotNull("Missing standard VM type", vmType);
55
		IStatus status = EEVMType.validateDefinitionFile(file);
56
		IStatus status = vmType.validateInstallLocation(file);
57
		assertTrue("Invalid install location", status.isOK());
56
		assertTrue("Invalid install location", status.isOK());
58
	}
57
	}
59
	
58
	
60
	/**
59
	/**
61
	 * Tests default libraries for the EE file
60
	 * Tests that the EE install location validation returns an INFO status.
62
	 */
61
	 */
63
	public void testDefaultLibraries() {
62
	public void testValidateInstallLocation() {
64
		File file = getEEFile();
63
		File file = getEEFile();
65
		IVMInstallType vmType = getStandardVMInstallType();
64
		IVMInstallType vmType = getVMInstallType();
66
		assertNotNull("Missing EE file", file);
65
		assertNotNull("Missing EE file", file);
67
		assertNotNull("Missing standard VM type", vmType);
66
		assertNotNull("Missing EE VM type", vmType);
68
		LibraryLocation[] libs = vmType.getDefaultLibraryLocations(file);
67
		IStatus status = vmType.validateInstallLocation(file);
68
		assertTrue("Invalid install location", status.getSeverity() == IStatus.INFO);
69
	}	
70
	
71
	/**
72
	 * Tests libraries for the EE file
73
	 */
74
	public void testLibraries() {
75
		File file = getEEFile();
76
		assertNotNull("Missing EE file", file);
77
		LibraryLocation[] libs = EEVMType.getLibraryLocations(file);
69
		String[] expected = new String[]{"end.jar", "classes.txt", "others.txt", "ext1.jar", "ext2.jar", "opt-ext.jar"};
78
		String[] expected = new String[]{"end.jar", "classes.txt", "others.txt", "ext1.jar", "ext2.jar", "opt-ext.jar"};
70
		assertEquals("Wrong number of libraries", expected.length, libs.length);
79
		assertEquals("Wrong number of libraries", expected.length, libs.length);
71
		for (int i = 0; i < expected.length; i++) {
80
		for (int i = 0; i < expected.length; i++) {
Lines 87-101 Link Here
87
	}
96
	}
88
	
97
	
89
	/**
98
	/**
99
	 * Tests default libraries for an EE VM type are empty.
100
	 */
101
	public void testDefaultLibraries() {
102
		File file = getEEFile();
103
		IVMInstallType vmType = getVMInstallType();
104
		assertNotNull("Missing EE file", file);
105
		assertNotNull("Missing EE VM type", vmType);
106
		LibraryLocation[] libs = vmType.getDefaultLibraryLocations(file);
107
		assertEquals("Wrong number of libraries", 0, libs.length);
108
	}	
109
	
110
	/**
90
	 * Tests default VM arguments. All arguments from the EE file should get passed through in the
111
	 * Tests default VM arguments. All arguments from the EE file should get passed through in the
91
	 * same order to the command line.
112
	 * same order to the command line.
92
	 */
113
	 */
93
	public void testDefaultVMArguments() {
114
	public void testVMArguments() {
94
		File file = getEEFile();
115
		File file = getEEFile();
95
		StandardVMType vmType = (StandardVMType) getStandardVMInstallType();
96
		assertNotNull("Missing EE file", file);
116
		assertNotNull("Missing EE file", file);
97
		assertNotNull("Missing standard VM type", vmType);
117
		String defaultVMArguments = EEVMType.getVMArguments(file);
98
		String defaultVMArguments = vmType.getDefaultVMArguments(file);
99
		String[] expected = new String[] {
118
		String[] expected = new String[] {
100
				"-Dee.executable",
119
				"-Dee.executable",
101
				"-Dee.executable.console",
120
				"-Dee.executable.console",
Lines 123-140 Link Here
123
	/**
142
	/**
124
	 * Test compatible environments
143
	 * Test compatible environments
125
	 */
144
	 */
126
	public void testCompatibleEEs() {
145
	public void testCompatibleEEs() throws CoreException {
127
		IVMInstall install = null;
146
		IVMInstall install = null;
128
		StandardVMType vmType = (StandardVMType) getStandardVMInstallType();
147
		EEVMType vmType = (EEVMType) getVMInstallType();
129
		try {
148
		try {
130
			File file = getEEFile();
149
			File file = getEEFile();
131
			assertNotNull("Missing EE file", file);
150
			assertNotNull("Missing EE file", file);
132
			assertNotNull("Missing standard VM type", vmType);
151
			assertNotNull("Missing EE VM type", vmType);
133
			VMStandin vm = new VMStandin(vmType, "test-ee-file-id");
152
			VMStandin standin = JavaRuntime.createVMFromDefinitionFile(file, "test-ee-file", "test-ee-file-id");
134
			vm.setInstallLocation(file);
153
			install = standin.convertToRealVM();
135
			vm.setName("test-ee-file");
136
			vm.setVMArgs(vmType.getDefaultVMArguments(file));
137
			install = vm.convertToRealVM();
138
			
154
			
139
			IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
155
			IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
140
			IExecutionEnvironment[] envs = manager.getExecutionEnvironments();
156
			IExecutionEnvironment[] envs = manager.getExecutionEnvironments();
Lines 143-151 Link Here
143
				IExecutionEnvironment env = envs[i];
159
				IExecutionEnvironment env = envs[i];
144
				if (env.getId().equals("CDC-1.1/Foundation-1.1")) {
160
				if (env.getId().equals("CDC-1.1/Foundation-1.1")) {
145
					found11 = true;
161
					found11 = true;
146
					assertTrue("Should be strictly compatible with " + env.getId(), env.isStrictlyCompatible(vm));
162
					assertTrue("Should be strictly compatible with " + env.getId(), env.isStrictlyCompatible(install));
147
				} else if (env.getId().indexOf("jdt.debug.tests") < 0) {
163
				} else if (env.getId().indexOf("jdt.debug.tests") < 0) {
148
					assertFalse("Should *not* be strictly compatible with " + env.getId(), env.isStrictlyCompatible(vm));
164
					assertFalse("Should *not* be strictly compatible with " + env.getId(), env.isStrictlyCompatible(install));
149
				}
165
				}
150
			}
166
			}
151
			assertTrue("Did not find foundation 1.1 environment", found11);
167
			assertTrue("Did not find foundation 1.1 environment", found11);
Lines 160-166 Link Here
160
		return JavaTestPlugin.getDefault().getFileInPlugin(TEST_EE_FILE);
176
		return JavaTestPlugin.getDefault().getFileInPlugin(TEST_EE_FILE);
161
	}
177
	}
162
	
178
	
163
	protected IVMInstallType getStandardVMInstallType() {
179
	protected IVMInstallType getVMInstallType() {
164
		return JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
180
		return JavaRuntime.getVMInstallType(EEVMType.ID_EE_VM_TYPE);
165
	}
181
	}
166
}
182
}
(-)testfiles/test-jre/bin/test-foundation11.ee (+1 lines)
Lines 25-30 Link Here
25
-Dee.name=Eclipse JDT Test JRE Definition
25
-Dee.name=Eclipse JDT Test JRE Definition
26
-Dee.description=Foundation Specification v1.1
26
-Dee.description=Foundation Specification v1.1
27
-Dee.copyright=(c) Copyright IBM Corp. 2007  All Rights Reserved
27
-Dee.copyright=(c) Copyright IBM Corp. 2007  All Rights Reserved
28
-Djava.home=..
28
29
29
# all args should get passed through to command line
30
# all args should get passed through to command line
30
-XspecialArg:123
31
-XspecialArg:123
(-)testfiles/test-jre/bin/test-foundation11-win32.ee (+1 lines)
Lines 25-30 Link Here
25
-Dee.name=Eclipse JDT Test JRE Definition
25
-Dee.name=Eclipse JDT Test JRE Definition
26
-Dee.description=Foundation Specification v1.1
26
-Dee.description=Foundation Specification v1.1
27
-Dee.copyright=(c) Copyright IBM Corp. 2007  All Rights Reserved
27
-Dee.copyright=(c) Copyright IBM Corp. 2007  All Rights Reserved
28
-Djava.home=..
28
29
29
# all args should get passed through to command line
30
# all args should get passed through to command line
30
-XspecialArg:123
31
-XspecialArg:123
(-)plugin.xml (+4 lines)
Lines 23-28 Link Here
23
            class="org.eclipse.jdt.internal.launching.Standard11xVMType"
23
            class="org.eclipse.jdt.internal.launching.Standard11xVMType"
24
            id="org.eclipse.jdt.launching.Standard11xVMType">
24
            id="org.eclipse.jdt.launching.Standard11xVMType">
25
      </vmInstallType>
25
      </vmInstallType>
26
      <vmInstallType
27
            class="org.eclipse.jdt.internal.launching.EEVMType"
28
            id="org.eclipse.jdt.launching.EEVMType">
29
      </vmInstallType>
26
   </extension>
30
   </extension>
27
   <extension
31
   <extension
28
         point="org.eclipse.debug.core.launchConfigurationTypes">
32
         point="org.eclipse.debug.core.launchConfigurationTypes">
(-)launching/org/eclipse/jdt/internal/launching/StandardVM.java (-4 / +16 lines)
Lines 41-50 Link Here
41
        StandardVMType installType = (StandardVMType) getVMInstallType();
41
        StandardVMType installType = (StandardVMType) getVMInstallType();
42
        File installLocation = getInstallLocation();
42
        File installLocation = getInstallLocation();
43
        if (installLocation != null) {
43
        if (installLocation != null) {
44
        	if (EEVMType.isEEInstall(installLocation)) {
44
            File executable = getJavaExecutable();
45
        		return EEVMType.getJavaVersion(installLocation);
46
        	}
47
            File executable = StandardVMType.findJavaExecutable(installLocation);
48
            if (executable != null) {
45
            if (executable != null) {
49
                String vmVersion = installType.getVMVersion(installLocation, executable);
46
                String vmVersion = installType.getVMVersion(installLocation, executable);
50
                // strip off extra info
47
                // strip off extra info
Lines 64-67 Link Here
64
        }
61
        }
65
        return null;
62
        return null;
66
    }
63
    }
64
    
65
    /**
66
     * Returns the java executable for this VM or <code>null</code> if cannot be found
67
     * 
68
     * @return executable for this VM or <code>null</code> if none
69
     */
70
    File getJavaExecutable() {
71
    	File installLocation = getInstallLocation();
72
        if (installLocation != null) {
73
            return StandardVMType.findJavaExecutable(installLocation);
74
        }
75
        return null;
76
    }
77
    
78
    
67
}
79
}
(-)launching/org/eclipse/jdt/internal/launching/StandardVMRunner.java (-2 / +8 lines)
Lines 171-181 Link Here
171
		
171
		
172
		// If no java command was specified, use default executable
172
		// If no java command was specified, use default executable
173
		if (command == null) {
173
		if (command == null) {
174
			File exe = StandardVMType.findJavaExecutable(fVMInstance.getInstallLocation());
174
			File exe = null;
175
			if (fVMInstance instanceof StandardVM) {
176
				exe = ((StandardVM)fVMInstance).getJavaExecutable();
177
			} else {
178
				exe = StandardVMType.findJavaExecutable(fVMInstance.getInstallLocation());
179
			}
175
			if (exe == null) {
180
			if (exe == null) {
176
				abort(MessageFormat.format(LaunchingMessages.StandardVMRunner_Unable_to_locate_executable_for__0__1, new String[]{fVMInstance.getName()}), null, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); 
181
				abort(MessageFormat.format(LaunchingMessages.StandardVMRunner_Unable_to_locate_executable_for__0__1, new String[]{fVMInstance.getName()}), null, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); 
182
			} else {
183
				return exe.getAbsolutePath();
177
			}
184
			}
178
			return exe.getAbsolutePath();
179
		}
185
		}
180
				
186
				
181
		// Build the path to the java executable.  First try 'bin', and if that
187
		// Build the path to the java executable.  First try 'bin', and if that
(-)launching/org/eclipse/jdt/internal/launching/VMDefinitionsContainer.java (-3 / +33 lines)
Lines 23-28 Link Here
23
import java.util.List;
23
import java.util.List;
24
import java.util.Map;
24
import java.util.Map;
25
import java.util.Set;
25
import java.util.Set;
26
import java.util.Map.Entry;
26
27
27
import javax.xml.parsers.DocumentBuilder;
28
import javax.xml.parsers.DocumentBuilder;
28
import javax.xml.parsers.DocumentBuilderFactory;
29
import javax.xml.parsers.DocumentBuilderFactory;
Lines 35-40 Link Here
35
import org.eclipse.core.runtime.Path;
36
import org.eclipse.core.runtime.Path;
36
import org.eclipse.core.runtime.Status;
37
import org.eclipse.core.runtime.Status;
37
import org.eclipse.debug.core.DebugPlugin;
38
import org.eclipse.debug.core.DebugPlugin;
39
import org.eclipse.jdt.launching.AbstractVMInstall;
38
import org.eclipse.jdt.launching.IVMInstall;
40
import org.eclipse.jdt.launching.IVMInstall;
39
import org.eclipse.jdt.launching.IVMInstall2;
41
import org.eclipse.jdt.launching.IVMInstall2;
40
import org.eclipse.jdt.launching.IVMInstallType;
42
import org.eclipse.jdt.launching.IVMInstallType;
Lines 130-136 Link Here
130
			}
132
			}
131
			vmList.add(vm);
133
			vmList.add(vm);
132
			File installLocation = vm.getInstallLocation();
134
			File installLocation = vm.getInstallLocation();
133
			if (installLocation == null || !vmInstallType.validateInstallLocation(installLocation).isOK()) {
135
			if (installLocation == null || vmInstallType.validateInstallLocation(installLocation).getSeverity() == IStatus.ERROR) {
134
				fInvalidVMList.add(vm);
136
				fInvalidVMList.add(vm);
135
			}
137
			}
136
			fVMList.add(vm);
138
			fVMList.add(vm);
Lines 344-349 Link Here
344
			}
346
			}
345
		}
347
		}
346
		
348
		
349
		// vm attributes
350
		if (vm instanceof AbstractVMInstall) {
351
			Map attributes = ((AbstractVMInstall)vm).getAttributes();
352
			if (!attributes.isEmpty()) {
353
				Element attrElement = doc.createElement("attributeMap"); //$NON-NLS-1$
354
				Iterator iterator = attributes.entrySet().iterator();
355
				while (iterator.hasNext()) {
356
					Entry entry = (Entry) iterator.next();
357
					Element entryElement = doc.createElement("entry"); //$NON-NLS-1$
358
					entryElement.setAttribute("key", (String)entry.getKey()); //$NON-NLS-1$
359
					entryElement.setAttribute("value", (String)entry.getValue()); //$NON-NLS-1$
360
					attrElement.appendChild(entryElement);
361
				}
362
				element.appendChild(attrElement);
363
			}
364
		}
365
		
347
		return element;
366
		return element;
348
	}
367
	}
349
	
368
	
Lines 534-543 Link Here
534
					if (subElementName.equals("libraryLocation")) { //$NON-NLS-1$
553
					if (subElementName.equals("libraryLocation")) { //$NON-NLS-1$
535
						LibraryLocation loc = getLibraryLocation(subElement);
554
						LibraryLocation loc = getLibraryLocation(subElement);
536
						vmStandin.setLibraryLocations(new LibraryLocation[]{loc});
555
						vmStandin.setLibraryLocations(new LibraryLocation[]{loc});
537
						break;
538
					} else if (subElementName.equals("libraryLocations")) { //$NON-NLS-1$
556
					} else if (subElementName.equals("libraryLocations")) { //$NON-NLS-1$
539
						setLibraryLocations(vmStandin, subElement);
557
						setLibraryLocations(vmStandin, subElement);
540
						break;
558
					} else if (subElementName.equals("attributeMap")) { //$NON-NLS-1$
559
						NodeList entries = subElement.getElementsByTagName("entry"); //$NON-NLS-1$
560
						for (int j = 0; j < entries.getLength(); j++) {
561
							Node entryNode = entries.item(j);
562
							if (entryNode instanceof Element) {
563
								Element entryElement = (Element) entryNode;
564
								String key = entryElement.getAttribute("key"); //$NON-NLS-1$
565
								String value = entryElement.getAttribute("value"); //$NON-NLS-1$
566
								if (key != null && value != null) {
567
									vmStandin.setAttribute(key, value);
568
								}
569
							}
570
						}
541
					}
571
					}
542
				}
572
				}
543
			}
573
			}
(-)launching/org/eclipse/jdt/internal/launching/EEVMType.java (-45 / +106 lines)
Lines 28-33 Link Here
28
import org.eclipse.core.runtime.IStatus;
28
import org.eclipse.core.runtime.IStatus;
29
import org.eclipse.core.runtime.Path;
29
import org.eclipse.core.runtime.Path;
30
import org.eclipse.core.runtime.Status;
30
import org.eclipse.core.runtime.Status;
31
import org.eclipse.jdt.launching.AbstractVMInstall;
32
import org.eclipse.jdt.launching.AbstractVMInstallType;
33
import org.eclipse.jdt.launching.IVMInstall;
31
import org.eclipse.jdt.launching.LibraryLocation;
34
import org.eclipse.jdt.launching.LibraryLocation;
32
35
33
import com.ibm.icu.text.MessageFormat;
36
import com.ibm.icu.text.MessageFormat;
Lines 38-44 Link Here
38
 * 
41
 * 
39
 * @since 3.4
42
 * @since 3.4
40
 */
43
 */
41
public class EEVMType {
44
public class EEVMType extends AbstractVMInstallType {
45
	
46
	/**
47
	 * VM Type id
48
	 */
49
	public static final String ID_EE_VM_TYPE = "org.eclipse.jdt.launching.EEVMType"; //$NON-NLS-1$
42
	
50
	
43
	/**
51
	/**
44
	 * Map of {EE File -> {Map of {PropertyName -> PropertyValue}}
52
	 * Map of {EE File -> {Map of {PropertyName -> PropertyValue}}
Lines 58-112 Link Here
58
	public static final String PROP_CLASS_LIB_LEVEL = "-Dee.class.library.level";  //$NON-NLS-1$
66
	public static final String PROP_CLASS_LIB_LEVEL = "-Dee.class.library.level";  //$NON-NLS-1$
59
	public static final String PROP_EXECUTABLE = "-Dee.executable";  //$NON-NLS-1$
67
	public static final String PROP_EXECUTABLE = "-Dee.executable";  //$NON-NLS-1$
60
	public static final String PROP_EXECUTABLE_CONSOLE = "-Dee.executable.console";  //$NON-NLS-1$
68
	public static final String PROP_EXECUTABLE_CONSOLE = "-Dee.executable.console";  //$NON-NLS-1$
69
	public static final String PROP_JAVA_HOME = "-Djava.home";  //$NON-NLS-1$
61
	
70
	
62
	private static final String[] REQUIRED_PROPERTIES = new String[]{PROP_EXECUTABLE, PROP_BOOT_CLASS_PATH, PROP_LANGUAGE_LEVEL};
71
	private static final String[] REQUIRED_PROPERTIES = new String[]{PROP_EXECUTABLE, PROP_BOOT_CLASS_PATH, PROP_LANGUAGE_LEVEL, PROP_JAVA_HOME};
63
	
72
64
	/**
73
	/**
65
	 * Returns whether the given install location corresponds to an .ee file.
74
	 * Returns the library locations defined in the given definition file.
66
	 * 
75
	 * 
67
	 * @param installLocation
76
	 * @param eeFile definition file
68
	 * @return whether the given install location corresponds to an .ee file.
77
	 * @return library locations defined in the file or an empty collection if none
69
	 */
78
	 */
70
	public static boolean isEEInstall(File installLocation) {
79
	public static LibraryLocation[] getLibraryLocations(File eeFile) {
71
		if (installLocation.isFile()) {
72
			String name = installLocation.getName();
73
			if (name.endsWith(".ee")) { //$NON-NLS-1$
74
				return true;
75
			}
76
		}
77
		return false;
78
	}
79
80
	/* (non-Javadoc)
81
	 * @see org.eclipse.jdt.launching.IVMInstallType#getDefaultLibraryLocations(java.io.File)
82
	 */
83
	public static LibraryLocation[] getDefaultLibraryLocations(File installLocation) {
84
		
80
		
85
		Map properties = getProperties(installLocation);
81
		Map properties = getProperties(eeFile);
86
		if (properties == null) {
82
		if (properties == null) {
87
			return new LibraryLocation[]{};
83
			return new LibraryLocation[]{};
88
		}
84
		}
89
		
85
		
90
		List allLibs = new ArrayList(); 
86
		List allLibs = new ArrayList(); 
91
		
87
		
92
		String dirs = getProperty(PROP_ENDORSED_DIRS, installLocation);
88
		String dirs = getProperty(PROP_ENDORSED_DIRS, eeFile);
93
		if (dirs != null) {
89
		if (dirs != null) {
94
			// Add all endorsed libraries - they are first, as they replace
90
			// Add all endorsed libraries - they are first, as they replace
95
			allLibs.addAll(StandardVMType.gatherAllLibraries(resolvePaths(dirs, installLocation)));
91
			allLibs.addAll(StandardVMType.gatherAllLibraries(resolvePaths(dirs, eeFile)));
96
		}
92
		}
97
		
93
		
98
		// next is the bootpath libraries
94
		// next is the bootpath libraries
99
		dirs = getProperty(PROP_BOOT_CLASS_PATH, installLocation);
95
		dirs = getProperty(PROP_BOOT_CLASS_PATH, eeFile);
100
		if (dirs != null) {
96
		if (dirs != null) {
101
			String[] bootpath = resolvePaths(dirs, installLocation);
97
			String[] bootpath = resolvePaths(dirs, eeFile);
102
			List boot = new ArrayList(bootpath.length);
98
			List boot = new ArrayList(bootpath.length);
103
			URL url = getDefaultJavadocLocation(installLocation);
99
			URL url = getJavadocLocation(eeFile);
104
			for (int i = 0; i < bootpath.length; i++) {
100
			for (int i = 0; i < bootpath.length; i++) {
105
				IPath path = new Path(bootpath[i]);
101
				IPath path = new Path(bootpath[i]);
106
				File lib = path.toFile(); 
102
				File lib = path.toFile(); 
107
				if (lib.exists() && lib.isFile()) {
103
				if (lib.exists() && lib.isFile()) {
108
					LibraryLocation libraryLocation = new LibraryLocation(path,
104
					LibraryLocation libraryLocation = new LibraryLocation(path,
109
									getDefaultSourceLocation(installLocation),
105
									getDefaultSourceLocation(eeFile),
110
									Path.EMPTY,
106
									Path.EMPTY,
111
									url);
107
									url);
112
					boot.add(libraryLocation);
108
					boot.add(libraryLocation);
Lines 116-124 Link Here
116
		}
112
		}
117
				
113
				
118
		// Add all extension libraries
114
		// Add all extension libraries
119
		dirs = getProperty(PROP_EXTENSION_DIRS, installLocation);
115
		dirs = getProperty(PROP_EXTENSION_DIRS, eeFile);
120
		if (dirs != null) {
116
		if (dirs != null) {
121
			allLibs.addAll(StandardVMType.gatherAllLibraries(resolvePaths(dirs, installLocation)));
117
			allLibs.addAll(StandardVMType.gatherAllLibraries(resolvePaths(dirs, eeFile)));
122
		}
118
		}
123
		
119
		
124
		
120
		
Lines 135-158 Link Here
135
		return (LibraryLocation[])allLibs.toArray(new LibraryLocation[allLibs.size()]);
131
		return (LibraryLocation[])allLibs.toArray(new LibraryLocation[allLibs.size()]);
136
	}
132
	}
137
	
133
	
138
	/* (non-Javadoc)
134
139
	 * @see org.eclipse.jdt.launching.AbstractVMInstallType#getDefaultJavadocLocation(java.io.File)
135
	/**
136
	 * Returns the javadoc location specified in the definition file or <code>null</code>
137
	 * if none.
138
	 * 
139
	 * @param eeFile definition file
140
	 * @return javadoc location specified in the definition file or <code>null</code> if none
140
	 */
141
	 */
141
	public static URL getDefaultJavadocLocation(File installLocation) {
142
	public static URL getJavadocLocation(File eeFile) {
142
		String version = getProperty(PROP_LANGUAGE_LEVEL, installLocation);
143
		String version = getProperty(PROP_LANGUAGE_LEVEL, eeFile);
143
		if (version != null) {
144
		if (version != null) {
144
			return StandardVMType.getDefaultJavadocLocation(version);
145
			return StandardVMType.getDefaultJavadocLocation(version);
145
		}
146
		}
146
		return null;
147
		return null;
147
	}
148
	}
148
	
149
	
149
	/* (non-Javadoc)
150
	/**
150
	 * @see org.eclipse.jdt.launching.AbstractVMInstallType#getDefaultVMArguments(java.io.File)
151
	 * Returns the definition file associated with the given VM or <code>null</code>
152
	 * if none.
153
	 * 
154
	 * @param vm VM install
155
	 * @return definition file or <code>null</code> if none. The file may/may not exist.
156
	 */
157
	public static File getDefinitionFile(IVMInstall vm) {
158
		if (vm instanceof AbstractVMInstall) {
159
			AbstractVMInstall avm = (AbstractVMInstall) vm;
160
			String path = avm.getAttribute(EEVMInstall.ATTR_DEFINITION_FILE);
161
			if (path != null) {
162
				return new File(path);
163
			}
164
		}
165
		return null;
166
	}
167
	
168
	/**
169
	 * Returns VM arguments defined in the given definition file or <code>null</code> if none.
170
	 * 
171
	 * @param eeFile definition file
172
	 * @return VM arguments or <code>null</code> if none
151
	 */
173
	 */
152
	public static String getDefaultVMArguments(File installLocation) {
174
	public static String getVMArguments(File eeFile) {
153
		Map properties = getProperties(installLocation);
175
		Map properties = getProperties(eeFile);
154
		if (properties != null) {
176
		if (properties != null) {
155
			List args = (List) fgArguments.get(installLocation);
177
			List args = (List) fgArguments.get(eeFile);
156
			StringBuffer buf = new StringBuffer();
178
			StringBuffer buf = new StringBuffer();
157
			Iterator iterator = args.iterator();
179
			Iterator iterator = args.iterator();
158
			while (iterator.hasNext()) {
180
			while (iterator.hasNext()) {
Lines 185-204 Link Here
185
		return Path.EMPTY;
207
		return Path.EMPTY;
186
	}
208
	}
187
209
188
	/* (non-Javadoc)
210
	/**
189
	 * @see org.eclipse.jdt.launching.IVMInstallType#validateInstallLocation(java.io.File)
211
	 * Returns a status indicating if the given definition file is valid.
212
	 * 
213
	 * @param eeFile definition file
214
	 * @return status indicating if the given definition file is valid
190
	 */
215
	 */
191
	public static IStatus validateInstallLocation(File installLocation) {
216
	public static IStatus validateDefinitionFile(File eeFile) {
192
		Map properties = getProperties(installLocation);
217
		Map properties = getProperties(eeFile);
193
		if (properties == null) {
218
		if (properties == null) {
194
			return new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), MessageFormat.format(LaunchingMessages.EEVMType_0, new String[]{installLocation.getName()} ));
219
			return new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), MessageFormat.format(LaunchingMessages.EEVMType_0, new String[]{eeFile.getName()} ));
195
		}
220
		}
196
		// validate required properties
221
		// validate required properties
197
		for (int i = 0; i < REQUIRED_PROPERTIES.length; i++) {
222
		for (int i = 0; i < REQUIRED_PROPERTIES.length; i++) {
198
			String key = REQUIRED_PROPERTIES[i];
223
			String key = REQUIRED_PROPERTIES[i];
199
			String property = (String) properties.get(key);
224
			String property = (String) properties.get(key);
200
			if (property == null) {
225
			if (property == null) {
201
				return new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), MessageFormat.format(LaunchingMessages.EEVMType_1, new String[]{installLocation.getName(), key} ));
226
				return new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), MessageFormat.format(LaunchingMessages.EEVMType_1, new String[]{eeFile.getName(), key} ));
202
			}
227
			}
203
		}
228
		}
204
		return Status.OK_STATUS;
229
		return Status.OK_STATUS;
Lines 209-215 Link Here
209
	 * is considered first.
234
	 * is considered first.
210
	 * 
235
	 * 
211
	 * @param installLocation ee file
236
	 * @param installLocation ee file
212
	 * @return standard executable
237
	 * @return standard executable or <code>null</code> if none
213
	 */
238
	 */
214
	public static File getExecutable(File installLocation) { 
239
	public static File getExecutable(File installLocation) { 
215
		String property = getProperty(PROP_EXECUTABLE, installLocation);
240
		String property = getProperty(PROP_EXECUTABLE, installLocation);
Lines 320-323 Link Here
320
		}
345
		}
321
		return null;
346
		return null;
322
	}
347
	}
348
349
	/* (non-Javadoc)
350
	 * @see org.eclipse.jdt.launching.AbstractVMInstallType#doCreateVMInstall(java.lang.String)
351
	 */
352
	protected IVMInstall doCreateVMInstall(String id) {
353
		return new EEVMInstall(this, id);
354
	}
355
356
	/* (non-Javadoc)
357
	 * @see org.eclipse.jdt.launching.IVMInstallType#detectInstallLocation()
358
	 */
359
	public File detectInstallLocation() {
360
		return null;
361
	}
362
363
	/* (non-Javadoc)
364
	 * @see org.eclipse.jdt.launching.IVMInstallType#getDefaultLibraryLocations(java.io.File)
365
	 */
366
	public LibraryLocation[] getDefaultLibraryLocations(File installLocationOrDefinitionFile) {
367
		return new LibraryLocation[0];
368
	}
369
370
	/* (non-Javadoc)
371
	 * @see org.eclipse.jdt.launching.IVMInstallType#getName()
372
	 */
373
	public String getName() {
374
		// TODO:
375
		return "Execution Environment Description";
376
	}
377
378
	/* (non-Javadoc)
379
	 * @see org.eclipse.jdt.launching.IVMInstallType#validateInstallLocation(java.io.File)
380
	 */
381
	public IStatus validateInstallLocation(File installLocationOrDefinitionFile) {
382
		return new Status(IStatus.INFO, LaunchingPlugin.getUniqueIdentifier(), "Unable to validate install location.");
383
	}
323
}
384
}
(-)launching/org/eclipse/jdt/internal/launching/StandardVMType.java (-31 / +7 lines)
Lines 79-87 Link Here
79
	 * <code>null</code>.
79
	 * <code>null</code>.
80
	 */
80
	 */
81
	public static File findJavaExecutable(File vmInstallLocation) {
81
	public static File findJavaExecutable(File vmInstallLocation) {
82
		if (EEVMType.isEEInstall(vmInstallLocation)) {
83
			return EEVMType.getExecutable(vmInstallLocation);
84
		}
85
		// Try each candidate in order.  The first one found wins.  Thus, the order
82
		// Try each candidate in order.  The first one found wins.  Thus, the order
86
		// of fgCandidateJavaLocations and fgCandidateJavaFiles is significant.
83
		// of fgCandidateJavaLocations and fgCandidateJavaFiles is significant.
87
		for (int i = 0; i < fgCandidateJavaFiles.length; i++) {
84
		for (int i = 0; i < fgCandidateJavaFiles.length; i++) {
Lines 282-291 Link Here
282
	 * @see org.eclipse.jdt.launching.IVMInstallType#getDefaultLibraryLocations(File)
279
	 * @see org.eclipse.jdt.launching.IVMInstallType#getDefaultLibraryLocations(File)
283
	 */
280
	 */
284
	public LibraryLocation[] getDefaultLibraryLocations(File installLocation) {
281
	public LibraryLocation[] getDefaultLibraryLocations(File installLocation) {
285
		if (EEVMType.isEEInstall(installLocation)) {
286
			return EEVMType.getDefaultLibraryLocations(installLocation);
287
		}
288
289
		// Determine the java executable that corresponds to the specified install location
282
		// Determine the java executable that corresponds to the specified install location
290
		// and use this to generate library information.  If no java executable was found, 
283
		// and use this to generate library information.  If no java executable was found, 
291
		// the 'standard' libraries will be returned.
284
		// the 'standard' libraries will be returned.
Lines 446-454 Link Here
446
	 * @see org.eclipse.jdt.launching.IVMInstallType#validateInstallLocation(java.io.File)
439
	 * @see org.eclipse.jdt.launching.IVMInstallType#validateInstallLocation(java.io.File)
447
	 */
440
	 */
448
	public IStatus validateInstallLocation(File javaHome) {
441
	public IStatus validateInstallLocation(File javaHome) {
449
		if (EEVMType.isEEInstall(javaHome)) {
450
			return EEVMType.validateInstallLocation(javaHome);
451
		}
452
		IStatus status = null;
442
		IStatus status = null;
453
		if (Platform.getOS().equals(Constants.OS_MACOSX)) {
443
		if (Platform.getOS().equals(Constants.OS_MACOSX)) {
454
			status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), 0, LaunchingMessages.StandardVMType_Standard_VM_not_supported_on_MacOS__1, null); 
444
			status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), 0, LaunchingMessages.StandardVMType_Standard_VM_not_supported_on_MacOS__1, null); 
Lines 602-630 Link Here
602
	 * @see org.eclipse.jdt.launching.AbstractVMInstallType#getDefaultJavadocLocation(java.io.File)
592
	 * @see org.eclipse.jdt.launching.AbstractVMInstallType#getDefaultJavadocLocation(java.io.File)
603
	 */
593
	 */
604
	public URL getDefaultJavadocLocation(File installLocation) {
594
	public URL getDefaultJavadocLocation(File installLocation) {
605
		if (EEVMType.isEEInstall(installLocation)) {
595
		File javaExecutable = findJavaExecutable(installLocation);
606
			return EEVMType.getDefaultJavadocLocation(installLocation);
596
		if (javaExecutable != null) {
607
		} else {
597
			LibraryInfo libInfo = getLibraryInfo(installLocation, javaExecutable);
608
			File javaExecutable = findJavaExecutable(installLocation);
598
			if (libInfo != null) {
609
			if (javaExecutable != null) {
599
				String version = libInfo.getVersion();
610
				LibraryInfo libInfo = getLibraryInfo(installLocation, javaExecutable);
600
				return getDefaultJavadocLocation(version);
611
				if (libInfo != null) {
612
					String version = libInfo.getVersion();
613
					return getDefaultJavadocLocation(version);
614
				}
615
			}
601
			}
616
			return null;
617
		}
602
		}
618
	}
603
		return null;
619
620
	/* (non-Javadoc)
621
	 * @see org.eclipse.jdt.launching.AbstractVMInstallType#getDefaultVMArguments(java.io.File)
622
	 */
623
	public String getDefaultVMArguments(File installLocation) {
624
		if (EEVMType.isEEInstall(installLocation)) {
625
			return EEVMType.getDefaultVMArguments(installLocation);
626
		}
627
		return super.getDefaultVMArguments(installLocation);
628
	}
604
	}
629
605
630
	/**
606
	/**
(-)launching/org/eclipse/jdt/launching/IVMInstall.java (-15 / +4 lines)
Lines 68-95 Link Here
68
	void setName(String name);
68
	void setName(String name);
69
	/**
69
	/**
70
	 * Returns the root directory of the install location of this VM.
70
	 * Returns the root directory of the install location of this VM.
71
	 * <p>
71
	 * 
72
	 * Since 3.4, this may also be a file describing a VM install.
73
	 * For example, the standard VM installs support execution
74
	 * environment description files, as described by
75
	 * <code>http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions</code>.
76
	 * </p>
77
	 * @return the root directory of this VM installation. May
72
	 * @return the root directory of this VM installation. May
78
	 * 			return <code>null</code>.
73
	 * 			return <code>null</code>.
79
	 */
74
	 */
80
	File getInstallLocation();
75
	File getInstallLocation();
81
	/**
76
	/**
82
	 * Sets the root directory of the install location of this VM.
77
	 * Sets the root directory of the install location of this VM.
83
	 * <p>
78
	 * 
84
	 * Since 3.4, this may also be a file describing a VM install.
79
	 * @param installLocation the root directory of this VM installation
85
	 * For example, the standard VM installs support execution
86
	 * environment description files, as described by
87
	 * <code>http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions</code>.
88
	 * </p>
89
	 * @param installLocationOrDefinitionFile the root directory or definition file for
90
	 * 	this VM installation
91
	 */
80
	 */
92
	void setInstallLocation(File installLocationOrDefinitionFile);
81
	void setInstallLocation(File installLocation);
93
		
82
		
94
	/**
83
	/**
95
	 * Returns the VM type of this VM.
84
	 * Returns the VM type of this VM.
(-)launching/org/eclipse/jdt/launching/AbstractVMInstallType.java (-11 / +5 lines)
Lines 157-185 Link Here
157
	 * implementation returns <code>null</code>, subclasses must override as
157
	 * implementation returns <code>null</code>, subclasses must override as
158
	 * appropriate.
158
	 * appropriate.
159
	 * <p>
159
	 * <p>
160
	 * Since 3.4, the argument may also be a file describing a VM install.
161
	 * For example, the standard VM installs support execution
162
	 * environment description files, as described by
163
	 * <code>http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions</code>.
164
	 * </p>
165
	 * <p>
166
	 * Note, this method would ideally be added to <code>IVMInstallType</code>,
160
	 * Note, this method would ideally be added to <code>IVMInstallType</code>,
167
	 * but it would have been a breaking API change between 2.0 and 2.1. Thus,
161
	 * but it would have been a breaking API change between 2.0 and 2.1. Thus,
168
	 * it has been added to the abstract base class that VM install types should
162
	 * it has been added to the abstract base class that VM install types should
169
	 * subclass.
163
	 * subclass.
170
	 * </p>
164
	 * </p>
171
	 * 
165
	 * 
172
	 * @param installLocationOrDefinitionFile home location or since 3.4, a definition file
166
	 * @param installLocationOrDefinitionFile home location
173
	 * @return default javadoc location or <code>null</code>
167
	 * @return default javadoc location or <code>null</code>
174
	 * @since 2.1
168
	 * @since 2.1
175
	 */
169
	 */
176
	public URL getDefaultJavadocLocation(File installLocationOrDefinitionFile) {
170
	public URL getDefaultJavadocLocation(File installLocation) {
177
		return null;		
171
		return null;		
178
	}
172
	}
179
	
173
	
180
	/**
174
	/**
181
	 * Returns a string of default VM arguments for a VM installed at the
175
	 * Returns a string of default VM arguments for a VM installed at the
182
	 * given home location or definition file, or <code>null</code> if none.
176
	 * given home location, or <code>null</code> if none.
183
	 * The default implementation returns <code>null</code>, subclasses must override
177
	 * The default implementation returns <code>null</code>, subclasses must override
184
	 * as appropriate.
178
	 * as appropriate.
185
	 * <p>
179
	 * <p>
Lines 188-198 Link Here
188
	 * it has been added to the abstract base class that VM install types should
182
	 * it has been added to the abstract base class that VM install types should
189
	 * subclass.
183
	 * subclass.
190
	 * </p>
184
	 * </p>
191
	 * @param installLocationOrDefinitionFile home location or definition file
185
	 * @param installLocation home location
192
	 * @return default VM arguments or <code>null</code> if none
186
	 * @return default VM arguments or <code>null</code> if none
193
	 * @since 3.4
187
	 * @since 3.4
194
	 */
188
	 */
195
	public String getDefaultVMArguments(File installLocationOrDefinitionFile) {
189
	public String getDefaultVMArguments(File installLocation) {
196
		return null;
190
		return null;
197
	}
191
	}
198
}
192
}
(-)launching/org/eclipse/jdt/launching/VMStandin.java (-1 / +20 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.launching;
11
package org.eclipse.jdt.launching;
12
12
13
import java.util.Iterator;
14
import java.util.Map;
15
import java.util.Map.Entry;
16
13
17
14
18
15
/**
19
/**
Lines 93-98 Link Here
93
			setVMArguments(realVM.getVMArguments());
97
			setVMArguments(realVM.getVMArguments());
94
			fJavaVersion = null;
98
			fJavaVersion = null;
95
		}
99
		}
100
		if (realVM instanceof AbstractVMInstall) {
101
			AbstractVMInstall vm2 = (AbstractVMInstall) realVM;
102
			Map attributes = vm2.getAttributes();
103
			Iterator iterator = attributes.entrySet().iterator();
104
			while (iterator.hasNext()) {
105
				Entry entry = (Entry) iterator.next();
106
				setAttribute((String)entry.getKey(), (String)entry.getValue());
107
			}
108
		}
96
	}
109
	}
97
	
110
	
98
	/**
111
	/**
Lines 126-132 Link Here
126
		}
139
		}
127
		
140
		
128
		if (realVM instanceof AbstractVMInstall) {
141
		if (realVM instanceof AbstractVMInstall) {
129
			 ((AbstractVMInstall)realVM).setNotify(true);
142
			AbstractVMInstall avm = (AbstractVMInstall) realVM;
143
			Iterator iterator = getAttributes().entrySet().iterator();
144
			while (iterator.hasNext()) {
145
				Entry entry = (Entry) iterator.next();
146
				avm.setAttribute((String)entry.getKey(), (String)entry.getValue());
147
			}
148
			avm.setNotify(true);
130
		}		
149
		}		
131
		if (!notify) {
150
		if (!notify) {
132
			JavaRuntime.fireVMAdded(realVM);
151
			JavaRuntime.fireVMAdded(realVM);
(-)launching/org/eclipse/jdt/launching/IVMInstallType.java (-18 / +7 lines)
Lines 88-107 Link Here
88
	/**
88
	/**
89
	 * Validates the given location of a VM installation.
89
	 * Validates the given location of a VM installation.
90
	 * <p>
90
	 * <p>
91
	 * Since 3.4, the given installLocation may be a file (rather than a home
92
	 * directory). For example, the standard VM install type accepts execution
93
	 * environment description files, as described by
94
	 * <code>http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions</code>.
95
	 * </p> 
96
	 * <p>
97
	 * For example, an implementation might check whether the VM executable 
91
	 * For example, an implementation might check whether the VM executable 
98
	 * is present.
92
	 * is present.
99
	 * </p>
93
	 * </p>
100
	 * @param installLocationOrDefinitionFile the root directory of a potential installation for
94
	 * 
101
	 *   this type of VM or since 3.4, a file describing an installation
95
	 * @param installLocation the root directory of a potential installation for
96
	 *   this type of VM
102
	 * @return a status object describing whether the install location is valid
97
	 * @return a status object describing whether the install location is valid
103
	 */
98
	 */
104
	IStatus validateInstallLocation(File installLocationOrDefinitionFile);
99
	IStatus validateInstallLocation(File installLocation);
105
	
100
	
106
	/**
101
	/**
107
	 * Tries to detect an installed VM that matches this VM install type.
102
	 * Tries to detect an installed VM that matches this VM install type.
Lines 120-138 Link Here
120
	 * at the given <code>installLocation</code>.
115
	 * at the given <code>installLocation</code>.
121
	 * The returned <code>LibraryLocation</code>s may not exist if the
116
	 * The returned <code>LibraryLocation</code>s may not exist if the
122
	 * <code>installLocation</code> is not a valid install location.
117
	 * <code>installLocation</code> is not a valid install location.
123
	 * <p>
118
	 * 
124
	 * Since 3.4, the given installLocation may be a file (rather than a home
119
	 * @param installLocation home location
125
	 * directory). For example, the standard VM install type accepts execution
126
	 * environment description files, as described by
127
	 * <code>http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions</code>.
128
	 * </p> 
129
	 * @param installLocationOrDefinitionFile home directory or since 3.4, a file
130
	 * 	describing an installation
131
	 * @see LibraryLocation
120
	 * @see LibraryLocation
132
	 * @see IVMInstallType#validateInstallLocation(File)
121
	 * @see IVMInstallType#validateInstallLocation(File)
133
	 * 
122
	 * 
134
	 * @return default library locations based on the given <code>installLocation</code>.
123
	 * @return default library locations based on the given <code>installLocation</code>.
135
	 * @since 2.0
124
	 * @since 2.0
136
	 */
125
	 */
137
	LibraryLocation[] getDefaultLibraryLocations(File installLocationOrDefinitionFile);	
126
	LibraryLocation[] getDefaultLibraryLocations(File installLocation);	
138
}
127
}
(-)launching/org/eclipse/jdt/launching/AbstractVMInstall.java (+57 lines)
Lines 55-60 Link Here
55
	private LibraryLocation[] fSystemLibraryDescriptions;
55
	private LibraryLocation[] fSystemLibraryDescriptions;
56
	private URL fJavadocLocation;
56
	private URL fJavadocLocation;
57
	private String fVMArgs;
57
	private String fVMArgs;
58
	/**
59
	 * Map VM specific attributes that are persisted restored with a VM install.
60
	 * @since 3.4
61
	 */
62
	private Map fAttributeMap = new HashMap();
63
	
58
	// system properties are cached in user preferences prefixed with this key, followed
64
	// system properties are cached in user preferences prefixed with this key, followed
59
	// by vm type, vm id, and system property name
65
	// by vm type, vm id, and system property name
60
	private static final String PREF_VM_INSTALL_SYSTEM_PROPERTY = "PREF_VM_INSTALL_SYSTEM_PROPERTY"; //$NON-NLS-1$
66
	private static final String PREF_VM_INSTALL_SYSTEM_PROPERTY = "PREF_VM_INSTALL_SYSTEM_PROPERTY"; //$NON-NLS-1$
Lines 484-488 Link Here
484
		throw new CoreException(new Status(IStatus.ERROR, LaunchingPlugin
490
		throw new CoreException(new Status(IStatus.ERROR, LaunchingPlugin
485
				.getUniqueIdentifier(), code, message, exception));
491
				.getUniqueIdentifier(), code, message, exception));
486
	}	
492
	}	
493
	
494
	/**
495
	 * Sets a VM specific attribute. Attributes are persisted and restored with VM installs.
496
	 * Specifying a value of <code>null</code> as a value removes the attribute. Change
497
	 * notification is provided to {@link IVMInstallChangedListener} for VM attributes.
498
	 * 
499
	 * @param key attribute key, cannot be <code>null</code>
500
	 * @param value attribute value or <code>null</code> to remove the attribute
501
	 * @since 3.4
502
	 */
503
	public void setAttribute(String key, String value) {
504
		String prevValue = (String) fAttributeMap.remove(key);
505
		boolean notify = false;
506
		if (value == null) {
507
			if (prevValue != null && fNotify) {
508
				notify = true;
509
			}
510
		} else {
511
			fAttributeMap.put(key, value);
512
			if (fNotify && (prevValue == null || !prevValue.equals(value))) {
513
				notify = true;
514
			}
515
		}
516
		if (notify) {
517
			PropertyChangeEvent event = new PropertyChangeEvent(this, key, prevValue, value);
518
			JavaRuntime.fireVMChanged(event);
519
		}
520
	}
487
    
521
    
522
	/**
523
	 * Returns a VM specific attribute associated with the given key or <code>null</code> 
524
	 * if none.
525
	 * 
526
	 * @param key attribute key, cannot be <code>null</code>
527
	 * @return attribute value, or <code>null</code> if none
528
	 * @since 3.4
529
	 */
530
	public String getAttribute(String key) {
531
		return (String) fAttributeMap.get(key);
532
	}
533
	
534
	/**
535
	 * Returns a map of VM specific attributes stored with this VM install. Keys
536
	 * and values are strings. Modifying the map does not modify the attributes
537
	 * associated with this VM install.
538
	 * 
539
	 * @return map of VM attributes
540
	 * @since 3.4
541
	 */
542
	public Map getAttributes() {
543
		return new HashMap(fAttributeMap);
544
	}
488
}
545
}
(-)launching/org/eclipse/jdt/launching/JavaRuntime.java (-1 / +48 lines)
Lines 59-64 Link Here
59
import org.eclipse.jdt.internal.launching.CompositeId;
59
import org.eclipse.jdt.internal.launching.CompositeId;
60
import org.eclipse.jdt.internal.launching.DefaultEntryResolver;
60
import org.eclipse.jdt.internal.launching.DefaultEntryResolver;
61
import org.eclipse.jdt.internal.launching.DefaultProjectClasspathEntry;
61
import org.eclipse.jdt.internal.launching.DefaultProjectClasspathEntry;
62
import org.eclipse.jdt.internal.launching.EEVMInstall;
63
import org.eclipse.jdt.internal.launching.EEVMType;
62
import org.eclipse.jdt.internal.launching.JREContainerInitializer;
64
import org.eclipse.jdt.internal.launching.JREContainerInitializer;
63
import org.eclipse.jdt.internal.launching.JavaSourceLookupUtil;
65
import org.eclipse.jdt.internal.launching.JavaSourceLookupUtil;
64
import org.eclipse.jdt.internal.launching.LaunchingMessages;
66
import org.eclipse.jdt.internal.launching.LaunchingMessages;
Lines 1592-1598 Link Here
1592
		LibraryLocation[] locations= vm.getLibraryLocations();
1594
		LibraryLocation[] locations= vm.getLibraryLocations();
1593
		if (locations == null) {
1595
		if (locations == null) {
1594
            URL defJavaDocLocation = vm.getJavadocLocation(); 
1596
            URL defJavaDocLocation = vm.getJavadocLocation(); 
1595
			LibraryLocation[] dflts= vm.getVMInstallType().getDefaultLibraryLocations(vm.getInstallLocation());
1597
			File installLocation = vm.getInstallLocation();
1598
			if (installLocation == null) {
1599
				return new LibraryLocation[0];
1600
			}
1601
			LibraryLocation[] dflts= vm.getVMInstallType().getDefaultLibraryLocations(installLocation);
1596
			libraryPaths = new IPath[dflts.length];
1602
			libraryPaths = new IPath[dflts.length];
1597
			sourcePaths = new IPath[dflts.length];
1603
			sourcePaths = new IPath[dflts.length];
1598
			sourceRootPaths = new IPath[dflts.length];
1604
			sourceRootPaths = new IPath[dflts.length];
Lines 2654-2658 Link Here
2654
            }
2660
            }
2655
        }		
2661
        }		
2656
	}
2662
	}
2663
	
2664
	/**
2665
	 * Creates a new VM based on the attributes specified in the given execution 
2666
	 * environment description file. The format of the file is defined by
2667
	 * <code>http://wiki.eclipse.org/index.php/Execution_Environment_Descriptions</code>.
2668
	 * 
2669
	 * @param eeFile VM definition file
2670
	 * @param name name for the VM
2671
	 * @param id id to assign to the new VM
2672
	 * @return VM standin 
2673
	 * @exception CoreException if unable to create a VM from the given definition file
2674
	 * @since 3.4
2675
	 */
2676
	public static VMStandin createVMFromDefinitionFile(File eeFile, String name, String id) throws CoreException {
2677
		IStatus status = EEVMType.validateDefinitionFile(eeFile);
2678
		if (status.isOK()) {
2679
			VMStandin standin = new VMStandin(getVMInstallType(EEVMType.ID_EE_VM_TYPE), id);
2680
			standin.setName(name);
2681
			String home = EEVMType.getProperty(EEVMType.PROP_JAVA_HOME, eeFile);
2682
			standin.setInstallLocation(new File(home));
2683
			standin.setLibraryLocations(EEVMType.getLibraryLocations(eeFile));
2684
			standin.setVMArgs(EEVMType.getVMArguments(eeFile));
2685
			standin.setJavadocLocation(EEVMType.getJavadocLocation(eeFile));
2686
			standin.setAttribute(EEVMInstall.ATTR_EXECUTION_ENVIRONMENT_ID, EEVMType.getProperty(EEVMType.PROP_CLASS_LIB_LEVEL, eeFile));
2687
			File exe = EEVMType.getExecutable(eeFile);
2688
			if (exe != null) {
2689
				try {
2690
					standin.setAttribute(EEVMInstall.ATTR_JAVA_EXE, exe.getCanonicalPath());
2691
				} catch (IOException e) {
2692
					throw new CoreException(new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(),
2693
							"Failed to create VM install", e));
2694
				}
2695
			}
2696
			standin.setAttribute(EEVMInstall.ATTR_JAVA_VERSION, EEVMType.getJavaVersion(eeFile));
2697
			standin.setAttribute(EEVMInstall.ATTR_DEFINITION_FILE, eeFile.getPath());
2698
			standin.setVMArgs(EEVMType.getVMArguments(eeFile));
2699
			return standin;
2700
		} else {
2701
			throw new CoreException(status);
2702
		}
2703
	}
2657
2704
2658
}
2705
}
(-)launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironmentAnalyzer.java (-2 / +3 lines)
Lines 18-23 Link Here
18
18
19
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.jdt.internal.launching.EEVMInstall;
21
import org.eclipse.jdt.internal.launching.EEVMType;
22
import org.eclipse.jdt.internal.launching.EEVMType;
22
import org.eclipse.jdt.launching.IVMInstall;
23
import org.eclipse.jdt.launching.IVMInstall;
23
import org.eclipse.jdt.launching.IVMInstall2;
24
import org.eclipse.jdt.launching.IVMInstall2;
Lines 72-79 Link Here
72
			return new CompatibleEnvironment[0];
73
			return new CompatibleEnvironment[0];
73
		IVMInstall2 vm2 = (IVMInstall2) vm;
74
		IVMInstall2 vm2 = (IVMInstall2) vm;
74
		List types = null;
75
		List types = null;
75
		if (EEVMType.isEEInstall(vm.getInstallLocation())) {
76
		if (EEVMType.ID_EE_VM_TYPE.equals(vm.getVMInstallType().getId())) {
76
			String eeId = EEVMType.getProperty(EEVMType.PROP_CLASS_LIB_LEVEL, vm.getInstallLocation());
77
			String eeId = ((EEVMInstall)vm).getAttribute(EEVMInstall.ATTR_EXECUTION_ENVIRONMENT_ID);
77
			if (eeId != null) {
78
			if (eeId != null) {
78
				types = getTypes(eeId);
79
				types = getTypes(eeId);
79
			}
80
			}
(-)launching/org/eclipse/jdt/internal/launching/EEVMInstall.java (+74 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.launching;
12
13
import java.io.File;
14
15
import org.eclipse.jdt.launching.IVMInstallType;
16
17
/**
18
 * A VM install created from an execution environment description file.
19
 * 
20
 * @since 3.4
21
 */
22
public class EEVMInstall extends StandardVM {
23
	
24
	/**
25
	 * Attribute key for Java version property
26
	 */
27
	public static final String ATTR_JAVA_VERSION = "ATTR_JAVA_VERSION"; //$NON-NLS-1$
28
	
29
	/**
30
	 * Attribute key for supported execution environment by this runtime
31
	 */
32
	public static final String ATTR_EXECUTION_ENVIRONMENT_ID = "ATTR_EXECUTION_ENVIRONMENT_ID"; //$NON-NLS-1$
33
	
34
	/**
35
	 * Attribute key for Java executable used by this VM
36
	 */
37
	public static final String ATTR_JAVA_EXE = "ATTR_JAVA_EXE"; //$NON-NLS-1$
38
39
	/**
40
	 * Path to file used to define the JRE
41
	 */
42
	public static final String ATTR_DEFINITION_FILE = "ATTR_DEFINITION_FILE"; //$NON-NLS-1$
43
	
44
	/**
45
	 * Constructs a VM install.
46
	 * 
47
	 * @param type vm type
48
	 * @param id unique id
49
	 */
50
	EEVMInstall(IVMInstallType type, String id) {
51
		super(type, id);
52
	}
53
54
	/* (non-Javadoc)
55
	 * @see org.eclipse.jdt.internal.launching.StandardVM#getJavaVersion()
56
	 */
57
	public String getJavaVersion() {
58
    	return getAttribute(ATTR_JAVA_VERSION);
59
	}
60
61
	/* (non-Javadoc)
62
	 * @see org.eclipse.jdt.internal.launching.StandardVM#getJavaExecutable()
63
	 */
64
	File getJavaExecutable() {
65
		String exe = getAttribute(ATTR_JAVA_EXE);
66
		if (exe != null) {
67
			return new File(exe);
68
		}
69
		return null;
70
	}
71
	
72
	
73
74
}

Return to bug 201758