Skip to content

Commit

Permalink
Merge pull request #1 from CloudSlang/enhancement
Browse files Browse the repository at this point in the history
Enhance metadata validation
  • Loading branch information
lucian-cm committed Jan 31, 2017
2 parents c7a6c0a + dd5fdec commit ce0be04
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 25 deletions.
Binary file not shown.
Binary file not shown.
Binary file removed lib/cloudslang-spi-1.0.2.jar
Binary file not shown.
Binary file added lib/cloudslang-spi-1.0.3.jar
Binary file not shown.
Binary file modified screenshots/syntax_highlighting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 38 additions & 21 deletions src/io/cloudslang/intellij/lang/annotator/ExecutableAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,17 @@
import com.intellij.psi.PsiFile;
import io.cloudslang.intellij.lang.dependencies.CloudSlangDependenciesProvider;
import io.cloudslang.intellij.lang.exceptions.LocatedRuntimeException;
import io.cloudslang.lang.compiler.MetadataExtractor;
import io.cloudslang.lang.compiler.SlangCompiler;
import io.cloudslang.lang.compiler.SlangSource;
import io.cloudslang.lang.compiler.modeller.SlangModeller;
import io.cloudslang.lang.compiler.modeller.result.ExecutableModellingResult;
import io.cloudslang.lang.compiler.modeller.result.MetadataModellingResult;
import io.cloudslang.lang.compiler.modeller.result.ModellingResult;
import io.cloudslang.lang.compiler.modeller.result.ParseModellingResult;
import io.cloudslang.lang.compiler.modeller.result.SystemPropertyModellingResult;
import io.cloudslang.lang.compiler.parser.YamlParser;
import io.cloudslang.lang.compiler.parser.model.ParsedSlang;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
Expand All @@ -55,6 +46,17 @@
import org.jetbrains.yaml.psi.YAMLValue;
import org.jetbrains.yaml.psi.impl.YAMLBlockMappingImpl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static io.cloudslang.intellij.lang.CloudSlangFileUtils.isCloudSlangFile;
import static io.cloudslang.intellij.lang.CloudSlangFileUtils.isCloudSlangSystemPropertiesFile;
Expand All @@ -80,38 +82,53 @@ public class ExecutableAnnotator extends ExternalAnnotator<ModellingResult, List
@Nullable
@Override
public ModellingResult collectInformation(@NotNull PsiFile file) {
MetadataExtractor metadataExtractor = provider.metadataExtractor();
if (isCloudSlangSystemPropertiesFile(file.getName())) {
SlangCompiler slangCompiler = provider.slangCompiler();

YAMLFile yamlFile = (YAMLFile) file;
SlangSource slangSource = new SlangSource(yamlFile.getText(), yamlFile.getName());
MetadataModellingResult metadataModellingResult = metadataExtractor.extractMetadataModellingResult(slangSource, true);
SystemPropertyModellingResult modellingResult = slangCompiler.loadSystemPropertiesFromSource(slangSource);
if (!modellingResult.getErrors().isEmpty()) {
List<RuntimeException> runtimeExceptions = modellingResult.getErrors()
.stream()
.map(this::transformMessageToExceptionList)
.flatMap(List::stream)
.collect(toList());
return new ExecutableModellingResult(null, runtimeExceptions);
}

List<RuntimeException> runtimeExceptions = mergeModellingResults(metadataModellingResult, modellingResult);
return new ExecutableModellingResult(null, runtimeExceptions);
} else if (isCloudSlangFile(file)) {
YamlParser yamlParser = provider.yamlParser();
SlangModeller slangModeller = provider.slangModeller();
YAMLFile yamlFile = (YAMLFile) file;

SlangSource slangSource = new SlangSource(yamlFile.getText(), yamlFile.getName());
try {
MetadataModellingResult metadataModellingResult = metadataExtractor.extractMetadataModellingResult(slangSource, true);
ParsedSlang parsedSlang = yamlParser.parse(slangSource);
ParseModellingResult parseModellingResult = yamlParser.validate(parsedSlang);
return slangModeller.createModel(parseModellingResult);
ExecutableModellingResult modellingResult = slangModeller.createModel(parseModellingResult);
List<RuntimeException> runtimeExceptions = mergeModellingResults(metadataModellingResult, modellingResult);
return new ExecutableModellingResult(null, runtimeExceptions);
} catch (RuntimeException e) {
return processExceptionToModellingResult(e);
}
}
return null;
}

private List<RuntimeException> mergeModellingResults(ModellingResult result1, ModellingResult result2) {
List<RuntimeException> runtimeExceptions = new ArrayList<>();

runtimeExceptions.addAll(getExceptionsFromResult(result2));
runtimeExceptions.addAll(getExceptionsFromResult(result1));

return runtimeExceptions;
}

private List<RuntimeException> getExceptionsFromResult(ModellingResult result1) {
return result1.getErrors()
.stream()
.map(this::transformMessageToExceptionList)
.flatMap(List::stream)
.collect(toList());
}

