Commit 299b8547 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

BS-12182

Add repository stores for page builder
parent 65a055a6
......@@ -34,8 +34,10 @@ import org.bonitasoft.studio.common.extension.BonitaStudioExtensionRegistryManag
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.engine.i18n.Messages;
import org.bonitasoft.studio.pagedesigner.PageDesignerPlugin;
import org.bonitasoft.studio.pagedesigner.core.WorkspaceSystemProperties;
import org.bonitasoft.studio.preferences.BonitaPreferenceConstants;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
import org.eclipse.core.resources.IFile;
......@@ -346,6 +348,7 @@ public class BOSWebServerManager {
Repository.NULL_PROGRESS_MONITOR);
workingCopy = conf.getWorkingCopy();
}
RepositoryManager.getInstance().getCurrentRepository().getAllStores();
workingCopy.setAttribute(
IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
getVMArgs());
......@@ -541,6 +544,11 @@ public class BOSWebServerManager {
System.getProperty(WATCHDOG_TIMER, "20000"));
addSystemProperty(args, "eclipse.product", Platform.getProduct()
.getApplication());
final WorkspaceSystemProperties workspaceSystemProperties = new WorkspaceSystemProperties();
addSystemProperty(args, workspaceSystemProperties.getPageRepositoryLocation());
addSystemProperty(args, workspaceSystemProperties.getWidgetRepositoryLocation());
addSystemProperty(args, workspaceSystemProperties.getFragmentRepositoryLocation());
return args.toString();
}
......@@ -549,6 +557,11 @@ public class BOSWebServerManager {
sBuilder.append("-D" + key + "=" + value);
}
protected void addSystemProperty(final StringBuilder sBuilder, final String systemPropertyArgument) {
sBuilder.append(" ");
sBuilder.append(systemPropertyArgument);
}
protected void startWatchdog() {
if (watchdogServer == null) {
final Thread server = new Thread(new Runnable() {
......
......@@ -4,5 +4,6 @@
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src-test/java"/>
<classpathentry exported="true" kind="lib" path="lib/workspace-api-1.0.0-SNAPSHOT.jar" sourcepath="/workspace-api"/>
<classpathentry kind="output" path="bin"/>
</classpath>
......@@ -9,11 +9,22 @@ Bundle-Vendor: Bonitasoft S.A.
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.bonitasoft.studio.browser;bundle-version="6.5.0",
org.bonitasoft.studio.common.repository;bundle-version="6.5.0",
org.bonitasoft.studio.preferences,
org.bonitasoft.studio.common,
org.eclipse.jdt.launching,
org.restlet;bundle-version="2.2.2",
org.junit;bundle-version="4.11.0";resolution:=optional,
org.mockito;bundle-version="1.9.5";resolution:=optional,
assertj-core;bundle-version="1.5.0";resolution:=optional,
org.bonitasoft.studio.preferences,
org.bonitasoft.studio.common
assertj-core;bundle-version="1.5.0";resolution:=optional
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.pagedesigner
Export-Package: org.bonitasoft.studio.pagedesigner,
org.bonitasoft.studio.pagedesigner.core,
org.bonitasoft.studio.pagedesigner.core.repository,
org.bonitasoft.studio.pagedesigner.core.resources,
org.bonitasoft.workspace.client.api,
org.bonitasoft.workspace.client.impl,
org.bonitasoft.workspace.common
Bundle-ClassPath: lib/workspace-api-1.0.0-SNAPSHOT.jar,
.
......@@ -4,5 +4,7 @@ bin.includes = META-INF/,\
.,\
webapp/,\
plugin.xml,\
plugin.properties
plugin.properties,\
lib/,\
lib/workspace-api-1.0.0-SNAPSHOT.jar
src.excludes = src-test/java/
invalidURLTitle=Invalid URL
invalidURLMsg=An error has occurred while opening a web browser.
\ No newline at end of file
invalidURLMsg=An error has occurred while opening a web browser.
formRepository=Forms
fragmentRepository=Fragments
widgetRepository=Widgets
\ No newline at end of file
......@@ -20,5 +20,17 @@
name="%OpenPageDesigner">
</command>
</extension>
<extension
point="org.bonitasoft.studio.repositoryStore">
<repositoryStore
class="org.bonitasoft.studio.pagedesigner.core.repository.WebFormRepositoryStore">
</repositoryStore>
<repositoryStore
class="org.bonitasoft.studio.pagedesigner.core.repository.WebFragmentRepositoryStore">
</repositoryStore>
<repositoryStore
class="org.bonitasoft.studio.pagedesigner.core.repository.WebWidgetRepositoryStore">
</repositoryStore>
</extension>
</plugin>
......@@ -9,7 +9,7 @@
</parent>
<groupId>org.bonitasoft.studio.bundles.plugins</groupId>
<artifactId>org.bonitasoft.studio.pagedesigner</artifactId>
<packaging>jar</packaging>
<packaging>eclipse-plugin</packaging>
<properties>
<webapp.dir>webapp</webapp.dir>
......
/**
* Copyright (C) 2014 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.pagedesigner.core;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.net.BindException;
import java.net.ServerSocket;
import org.bonitasoft.studio.pagedesigner.core.resources.WorkspaceServerResource;
import org.eclipse.jdt.launching.SocketUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.restlet.Component;
import org.restlet.Server;
import org.restlet.data.Protocol;
import org.restlet.resource.Finder;
import org.restlet.routing.TemplateRoute;
import org.restlet.routing.VirtualHost;
import org.restlet.util.RouteList;
/**
* @author Romain Bioteau
*
*/
public class WorkspaceResourceServerManagerTest {
private WorkspaceResourceServerManager workspaceResourceServerManager;
private int port;
private Server server;
private VirtualHost defaultHost;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
workspaceResourceServerManager = WorkspaceResourceServerManager.getInstance();
port = SocketUtil.findFreePort();
workspaceResourceServerManager.start(port);
final Component component = workspaceResourceServerManager.getComponent();
assertThat(component).isNotNull();
assertThat(component.isStarted()).isTrue();
assertThat(component.getServers()).hasSize(1);
server = component.getServers().get(0);
defaultHost = component.getDefaultHost();
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
workspaceResourceServerManager.stop();
}
@Test
public void should_start_a_restlet_component_on_the_given_port() throws Exception {
assertThat(server.getPort()).isEqualTo(port);
}
@Test
public void should_start_a_restlet_component_with_http_protocol() throws Exception {
assertThat(server.getProtocols().get(0)).isEqualTo(Protocol.HTTP);
}
@Test
public void should_stop_the_restlet_component() throws Exception {
workspaceResourceServerManager.stop();
assertThat(workspaceResourceServerManager.getComponent()).isNull();
}
@Test(expected = BindException.class)
public void should_throw_an_exception_if_port_already_in_use() throws Exception {
workspaceResourceServerManager.stop();
new Thread(new Runnable() {
@Override
public void run() {
try (ServerSocket serverSocket = new ServerSocket(port);) {
serverSocket.accept();
} catch (final IOException e) {
e.printStackTrace();
}
}
}).start();
workspaceResourceServerManager.start(port);
}
@Test
public void should_start_a_restlet_component_with_attached_server_routes() throws Exception {
final RouteList routes = defaultHost.getRoutes();
assertThat(routes).hasSize(2);
final TemplateRoute r1 = (TemplateRoute) routes.get(0);
assertThat(r1.getTemplate().getPattern()).isEqualTo("/workspace/{filePath}/{action}");
assertThat(((Finder) r1.getNext()).getTargetClass()).isEqualTo(WorkspaceServerResource.class);
final TemplateRoute r2 = (TemplateRoute) routes.get(1);
assertThat(r2.getTemplate().getPattern()).isEqualTo("/workspace/{action}");
assertThat(((Finder) r2.getNext()).getTargetClass()).isEqualTo(WorkspaceServerResource.class);
}
}
/**
* Copyright (C) 2014 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.pagedesigner.core;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import java.io.File;
import org.bonitasoft.studio.pagedesigner.core.repository.WebFormRepositoryStore;
import org.bonitasoft.studio.pagedesigner.core.repository.WebFragmentRepositoryStore;
import org.bonitasoft.studio.pagedesigner.core.repository.WebWidgetRepositoryStore;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.Path;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
/**
* @author Romain Bioteau
*
*/
@RunWith(MockitoJUnitRunner.class)
public class WorkspaceSystemPropertiesTest {
private WorkspaceSystemProperties workspaceSystemProperties;
@Mock
private WebFormRepositoryStore webFormRepository;
@Mock
private WebFragmentRepositoryStore webFragmentRepository;
@Mock
private WebWidgetRepositoryStore webWidgetRepository;
@Mock
private IFolder widgetResource;
@Mock
private IFolder formResource;
@Mock
private IFolder fragmentResource;
@Rule
public TemporaryFolder tmpFolder = new TemporaryFolder();
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
workspaceSystemProperties = spy(new WorkspaceSystemProperties());
final File widgetFolder = tmpFolder.newFolder("widgets");
when(widgetResource.getLocation()).thenReturn(Path.fromOSString(widgetFolder.getAbsolutePath()));
final File formsFolder = tmpFolder.newFolder("forms");
when(formResource.getLocation()).thenReturn(Path.fromOSString(formsFolder.getAbsolutePath()));
final File fragmentFolder = tmpFolder.newFolder("fragment");
when(fragmentResource.getLocation()).thenReturn(Path.fromOSString(fragmentFolder.getAbsolutePath()));
when(webWidgetRepository.getResource()).thenReturn(widgetResource);
when(webFragmentRepository.getResource()).thenReturn(fragmentResource);
when(webFormRepository.getResource()).thenReturn(formResource);
doReturn(webFormRepository).when(workspaceSystemProperties).getWebFormRepository();
doReturn(webFragmentRepository).when(workspaceSystemProperties).getWebFragmentRepository();
doReturn(webWidgetRepository).when(workspaceSystemProperties).getWebWidgetRepository();
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
@Test(expected = IllegalStateException.class)
public void should_getPageRepositoryLocation_throw_an_IllegalStateException_if_store_is_not_loaded() throws Exception {
doReturn(null).when(workspaceSystemProperties).getWebFormRepository();
workspaceSystemProperties.getPageRepositoryLocation();
}
@Test(expected = IllegalStateException.class)
public void should_getFragmentRepositoryLocation_throw_an_IllegalStateException_if_store_is_not_loaded() throws Exception {
doReturn(null).when(workspaceSystemProperties).getWebFragmentRepository();
workspaceSystemProperties.getFragmentRepositoryLocation();
}
@Test(expected = IllegalStateException.class)
public void should_getWidgetRepositoryLocation_throw_an_IllegalStateException_if_store_is_not_loaded() throws Exception {
doReturn(null).when(workspaceSystemProperties).getWebWidgetRepository();
workspaceSystemProperties.getWidgetRepositoryLocation();
}
@Test
public void should_getPageRepositoryLocation_return_a_valid_system_properties_for_page_repository() throws Exception {
assertThat(workspaceSystemProperties.getPageRepositoryLocation()).isEqualTo(
"-Drepository.pages=\"" + formResource.getLocation().toFile().getAbsolutePath() + "\"");
}
@Test
public void should_getFragmentRepositoryLocation_return_a_valid_system_properties_for_fragment_repository() throws Exception {
assertThat(workspaceSystemProperties.getFragmentRepositoryLocation()).isEqualTo(
"-Drepository.fragments=\"" + fragmentResource.getLocation().toFile().getAbsolutePath() + "\"");
}
@Test
public void should_getWidgetRepositoryLocation_return_a_valid_system_properties_for_fragment_repository() throws Exception {
assertThat(workspaceSystemProperties.getWidgetRepositoryLocation()).isEqualTo(
"-Drepository.widgets=\"" + widgetResource.getLocation().toFile().getAbsolutePath() + "\"");
}
@Test
public void should_aSystemProperty_return_a_well_formatted_system_property_argument() throws Exception {
assertThat(WorkspaceSystemProperties.aSystemProperty("aProperty.name", "myValue")).isEqualTo("-DaProperty.name=myValue");
final File folder = tmpFolder.newFolder();
assertThat(WorkspaceSystemProperties.aSystemProperty("aProperty.name", folder)).isEqualTo("-DaProperty.name=\"" + folder.getAbsolutePath() + "\"");
}
}
package org.bonitasoft.studio.pagedesigner.core;
import org.bonitasoft.studio.pagedesigner.core.resources.WorkspaceServerResource;
import org.restlet.Component;
import org.restlet.data.Protocol;
public class WorkspaceResourceServerManager {
private Component component;
private static WorkspaceResourceServerManager INSTANCE;
public synchronized static WorkspaceResourceServerManager getInstance() {
if (INSTANCE == null) {
INSTANCE = new WorkspaceResourceServerManager();
}
return INSTANCE;
}
private WorkspaceResourceServerManager() {
}
public synchronized void start(final int port) throws Exception {
if (component == null || !component.isStarted()) {
component = new Component();
component.getServers().add(Protocol.HTTP, port);
component.getDefaultHost().attach(
"/workspace/{filePath}/{action}",
WorkspaceServerResource.class);
component.getDefaultHost().attach("/workspace/{action}", WorkspaceServerResource.class);
component.start();
}
}
public synchronized void stop() throws Exception {
if (component != null && component.isStarted()) {
component.stop();
component = null;
}
}
protected Component getComponent() {
return component;
}
}
/**
* Copyright (C) 2014 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.pagedesigner.core;
import java.io.File;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.pagedesigner.core.repository.WebFormRepositoryStore;
import org.bonitasoft.studio.pagedesigner.core.repository.WebFragmentRepositoryStore;
import org.bonitasoft.studio.pagedesigner.core.repository.WebWidgetRepositoryStore;
/**
* @author Romain Bioteau
*
*/
public class WorkspaceSystemProperties {
private static final String REPOSITORY_PAGES_PROPERTIES = "repository.pages";
private static final String REPOSITORY_FRAGMENTS_PROPERTIES = "repository.fragments";
private static final String REPOSITORY_WIDGETS_PROPERTIES = "repository.widgets";;
public String getPageRepositoryLocation() {
final WebFormRepositoryStore webFormRepository = getWebFormRepository();
if(webFormRepository == null){
throw new IllegalStateException("WebFormRepositoryStore has not be loaded yet.");
}
return aSystemProperty(REPOSITORY_PAGES_PROPERTIES, webFormRepository.getResource().getLocation().toFile());
}
public String getFragmentRepositoryLocation() {
final WebFragmentRepositoryStore webFragmentRepository = getWebFragmentRepository();
if (webFragmentRepository == null) {
throw new IllegalStateException("WebFragmentRepositoryStore has not be loaded yet.");
}
return aSystemProperty(REPOSITORY_FRAGMENTS_PROPERTIES, webFragmentRepository.getResource().getLocation().toFile());
}
public String getWidgetRepositoryLocation() {
final WebWidgetRepositoryStore webWidgetRepository = getWebWidgetRepository();
if (webWidgetRepository == null) {
throw new IllegalStateException("WebWidgetRepositoryStore has not be loaded yet.");
}
return aSystemProperty(REPOSITORY_WIDGETS_PROPERTIES, webWidgetRepository.getResource().getLocation().toFile());
}
protected WebFormRepositoryStore getWebFormRepository() {
return RepositoryManager.getInstance().getRepositoryStore(WebFormRepositoryStore.class);
}
protected WebFragmentRepositoryStore getWebFragmentRepository() {
return RepositoryManager.getInstance().getRepositoryStore(WebFragmentRepositoryStore.class);
}
protected WebWidgetRepositoryStore getWebWidgetRepository() {
return RepositoryManager.getInstance().getRepositoryStore(WebWidgetRepositoryStore.class);
}
static String aSystemProperty(final String propertyName, final Object value) {
String properyValue = value.toString();
if (value instanceof File) {
properyValue = "\"" + ((File) value).getAbsolutePath() + "\"";
}
return "-D" + propertyName + "=" + properyValue;
}
}
/**
* Copyright (C) 2014 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.pagedesigner.core.repository;
import org.bonitasoft.studio.common.repository.filestore.AbstractFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
</