Commits

Anonymous committed 5dce0d6

Read the eclipse platform location from the workspace, if available. Otherwise, allow to use a system property to locate the platform.

Comments (0)

Files changed (3)

project/src/org/netbeans/modules/eclipse/project/EclipsePlatform.java

 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.WeakHashMap;
 import java.util.jar.Manifest;
 import java.util.prefs.PreferenceChangeEvent;
 import java.util.prefs.PreferenceChangeListener;
     }
 
     private static synchronized void defaultPlatformUpdated() {
-        String location = NbPreferences.forModule(EclipsePlatform.class).get(KEY_DEFAULT_PLATFORM_LOCATION, "");
+        String location = NbPreferences.forModule(EclipsePlatform.class).get(KEY_DEFAULT_PLATFORM_LOCATION, System.getProperty("eclipse.platform.dir"));
         File locationFile = !location.isEmpty() ? new File(location) : null;
 
         if (locationFile != null && locationFile.isDirectory()) {
-            INSTANCE.setValue(new EclipsePlatform(locationFile));
+            INSTANCE.setValue(new EclipsePlatform(FileUtil.toFileObject(locationFile)));
         } else {
             INSTANCE.setValue(null);
         }
     }
 
+    private static final Map<FileObject, Reference<Property<EclipsePlatform>>> workspaceRoot2Platform = new WeakHashMap<FileObject, Reference<Property<EclipsePlatform>>>();
+
+    public static Property<EclipsePlatform> getPlatform(FileObject platformRoot) {
+        Reference<Property<EclipsePlatform>> platformRef = workspaceRoot2Platform.get(platformRoot);
+        Property<EclipsePlatform> platform = platformRef != null ? platformRef.get() : null;
+
+        if (platform == null) {
+            workspaceRoot2Platform.put(platformRoot, new WeakReference<Property<EclipsePlatform>>(platform = new Property<EclipsePlatform>()));
+            platform.setValue(new EclipsePlatform(platformRoot));
+        }
+
+        return platform;
+    }
+
     private final FileObject platformRoot;
     private final Map<String, Collection<URL>> bundleName2BundleJars;
     private final Map<String, URL> exportedPackage2BundleJars;
     private final Map<URL, Result> binary2SourceResult;
 
-    private EclipsePlatform(File locationFile) {
-        platformRoot = FileUtil.toFileObject(locationFile);
+    private EclipsePlatform(FileObject platformRoot) {
+        this.platformRoot = platformRoot;
         bundleName2BundleJars = new HashMap<String, Collection<URL>>();
         exportedPackage2BundleJars = new HashMap<String, URL>();
         binary2SourceResult = new HashMap<URL, Result>();

project/src/org/netbeans/modules/eclipse/project/EclipseProjectImpl.java

 import org.netbeans.spi.project.ui.LogicalViewProvider;
 import org.netbeans.spi.project.ui.ProjectOpenedHook;
 import org.openide.filesystems.FileObject;
+import org.openide.filesystems.URLMapper;
 import org.openide.nodes.AbstractNode;
 import org.openide.nodes.ChildFactory;
 import org.openide.nodes.Children;
     public EclipseProjectImpl(EclipseProject imported, FileObject projectDir) throws MalformedURLException {
         this.imported = imported;
         this.projectDir = projectDir;
-        this.platform = EclipsePlatform.getDefault();
+        String osgiInstall = imported.getWorkspace() != null ? imported.getWorkspace().osgiInstall() : null;
+        FileObject osgiInstallFile = osgiInstall != null ? URLMapper.findFileObject(new URL(osgiInstall)) : null;
+        this.platform = osgiInstallFile != null ? EclipsePlatform.getPlatform(osgiInstallFile) : EclipsePlatform.getDefault();
         ClassPath source = computeCP(projectDir, platform, imported.getSourceRoots());
         ClassPath compile = computeCP(projectDir, platform, imported.getClassPathEntries());
         File output = new File(imported.getOutput().getAbsolutePath());

project/src/org/netbeans/modules/eclipse/project/borrowed/Workspace.java

             ".metadata/.plugins/org.eclipse.core.runtime/.settings/"; //NOI18N
     static final String CORE_PREFERENCE =
             RUNTIME_SETTINGS + "org.eclipse.jdt.core.prefs"; //NOI18N
+    static final String PDE_CORE_PREFERENCE =
+            ".metadata/.plugins/org.eclipse.pde.core/Eclipse Application/config.ini"; //NOI18N
     static final String RESOURCES_PREFERENCE =
             RUNTIME_SETTINGS + "org.eclipse.core.resources.prefs"; //NOI18N
     static final String LAUNCHING_PREFERENCES =
             ".metadata/.plugins/org.eclipse.jst.jsf.core/JSFLibraryRegistryV2.xml"; //NOI18N
     
     private File corePrefFile;
+    private File pdeCorePrefFile;
     private File resourcesPrefFile;
     private File launchingPrefsFile;
     private File resourceProjectsDir;
     Workspace(File workspaceDir) {
         this.workspaceDir = workspaceDir;
         corePrefFile = new File(workspaceDir, CORE_PREFERENCE);
+        pdeCorePrefFile = new File(workspaceDir, PDE_CORE_PREFERENCE);
         resourcesPrefFile = new File(workspaceDir, RESOURCES_PREFERENCE);
         launchingPrefsFile = new File(workspaceDir, LAUNCHING_PREFERENCES);
         resourceProjectsDir = new File(workspaceDir, RESOURCE_PROJECTS_DIR);
             }
         }
     }
+
+    public String osgiInstall() {
+        Properties p = new Properties();
+        EclipseUtils.tryLoad(p, pdeCorePrefFile);
+        for (Map.Entry e : p.entrySet()) {
+            String key = (String)e.getKey();
+            String value = (String)e.getValue();
+            if ("osgi.install.area".equals(key)) { //NOI18N
+                return value;
+            }
+        }
+
+        return null;
+    }
     
     private List<String> parseLibDefinition(String s) {
         List<String> res = new ArrayList<String>();