From 60a68898d04949b51b9616f0339059abd1f1d716 Mon Sep 17 00:00:00 2001 From: Juergen Gehring Date: Fri, 7 Apr 2017 01:44:27 -0700 Subject: [PATCH] CommonAPI-D-Bus-Tools 3.1.11.1 --- CHANGES | 2 + .../compositeArtifacts.xml | 13 + .../compositeContent.xml | 13 + .../plugin.xml | 2 +- .../dbus/validator/ValidatorDBusUi.java | 12 +- .../ValidatorDBusPreferencesPage.java | 5 +- .../CMakeLists.txt | 71 +- .../FInterfaceDBusDeploymentGenerator.xtend | 44 +- .../FInterfaceDBusStubAdapterGenerator.xtend | 2 +- ...ypeCollectionDBusDeploymentGenerator.xtend | 24 +- .../dbus/verification/ValidatorDBus.java | 658 +++++++++--------- 11 files changed, 464 insertions(+), 382 deletions(-) create mode 100644 org.genivi.commonapi.dbus.updatesite/composite_update_site/compositeArtifacts.xml create mode 100644 org.genivi.commonapi.dbus.updatesite/composite_update_site/compositeContent.xml diff --git a/CHANGES b/CHANGES index c5b77e1..1a10492 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,7 @@ Changes ======= +v3.1.11.1 +- Support deployment for anonymous arrays v3.1.10 - Upgrade to JDK-1.8. diff --git a/org.genivi.commonapi.dbus.updatesite/composite_update_site/compositeArtifacts.xml b/org.genivi.commonapi.dbus.updatesite/composite_update_site/compositeArtifacts.xml new file mode 100644 index 0000000..25b68ab --- /dev/null +++ b/org.genivi.commonapi.dbus.updatesite/composite_update_site/compositeArtifacts.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/org.genivi.commonapi.dbus.updatesite/composite_update_site/compositeContent.xml b/org.genivi.commonapi.dbus.updatesite/composite_update_site/compositeContent.xml new file mode 100644 index 0000000..9a45538 --- /dev/null +++ b/org.genivi.commonapi.dbus.updatesite/composite_update_site/compositeContent.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/org.genivi.commonapi.dbus.validator/plugin.xml b/org.genivi.commonapi.dbus.validator/plugin.xml index bea1056..cef8cda 100644 --- a/org.genivi.commonapi.dbus.validator/plugin.xml +++ b/org.genivi.commonapi.dbus.validator/plugin.xml @@ -14,7 +14,7 @@ + name="CommonAPI-DBus Validator"> diff --git a/org.genivi.commonapi.dbus.validator/src/org/genivi/commonapi/dbus/validator/ValidatorDBusUi.java b/org.genivi.commonapi.dbus.validator/src/org/genivi/commonapi/dbus/validator/ValidatorDBusUi.java index 42f165a..e4eb345 100644 --- a/org.genivi.commonapi.dbus.validator/src/org/genivi/commonapi/dbus/validator/ValidatorDBusUi.java +++ b/org.genivi.commonapi.dbus.validator/src/org/genivi/commonapi/dbus/validator/ValidatorDBusUi.java @@ -23,16 +23,10 @@ public class ValidatorDBusUi extends ValidatorDBus { @Override public void validateModel(FModel model, ValidationMessageAcceptor messageAcceptor) { - try { - if (!isValidatorEnabled()) { - return; - } - super.validateModel(model, messageAcceptor); - } - catch (Exception ex) { - ex.printStackTrace(); - throw ex; + if (!isValidatorEnabled()) { + return; } + super.validateModel(model, messageAcceptor); } diff --git a/org.genivi.commonapi.dbus.validator/src/org/genivi/commonapi/dbus/validator/preference/ValidatorDBusPreferencesPage.java b/org.genivi.commonapi.dbus.validator/src/org/genivi/commonapi/dbus/validator/preference/ValidatorDBusPreferencesPage.java index 026d0d4..431f324 100644 --- a/org.genivi.commonapi.dbus.validator/src/org/genivi/commonapi/dbus/validator/preference/ValidatorDBusPreferencesPage.java +++ b/org.genivi.commonapi.dbus.validator/src/org/genivi/commonapi/dbus/validator/preference/ValidatorDBusPreferencesPage.java @@ -28,10 +28,10 @@ public void checkState() { @Override public void createFieldEditors() { addField(new BooleanFieldEditor(PreferenceConstantsDBus.P_ENABLE_DBUS_VALIDATOR, - "validator enabled", getFieldEditorParent())); + "Enable CommonAPI-DBus specific validation of Franca IDL files", getFieldEditorParent())); addField(new BooleanFieldEditor( ENABLED_WORKSPACE_CHECK, - "enable the whole workspace check (Note: Validations takes up to two minutes if enabled)", + "Enable whole workspace check", getFieldEditorParent())); } @@ -39,7 +39,6 @@ public void createFieldEditors() { public void init(IWorkbench workbench) { IPreferenceStore prefStore = CommonApiDBusUiPlugin.getValidatorPreferences(); setPreferenceStore(prefStore); - setDescription("Disable or enable the dbus validator!"); } } diff --git a/org.genivi.commonapi.dbus.verification/CMakeLists.txt b/org.genivi.commonapi.dbus.verification/CMakeLists.txt index 3929eda..97082b7 100644 --- a/org.genivi.commonapi.dbus.verification/CMakeLists.txt +++ b/org.genivi.commonapi.dbus.verification/CMakeLists.txt @@ -38,6 +38,7 @@ SET(COMMONAPI_CMAKE_INSTALL_PATH "na" CACHE STRING "CommonAPI install path of th SET(COMMONAPI_DBUS_CMAKE_INSTALL_PATH "na" CACHE STRING "CommonAPI-DBus install path of the cmake files") SET(COMMONAPI_DBUS_TOOL_GENERATOR "na" CACHE STRING "CommonAPI-DBus-Tools generator install path") SET(COMMONAPI_TEST_FIDL_PATH "na" CACHE STRING "Path to directory with test fidl files for code generation") +SET(COMMONAPI_SRC_GEN_DEST "src-gen" CACHE STRING "Path to the destination directory of the generated sources") if("${COMMONAPI_DBUS_TOOL_GENERATOR}" STREQUAL "na") message(FATAL_ERROR "The file path for the commonapi_dbus_generator needs to be specified! Use '-DCOMMONAPI_DBUS_TOOL_GENERATOR' to do so.") @@ -54,6 +55,8 @@ else() endif() message("Build type: ${CMAKE_BUILD_TYPE}") +message("The path to the destination directory of the generated sources is set to: ${COMMONAPI_SRC_GEN_DEST}") + ############################################################################## # add COMMONAPI install path to cmake find root path @@ -105,10 +108,10 @@ endif() # generate code from fidl file(GLOB FIDL_FILES "${COMMONAPI_TEST_FIDL_PATH}/*.fidl") message("FIDL_FILES: ${FIDL_FILES}") -execute_process(COMMAND ${COMMONAPI_DBUS_TOOL_GENERATOR} -dest src-gen ${FIDL_FILES} +execute_process(COMMAND ${COMMONAPI_DBUS_TOOL_GENERATOR} -dest ${COMMONAPI_SRC_GEN_DEST} ${FIDL_FILES} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) -execute_process(COMMAND ${COMMONAPI_TOOL_GENERATOR} -dest src-gen ${FIDL_FILES} +execute_process(COMMAND ${COMMONAPI_TOOL_GENERATOR} -dest ${COMMONAPI_SRC_GEN_DEST} ${FIDL_FILES} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) ############################################################################## @@ -137,13 +140,17 @@ message("Compiler options: ${CMAKE_CXX_FLAGS}") include_directories( src - src-gen + ${COMMONAPI_SRC_GEN_DEST} ${COMMONAPI_INCLUDE_DIRS} ${DBus_INCLUDE_DIRS} ${COMMONAPI_DBUS_INCLUDE_DIRS} ) -if ("${USE_INSTALLED_DBUS}" STREQUAL "OFF") +if ("${USE_INSTALLED_DBUS}" STREQUAL "ON") + link_directories( + ${DBus_LIBRARY_DIRS} + ) +else() link_directories( ${DBus_INCLUDE_DIRS}/dbus/.libs ) @@ -151,36 +158,36 @@ endif() if (MSVC) # source files - file(GLOB GLUE_SRCS "src-gen/v1/commonapi/runtime/*.cpp" - "src-gen/v1/commonapi/communication/*.cpp" - "src-gen/v1/commonapi/advanced/bselective/*.cpp" - "src-gen/v1/commonapi/advanced/managed/*.cpp" - "src-gen/v1/commonapi/advanced/extended/*.cpp" - "src-gen/v1/commonapi/advanced/polymorph/*.cpp" - "src-gen/v1/commonapi/datatypes/primitive/*.cpp" - "src-gen/v1/commonapi/datatypes/advanced/*.cpp" - "src-gen/v1/commonapi/datatypes/derived/*.cpp" - "src-gen/v1/commonapi/datatypes/combined/*.cpp" - "src-gen/v1/commonapi/threading/*.cpp" - "src-gen/v1/commonapi/performance/primitive/*.cpp" - "src-gen/v1/commonapi/performance/complex/*.cpp" - "src-gen/v1/commonapi/stability/sp/*.cpp") + file(GLOB GLUE_SRCS "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/runtime/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/communication/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/advanced/bselective/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/advanced/managed/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/advanced/extended/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/advanced/polymorph/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/datatypes/primitive/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/datatypes/advanced/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/datatypes/derived/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/datatypes/combined/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/threading/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/performance/primitive/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/performance/complex/*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/stability/sp/*.cpp") else() # source files - file(GLOB GLUE_SRCS "src-gen/v1/commonapi/runtime/*DBus*.cpp" - "src-gen/v1/commonapi/communication/*DBus*.cpp" - "src-gen/v1/commonapi/advanced/bselective/*DBus*.cpp" - "src-gen/v1/commonapi/advanced/managed/*DBus*.cpp" - "src-gen/v1/commonapi/advanced/extended/*DBus*.cpp" - "src-gen/v1/commonapi/advanced/polymorph/*DBus*.cpp" - "src-gen/v1/commonapi/datatypes/primitive/*DBus*.cpp" - "src-gen/v1/commonapi/datatypes/advanced/*DBus*.cpp" - "src-gen/v1/commonapi/datatypes/derived/*DBus*.cpp" - "src-gen/v1/commonapi/datatypes/combined/*DBus*.cpp" - "src-gen/v1/commonapi/threading/*DBus*.cpp" - "src-gen/v1/commonapi/performance/primitive/*DBus*.cpp" - "src-gen/v1/commonapi/performance/complex/*DBus*.cpp" - "src-gen/v1/commonapi/stability/sp/*DBus*.cpp") + file(GLOB GLUE_SRCS "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/runtime/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/communication/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/advanced/bselective/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/advanced/managed/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/advanced/extended/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/advanced/polymorph/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/datatypes/primitive/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/datatypes/advanced/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/datatypes/derived/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/datatypes/combined/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/threading/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/performance/primitive/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/performance/complex/*DBus*.cpp" + "${COMMONAPI_SRC_GEN_DEST}/v1/commonapi/stability/sp/*DBus*.cpp") endif() # CommonAPI-DBus library diff --git a/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/generator/FInterfaceDBusDeploymentGenerator.xtend b/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/generator/FInterfaceDBusDeploymentGenerator.xtend index a6cac33..17962f6 100644 --- a/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/generator/FInterfaceDBusDeploymentGenerator.xtend +++ b/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/generator/FInterfaceDBusDeploymentGenerator.xtend @@ -180,18 +180,38 @@ class FInterfaceDBusDeploymentGenerator extends FTypeCollectionDBusDeploymentGen def protected dispatch String generateDeploymentDefinition(FAttribute _attribute, FInterface _interface, PropertyAccessor _accessor) { if (_accessor.hasSpecificDeployment(_attribute) || (_attribute.array && _accessor.hasDeployment(_attribute))) { - var String definition = _attribute.getDeploymentType(_interface, true) + " " + _attribute.name + "Deployment(" - definition += _attribute.getDeploymentParameter(_attribute, _accessor) + var String definition = "" + if (_attribute.array) { + definition += _attribute.type.getDeploymentType(_interface, true) + " " + _attribute.name + "ElementDeployment(" + definition += getDeploymentParameter(_attribute.type, _attribute, _accessor) + definition += ");\n"; + } + definition += _attribute.getDeploymentType(_interface, true) + " " + _attribute.name + "Deployment(" + if (_attribute.array) { + definition += "&" + _attribute.name + "ElementDeployment" + } else { + definition += _attribute.getDeploymentParameter(_attribute, _accessor) + } definition += ");" return definition } - return "" + return "" } def protected String generateDeploymentDefinition(FArgument _argument, FMethod _method, FInterface _interface, PropertyAccessor _accessor) { if (_accessor.hasSpecificDeployment(_argument) || (_argument.array && _accessor.hasDeployment(_argument))) { - var String definition = _argument.getDeploymentType(_interface, true) + " " + _method.name + "_" + _argument.name + "Deployment(" - definition += _argument.getDeploymentParameter(_argument, _accessor) + var String definition = "" + if (_argument.array) { + definition += _argument.type.getDeploymentType(_interface, true) + " " + _method.name + "_" + _argument.name + "ElementDeployment(" + definition += getDeploymentParameter(_argument.type, _argument, _accessor) + definition += ");\n"; + } + definition += _argument.getDeploymentType(_interface, true) + " " + _method.name + "_" + _argument.name + "Deployment(" + if (_argument.array) { + definition += "&" + _method.name + "_" + _argument.name + "ElementDeployment" + } else { + definition += _argument.getDeploymentParameter(_argument, _accessor) + } definition += ");" return definition } @@ -199,8 +219,18 @@ class FInterfaceDBusDeploymentGenerator extends FTypeCollectionDBusDeploymentGen def protected String generateDeploymentDefinition(FArgument _argument, FBroadcast _broadcast, FInterface _interface, PropertyAccessor _accessor) { if (_accessor.hasSpecificDeployment(_argument) || (_argument.array && _accessor.hasDeployment(_argument))) { - var String definition = _argument.getDeploymentType(_interface, true) + " " + _broadcast.name + "_" + _argument.name + "Deployment(" - definition += _argument.getDeploymentParameter(_argument, _accessor) + var String definition = "" + if (_argument.array) { + definition += _argument.type.getDeploymentType(_interface, true) + " " + _broadcast.name + "_" + _argument.name + "ElementDeployment(" + definition += getDeploymentParameter(_argument.type, _argument, _accessor) + definition += ");\n"; + } + definition += _argument.getDeploymentType(_interface, true) + " " + _broadcast.name + "_" + _argument.name + "Deployment(" + if (_argument.array) { + definition += "&" + _broadcast.name + "_" + _argument.name + "ElementDeployment" + } else { + definition += _argument.getDeploymentParameter(_argument, _accessor) + } definition += ");" return definition } diff --git a/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/generator/FInterfaceDBusStubAdapterGenerator.xtend b/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/generator/FInterfaceDBusStubAdapterGenerator.xtend index 0352007..24474d7 100644 --- a/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/generator/FInterfaceDBusStubAdapterGenerator.xtend +++ b/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/generator/FInterfaceDBusStubAdapterGenerator.xtend @@ -733,7 +733,7 @@ class FInterfaceDBusStubAdapterGenerator { «val PropertyAccessor providerAccessor = new PropertyAccessor(new FDeployedProvider(p))» «FOR i : p.instances.filter[target == fInterface]» CommonAPI::DBus::DBusAddressTranslator::get()->insert( - "local:«fInterface.fullyQualifiedNameWithVersion»»:«providerAccessor.getInstanceId(i)»", + "local:«fInterface.fullyQualifiedNameWithVersion»:«providerAccessor.getInstanceId(i)»", "«providerAccessor.getDBusServiceName(i)»", "«providerAccessor.getDBusObjectPath(i)»", "«providerAccessor.getDBusInterfaceName(i)»"); diff --git a/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/generator/FTypeCollectionDBusDeploymentGenerator.xtend b/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/generator/FTypeCollectionDBusDeploymentGenerator.xtend index ea0c02e..b9c1288 100644 --- a/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/generator/FTypeCollectionDBusDeploymentGenerator.xtend +++ b/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/generator/FTypeCollectionDBusDeploymentGenerator.xtend @@ -336,8 +336,18 @@ class FTypeCollectionDBusDeploymentGenerator { def protected dispatch String generateDeploymentDefinition(FField _field, FTypeCollection _tc, PropertyAccessor _accessor) { if (_accessor.hasSpecificDeployment(_field)) { - var String definition = _field.getDeploymentType(null, false) + " " + _field.getRelativeName() + "Deployment(" - definition += getDeploymentParameter(_field.type, _field, _accessor) + var String definition = ""; + if (_field.array) { + definition += _field.type.getDeploymentType(null, false) + " " + _field.getRelativeName() + "ElementDeployment(" + definition += getDeploymentParameter(_field.type, _field, _accessor) + definition += ");\n"; + } + definition += _field.getDeploymentType(null, false) + " " + _field.getRelativeName() + "Deployment(" + if (_field.array) { + definition += "&" + _field.getRelativeName() + "ElementDeployment" + } else { + definition += getDeploymentParameter(_field.type, _field, _accessor) + } definition += ");\n" return definition } @@ -352,16 +362,6 @@ class FTypeCollectionDBusDeploymentGenerator { return "" } - def protected dispatch String generateDeploymentDefinition(FAttribute _attribute, FTypeCollection _tc, PropertyAccessor _accessor) { - if (_accessor.hasSpecificDeployment(_attribute)) { - var String definition = _attribute.getDeploymentType(null, false) + " " + _attribute.name + "Deployment(" - definition += _attribute.getDeploymentParameter(_attribute, _accessor) - definition += ");" - return definition - } - return "" - } - def protected dispatch String getDeploymentParameter(FArrayType _array, EObject _source, PropertyAccessor _accessor) { var String parameter = getArrayElementTypeDeploymentParameter(_array.elementType, _array, _accessor) var String arrayDeploymentParameter = getArrayDeploymentParameter(_array, _source, _accessor) diff --git a/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/verification/ValidatorDBus.java b/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/verification/ValidatorDBus.java index c654ea1..4838b36 100644 --- a/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/verification/ValidatorDBus.java +++ b/org.genivi.commonapi.dbus/src/org/genivi/commonapi/dbus/verification/ValidatorDBus.java @@ -20,7 +20,6 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; -import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; @@ -55,186 +54,205 @@ * validator detects errors. * */ -public class ValidatorDBus implements IFrancaExternalValidator { - - private FTypeCycleDetector cycleDetector; - // > - private HashMap> importList = new HashMap>(); - private AllInfoMapsBuilder aimBuilder = new AllInfoMapsBuilder(); - private Map>> fastAllInfo = new HashMap>>(); - private Boolean hasChanged = false; - private ResourceSet resourceSet; - private Set resourceList = new HashSet(); - private boolean isCommandLineEnvironment = false; - private String path = null; +public class ValidatorDBus implements IFrancaExternalValidator +{ + + private FTypeCycleDetector cycleDetector; + private HashMap> importList = new HashMap>(); + private AllInfoMapsBuilder aimBuilder = new AllInfoMapsBuilder(); + private Map>> fastAllInfo = new HashMap>>(); + private Boolean hasChanged = false; + private ResourceSet resourceSet; + private Set resourceList = new HashSet(); + + public ValidatorDBus() + { + cycleDetector = Guice.createInjector().getInstance(FTypeCycleDetector.class); + } @Override - public void validateModel(FModel model, - ValidationMessageAcceptor messageAcceptor) { - if (!isValidatorEnabled()) { - return; - } - cycleDetector = Guice.createInjector().getInstance( - FTypeCycleDetector.class); - - resourceSet = new ResourceSetImpl(); - Resource res = model.eResource(); - URI uri = res.getURI(); // file:/home/.../input/Test.fidl - res.getURI().isFile(); - int segCount = 0; - Path platformPath = null; - IFile file = null; - IPath filePath = null; - String cwd = null; - String parentfolder = null; - - if(uri.toString().startsWith("platform:")) { - segCount = uri.segmentCount() - 2; - platformPath = new Path(res.getURI().toPlatformString(true)); - file = ResourcesPlugin.getWorkspace().getRoot().getFile(platformPath); - filePath = file.getLocation(); - cwd = filePath.removeLastSegments(1).toString(); - path = file.getLocation().toString(); - parentfolder = filePath.removeLastSegments(segCount).toString(); // e.g.: /home/.../project/runtime-New_configuration/Testprojekt - } - else if(uri.toString().startsWith("file:")) { - String fileName = uri.segment(uri.segmentCount() - 1); - String uriString = uri.toString(); - path = uriString.replaceFirst("file:", ""); - cwd = path.replaceFirst(fileName, ""); - isCommandLineEnvironment = true; - parentfolder = uri.segment(uri.segmentCount() - 2); - } - + public void validateModel(FModel model, ValidationMessageAcceptor messageAcceptor) + { try { - initImportList(model, cwd, path); - importList = buildImportList(importList); - } catch (NullPointerException e) { - } - for (FTypeCollection fTypeCollection : model.getTypeCollections()) { - validateImportedTypeCollections(model, messageAcceptor, file, cwd, - fTypeCollection); - } - - if (isWholeWorkspaceCheckActive()) { - if (aimBuilder.buildAllInfos(parentfolder)) { - fastAllInfo = aimBuilder.fastAllInfo; - } else { - if (!uri.segment(2).toString().equals("bin")) - aimBuilder.updateAllInfo(model, - filePath.toString()); - fastAllInfo = aimBuilder.fastAllInfo; + if (!isValidatorEnabled()) + { + return; + } + resourceSet = new ResourceSetImpl(); + Resource res = model.eResource(); + URI uri = res.getURI(); + + boolean isWorkspaceUri = res.getURI().isPlatform(); + IPath filePath; + String filePathString; + if (isWorkspaceUri) + { + Path platformPath = new Path(res.getURI().toPlatformString(true)); + IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(platformPath); + filePath = file.getLocation(); + filePathString = file.getLocation().toString(); + } + else + { + filePath = new Path(res.getURI().toFileString()); + filePathString = filePath.toString(); } - } else { - resourceList.add(model); - aimBuilder.buildAllInfo(resourceList); - } - HashMap> managedInterfaces = new HashMap>(); - for (FInterface fInterface : model.getInterfaces()) { - managedInterfaces - .put(fInterface, fInterface.getManagedInterfaces()); - validateImportedTypeCollections(model, messageAcceptor, file, parentfolder, - fInterface); - } - for (FTypeCollection fTypeCollection : model.getTypeCollections()) { - try { - validateTypeCollectionName(model, messageAcceptor, filePath, - fTypeCollection); - } catch (Exception e) { - e.printStackTrace(); + try + { + String cwd = filePath.removeLastSegments(1).toString(); + initImportList(model, cwd, filePathString); + importList = buildImportList(importList); + + for (FTypeCollection fTypeCollection : model.getTypeCollections()) + { + validateImportedTypeCollections(model, messageAcceptor, filePath.lastSegment(), cwd, fTypeCollection); + } + } + catch (NullPointerException e) + { } - validateTypeCollectionElements(messageAcceptor, fTypeCollection); - } - for (FInterface fInterface : model.getInterfaces()) { - validateTypeCollectionName(model, messageAcceptor, filePath, - fInterface); - validateFInterfaceElements(messageAcceptor, fInterface); - } - resourceList.clear(); - importList.clear(); + if (isWorkspaceUri) + { + // That path segment logic works only for paths within an Eclipse Workspace, but not for the command line + // which may point to files outside an Eclipse Workspace. + int segCount = uri.segmentCount() - 2; + String cwd = filePath.removeLastSegments(segCount).toString(); + if (isWholeWorkspaceCheckActive()) + { + if (aimBuilder.buildAllInfos(cwd)) + { + fastAllInfo = aimBuilder.fastAllInfo; + } + else + { + if (!uri.segment(2).toString().equals("bin")) + aimBuilder.updateAllInfo(model, filePath.toString()); + fastAllInfo = aimBuilder.fastAllInfo; + } + } + else + { + resourceList.add(model); + aimBuilder.buildAllInfo(resourceList); + } + + + cwd = filePath.removeLastSegments(1).toString(); + for (FInterface fInterface : model.getInterfaces()) + { + validateImportedTypeCollections(model, messageAcceptor, filePath.lastSegment(), cwd, fInterface); + } + } + + for (FTypeCollection fTypeCollection : model.getTypeCollections()) + { + validateTypeCollectionName(model, messageAcceptor, filePath, fTypeCollection); + validateTypeCollectionElements(messageAcceptor, fTypeCollection); + } + + for (FInterface fInterface : model.getInterfaces()) + { + validateTypeCollectionName(model, messageAcceptor, filePath, fInterface); + validateFInterfaceElements(messageAcceptor, fInterface); + } + resourceList.clear(); + importList.clear(); + } + catch (Exception ex) { + ex.printStackTrace(); + throw ex; + } } + // put all imports (with absolute path) of this model to a map - private void initImportList(FModel model, String cwd, String filePath) { + private void initImportList(FModel model, String cwd, String filePath) + { HashSet importedFiles = new HashSet(); - for (Import fImport : model.getImports()) { + for (Import fImport : model.getImports()) + { Path absoluteImportPath = new Path(fImport.getImportURI()); - if (!absoluteImportPath.isAbsolute()) { - absoluteImportPath = new Path(cwd + "/" - + fImport.getImportURI()); + if (!absoluteImportPath.isAbsolute()) + { + absoluteImportPath = new Path(cwd + "/" + fImport.getImportURI()); importedFiles.add(absoluteImportPath.toString()); - } else { - importedFiles.add(absoluteImportPath.toString().replaceFirst( - absoluteImportPath.getDevice() + "/", "")); + } + else + { + importedFiles.add(absoluteImportPath.toString().replaceFirst(absoluteImportPath.getDevice() + "/", "")); } } importList.put(filePath, importedFiles); } - private EObject buildResource(String filename, String cwd) { + private EObject buildResource(String filename, String cwd) + { URI fileURI = normalizeURI(URI.createURI(filename)); URI cwdURI = normalizeURI(URI.createURI(cwd)); Resource resource = null; - if (cwd != null && cwd.length() > 0) { - fileURI = URI.createURI((cwdURI.toString() + "/" + fileURI - .toString()).replaceAll("/+", "/")); + if (cwd != null && cwd.length() > 0) + { + fileURI = URI.createURI((cwdURI.toString() + "/" + fileURI.toString()).replaceAll("/+", "/")); } - try { + try + { resource = resourceSet.getResource(fileURI, true); resource.load(Collections.EMPTY_MAP); - } catch (RuntimeException e) { + } + catch (RuntimeException e) + { return null; - } catch (IOException io) { + } + catch (IOException io) + { return null; } return resource.getContents().get(0); } - private static URI normalizeURI(URI path) { - if (path.isFile()) { + private static URI normalizeURI(URI path) + { + if (path.isFile()) + { return URI.createURI(path.toString().replaceAll("\\\\", "/")); } return path; } - private HashMap> buildImportList( - HashMap> rekImportList) { + private HashMap> buildImportList(HashMap> rekImportList) + { HashMap> helpMap = new HashMap>(); - for (Entry> entry : rekImportList.entrySet()) { - for (String importedPath : entry.getValue()) { - if (!rekImportList.containsKey(importedPath)) { + for (Entry> entry : rekImportList.entrySet()) + { + for (String importedPath : entry.getValue()) + { + if (!rekImportList.containsKey(importedPath)) + { hasChanged = true; HashSet importedFIDL = new HashSet(); EObject resource = null; - resource = buildResource( - importedPath.substring( - importedPath.lastIndexOf("/") + 1, - importedPath.length()), - "file:/" - + importedPath.substring(0, - importedPath.lastIndexOf("/") + 1)); + resource = buildResource(importedPath.substring(importedPath.lastIndexOf("/") + 1, importedPath.length()), "file:/" + + importedPath.substring(0, importedPath.lastIndexOf("/") + 1)); resourceList.add(resource); - for (EObject imp : resource.eContents()) { - if (imp instanceof Import) { - Path importImportedPath = new Path( - ((Import) imp).getImportURI()); - if (importImportedPath.isAbsolute()) { - importedFIDL.add(importImportedPath.toString() - .replaceFirst( - importImportedPath.getDevice() - + "/", "")); - } else { - importImportedPath = new Path( - importedPath.substring(0, - importedPath.lastIndexOf("/")) - + "/" - + ((Import) imp).getImportURI()); + for (EObject imp : resource.eContents()) + { + if (imp instanceof Import) + { + Path importImportedPath = new Path(((Import) imp).getImportURI()); + if (importImportedPath.isAbsolute()) + { + importedFIDL.add(importImportedPath.toString().replaceFirst(importImportedPath.getDevice() + "/", "")); + } + else + { + importImportedPath = new Path(importedPath.substring(0, importedPath.lastIndexOf("/")) + "/" + + ((Import) imp).getImportURI()); importedFIDL.add(importImportedPath.toString()); } } @@ -243,117 +261,110 @@ private HashMap> buildImportList( } } } - if (hasChanged) { + if (hasChanged) + { hasChanged = false; helpMap.putAll(rekImportList); return buildImportList(helpMap); - } else { + } + else + { return rekImportList; } } - private void validateTypeCollectionName(FModel model, - ValidationMessageAcceptor messageAcceptor, IPath filePath, - FTypeCollection fTypeCollection) { - String typeCollectionName = fTypeCollection.getName(); - if(typeCollectionName != null) { - if (typeCollectionName.contains(".")) { - acceptError("Name may not contain '.'", fTypeCollection, - FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, - messageAcceptor); - } - - // since Franca 0.8.10 is released, this check is unnecessary - if (!isFrancaVersionGreaterThan(0, 8, 9)) { - if (fastAllInfo.get(typeCollectionName).get(model.getName()) - .size() > 1) { - for (String s : fastAllInfo.get(typeCollectionName).get( - model.getName())) { - if (!s.equals(filePath.toString())) { - if (importList.containsKey(s)) { - acceptError( - "Imported file " - + s - + " has interface or typeCollection with the same name and same package!", - fTypeCollection, - FrancaPackage.Literals.FMODEL_ELEMENT__NAME, - -1, messageAcceptor); - } else { - acceptWarning( - "Interface or typeCollection in file " - + s - + " has the same name and same package!", - fTypeCollection, - FrancaPackage.Literals.FMODEL_ELEMENT__NAME, - -1, messageAcceptor); - } - } - } - } - } - } + private void validateTypeCollectionName(FModel model, ValidationMessageAcceptor messageAcceptor, IPath filePath, + FTypeCollection fTypeCollection) + { + String typeCollectionName = fTypeCollection.getName(); + if (typeCollectionName != null) + { + if (typeCollectionName.contains(".")) + { + acceptError("Name may not contain '.'", fTypeCollection, FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, messageAcceptor); + } + + // since Franca 0.8.10 is released, this check is unnecessary + if (!isFrancaVersionGreaterThan(0, 8, 9)) + { + if (fastAllInfo.get(typeCollectionName).get(model.getName()).size() > 1) + { + for (String s : fastAllInfo.get(typeCollectionName).get(model.getName())) + { + if (!s.equals(filePath.toString())) + { + if (importList.containsKey(s)) + { + acceptError("Imported file " + s + " has interface or typeCollection with the same name and same package!", + fTypeCollection, FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, messageAcceptor); + } + else + { + acceptWarning("Interface or typeCollection in file " + s + " has the same name and same package!", + fTypeCollection, FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, messageAcceptor); + } + } + } + } + } + } } - private void validateTypeCollectionElements( - ValidationMessageAcceptor messageAcceptor, - FTypeCollection fTypeCollection) { - for (FType fType : fTypeCollection.getTypes()) { - if (fType instanceof FMapType) { + private void validateTypeCollectionElements(ValidationMessageAcceptor messageAcceptor, FTypeCollection fTypeCollection) + { + for (FType fType : fTypeCollection.getTypes()) + { + if (fType instanceof FMapType) + { validateMapKey((FMapType) fType, messageAcceptor); } - // don't log the good case - //acceptInfo("type collections: " + fType, messageAcceptor); - if (fType instanceof FEnumerationType) { - for (FEnumerator fEnumerator : ((FEnumerationType) fType) - .getEnumerators()) { - if (fEnumerator.getValue() != null) { + + if (fType instanceof FEnumerationType) + { + for (FEnumerator fEnumerator : ((FEnumerationType) fType).getEnumerators()) + { + if (fEnumerator.getValue() != null) + { String enumeratorValue = FrancaGeneratorExtensions.getEnumeratorValue(fEnumerator.getValue()).toLowerCase(); - validateEnumerationValue(enumeratorValue, - messageAcceptor, fEnumerator); + validateEnumerationValue(enumeratorValue, messageAcceptor, fEnumerator); } } } } } - private void validateImportedTypeCollections(FModel model, - ValidationMessageAcceptor messageAcceptor, final IFile file, - String cwd, FTypeCollection fTypeCollection) { + private void validateImportedTypeCollections(FModel model, ValidationMessageAcceptor messageAcceptor, String fileName, String cwd, + FTypeCollection fTypeCollection) + { String type = "typeCollection name"; if (fTypeCollection instanceof FInterface) type = "interface name"; - String entryKey = null; - for (Entry, ArrayList>> entry : aimBuilder.allInfo - .entrySet()) { - if(isCommandLineEnvironment) { - entryKey = path; - } else { - entryKey = cwd + "/" + file.getName(); - } - if (!entry.getKey().equals(entryKey)) { + for (Entry, ArrayList>> entry : aimBuilder.allInfo.entrySet()) + { + if (!entry.getKey().equals(cwd + "/" + fileName)) + { Triple, ArrayList> entryValue = entry.getValue(); - if (entryValue.packageName != null) { - if (entryValue.packageName.startsWith(model.getName() - + "." + fTypeCollection.getName())) { - // don't log the good case - //acceptInfo("imported type collections: " + entry, messageAcceptor); - if (importList.get(cwd + "/" + file.getName()).contains( - entry.getKey())) { - acceptError( - "Imported file's package " - + entryValue.packageName - + " may not start with package " - + model.getName() + " + " + type - + fTypeCollection.getName(), - fTypeCollection, - FrancaPackage.Literals.FMODEL_ELEMENT__NAME, - -1, messageAcceptor); - } else { - acceptWarning(entry.getKey() + ". File's package " - + entryValue.packageName - + " starts with package " + model.getName() - + " + " + type + fTypeCollection.getName(), - fTypeCollection, null, -1, messageAcceptor); + if (entryValue.packageName != null) + { + if (entryValue.packageName.startsWith(model.getName() + "." + fTypeCollection.getName())) + { + HashSet importPaths = importList.get(cwd + "/" + fileName); + if (importPaths != null) + { + if (importPaths.contains(entry.getKey())) + { + acceptError( + "Imported file's package " + entryValue.packageName + " may not start with package " + + model.getName() + " + " + type + " " + fTypeCollection.getName(), fTypeCollection, + FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, messageAcceptor); + } + else + { + acceptWarning( + "File's package " + entryValue.packageName + " starts with package " + + model.getName() + " + " + type + " " + fTypeCollection.getName(), fTypeCollection, null, -1, + messageAcceptor); + } } } } @@ -361,35 +372,36 @@ private void validateImportedTypeCollections(FModel model, } } - private void validateEnumerationValue(String enumeratorValue, - ValidationMessageAcceptor messageAcceptor, FEnumerator fEnumerator) { + private void validateEnumerationValue(String enumeratorValue, ValidationMessageAcceptor messageAcceptor, FEnumerator fEnumerator) + { String value = enumeratorValue; - if (value.length() == 0) { - acceptWarning("Missing value!", fEnumerator, - FrancaPackage.Literals.FENUMERATOR__VALUE, -1, - messageAcceptor); + if (value.length() == 0) + { + acceptWarning("Missing value!", fEnumerator, FrancaPackage.Literals.FENUMERATOR__VALUE, -1, messageAcceptor); return; } - if (value.length() == 1) { - if (48 > value.charAt(0) || value.charAt(0) > 57) { - acceptWarning("Not a valid number!", fEnumerator, - FrancaPackage.Literals.FENUMERATOR__VALUE, -1, - messageAcceptor); + if (value.length() == 1) + { + if (48 > value.charAt(0) || value.charAt(0) > 57) + { + acceptWarning("Not a valid number!", fEnumerator, FrancaPackage.Literals.FENUMERATOR__VALUE, -1, messageAcceptor); return; } } - if (value.length() > 2) { - if (value.charAt(0) == '0') { + if (value.length() > 2) + { + if (value.charAt(0) == '0') + { // binary - if (value.charAt(1) == 'b') { - for (int i = 2; i < value.length(); i++) { - if (value.charAt(i) != '0' && value.charAt(i) != '1') { - acceptWarning( - "Not a valid number! Should be binary", - fEnumerator, - FrancaPackage.Literals.FENUMERATOR__VALUE, + if (value.charAt(1) == 'b') + { + for (int i = 2; i < value.length(); i++) + { + if (value.charAt(i) != '0' && value.charAt(i) != '1') + { + acceptWarning("Not a valid number! Should be binary", fEnumerator, FrancaPackage.Literals.FENUMERATOR__VALUE, -1, messageAcceptor); return; } @@ -397,17 +409,15 @@ private void validateEnumerationValue(String enumeratorValue, return; } // hex - if (value.charAt(1) == 'x') { - for (int i = 2; i < value.length(); i++) { - if ((48 > value.charAt(i) || value - .charAt(i) > 57) - && (97 > value.charAt(i) || value - .charAt(i) > 102)) { - acceptWarning( - "Not a valid number! Should be hexadecimal", - fEnumerator, - FrancaPackage.Literals.FENUMERATOR__VALUE, - -1, messageAcceptor); + if (value.charAt(1) == 'x') + { + for (int i = 2; i < value.length(); i++) + { + if ((48 > value.charAt(i) || value.charAt(i) > 57) + && (97 > value.charAt(i) || value.charAt(i) > 102)) + { + acceptWarning("Not a valid number! Should be hexadecimal", fEnumerator, + FrancaPackage.Literals.FENUMERATOR__VALUE, -1, messageAcceptor); return; } } @@ -415,13 +425,14 @@ private void validateEnumerationValue(String enumeratorValue, } } } - if (value.charAt(0) == '0') { + if (value.charAt(0) == '0') + { // oct - for (int i = 1; i < value.length(); i++) { - if (48 > value.charAt(i) || value.charAt(i) > 55) { - acceptWarning("Not a valid number! Should be octal", - fEnumerator, - FrancaPackage.Literals.FENUMERATOR__VALUE, -1, + for (int i = 1; i < value.length(); i++) + { + if (48 > value.charAt(i) || value.charAt(i) > 55) + { + acceptWarning("Not a valid number! Should be octal", fEnumerator, FrancaPackage.Literals.FENUMERATOR__VALUE, -1, messageAcceptor); return; } @@ -429,123 +440,136 @@ private void validateEnumerationValue(String enumeratorValue, return; } // dec - for (int i = 0; i < value.length(); i++) { - if (48 > value.charAt(i) || value.charAt(i) > 57) { - acceptWarning("Not a valid number! Should be decimal", - fEnumerator, FrancaPackage.Literals.FENUMERATOR__VALUE, - -1, messageAcceptor); + for (int i = 0; i < value.length(); i++) + { + if (48 > value.charAt(i) || value.charAt(i) > 57) + { + acceptWarning("Not a valid number! Should be decimal", fEnumerator, FrancaPackage.Literals.FENUMERATOR__VALUE, -1, + messageAcceptor); return; } } } - private void validateFInterfaceElements( - ValidationMessageAcceptor messageAcceptor, FInterface fInterface) { - for (FMethod fMethod : fInterface.getMethods()) { - // don't log the good case - //acceptInfo("interface elements: " + fMethod, messageAcceptor); - for (FArgument out : fMethod.getOutArgs()) { + private void validateFInterfaceElements(ValidationMessageAcceptor messageAcceptor, FInterface fInterface) + { + for (FMethod fMethod : fInterface.getMethods()) + { + for (FArgument out : fMethod.getOutArgs()) + { validateMethodArgument(messageAcceptor, fMethod, out); } - for (FArgument in : fMethod.getInArgs()) { + for (FArgument in : fMethod.getInArgs()) + { validateMethodArgument(messageAcceptor, fMethod, in); } } } - private void validateMethodArgument( - ValidationMessageAcceptor messageAcceptor, FMethod fMethod, - FArgument arg) { - if (arg.getName().equals(fMethod.getName())) { - acceptError("Parameters cannot share name with method", arg, - FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, - messageAcceptor); + private void validateMethodArgument(ValidationMessageAcceptor messageAcceptor, FMethod fMethod, FArgument arg) + { + if (arg.getName().equals(fMethod.getName())) + { + acceptError("Parameters cannot share name with method", arg, FrancaPackage.Literals.FMODEL_ELEMENT__NAME, -1, messageAcceptor); } } - private void validateMapKey(FMapType m, - ValidationMessageAcceptor messageAcceptor) { - if (cycleDetector.hasCycle(m)) { + private void validateMapKey(FMapType m, ValidationMessageAcceptor messageAcceptor) + { + if (cycleDetector.hasCycle(m)) + { return; } FTypeRef key = m.getKeyType(); - if (isTypeAcceptableAsMapKey(key)) { + if (isTypeAcceptableAsMapKey(key)) + { return; } - while (key.getDerived() instanceof FTypeDef) { + while (key.getDerived() instanceof FTypeDef) + { key = ((FTypeDef) key.getDerived()).getActualType(); - if (isTypeAcceptableAsMapKey(key)) { + if (isTypeAcceptableAsMapKey(key)) + { return; } } - acceptError("Key type has to be an primitive type!", m, - FrancaPackage.Literals.FMAP_TYPE__KEY_TYPE, -1, messageAcceptor); + acceptError("Key type has to be an primitive type!", m, FrancaPackage.Literals.FMAP_TYPE__KEY_TYPE, -1, messageAcceptor); } - private boolean isTypeAcceptableAsMapKey(FTypeRef typeRef) { + private boolean isTypeAcceptableAsMapKey(FTypeRef typeRef) + { boolean accepted = false; - if (!typeRef.getPredefined().toString().equals("undefined")) { + if (!typeRef.getPredefined().toString().equals("undefined")) + { accepted = true; // basic types are ok - } else if (typeRef.getDerived() instanceof FEnumerationType) { + } + else if (typeRef.getDerived() instanceof FEnumerationType) + { accepted = true; // enums are also ok } return accepted; } - protected boolean isWholeWorkspaceCheckActive() { + protected boolean isWholeWorkspaceCheckActive() + { return false; } - private boolean isFrancaVersionGreaterThan(int major, int minor, int micro) { - Version francaVersion = ((BundleReference) FArgument.class - .getClassLoader()).getBundle().getVersion(); - if (francaVersion.getMajor() > major) { + private boolean isFrancaVersionGreaterThan(int major, int minor, int micro) + { + Version francaVersion = ((BundleReference) FArgument.class.getClassLoader()).getBundle().getVersion(); + if (francaVersion.getMajor() > major) + { return true; } - if (francaVersion.getMajor() < major){ + if (francaVersion.getMajor() < major) + { return false; } - if (francaVersion.getMinor() > minor) { + if (francaVersion.getMinor() > minor) + { return true; } - if (francaVersion.getMinor() < minor){ + if (francaVersion.getMinor() < minor) + { return false; } - if (francaVersion.getMicro() > micro) { + if (francaVersion.getMicro() > micro) + { return true; } - if (francaVersion.getMicro() < micro) { + if (francaVersion.getMicro() < micro) + { return false; } return false; } - public boolean isValidatorEnabled() { - return true; + public boolean isValidatorEnabled() + { + return true; } - private void acceptError(String message, EObject object, - EStructuralFeature feature, int index, - ValidationMessageAcceptor messageAcceptor) { - messageAcceptor.acceptError("DBus validation: " + message, object, - feature, index, null); + private void acceptError(String message, EObject object, EStructuralFeature feature, int index, + ValidationMessageAcceptor messageAcceptor) + { + messageAcceptor.acceptError("DBus validation: " + message, object, feature, index, null); } - private void acceptWarning(String message, EObject object, - EStructuralFeature feature, int index, - ValidationMessageAcceptor messageAcceptor) { - messageAcceptor.acceptWarning("DBus validation: " + message, object, - feature, index, null); + private void acceptWarning(String message, EObject object, EStructuralFeature feature, int index, + ValidationMessageAcceptor messageAcceptor) + { + messageAcceptor.acceptWarning("DBus validation: " + message, object, feature, index, null); } - protected void acceptInfo(String message, ValidationMessageAcceptor messageAcceptor) { + protected void acceptInfo(String message, ValidationMessageAcceptor messageAcceptor) + { messageAcceptor.acceptInfo(message, null, null, 0, null); } } -