Commit 4cf6894c authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub
Browse files

fix(repository) generate the bdm jar when opening a project (#1854)

* Called after a clone for example
* Guarantee a better sync (avoid false positive validation error)
parent 0c492029
......@@ -40,22 +40,24 @@ public class HideEmptyRepository extends ViewerFilter {
if (store != null) {
try {
IFolder resource = store.getResource();
IResource[] members = resource.members();
if (store instanceof WebWidgetRepositoryStore) {
return Stream.of(members)
.filter(r -> !r.getName().startsWith("."))
.anyMatch(r -> !r.getName().startsWith("pb"));
if (resource.exists()) {
IResource[] members = resource.members();
if (store instanceof WebWidgetRepositoryStore) {
return Stream.of(members)
.filter(r -> !r.getName().startsWith("."))
.anyMatch(r -> !r.getName().startsWith("pb"));
}
if (store instanceof WebPageRepositoryStore) {
return Stream.of(members)
.anyMatch(r -> !r.getName().startsWith("."));
}
if (store instanceof WebFragmentRepositoryStore) {
return Stream.of(members)
.anyMatch(r -> !r.getName().startsWith("."));
}
return members.length > 0;
}
if (store instanceof WebPageRepositoryStore) {
return Stream.of(members)
.anyMatch(r -> !r.getName().startsWith("."));
}
if (store instanceof WebFragmentRepositoryStore) {
return Stream.of(members)
.anyMatch(r -> !r.getName().startsWith("."));
}
return members.length > 0;
} catch (CoreException e) {
BonitaStudioLog.error(e);
}
......
......@@ -26,6 +26,7 @@ import java.io.InputStream;
import java.util.Optional;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IJavaProject;
import org.junit.Before;
import org.junit.Test;
......@@ -85,7 +86,7 @@ public class BusinessObjectModelRepositoryStoreTest {
doReturn(businessObjectFileStore).when(storeUnderTest).superDoImportInputStream("test", inputStream);
doReturn(true).when(storeUnderTest).isDeployable();
doNothing().when(storeUnderTest).deploy(businessObjectFileStore);
doNothing().when(storeUnderTest).generateJar(businessObjectFileStore);
doReturn(Status.OK_STATUS).when(storeUnderTest).generateJar(businessObjectFileStore);
storeUnderTest.doImportInputStream("test", inputStream);
......@@ -98,7 +99,7 @@ public class BusinessObjectModelRepositoryStoreTest {
doReturn(businessObjectFileStore).when(storeUnderTest).superDoImportInputStream("test", inputStream);
doReturn(false).when(storeUnderTest).isDeployable();
doNothing().when(storeUnderTest).deploy(businessObjectFileStore);
doNothing().when(storeUnderTest).generateJar(businessObjectFileStore);
doReturn(Status.OK_STATUS).when(storeUnderTest).generateJar(businessObjectFileStore);
storeUnderTest.doImportInputStream("test", inputStream);
......
......@@ -41,7 +41,9 @@ import org.bonitasoft.studio.businessobject.core.operation.GenerateBDMOperation;
import org.bonitasoft.studio.businessobject.i18n.Messages;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.IBonitaProjectListener;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.model.IRepository;
import org.bonitasoft.studio.common.repository.store.AbstractRepositoryStore;
import org.bonitasoft.studio.pics.Pics;
import org.eclipse.core.runtime.CoreException;
......@@ -71,7 +73,7 @@ import com.google.common.io.Files;
* @author Romain Bioteau
*/
public class BusinessObjectModelRepositoryStore<F extends AbstractBDMFileStore>
extends AbstractRepositoryStore<AbstractBDMFileStore> {
extends AbstractRepositoryStore<AbstractBDMFileStore> implements IBonitaProjectListener {
private static final String STORE_NAME = "bdm";
......@@ -91,6 +93,12 @@ public class BusinessObjectModelRepositoryStore<F extends AbstractBDMFileStore>
return converter;
}
@Override
public void createRepositoryStore(IRepository repository) {
super.createRepositoryStore(repository);
repository.addProjectListener(this);
}
@Override
public AbstractBDMFileStore createRepositoryFileStore(final String fileName) {
return new BusinessObjectModelFileStore(fileName, this);
......@@ -145,7 +153,6 @@ public class BusinessObjectModelRepositoryStore<F extends AbstractBDMFileStore>
} else {
fileStore = superDoImportInputStream(fileName, inputStream);
}
generateJar(fileStore);
if (isDeployable()) {
deploy((BusinessObjectModelFileStore) fileStore);
......@@ -153,11 +160,13 @@ public class BusinessObjectModelRepositoryStore<F extends AbstractBDMFileStore>
return fileStore;
}
protected void generateJar(F fileStore) {
protected IStatus generateJar(F fileStore) {
try {
new GenerateBDMOperation((BusinessObjectModelFileStore) fileStore).run(Repository.NULL_PROGRESS_MONITOR);
return Status.OK_STATUS;
} catch (InvocationTargetException | InterruptedException e) {
BonitaStudioLog.error(e);
return new Status(IStatus.ERROR, BusinessObjectPlugin.PLUGIN_ID, "Failed to generate jar from BDM.", e);
}
}
......@@ -295,4 +304,26 @@ public class BusinessObjectModelRepositoryStore<F extends AbstractBDMFileStore>
return (F) super.getChild(fileName, force);
}
@Override
public void projectOpened(Repository repository, IProgressMonitor monitor) {
Job job = new Job(Messages.generatingJarFromBDMModel) {
@Override
protected IStatus run(IProgressMonitor monitor) {
F fStore = getChild(BusinessObjectModelFileStore.BOM_FILENAME, true);
if (fStore != null) {
return generateJar(fStore);
}
return Status.OK_STATUS;
}
};
job.schedule();
}
@Override
public void projectClosed(Repository repository, IProgressMonitor monitor) {
//Nothing to do
}
}
......@@ -19,6 +19,7 @@ import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import org.bonitasoft.studio.common.repository.IBonitaProjectListener;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.core.DatabaseHandler;
import org.eclipse.core.resources.IProject;
......@@ -86,4 +87,5 @@ public interface IRepository extends IFileStoreChangeListener {
DatabaseHandler getDatabaseHandler();
void addProjectListener(IBonitaProjectListener listener);
}
......@@ -159,7 +159,8 @@ public class DefinitionResourceProvider {
if (resourceBundle != null) {
return resourceBundle;
}
final IRepositoryFileStore fileStore = store.getChild(URI.decode(definition.eResource().getURI().lastSegment()), true);
final IRepositoryFileStore fileStore = store.getChild(URI.decode(definition.eResource().getURI().lastSegment()),
true);
if (fileStore == null) {
return null;
}
......@@ -427,15 +428,18 @@ public class DefinitionResourceProvider {
}
final String defId = URI.decode(def.eResource().getURI().trimFileExtension().lastSegment());
try {
for (final IResource r : store.getResource().members()) {
if (r.getFileExtension() != null
&& r.getFileExtension().equals("properties")) {
final String resourceName = r.getName();
if (resourceName.contains(defId)) {
final String baseName = resourceName.substring(0,
defId.length());
if (baseName.equals(defId)) {
result.add(((IFile) r).getLocation().toFile());
IFolder resource = store.getResource();
if (resource.exists()) {
for (final IResource r : resource.members()) {
if (r.getFileExtension() != null
&& r.getFileExtension().equals("properties")) {
final String resourceName = r.getName();
if (resourceName.contains(defId)) {
final String baseName = resourceName.substring(0,
defId.length());
if (baseName.equals(defId)) {
result.add(((IFile) r).getLocation().toFile());
}
}
}
}
......
......@@ -92,6 +92,9 @@ public class RecentProcessContentProvider implements IIntroXHTMLContentProvider
* java.lang.String, org.w3c.dom.Element)
*/
public void createContent(String id, Element parent) {
if(!RepositoryManager.getInstance().hasActiveRepository() || !RepositoryManager.getInstance().getCurrentRepository().isLoaded()) {
return;
}
DiagramRepositoryStore diagramSotre = (DiagramRepositoryStore) RepositoryManager
.getInstance().getRepositoryStore(DiagramRepositoryStore.class);
int nbProc = Integer.parseInt(id.split(",")[0]);
......
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