Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into qnames
Browse files Browse the repository at this point in the history
# Conflicts:
#	app.hypermedia.testing.dsl/src/main/java/app/hypermedia/testing/dsl/Hydra.xtext
#	app.hypermedia.testing.dsl/src/main/java/app/hypermedia/testing/dsl/generator/HydraGenerator.xtend
#	app.hypermedia.testing.dsl/src/main/java/app/hypermedia/testing/dsl/validation/HydraValidator.xtend
#	app.hypermedia.testing.dsl/src/test/java/app/hypermedia/testing/dsl/tests/TestHelpers.xtend
#	app.hypermedia.testing.dsl/src/test/java/app/hypermedia/testing/dsl/tests/generator/core/ClassTest.xtend
#	app.hypermedia.testing.dsl/src/test/java/app/hypermedia/testing/dsl/tests/generator/core/HeaderTest.xtend
#	app.hypermedia.testing.dsl/src/test/java/app/hypermedia/testing/dsl/tests/generator/core/LinkTest.xtend
#	app.hypermedia.testing.dsl/src/test/java/app/hypermedia/testing/dsl/tests/generator/core/PropertyTest.xtend
#	app.hypermedia.testing.dsl/src/test/java/app/hypermedia/testing/dsl/tests/generator/hydra/FollowTest.xtend
#	app.hypermedia.testing.dsl/src/test/java/app/hypermedia/testing/dsl/tests/generator/hydra/OperationTest.xtend
#	app.hypermedia.testing.dsl/src/test/java/app/hypermedia/testing/dsl/tests/hydra/OperationParsingTest.xtend
  • Loading branch information
tpluscode committed Jul 26, 2019
2 parents a2f1181 + ee4f040 commit d5e772c
Show file tree
Hide file tree
Showing 36 changed files with 922 additions and 202 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ insert_final_newline = true
indent_style = space
indent_size = 4

[*.{yaml,yml,json}]
[*.{yaml,yml,json,js}]
indent_size = 2
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
language: java
before_install:
- mvn editorconfig:check
9 changes: 9 additions & 0 deletions api-examples/hydra/operation/no-invocations.hydra
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
With Class <http://example.com/vocab#Task> {
Expect Operation <http://example.com/vocab#CancelTask>
}

