Write initial features file at startup to ensure it exists prior to any user installation
--- a/core/com.nokia.carbide.cpp/META-INF/MANIFEST.MF Wed Aug 25 17:55:05 2010 -0500
+++ b/core/com.nokia.carbide.cpp/META-INF/MANIFEST.MF Wed Aug 25 20:02:15 2010 -0500
@@ -14,6 +14,7 @@
org.eclipse.core.filesystem,
org.eclipse.ui.ide,
org.eclipse.cdt.core,
+ com.nokia.carbide.discovery.ui;bundle-version="1.0.0",
org.eclipse.equinox.p2.ui;bundle-version="2.0.0",
com.nokia.carbide.cpp.featureTracker
Bundle-ActivationPolicy: lazy
--- a/core/com.nokia.carbide.cpp/src/com/nokia/carbide/cpp/ProductPlugin.java Wed Aug 25 17:55:05 2010 -0500
+++ b/core/com.nokia.carbide.cpp/src/com/nokia/carbide/cpp/ProductPlugin.java Wed Aug 25 20:02:15 2010 -0500
@@ -16,12 +16,15 @@
*/
package com.nokia.carbide.cpp;
+import java.io.File;
+
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import com.nokia.carbide.cpp.internal.featureTracker.FeatureUseTrackerConsts;
import com.nokia.carbide.cpp.internal.featureTracker.FeatureUseTrackerPlugin;
+import com.nokia.carbide.internal.discovery.ui.wizard.P2Utils;
/**
* The main plugin class to be used in the desktop.
@@ -43,6 +46,10 @@
*/
public void start(BundleContext context) throws Exception {
super.start(context);
+ File file = P2Utils.getInitialFeaturesFile();
+ if (!file.exists()) {
+ P2Utils.writeFeaturesToFile(file);
+ }
FeatureUseTrackerPlugin.getFeatureUseProxy().startUsingFeature(FeatureUseTrackerConsts.CARBIDE_IDE);
}
--- a/core/com.nokia.carbide.discovery.ui/META-INF/MANIFEST.MF Wed Aug 25 17:55:05 2010 -0500
+++ b/core/com.nokia.carbide.discovery.ui/META-INF/MANIFEST.MF Wed Aug 25 20:02:15 2010 -0500
@@ -30,4 +30,5 @@
com.nokia.carbide.internal.discovery.ui.command;x-internal:=true,
com.nokia.carbide.internal.discovery.ui.editor;x-internal:=true,
com.nokia.carbide.internal.discovery.ui.extension;x-internal:=true,
- com.nokia.carbide.internal.discovery.ui.view;x-internal:=true
+ com.nokia.carbide.internal.discovery.ui.view;x-internal:=true,
+ com.nokia.carbide.internal.discovery.ui.wizard;x-friends:="com.nokia.carbide.cpp"
--- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/discovery/ui/Messages.java Wed Aug 25 17:55:05 2010 -0500
+++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/discovery/ui/Messages.java Wed Aug 25 20:02:15 2010 -0500
@@ -68,7 +68,6 @@
public static String ExportWizard_ReadInstalledFeaturesError;
public static String ExportWizard_Title;
public static String ExportWizard_WriteFileError;
- public static String ExportWizard_WriteInstalledFeaturesError;
public static String FeatureInstallOperation_ConfiguringTaskName;
public static String FeatureInstallOperation_IdLabel;
public static String FeatureInstallOperation_MissingFeaturesError;
@@ -96,6 +95,7 @@
public static String InstallExtensionsPortalExtension_ExportActionLabel;
public static String InstallExtensionsPortalExtension_ImportActionLabel;
public static String InstallExtensionsPortalExtension_MigrateTitle;
+ public static String P2Utils_WriteInitialFeaturesFileError;
public static String PortalEditor_BadCommandBarFactoryError;
public static String PortalEditor_Name;
public static String PortalEditor_NoLayersError;
--- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/discovery/ui/messages.properties Wed Aug 25 17:55:05 2010 -0500
+++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/discovery/ui/messages.properties Wed Aug 25 20:02:15 2010 -0500
@@ -46,7 +46,6 @@
ExportWizard_ReadInstalledFeaturesError=Could not read installed features file:
ExportWizard_Title=Export
ExportWizard_WriteFileError=Could not write export file due to error: {0}
-ExportWizard_WriteInstalledFeaturesError=Could not write installed features file:
FeatureInstallOperation_ConfiguringTaskName=Configuring install operation
FeatureInstallOperation_IdLabel=id=
FeatureInstallOperation_MissingFeaturesError=Install failed. Could not find some features: \n
@@ -74,6 +73,7 @@
InstallExtensionsPortalExtension_ExportActionLabel=Export...
InstallExtensionsPortalExtension_ImportActionLabel=Import...
InstallExtensionsPortalExtension_MigrateTitle=Migrate
+P2Utils_WriteInitialFeaturesFileError=Could not write inital features file: {0}
PortalEditor_BadCommandBarFactoryError=Command bar factory class could not be created for id: {0
PortalEditor_Name=Carbide.c++ Portal
PortalEditor_NoLayersError=Could not load portal page because no layers were found for id: {0}
--- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/wizard/ExportWizard.java Wed Aug 25 17:55:05 2010 -0500
+++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/wizard/ExportWizard.java Wed Aug 25 20:02:15 2010 -0500
@@ -22,21 +22,13 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
-import java.net.URI;
-import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;
@@ -71,42 +63,32 @@
public void init(IWorkbench workbench, IStructuredSelection selection) {
setDefaultPageImageDescriptor(Activator.getImageDescriptor("icons\\install_wiz.gif")); //$NON-NLS-1$
setWindowTitle(Messages.ExportWizard_Title);
- exportPage = new ExportPage(getFilteredFeatureIds());
+ exportPage = new ExportPage(getInitialFeatureIds());
addPage(exportPage);
}
- private Collection<String> getFilteredFeatureIds() {
+ private Collection<String> getInitialFeatureIds() {
+ // make sure it exists if not written already
+ File file = P2Utils.getInitialFeaturesFile();
+ if (!file.exists()) {
+ P2Utils.writeFeaturesToFile(file);
+ }
+
Collection<FeatureInfo> installedFeatures = null;
- Location installLocation = Platform.getInstallLocation();
- URL url = installLocation.getURL();
- IPath path = new Path(url.getPath());
- path = path.append("configuration/installedFeatures.xml"); //$NON-NLS-1$
- File file = path.toFile();
- if (!file.exists()) {
- installedFeatures = P2Utils.getInstalledFeatures(new NullProgressMonitor());
- ImportExportData data = new ImportExportData(false, Collections.<URI>emptyList(), installedFeatures);
- try {
- Streamer.writeToXML(new FileOutputStream(file), data);
- } catch (Exception e) {
- Activator.logError(Messages.ExportWizard_WriteInstalledFeaturesError + file, e);
+ try {
+ ImportExportData data = Streamer.readFromXML(new FileInputStream(file));
+ installedFeatures = data.getFeatureInfos();
+ } catch (Exception e) {
+ Activator.logError(Messages.ExportWizard_ReadInstalledFeaturesError + file, e);
+ }
+
+ Collection<String> featureIds = new ArrayList<String>();
+ if (installedFeatures != null) {
+ for (FeatureInfo featureInfo : installedFeatures) {
+ featureIds.add(featureInfo.getId());
}
}
- else {
- try {
- ImportExportData data = Streamer.readFromXML(new FileInputStream(file));
- installedFeatures = data.getFeatureInfos();
- } catch (Exception e) {
- Activator.logError(Messages.ExportWizard_ReadInstalledFeaturesError + file, e);
- }
- }
-
- Collection<String> filteredIds = new ArrayList<String>();
- if (installedFeatures != null) {
- for (FeatureInfo featureInfo : installedFeatures) {
- filteredIds.add(featureInfo.getId());
- }
- }
- return filteredIds;
+ return featureIds;
}
}
--- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/wizard/P2Utils.java Wed Aug 25 17:55:05 2010 -0500
+++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/wizard/P2Utils.java Wed Aug 25 20:02:15 2010 -0500
@@ -16,14 +16,23 @@
*/
package com.nokia.carbide.internal.discovery.ui.wizard;
+import java.io.File;
+import java.io.FileOutputStream;
import java.net.URI;
+import java.net.URL;
+import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
@@ -32,8 +41,12 @@
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
+import org.eclipse.osgi.service.datalocation.Location;
-class P2Utils {
+import com.nokia.carbide.discovery.ui.Activator;
+import com.nokia.carbide.discovery.ui.Messages;
+
+public class P2Utils {
public static Collection<URI> getKnownRepositories() {
ProvisioningUI provisioningUI = ProvisioningUI.getDefaultUI();
@@ -61,4 +74,26 @@
}
return infos;
}
+
+ public static void writeFeaturesToFile(File file) {
+ if (!file.exists()) {
+ Collection<FeatureInfo> initialFeatures = P2Utils.getInstalledFeatures(new NullProgressMonitor());
+ ImportExportData data = new ImportExportData(false, Collections.<URI>emptyList(), initialFeatures);
+ try {
+ Streamer.writeToXML(new FileOutputStream(file), data);
+ } catch (Exception e) {
+ Activator.logError(MessageFormat.format(
+ Messages.P2Utils_WriteInitialFeaturesFileError, file), e);
+ }
+ }
+ }
+
+ public static File getInitialFeaturesFile() {
+ Location installLocation = Platform.getInstallLocation();
+ URL url = installLocation.getURL();
+ IPath path = new Path(url.getPath());
+ path = path.append("configuration/initialFeatures.xml"); //$NON-NLS-1$
+ File file = path.toFile();
+ return file;
+ }
}