Commit 521d39a6 authored by azara's avatar azara
Browse files

Add an entry in 5.x migration report when Reflection is used in Groovy

and Connectors calling process level libraries
parent ccb1fbda
package org.bonitasoft.studio.common;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.bonitasoft.studio.common.emf.tools.ModelHelper;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.jface.ValidationDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.model.process.MainProcess;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.Parameterization;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
public class ProcessesValidationAction {
private List<AbstractProcess> listOfProcessesToValidate;
private IStatus status;
public ProcessesValidationAction(List<AbstractProcess> executableProcesses){
this.listOfProcessesToValidate = executableProcesses;
}
public void performValidation() {
final ICommandService cmdService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command cmd = cmdService.getCommand("org.bonitasoft.studio.validation.batchValidation");
if (cmd.isEnabled()) {
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
Set<String> procFiles = new HashSet<String>();
for (AbstractProcess p : listOfProcessesToValidate) {
Resource eResource = p.eResource();
if (eResource != null) {
procFiles.add(URI.decode(eResource.getURI().lastSegment()));
}
}
try {
Parameterization showReportParam = new Parameterization(cmd.getParameter("showReport"), Boolean.FALSE.toString());
Parameterization filesParam = new Parameterization(cmd.getParameter("diagrams"), procFiles.toString());
status = (IStatus) handlerService.executeCommand(new ParameterizedCommand(cmd, new Parameterization[] { showReportParam,
filesParam }), null);
} catch (Exception e) {
BonitaStudioLog.error(e);
}
}
}
private boolean statusContainsError() {
if (status != null) {
for (IStatus s : status.getChildren()) {
if (s.getSeverity() == IStatus.WARNING || s.getSeverity() == IStatus.ERROR) {
return true;
}
}
}
return false;
}
public boolean displayConfirmationDialog(){
if (statusContainsError()) {
if (!FileActionDialog.getDisablePopup()) {
String errorMessage = Messages.errorValidationMessage
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getTitle()
+ Messages.errorValidationContinueAnywayMessage;
int result = new ValidationDialog(Display.getDefault().getActiveShell(), Messages.validationFailedTitle, errorMessage,
ValidationDialog.YES_NO_SEEDETAILS).open();
if (result == ValidationDialog.NO) {
return false;
} else {
if (result == ValidationDialog.SEE_DETAILS) {
activateValidationPart();
return false;
}
}
}
}
return true;
}
public boolean displayOkSeeMoreDetailsDialog(){
if (statusContainsError()) {
String errorMessage = Messages.errorValidationMessage
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getTitle();
int result = new ValidationDialog(Display.getDefault().getActiveShell(), Messages.validationFailedTitle, errorMessage,
ValidationDialog.OK_SEEDETAILS).open();
if (result == ValidationDialog.SEE_DETAILS) {
activateValidationPart();
}
}
return true;
}
public void activateValidationPart(){
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart part = activePage.getActiveEditor();
if (part != null && part instanceof DiagramEditor) {
MainProcess proc = ModelHelper.getMainProcess(((DiagramEditor) part).getDiagramEditPart().resolveSemanticElement());
String partName = proc.getName() + " (" + proc.getVersion() + ")";
for (IEditorReference ref : activePage.getEditorReferences()) {
if (partName.equals(ref.getPartName())) {
activePage.activate(ref.getPart(true));
break;
}
}
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
activePage.showView("org.bonitasoft.studio.validation.view");
} catch (PartInitException e) {
BonitaStudioLog.error(e);
}
}
});
}
}
......@@ -118,4 +118,6 @@ descripitonProperty=Description
tooLongDescriptionHasBeenTruncated=A description in this element has been truncated because it was exceeding the new maximum of allowed characters
warningImageFormat=Invalid image format
warningImageFormatMessage={0} could not be imported because it is not in the correct format. Please use one of the following supported formats: *.gif;*.jpg;*.jpeg;*.png;*.bmp.
migratingCustomConnector=Migrating custom connector {0}...
\ No newline at end of file
migratingCustomConnector=Migrating custom connector {0}...
groovyForNameWarningDescription=Groovy reflection has been detected in script. The classpath management has changed and you should consider to change the script or put libraries in shared classpath
groovyForNameWarningPropertyName=Script content
\ No newline at end of file
......@@ -11884,7 +11884,8 @@
<changes xsi:type="history:MigrationChange" migration="org.bonitasoft.studio.importer.bar.custom.migration.AutoLoginMigration"/>
<changes xsi:type="history:MigrationChange" migration="org.bonitasoft.studio.importer.bar.custom.migration.StartTimerCustomMigration"/>
<changes xsi:type="history:MigrationChange" migration="org.bonitasoft.studio.importer.bar.custom.migration.ResourceFolderMigration"/>
<changes xsi:type="history:MigrationChange" migration="org.bonitasoft.studio.importer.bar.custom.migration.ElementDocumentationCustomMigration"/>
<changes xsi:type="history:MigrationChange" migration="org.bonitasoft.studio.importer.bar.custom.migration.ElementDocumentationCustomMigration"/>
<changes xsi:type="history:MigrationChange" migration="org.bonitasoft.studio.importer.bar.custom.migration.GroovyMigration"/>
</releases>
<releases/>
</history:History>
package org.bonitasoft.studio.importer.bar.custom.migration;
import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.importer.bar.i18n.Messages;
import org.bonitasoft.studio.migration.migrator.ReportCustomMigration;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.edapt.migration.Instance;
import org.eclipse.emf.edapt.migration.Metamodel;
import org.eclipse.emf.edapt.migration.MigrationException;
import org.eclipse.emf.edapt.migration.Model;
public class GroovyMigration extends ReportCustomMigration {
private final String FOR_NAME_STRING = "Class.forName(";
@Override
public void migrateAfter(Model model, Metamodel metamodel)
throws MigrationException {
for (Instance expression : model.getAllInstances("expression.Expression")){
String expressionType = expression.get("type");
if (ExpressionConstants.SCRIPT_TYPE.equals(expressionType)){
if (containsForNameString((String)expression.get("content"))){
addReportChange((String)expression.get("name"),
expression.getType().getEClass().getName(),
expression.getContainer().getUuid(),
Messages.groovyForNameWarningDescription,
Messages.groovyForNameWarningPropertyName,
IStatus.WARNING);
}
}
}
}
private boolean containsForNameString(String script){
return script.contains(FOR_NAME_STRING);
}
}
......@@ -266,6 +266,12 @@ public class Messages extends NLS {
public static String migratingCustomConnector;
public static String groovyForNameWarningDescription;
public static String propertyName;
public static String groovyForNameWarningPropertyName;
static {
initializeMessages("messages", Messages.class); //$NON-NLS-1$
}
......
Supports Markdown
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