Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2013-05-02 20:11:14 +0000
committerRoberto E. Escobar2013-05-15 20:13:33 +0000
commit061817c454dc4f6f02394d43369c0ab230440b5b (patch)
tree56a1f0bc120d24b71de8e923f8671a0132f4727b /plugins
parent25c67dffd9b7801af4ce4d129478957a53990004 (diff)
downloadorg.eclipse.osee-061817c454dc4f6f02394d43369c0ab230440b5b.tar.gz
org.eclipse.osee-061817c454dc4f6f02394d43369c0ab230440b5b.tar.xz
org.eclipse.osee-061817c454dc4f6f02394d43369c0ab230440b5b.zip
refactor: Change ModelUtil to OseeDslResourceUtil
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.osee.client.integration.tests/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/dsl/ui/integration/OseeDslRoleContextProviderTest.java11
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/mocks/MockModel.java13
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtilTest.java23
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeModelingServiceImpl.java19
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtil.java79
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeTypeModifier.java28
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/AbstractOseeDslProvider.java9
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/OseeDslResource.java25
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/OseeDslResourceUtil.java105
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/internal/OseeDslResourceImpl.java51
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/AttributeModifier.java3
12 files changed, 246 insertions, 121 deletions
diff --git a/plugins/org.eclipse.osee.client.integration.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.client.integration.tests/META-INF/MANIFEST.MF
index dc8a01ff749..4b7fe09e94f 100644
--- a/plugins/org.eclipse.osee.client.integration.tests/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.client.integration.tests/META-INF/MANIFEST.MF
@@ -13,6 +13,7 @@ Import-Package: org.eclipse.core.runtime,
org.eclipse.osee.framework.core.client,
org.eclipse.osee.framework.core.client.server,
org.eclipse.osee.framework.core.data,
+ org.eclipse.osee.framework.core.dsl,
org.eclipse.osee.framework.core.dsl.integration,
org.eclipse.osee.framework.core.dsl.oseeDsl,
org.eclipse.osee.framework.core.enums,
diff --git a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/dsl/ui/integration/OseeDslRoleContextProviderTest.java b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/dsl/ui/integration/OseeDslRoleContextProviderTest.java
index 41c7345d88e..cb3adbf8771 100644
--- a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/dsl/ui/integration/OseeDslRoleContextProviderTest.java
+++ b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/dsl/ui/integration/OseeDslRoleContextProviderTest.java
@@ -18,13 +18,12 @@ import java.util.List;
import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule;
import org.eclipse.osee.client.test.framework.OseeLogMonitorRule;
import org.eclipse.osee.framework.core.data.IAccessContextId;
-import org.eclipse.osee.framework.core.dsl.integration.util.ModelUtil;
+import org.eclipse.osee.framework.core.dsl.OseeDslResourceUtil;
import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl;
import org.eclipse.osee.framework.core.dsl.ui.integration.operations.OseeDslRoleContextProvider;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.SystemUser;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
@@ -46,10 +45,10 @@ public class OseeDslRoleContextProviderTest {
public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule();
@Test
- public void testGetContextId() throws OseeCoreException {
+ public void testGetContextId() throws Exception {
String contextGuid = GUID.create();
String testSheet = getTestSheet1(contextGuid, SystemUser.Guest.getGuid());
- OseeDsl model = ModelUtil.loadModel("osee:/text.osee", testSheet);
+ OseeDsl model = OseeDslResourceUtil.loadModel("osee:/text.osee", testSheet).getModel();
MockDslProvider dslProvider = new MockDslProvider(model);
OseeDslRoleContextProvider contextProvider = new OseeDslRoleContextProvider(dslProvider);
Artifact guest = ArtifactQuery.getArtifactFromId(SystemUser.Guest.getGuid(), CoreBranches.COMMON);
@@ -60,12 +59,12 @@ public class OseeDslRoleContextProviderTest {
}
@Test
- public void testGetContextIdExtended() throws OseeCoreException {
+ public void testGetContextIdExtended() throws Exception {
String contextGuid1 = GUID.create();
String contextGuid2 = GUID.create();
String role2Guid = GUID.create();
String testSheet = getTestSheet2(contextGuid1, SystemUser.Guest.getGuid(), contextGuid2, role2Guid);
- OseeDsl model = ModelUtil.loadModel("osee:/text.osee", testSheet);
+ OseeDsl model = OseeDslResourceUtil.loadModel("osee:/text.osee", testSheet).getModel();
MockDslProvider dslProvider = new MockDslProvider(model);
OseeDslRoleContextProvider contextProvider = new OseeDslRoleContextProvider(dslProvider);
Artifact guest = ArtifactQuery.getArtifactFromId(SystemUser.Guest.getGuid(), CoreBranches.COMMON);
diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/mocks/MockModel.java b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/mocks/MockModel.java
index 25a5e45a075..28afb6adb7a 100644
--- a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/mocks/MockModel.java
+++ b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/mocks/MockModel.java
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.dsl.integration.mocks;
-import org.eclipse.osee.framework.core.dsl.integration.util.ModelUtil;
+import org.eclipse.osee.framework.core.dsl.OseeDslResourceUtil;
import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessContext;
import org.eclipse.osee.framework.core.dsl.oseeDsl.ArtifactMatchRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.ArtifactTypeRestriction;
@@ -24,6 +24,7 @@ import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactType;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeType;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeExceptions;
import org.eclipse.osee.framework.core.util.HexUtil;
import org.junit.Assert;
@@ -37,8 +38,14 @@ public final class MockModel {
}
public static XArtifactMatcher createMatcher(String rawXTextData) throws OseeCoreException {
- OseeDsl model = ModelUtil.loadModel("osee:/text.osee", rawXTextData);
- return model.getArtifactMatchRefs().iterator().next();
+ XArtifactMatcher toReturn = null;
+ try {
+ OseeDsl model = OseeDslResourceUtil.loadModel("osee:/text.osee", rawXTextData).getModel();
+ toReturn = model.getArtifactMatchRefs().iterator().next();
+ } catch (Exception ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
+ return toReturn;
}
public static OseeDsl createDsl() {
diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtilTest.java b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtilTest.java
index 8b8d41fc3d2..036de68dd60 100644
--- a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtilTest.java
+++ b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtilTest.java
@@ -11,9 +11,9 @@
package org.eclipse.osee.framework.core.dsl.integration.util;
import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.osee.framework.core.dsl.OseeDslResourceUtil;
import org.eclipse.osee.framework.core.dsl.integration.mocks.DslAsserts;
import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessContext;
import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessPermissionEnum;
@@ -31,7 +31,6 @@ import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactType;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeType;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationSideEnum;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.junit.Assert;
import org.junit.Test;
@@ -47,10 +46,10 @@ public class ModelUtilTest {
private static final String ACCESS_TEST_INPUT = "testAccessModel.osee";
@Test
- public void testModelUtilLoadType() throws OseeCoreException, IOException {
+ public void testModelUtilLoadType() throws Exception {
String rawXTextData = Lib.fileToString(getClass(), TYPE_TEST_INPUT);
- OseeDsl model1 = ModelUtil.loadModel("osee:/text.osee", rawXTextData);
+ OseeDsl model1 = OseeDslResourceUtil.loadModel("osee:/text.osee", rawXTextData).getModel();
Assert.assertEquals(5, model1.getArtifactTypes().size());
Iterator<XArtifactType> type1 = model1.getArtifactTypes().iterator();
@@ -82,20 +81,20 @@ public class ModelUtilTest {
"Lexicographical_Ascending", RelationMultiplicityEnum.ONE_TO_MANY);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- ModelUtil.saveModel(model1, "osee:/text.osee", outputStream, false);
+ OseeDslResourceUtil.saveModel(model1, "osee:/text.osee", outputStream, false);
outputStream.flush();
String value = outputStream.toString("UTF-8");
modelEquals(rawXTextData, value);
- OseeDsl model2 = ModelUtil.loadModel("osee:/text2.osee", value);
+ OseeDsl model2 = OseeDslResourceUtil.loadModel("osee:/text2.osee", value).getModel();
DslAsserts.assertEquals(model1, model2);
}
@Test
- public void testModelUtilLoadAccess() throws OseeCoreException, IOException {
+ public void testModelUtilLoadAccess() throws Exception {
String rawXTextData = Lib.fileToString(getClass(), ACCESS_TEST_INPUT);
- OseeDsl model1 = ModelUtil.loadModel("osee:/text.osee", rawXTextData);
+ OseeDsl model1 = OseeDslResourceUtil.loadModel("osee:/text.osee", rawXTextData).getModel();
Assert.assertEquals(2, model1.getArtifactTypes().size());
Iterator<XArtifactType> type1 = model1.getArtifactTypes().iterator();
DslAsserts.assertEquals(type1.next(), "Artifact", "BZOUrxO35x+LBZkEYzAA", new String[0]);
@@ -158,16 +157,16 @@ public class ModelUtilTest {
// @formatter:on
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- ModelUtil.saveModel(model1, "osee:/text.osee", outputStream, false);
+ OseeDslResourceUtil.saveModel(model1, "osee:/text.osee", outputStream, false);
outputStream.flush();
String value = outputStream.toString("UTF-8");
modelEquals(rawXTextData, value);
- OseeDsl model2 = ModelUtil.loadModel("osee:/text2.osee", value);
+ OseeDsl model2 = OseeDslResourceUtil.loadModel("osee:/text2.osee", value).getModel();
DslAsserts.assertEquals(model1, model2);
}
-
- private static void modelEquals(String rawExpected, String actual){
+
+ private static void modelEquals(String rawExpected, String actual) {
String expected = rawExpected.replaceAll("\n", System.getProperty("line.separator"));
Assert.assertEquals(expected, actual);
}
diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeModelingServiceImpl.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeModelingServiceImpl.java
index be362978bc6..e05227ef3a7 100644
--- a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeModelingServiceImpl.java
+++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeModelingServiceImpl.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.dsl.integration.internal;
-import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
@@ -18,6 +17,7 @@ import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.compare.diff.metamodel.ComparisonResourceSnapshot;
import org.eclipse.emf.compare.diff.metamodel.DiffFactory;
+import org.eclipse.osee.framework.core.dsl.OseeDslResourceUtil;
import org.eclipse.osee.framework.core.dsl.integration.CreateOseeTypeChangesReportOperation;
import org.eclipse.osee.framework.core.dsl.integration.EMFCompareOperation;
import org.eclipse.osee.framework.core.dsl.integration.OseeToXtextOperation;
@@ -94,8 +94,9 @@ public class OseeModelingServiceImpl implements IOseeModelingService {
IOperation operation = new OseeToXtextOperation(cache, modelFactory, model);
Operations.executeWorkAndCheckStatus(operation, monitor);
try {
- ModelUtil.saveModel(model, "osee:/oseeTypes_" + Lib.getDateTimeString() + ".osee", outputStream, false);
- } catch (IOException ex) {
+ OseeDslResourceUtil.saveModel(model, "osee:/oseeTypes_" + Lib.getDateTimeString() + ".osee", outputStream,
+ false);
+ } catch (Exception ex) {
OseeExceptions.wrapAndThrow(ex);
}
}
@@ -106,7 +107,12 @@ public class OseeModelingServiceImpl implements IOseeModelingService {
if (!modelName.endsWith(".osee")) {
modelName += ".osee";
}
- OseeDsl inputModel = ModelUtil.loadModel("osee:/" + modelName, request.getModel());
+ OseeDsl inputModel = null;
+ try {
+ inputModel = OseeDslResourceUtil.loadModel("osee:/" + modelName, request.getModel()).getModel();
+ } catch (Exception ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
IOseeCachingService tempCacheService = getService(IOseeCachingServiceFactory.class).createCachingService(false);
OseeTypeCache tempCache =
@@ -120,10 +126,6 @@ public class OseeModelingServiceImpl implements IOseeModelingService {
List<IOperation> ops = new ArrayList<IOperation>();
- if (request.isCreateCompareReport()) {
- ops.add(new OseeToXtextOperation(tempCache, modelFactory, baseModel));
- }
-
ops.add(new XTextToOseeTypeOperation(modelFactoryService, tempCache, tempCacheService.getBranchCache(),
inputModel));
if (request.isCreateTypeChangeReport()) {
@@ -138,7 +140,6 @@ public class OseeModelingServiceImpl implements IOseeModelingService {
if (request.isPersistAllowed()) {
IOseeCachingService caches = getService(IOseeCachingService.class);
- ;
// TODO Make this call transaction based
tempCache.storeAllModified();
diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtil.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtil.java
index ce03a2e9af1..e002c5c98b3 100644
--- a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtil.java
+++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/util/ModelUtil.java
@@ -13,28 +13,18 @@ package org.eclipse.osee.framework.core.dsl.integration.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
-import java.util.HashMap;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
-import org.eclipse.osee.framework.core.dsl.OseeDslStandaloneSetup;
-import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeExceptions;
-import org.eclipse.osee.framework.core.exception.OseeStateException;
-import org.eclipse.xtext.resource.SaveOptions;
-import org.eclipse.xtext.resource.XtextResource;
-import org.eclipse.xtext.resource.XtextResourceSet;
-import com.google.inject.Injector;
/**
* @author Roberto E. Escobar
@@ -45,66 +35,6 @@ public final class ModelUtil {
// Utility Class
}
- public static OseeDsl loadModel(InputStream inputStream, boolean isZipped) throws OseeCoreException {
- Injector injector = new OseeDslStandaloneSetup().createInjectorAndDoEMFRegistration();
- XtextResource resource = injector.getInstance(XtextResource.class);
-
- Map<String, Boolean> options = new HashMap<String, Boolean>();
- options.put(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
- if (isZipped) {
- options.put(Resource.OPTION_ZIP, Boolean.TRUE);
- }
- try {
- resource.setURI(URI.createURI("http://www.eclipse.org/osee/framework/OseeTypes"));
- resource.load(inputStream, options);
- } catch (IOException ex) {
- OseeExceptions.wrapAndThrow(ex);
- }
- OseeDsl model = (OseeDsl) resource.getContents().get(0);
- for (Diagnostic diagnostic : resource.getErrors()) {
- throw new OseeStateException(diagnostic.toString());
- }
- return model;
- }
-
- public static OseeDsl loadModel(String uri, String xTextData) throws OseeCoreException {
- try {
- OseeDslStandaloneSetup setup = new OseeDslStandaloneSetup();
- Injector injector = setup.createInjectorAndDoEMFRegistration();
- XtextResourceSet set = injector.getInstance(XtextResourceSet.class);
-
- // set.setClasspathURIContext(ModelUtil.class);
- set.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
-
- Resource resource = set.createResource(URI.createURI(uri));
- resource.load(new ByteArrayInputStream(xTextData.getBytes("UTF-8")), set.getLoadOptions());
- OseeDsl model = (OseeDsl) resource.getContents().get(0);
- for (Diagnostic diagnostic : resource.getErrors()) {
- throw new OseeStateException(diagnostic.toString());
- }
- return model;
- } catch (IOException ex) {
- OseeExceptions.wrapAndThrow(ex);
- return null; // unreachable since wrapAndThrow() always throws an exception
- }
- }
-
- public static void saveModel(OseeDsl model, String uri, OutputStream outputStream, boolean isZipped) throws IOException {
- OseeDslStandaloneSetup.doSetup();
-
- ResourceSet resourceSet = new ResourceSetImpl();
- Resource resource = resourceSet.createResource(URI.createURI(uri));
- resource.getContents().add(model);
-
- Map<String, Boolean> options = new HashMap<String, Boolean>();
- // options.put(XtextResource.OPTION_FORMAT, Boolean.TRUE);
- if (isZipped) {
- options.put(Resource.OPTION_ZIP, Boolean.TRUE);
- }
- SaveOptions saveOptions = SaveOptions.getOptions(options);
- resource.save(outputStream, saveOptions.toOptionsMap());
- }
-
private static void storeModel(Resource resource, OutputStream outputStream, EObject object, String uri, Map<String, Boolean> options) throws OseeCoreException {
try {
resource.setURI(URI.createURI(uri));
@@ -119,15 +49,6 @@ public final class ModelUtil {
return modelToString(new XMLResourceImpl(), object, uri, options);
}
- public static String modelToStringXText(EObject object, String uri, Map<String, Boolean> options) throws OseeCoreException {
- OseeDslStandaloneSetup setup = new OseeDslStandaloneSetup();
- Injector injector = setup.createInjectorAndDoEMFRegistration();
- Resource resource = injector.getInstance(XtextResource.class);
- Map<String, Boolean> options2 = new HashMap<String, Boolean>();
- options2.put(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
- return modelToString(resource, object, uri, options2);
- }
-
private static String modelToString(Resource resource, EObject object, String uri, Map<String, Boolean> options) throws OseeCoreException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
storeModel(resource, outputStream, object, uri, options);
diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeTypeModifier.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeTypeModifier.java
index a16c4e9e5e4..d3bbb1783c6 100644
--- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeTypeModifier.java
+++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/OseeTypeModifier.java
@@ -17,12 +17,13 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.osee.framework.core.dsl.integration.util.ModelUtil;
+import org.eclipse.osee.framework.core.dsl.OseeDslResourceUtil;
import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl;
import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeType;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeExceptions;
import org.eclipse.osee.framework.core.util.Conditions;
import org.eclipse.osee.framework.core.util.HexUtil;
import org.eclipse.osee.framework.jdk.core.util.Lib;
@@ -34,8 +35,13 @@ import org.eclipse.osee.framework.ui.skynet.render.AttributeModifier;
public class OseeTypeModifier implements AttributeModifier {
@Override
- public InputStream modifyForSave(Artifact owner, File file) throws OseeCoreException, IOException {
- String value = Lib.fileToString(file);
+ public InputStream modifyForSave(Artifact owner, File file) throws OseeCoreException {
+ String value = null;
+ try {
+ value = Lib.fileToString(file);
+ } catch (IOException ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
List<Artifact> artifacts =
ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.OseeTypeDefinition, BranchManager.getCommonBranch());
@@ -49,7 +55,12 @@ public class OseeTypeModifier implements AttributeModifier {
}
combinedSheets.append(sheetData.replaceAll("import\\s+\"", "// import \""));
}
- OseeDsl oseeDsl = ModelUtil.loadModel("osee:/TypeModel.osee", combinedSheets.toString());
+ OseeDsl oseeDsl = null;
+ try {
+ oseeDsl = OseeDslResourceUtil.loadModel("osee:/TypeModel.osee", combinedSheets.toString()).getModel();
+ } catch (Exception ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
Set<Long> uuids = new HashSet<Long>();
for (EObject object : oseeDsl.eContents()) {
@@ -58,7 +69,14 @@ public class OseeTypeModifier implements AttributeModifier {
}
}
Conditions.checkExpressionFailOnTrue(uuids.contains(0L), "Uuid of 0L is not allowed");
- return Lib.stringToInputStream(value);
+
+ InputStream inputStream = null;
+ try {
+ inputStream = Lib.stringToInputStream(value);
+ } catch (Exception ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
+ return inputStream;
}
private void addUuid(Set<Long> set, OseeType type) throws OseeCoreException {
diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/AbstractOseeDslProvider.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/AbstractOseeDslProvider.java
index 915d15a0325..8edc8cb3870 100644
--- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/AbstractOseeDslProvider.java
+++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/AbstractOseeDslProvider.java
@@ -11,9 +11,8 @@
package org.eclipse.osee.framework.core.dsl.ui.integration.operations;
import java.io.ByteArrayOutputStream;
-import java.io.IOException;
+import org.eclipse.osee.framework.core.dsl.OseeDslResourceUtil;
import org.eclipse.osee.framework.core.dsl.integration.OseeDslProvider;
-import org.eclipse.osee.framework.core.dsl.integration.util.ModelUtil;
import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeExceptions;
@@ -44,7 +43,7 @@ public abstract class AbstractOseeDslProvider implements OseeDslProvider {
Operations.executeWorkAndCheckStatus(operation);
try {
outputStream.write(accessModel.getBytes("utf-8"));
- oseeDsl = ModelUtil.loadModel(locationUri, outputStream.toString("utf-8"));
+ oseeDsl = OseeDslResourceUtil.loadModel(locationUri, outputStream.toString("utf-8")).getModel();
} catch (Exception ex) {
OseeExceptions.wrapAndThrow(ex);
}
@@ -62,10 +61,10 @@ public abstract class AbstractOseeDslProvider implements OseeDslProvider {
public void storeDsl(OseeDsl dsl) throws OseeCoreException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
- ModelUtil.saveModel(dsl, locationUri, outputStream, false);
+ OseeDslResourceUtil.saveModel(dsl, locationUri, outputStream, false);
saveModelToStorage(outputStream.toString("UTF-8"));
loadDsl();
- } catch (IOException ex) {
+ } catch (Exception ex) {
OseeExceptions.wrapAndThrow(ex);
}
}
diff --git a/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/OseeDslResource.java b/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/OseeDslResource.java
new file mode 100644
index 00000000000..6c32001052a
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/OseeDslResource.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.dsl;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface OseeDslResource {
+
+ Collection<String> getErrors();
+
+ OseeDsl getModel();
+
+}
diff --git a/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/OseeDslResourceUtil.java b/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/OseeDslResourceUtil.java
new file mode 100644
index 00000000000..831091b0740
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/OseeDslResourceUtil.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.dsl;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.osee.framework.core.dsl.internal.OseeDslResourceImpl;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl;
+import org.eclipse.xtext.resource.SaveOptions;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.resource.XtextResourceSet;
+import com.google.inject.Injector;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class OseeDslResourceUtil {
+
+ private OseeDslResourceUtil() {
+ // Utility Class
+ }
+
+ public static OseeDslResource loadModelUnchecked(String uri, InputStream xTextData) throws Exception {
+ OseeDslStandaloneSetup setup = new OseeDslStandaloneSetup();
+ Injector injector = setup.createInjectorAndDoEMFRegistration();
+ XtextResourceSet set = injector.getInstance(XtextResourceSet.class);
+
+ set.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
+ Resource resource = set.createResource(URI.createURI(uri));
+ Map<Object, Object> loadOptions = set.getLoadOptions();
+ resource.load(xTextData, loadOptions);
+
+ OseeDslResource displayLogicResource = new OseeDslResourceImpl(resource);
+ return displayLogicResource;
+ }
+
+ public static OseeDslResource loadModelUnchecked(String uri, String xTextData) throws Exception {
+ return loadModelUnchecked(uri, new ByteArrayInputStream(xTextData.getBytes("UTF-8")));
+ }
+
+ public static OseeDslResource loadModel(String uri, String xTextData) throws Exception {
+ OseeDslResource displayLogicResource = loadModelUnchecked(uri, xTextData);
+ checkErrorsEmpty(displayLogicResource.getErrors());
+ return displayLogicResource;
+ }
+
+ public static OseeDslResource loadModel(String uri, InputStream xTextData) throws Exception {
+ OseeDslResource displayLogicResource = loadModelUnchecked(uri, xTextData);
+ checkErrorsEmpty(displayLogicResource.getErrors());
+ return displayLogicResource;
+ }
+
+ public static void saveModel(OseeDslResource dslResource, OutputStream outputStream, boolean compressOnSave) throws Exception {
+ if (dslResource instanceof OseeDslResourceImpl) {
+ OseeDslResourceImpl resourceImpl = (OseeDslResourceImpl) dslResource;
+ Resource resource = resourceImpl.getResource();
+ saveResource(resource, outputStream, compressOnSave);
+ } else {
+ throw new IllegalArgumentException(String.format("Unsupported dslResource class [%s]",
+ dslResource != null ? dslResource.getClass() : "null"));
+ }
+ }
+
+ public static void saveModel(OseeDsl model, String uri, OutputStream outputStream, boolean compressOnSave) throws Exception {
+ OseeDslStandaloneSetup.doSetup();
+
+ ResourceSet resourceSet = new ResourceSetImpl();
+ Resource resource = resourceSet.createResource(URI.createURI(uri));
+ resource.getContents().add(model);
+
+ saveResource(resource, outputStream, compressOnSave);
+ }
+
+ private static void saveResource(Resource resource, OutputStream outputStream, boolean compressOnSave) throws Exception {
+ Map<String, Boolean> options = new HashMap<String, Boolean>();
+ if (compressOnSave) {
+ options.put(Resource.OPTION_ZIP, Boolean.TRUE);
+ }
+ SaveOptions saveOptions = SaveOptions.getOptions(options);
+ resource.save(outputStream, saveOptions.toOptionsMap());
+ }
+
+ private static void checkErrorsEmpty(Collection<String> errors) throws Exception {
+ if (errors != null && !errors.isEmpty()) {
+ throw new IllegalStateException(errors.iterator().next());
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/internal/OseeDslResourceImpl.java b/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/internal/OseeDslResourceImpl.java
new file mode 100644
index 00000000000..b72c6cf9a83
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/internal/OseeDslResourceImpl.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.dsl.internal;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.osee.framework.core.dsl.OseeDslResource;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class OseeDslResourceImpl implements OseeDslResource {
+
+ private final Resource resource;
+
+ public OseeDslResourceImpl(Resource resource) {
+ this.resource = resource;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ @Override
+ public Collection<String> getErrors() {
+ List<String> errors = new LinkedList<String>();
+ for (org.eclipse.emf.ecore.resource.Resource.Diagnostic diagnostic : resource.getErrors()) {
+ errors.add(diagnostic.toString());
+ }
+ return errors;
+ }
+
+ @Override
+ public OseeDsl getModel() {
+ EList<EObject> contents = resource.getContents();
+ return !contents.isEmpty() ? (OseeDsl) contents.get(0) : null;
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/AttributeModifier.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/AttributeModifier.java
index 2dd2c470ee7..bf88e5fdf6b 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/AttributeModifier.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/AttributeModifier.java
@@ -11,12 +11,11 @@
package org.eclipse.osee.framework.ui.skynet.render;
import java.io.File;
-import java.io.IOException;
import java.io.InputStream;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
public interface AttributeModifier {
- InputStream modifyForSave(Artifact owner, File file) throws OseeCoreException, IOException;
+ InputStream modifyForSave(Artifact owner, File file) throws OseeCoreException;
}

Back to the top