With Operation <http://example.com/vocab#CancelTask> {
Invoke {
// ...
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ protected void generateOne(File input) {
private boolean validate(Resource resource) {
List<Issue> issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
if (!issues.isEmpty()) {
issues.forEach(issue -> System.out.printf("Line %3s: %s %n", issue.getLineNumber(), issue.getMessage()));
issues.forEach(issue -> System.out.printf(
"Line %3s: %s %s %n",
issue.getLineNumber(),
issue.getSeverity(),
issue.getMessage()));
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import org.eclipse.xtext.util.Modules2
*/
class HydraIdeSetup extends HydraStandaloneSetup {

override createInjector() {
Guice.createInjector(Modules2.mixin(new HydraRuntimeModule, new HydraIdeModule))
}
override createInjector() {
Guice.createInjector(Modules2.mixin(new HydraRuntimeModule, new HydraIdeModule))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import org.eclipse.xtext.web.servlet.XtextServlet
*/
@WebServlet(name = 'XtextServices', urlPatterns = '/xtext-service/*')
class HydraServlet extends XtextServlet {
DisposableRegistry disposableRegistry
override init() {
super.init()
val injector = new HydraWebSetup().createInjectorAndDoEMFRegistration()
disposableRegistry = injector.getInstance(DisposableRegistry)
}
override destroy() {
if (disposableRegistry !== null) {
disposableRegistry.dispose()
disposableRegistry = null
}
super.destroy()
}

DisposableRegistry disposableRegistry

override init() {
super.init()
val injector = new HydraWebSetup().createInjectorAndDoEMFRegistration()
disposableRegistry = injector.getInstance(DisposableRegistry)
}

override destroy() {
if (disposableRegistry !== null) {
disposableRegistry.dispose()
disposableRegistry = null
}
super.destroy()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import org.eclipse.xtext.util.Modules2
* Initialization support for running Xtext languages in web applications.
*/
class HydraWebSetup extends HydraStandaloneSetup {
override Injector createInjector() {
return Guice.createInjector(Modules2.mixin(new HydraRuntimeModule, new HydraIdeModule, new HydraWebModule))
}

override Injector createInjector() {
return Guice.createInjector(Modules2.mixin(new HydraRuntimeModule, new HydraIdeModule, new HydraWebModule))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ WithModifier: 'With';

ClassBlock:
WithModifier 'Class' name=Identifier '{'
(children+=RepresentationStep)*
(classChildren+=RepresentationStep)*
'}';

PropertyBlock:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
grammar app.hypermedia.testing.dsl.Hydra with app.hypermedia.testing.dsl.Core

import "http://testing.hypermedia.app/dsl/core"
generate hydra "http://testing.hypermedia.app/dsl/hydra"

HydraScenario:
(namespaces+=NamespaceDeclaration)*
(steps+=TopLevelStep)*;
@Override

@Override
TopLevelStep:
super |
RelaxedOperationBlock;
@Override
OperationBlock;

@Override
RepresentationStep:
super |
OperationBlock
;

@Override
Identifier:
UriName |
@Override
Identifier:
UriName |
PrefixedName
;

Expand All @@ -32,17 +32,10 @@ PrefixDeclaration: value=PREFIX;
UriName: value=URI;
PrefixedName: value=QNAME;

RelaxedOperationBlock:
WithModifier 'Operation' name=Identifier '{'
(invocations+=InvocationBlock)*
'}'
;

// TODO: Can we use only one step for this and restrict Expect Operation from being used on top level??
OperationBlock:
modifier=Modifier 'Operation' name=Identifier '{'
modifier=Modifier 'Operation' name=Identifier ('{'
(invocations+=InvocationBlock)*
'}'
'}')?
;

InvocationBlock:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package app.hypermedia.testing.dsl
*/
class HydraStandaloneSetup extends HydraStandaloneSetupGenerated {

def static void doSetup() {
new HydraStandaloneSetup().createInjectorAndDoEMFRegistration()
}
def static void doSetup() {
new HydraStandaloneSetup().createInjectorAndDoEMFRegistration()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import org.eclipse.xtext.nodemodel.INode

class VariableReferenceConverter implements IValueConverter<String> {
final String INVALID_VALUE_ERROR = "Variable must be string enclosed with brackets"
override toString(String value)

override toString(String value)
'''[«value»]'''

override toValue(String string, INode node) throws ValueConverterException {
if (string === null) {
return null
}

if(string.length < 3 || !string.startsWith("[") || !string.endsWith("]")) {
throw new ValueConverterException(INVALID_VALUE_ERROR, node, null)
}

return string.substring(1, string.length - 1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import org.json.JSONObject
import org.json.JSONArray
import java.util.Map
import java.util.HashMap
import app.hypermedia.testing.dsl.core.ResponseStep
import app.hypermedia.testing.dsl.core.FollowStatement
import app.hypermedia.testing.dsl.core.Identifier
import app.hypermedia.testing.dsl.core.CoreScenario
import org.eclipse.emf.common.util.EList

/**
* Generates code from your model files on save.
Expand All @@ -37,7 +38,7 @@ class CoreGenerator extends AbstractGenerator {

override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {

val Iterable<EObject> blocks = resource.allContents.filter(TopLevelStep).toList
val Iterable<TopLevelStep> blocks = getSteps(resource.contents).toList

if ( ! blocks.empty) {
val String dslFileName = resource.getURI().lastSegment.toString();
Expand All @@ -46,13 +47,13 @@ class CoreGenerator extends AbstractGenerator {
}
}

def generateSteps(Iterable<EObject> blocks) {
def generateSteps(Iterable<TopLevelStep> blocks) {
val scenario = new JSONObject();
val steps = new JSONArray()

for (block : blocks) {
val stepJson = block.step
steps.put(new JSONObject(stepJson.toString()))
steps.put(new JSONObject(stepJson.toString()))
}

scenario.put('steps', steps)
Expand All @@ -76,7 +77,7 @@ class CoreGenerator extends AbstractGenerator {
val map = new HashMap<String, Object>
map.put('classId', cb.name.identifier)

return buildBlock('Class', cb.children, map)
return buildBlock('Class', cb.classChildren, map)
}

def dispatch step(PropertyBlock it) {
Expand Down Expand Up @@ -152,7 +153,7 @@ class CoreGenerator extends AbstractGenerator {
def dispatch step(FollowStatement it) {
val map = new HashMap<String, Object>
map.put('variable', variable)

return buildStatement('Follow', map)
}

Expand All @@ -163,4 +164,8 @@ class CoreGenerator extends AbstractGenerator {
def dispatch identifier(Identifier it) {
return value
}

protected def getSteps(EList<EObject> s) {
return s.filter(CoreScenario).flatMap[cs | cs.steps]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package app.hypermedia.testing.dsl.generator

import app.hypermedia.testing.dsl.hydra.OperationBlock
import app.hypermedia.testing.dsl.hydra.InvocationBlock
import app.hypermedia.testing.dsl.hydra.RelaxedOperationBlock
import app.hypermedia.testing.dsl.Modifier
import java.util.HashMap
import app.hypermedia.testing.dsl.hydra.UriName
Expand All @@ -15,44 +14,43 @@ import org.eclipse.xtext.generator.IGeneratorContext
import org.eclipse.emf.ecore.resource.Resource
import app.hypermedia.testing.dsl.hydra.NamespaceDeclaration
import java.util.Map
import app.hypermedia.testing.dsl.hydra.HydraScenario
import org.eclipse.emf.common.util.EList
import org.eclipse.emf.ecore.EObject

/**
* Generates code from your model files on save.
*
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
class HydraGenerator extends CoreGenerator {
final Map<String, String> _namespaces
final Map<String, String> _namespaces

new () {
_namespaces = new HashMap
}

override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
resource.allContents.filter(NamespaceDeclaration).forEach[it | _namespaces.put(prefix.value, namespace)]

super.doGenerate(resource, fsa, context)
}

protected override getSteps(EList<EObject> s) {
return s.filter(HydraScenario).flatMap[cs | cs.steps]
}

def dispatch step(OperationBlock it) {
val map = new HashMap<String, Object>
map.put('operationId', name.identifier)
map.put('strict', modifier != Modifier.WITH)

return buildBlock('Operation', invocations, map)
}

def dispatch step(RelaxedOperationBlock it) {
val map = new HashMap<String, Object>
map.put('operationId', name.identifier)
map.put('strict', false)


return buildBlock('Operation', invocations, map)
}

def dispatch step(InvocationBlock it) {
val map = new HashMap<String, Object>

return buildBlock('Invocation', children, map)
}

Expand All @@ -65,11 +63,11 @@ class HydraGenerator extends CoreGenerator {
val prefix = pair.get(0)
val term = pair.get(1)
val namespace = _namespaces.get(prefix)

if (namespace === null) {
throw new IllegalStateException('''Unmapped prefix "«prefix»"''')
}

return '''«namespace»«term»'''
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package app.hypermedia.testing.dsl.scoping

/**
* This class contains custom scoping description.
*
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping
* on how and when to use it.
*/
Expand Down
Loading

0 comments on commit d5e772c

Please sign in to comment.