Commit 004de227 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub
Browse files

feat(deploy) validation options + cancel (#1845)

Closes BST-470
parent 6a4cae67
......@@ -67,7 +67,6 @@ validationError=The following errors have been detected in your project.\nThe pr
bdmGenerationError=An error occurred while generating Business Data Model Java archive.
selectArtifactToDeployTitle=Select artifacts to deploy
selectArtifactToDeploy=Select some artifacts from the current project and deploy them.
warningMissingDependency=\u26A0\uFE0F Deploy operation might fail or the state of the Studio runtime might become inconsistent if you forget to deploy an artifact dependency. If it happens, you'll have the possibility to deploy the missing artifacts later.
deploy=Deploy
selectAll=Select all
selectNone=Select none
......@@ -91,4 +90,5 @@ appDescriptorUnknownAppPage=Application descriptor '%s': Application page '%s' h
appDescriptorUnknownPageToken=Application descriptor '%s': Application page token '%s' doesn't exists.
appDescriptorUnknownLayoutPage=Application descriptor '%s': Application layout '%s' has not been found.
appDescriptorUnknownTheme=Application descriptor '%s': Application theme '%s' has not been found.
deploySuccessMsg=All artifacts has been deployed successfully.
\ No newline at end of file
deploySuccessMsg=All artifacts has been deployed successfully.
validateProcess=Validate before deploy
\ No newline at end of file
......@@ -70,7 +70,7 @@ public class DeployArtifactsHandler {
RepositoryAccessor repositoryAccessor, IProgressService progressService)
throws InvocationTargetException, InterruptedException {
progressService.busyCursorWhile( monitor -> {
progressService.busyCursorWhile(monitor -> {
repositoryModel = new RepositoryModelBuilder().create(repositoryAccessor);
});
......@@ -92,8 +92,17 @@ public class DeployArtifactsHandler {
IWizardContainer container) {
MultiStatus status = new MultiStatus(ApplicationPlugin.PLUGIN_ID, 0, null, null);
try {
if ((boolean) deployOptions.get(DeployOptions.RUN_VALIDATION)) {
container.run(true, true,
performArtifactsValidation(artifactsToDeploy, status));
}
if (status.getSeverity() == IStatus.CANCEL) {
return null;
} else if (!status.isOK()) {
return status;
}
container.run(true, false,
performFinish(repositoryAccessor,artifactsToDeploy, deployOptions, status));
performFinish(repositoryAccessor, artifactsToDeploy, deployOptions, status));
} catch (InvocationTargetException | InterruptedException e) {
BonitaStudioLog.error(e);
return new Status(IStatus.ERROR, ApplicationPlugin.PLUGIN_ID, "Deploy failed",
......@@ -112,16 +121,11 @@ public class DeployArtifactsHandler {
try {
APISession session = apiSessionOperation.getSession();
DeployTenantResourcesOperation deployTenantResourcesOperation = new DeployTenantResourcesOperation(
artifactsToDeploy.stream().filter(TenantArtifact.class::isInstance).map(TenantArtifact.class::cast).collect(Collectors.toList()), session, deployOptions);
artifactsToDeploy.stream().filter(TenantArtifact.class::isInstance)
.map(TenantArtifact.class::cast).collect(Collectors.toList()),
session, deployOptions);
deployTenantResourcesOperation.run(monitor);
status.addAll(deployTenantResourcesOperation.getStatus());
if (shouldValidate()) {
IStatus validationStatus = performArtifactsValidation(artifactsToDeploy, monitor);
if (!validationStatus.isOK()) {
status.addAll(validationStatus);
return;
}
}
IStatus buildStatus = performBuild(repositoryAccessor, artifactsToDeploy, monitor);
if (!buildStatus.isOK()) {
if (buildStatus instanceof MultiStatus) {
......@@ -139,10 +143,6 @@ public class DeployArtifactsHandler {
};
}
private boolean shouldValidate() {
return true;
}
private WizardBuilder<IStatus> createWizard(
WizardBuilder<IStatus> builder,
SelectArtifactToDeployPage page,
......@@ -168,17 +168,19 @@ public class DeployArtifactsHandler {
HashMap<String, Object> options = new HashMap<String, Object>();
options.put(DeployOptions.CLEAN_BDM, page.isCleanBDM());
options.put(DeployOptions.DEFAULT_USERNAME, page.getDefaultUsername());
options.put(DeployOptions.RUN_VALIDATION, page.isValidate());
return options;
}
private void openStatusDialog(Shell activeShell, IStatus status) {
if (status instanceof MultiStatus) {
if(status.getSeverity() == IStatus.ERROR || status.getSeverity() == IStatus.WARNING) {
MultiStatusDialog multiStatusDialog = new MultiStatusDialog(activeShell, Messages.deployStatus, Messages.deployStatusMessage,
if (status.getSeverity() == IStatus.ERROR || status.getSeverity() == IStatus.WARNING) {
MultiStatusDialog multiStatusDialog = new MultiStatusDialog(activeShell, Messages.deployStatus,
Messages.deployStatusMessage,
new String[] { IDialogConstants.OK_LABEL }, (MultiStatus) status);
multiStatusDialog.setLevel(IStatus.WARNING);
multiStatusDialog.open();
}else {
} else {
MessageDialog.openInformation(activeShell, Messages.deployStatus, Messages.deploySuccessMsg);
}
} else {
......@@ -204,12 +206,13 @@ public class DeployArtifactsHandler {
return operation.getStatus();
}
private IStatus performArtifactsValidation(Collection<Artifact> artifactsToDeploy,
IProgressMonitor monitor)
private IRunnableWithProgress performArtifactsValidation(Collection<Artifact> artifactsToDeploy, MultiStatus status)
throws InvocationTargetException, InterruptedException {
ValidateProjectOperation operation = new ValidateProjectOperation(artifactsToDeploy);
operation.run(monitor);
return operation.getStatus();
return monitor -> {
ValidateProjectOperation operation = new ValidateProjectOperation(artifactsToDeploy);
operation.run(monitor);
status.add(operation.getStatus());
};
}
}
......@@ -105,7 +105,6 @@ public class Messages extends NLS {
public static String bdmGenerationError;
public static String selectArtifactToDeployTitle;
public static String selectArtifactToDeploy;
public static String warningMissingDependency;
public static String deploy;
public static String selectAll;
public static String selectNone;
......@@ -132,6 +131,7 @@ public class Messages extends NLS {
public static String appDescriptorUnknownTheme;
public static String deploySuccessMsg;
public static String validateProcess;
static {
......
......@@ -24,23 +24,20 @@ import org.bonitasoft.studio.application.ApplicationPlugin;
import org.bonitasoft.studio.application.ui.control.model.Artifact;
import org.bonitasoft.studio.application.ui.control.model.ProcessVersion;
import org.bonitasoft.studio.common.core.IRunnableWithStatus;
import org.bonitasoft.studio.ui.util.ProcessValidationStatus;
import org.bonitasoft.studio.validation.common.operation.BatchValidationOperation;
import org.bonitasoft.studio.validation.common.operation.OffscreenEditPartFactory;
import org.bonitasoft.studio.validation.common.operation.RunProcessesValidationOperation;
import org.bonitasoft.studio.validation.common.operation.ValidationMarkerProvider;
import org.bonitasoft.studio.validation.common.operation.ProcessValidationOperation;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
public class ValidateProjectOperation implements IRunnableWithStatus {
private MultiStatus status;
private List<ProcessVersion> fileStoreToValidate;
private List<ProcessVersion> processToValidate;
public ValidateProjectOperation(Collection<Artifact> artifactsToValidate) {
this.fileStoreToValidate = artifactsToValidate.stream()
this.processToValidate = artifactsToValidate.stream()
.filter(ProcessVersion.class::isInstance)
.map(ProcessVersion.class::cast)
.collect(Collectors.toList());
......@@ -49,21 +46,19 @@ public class ValidateProjectOperation implements IRunnableWithStatus {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
for (ProcessVersion pv : fileStoreToValidate) {
ProcessValidationOperation validationAction = new ProcessValidationOperation();
for (ProcessVersion pv : processToValidate) {
if (monitor.isCanceled()) {
this.status.add(Status.CANCEL_STATUS);
break;
}
RunProcessesValidationOperation validationAction = new RunProcessesValidationOperation(
new BatchValidationOperation(
new OffscreenEditPartFactory(
org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory.getInstance()),
new ValidationMarkerProvider()));
validationAction.addProcess(pv.getModel());
validationAction.run(monitor);
if (!monitor.isCanceled()
&& Objects.equals(validationAction.getStatus().getSeverity(), ValidationStatus.ERROR)) {
status.add(new ProcessValidationStatus(pv.getModel(),validationAction.getStatus()));
}
}
validationAction.run(monitor);
if(monitor.isCanceled()) {
status.add(Status.CANCEL_STATUS);
}else if(Objects.equals(validationAction.getStatus().getSeverity(), ValidationStatus.ERROR)) {
status.addAll(validationAction.getStatus());
}
}
......
......@@ -88,6 +88,7 @@ public class SelectArtifactToDeployPage implements ControlSupplier {
private static final String DEPLOY_DEFAULT_SELECTION = "deployDefaultSelection";
private static final String CLEAN_BDM_DEFAULT_SELECTION = "cleanBDMDefaultSelection";
private static final String VALIDATE_DEFAULT_SELECTION = "RunValidation";
private CheckboxRepositoryTreeViewer fileStoreViewer;
protected IObservableSet<Object> checkedElementsObservable; // Bounded to the viewer -> doesn't contain filtered elements
......@@ -104,6 +105,8 @@ public class SelectArtifactToDeployPage implements ControlSupplier {
private IEnvironmentProvider environmentProvider;
private Set<Object> defaultSelectedElements;
private RepositoryModel repositoryModel;
private Button validateProcessOption;
private boolean validate = true;
public SelectArtifactToDeployPage(RepositoryModel repositoryModel, IEnvironmentProvider environmentProvider) {
this.repositoryModel = repositoryModel;
......@@ -116,6 +119,7 @@ public class SelectArtifactToDeployPage implements ControlSupplier {
if (section != null && section.getArray(DEPLOY_DEFAULT_SELECTION) != null) {
defaultSelectedElements = fromStrings(section.getArray(DEPLOY_DEFAULT_SELECTION));
cleanBDM = section.getBoolean(CLEAN_BDM_DEFAULT_SELECTION);
validate = section.getBoolean(VALIDATE_DEFAULT_SELECTION);
}
environment = ConfigurationPlugin.getDefault().getPreferenceStore()
.getString(ConfigurationPreferenceConstants.DEFAULT_CONFIGURATION);
......@@ -127,6 +131,7 @@ public class SelectArtifactToDeployPage implements ControlSupplier {
IDialogSettings section = settings.addNewSection(repositoryModel.getName());
section.put(DEPLOY_DEFAULT_SELECTION, stringify(allCheckedElements));
section.put(CLEAN_BDM_DEFAULT_SELECTION, cleanBDM);
section.put(VALIDATE_DEFAULT_SELECTION, validate);
ConfigurationPlugin.getDefault().getPreferenceStore()
.setValue(ConfigurationPreferenceConstants.DEFAULT_CONFIGURATION, environment);
}
......@@ -169,10 +174,6 @@ public class SelectArtifactToDeployPage implements ControlSupplier {
.create());
mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
// Label warningDependencyLabel = new Label(mainComposite, SWT.WRAP);
// warningDependencyLabel.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
// warningDependencyLabel.setText(Messages.warningMissingDependency);
Composite viewerAndButtonsComposite = new Composite(mainComposite, SWT.NONE);
viewerAndButtonsComposite.setLayout(
GridLayoutFactory.fillDefaults().numColumns(2).spacing(LayoutConstants.getSpacing().x, 1).create());
......@@ -434,7 +435,13 @@ public class SelectArtifactToDeployPage implements ControlSupplier {
ctx.bindValue(WidgetProperties.selection().observe(cleanDeployOption),
PojoProperties.value("cleanBDM").observe(this));
validateProcessOption = new Button(deployOptionGroup, SWT.CHECK);
validateProcessOption.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).create());
validateProcessOption.setText(Messages.validateProcess);
ctx.bindValue(WidgetProperties.selection().observe(validateProcessOption),
PojoProperties.value("validate").observe(this));
}
private Organization getSelectedOrganization() {
......@@ -608,6 +615,14 @@ public class SelectArtifactToDeployPage implements ControlSupplier {
public void setCleanBDM(boolean cleanBDM) {
this.cleanBDM = cleanBDM;
}
public boolean isValidate() {
return validate;
}
public void setValidate(boolean validate) {
this.validate = validate;
}
public String getEnvironment() {
return environment;
......
......@@ -19,5 +19,6 @@ public interface DeployOptions {
public static final String DEFAULT_USERNAME = "DEFAULT_USERNAME";
public static final String CLEAN_BDM = "CLEAN_BDM";
public static final String RUN_VALIDATION = "RUN_VALIDATION";
}
......@@ -42,7 +42,7 @@ public class ProcessValidationStatus extends Status {
}
return String.format("%s %s %s (%s)", issues, Messages.issuesFoundIn, process.getName(), process.getVersion());
}
return String.format("%s (%s)", process.getName(), process.getVersion());
return validationStatus.getSeverity() == IStatus.ERROR ? String.format("%s %s %s (%s)", 1, Messages.issueFoundIn, process.getName(), process.getVersion()) : String.format("%s (%s)", process.getName(), process.getVersion());
}
protected int countIssues() {
......
......@@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.ui,
org.junit;bundle-version="4.11.0";resolution:=optional,
assertj-core;bundle-version="1.5.0";resolution:=optional,
org.eclipse.ui.workbench,
org.eclipse.ui.ide;bundle-version="3.10.1"
org.eclipse.ui.ide;bundle-version="3.10.1",
org.bonitasoft.studio.ui;bundle-version="7.10.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.validation.common.operation
......
/**
* Copyright (C) 2012-2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.validation.common.operation;
import static com.google.common.collect.Lists.newArrayList;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.ui.util.ProcessValidationStatus;
import org.bonitasoft.studio.validation.common.ValidationCommonPlugin;
import org.bonitasoft.studio.validation.common.i18n.Messages;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.emf.validation.model.EvaluationMode;
import org.eclipse.emf.validation.service.IBatchValidator;
import org.eclipse.emf.validation.service.ModelValidationService;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
public class ProcessValidationOperation extends WorkspaceModifyOperation {
private final List<AbstractProcess> listOfProcessesToValidate = new ArrayList<>();
private MultiStatus status = new MultiStatus(ValidationCommonPlugin.PLUGIN_ID ,-1, null, null);
public ProcessValidationOperation addProcess(final AbstractProcess process) {
listOfProcessesToValidate.add(process);
return this;
}
public ProcessValidationOperation addProcesses(final List<AbstractProcess> processes) {
listOfProcessesToValidate.addAll(newArrayList(processes));
return this;
}
public IStatus getStatus() {
return status;
}
@Override
protected void execute(IProgressMonitor monitor)
throws CoreException, InvocationTargetException, InterruptedException {
final IBatchValidator validator = (IBatchValidator) ModelValidationService.getInstance().newValidator(
EvaluationMode.BATCH);
validator.setIncludeLiveConstraints(true);
listOfProcessesToValidate.stream().forEach( process -> {
if(!monitor.isCanceled()) {
monitor.setTaskName(Messages.bind(Messages.validatingProcess, process.getName(), process.getVersion()));
status.add(new ProcessValidationStatus(process,validator.validate(process, monitor)));
}
});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment