Enhancing STC and scenarios.

Change-Id: I1227e68f8a44707f671b09dcd2967b580e14ca79
diff --git a/tools/test/scenarios/archetypes.xml b/tools/test/scenarios/archetypes.xml
index 42c4ffb..f83879c 100644
--- a/tools/test/scenarios/archetypes.xml
+++ b/tools/test/scenarios/archetypes.xml
@@ -18,28 +18,28 @@
         <step name="Clean-Up" cwd="${WORKSPACE}/tmp" env="~"
               exec="rm -r test-app"/>
 
-        <step name="Create-App" cwd="${WORKSPACE}/tmp" requires="Clean-Up"
+        <step name="Create-App" cwd="${WORKSPACE}/tmp" requires="^"
               exec="onos-create-app app org.test.app test-app 1.2.3 org.test.app -DinteractiveMode=false"/>
         <step name="Build-App" requires="Create-App" exec="mvn clean install"/>
-        <step name="Install-App" requires="Build-App"
+        <step name="Install-App" requires="^"
               exec="onos-app ${OCI} install! target/test-app-1.2.3.oar"/>
-        <step name="Verify-App" requires="Install-App"
+        <step name="Verify-App" requires="^"
               exec="onos-check-components ${OCI} org.test.app.AppComponent"/>
 
         <step name="Create-App-CLI-Overlay" requires="Install-App"
               exec="onos-create-app cli org.test.app test-app 1.2.3 org.test.app -DinteractiveMode=false"/>
-        <step name="Build-App-With-CLI" requires="Create-App-CLI-Overlay"
+        <step name="Build-App-With-CLI" requires="^"
               exec="mvn clean install"/>
-        <step name="Reinstall-App-With-CLI" requires="Build-App-With-CLI,-Verify-App"
+        <step name="Reinstall-App-With-CLI" requires="^,~Verify-App"
               exec="onos-app ${OCI} reinstall! target/test-app-1.2.3.oar"/>
-        <step name="Verify-CLI" requires="Reinstall-App-With-CLI"
+        <step name="Verify-CLI" requires="^"
               exec="onos ${OCI} sample"/>
 
         <step name="Create-App-UI-Overlay" requires="Reinstall-App-With-CLI"
               exec="onos-create-app ui org.test.app test-app 1.2.3 org.test.app -DinteractiveMode=false"/>
-        <step name="Build-App-With-UI" requires="Create-App-UI-Overlay"
+        <step name="Build-App-With-UI" requires="^"
               exec="mvn clean install"/>
-        <step name="Reinstall-App-With-UI" requires="Build-App-With-UI,-Verify-CLI"
+        <step name="Reinstall-App-With-UI" requires="^,~Verify-CLI"
               exec="onos-app ${OCI} reinstall! target/test-app-1.2.3.oar"/>
     </group>
 </scenario>
diff --git a/tools/test/scenarios/setup.xml b/tools/test/scenarios/setup.xml
index d43e77c..8a24540 100644
--- a/tools/test/scenarios/setup.xml
+++ b/tools/test/scenarios/setup.xml
@@ -27,11 +27,11 @@
                   requires="Install-${#}"/>
 
             <step name="Check-Logs-${#}" exec="onos-check-logs ${OC#}"
-                  requires="-Wait-for-Start-${#}"/>
+                  requires="~Wait-for-Start-${#}"/>
             <step name="Check-Components-${#}" exec="onos-check-components ${OC#}"
-                  requires="-Wait-for-Start-${#}"/>
+                  requires="~Wait-for-Start-${#}"/>
             <step name="Check-Apps-${#}" exec="onos-check-apps ${OC#}"
-                  requires="-Wait-for-Start-${#}"/>
+                  requires="~Wait-for-Start-${#}"/>
         </parallel>
     </group>
 </scenario>
diff --git a/tools/test/scenarios/smoke.xml b/tools/test/scenarios/smoke.xml
index 423f348..3161c21 100644
--- a/tools/test/scenarios/smoke.xml
+++ b/tools/test/scenarios/smoke.xml
@@ -15,6 +15,13 @@
   -->
 <scenario name="smoke-test" description="ONOS smoke test">
     <import file="${ONOS_ROOT}/tools/test/scenarios/prerequisites.xml"/>
+
     <import file="${ONOS_ROOT}/tools/test/scenarios/setup.xml"/>
     <dependency name="Setup" requires="Prerequisites"/>
+
+    <import file="${ONOS_ROOT}/tools/test/scenarios/archetypes.xml"/>
+    <dependency name="Archetypes" requires="Setup"/>
+
+    <import file="${ONOS_ROOT}/tools/test/scenarios/wrapup.xml"/>
+    <dependency name="Wrapup" requires="~Archetypes,Setup"/>
 </scenario>
diff --git a/tools/test/scenarios/wrapup.xml b/tools/test/scenarios/wrapup.xml
new file mode 100644
index 0000000..e46441d
--- /dev/null
+++ b/tools/test/scenarios/wrapup.xml
@@ -0,0 +1,24 @@
+<!--
+  ~ Copyright 2015 Open Networking Laboratory
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<scenario name="wrapup" description="ONOS test wrapup">
+    <group name="Wrapup">
+        <parallel var="${OC#}">
+            <step name="Final-Check-Logs-${#}" exec="onos-check-logs ${OC#}"/>
+            <step name="Fetch-Logs-${#}" exec="onos-fetch-logs ${OC#}"
+                  cwd="${WORKSPACE}/tmp/stc" requires="~^"/>
+        </parallel>
+    </group>
+</scenario>
diff --git a/utils/stc/src/main/java/org/onlab/stc/Compiler.java b/utils/stc/src/main/java/org/onlab/stc/Compiler.java
index 167570c..daa9f77 100644
--- a/utils/stc/src/main/java/org/onlab/stc/Compiler.java
+++ b/utils/stc/src/main/java/org/onlab/stc/Compiler.java
@@ -73,6 +73,7 @@
     private ProcessFlow processFlow;
     private File logDir;
 
+    private String previous = null;
     private String pfx = "";
     private boolean debugOn = System.getenv("debug") != null;
 
@@ -130,6 +131,7 @@
 
     /**
      * Returns the log directory where scenario logs should be kept.
+     *
      * @return scenario logs directory
      */
     public File logDir() {
@@ -258,6 +260,7 @@
         }
         steps.put(step.name(), step);
         processRequirements(step, expand(cfg.getString(REQUIRES)), namespace);
+        previous = step.name();
         return true;
     }
 
@@ -317,9 +320,11 @@
      * @param namespace optional namespace
      */
     private void processRequirements(Step src, String requires, String namespace) {
-        split(requires).forEach(name -> {
-            boolean isSoft = name.startsWith("-");
-            Step dst = getStep(expand(name.replaceFirst("^-", "")), namespace);
+        split(requires).forEach(n -> {
+            boolean isSoft = n.startsWith("~");
+            String name = n.replaceFirst("^~", "");
+            name = previous != null && name.equals("^") ? previous : name;
+            Step dst = getStep(name, namespace);
             if (!inactiveSteps.containsValue(dst)) {
                 dependencies.add(new Dependency(src, dst, isSoft));
             }
diff --git a/utils/stc/src/test/resources/org/onlab/stc/scenario.xml b/utils/stc/src/test/resources/org/onlab/stc/scenario.xml
index 3fd35c2..8e7f462 100644
--- a/utils/stc/src/test/resources/org/onlab/stc/scenario.xml
+++ b/utils/stc/src/test/resources/org/onlab/stc/scenario.xml
@@ -18,13 +18,13 @@
 
     <import file="/tmp/junit-stc/two-scenario.xml"/>
 
-    <dependency name="dude" requires="-yolo"/>
+    <dependency name="dude" requires="~yolo"/>
 
     <step name="yo" exec="some-command ${HOME} and ${prop.foo} args" if="${prop.foo}"/>
     <step name="hi" exec="some-command ${prop.bar} or ${HOME} other args"/>
     <step name="there" exec="another-command" requires="yo,hi"/>
 
-    <step name="maybe" exec="another-command" requires="-hi" unless="${prop.foo}"/>
+    <step name="maybe" exec="another-command" requires="~hi" unless="${prop.foo}"/>
 
     <group name="alpha" exec="same-command args" requires="yo">
         <step name="one" exec="asdads"/>