Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrrader2014-09-16 23:03:12 +0000
committerRoberto E. Escobar2014-10-01 21:05:05 +0000
commit075843a03f472b82181db5a187e592b6313235ab (patch)
tree86edf6af821043684bb5b738a4dc63696a38b360
parentfe23377ff9e7c6fcacc62550aa059cd777cf2d73 (diff)
downloadorg.eclipse.osee-075843a03f472b82181db5a187e592b6313235ab.tar.gz
org.eclipse.osee-075843a03f472b82181db5a187e592b6313235ab.tar.xz
org.eclipse.osee-075843a03f472b82181db5a187e592b6313235ab.zip
feature[ats_ATS98067]: Create CodeUnitTagger to add GUID to .ada files
Change-Id: I081a56babc834d090b568f61beae0a2b1988127e Signed-off-by: rrader <ryan.rader@boeing.com>
-rw-r--r--plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/traceability/CodeUnitAnnotationUtilityTest.java76
-rw-r--r--plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/traceability/TraceabilityTestSuite.java2
-rw-r--r--plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/AbstractSourceTagger.java13
-rw-r--r--plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/CodeUnitTagger.java71
-rw-r--r--plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/TestUnitTagger.java11
-rw-r--r--plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/TraceUnitToArtifactProcessor.java3
6 files changed, 164 insertions, 12 deletions
diff --git a/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/traceability/CodeUnitAnnotationUtilityTest.java b/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/traceability/CodeUnitAnnotationUtilityTest.java
new file mode 100644
index 00000000000..6b45f145d6b
--- /dev/null
+++ b/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/traceability/CodeUnitAnnotationUtilityTest.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.define.traceability;
+
+import java.nio.CharBuffer;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Ryan Rader
+ */
+public class CodeUnitAnnotationUtilityTest {
+
+ private CharBuffer getClassNoAnnotation() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("\n");
+ sb.append("\n");
+ sb.append("-- Proprietary header ends------------------------------------------------------");
+ sb.append("\n");
+ return CharBuffer.wrap(sb.toString());
+ }
+
+ private CharBuffer getClassWithAnnotation() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("\n");
+ sb.append("\n");
+ sb.append("-- Proprietary header ends------------------------------------------------------");
+ sb.append("\n");
+ sb.append("-- ObjectId(\"TEST\")\n");
+ return CharBuffer.wrap(sb.toString());
+ }
+
+ @Test
+ public void testGetTraceAnnotationGuid() {
+ CodeUnitTagger util = CodeUnitTagger.getInstance();
+ // Check that getSourceTag returns null when there is no ObjectId
+ String guid = util.getSourceTag(getClassNoAnnotation());
+ Assert.assertNull(guid);
+
+ // Check that getSourceTag returns 'TEST' when there is an ObjectId = TEST
+ guid = util.getSourceTag(getClassWithAnnotation());
+ Assert.assertEquals("TEST", guid);
+ }
+
+ @Test
+ public void testAddTraceAnnotation() {
+ CodeUnitTagger util = CodeUnitTagger.getInstance();
+ // Check that addSourceTag returns ObjectId("TEST") when it adds an objectId
+ String result = util.addSourceTag(getClassNoAnnotation(), "TEST").toString();
+ Assert.assertTrue(result.contains("-- ObjectId(\"TEST\")"));
+
+ // Check that addSourceTag overwrites TEST with GUID
+ result = util.addSourceTag(getClassWithAnnotation(), "GUID").toString();
+ Assert.assertTrue(result.contains("-- ObjectId(\"GUID\")"));
+ Assert.assertFalse(result.contains("-- ObjectId(\"TEST\")"));
+ }
+
+ @Test
+ public void testRemoveTraceAnnotation() {
+ CodeUnitTagger util = CodeUnitTagger.getInstance();
+ // Check that removeSourceTag doesn't add in ObjectId("TEST") if it wasnt there to begin with
+ String result = util.removeSourceTag(getClassNoAnnotation()).toString();
+ Assert.assertFalse(result.contains("-- ObjectId(\"TEST\")"));
+ // Check that removeSourceTag returns ObjectId("TEST") is no longer there
+ result = util.removeSourceTag(getClassWithAnnotation()).toString();
+ Assert.assertFalse(result.contains("-- ObjectId(\"TEST\")"));
+ }
+}
diff --git a/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/traceability/TraceabilityTestSuite.java b/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/traceability/TraceabilityTestSuite.java
index 0ae28f270a6..db6013da7fc 100644
--- a/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/traceability/TraceabilityTestSuite.java
+++ b/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/traceability/TraceabilityTestSuite.java
@@ -14,7 +14,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
-@Suite.SuiteClasses({TestUnitAnnotationUtilityTest.class})
+@Suite.SuiteClasses({TestUnitAnnotationUtilityTest.class, CodeUnitAnnotationUtilityTest.class})
/**
* @author John R. Misinco
*/
diff --git a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/AbstractSourceTagger.java b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/AbstractSourceTagger.java
index c4376b13770..9d409a85057 100644
--- a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/AbstractSourceTagger.java
+++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/AbstractSourceTagger.java
@@ -14,6 +14,8 @@ import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.CharBuffer;
+import java.util.regex.Matcher;
+import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet;
import org.eclipse.osee.framework.jdk.core.util.Lib;
/**
@@ -47,4 +49,15 @@ public abstract class AbstractSourceTagger {
}
}
+ public CharBuffer removeMatches(CharBuffer buffer, Matcher matcher) {
+ CharBuffer copy = buffer.duplicate();
+ matcher.reset(copy);
+ if (matcher.find()) {
+ ChangeSet changeSet = new ChangeSet(copy);
+ changeSet.delete(matcher.start(), matcher.end() + 1);
+ copy = CharBuffer.wrap(changeSet.applyChangesToSelf().toString().toCharArray());
+ }
+ return copy;
+ }
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/CodeUnitTagger.java b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/CodeUnitTagger.java
new file mode 100644
index 00000000000..083e912fa2f
--- /dev/null
+++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/CodeUnitTagger.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.define.traceability;
+
+import java.nio.CharBuffer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet;
+
+/**
+ * @author Ryan Rader
+ */
+public class CodeUnitTagger extends AbstractSourceTagger {
+
+ private static final String ANNOTATION_STRING = "-- ObjectId(\"%s\")\n";
+
+ private static final Pattern annotationPattern = Pattern.compile("-- ObjectId\\s*\\(\"(.*?)\"\\s*\\)");
+ private static final Pattern importBlockPattern = Pattern.compile("(Proprietary header ends.*\\n)");
+
+ private final Matcher annotationMatcher;
+ private final Matcher importBlockMatcher;
+
+ private static final CodeUnitTagger instance = new CodeUnitTagger();
+
+ private CodeUnitTagger() {
+ annotationMatcher = annotationPattern.matcher("");
+ importBlockMatcher = importBlockPattern.matcher("");
+ }
+
+ public static CodeUnitTagger getInstance() {
+ return instance;
+ }
+
+ @Override
+ public String getSourceTag(CharBuffer buffer) {
+ String toReturn = null;
+ annotationMatcher.reset(buffer);
+ if (annotationMatcher.find()) {
+ toReturn = annotationMatcher.group(1);
+ }
+ return toReturn;
+ }
+
+ @Override
+ public CharBuffer addSourceTag(CharBuffer buffer, String guid) {
+ buffer = removeSourceTag(buffer);
+ importBlockMatcher.reset(buffer);
+ if (importBlockMatcher.find()) {
+ int stop = importBlockMatcher.end();
+ ChangeSet changeSet = new ChangeSet(buffer);
+ changeSet.replace(stop, stop, String.format(ANNOTATION_STRING, guid));
+ return CharBuffer.wrap(changeSet.applyChangesToSelf().toString().toCharArray());
+ }
+ return buffer;
+ }
+
+ @Override
+ public CharBuffer removeSourceTag(CharBuffer buffer) {
+ buffer = removeMatches(buffer, annotationMatcher);
+ return buffer;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/TestUnitTagger.java b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/TestUnitTagger.java
index cd48e9eaf90..929fac88f49 100644
--- a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/TestUnitTagger.java
+++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/TestUnitTagger.java
@@ -90,17 +90,6 @@ public class TestUnitTagger extends AbstractSourceTagger {
return buffer;
}
- private CharBuffer removeMatches(CharBuffer buffer, Matcher matcher) {
- CharBuffer copy = buffer.duplicate();
- matcher.reset(copy);
- if (matcher.find()) {
- ChangeSet changeSet = new ChangeSet(copy);
- changeSet.delete(matcher.start(), matcher.end() + 1);
- copy = CharBuffer.wrap(changeSet.applyChangesToSelf().toString().toCharArray());
- }
- return copy;
- }
-
@Override
public CharBuffer removeSourceTag(CharBuffer buffer) {
buffer = removeMatches(buffer, importMatcher);
diff --git a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/TraceUnitToArtifactProcessor.java b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/TraceUnitToArtifactProcessor.java
index 108467baa0a..9dea2632fe1 100644
--- a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/TraceUnitToArtifactProcessor.java
+++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/traceability/operations/TraceUnitToArtifactProcessor.java
@@ -24,6 +24,7 @@ import org.eclipse.nebula.widgets.xviewer.XViewerColumn;
import org.eclipse.nebula.widgets.xviewer.XViewerColumn.SortDataType;
import org.eclipse.osee.define.internal.Activator;
import org.eclipse.osee.define.traceability.AbstractSourceTagger;
+import org.eclipse.osee.define.traceability.CodeUnitTagger;
import org.eclipse.osee.define.traceability.HierarchyHandler;
import org.eclipse.osee.define.traceability.TestUnitTagger;
import org.eclipse.osee.define.traceability.TraceabilityExtractor;
@@ -133,6 +134,8 @@ public class TraceUnitToArtifactProcessor implements ITraceUnitProcessor {
private AbstractSourceTagger getGuidUtility(IArtifactType artifactType) {
if (artifactType.equals(CoreArtifactTypes.TestCase)) {
return TestUnitTagger.getInstance();
+ } else if (artifactType.equals(CoreArtifactTypes.CodeUnit)) {
+ return CodeUnitTagger.getInstance();
}
return null;
}

Back to the top