Commit e6dc13b0 authored by Romain Bioteau's avatar Romain Bioteau

Refactor validation

Improve monitor
parent 08f91b2d
......@@ -489,8 +489,8 @@
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
<plugin
id="org.bonitasoft.studio.parameters"
download-size="0"
install-size="0"
......@@ -511,4 +511,11 @@
version="0.0.0"
unpack="false"/>
<plugin
id="org.bonitasoft.studio.validation.common"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>
......@@ -63,7 +63,9 @@ Require-Bundle: org.bonitasoft.studio.diagram,
org.mockito;bundle-version="1.9.5";resolution:=optional,
org.junit;bundle-version="4.11.0";resolution:=optional,
assertj-core;bundle-version="1.5.0";resolution:=optional,
org.bonitasoft.studio.tests-utils;bundle-version="6.4.1";resolution:=optional
org.bonitasoft.studio.tests-utils;bundle-version="6.4.1";resolution:=optional,
org.eclipse.debug.ui,
org.codehaus.groovy.eclipse.ui;bundle-version="2.9.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Import-Package: javax.annotation;version="1.1.0",
......
......@@ -482,6 +482,11 @@
id="org.bonitasoft.studio.application.command.rename"
name="Rename Command">
</command>
<command
defaultHandler="org.bonitasoft.studio.application.handler.ImportArtifactsFromZipHandler"
id="org.bonitasoft.studio.repository.importArtifacts"
name="import artifacts">
</command>
</extension>
<extension
point="org.eclipse.ui.views">
......
/**
* Copyright (C) 2009-2012 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
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.application;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.debug.DebugPlugin;
import org.bonitasoft.studio.validation.ValidationPlugin;
......@@ -32,72 +28,71 @@ import org.osgi.framework.BundleException;
*/
public class ApplicationPlugin extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.bonitasoft.studio.application"; //$NON-NLS-1$
// The plug-in ID
public static final String PLUGIN_ID = "org.bonitasoft.studio.application"; //$NON-NLS-1$
public static final String BAR_DEFAULT_PATH = "barPath";
public static final String BAR_DEFAULT_PATH = "barPath";
// The shared instance
private static ApplicationPlugin plugin;
// The shared instance
private static ApplicationPlugin plugin;
/**
* The constructor
*/
public ApplicationPlugin() {
}
/**
* The constructor
*/
public ApplicationPlugin() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
plugin = this;
init(context);
}
super.start(context);
plugin = this;
init(context);
}
private void init(final BundleContext context) throws CoreException {
if(getDialogSettings().get(BAR_DEFAULT_PATH) == null){
getDialogSettings().put(BAR_DEFAULT_PATH, System.getProperty("user.home"));
}
try {
DebugPlugin.getDefault().getBundle().start();
ValidationPlugin.getDefault().getBundle().start();
} catch (final BundleException e) {
BonitaStudioLog.error(e);
}
}
private void init(final BundleContext context) throws CoreException {
if (getDialogSettings().get(BAR_DEFAULT_PATH) == null) {
getDialogSettings().put(BAR_DEFAULT_PATH, System.getProperty("user.home"));
}
try {
DebugPlugin.getDefault().getBundle().start();
ValidationPlugin.getDefault().getBundle().start();
} catch (final BundleException e) {
BonitaStudioLog.error(e);
}
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(final BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static ApplicationPlugin getDefault() {
return plugin;
}
plugin = null;
super.stop(context);
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(final String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static ApplicationPlugin getDefault() {
return plugin;
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(final String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
}
......@@ -73,6 +73,7 @@ import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
import org.eclipse.ui.internal.splash.SplashHandlerFactory;
import org.osgi.framework.BundleException;
public class BonitaStudioWorkbenchAdvisor extends WorkbenchAdvisor implements IStartup {
......@@ -148,6 +149,8 @@ public class BonitaStudioWorkbenchAdvisor extends WorkbenchAdvisor implements IS
}
monitor.beginTask(BOSSplashHandler.BONITA_TASK, 100);
startGroovyPlugin();
monitor.subTask(Messages.initializingCurrentRepository);
disableInternalWebBrowser();
......@@ -156,7 +159,6 @@ public class BonitaStudioWorkbenchAdvisor extends WorkbenchAdvisor implements IS
final List<IConfigurationElement> sortedConfigElems = retrievePreStartupContribution();
sortConfigurationElementsByPriority(sortedConfigElems);
executeConfigurationElement(sortedConfigElems);
try {
ResourcesPlugin.getWorkspace().run(initRepositoryRunnable(), monitor);
} catch (final CoreException e) {
......@@ -167,6 +169,14 @@ public class BonitaStudioWorkbenchAdvisor extends WorkbenchAdvisor implements IS
executeContributions();
}
protected void startGroovyPlugin() {
try {
org.codehaus.groovy.eclipse.GroovyPlugin.getDefault().getBundle().start();
} catch (final BundleException e1) {
BonitaStudioLog.error("Failed to loag Groovy plugin", e1);
}
}
private void checkCurrentRepository(final IProgressMonitor monitor) {
final String current = CommonRepositoryPlugin.getDefault().getPreferenceStore().getString(RepositoryPreferenceConstant.CURRENT_REPOSITORY);
final IRepository repository = RepositoryManager.getInstance().getCurrentRepository();
......
......@@ -17,10 +17,13 @@ package org.bonitasoft.studio.application.advisor;
import java.io.File;
import java.io.FileFilter;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.model.IRepository;
import org.bonitasoft.studio.importer.ImporterRegistry;
import org.bonitasoft.studio.importer.processors.ToProcProcessor;
import org.eclipse.core.resources.ResourcesPlugin;
/**
......@@ -49,7 +52,13 @@ public class InitWorkspaceAdvisor extends InstallerApplicationWorkbenchAdvisor {
final IRepository repository = RepositoryManager.getInstance().getRepository(repositoryName);
if (repository != null) {
try {
repository.importFromArchive(workspaceArchive, false, false);
final boolean disableConfirmation = FileActionDialog.getDisablePopup();
FileActionDialog.setDisablePopup(false);
final ToProcProcessor importer = ImporterRegistry.getInstance().createImporterFor(workspaceArchive.getName());
if (importer != null) {
importer.createDiagram(workspaceArchive.toURL(), Repository.NULL_PROGRESS_MONITOR);
}
FileActionDialog.setDisablePopup(disableConfirmation);
workspaceArchive.delete();
} catch (final Exception e) {
BonitaStudioLog.error(e);
......@@ -59,5 +68,4 @@ public class InitWorkspaceAdvisor extends InstallerApplicationWorkbenchAdvisor {
RepositoryManager.getInstance().setRepository("default", Repository.NULL_PROGRESS_MONITOR);
}
}
}
......@@ -3,16 +3,18 @@
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
*/
package org.bonitasoft.studio.common.repository.handler;
package org.bonitasoft.studio.application.handler;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import org.bonitasoft.studio.common.jface.BonitaErrorDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.Messages;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.operation.ImportBosArchiveOperation;
import org.bonitasoft.studio.importer.ImporterRegistry;
import org.bonitasoft.studio.importer.processors.ToProcProcessor;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
......@@ -26,13 +28,10 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
/**
*
* @author Baptiste Mesta
*
* Handler that launch a dialog to import artifacts from a zip
*
*/
public class ImportArtifactsFromZip extends AbstractHandler {
public class ImportArtifactsFromZipHandler extends AbstractHandler {
public static final String FILE_EXTENSION_OLD = ".bosworkspace";
......@@ -50,10 +49,14 @@ public class ImportArtifactsFromZip extends AbstractHandler {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final ImportBosArchiveOperation operation = new ImportBosArchiveOperation();
operation.setArchiveFile(workspaceArchiveFile);
operation.setCurrentRepository(RepositoryManager.getInstance().getCurrentRepository());
operation.run(monitor);
final ToProcProcessor importer = ImporterRegistry.getInstance().createImporterFor(workspaceArchiveFile);
try {
importer.createDiagram(new File(workspaceArchiveFile).toURL(), monitor);
} catch (final MalformedURLException e) {
throw new InvocationTargetException(e);
} catch (final Exception e) {
throw new InvocationTargetException(e);
}
}
};
......
......@@ -47,11 +47,6 @@
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="org.bonitasoft.studio.common.repository.handler.ImportArtifactsFromZip"
id="org.bonitasoft.studio.repository.importArtifacts"
name="import artifacts">
</command>
<command
defaultHandler="org.bonitasoft.studio.common.repository.handler.ExportArtifactsToZip"
id="org.bonitasoft.studio.repository.exportArtifacts"
......
......@@ -32,7 +32,6 @@ import org.apache.xbean.classloader.NonLockingJarFileClassLoader;
import org.bonitasoft.engine.bpm.bar.BusinessArchive;
import org.bonitasoft.studio.common.DateUtil;
import org.bonitasoft.studio.common.extension.BonitaStudioExtensionRegistryManager;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.core.BonitaBPMProjectClasspath;
import org.bonitasoft.studio.common.repository.core.BonitaBPMProjectMigrationOperation;
......@@ -42,7 +41,6 @@ import org.bonitasoft.studio.common.repository.model.IRepository;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.bonitasoft.studio.common.repository.operation.ExportBosArchiveOperation;
import org.bonitasoft.studio.common.repository.operation.ImportBosArchiveOperation;
import org.bonitasoft.studio.common.repository.preferences.RepositoryPreferenceConstant;
import org.bonitasoft.studio.common.repository.store.RepositoryStoreComparator;
import org.bonitasoft.studio.pics.Pics;
......@@ -461,17 +459,6 @@ public class Repository implements IRepository {
}
}
@Override
public void importFromArchive(final File archiveFile, final boolean askOverwrite, final boolean validateAfterImport) {
final boolean disableConfirmation = FileActionDialog.getDisablePopup();
FileActionDialog.setDisablePopup(!askOverwrite);
final ImportBosArchiveOperation operation = new ImportBosArchiveOperation(validateAfterImport);
operation.setArchiveFile(archiveFile.getAbsolutePath());
operation.setCurrentRepository(RepositoryManager.getInstance().getCurrentRepository());
operation.run(NULL_PROGRESS_MONITOR);
FileActionDialog.setDisablePopup(disableConfirmation);
}
@Override
public void exportToArchive(final String fileName) {
final ExportBosArchiveOperation operation = new ExportBosArchiveOperation();
......
......@@ -14,7 +14,6 @@
*/
package org.bonitasoft.studio.common.repository.model;
import java.io.File;
import java.util.List;
import org.eclipse.core.resources.IFile;
......@@ -63,8 +62,6 @@ public interface IRepository extends IFileStoreChangeListener {
Image getIcon();
void importFromArchive(File archiveFile, boolean askOverwrite, boolean validateAfterImport);
void exportToArchive(String file);
IRepositoryFileStore getFileStore(IResource resource);
......
......@@ -234,9 +234,6 @@ searchIndexListViewerTitle=Search index
parameterListTitle=Parameter
widgetListViewerTitle=Widget
outlineDialogRefactoringText=Here are the references found for the {0}\:
errorValidationMessage=Some errors have been found in the diagram
errorValidationContinueAnywayMessage=\n Do you want to continue anyway?
validationFailedTitle=Some errors have been found in the diagram
removalConfirmationDialogTitle=Removal confirmation
endWarningMessage=If you click OK, the refactor window is displayed and you can update the scripts that use
showHelp=Show help
......
......@@ -18,7 +18,6 @@ import org.eclipse.osgi.util.NLS;
/**
* @author Mickael Istria
*
*/
public class Messages extends NLS {
......@@ -192,7 +191,6 @@ public class Messages extends NLS {
public static String edit;
public static String openNameAndVersionDialogTitle;
public static String january;
public static String february;
public static String march;
......@@ -272,9 +270,6 @@ public class Messages extends NLS {
public static String outlineDialogRefactoringText;
public static String removalConfirmationDialogTitle;
public static String errorValidationMessage;
public static String errorValidationContinueAnywayMessage;
public static String validationFailedTitle;
public static String endWarningMessage;
public static String showHelp;
public static String createAndNewButton;
......@@ -283,5 +278,4 @@ public class Messages extends NLS {
public static String hideHelp;
public static String toggleHelp;
}
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 final List<AbstractProcess> listOfProcessesToValidate;
private IStatus status;
public ProcessesValidationAction(final List<AbstractProcess> processes){
listOfProcessesToValidate = processes;
}
public void performValidation() {
final ICommandService cmdService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
final Command cmd = cmdService.getCommand("org.bonitasoft.studio.validation.batchValidation");
if (cmd.isEnabled()) {
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
final Set<String> procFiles = new HashSet<String>();
for (final AbstractProcess p : listOfProcessesToValidate) {
final Resource eResource = p.eResource();
if (eResource != null) {
procFiles.add(URI.decode(eResource.getURI().lastSegment()));
}
}
try {
final Parameterization showReportParam = new Parameterization(cmd.getParameter("showReport"), Boolean.FALSE.toString());
final Parameterization filesParam = new Parameterization(cmd.getParameter("diagrams"), procFiles.toString());
status = (IStatus) handlerService.executeCommand(new ParameterizedCommand(cmd, new Parameterization[] { showReportParam,
filesParam }), null);
} catch (final Exception e) {
BonitaStudioLog.error(e);
}
}
}
private boolean statusContainsError() {
if (status != null) {
for (final 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()) {
final String errorMessage = Messages.errorValidationMessage
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getTitle()
+ Messages.errorValidationContinueAnywayMessage;
final 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) {
showValidationPart();
return false;
}
}
}
}
return true;
}
public boolean displayOkSeeMoreDetailsDialog(){
if (statusContainsError()) {
final String errorMessage = Messages.errorValidationMessage
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getTitle();
final int result = new ValidationDialog(Display.getDefault().getActiveShell(), Messages.validationFailedTitle, errorMessage,
ValidationDialog.OK_SEEDETAILS).open();
if (result == ValidationDialog.SEE_DETAILS) {
showValidationPart();
}
}
return true;
}
public IStatus getStatus() {
return status;
}
public static void showValidationPart() {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final IEditorPart part = activePage.getActiveEditor();
if (part != null && part instanceof DiagramEditor) {
final MainProcess proc = ModelHelper.getMainProcess(((DiagramEditor) part).getDiagramEditPart().resolveSemanticElement());
final String partName = proc.getName() + " (" + proc.getVersion() + ")";
for (final 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 (final PartInitException e) {
BonitaStudioLog.error(e);
}
}
});
}
}
/**
* Copyright (C) 2009 BonitaSoft S.A.
* BonitaSoft, 31 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
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.log;
......@@ -24,11 +21,9 @@ import org.eclipse.e4.ui.internal.workbench.WorkbenchLogger;
/**
* @author Romain Bioteau
*
*/
public class BonitaStudioLog {
public static void log(final String message) {
final Logger logger = getLogger(Activator.PLUGIN_ID);
if (logger != null) {
......@@ -65,6 +60,16 @@ public class BonitaStudioLog {
}
}