Commit 337df76c authored by Bonita CI's avatar Bonita CI
Browse files

Merge branch 'CoreProduct' into 'feat_test_api'

parents c93766fa a4a53fc3
......@@ -22,6 +22,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import org.bonitasoft.studio.common.extension.ExtensionContextInjectionFactory;
import org.bonitasoft.studio.common.repository.core.BonitaHomeHandler;
import org.bonitasoft.studio.common.repository.core.ProjectClasspathFactory;
import org.bonitasoft.studio.common.repository.core.ProjectManifestFactory;
import org.bonitasoft.studio.common.repository.jdt.JDTTypeHierarchyManager;
......@@ -50,6 +51,8 @@ public class RepositoryTest {
private IProgressMonitor monitor;
@Mock
private ProjectClasspathFactory bonitaBPMProjectClasspath;
@Mock
private BonitaHomeHandler bonitaHomeHandler;
@Test
public void should_open_trigger_project_manifest_factory() throws Exception {
......@@ -80,7 +83,7 @@ public class RepositoryTest {
@Test
public void should_refresh_project_when_deleting_an_open_repository() throws Exception {
final Repository repository = spy(newRepository());
final Repository repository = newRepository();
doReturn(true).when(repository).isBuildEnable();
doReturn(true).when(project).isOpen();
......@@ -90,8 +93,10 @@ public class RepositoryTest {
}
private Repository newRepository() {
return new Repository(workspace, project, extensionContextInjectionFactory, jdtTypeHierarchyManager, projectManifestFactory,
bonitaBPMProjectClasspath, true);
final Repository repo = spy(new Repository(workspace, project, extensionContextInjectionFactory, jdtTypeHierarchyManager, projectManifestFactory,
bonitaBPMProjectClasspath, true));
doReturn(bonitaHomeHandler).when(repo).getBonitaHomeHandler();
return repo;
}
}
......@@ -24,6 +24,7 @@ import org.bonitasoft.studio.common.ProjectUtil;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.CommonRepositoryPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
......@@ -32,19 +33,20 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class BonitaHomeHandler {
private static final String TENANT_ID = "1";
public static final String BONITA_HOME = "bonita_home";
private final IProject project;
public BonitaHomeHandler(IProject project) {
public BonitaHomeHandler(final IProject project) {
this.project = project;
}
public void cleanTenant() {
final File bonitaServerFile = Paths.get(getRoot(), "engine-server", "work", "tenants", "1").toFile();
final File bonitaServerFile = Paths.get(getRoot(), "engine-server", "work", "tenants", TENANT_ID).toFile();
PlatformUtil.delete(bonitaServerFile, null);
final File bonitaClientFile = Paths.get(getRoot(), "engine-client", "work", "tenants", "1").toFile();
final File bonitaClientFile = Paths.get(getRoot(), "engine-client", "work", "tenants", TENANT_ID).toFile();
PlatformUtil.delete(bonitaClientFile, null);
final File bonitaWebClientFile = Paths.get(getRoot(), "client", "tenants", "1").toFile();
final File bonitaWebClientFile = Paths.get(getRoot(), "client", "tenants", TENANT_ID).toFile();
PlatformUtil.delete(bonitaWebClientFile, null);
final File platformTomcatConfig = Paths.get(getRoot(), "client", "platform", "conf", "platform-tenant-config.properties").toFile();
PlatformUtil.delete(platformTomcatConfig, null);
......@@ -85,11 +87,11 @@ public class BonitaHomeHandler {
return Paths.get(getRoot(), "engine-server", "work", "platform").toFile();
}
public String getRoot(){
public String getRoot() {
return project.getFile(BONITA_HOME).getLocation().toFile().getAbsolutePath();
}
public void initBonitaHome(IProgressMonitor monitor) throws CoreException {
public void initBonitaHome(final IProgressMonitor monitor) throws CoreException {
final File bonitaHome = new File(getRoot());
if (!bonitaHome.exists()) {
final URL url = ProjectUtil.getConsoleLibsBundle().getResource("tomcat/bonita");
......@@ -144,4 +146,8 @@ public class BonitaHomeHandler {
+ File.separator + "work"
+ File.separator + "i18n");
}
public IFile getCustomPermissionMappingFile() {
return project.getFile(BONITA_HOME + "/client/tenants/" + TENANT_ID + "/conf/custom-permissions-mapping.properties");
}
}
......@@ -14,8 +14,11 @@
*/
package org.bonitasoft.studio.common.perspectives;
import java.util.Objects;
import org.bonitasoft.studio.common.RestAPIExtensionNature;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
......@@ -23,7 +26,6 @@ import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IPerspectiveFactory;
/**
*
* Must extends this class to enable the automatic switch between perspectives depending of the editor type
*
* @author Baptiste Mesta
......@@ -31,27 +33,29 @@ import org.eclipse.ui.IPerspectiveFactory;
*/
public abstract class AbstractPerspectiveFactory implements IPerspectiveFactory {
/**
* returns true if the perspective must be activated when opening the editor part given in param
*
* @param part
* the editor part that is brought to top
* @return
* true if perspective must be activated, false otherwise
*/
public abstract boolean isRelevantFor(IEditorPart part);
/**
*
* @return the id of the perspective
*/
public abstract String getID();
private static final String CUSTOM_PERMISSIONS_MAPPING_FILE = "custom-permissions-mapping.properties";
/**
* returns true if the perspective must be activated when opening the editor part given in param
*
* @param part
* the editor part that is brought to top
* @return
* true if perspective must be activated, false otherwise
*/
public abstract boolean isRelevantFor(IEditorPart part);
/**
* @return the id of the perspective
*/
public abstract String getID();
protected boolean isInsideprojectWithREStApiExtensionNature(final IEditorPart part) {
final IEditorInput editorInput = part.getEditorInput();
if (editorInput instanceof IFileEditorInput) {
try {
return ((IFileEditorInput) editorInput).getFile().getProject().hasNature(RestAPIExtensionNature.NATURE_ID);
final IFile file = ((IFileEditorInput) editorInput).getFile();
return file.getProject().hasNature(RestAPIExtensionNature.NATURE_ID) || Objects.equals(file.getName(), CUSTOM_PERMISSIONS_MAPPING_FILE);
} catch (final CoreException e) {
BonitaStudioLog.error(e);
}
......
......@@ -40,6 +40,7 @@ public class TomcatVmArgsBuilderTest {
doNothing().when(tomcatVmArgsBuilder).addUIDesignerOptions(any(StringBuilder.class));
doNothing().when(tomcatVmArgsBuilder).addWatchDogProperties(any(StringBuilder.class));
doReturn("test.bonita.product.application.id").when(tomcatVmArgsBuilder).getProductApplicationId();
doReturn("bonita.home.root").when(tomcatVmArgsBuilder).getBonitaHomeRoot();
}
@Test
......
......@@ -47,7 +47,7 @@ public class TomcatVmArgsBuilder {
addSystemProperty(args, "btm.root", "\"" + tomcatInstanceLocation + "\"");
addSystemProperty(args, "wtp.deploy", "\"" + tomcatInstanceLocation + File.separatorChar + "webapps\"");
addSystemProperty(args, "java.endorsed.dirs", "\"" + tomcatInstanceLocation + File.separatorChar + "endorsed\"");
addSystemProperty(args, "bonita.home", "\"" + repositoryAccessor.getCurrentRepository().getBonitaHomeHandler().getRoot() + "\"");
addSystemProperty(args, "bonita.home", "\"" + getBonitaHomeRoot() + "\"");
addSystemProperty(args, "sysprop.bonita.db.vendor", "h2");
addSystemProperty(args, "bitronix.tm.configuration",
"\"" + tomcatInstanceLocation + File.separatorChar + "conf" + File.separatorChar + "bitronix-config.properties\"");
......@@ -69,6 +69,15 @@ public class TomcatVmArgsBuilder {
return res;
}
/**
* /!\ Public for test purpose only
*
* @return
*/
public String getBonitaHomeRoot() {
return repositoryAccessor.getCurrentRepository().getBonitaHomeHandler().getRoot();
}
public String getProductApplicationId() {
return Platform.getProduct() != null ? Platform.getProduct().getApplication() : null;
}
......
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