Commit 6fc64d88 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub

fix(import) fix import workspace (#1496)

Closes BS-19105
parent 005c7216
......@@ -320,7 +320,8 @@ public class Repository implements IRepository, IJavaContainer, IRenamable {
}
protected void closeAllEditors() {
Display.getDefault().syncExec(() -> {
if (PlatformUI.isWorkbenchRunning()) {
Display.getDefault().syncExec(() -> {
final IWorkbenchWindow activeWorkbenchWindow = PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null
......@@ -331,7 +332,8 @@ public class Repository implements IRepository, IJavaContainer, IRenamable {
&& !(activeWorkbenchWindow.getActivePage().getActivePart() instanceof ViewIntroAdapterPart)) {
Display.getDefault().readAndDispatch();
}
});
});
}
}
protected synchronized void initRepositoryStores(final IProgressMonitor monitor) {
......
......@@ -59,6 +59,7 @@ import org.eclipse.jdt.internal.launching.StandardVMType;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.SocketUtil;
import org.eclipse.ui.PlatformUI;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.restlet.resource.ClientResource;
......@@ -321,12 +322,16 @@ public class UIDesignerServerManager implements IBonitaProjectListener {
@Override
public void projectOpened(Repository repository, IProgressMonitor monitor) {
start(repository, monitor);
if (PlatformUI.isWorkbenchRunning()) {
start(repository, monitor);
}
}
@Override
public void projectClosed(Repository repository, IProgressMonitor monitor) {
stop();
if (PlatformUI.isWorkbenchRunning()) {
stop();
}
}
}
......@@ -27,6 +27,7 @@ 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.designer.UIDesignerPlugin;
import org.bonitasoft.studio.designer.core.UIDesignerServerManager;
import org.bonitasoft.studio.designer.core.bar.BarResourceCreationException;
import org.bonitasoft.studio.designer.core.bos.WebFormBOSArchiveFileStoreProvider;
import org.eclipse.jface.viewers.StyledString;
......@@ -73,7 +74,7 @@ public class WebPageFileStore extends InFolderJSONFileStore implements IDeployab
@Override
public Set<IRepositoryFileStore> getRelatedFileStore() {
if (PlatformUtil.isHeadless()) {
if (PlatformUtil.isHeadless() || !UIDesignerServerManager.getInstance().isStarted()) {
return super.getRelatedFileStore();
}
if (webFormBOSArchiveFileStoreProvider != null) {
......
......@@ -21,6 +21,7 @@ import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.PlatformUI;
public class EnginePreferencesInitializer extends AbstractPreferenceInitializer {
......@@ -40,9 +41,11 @@ public class EnginePreferencesInitializer extends AbstractPreferenceInitializer
store.setDefault(EnginePreferenceConstants.TOMCAT_XMX_OPTION, 512);
store.setDefault(EnginePreferenceConstants.TOMCAT_EXTRA_PARAMS, "-DnoCacheCustomPage=true");
DebugUITools.getPreferenceStore().setValue(
org.eclipse.debug.internal.ui.IInternalDebugUIConstants.PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH,
MessageDialogWithToggle.NEVER);
if (PlatformUI.isWorkbenchRunning()) {
DebugUITools.getPreferenceStore().setValue(
org.eclipse.debug.internal.ui.IInternalDebugUIConstants.PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH,
MessageDialogWithToggle.NEVER);
}
}
}
......@@ -50,4 +50,5 @@ legacyFormsNotImported=Linked to 6.x forms - not imported
formsRemovedFromStudio=They have been removed from Bonita Studio and will not be imported.
legacyFormsNotImportedFromWorkspace=6.x forms based on Google Web Toolkit (GWT) technology are not supported anymore.\nThey have been removed from Bonita Studio. Such forms and their related content will not be imported.
containsLegacyFormsWarning=Contains 6.x forms. They are not supported anymore. They will be removed during migration.
spDiagramCannotBeImportedError=Designed with a Subscription edition. Incompatible with Community edition.
\ No newline at end of file
spDiagramCannotBeImportedError=Designed with a Subscription edition. Incompatible with Community edition.
projectConnectorToVCS='%s' is connected to a VCS. You must clone/checkout this project from Team menu.
\ No newline at end of file
package org.bonitasoft.studio.importer.bos;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
......@@ -15,9 +14,6 @@ public class BosArchiveImporterPlugin extends AbstractUIPlugin {
// The shared instance
private static BosArchiveImporterPlugin plugin;
static {
FieldDecorationRegistry.getDefault();
}
/**
* The constructor
......
......@@ -78,5 +78,6 @@ public class Messages extends NLS {
public static String legacyFormsNotImportedFromWorkspace;
public static String spDiagramCannotBeImportedError;
public static String containsLegacyFormsWarning;
public static String projectConnectorToVCS;
}
......@@ -15,6 +15,7 @@
package org.bonitasoft.studio.importer.bos.operation;
import java.io.File;
import java.util.HashMap;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
......@@ -24,15 +25,25 @@ import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.BonitaProjectNature;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.connector.model.definition.util.ConnectorDefinitionAdapterFactory;
import org.bonitasoft.studio.designer.core.repository.WebFragmentRepositoryStore;
import org.bonitasoft.studio.diagram.custom.repository.DiagramRepositoryStore;
import org.bonitasoft.studio.importer.bos.i18n.Messages;
import org.bonitasoft.studio.model.parameter.util.ParameterAdapterFactory;
import org.bonitasoft.studio.model.process.MainProcess;
import org.bonitasoft.studio.model.process.util.ProcessAdapterFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edapt.migration.MigrationException;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.ui.PlatformUI;
......@@ -69,8 +80,8 @@ public class ImportWorkspaceApplication implements IApplication {
.map(repositoryAccessor::getRepository)
.forEach(repository -> {
System.out.println(
String.format("$SCAN_PROGRESS_%s:%s:%s", repository.getName(), repository.getVersion(),
findEdition(repository)));
String.format("$SCAN_PROGRESS_%s:%s:%s:%s", repository.getName(), repository.getVersion(),
findEdition(repository), connected(repository)));
export
.map(value -> value.split("=")[1])
.map(repositories -> repositories.split(":"))
......@@ -108,18 +119,44 @@ public class ImportWorkspaceApplication implements IApplication {
}
private String findEdition(Repository repository) {
final DiagramRepositoryStore diagramStore = repository.getRepositoryStore(DiagramRepositoryStore.class);
final WebFragmentRepositoryStore fragmentStore = repository.getRepositoryStore(WebFragmentRepositoryStore.class);
if (!fragmentStore.isEmpty()) {
File repoDir = repository.getProject().getLocation().toFile();
File fragRepo = new File(repoDir, WebFragmentRepositoryStore.WEB_FRAGMENT_REPOSITORY_NAME);
if (fragRepo.listFiles(f -> !f.getName().startsWith(".") && f.isDirectory()).length > 0) {
return "Subscription";
}
if (!diagramStore.isEmpty()
&& diagramStore.getChildren().get(0).getContent().getConfigId().toString().contains("sp")) {
File diagramRepo = new File(repoDir, "diagrams");
File[] diagrams = diagramRepo.listFiles(f -> !f.getName().startsWith(".") && f.isFile());
if (diagrams.length > 0
&& isSPDiagram(diagrams[0])) {
return "Subscription";
}
return "Community";
}
private boolean isSPDiagram(File file) {
ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
adapterFactory.addAdapterFactory(new ProcessAdapterFactory());
adapterFactory.addAdapterFactory(new ParameterAdapterFactory());
adapterFactory.addAdapterFactory(new ConnectorDefinitionAdapterFactory());
adapterFactory
.addAdapterFactory(new ResourceItemProviderAdapterFactory());
adapterFactory
.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
new BasicCommandStack(), new HashMap<Resource, Boolean>());
URI fileURI = URI.createFileURI(file.getAbsolutePath());
Resource resource = editingDomain.getResourceSet().getResource(fileURI, true);
MainProcess process = (MainProcess) resource.getContents().get(0);
return process.getConfigId().toString().contains("sp");
}
private String connected(Repository repository) {
File git = new File(repository.getProject().getLocation().toFile(), ".git");
File svn = new File(repository.getProject().getLocation().toFile(), ".svn");
return svn.exists() || git.exists() ? "Shared" : "Local";
}
private Predicate<? super IProject> hasBonitaNature() {
return project -> {
final boolean closed = !project.isOpen();
......@@ -140,10 +177,6 @@ public class ImportWorkspaceApplication implements IApplication {
};
}
/*
* (non-Javadoc)
* @see org.eclipse.equinox.app.IApplication#stop()
*/
@Override
public void stop() {
try {
......
......@@ -81,7 +81,7 @@ public class ScanWorkspaceOperation implements IRunnableWithProgress {
}
});
while (!launch.isTerminated()) {
Thread.sleep(100);
Thread.sleep(1000);
}
if (workspaceModel.isEmpty()) {
workspaceModel.setStatus(ValidationStatus.error(Messages.noRepositoryFoundAtLocation));
......@@ -138,8 +138,12 @@ public class ScanWorkspaceOperation implements IRunnableWithProgress {
final String repoName = scannedRepo[0];
final String repoVersion = scannedRepo[1];
final String repoEdition = scannedRepo[2].trim();
final String connected = scannedRepo[3].trim();
final ImportRepositoryModel repositoryModel = new ImportRepositoryModel(repoName, repoVersion, repoEdition);
final MultiStatus repoStatus = new MultiStatus(BosArchiveImporterPlugin.PLUGIN_ID, 0, "", null);
if ("Shared".equals(connected)) {
repoStatus.add(ValidationStatus.error(String.format(Messages.projectConnectorToVCS, repoName)));
}
if (!ProductVersion.canBeImported(repoVersion)) {
repoStatus.add(ValidationStatus
.error(String.format(Messages.cannotImportWorkspaceWithVersion, repoName, repoVersion)));
......
......@@ -27,6 +27,7 @@ import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.IPreferenceConstants;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.browser.WebBrowserUIPlugin;
......@@ -149,10 +150,13 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer impleme
}
protected void initDefaultDebugPreferences() {
DebugUIPlugin.getDefault().getPreferenceStore().setDefault(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, false);
DebugUIPlugin.getDefault().getPreferenceStore().setDefault(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, false);
DebugPlugin.getDefault().getPluginPreferences().setDefault(IInternalDebugCoreConstants.PREF_ENABLE_STATUS_HANDLERS,
false);
if (PlatformUI.isWorkbenchRunning()) {
DebugUIPlugin.getDefault().getPreferenceStore().setDefault(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, false);
DebugUIPlugin.getDefault().getPreferenceStore().setDefault(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, false);
DebugPlugin.getDefault().getPluginPreferences().setDefault(
IInternalDebugCoreConstants.PREF_ENABLE_STATUS_HANDLERS,
false);
}
}
}
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