Re-install optional features
diff --git a/update/org.eclipse.update.core/src/org/eclipse/update/core/Feature.java b/update/org.eclipse.update.core/src/org/eclipse/update/core/Feature.java
index 9f164ba..ddbb104 100644
--- a/update/org.eclipse.update.core/src/org/eclipse/update/core/Feature.java
+++ b/update/org.eclipse.update.core/src/org/eclipse/update/core/Feature.java
@@ -262,7 +262,7 @@
IFeatureReference[] children = getIncludedFeatureReferences();
if (optionalfeatures!=null){
- children = optionalChildrenToInstall(children,optionalfeatures);
+ children = UpdateManagerUtils.optionalChildrenToInstall(children,optionalfeatures);
}
@@ -425,42 +425,6 @@
}
/**
- * Return the optional children to install
- * The optional features to install may not all be direct children
- * of the feature.
- *
- * @param children all the nested features
- * @param optionalfeatures optional features to install
- * @return IFeatureReference[]
- */
- private IFeatureReference[] optionalChildrenToInstall(IFeatureReference[] children, IFeatureReference[] optionalfeatures) {
- if (optionalfeatures.length==0) return optionalfeatures;
-
- List optionalChildrenToInstall = new ArrayList();
- for (int i = 0; i < children.length; i++) {
- IFeatureReference optionalFeature = children[i];
- if (!optionalFeature.isOptional()){
- optionalChildrenToInstall.add(optionalFeature);
- } else {
- for (int j = 0; j < optionalfeatures.length; j++) {
- if (optionalFeature.equals(optionalfeatures[j])){
- optionalChildrenToInstall.add(optionalFeature);
- break;
- }
- }
- }
- }
-
- IFeatureReference[] result = new IFeatureReference[optionalChildrenToInstall.size()];
- if (optionalChildrenToInstall.size()>0){
- optionalChildrenToInstall.toArray(result);
- }
-
- return result;
- }
-
-
- /**
* Returns an array of plug-in entries referenced by this feature
*
* @see IFeature#getPluginEntries()
diff --git a/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/ConfigurationPolicy.java b/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/ConfigurationPolicy.java
index 49e1846..475b8cb 100644
--- a/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/ConfigurationPolicy.java
+++ b/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/ConfigurationPolicy.java
@@ -47,9 +47,10 @@
* @since 2.0
*/
public boolean isConfigured(IFeatureReference featureReference) {
-
- if (featureReference==null) return false;
-
+
+ if (featureReference == null)
+ return false;
+
// returns true if the feature is part of the configured list
IFeatureReference[] refs = getConfiguredFeatures();
for (int i = 0; i < refs.length; i++) {
@@ -60,48 +61,38 @@
return false;
}
-
/**
* adds the feature to the list of features if the policy is USER_INCLUDE
*/
- public void configure(
- IFeatureReference featureReference,
- boolean callInstallHandler,
- boolean createActivity)
- throws CoreException {
+ public void configure(IFeatureReference featureReference, boolean callInstallHandler, boolean createActivity) throws CoreException {
if (isConfigured(featureReference)) // already configured
return;
-
- if (featureReference == null){
+
+ if (featureReference == null) {
UpdateManagerPlugin.warn("The feature reference to configure is null");
return;
}
-
- IFeature feature = null;
+
+ IFeature feature = null;
try {
feature = featureReference.getFeature();
- } catch (CoreException e){
+ } catch (CoreException e) {
URL url = featureReference.getURL();
- String urlString = (url!=null)?url.toExternalForm():"<no feature reference url>";
- UpdateManagerPlugin.warn("Error retrieving feature:"+urlString,e);
+ String urlString = (url != null) ? url.toExternalForm() : "<no feature reference url>";
+ UpdateManagerPlugin.warn("Error retrieving feature:" + urlString, e);
return;
}
- if (feature == null){
+ if (feature == null) {
URL url = featureReference.getURL();
- String urlString = (url!=null)?url.toExternalForm():"<no feature reference url>";
- UpdateManagerPlugin.warn("The feature to unconfigure is null: feature reference is:"+urlString);
+ String urlString = (url != null) ? url.toExternalForm() : "<no feature reference url>";
+ UpdateManagerPlugin.warn("The feature to unconfigure is null: feature reference is:" + urlString);
}
// Setup optional install handler
InstallHandlerProxy handler = null;
- if (callInstallHandler && feature.getInstallHandlerEntry()!=null)
- handler =
- new InstallHandlerProxy(
- IInstallHandler.HANDLER_ACTION_CONFIGURE,
- feature,
- feature.getInstallHandlerEntry(),
- null);
+ if (callInstallHandler && feature.getInstallHandlerEntry() != null)
+ handler = new InstallHandlerProxy(IInstallHandler.HANDLER_ACTION_CONFIGURE, feature, feature.getInstallHandlerEntry(), null);
boolean success = false;
Throwable originalException = null;
@@ -111,7 +102,7 @@
handler.configureInitiated();
ConfigurationActivity activity = null;
- if (createActivity){
+ if (createActivity) {
activity = new ConfigurationActivity(IActivity.ACTION_CONFIGURE);
activity.setLabel(feature.getVersionedIdentifier().toString());
activity.setDate(new Date());
@@ -120,12 +111,12 @@
addConfiguredFeatureReference((FeatureReferenceModel) featureReference);
// everything done ok
- if (activity!=null){
+ if (activity != null) {
InstallConfiguration installConfig = (InstallConfiguration) SiteManager.getLocalSite().getCurrentConfiguration();
activity.setStatus(IActivity.STATUS_OK);
installConfig.addActivityModel((ConfigurationActivityModel) activity);
}
-
+
if (handler != null)
handler.completeConfigure();
@@ -141,13 +132,9 @@
newException = t;
}
if (originalException != null) // original exception wins
- throw Utilities.newCoreException(
- Policy.bind("InstallHandler.error", feature.getLabel()),
- originalException);
+ throw Utilities.newCoreException(Policy.bind("InstallHandler.error", feature.getLabel()), originalException);
if (newException != null)
- throw Utilities.newCoreException(
- Policy.bind("InstallHandler.error", feature.getLabel()),
- newException);
+ throw Utilities.newCoreException(Policy.bind("InstallHandler.error", feature.getLabel()), newException);
}
}
@@ -155,105 +142,95 @@
* check if the plugins to unconfigure are required by other configured feature and
* adds the feature to the list of unconfigured features
*/
- public boolean unconfigure(IFeatureReference featureReference,boolean callInstallHandler, boolean createActivity)
- throws CoreException {
+ public boolean unconfigure(IFeatureReference featureReference, boolean callInstallHandler, boolean createActivity) throws CoreException {
if (!isConfigured(featureReference))
return true;
- if (featureReference == null){
+ if (featureReference == null) {
UpdateManagerPlugin.warn("The feature reference to unconfigure is null");
return false;
}
-
+
IFeature feature = null;
try {
feature = featureReference.getFeature();
- } catch (CoreException e){
+ } catch (CoreException e) {
URL url = featureReference.getURL();
- String urlString = (url!=null)?url.toExternalForm():"<no feature reference url>";
- UpdateManagerPlugin.warn("Error retrieving feature:"+urlString,e);
+ String urlString = (url != null) ? url.toExternalForm() : "<no feature reference url>";
+ UpdateManagerPlugin.warn("Error retrieving feature:" + urlString, e);
return false;
}
- if (feature==null){
+ if (feature == null) {
URL url = featureReference.getURL();
- String urlString = (url!=null)?url.toExternalForm():"<no feature reference url>";
- UpdateManagerPlugin.warn("The feature to unconfigure is null: feature reference is:"+urlString);
- return false;
+ String urlString = (url != null) ? url.toExternalForm() : "<no feature reference url>";
+ UpdateManagerPlugin.warn("The feature to unconfigure is null: feature reference is:" + urlString);
+ return false;
}
// Setup optional install handler
InstallHandlerProxy handler = null;
- if (callInstallHandler && feature.getInstallHandlerEntry()!=null){
- handler = new InstallHandlerProxy(
- IInstallHandler.HANDLER_ACTION_UNCONFIGURE,
- feature,
- feature.getInstallHandlerEntry(),
- null);
+ if (callInstallHandler && feature.getInstallHandlerEntry() != null) {
+ handler = new InstallHandlerProxy(IInstallHandler.HANDLER_ACTION_UNCONFIGURE, feature, feature.getInstallHandlerEntry(), null);
}
-
+
boolean success = false;
Throwable originalException = null;
-
// do the unconfigure action
try {
-
+
ConfigurationActivity activity = null;
- if (createActivity){
+ if (createActivity) {
activity = new ConfigurationActivity(IActivity.ACTION_UNCONFIGURE);
activity.setLabel(feature.getVersionedIdentifier().toString());
activity.setDate(new Date());
}
InstallConfiguration installConfig = ((InstallConfiguration) SiteManager.getLocalSite().getCurrentConfiguration());
-
+
// Allow unconfigure if the feature is optional from all the parents
// or if the feature is mandatory and non of its parent are configured
- if (validateNoConfiguredParents(feature)){
- if (handler!=null)
+ if (validateNoConfiguredParents(feature)) {
+ if (handler != null)
handler.unconfigureInitiated();
addUnconfiguredFeatureReference((FeatureReferenceModel) featureReference);
- if (handler!=null)
- handler.completeUnconfigure();
-
+ if (handler != null)
+ handler.completeUnconfigure();
+
// everything done ok
- if (activity!=null){
+ if (activity != null) {
activity.setStatus(IActivity.STATUS_OK);
installConfig.addActivityModel((ConfigurationActivityModel) activity);
}
success = true;
} else {
- if (activity!=null){
- activity.setStatus(IActivity.STATUS_NOK);
- installConfig.addActivityModel((ConfigurationActivityModel) activity);
+ if (activity != null) {
+ activity.setStatus(IActivity.STATUS_NOK);
+ installConfig.addActivityModel((ConfigurationActivityModel) activity);
}
- }
+ }
} catch (Throwable t) {
originalException = t;
} finally {
Throwable newException = null;
try {
- if (handler!=null)
+ if (handler != null)
handler.unconfigureCompleted(success);
} catch (Throwable t) {
newException = t;
}
if (originalException != null) // original exception wins
- throw Utilities.newCoreException(
- Policy.bind("InstallHandler.error", feature.getLabel()),
- originalException);
+ throw Utilities.newCoreException(Policy.bind("InstallHandler.error", feature.getLabel()), originalException);
if (newException != null)
- throw Utilities.newCoreException(
- Policy.bind("InstallHandler.error", feature.getLabel()),
- newException);
+ throw Utilities.newCoreException(Policy.bind("InstallHandler.error", feature.getLabel()), newException);
}
- if (!success){
+ if (!success) {
URL url = featureReference.getURL();
- String urlString = (url!=null)?url.toExternalForm():"<no feature reference url>";
- UpdateManagerPlugin.warn("Unable to unconfigure:"+urlString);
+ String urlString = (url != null) ? url.toExternalForm() : "<no feature reference url>";
+ UpdateManagerPlugin.warn("Unable to unconfigure:" + urlString);
}
return success;
}
@@ -265,10 +242,9 @@
* plugins for unconfigured features that are not referenced
* by any configured features.
*/
- public String[] getPluginPath(ISite site, String[] pluginRead)
- throws CoreException {
+ public String[] getPluginPath(ISite site, String[] pluginRead) throws CoreException {
- String [] result;
+ String[] result;
String[] pluginsToWrite;
if (getPolicy() == IPlatformConfiguration.ISitePolicy.USER_EXCLUDE) {
// EXCLUDE: return unconfigured plugins MINUS any plugins that
@@ -282,10 +258,10 @@
}
//TRACE
- if (UpdateManagerPlugin.DEBUG && UpdateManagerPlugin.DEBUG_SHOW_RECONCILER){
- UpdateManagerPlugin.debug("GetPluginPath for: "+((site==null)?"<No site>":site.getURL().toString()));
- for (int i = 0; i < pluginsToWrite.length; i++) {
- UpdateManagerPlugin.debug("To write:"+pluginsToWrite[i]);
+ if (UpdateManagerPlugin.DEBUG && UpdateManagerPlugin.DEBUG_SHOW_RECONCILER) {
+ UpdateManagerPlugin.debug("GetPluginPath for: " + ((site == null) ? "<No site>" : site.getURL().toString()));
+ for (int i = 0; i < pluginsToWrite.length; i++) {
+ UpdateManagerPlugin.debug("To write:" + pluginsToWrite[i]);
}
}
@@ -317,10 +293,10 @@
}
}
result = union(included, pluginsToWrite);*/
-
+
result = pluginsToWrite;
- return result;
+ return result;
}
/**
@@ -365,7 +341,7 @@
* removes a feature reference
*/
public void removeFeatureReference(IFeatureReference featureRef) {
- if (featureRef instanceof FeatureReferenceModel){
+ if (featureRef instanceof FeatureReferenceModel) {
removeFeatureReference((FeatureReferenceModel) featureRef);
}
}
@@ -374,10 +350,7 @@
* return an array of plugin path for the array of feature reference
* Each plugin path only appears once [bug 21750]
*/
- private String[] getPluginString(
- ISite site,
- IFeatureReference[] arrayOfFeatureRef)
- throws CoreException {
+ private String[] getPluginString(ISite site, IFeatureReference[] arrayOfFeatureRef) throws CoreException {
String[] result = new String[0];
@@ -390,12 +363,12 @@
IFeature feature = null;
try {
feature = element.getFeature();
- } catch (CoreException e){
- UpdateManagerPlugin.warn(null,e);
+ } catch (CoreException e) {
+ UpdateManagerPlugin.warn(null, e);
};
IPluginEntry[] entries = null;
if (feature == null) {
- UpdateManagerPlugin.warn("Null Feature",new Exception());
+ UpdateManagerPlugin.warn("Null Feature", new Exception());
entries = new IPluginEntry[0];
} else {
entries = feature.getPluginEntries();
@@ -403,25 +376,20 @@
for (int index = 0; index < entries.length; index++) {
IPluginEntry entry = entries[index];
-
+
// obtain the path of the plugin directories on the site
ContentReference[] featureContentReference = null;
try {
- featureContentReference =
- feature
- .getFeatureContentProvider()
- .getPluginEntryArchiveReferences(entry, null /*IProgressMonitor*/
+ featureContentReference = feature.getFeatureContentProvider().getPluginEntryArchiveReferences(entry, null /*IProgressMonitor*/
);
} catch (CoreException e) {
- UpdateManagerPlugin.warn(null,e);
+ UpdateManagerPlugin.warn(null, e);
}
-
+
// transform into a valid String
if (featureContentReference != null) {
for (int j = 0; j < featureContentReference.length; j++) {
- URL url =
- site.getSiteContentProvider().getArchiveReference(
- featureContentReference[j].getIdentifier());
+ URL url = site.getSiteContentProvider().getArchiveReference(featureContentReference[j].getIdentifier());
if (url != null) {
// make it relative to teh site
String path = UpdateManagerUtils.getURLAsString(site.getURL(), url);
@@ -447,7 +415,6 @@
return result;
}
-
/**
* we need to figure out which plugin SHOULD NOT be written and
* remove them from include
@@ -480,8 +447,6 @@
return resultEntry;
}
-
-
/**
* Returns and array with the union of plugins
*/
@@ -516,26 +481,27 @@
/*
*
*/
- private boolean validateNoConfiguredParents(IFeature feature) throws CoreException {
- if (feature==null){
- UpdateManagerPlugin.warn("ConfigurationPolicy: validate Feature is null");
- return true;
- }
-
- IFeatureReference[] parents = UpdateManagerUtils.getParentFeatures(feature, getConfiguredFeatures());
- if (parents.length==0)
- return true;
-
- String msg = Policy.bind("ConfigurationPolicy.UnableToDisable",feature.getLabel());
- UpdateManagerPlugin.warn(msg);
- IFeature parentFeature = null;
- for (int i = 0; i < parents.length; i++) {
- try {
- parentFeature = parents[i].getFeature();
- } catch (CoreException e){}
- String featureLabel = (parentFeature==null)?parents[i].getURL().toExternalForm():parentFeature.getLabel();
- UpdateManagerPlugin.warn(Policy.bind("ConfigurationPolicy.ParentIsEnable",featureLabel));
+ private boolean validateNoConfiguredParents(IFeature feature) throws CoreException {
+ if (feature == null) {
+ UpdateManagerPlugin.warn("ConfigurationPolicy: validate Feature is null");
+ return true;
}
- return false;
- }
+
+ IFeatureReference[] parents = UpdateManagerUtils.getParentFeatures(feature, getConfiguredFeatures());
+ if (parents.length == 0)
+ return true;
+
+ String msg = Policy.bind("ConfigurationPolicy.UnableToDisable", feature.getLabel());
+ UpdateManagerPlugin.warn(msg);
+ IFeature parentFeature = null;
+ for (int i = 0; i < parents.length; i++) {
+ try {
+ parentFeature = parents[i].getFeature();
+ } catch (CoreException e) {
+ }
+ String featureLabel = (parentFeature == null) ? parents[i].getURL().toExternalForm() : parentFeature.getLabel();
+ UpdateManagerPlugin.warn(Policy.bind("ConfigurationPolicy.ParentIsEnable", featureLabel));
+ }
+ return false;
+ }
}
\ No newline at end of file
diff --git a/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/ConfiguredSite.java b/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/ConfiguredSite.java
index 4aa6437..9648747 100644
--- a/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/ConfiguredSite.java
+++ b/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/ConfiguredSite.java
@@ -210,7 +210,7 @@
}
// call the configure task
if (installedFeature != null)
- configure(installedFeature, false);
+ configure(installedFeature, optionalFeatures, false);
/*callInstallHandler*/
return installedFeatureRef;
@@ -284,14 +284,14 @@
* @see IConfiguredSite#configure(IFeature)
*/
public void configure(IFeature feature) throws CoreException {
- configure(feature, true /*callInstallHandler*/
+ configure(feature, null, true /*callInstallHandler*/
);
}
/*
- * @see IConfiguredSite#configure(IFeatureReference,boolean)
+ *
*/
- private void configure(IFeature feature, boolean callInstallHandler) throws CoreException {
+ private void configure(IFeature feature, IFeatureReference[] optionalFeatures, boolean callInstallHandler) throws CoreException {
if (feature == null) {
UpdateManagerPlugin.warn("Attempting to configure a null feature in site:" + getSite().getURL().toExternalForm());
@@ -303,11 +303,16 @@
return;
// bottom up approach, same configuredSite
+ //IFeatureReference[] childrenRef = feature.getIncludedFeatureReferences();
IFeatureReference[] childrenRef = feature.getIncludedFeatureReferences();
+ if (optionalFeatures!=null){
+ childrenRef = optionalChildrenToInstall(childrenRef,optionalFeatures);
+ }
+
for (int i = 0; i < childrenRef.length; i++) {
try {
IFeature child = childrenRef[i].getFeature();
- configure(child, callInstallHandler);
+ configure(child, optionalFeatures, callInstallHandler);
} catch (CoreException e) {
// will skip any bad children
if (!childrenRef[i].isOptional())
@@ -324,7 +329,46 @@
for (int i = 0; i < siteListeners.length; i++) {
((IConfiguredSiteChangedListener) siteListeners[i]).featureConfigured(feature);
}
+ }
+ /**
+ * Return the optional children to install
+ * The optional features to install may not all be direct children
+ * of the feature.
+ *
+ * @param children all the nested features
+ * @param optionalfeatures optional features to install
+ * @return IFeatureReference[]
+ */
+ private IFeatureReference[] optionalChildrenToInstall(IFeatureReference[] children, IFeatureReference[] optionalfeatures) {
+ if (optionalfeatures.length==0) return optionalfeatures;
+
+ List optionalChildrenToInstall = new ArrayList();
+ for (int i = 0; i < children.length; i++) {
+ IFeatureReference optionalFeature = children[i];
+ if (!optionalFeature.isOptional()){
+ optionalChildrenToInstall.add(optionalFeature);
+ } else {
+ for (int j = 0; j < optionalfeatures.length; j++) {
+ // must compare feature as optionalFeatures are from the install site
+ // where children are on the local site
+ try {
+ IFeature installedChildren = optionalfeatures[j].getFeature();
+ if (installedChildren.equals(optionalFeature.getFeature())){
+ optionalChildrenToInstall.add(optionalFeature);
+ break;
+ }
+ } catch (CoreException e){}
+ }
+ }
+ }
+
+ IFeatureReference[] result = new IFeatureReference[optionalChildrenToInstall.size()];
+ if (optionalChildrenToInstall.size()>0){
+ optionalChildrenToInstall.toArray(result);
+ }
+
+ return result;
}
/*
diff --git a/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/SiteReconciler.java b/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/SiteReconciler.java
index f1ef143..b222aab 100644
--- a/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/SiteReconciler.java
+++ b/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/SiteReconciler.java
@@ -714,10 +714,15 @@
IFeature child = null;
try {
child = children[j].getFeature();
- expandFeature(child, features);
} catch (CoreException e){
- if (!children[j].isOptional()) throw e;
+ // the child may be missing, warn and return
+ if (children[j].isOptional()) {
+ UpdateManagerPlugin.warn("",e);
+ return;
+ }
+ throw e;
}
+ expandFeature(child, features);
}
}
diff --git a/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/UpdateManagerUtils.java b/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/UpdateManagerUtils.java
index 6f1b3ec..c5b180b 100644
--- a/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/UpdateManagerUtils.java
+++ b/update/org.eclipse.update.core/src/org/eclipse/update/internal/core/UpdateManagerUtils.java
@@ -526,4 +526,39 @@
}
}
}
+
+ /**
+ * Return the optional children to install
+ * The optional features to install may not all be direct children
+ * of the feature.
+ *
+ * @param children all the nested features
+ * @param optionalfeatures optional features to install
+ * @return IFeatureReference[]
+ */
+ public static IFeatureReference[] optionalChildrenToInstall(IFeatureReference[] children, IFeatureReference[] optionalfeatures) {
+ if (optionalfeatures.length==0) return optionalfeatures;
+
+ List optionalChildrenToInstall = new ArrayList();
+ for (int i = 0; i < children.length; i++) {
+ IFeatureReference optionalFeature = children[i];
+ if (!optionalFeature.isOptional()){
+ optionalChildrenToInstall.add(optionalFeature);
+ } else {
+ for (int j = 0; j < optionalfeatures.length; j++) {
+ if (optionalFeature.equals(optionalfeatures[j])){
+ optionalChildrenToInstall.add(optionalFeature);
+ break;
+ }
+ }
+ }
+ }
+
+ IFeatureReference[] result = new IFeatureReference[optionalChildrenToInstall.size()];
+ if (optionalChildrenToInstall.size()>0){
+ optionalChildrenToInstall.toArray(result);
+ }
+
+ return result;
+ }
}
\ No newline at end of file