Skip to content

Commit 8fedf1b

Browse files
committed
Support a "simple variable with defaults" for the simple installer
- Provide an annotation to mark a variable that can be used in products in the installer's simple mode and will simply take on the variable's default value, or the value of the variable's first choice, without prompting and will be handled as usual in the installer's advanced mode.
1 parent dbc5f74 commit 8fedf1b

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

plugins/org.eclipse.oomph.setup.editor/src/org/eclipse/oomph/setup/presentation/SetupActionBarContributor.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,19 @@ private Collection<IAction> addSpecializedAnnotationCreationActions(Collection<?
719719
}
720720
}
721721

722+
if (variable.getAnnotation(AnnotationConstants.ANNOTATION_SIMPLE_MODE_DEFAULT_VARIABLE) == null)
723+
{
724+
String name = variable.getName();
725+
if (name != null && !name.startsWith("*") && (variable.getDefaultValue() != null || !variable.getChoices().isEmpty())) //$NON-NLS-1$
726+
{
727+
Annotation annotation = BaseFactory.eINSTANCE.createAnnotation(AnnotationConstants.ANNOTATION_SIMPLE_MODE_DEFAULT_VARIABLE);
728+
CommandParameter descriptor = new CommandParameter(null, BasePackage.Literals.MODEL_ELEMENT__ANNOTATIONS, annotation);
729+
Action action = sibling ? new CreateSiblingAction(domain, selection, descriptor) : new CreateChildAction(domain, selection, descriptor);
730+
action.setText(action.getText() + " - " + AnnotationConstants.ANNOTATION_SIMPLE_MODE_DEFAULT_VARIABLE); //$NON-NLS-1$
731+
actions.add(action);
732+
}
733+
}
734+
722735
if (variable.getAnnotation(AnnotationConstants.ANNOTATION_INHERITED_CHOICES) == null)
723736
{
724737
Annotation annotation = BaseFactory.eINSTANCE.createAnnotation(AnnotationConstants.ANNOTATION_INHERITED_CHOICES);

plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/SimpleVariablePage.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.eclipse.oomph.setup.SetupTaskContext;
4141
import org.eclipse.oomph.setup.Trigger;
4242
import org.eclipse.oomph.setup.User;
43+
import org.eclipse.oomph.setup.VariableChoice;
4344
import org.eclipse.oomph.setup.VariableTask;
4445
import org.eclipse.oomph.setup.internal.core.AbstractSetupTaskContext;
4546
import org.eclipse.oomph.setup.internal.core.SetupContext;
@@ -1267,6 +1268,11 @@ public void run()
12671268

12681269
SimplePrompter prompter = new SimplePrompter(OS.INSTANCE.getForBitness(javaController.getBitness()), vmPath);
12691270
performer = SetupTaskPerformer.create(uriConverter, prompter, Trigger.BOOTSTRAP, setupContext, false);
1271+
List<VariableTask> resolvedSimpleDefaultVariables = prompter.getResolvedSimpleDefaultVariables();
1272+
if (performer == null)
1273+
{
1274+
performer = SetupTaskPerformer.create(uriConverter, prompter, Trigger.BOOTSTRAP, setupContext, false);
1275+
}
12701276

12711277
final List<VariableTask> unresolvedVariables = prompter.getUnresolvedVariables();
12721278
if (!unresolvedVariables.isEmpty())
@@ -1352,6 +1358,7 @@ public void init(UIServices serviceUI)
13521358
performer.log(NLS.bind(Messages.SimpleVariablePage_ExecutingTasks_message, performer.getTrigger().toString().toLowerCase()));
13531359
performer.put(org.eclipse.equinox.internal.provisional.p2.core.eventbus.ProvisioningListener.class, new DownloadArtifactLister());
13541360
performer.perform(progress);
1361+
performer.getUnresolvedVariables().addAll(resolvedSimpleDefaultVariables);
13551362
performer.recordVariables(installation, null, user);
13561363
performer.savePasswords();
13571364

@@ -1988,6 +1995,38 @@ public String getVMPath()
19881995
return vmPath;
19891996
}
19901997

1998+
public List<VariableTask> getResolvedSimpleDefaultVariables()
1999+
{
2000+
List<VariableTask> result = new ArrayList<VariableTask>();
2001+
for (Iterator<VariableTask> it = unresolvedVariables.iterator(); it.hasNext();)
2002+
{
2003+
VariableTask variable = it.next();
2004+
String name = variable.getName();
2005+
if (variable.getAnnotation(AnnotationConstants.ANNOTATION_SIMPLE_MODE_DEFAULT_VARIABLE) != null)
2006+
{
2007+
String value = variable.getDefaultValue();
2008+
if (value == null)
2009+
{
2010+
EList<VariableChoice> choices = variable.getChoices();
2011+
if (!choices.isEmpty())
2012+
{
2013+
value = choices.get(0).getLabel();
2014+
}
2015+
}
2016+
2017+
if (value != null)
2018+
{
2019+
variable.setValue(value);
2020+
put(name, value);
2021+
result.add(variable);
2022+
it.remove();
2023+
}
2024+
}
2025+
}
2026+
2027+
return result;
2028+
}
2029+
19912030
public List<VariableTask> getUnresolvedVariables()
19922031
{
19932032
return unresolvedVariables;

plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/AnnotationConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public final class AnnotationConstants
7373

7474
public static final String ANNOTATION_GLOBAL_VARIABLE = "http://www.eclipse.org/oomph/setup/GlobalVariable"; //$NON-NLS-1$
7575

76+
public static final String ANNOTATION_SIMPLE_MODE_DEFAULT_VARIABLE = "http://www.eclipse.org/oomph/setup/SimpleDefaultVariable"; //$NON-NLS-1$
77+
7678
public static final String ANNOTATION_UNDECLARED_VARIABLE = "http://www.eclipse.org/oomph/setup/UndeclaredVariable"; //$NON-NLS-1$
7779

7880
public static final String KEY_INHERIT = "inherit"; //$NON-NLS-1$

0 commit comments

Comments
 (0)