use of org.xwiki.extension.distribution.internal.job.step.DistributionStep in project xwiki-platform by xwiki.
the class AbstractDistributionJob method runInternal.
@Override
protected void runInternal() throws Exception {
List<DistributionStep> steps = getStatus().getSteps();
this.progressManager.pushLevelProgress(steps.size(), this);
// Initialize steps
WelcomeDistributionStep welcomeStep = (WelcomeDistributionStep) getStep(steps, WelcomeDistributionStep.ID);
ReportDistributionStep reportStep = (ReportDistributionStep) getStep(steps, ReportDistributionStep.ID);
for (DistributionStep step : steps) {
step.initialize(this);
// Enable Welcome step if one of the steps is enabled
if (step.getState() == null) {
if (welcomeStep != null) {
welcomeStep.setState(null);
}
if (reportStep != null) {
reportStep.setState(null);
}
}
}
// Execute steps
try {
for (int index = 0; index < steps.size(); ++index) {
this.progressManager.startStep(this);
getStatus().setCurrentStateIndex(index);
DistributionStep step = steps.get(index);
// Prepare step
step.prepare();
// Execute step
if (step.getState() == null) {
if (getRequest().isInteractive()) {
DistributionQuestion question = new DistributionQuestion(step);
// Waiting to start
signalReady();
getStatus().ask(question);
if (question.getAction() != null) {
switch(question.getAction()) {
case CANCEL:
for (; index < steps.size(); ++index) {
steps.get(index).setState(DistributionStep.State.CANCELED);
}
case SKIP:
index = steps.size() - 1;
break;
default:
break;
}
}
// Save the status so that we remember the answer even if the DW is stopped before the end
this.store.storeAsync(this.status);
} else {
step.executeNonInteractive();
}
}
this.progressManager.endStep(this);
}
} finally {
this.progressManager.popLevelProgress(this);
}
}
use of org.xwiki.extension.distribution.internal.job.step.DistributionStep in project xwiki-platform by xwiki.
the class DefaultDistributionJob method createSteps.
@Override
protected List<DistributionStep> createSteps() {
List<DistributionStep> steps = new ArrayList<>();
boolean isMainWiki = isMainWiki();
// Create admin user if needed
if (isMainWiki) {
try {
steps.add(this.componentManager.<DistributionStep>getInstance(DistributionStep.class, FirstAdminUserStep.ID));
} catch (ComponentLookupException e) {
this.logger.error("Failed to get first admin step instance", e);
}
}
// Install/upgrade main wiki UI
addDefaultUIStep(steps, isMainWiki);
// Upgrade other wikis
if (isMainWiki) {
ExtensionId wikiUI = this.distributionManager.getWikiUIExtensionId();
if (wikiUI != null && StringUtils.isNotBlank(wikiUI.getId())) {
// ... but only if the wiki extension ID is defined
try {
steps.add(this.componentManager.<DistributionStep>getInstance(DistributionStep.class, WikisDefaultUIDistributionStep.ID));
} catch (ComponentLookupException e) {
this.logger.error("Failed to get all in one default UI step instance", e);
}
} else {
// TODO: Display the wikis flavor step
}
}
// Upgrade outdated extensions
try {
steps.add(this.componentManager.<DistributionStep>getInstance(DistributionStep.class, OutdatedExtensionsDistributionStep.ID));
} catch (ComponentLookupException e) {
this.logger.error("Failed to get outdated extensions step instance", e);
}
return steps;
}
use of org.xwiki.extension.distribution.internal.job.step.DistributionStep in project xwiki-platform by xwiki.
the class AbstractDistributionJob method createNewStatus.
@Override
protected DistributionJobStatus createNewStatus(R request) {
List<DistributionStep> steps = createSteps();
if (getRequest().isInteractive()) {
// Add Welcome step
try {
DistributionStep welcomeStep = this.componentManager.<DistributionStep>getInstance(DistributionStep.class, WelcomeDistributionStep.ID);
welcomeStep.setState(State.COMPLETED);
steps.add(0, welcomeStep);
} catch (ComponentLookupException e1) {
this.logger.error("Failed to get step instance for id [{}]", WelcomeDistributionStep.ID);
}
// Add Report step
try {
DistributionStep welcomeStep = this.componentManager.<DistributionStep>getInstance(DistributionStep.class, ReportDistributionStep.ID);
welcomeStep.setState(State.COMPLETED);
steps.add(welcomeStep);
} catch (ComponentLookupException e1) {
this.logger.error("Failed to get step instance for id [{}]", ReportDistributionStep.ID);
}
}
// Create status
DistributionJobStatus status = createNewDistributionStatus(request, steps);
if (this.distributionManager.getDistributionExtension() != null) {
DistributionJobStatus previousStatus = getPreviousStatus();
if (previousStatus != null && previousStatus.getDistributionExtension() != null && !Objects.equals(previousStatus.getDistributionExtension(), this.distributionManager.getDistributionExtension().getId())) {
status.setPreviousDistributionExtension(previousStatus.getDistributionExtension());
status.setPreviousDistributionExtensionUI(previousStatus.getDistributionExtensionUI());
}
status.setDistributionExtension(this.distributionManager.getDistributionExtension().getId());
status.setDistributionExtensionUI(getUIExtensionId());
}
return status;
}
Aggregations