-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model Documentation Generation #6
base: snapshot
Are you sure you want to change the base?
Changes from 12 commits
4431e31
6a12b3c
9a88225
f974d40
7a9b7be
77e2992
414f4a5
e4c85b9
a368b7a
d5c37db
b058b7f
88e9915
8a33ef4
ae3bfe3
533f685
7474cde
075ce36
982c04e
c3baeac
ebc7a18
7d804ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,5 +54,6 @@ header: | |
- 'gradlew' | ||
- 'gradlew.bat' | ||
- 'settings.gradle' | ||
- '**/*Test.java' | ||
|
||
comment: always |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
bnd_version=6.3.0-RC1 | ||
bnd_version=6.3.1 | ||
bnd_snapshots=https://bndtools.jfrog.io/ui/native/libs-release/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/** | ||
/* | ||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||
* All rights reserved. | ||
* | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/** | ||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||
* All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Data In Motion - initial API and implementation | ||
*/ | ||
package org.gecko.emf.json.tests; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.emf.common.util.URI; | ||
import org.eclipse.emf.ecore.EcorePackage; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | ||
import org.gecko.emf.json.configuration.ConfigurableJsonResource; | ||
import org.gecko.emf.json.configuration.ConfigurableJsonResourceFactory; | ||
import org.gecko.emf.json.constants.EMFJs; | ||
import org.gecko.emf.osgi.example.model.basic.BasicFactory; | ||
import org.gecko.emf.osgi.example.model.basic.BasicPackage; | ||
import org.gecko.emf.osgi.example.model.basic.Person; | ||
import org.gecko.emf.osgi.example.model.basic.impl.BasicPackageImpl; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* | ||
* @author mark | ||
* @since 15.07.2022 | ||
*/ | ||
public class RootElementTest { | ||
|
||
private ResourceSetImpl resourceSet; | ||
private BasicPackage packageImpl; | ||
private BasicFactory factoryImpl; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
resourceSet = new ResourceSetImpl(); | ||
resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE); | ||
packageImpl = BasicPackageImpl.init(); | ||
factoryImpl = BasicFactory.eINSTANCE; | ||
resourceSet.getPackageRegistry().put(BasicPackage.eNS_URI, packageImpl); | ||
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("json", new ConfigurableJsonResourceFactory()); | ||
} | ||
|
||
@Test | ||
public void testSaveJson() { | ||
Resource resource = resourceSet.createResource(URI.createURI("test.json")); | ||
assertNotNull(resource); | ||
assertTrue(resource instanceof ConfigurableJsonResource); | ||
|
||
Person p = factoryImpl.createPerson(); | ||
p.setFirstName("Emil"); | ||
p.setLastName("Tester"); | ||
resource.getContents().add(p); | ||
|
||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
try { | ||
resource.save(baos, null); | ||
} catch (IOException e) { | ||
fail("Error saving Person"); | ||
} | ||
String result = new String(baos.toByteArray()); | ||
System.out.println(result); | ||
} | ||
|
||
@Test | ||
public void testLoadJsonError() { | ||
String json = "{\n" | ||
+ " \"firstName\" : \"Emil\",\n" | ||
+ " \"lastName\" : \"Tester\"\n" | ||
+ "}"; | ||
Resource loadResource = resourceSet.createResource(URI.createURI("test-load-error.json")); | ||
assertNotNull(loadResource); | ||
assertTrue(loadResource instanceof ConfigurableJsonResource); | ||
|
||
ByteArrayInputStream bais = new ByteArrayInputStream(json.getBytes()); | ||
try { | ||
loadResource.load(bais, null); | ||
assertEquals(0, loadResource.getContents().size()); | ||
} catch (IOException e) { | ||
fail("Error loading Person"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testLoadJson() { | ||
String json = "{\n" | ||
+ " \"firstName\" : \"Emil\",\n" | ||
+ " \"lastName\" : \"Tester\"\n" | ||
+ "}"; | ||
Resource loadResource = resourceSet.createResource(URI.createURI("test-load.json")); | ||
assertNotNull(loadResource); | ||
assertTrue(loadResource instanceof ConfigurableJsonResource); | ||
|
||
ByteArrayInputStream bais = new ByteArrayInputStream(json.getBytes()); | ||
try { | ||
Map<String, Object> loadOptions = new HashMap<String, Object>(); | ||
loadOptions.put(EMFJs.OPTION_ROOT_ELEMENT, packageImpl.getPerson()); | ||
loadResource.load(bais, loadOptions); | ||
assertEquals(1, loadResource.getContents().size()); | ||
Person p = (Person) loadResource.getContents().get(0); | ||
assertEquals("Emil", p.getFirstName()); | ||
assertEquals("Tester", p.getLastName()); | ||
} catch (IOException e) { | ||
fail("Error loading Person"); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
@@ -11,6 +11,7 @@ | |||||||||||||||||
*/ | ||||||||||||||||||
package org.gecko.emf.json.configuration; | ||||||||||||||||||
|
||||||||||||||||||
import static org.eclipse.emfcloud.jackson.databind.EMFContext.Attributes.ROOT_ELEMENT; | ||||||||||||||||||
import static org.eclipse.emfcloud.jackson.databind.EMFContext.Attributes.RESOURCE; | ||||||||||||||||||
import static org.eclipse.emfcloud.jackson.databind.EMFContext.Attributes.RESOURCE_SET; | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -107,11 +108,6 @@ public ObjectMapper configureMapper(Map<?, ?> options) { | |||||||||||||||||
|
||||||||||||||||||
private EMFModule createInitModule(Map<?, ?> options, boolean isNew) { | ||||||||||||||||||
EMFModule module = new EMFModule(); | ||||||||||||||||||
Boolean serContainment = getOrDefault(options, EMFJs.OPTION_SERIALIZE_CONTAINMENT_AS_HREF, | ||||||||||||||||||
isNew ? false : null); | ||||||||||||||||||
if (serContainment != null) { | ||||||||||||||||||
module.configure(Feature.OPTION_SERIALIZE_CONTAINMENT_AS_HREF, serContainment); | ||||||||||||||||||
} | ||||||||||||||||||
Boolean serDefaults = getOrDefault(options, EMFJs.OPTION_SERIALIZE_DEFAULT_VALUE, isNew ? false : null); | ||||||||||||||||||
if (serDefaults != null) { | ||||||||||||||||||
module.configure(Feature.OPTION_SERIALIZE_DEFAULT_VALUE, serDefaults); | ||||||||||||||||||
|
@@ -216,6 +212,10 @@ protected void doLoad(InputStream inputStream, Map<?, ?> options) throws IOExcep | |||||||||||||||||
|
||||||||||||||||||
ContextAttributes attributes = EMFContext.from(options).withPerCallAttribute(RESOURCE_SET, getResourceSet()) | ||||||||||||||||||
.withPerCallAttribute(RESOURCE, this); | ||||||||||||||||||
EClass eclass = getOrDefault(options, EMFJs.OPTION_ROOT_ELEMENT, null); | ||||||||||||||||||
if (eclass != null) { | ||||||||||||||||||
attributes = attributes.withPerCallAttribute(ROOT_ELEMENT, eclass); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
configureMapper(options).reader().with(attributes).forType(Resource.class).withValueToUpdate(this) | ||||||||||||||||||
.readValue(inputStream); | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
@@ -51,10 +51,6 @@ public final class EMFJs { | |||||||||||||||||
*/ | ||||||||||||||||||
public static final String OPTION_INDENT_OUTPUT = "OPTION_INDENT_OUTPUT"; | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* Option used to indicate the module to serialize containments as references. | ||||||||||||||||||
*/ | ||||||||||||||||||
public static final String OPTION_SERIALIZE_CONTAINMENT_AS_HREF = "OPTION_SERIALIZE_CONTAINMENT_AS_HREF"; | ||||||||||||||||||
/** | ||||||||||||||||||
* When value is true, the writer will include an _id key to each json objects | ||||||||||||||||||
* and sets as value the fragment identifier. | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
@@ -70,7 +70,6 @@ public void convertAnnotation(Annotation annotation, boolean serialize, Map<Obje | |||||||||||||||||
|
||||||||||||||||||
options.put(EMFJs.OPTION_DATE_FORMAT, config.dateFormat()); | ||||||||||||||||||
options.put(EMFJs.OPTION_INDENT_OUTPUT, config.indentOutput()); | ||||||||||||||||||
options.put(EMFJs.OPTION_SERIALIZE_CONTAINMENT_AS_HREF, config.serializeContainmentAsHref()); | ||||||||||||||||||
options.put(EMFJs.OPTION_SERIALIZE_DEFAULT_VALUE, config.serializeDefaultValues()); | ||||||||||||||||||
options.put(EMFJs.OPTION_SERIALIZE_TYPE, config.serializeTypes()); | ||||||||||||||||||
options.put(EMFJs.OPTION_USE_ID, config.useId()); | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||
/** | ||||||||||||||||||
/* | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
* Copyright (c) 2012 - 2022 Data In Motion and others. | ||||||||||||||||||
* All rights reserved. | ||||||||||||||||||
* | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.