Commit a0709329 authored by Romain Bioteau's avatar Romain Bioteau Committed by Adrien

fix(import) import workspace failing (#1561)

* Import workspace fails when trying to load an EMF resource containing
v6 legacy forms feature
* Fix some issue during migration

Closes BS-19292
parent e96b55c7
...@@ -29,6 +29,7 @@ import org.eclipse.core.runtime.CoreException; ...@@ -29,6 +29,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.edapt.migration.MigrationException; import org.eclipse.emf.edapt.migration.MigrationException;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.PlatformUI;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
/** /**
...@@ -120,7 +121,9 @@ public class ActorFilterDefRepositoryStore extends AbstractDefinitionRepositoryS ...@@ -120,7 +121,9 @@ public class ActorFilterDefRepositoryStore extends AbstractDefinitionRepositoryS
@Override @Override
public void migrate(final IProgressMonitor monitor) throws CoreException, MigrationException { public void migrate(final IProgressMonitor monitor) throws CoreException, MigrationException {
super.migrate(monitor); super.migrate(monitor);
getResourceProvider().loadDefinitionsCategories(null); if(PlatformUI.isWorkbenchRunning()) {
getResourceProvider().loadDefinitionsCategories(null);
}
} }
} }
...@@ -722,11 +722,7 @@ public class Repository implements IRepository, IJavaContainer, IRenamable { ...@@ -722,11 +722,7 @@ public class Repository implements IRepository, IJavaContainer, IRenamable {
public void migrate(final IProgressMonitor monitor) throws CoreException, MigrationException { public void migrate(final IProgressMonitor monitor) throws CoreException, MigrationException {
Assert.isNotNull(project); Assert.isNotNull(project);
monitor.beginTask(String.format(Messages.migratingRepository, getName()), IProgressMonitor.UNKNOWN); monitor.beginTask(String.format(Messages.migratingRepository, getName()), IProgressMonitor.UNKNOWN);
IFolder settings = project.getFolder(".settings");
if (settings.exists()) {
settings.delete(true, null);
}
for (final IRepositoryStore<?> store : getAllStores()) { for (final IRepositoryStore<?> store : getAllStores()) {
store.createRepositoryStore(this); store.createRepositoryStore(this);
store.migrate(monitor); store.migrate(monitor);
......
...@@ -27,8 +27,10 @@ import org.bonitasoft.studio.connectors.i18n.Messages; ...@@ -27,8 +27,10 @@ import org.bonitasoft.studio.connectors.i18n.Messages;
import org.bonitasoft.studio.pics.Pics; import org.bonitasoft.studio.pics.Pics;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.edapt.migration.MigrationException; import org.eclipse.emf.edapt.migration.MigrationException;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.PlatformUI;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
/** /**
...@@ -128,7 +130,9 @@ public class ConnectorDefRepositoryStore extends AbstractDefinitionRepositorySto ...@@ -128,7 +130,9 @@ public class ConnectorDefRepositoryStore extends AbstractDefinitionRepositorySto
@Override @Override
public void migrate(final IProgressMonitor monitor) throws CoreException, MigrationException { public void migrate(final IProgressMonitor monitor) throws CoreException, MigrationException {
super.migrate(monitor); super.migrate(monitor);
getResourceProvider().loadDefinitionsCategories(null); if(PlatformUI.isWorkbenchRunning()) {
getResourceProvider().loadDefinitionsCategories(null);
}
} }
} }
...@@ -33,6 +33,9 @@ public abstract class WebArtifactRepositoryStore<T extends IRepositoryFileStore> ...@@ -33,6 +33,9 @@ public abstract class WebArtifactRepositoryStore<T extends IRepositoryFileStore>
final List<T> result = new ArrayList<>(); final List<T> result = new ArrayList<>();
final IFolder folder = getResource(); final IFolder folder = getResource();
if(!folder.exists() || !folder.isAccessible()) {
return result;
}
try { try {
for (final IResource r : folder.members()) { for (final IResource r : folder.members()) {
if (!r.isHidden() && !r.getName().startsWith(".") && r instanceof IFolder) { if (!r.isHidden() && !r.getName().startsWith(".") && r instanceof IFolder) {
......
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
package org.bonitasoft.studio.importer.bos.operation; package org.bonitasoft.studio.importer.bos.operation;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Stream; import java.util.stream.Stream;
...@@ -39,6 +41,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; ...@@ -39,6 +41,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.command.BasicCommandStack; import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.common.util.URI; import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.emf.edapt.migration.MigrationException; import org.eclipse.emf.edapt.migration.MigrationException;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory; import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
...@@ -80,7 +83,8 @@ public class ImportWorkspaceApplication implements IApplication { ...@@ -80,7 +83,8 @@ public class ImportWorkspaceApplication implements IApplication {
.map(repositoryAccessor::getRepository) .map(repositoryAccessor::getRepository)
.forEach(repository -> { .forEach(repository -> {
System.out.println( System.out.println(
String.format("$SCAN_PROGRESS_%s:%s:%s:%s", repository.getName(), repository.getVersion(), String.format("$SCAN_PROGRESS_%s:%s:%s:%s", repository.getName(),
repository.getVersion(),
findEdition(repository), connected(repository))); findEdition(repository), connected(repository)));
export export
.map(value -> value.split("=")[1]) .map(value -> value.split("=")[1])
...@@ -143,9 +147,10 @@ public class ImportWorkspaceApplication implements IApplication { ...@@ -143,9 +147,10 @@ public class ImportWorkspaceApplication implements IApplication {
.addAdapterFactory(new ResourceItemProviderAdapterFactory()); .addAdapterFactory(new ResourceItemProviderAdapterFactory());
adapterFactory adapterFactory
.addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); .addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(adapterFactory, AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
new BasicCommandStack(), new HashMap<Resource, Boolean>()); new BasicCommandStack(), new HashMap<Resource, Boolean>());
URI fileURI = URI.createFileURI(file.getAbsolutePath()); URI fileURI = URI.createFileURI(file.getAbsolutePath());
editingDomain.getResourceSet().getLoadOptions().put(XMIResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
Resource resource = editingDomain.getResourceSet().getResource(fileURI, true); Resource resource = editingDomain.getResourceSet().getResource(fileURI, true);
MainProcess process = (MainProcess) resource.getContents().get(0); MainProcess process = (MainProcess) resource.getContents().get(0);
return process.getConfigId().toString().contains("sp"); return process.getConfigId().toString().contains("sp");
......
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