Bug 462404: New Eclipse.app layout: "Import > From Existing
Installation" doesn't accept app bundle

When Mac app bundle is provided try to drill down to Contents/Eclipse
folder if it exists.

Change-Id: I29844aed359b1b062cf209675a993e1ba06d09d3
Signed-off-by: Lakshmi Shanmugam <lshanmug@in.ibm.com>
diff --git a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/AbstractPage.java b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/AbstractPage.java
index f06ddde..e998dc8 100644
--- a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/AbstractPage.java
+++ b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/AbstractPage.java
@@ -324,6 +324,7 @@
 			public void keyPressed(KeyEvent e) {
 				if (e.character == SWT.CR) {
 					entryChanged = false;
+					modifyDestinationValue(getDestinationValue());
 					handleDestinationChanged(getDestinationValue());
 				}
 			}
@@ -757,4 +758,9 @@
 	protected void addDestinationItem(String value) {
 		destinationNameField.add(value);
 	}
+
+	void modifyDestinationValue(String destinationValue) {
+		//Do nothing
+	}
+
 }
\ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/ImportFromInstallationPage.java b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/ImportFromInstallationPage.java
index fc33368..3b78745 100644
--- a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/ImportFromInstallationPage.java
+++ b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/ImportFromInstallationPage.java
@@ -282,7 +282,7 @@
 		final String selectedFileName = dialog.open();

 

 		if (selectedFileName != null) {

-			setDestinationValue(selectedFileName);

+			modifyDestinationValue(selectedFileName);

 			handleDestinationChanged(selectedFileName);

 		}

 	}

@@ -325,6 +325,24 @@
 	}

 

 	@Override

+	void modifyDestinationValue(String selectedFileName) {

+		/*

+		 * If the destination file is a Mac app bundle, modify the destination 

+		 * to *.app/Contents/Eclipse if the path exists.

+		 */

+		if ("cocoa".equals(SWT.getPlatform())) { //$NON-NLS-1$

+			Path nPath = new Path(selectedFileName);

+			if (nPath.lastSegment().endsWith(".app")) { //$NON-NLS-1$

+				IPath appendedPath = nPath.append("Contents").append("Eclipse");//$NON-NLS-1$ //$NON-NLS-2$

+				if (appendedPath.toFile().exists()) {

+					selectedFileName = appendedPath.toOSString();

+				}

+			}

+		}

+		setDestinationValue(selectedFileName);

+	}

+

+	@Override

 	protected boolean validDestination() {

 		if (this.destinationNameField == null)

 			return true;