diff options
author | muhammad.m.alam2 | 2022-07-27 21:11:43 +0000 |
---|---|---|
committer | Murshed Alam | 2022-09-21 18:24:06 +0000 |
commit | b239ebab6848d654fa2f8b28476431c2fa224b05 (patch) | |
tree | aae8733f9923ff992ab7e8bf5289748296fc013b | |
parent | af92ce46b757bd7b89680c998ac7b9dabf91e9c4 (diff) | |
download | org.eclipse.osee-b239ebab6848d654fa2f8b28476431c2fa224b05.tar.gz org.eclipse.osee-b239ebab6848d654fa2f8b28476431c2fa224b05.tar.xz org.eclipse.osee-b239ebab6848d654fa2f8b28476431c2fa224b05.zip |
feature[TW20783]: BAT - Resolve potentially mismatching features and configuration tags
Change-Id: I9deb0400ca7ecf84cdf7f714ecd07103ec1e883d
2 files changed, 101 insertions, 16 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/applicability/BatFileProcessor.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/applicability/BatFileProcessor.java index 129e7193e74..332ecb3ed57 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/applicability/BatFileProcessor.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/applicability/BatFileProcessor.java @@ -94,6 +94,9 @@ public class BatFileProcessor { String endConfig = matcher.group(BlockApplicabilityOps.endConfigCommentMatcherGroup); String beginConfigGrp = matcher.group(BlockApplicabilityOps.beginConfigGrpCommentMatcherGroup); String endConfigGrp = matcher.group(BlockApplicabilityOps.endConfigGrpCommentMatcherGroup); + String featureElse = matcher.group(BlockApplicabilityOps.featureElseCommentMatcherGroup); + String configureElse = matcher.group(BlockApplicabilityOps.configureElseCommentMatcherGroup); + String configureGroupElse = matcher.group(BlockApplicabilityOps.configureGroupElseCommentMatcherGroup); if (beginFeature != null) { applicabilityType = ApplicabilityType.Feature; @@ -102,46 +105,52 @@ public class BatFileProcessor { } else if (beginConfig != null) { applicabilityExpression = matcher.group(BlockApplicabilityOps.beginConfigTagMatcherGroup); applicabilityType = ApplicabilityType.Configuration; + if (beginConfig.contains("Not")) { applicabilityType = ApplicabilityType.NotConfiguration; } - matcherIndex = startApplicabilityBlock(applicabilityType, matcher, beginConfigGrp, applicabilityExpression); + matcherIndex = startApplicabilityBlock(applicabilityType, matcher, beginConfig, applicabilityExpression); } else if (beginConfigGrp != null) { applicabilityExpression = matcher.group(BlockApplicabilityOps.beginConfigGrpTagMatcherGroup); applicabilityType = ApplicabilityType.ConfigurationGroup; + if (beginConfigGrp.contains("Not")) { applicabilityType = ApplicabilityType.NotConfigurationGroup; } matcherIndex = startApplicabilityBlock(applicabilityType, matcher, beginConfigGrp, applicabilityExpression); + } else if (featureElse != null) { + checkForMismatchTags(inFile, endFeature, endConfig, endConfigGrp, featureElse, configureElse, + configureGroupElse); + matcherIndex = matcher.end(); + } else if (configureElse != null) { + checkForMismatchTags(inFile, endFeature, endConfig, endConfigGrp, featureElse, configureElse, + configureGroupElse); + matcherIndex = matcher.end(); + } else if (configureGroupElse != null) { + checkForMismatchTags(inFile, endFeature, endConfig, endConfigGrp, featureElse, configureElse, + configureGroupElse); + matcherIndex = matcher.end(); } else if (endFeature != null || endConfig != null || endConfigGrp != null) { - if (applicBlocks.isEmpty()) { - OseeLog.log(getClass(), Level.INFO, - "BatFileProcessor::applyApplicabilityContent => An Applicability End tag was found before a beginning tag for: " + inFile.getPath()); - results.warningf("An Applicability End tag was found before a beginning tag for %s\n", inFile.getPath()); - tagProcessed = false; - return fileContent; - } + checkForMismatchTags(inFile, endFeature, endConfig, endConfigGrp, featureElse, configureElse, + configureGroupElse); ApplicabilityBlock applicBlock = finishApplicabilityBlock(toReturn, matcher); String toReplace = toReturn.substring(applicBlock.getStartInsertIndex(), applicBlock.getEndInsertIndex()); toReturn = toReturn.replace(toReplace, applicBlock.getInsideText()); matcherIndex = applicBlock.getStartInsertIndex() + applicBlock.getInsideText().length(); matcher = fileTypeApplicabilityData.getCommentedTagPattern().matcher(toReturn); - tagProcessed = true; } else { OseeLog.log(getClass(), Level.INFO, "BatFileProcessor::applyApplicabilityContent => Did not find a start or end feature tag for: " + inFile.getPath()); - results.warningf("Did not find a start or end feature tag for %s but a similar tag was matched\n", - inFile.getPath()); - tagProcessed = false; - return fileContent; + throw new TagNotPlacedCorrectlyException("Tag was not placed correctly in file: " + inFile.getPath()); } } + if (!applicBlocks.isEmpty()) { throw new TagNotPlacedCorrectlyException("Tag was not placed correctly in file: " + inFile.getPath()); } - results.logf("BatFileProcessor::applyApplicabilityContent => Completed for file %s and tagProcessed = %s\n", - inFile.getPath(), tagProcessed); + OseeLog.log(getClass(), Level.INFO, + "BatFileProcessor::applyApplicabilityContent => Completed for file: " + inFile.getPath() + "and tagProcessed = " + tagProcessed); return CharBuffer.wrap(toReturn.toCharArray()); } @@ -155,6 +164,63 @@ public class BatFileProcessor { return matcher.end(); } + private void checkForMismatchTags(File inFile, String endFeature, String endConfig, String endConfigGrp, String featureElse, String configureElse, String configureGroupElse) throws TagNotPlacedCorrectlyException { + if (applicBlocks.isEmpty()) { + if (featureElse != null) { + OseeLog.log(getClass(), Level.INFO, + "BatFileProcessor::applyApplicabilityContent => Else Feature tag was not placed correctly in file: " + inFile.getPath()); + throw new TagNotPlacedCorrectlyException( + "Else Feature tag was not placed correctly in file: " + inFile.getPath()); + + } else if (configureElse != null) { + OseeLog.log(getClass(), Level.INFO, + "BatFileProcessor::applyApplicabilityContent => Else Configure tag was not placed correctly in file: " + inFile.getPath()); + throw new TagNotPlacedCorrectlyException( + "Else Configure tag was not placed correctly in file: " + inFile.getPath()); + + } else if (configureGroupElse != null) { + OseeLog.log(getClass(), Level.INFO, + "BatFileProcessor::applyApplicabilityContent => Else Configure Group tag was not placed correctly in file: " + inFile.getPath()); + throw new TagNotPlacedCorrectlyException( + "Else Configure Group tag was not placed correctly in file: " + inFile.getPath()); + + } else { + OseeLog.log(getClass(), Level.INFO, + "BatFileProcessor::applyApplicabilityContent => Applicability tag was not placed correctly in file: " + inFile.getPath()); + throw new TagNotPlacedCorrectlyException( + "Applicability tag was not placed correctly in file: " + inFile.getPath()); + } + } else if ((endFeature != null) || (featureElse != null)) { + if (applicBlocks.peek().getType() != ApplicabilityType.Feature) { + throw new TagNotPlacedCorrectlyException( + "Feature or Feature Else tag was not placed correctly in file: " + inFile.getPath()); + } + } else if ((endConfig != null) || (configureElse != null)) { + if (applicBlocks.peek().getBeginTag().contains("Not")) { + if (applicBlocks.peek().getType() != ApplicabilityType.NotConfiguration) { + throw new TagNotPlacedCorrectlyException( + "Config Not or Config Else tag was not placed correctly in file: " + inFile.getPath()); + } + + } else if (applicBlocks.peek().getType() != ApplicabilityType.Configuration) { + throw new TagNotPlacedCorrectlyException( + "Config or Config Else tag was not placed correctly in file: " + inFile.getPath()); + } + + } else if ((endConfigGrp != null) || (configureGroupElse != null)) { + if (applicBlocks.peek().getBeginTag().contains("Not")) { + if (applicBlocks.peek().getType() != ApplicabilityType.NotConfigurationGroup) { + throw new TagNotPlacedCorrectlyException( + "Config Group Not or Config Group Else tag was not placed correctly in file: " + inFile.getPath()); + } + + } else if (applicBlocks.peek().getType() != ApplicabilityType.ConfigurationGroup) { + throw new TagNotPlacedCorrectlyException( + "Config Group or Config Group Else tag was not placed correctly in file: " + inFile.getPath()); + } + } + } + private ApplicabilityBlock finishApplicabilityBlock(String toReturn, Matcher matcher) throws IOException { ApplicabilityBlock applicBlock = applicBlocks.pop(); applicBlock.setEndTextIndex(matcher.start()); diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/applicability/BlockApplicabilityOps.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/applicability/BlockApplicabilityOps.java index b7e5a2bb7d9..13ff55fa937 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/applicability/BlockApplicabilityOps.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/applicability/BlockApplicabilityOps.java @@ -78,6 +78,9 @@ public class BlockApplicabilityOps { public static final String ENDCONFIG = " ?(End Configuration(?!Group) ?((\\[.*?\\]))?) ?"; public static final String BEGINCONFIGGRP = " ?(ConfigurationGroup( Not)? ?(\\[(.*?)\\])) ?"; public static final String ENDCONFIGGRP = " ?(End ConfigurationGroup ?((\\[.*?\\]))?) ?"; + public static final String FEATURE_ELSE = " ?(Feature Else ?((\\[.*?\\]))?) ?"; + public static final String CONFIGURE_ELSE = " ?(Configuration Else ?((\\[.*?\\]))?) ?"; + public static final String CONFIGURE_GROUP_ELSE = " ?(ConfigurationGroup Else ?((\\[.*?\\]))?) ?"; public static final String COMMENT_EXTRA_CHARS = INLINE_WHITESPACE + "(" + SINGLE_NEW_LINE + ")?"; public static final String ELSE = @@ -99,6 +102,15 @@ public class BlockApplicabilityOps { public static final int endConfigGrpCommentMatcherGroup = 28; public static final int endConfigGrpTagMatcherGroup = 29; + public static final int featureElseCommentMatcherGroup = 33; + public static final int featureElseTagMatcherGroup = 34; + + public static final int configureElseCommentMatcherGroup = 38; + public static final int configureElseTagMatcherGroup = 39; + + public static final int configureGroupElseCommentMatcherGroup = 43; + public static final int configureGroupElseTagMatcherGroup = 44; + private final OrcsApi orcsApi; private final Log logger; private final ScriptEngine se; @@ -689,8 +701,15 @@ public class BlockApplicabilityOps { "(" + INLINE_WHITESPACE + commentPrefix + BEGINCONFIGGRP + INLINE_WHITESPACE + commentSuffix + COMMENT_EXTRA_CHARS + ")"; String commentedConfigGrpEnd = "(" + INLINE_WHITESPACE + commentPrefix + ENDCONFIGGRP + INLINE_WHITESPACE + commentSuffix + COMMENT_EXTRA_CHARS + ")"; + String commentedFeatureElse = + "(" + INLINE_WHITESPACE + commentPrefix + FEATURE_ELSE + INLINE_WHITESPACE + commentSuffix + COMMENT_EXTRA_CHARS + ")"; + String commentedConfigureElse = + "(" + INLINE_WHITESPACE + commentPrefix + CONFIGURE_ELSE + INLINE_WHITESPACE + commentSuffix + COMMENT_EXTRA_CHARS + ")"; + String commentedConfigureGroupElse = + "(" + INLINE_WHITESPACE + commentPrefix + CONFIGURE_GROUP_ELSE + INLINE_WHITESPACE + commentSuffix + COMMENT_EXTRA_CHARS + ")"; + String pattern = - commentedFeatureStart + "|" + commentedFeatureEnd + "|" + commentedConfigStart + "|" + commentedConfigEnd + "|" + commentedConfigGrpStart + "|" + commentedConfigGrpEnd; + commentedFeatureStart + "|" + commentedFeatureEnd + "|" + commentedConfigStart + "|" + commentedConfigEnd + "|" + commentedConfigGrpStart + "|" + commentedConfigGrpEnd + "|" + commentedFeatureElse + "|" + commentedConfigureElse + "|" + commentedConfigureGroupElse; return Pattern.compile(pattern, Pattern.DOTALL | Pattern.MULTILINE); } }
\ No newline at end of file |