Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Close #53
Browse files Browse the repository at this point in the history
  • Loading branch information
jachinte committed Oct 6, 2017
1 parent aaeb7e5 commit 246c81e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ subsystem DockerCE {
*/
var String gpgKey = '9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88'

on hosts {
on HTTPS.hosts {
init:
(cmd 'docker --version')
.fetch [ replace.set(!it.contains(version)) ]
.fallback [ install.set(true) ]
}

on hosts? install || replace {
on HTTPS.hosts? install || replace {
verification: init, org.amelia.dsl.examples.ubuntu.HTTPS.installation;
cmd 'curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -'
(cmd 'apt-key fingerprint 0EBFCD88')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ subsystem FraSCAti {
*/
var String binary = 'https://github.com/jachinte/frascati-binaries/raw/master/frascati'

on hosts {
on Java1_6u23.HTTPS.hosts {
verification: org.amelia.dsl.examples.ubuntu.frascati.Java1_6u23.configuration;
// Install FraSCAti unless it is already installed
(cmd 'frascati --version').fallback [ install.set(true) ]
}

on hosts? install {
on Java1_6u23.HTTPS.hosts? install {
download: verification;
cd '/tmp'
(cmd 'curl -L -o frascati-1.4-bin.zip «zip»')
Expand All @@ -51,7 +51,7 @@ subsystem FraSCAti {
cmd 'chmod a+x /opt/frascati-runtime-1.4/bin/frascati'

configuration: update;
cmd 'chown -R «user» /opt/frascati-runtime-1.4'
cmd 'chown -R «Java1_6u23.user» /opt/frascati-runtime-1.4'
cmd 'echo "export FRASCATI_HOME=/opt/frascati-runtime-1.4" >> /etc/profile'
cmd 'echo "export PATH=\$PATH:\$FRASCATI_HOME/bin" >> /etc/profile'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.amelia.dsl.examples.ubuntu.frascati

import org.amelia.dsl.lib.descriptors.Host
import java.util.concurrent.atomic.AtomicBoolean
import static org.amelia.dsl.examples.Util.raiseif
import static extension org.amelia.dsl.examples.Util.warn

includes org.amelia.dsl.examples.ubuntu.HTTPS

/*
* Installs Oracle JDK 2.6.0_23.
*
Expand All @@ -13,11 +14,6 @@ import static extension org.amelia.dsl.examples.Util.warn
*/
subsystem Java1_6u23 {

/*
* The hosts in which Java is installed.
*/
param Iterable<Host> hosts

/*
* The user that shall own the installation folder.
*/
Expand All @@ -33,14 +29,14 @@ subsystem Java1_6u23 {
*/
var String binary = 'https://github.com/jachinte/oracle-jdk-1.6.0_23/raw/master/jdk-6u23-linux-x64.bin'

on hosts {
on HTTPS.hosts {
verification:
(cmd 'java -version')
.fetch [ raiseif(!it.contains('1.6.0_23'), 'Different JDK already installed') ]
.fallback [ install.set(true) ]
}

on hosts? install {
on HTTPS.hosts? install {
download: verification;
cd '/tmp'
(cmd 'curl -L -o jdk-6u23-linux-x64.bin «binary»')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ deployment Deployment {
val unprivileged = host(System.getProperty('host'), System.getProperty('unprivileged-user'))

// configure subsystems
add(new FraSCAti(#[ priviledged ], unprivileged.username))
add(new FraSCAti(unprivileged.username, #[ priviledged ]))
add(new Server(unprivileged))
add(new Client(unprivileged))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.amelia.dsl.lib.descriptors.CommandDescriptor
import org.amelia.dsl.lib.descriptors.Host
import org.amelia.dsl.lib.util.Arrays
import org.eclipse.xtext.common.types.JvmField
import org.eclipse.xtext.common.types.JvmOperation
import org.eclipse.xtext.common.types.JvmVisibility
import org.eclipse.xtext.naming.IQualifiedNameProvider
import org.eclipse.xtext.naming.QualifiedName
Expand Down Expand Up @@ -167,24 +168,24 @@ class AmeliaJvmModelInferrer extends AbstractModelInferrer {
val params = subsystem.params
val includedSubsystems = subsystem.includedSubsystems
val includedParams = subsystem.includedParams(false)
val includedVars = subsystem.includedVars(false)
val _parameters = newArrayList
val fields = newArrayList
val constructors = newArrayList
val methods = newArrayList
val getters = newArrayList
val hasConfigBlock = newArrayList(false)

// count blocks and rules (indices)
hostBlockIndices = subsystem.hostBlocksIndices
ruleIndices = subsystem.rulesIndices

documentation = subsystem.documentation
superTypes += typeRef(Subsystem.Deployment)

// Transform includes into fields
fields += subsystem.includesAsFields

// Transform includes into fields & getters
fields += includedSubsystems.asFields
getters += includedSubsystems.asGetters

for (e : subsystem.body.expressions) {
switch (e) {
VariableDeclaration: {
Expand Down Expand Up @@ -285,19 +286,6 @@ class AmeliaJvmModelInferrer extends AbstractModelInferrer {
]
]
}
// Add a getter for non-duplicate parameters
val includedParamsAndVars = includedParams + includedVars
val duplicates = (includedParamsAndVars + subsystem.variables).groupBy[p|p.name]
.values.filter[l|l.size > 1]
.map[l|l.get(0).name]
.toList
for (paramOrVar : includedParamsAndVars) {
if (!duplicates.contains(paramOrVar.name)) {
getters += paramOrVar.toMethod("get" + paramOrVar.name.toFirstUpper, paramOrVar.type ?: inferredType) [
body = '''return this.«paramOrVar.fullyQualifiedName.skipLast(1).javaName».get«paramOrVar.name.toFirstUpper»();'''
]
}
}
methods += subsystem.toMethod("init", typeRef(void)) [
visibility = JvmVisibility.PRIVATE
body = initRules(subsystem)
Expand Down Expand Up @@ -338,7 +326,7 @@ class AmeliaJvmModelInferrer extends AbstractModelInferrer {
}
]
]

// Method to return all rules from included subsystems
getters += subsystem.toMethod("getAllRules", typeRef(CommandDescriptor).addArrayTypeDimension) [
body = [
Expand Down Expand Up @@ -620,17 +608,22 @@ class AmeliaJvmModelInferrer extends AbstractModelInferrer {
]
}

def List<JvmField> includesAsFields(org.amelia.dsl.amelia.Subsystem subsystem) {
def List<JvmField> asFields(Iterable<org.amelia.dsl.amelia.Subsystem> includedSubsystems) {
val members = newArrayList
val model = subsystem.eContainer as Model
if (model.extensions !== null) {
for (include : model.extensions.declarations.filter(IncludeDeclaration)) {
if (include.element instanceof org.amelia.dsl.amelia.Subsystem) {
val includedSubsystem = include.element as org.amelia.dsl.amelia.Subsystem
val fqn = includedSubsystem.fullyQualifiedName
members += includedSubsystem.toField("$" + fqn.toString("$"), typeRef(fqn.toString))
}
}
for (subsystem : includedSubsystems) {
val fqn = subsystem.fullyQualifiedName
members += subsystem.toField("$" + fqn.toString("$"), typeRef(fqn.toString))
}
return members
}

def List<JvmOperation> asGetters(Iterable<org.amelia.dsl.amelia.Subsystem> includedSubsystems) {
val members = newArrayList
for (subsystem : includedSubsystems) {
val fqn = subsystem.fullyQualifiedName
members += subsystem.toMethod(subsystem.name, typeRef(fqn.toString)) [
body = '''return this.$«fqn.toString("$")»;'''
]
}
return members
}
Expand Down Expand Up @@ -695,10 +688,6 @@ class AmeliaJvmModelInferrer extends AbstractModelInferrer {
return includedVariableDecl(subsystem, recursive, true, false)
}

def List<VariableDeclaration> includedVars(org.amelia.dsl.amelia.Subsystem subsystem, boolean recursive) {
return includedVariableDecl(subsystem, recursive, false, true)
}

def List<VariableDeclaration> includedVariableDecl(org.amelia.dsl.amelia.Subsystem subsystem,
boolean recursive, boolean inclParams, boolean inclVars) {
val variableDecls = newArrayList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*/
package org.amelia.dsl.validation

import com.google.inject.Inject
import com.google.common.base.Supplier
import java.net.URI
import java.util.Collection
import java.util.List
import java.util.Set
import java.util.concurrent.atomic.AtomicBoolean
import org.amelia.dsl.amelia.AmeliaPackage
import org.amelia.dsl.amelia.CdCommand
import org.amelia.dsl.amelia.CompileCommand
Expand All @@ -46,8 +47,8 @@ import org.amelia.dsl.amelia.TypeDeclaration
import org.amelia.dsl.amelia.VariableDeclaration
import org.amelia.dsl.lib.descriptors.Host
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.xtext.EcoreUtil2
import org.eclipse.xtext.naming.IQualifiedNameProvider
import org.eclipse.xtext.validation.Check
import org.eclipse.xtext.xbase.XAbstractFeatureCall
import org.eclipse.xtext.xbase.XBooleanLiteral
Expand All @@ -59,9 +60,6 @@ import org.eclipse.xtext.xbase.XNumberLiteral
import org.eclipse.xtext.xbase.XStringLiteral
import org.eclipse.xtext.xbase.XTypeLiteral
import org.eclipse.xtext.xbase.XbasePackage
import java.util.concurrent.atomic.AtomicBoolean
import com.google.common.base.Supplier
import org.eclipse.emf.ecore.util.EcoreUtil

/**
* This class contains custom validation rules.
Expand All @@ -72,8 +70,6 @@ import org.eclipse.emf.ecore.util.EcoreUtil
*/
class AmeliaValidator extends AbstractAmeliaValidator {

@Inject extension IQualifiedNameProvider

public static val CONFIGURE_NOT_ALLOWED = "amelia.issue.configureNotAllowed"
public static val CONFLICTING_PARAMETER = "amelia.issue.conflictingParam"
public static val CYCLIC_DEPENDENCY = "amelia.issue.cyclicDependency"
Expand Down Expand Up @@ -156,16 +152,26 @@ class AmeliaValidator extends AbstractAmeliaValidator {
val parent = varDecl.eContainer.eContainer
switch (parent) {
Subsystem: {
val duplicateVars = (parent.body as SubsystemBlockExpression).expressions.filter [ v |
switch (v) {
VariableDeclaration case v.name.equals(varDecl.name):
return !v.equals(varDecl)
RuleDeclaration case v.name.equals(varDecl.name):
return true
default:
return false
}
]
val model = parent.eContainer as Model
var duplicateVars = (parent.body as SubsystemBlockExpression).expressions
.filter [ v |
switch (v) {
VariableDeclaration case v.name.equals(varDecl.name):
return !v.equals(varDecl)
RuleDeclaration case v.name.equals(varDecl.name):
return true
default:
return false
}
]
.map[w|1]
.toList
if (model.extensions !== null) {
duplicateVars += model.extensions.declarations
.filter(IncludeDeclaration)
.filter[s|s.element.name.equals(varDecl.name)]
.map[w|1]
}
if (!duplicateVars.isEmpty) {
error("Duplicate local variable " + varDecl.name, AmeliaPackage.Literals.VARIABLE_DECLARATION__NAME,
DUPLICATE_LOCAL_VARIABLE)
Expand All @@ -190,56 +196,7 @@ class AmeliaValidator extends AbstractAmeliaValidator {
AmeliaPackage.Literals.VARIABLE_DECLARATION__TYPE, MISSING_VARIABLE_TYPE)
}
}

@Check
def checkConflictingVarDecl(Subsystem subsystem) {
val model = subsystem.eContainer as Model
if (model.extensions !== null) {
val includes = model.extensions.declarations.filter(IncludeDeclaration)
val includedSubsystems = includes.map[i| if(i.element instanceof Subsystem) i.element as Subsystem]
val conflictingVarDcls = includedSubsystems
.map[s|s.body.expressions.filter(VariableDeclaration)].flatten
.groupBy[p|p.name].values.filter[l|l.size > 1]
if (!conflictingVarDcls.empty) {
var names = conflictingVarDcls.join("'", "', '", "'", [l|l.get(0).name])
val index = names.lastIndexOf("', '")
if (index > -1)
names = names.substring(0, index + 1) + " and " + names.substring(index + 3)
val d = if(conflictingVarDcls.size == 1) #["", "s", "Its"] else #["s", "", "Their"]
info('''Variable«d.get(0)» «names» belong«d.get(1)» to several included subsystems. «d.get(2)» direct access has been hidden''',
AmeliaPackage.Literals.TYPE_DECLARATION__NAME)
}
}
}

@Check
def checkConflictingVarDecl(VariableDeclaration varDecl) {
val type = if(varDecl.param) "parameter" else "variable"
val model = EcoreUtil2.getRootContainer(varDecl) as Model
val typeDecl = model.typeDeclaration
if (typeDecl instanceof Subsystem) {
if (model.extensions !== null) {
val includes = model.extensions.declarations.filter(IncludeDeclaration)
val includedSubsystems = includes.filter[i|i.element instanceof Subsystem].map[i|i.element as Subsystem]
val includedVarDecls = includedSubsystems
.map[s|s.body.expressions.filter(VariableDeclaration)].flatten
if (includedVarDecls.map[p|p.name].toList.contains(varDecl.name)) {
val conflictingVarDecl = includedVarDecls.filter[p|p.name.equals(varDecl.name)]
val subsystems = conflictingVarDecl.map[ p |
((EcoreUtil2.getRootContainer(p) as Model).typeDeclaration) as Subsystem
]
val d = if(subsystems.size == 1) "" else "s"
var list = subsystems.join("'", "', '", "'", [s|s.fullyQualifiedName.toString])
val index = list.lastIndexOf("', '")
if (index > -1)
list = list.substring(0, index + 1) + " and " + list.substring(index + 3)
info('''This «type» hides the direct access to parameter '«varDecl.name»' from the included subsystem«d» «list»''',
AmeliaPackage.Literals.VARIABLE_DECLARATION__NAME, CONFLICTING_PARAMETER)
}
}
}
}


@Check
def checkRuleNameIsUnique(RuleDeclaration rule) {
val subsystem = (EcoreUtil2.getRootContainer(rule) as Model).typeDeclaration as Subsystem
Expand Down

0 comments on commit 246c81e

Please sign in to comment.