@NotNull
private ModellingResult processExceptionToModellingResult(RuntimeException e) {
final List<RuntimeException> runtimeExceptions = transformMessageToExceptionList(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import io.cloudslang.lang.compiler.modeller.transformers.WorkFlowTransformer;
import io.cloudslang.lang.compiler.parser.MetadataParser;
import io.cloudslang.lang.compiler.parser.YamlParser;
import io.cloudslang.lang.compiler.parser.utils.MetadataValidator;
import io.cloudslang.lang.compiler.parser.utils.MetadataValidatorImpl;
import io.cloudslang.lang.compiler.parser.utils.ParserExceptionHandler;
import io.cloudslang.lang.compiler.scorecompiler.ExecutionPlanBuilder;
import io.cloudslang.lang.compiler.scorecompiler.ExecutionStepFactory;
Expand Down Expand Up @@ -147,11 +149,16 @@ public DependencyFormatValidator dependencyFormatValidator() {

public MetadataExtractor metadataExtractor() {
MetadataExtractorImpl metadataExtractor = new MetadataExtractorImpl();
metadataExtractor.setMetadataValidator(metadataValidator());
metadataExtractor.setMetadataModeller(metadataModeller());
metadataExtractor.setMetadataParser(metadataParser());
return metadataExtractor;
}

public MetadataValidator metadataValidator() {
return new MetadataValidatorImpl();
}


public MetadataParser metadataParser() {
MetadataParser metadataParser = new MetadataParser();
Expand Down
8 changes: 4 additions & 4 deletions src/io/cloudslang/intellij/lang/templates/CloudSlang.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<templateSet group="CloudSlang">
<template name="operation" value="####################################################&#10;#!!&#10;#! @description: $operation_description$&#10;#!&#10;#! @input $input_1_name$: $standard_description$&#10;#! @input $input_2_name$: $standard_description$&#10;#! @output $output_name$: $standard_description$&#10;#! @result $result_1_name$: $result_1_description$&#10;#! @result $result_2_name$: $result_2_description$&#10;#!!#&#10;####################################################&#10;&#10;namespace: $namespace$&#10;&#10;operation:&#10; name: $operation_name$&#10;&#10; inputs:&#10; - $input_1$&#10; - $input_2$&#10;&#10; java_action:&#10; gav: '$group$:$artifact$:$version$'&#10; class_name: $class$&#10; method_name: $method$&#10;&#10; outputs:&#10; - $output$&#10;&#10; results:&#10; - $result_1$: ${$success_condition$}&#10; - $result_2$" description="CloudSlang Template" toReformat="false" toShortenFQNames="true">
<template name="operation" value="########################################################################################################################&#10;#!!&#10;#! @description: $operation_description$&#10;#!&#10;#! @input $input_1_name$: $standard_description$&#10;#! @input $input_2_name$: $standard_description$&#10;#! @output $output_name$: $standard_description$&#10;#! @result $result_1_name$: $result_1_description$&#10;#! @result $result_2_name$: $result_2_description$&#10;#!!#&#10;########################################################################################################################&#10;&#10;namespace: $namespace$&#10;&#10;operation:&#10; name: $operation_name$&#10;&#10; inputs:&#10; - $input_1$&#10; - $input_2$&#10;&#10; java_action:&#10; gav: '$group$:$artifact$:$version$'&#10; class_name: $class$&#10; method_name: $method$&#10;&#10; outputs:&#10; - $output$&#10;&#10; results:&#10; - $result_1$: ${$success_condition$}&#10; - $result_2$" description="CloudSlang Template" toReformat="false" toShortenFQNames="true">
<variable name="namespace" expression="relativePathToProject" defaultValue="" alwaysStopAt="true" />
<variable name="input_1" expression="" defaultValue="&quot;input_1&quot;" alwaysStopAt="true" />
<variable name="input_2" expression="" defaultValue="&quot;input_2&quot;" alwaysStopAt="true" />
Expand Down Expand Up @@ -49,7 +49,7 @@
<variable name="result_1_name" expression="result_1" defaultValue="" alwaysStopAt="false" />
<variable name="result_2_name" expression="result_2" defaultValue="" alwaysStopAt="false" />
<variable name="result_1_description" expression="" defaultValue="&quot;Flow completed successfully.&quot;" alwaysStopAt="false" />
<variable name="result_2_description" expression="" defaultValue="&quot;Failure occured during execution.&quot;" alwaysStopAt="false" />
<variable name="result_2_description" expression="" defaultValue="&quot;Failure occurred during execution.&quot;" alwaysStopAt="false" />
<variable name="standard_description" expression="" defaultValue="&quot;Generated description&quot;" alwaysStopAt="false" />
<variable name="flow_description" expression="" defaultValue="&quot;Generated flow description&quot;" alwaysStopAt="false" />
<context>
Expand Down Expand Up @@ -169,8 +169,8 @@
<option name="CloudSlang" value="true" />
</context>
</template>
<template name="required" value="required: $default_requierd$" description="CloudSlang Template" toReformat="false" toShortenFQNames="true">
<variable name="default_requierd" expression="" defaultValue="&quot;false&quot;" alwaysStopAt="true" />
<template name="required" value="required: $default_required$" description="CloudSlang Template" toReformat="false" toShortenFQNames="true">
<variable name="default_required" expression="" defaultValue="&quot;false&quot;" alwaysStopAt="true" />
<context>
<option name="CloudSlang" value="true" />
</context>
Expand Down

0 comments on commit ce0be04

Please sign in to comment.