Commit 4b34a9cb authored by Romain Bioteau's avatar Romain Bioteau
Browse files

feat(BOSImport) Use extension for BOS Validator (#386)

* feat(BOSImport) Use extension for BOS Validator
parent 01f86614
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src-test/java"/>
......
#Mon Feb 27 13:30:04 CET 2012
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.compiler.source=1.7
......@@ -25,8 +25,10 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.databinding;bundle-version="1.4.2",
org.bonitasoft.studio.validation.common;bundle-version="7.1.0",
org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.8.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Import-Package: org.bonitasoft.engine.bpm.bar
Export-Package: org.bonitasoft.studio.importer.bos.factory,
org.bonitasoft.studio.importer.bos.operation
org.bonitasoft.studio.importer.bos.operation,
org.bonitasoft.studio.importer.bos.status,
org.bonitasoft.studio.importer.bos.validator
......@@ -5,6 +5,7 @@ bin.includes = META-INF/,\
plugin.xml,\
icons/,\
messages.properties,\
plugin.properties
plugin.properties,\
schema/
src.excludes = src-test/java/
src.excludes = src-test/resources/
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="org.bonitasoft.studio.importer.bos.validator" name="org.bonitasoft.studio.importer.bos.validator" schema="schema/org.bonitasoft.studio.importer.bos.validator.exsd"/>
<extension
point="org.bonitasoft.studio.importer.import">
<importFactory
......@@ -12,5 +13,11 @@
priorityDisplay="1">
</importFactory>
</extension>
<extension
point="org.bonitasoft.studio.importer.bos.validator">
<bosImporterValidator
class="org.bonitasoft.studio.importer.bos.validator.DiagramValidator">
</bosImporterValidator>
</extension>
</plugin>
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.bonitasoft.studio.importer.bos" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.bonitasoft.studio.importer.bos" id="org.bonitasoft.studio.importer.bos.validator" name="org.bonitasoft.studio.importer.bos.validator"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence>
<element ref="bosImporterValidator" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="bosImporterValidator">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.bonitasoft.studio.importer.bos.validator.BosImporterValidator"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
......@@ -5,6 +5,7 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import java.io.File;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
......@@ -40,6 +41,7 @@ public class ImportBosArchiveOperationTest {
public void setUp() throws Exception {
archiveFile = new File(ImportBosArchiveOperationTest.class.getResource("/customer_support_2.0.bos").getFile());
doNothing().when(operationUnserTest).cleanTmpProject();
doReturn(Collections.emptyList()).when(operationUnserTest).getValidators();
doReturn(container).when(operationUnserTest).createTempProject(archiveFile, monitor);
doReturn(container).when(operationUnserTest).getRootContainer(Mockito.any(IContainer.class), Mockito.any(Map.class));
doReturn(new Properties()).when(operationUnserTest).getManifestInfo(container);
......
......@@ -14,6 +14,7 @@
*/
package org.bonitasoft.studio.importer.bos.operation;
import static com.google.common.collect.Lists.newArrayList;
import static org.bonitasoft.studio.common.Messages.bosProductName;
import static org.bonitasoft.studio.common.jface.FileActionDialog.activateYesNoToAll;
import static org.bonitasoft.studio.common.jface.FileActionDialog.deactivateYesNoToAll;
......@@ -32,6 +33,7 @@ import java.util.Properties;
import java.util.Set;
import org.bonitasoft.studio.common.ProductVersion;
import org.bonitasoft.studio.common.extension.BonitaStudioExtensionRegistryManager;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.CommonRepositoryPlugin;
......@@ -41,15 +43,12 @@ import org.bonitasoft.studio.common.repository.filestore.FileStoreChangeEvent;
import org.bonitasoft.studio.common.repository.filestore.FileStoreChangeEvent.EventType;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.bonitasoft.studio.common.repository.model.ReadFileStoreException;
import org.bonitasoft.studio.common.repository.operation.ExportBosArchiveOperation;
import org.bonitasoft.studio.importer.bos.BosArchiveImporterPlugin;
import org.bonitasoft.studio.importer.bos.status.ImportBosArchiveStatusBuilder;
import org.bonitasoft.studio.importer.bos.validator.BosImporterValidator;
import org.bonitasoft.studio.importer.bos.validator.ValidationException;
import org.bonitasoft.studio.importer.ui.dialog.SkippableProgressMonitorJobsDialog;
import org.bonitasoft.studio.model.process.AbstractProcess;
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.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
......@@ -60,6 +59,7 @@ import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
......@@ -175,20 +175,13 @@ public class ImportBosArchiveOperation implements IRunnableWithProgress {
}
final ImportBosArchiveStatusBuilder statusBuilder = new ImportBosArchiveStatusBuilder();
if (validate) {
for (final IRepositoryFileStore diagramFileStore : iResourceImporter.getImportedProcesses()) {
final List<BosImporterValidator> validators = getValidators();
for (final BosImporterValidator validator : validators) {
try {
final AbstractProcess process = (AbstractProcess) diagramFileStore.getContent();
final RunProcessesValidationOperation validationAction = new RunProcessesValidationOperation(
new BatchValidationOperation(
new OffscreenEditPartFactory(org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory.getInstance()),
new ValidationMarkerProvider()));
validationAction.addProcess(process);
validationAction.run(monitor);
statusBuilder.addStatus(process, validationAction.getStatus());
} catch (final ReadFileStoreException e) {
throw new InvocationTargetException(e, "Failed to retrieve diagram content");
validator.validate(iResourceImporter, statusBuilder, monitor);
} catch (final ValidationException e) {
statusBuilder.addStatus(new Status(IStatus.ERROR, BosArchiveImporterPlugin.PLUGIN_ID, "Validation error", e));
}
}
}
validationStatus = monitor.isCanceled() ? ValidationStatus.warning(org.bonitasoft.studio.importer.bos.i18n.Messages.skippedValidationMessage)
......@@ -196,6 +189,19 @@ public class ImportBosArchiveOperation implements IRunnableWithProgress {
.done();
}
protected List<BosImporterValidator> getValidators() {
final List<BosImporterValidator> validators = newArrayList();
for (final IConfigurationElement element : BonitaStudioExtensionRegistryManager.getInstance()
.getConfigurationElements("org.bonitasoft.studio.importer.bos.validator")) {
try {
validators.add((BosImporterValidator) element.createExecutableExtension("class"));
} catch (final CoreException e) {
BonitaStudioLog.error(e);
}
}
return validators;
}
public void setCurrentRepository(final Repository currentRepository) {
this.currentRepository = currentRepository;
}
......
/**
* Copyright (C) 2016 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.importer.bos.validator;
import org.bonitasoft.studio.importer.bos.operation.IResourceImporter;
import org.bonitasoft.studio.importer.bos.status.ImportBosArchiveStatusBuilder;
import org.eclipse.core.runtime.IProgressMonitor;
public interface BosImporterValidator {
ImportBosArchiveStatusBuilder validate(IResourceImporter resourceImporter, ImportBosArchiveStatusBuilder statusBuilder, IProgressMonitor monitor)
throws ValidationException;
}
/**
* Copyright (C) 2016 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.importer.bos.validator;
import java.lang.reflect.InvocationTargetException;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.ReadFileStoreException;
import org.bonitasoft.studio.importer.bos.operation.IResourceImporter;
import org.bonitasoft.studio.importer.bos.status.ImportBosArchiveStatusBuilder;
import org.bonitasoft.studio.model.process.AbstractProcess;
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.eclipse.core.runtime.IProgressMonitor;
public class DiagramValidator implements BosImporterValidator {
/* (non-Javadoc)
* @see org.bonitasoft.studio.importer.bos.validator.BosImporterValidator#validate(org.bonitasoft.studio.importer.bos.operation.IResourceImporter)
*/
@Override
public ImportBosArchiveStatusBuilder validate(IResourceImporter resourceImporter, ImportBosArchiveStatusBuilder statusBuilder, IProgressMonitor monitor)
throws ValidationException {
for (final IRepositoryFileStore diagramFileStore : resourceImporter.getImportedProcesses()) {
try {
final AbstractProcess process = (AbstractProcess) diagramFileStore.getContent();
final RunProcessesValidationOperation validationAction = new RunProcessesValidationOperation(
new BatchValidationOperation(
new OffscreenEditPartFactory(org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory.getInstance()),
new ValidationMarkerProvider()));
validationAction.addProcess(process);
validationAction.run(monitor);
statusBuilder.addStatus(process, validationAction.getStatus());
} catch (final ReadFileStoreException | InvocationTargetException | InterruptedException e) {
throw new ValidationException(e, "Failed to validate diagram content");
}
}
return statusBuilder;
}
}
/**
* Copyright (C) 2016 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.importer.bos.validator;
public class ValidationException extends Exception {
public ValidationException(Throwable t, String message) {
super(message, t);
}
}
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