Simplifying rules and providing sensible defaults

Updated cordvtn, dhcp, fwd, onos-api, of-api, onlab-rest, onos-rest, onos-gui

Also, fixed checkstyle error print

Change-Id: I9d6ab76791e8603678079067a3b4e007ca7c4667
diff --git a/BUCK b/BUCK
index 76721d7..63a1995 100644
--- a/BUCK
+++ b/BUCK
@@ -1,4 +1,4 @@
-DEPS = [
+CORE = [
     '//utils/osgi:onlab-osgi',
     '//utils/junit:onlab-junit',
     '//utils/misc:onlab-misc',
@@ -81,7 +81,14 @@
 
     '//web/api:onos-rest',
     '//web/gui:onos-gui',
+]
 
+APPS = [
+    '//apps/dhcp:onos-apps-dhcp-oar',
+    '//apps/fwd:onos-apps-fwd-oar',
+]
+
+APP_JARS = [
     '//apps/cpman/api:onos-app-cpman-api',
     '//apps/cpman/app:onos-app-cpman-app',
     '//apps/aaa:onos-app-aaa',
@@ -90,14 +97,14 @@
     '//apps/routing-api:onos-app-routing-api',
     '//apps/cip:onos-app-cip',
     '//apps/cordmcast:onos-app-cord-mcast',
-    '//apps/cordvtn:onos-app-cordvtn',
-    '//apps/dhcp/api:onos-app-dhcp-api',
-    '//apps/dhcp/app:onos-app-dhcp-app',
+    '//apps/cordvtn:onos-apps-cordvtn',
+    '//apps/dhcp/api:onos-apps-dhcp-api',
+    '//apps/dhcp/app:onos-apps-dhcp-app',
     '//apps/drivermatrix:onos-app-drivermatrix',
     '//apps/events:onos-app-events',
     '//apps/faultmanagement:onos-app-fm',
     '//apps/flowanalyzer:onos-app-flowanalyzer',
-    '//apps/fwd:onos-app-fwd',
+    '//apps/fwd:onos-apps-fwd',
     '//apps/igmp:onos-app-igmp',
     '//apps/influxdbmetrics:onos-app-influxdb',
     '//apps/olt:onos-app-olt-api',
@@ -128,9 +135,21 @@
 ]
 
 java_library(
-   name = 'onos',
-   visibility = ['PUBLIC'],
-   deps = DEPS
+    name = 'core',
+    visibility = ['PUBLIC'],
+    deps = CORE,
+)
+
+java_library(
+    name = 'apps',
+    visibility = ['PUBLIC'],
+    deps = APPS + APP_JARS,
+)
+
+java_library(
+    name = 'onos',
+    visibility = ['PUBLIC'],
+    deps = [ ':core', ':apps' ]
 )
 
 INSTALL = [
diff --git a/apps/cordvtn/BUCK b/apps/cordvtn/BUCK
index 27ca9ce..2f0387c 100644
--- a/apps/cordvtn/BUCK
+++ b/apps/cordvtn/BUCK
@@ -1,9 +1,3 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-
-CURRENT_NAME = 'onos-app-cordvtn'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:org.apache.karaf.shell.console',
@@ -13,29 +7,14 @@
     '//cli:onos-cli',
     '//core/store/serializers:onos-core-serializers',
     '//apps/openstackinterface:onos-app-openstackinterface-api',
-    '//apps/dhcp/api:onos-app-dhcp-api',
+    '//apps/dhcp/api:onos-apps-dhcp-api',
     '//protocols/ovsdb/api:onos-ovsdb-api',
     '//protocols/ovsdb/rfc:onos-ovsdb-rfc',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-java_library(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-    resources_root = 'src/main/resources',
-    resources = glob(['src/main/resources/**']),
+    web_context = '/onos/cordvtn',
 )
 
-java_test(
-    name = 'tests',
-    srcs = glob([TEST + '/*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [CURRENT_TARGET],
-    source_under_test = [CURRENT_TARGET],
-)
+#FIXME need onos_app
\ No newline at end of file
diff --git a/apps/dhcp/BUCK b/apps/dhcp/BUCK
index 4affce2..1be783a 100644
--- a/apps/dhcp/BUCK
+++ b/apps/dhcp/BUCK
@@ -1,11 +1,10 @@
 BUNDLES = [
-    '//apps/dhcp/api:onos-app-dhcp-api',
-    '//apps/dhcp/app:onos-app-dhcp-app',
+    '//apps/dhcp/api:onos-apps-dhcp-api',
+    '//apps/dhcp/app:onos-apps-dhcp-app',
 ]
 
 onos_app(
-  app_name = 'org.onosproject.dhcp',
-  feature_coords = ONOS_GROUP_ID + ':onos-app-dhcp:' + ONOS_VERSION,
+  feature_coords = ONOS_GROUP_ID + ':onos-apps-dhcp:' + ONOS_VERSION,
   title = 'DHCP Server App',
   category = 'Utility',
   url = 'http://onosproject.org',
diff --git a/apps/dhcp/api/BUCK b/apps/dhcp/api/BUCK
index 9989504..ee55792 100644
--- a/apps/dhcp/api/BUCK
+++ b/apps/dhcp/api/BUCK
@@ -1,29 +1,7 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-
-CURRENT_NAME = 'onos-app-dhcp-api'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-)
-
-java_test(
-    name = 'tests',
-    srcs = glob([TEST + '/*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [CURRENT_TARGET],
-    source_under_test = [CURRENT_TARGET],
-)
+)
\ No newline at end of file
diff --git a/apps/dhcp/app/BUCK b/apps/dhcp/app/BUCK
index a3b4ea1..df15319 100644
--- a/apps/dhcp/app/BUCK
+++ b/apps/dhcp/app/BUCK
@@ -1,10 +1,8 @@
-CURRENT_NAME = 'onos-app-dhcp-app'
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:javax.ws.rs-api',
     '//lib:org.apache.karaf.shell.console',
-    '//apps/dhcp/api:onos-app-dhcp-api',
+    '//apps/dhcp/api:onos-apps-dhcp-api',
     '//utils/rest:onlab-rest',
     '//core/store/serializers:onos-core-serializers',
     '//cli:onos-cli',
@@ -14,12 +12,8 @@
     '//lib:TEST_ADAPTERS',
 ]
 
-osgi_jar(
-    name = CURRENT_NAME,
+osgi_jar_with_tests (
     deps = COMPILE_DEPS,
-    srcs = glob([SRC + '/*.java']),
-    resources = glob([RESOURCES_ROOT + '**']),
-    test_srcs = glob([TEST + '/*.java']),
     test_deps = TEST_DEPS,
     web_context = '/onos/dhcp',
 )
diff --git a/apps/fwd/BUCK b/apps/fwd/BUCK
index 9cb77c4..148d380 100644
--- a/apps/fwd/BUCK
+++ b/apps/fwd/BUCK
@@ -1,30 +1,16 @@
-CURRENT_NAME = 'onos-app-fwd'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:org.apache.karaf.shell.console',
     '//cli:onos-cli',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
 osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
     deps = COMPILE_DEPS,
-    test_srcs = glob([TEST + '/*.java']),
-    test_deps = TEST_DEPS,
-    visibility = ['PUBLIC'],
 )
 
 onos_app(
-    app_name = 'org.onosproject.fwd',
     title = 'Reactive Forwarding App',
     category = 'Traffic Steering',
     url = 'http://onosproject.org',
     description = 'Reactive forwarding application using flow subsystem.',
-    included_bundles = [ CURRENT_TARGET ],
 )
\ No newline at end of file
diff --git a/bucklets/onos.bucklet b/bucklets/onos.bucklet
index d64ba16..e2e0349 100644
--- a/bucklets/onos.bucklet
+++ b/bucklets/onos.bucklet
@@ -4,21 +4,26 @@
 FORCE_INSTALL=True
 NONE='NONE'
 
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
+SRC = 'src/main/java/**/'
+TEST = 'src/test/java/**/'
 RESOURCES_ROOT = 'src/main/resources/'
+TEST_RESOURCES_ROOT = 'src/test/resources/'
+
 
 ONOS_GROUP_ID = 'org.onosproject'
 ONOS_VERSION = '1.6.0-SNAPSHOT'
+ONOS_ARTIFACT_BASE = 'onos-'
+
+def _get_name():
+    base_path = get_base_path()
+    return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
 
 def osgi_jar(
-    name,
-    srcs,
-    test_srcs = None,
+    name = None,
+    srcs = None,
     group_id = ONOS_GROUP_ID,
     version = ONOS_VERSION,
     deps = [],
-    test_deps = [ '//lib:TEST' ],
     visibility = ['PUBLIC'],
     license = 'NONE',
     description = '',
@@ -27,19 +32,31 @@
     export_packages = '*',
     include_resources = NONE,
     web_context = NONE,
-    resources = None,
+    resources = NONE,
     resources_root = None,
-    test_resources = None,
-    test_resources_root = None,
     **kwargs
     ):
 
+  # if name and _get_name() != name:
+  #     print _get_name(), '!=', name
+  if name is None:
+      name = _get_name()
+
+  if srcs is None:
+      srcs = glob([SRC + '/*.java'])
+
+  if resources == NONE and resources_root is not None:
+      resources = glob([resources_root + '**'])
+  elif resources == NONE:
+      resources = glob([RESOURCES_ROOT + '**'])
+
+  if resources and not resources_root:
+      resources_root = RESOURCES_ROOT
+
   bare_jar_name = name + '-jar'
   osgi_jar_name = name + '-osgi'
   mvn_coords = group_id + ':' + name + ':' + version
 
-  if resources and not resources_root:
-      resources_root = RESOURCES_ROOT
 
   java_library(
       name = bare_jar_name,
@@ -98,7 +115,9 @@
                        '-o $OUT',
                        '-c $(location //tools/build/conf:checkstyle-xml)',
                        ' '.join(srcs) ))
-  error_cmd = '(touch $OUT; cat $OUT | grep "^\[ERROR\]"; exit 1)'
+  error_cmd = ' | '.join(( '( touch $OUT; cat $OUT',
+                           'grep -E "^[^: ]*:\d+:\d+: error:"',
+                           'sed "s#^.*__srcs/#%s:#g" ; exit 1)' % name, ))
   cmd = ' || '.join((chk_cmd, error_cmd))
   genrule(
     name = name + '-checkstyle',
@@ -126,18 +145,48 @@
     visibility = visibility,
   )
 
+def osgi_jar_with_tests(
+        name = None,
+        deps = [],
+        test_srcs = None,
+        test_deps = [ '//lib:TEST' ],
+        test_resources = None,
+        test_resources_root = None,
+        visibility = [ 'PUBLIC' ],
+        **kwargs
+    ):
+
+  if name is None:
+      name = _get_name()
+
+  osgi_jar(name = name,
+           deps = deps,
+           visibility = visibility,
+           **kwargs)
 
   if test_resources and not test_resources_root:
-      test_resources_root = RESOURCES_ROOT
+      test_resources_root = TEST_RESOURCES_ROOT
+  if test_resources_root and not test_resources:
+      test_resources = glob([test_resources_root + '**'])
+  if not test_resources and not test_resources_root:
+      test_resources = glob([TEST_RESOURCES_ROOT + '**'])
+      if test_resources:
+        test_resources_root = TEST_RESOURCES_ROOT
 
-  if test_srcs is not None:
-      java_test(
-        name = 'tests',
-        srcs = test_srcs,
-        deps = deps +
-               test_deps +
-               [':' + bare_jar_name],
-        source_under_test = [':' + bare_jar_name],
-        resources = test_resources,
-        resources_root = test_resources_root
-        )
+  if test_srcs is None:
+      test_srcs = glob([TEST + '/*.java'])
+
+  if not test_srcs:
+          print "Generating test rule for %s, but there are no tests." % name
+
+  java_test(
+    name = name + '-tests',
+    srcs = test_srcs,
+    deps = deps +
+           test_deps +
+           [':' + name + '-jar'],
+    source_under_test = [':' + name + '-jar'],
+    resources = test_resources,
+    resources_root = test_resources_root,
+    visibility = visibility
+    )
diff --git a/bucklets/onos_app.bucklet b/bucklets/onos_app.bucklet
index ba76649..d95427e 100644
--- a/bucklets/onos_app.bucklet
+++ b/bucklets/onos_app.bucklet
@@ -1,10 +1,24 @@
 ONOS_ORIGIN = 'ON.Lab'
 ONOS_VERSION = '1.6.0-SNAPSHOT'
 DEFAULT_APP_CATEGORY = 'Utility'
+ONOS_ARTIFACT_BASE = 'onos-'
+APP_PREFIX = 'org.onosproject.'
+
+import os.path
+
+# FIXME Factor this into common place
+def _get_name():
+    base_path = get_base_path()
+    return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
+
+def _get_app_name():
+    base_path = get_base_path()
+    return APP_PREFIX + os.path.basename(base_path)
 
 def onos_app(
-        app_name,
-        title,
+        app_name = None,
+        name = None,
+        title = None,
         version = ONOS_VERSION,
         origin = ONOS_ORIGIN,
         category = DEFAULT_APP_CATEGORY,
@@ -14,13 +28,31 @@
         feature_coords = None,
         required_features = [ 'onos-api' ],
         required_apps = [],
-        included_bundles = [],
+        included_bundles = None,
         excluded_bundles = [],
+        visibility = [ 'PUBLIC' ],
         **kwargs):
+    if name is None:
+        name = _get_name()
+
+    if app_name is None:
+        app_name = _get_app_name()
+
+    if title is None:
+        print "Missing title for %s" % _get_name()
+        title = _get_app_name()
+
+    if included_bundles is None:
+        target = ':' + _get_name()
+        included_bundles = [ target ]
 
     if not feature_coords and len(included_bundles) == 1:
         feature_coords = '$(maven_coords %s)' % included_bundles[0]
 
+    if not feature_coords:
+        print 'Missing maven coordinates for %s app feature.' % name
+        return
+
     args = [ '-n %s' % feature_coords,
              '-v %s' % version,
              '-t "%s"' % title,
@@ -36,26 +68,27 @@
 
     cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT'
     genrule(
-        name = 'app-features',
+        name = name + '-features',
         bash = cmd,
         out = 'features.xml',
         visibility = [],
     )
     cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT'
     genrule(
-        name = 'app-xml',
+        name = name + '-app-xml',
         bash = cmd,
         out = 'app.xml',
         visibility = [],
     )
 
     sources = [
-        '$(location :app-features) %s' % feature_coords,
-        '$(location :app-xml) NONE',
+        '$(location :%s-features) %s' % (name, feature_coords),
+        '$(location :%s-app-xml) NONE' % name,
     ]
     sources += ['$(location %s) $(maven_coords %s)' % (i, i) for i in included_bundles]
     genrule(
-        name = 'app-oar',
+        name = name + '-oar',
         out = 'app.oar',
-        bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources)
+        bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources),
+        visibility = visibility,
     )
diff --git a/core/api/BUCK b/core/api/BUCK
index 2ba9801..b066908 100644
--- a/core/api/BUCK
+++ b/core/api/BUCK
@@ -1,8 +1,3 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-CURRENT_NAME = 'onos-api'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:COMPILE',
     '//utils/misc:onlab-misc',
@@ -10,25 +5,7 @@
     '//utils/rest:onlab-rest',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
+    name = 'onos-api',
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-)
-
-java_test(
-    name = 'onos-api-tests',
-    visibility = ['PUBLIC'],
-    srcs = glob([TEST + '/*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [CURRENT_TARGET],
-    source_under_test = [CURRENT_TARGET],
-    resources_root = 'src/test/resources',
-    resources = glob(['src/test/resources/**']),
-)
+)
\ No newline at end of file
diff --git a/lib/BUCK b/lib/BUCK
index 5899d81..cfc2bfd 100644
--- a/lib/BUCK
+++ b/lib/BUCK
@@ -593,12 +593,12 @@
   license = 'Apache2.0',
 )
 
-maven_jar(
-  name = 'atomix-coordination',
-  id = 'io.atomix:atomix-coordination:1.0.0-rc3',
-  sha1 = '182a2618cbef13e6efe58b85aadfa1176b9d08f3',
-  license = 'Apache2.0',
-)
+# maven_jar(
+#   name = 'atomix-coordination',
+#   id = 'io.atomix:atomix-coordination:1.0.0-rc3',
+#   sha1 = '182a2618cbef13e6efe58b85aadfa1176b9d08f3',
+#   license = 'Apache2.0',
+# )
 
 maven_jar(
   name = 'atomix-messaging',
diff --git a/pom.xml b/pom.xml
index d14e38a..b389778 100644
--- a/pom.xml
+++ b/pom.xml
@@ -105,8 +105,28 @@
     -->
     <repositories>
         <repository>
+            <id>central</id>
+            <name>Central Repository</name>
+            <url>http://repo.maven.apache.org/maven2</url>
+            <layout>default</layout>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+            <releases>
+                <enabled>true</enabled>
+                <updatePolicy>never</updatePolicy>
+                <checksumPolicy>fail</checksumPolicy>
+            </releases>
+        </repository>
+
+        <repository>
             <id>snapshots</id>
             <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+            <snapshots>
+                <enabled>true</enabled>
+                <updatePolicy>never</updatePolicy>
+                <checksumPolicy>fail</checksumPolicy>
+            </snapshots>
         </repository>
     </repositories>
 
diff --git a/protocols/openflow/api/BUCK b/protocols/openflow/api/BUCK
index c681174..bca8133f 100644
--- a/protocols/openflow/api/BUCK
+++ b/protocols/openflow/api/BUCK
@@ -1,8 +1,3 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-CURRENT_NAME = 'onos-of-api'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:openflowj',
@@ -13,18 +8,8 @@
     '//core/api:onos-api-tests',
 ]
 
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
+    name = 'onos-of-api',
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-)
-
-java_test(
-    name = 'tests',
-    srcs = glob([TEST + '/*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [CURRENT_TARGET],
-    source_under_test = [CURRENT_TARGET],
+    test_deps = TEST_DEPS,
 )
diff --git a/tools/build/conf/BUCK b/tools/build/conf/BUCK
index 71f32e6..73831c4 100644
--- a/tools/build/conf/BUCK
+++ b/tools/build/conf/BUCK
@@ -14,6 +14,7 @@
   visibility = [ 'PUBLIC' ]
 )
 
+#FIXME location suppression.xml does not trigger this rule
 export_file(
   name = 'suppressions.xml',
   src = suppression_source,
diff --git a/utils/rest/BUCK b/utils/rest/BUCK
index 8748675..27fa55d 100644
--- a/utils/rest/BUCK
+++ b/utils/rest/BUCK
@@ -1,8 +1,3 @@
-SRC = 'src/main/java/org/onlab/**/'
-TEST = 'src/test/java/org/onlab/**/'
-CURRENT_NAME = 'onlab-rest'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:COMPILE',
     '//utils/osgi:onlab-osgi',
@@ -11,22 +6,7 @@
     '//lib:jersey-server',
 ]
 
-TEST_DEPS = [
-    '//lib:TEST',
-]
-
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
+osgi_jar_with_tests (
+    name = 'onlab-rest',
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-)
-
-java_test(
-    name = 'tests',
-    srcs = glob([TEST + '/*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [CURRENT_TARGET],
-    source_under_test = [CURRENT_TARGET],
-)
+)
\ No newline at end of file
diff --git a/web/api/BUCK b/web/api/BUCK
index 2b1d0fb..f74f488 100644
--- a/web/api/BUCK
+++ b/web/api/BUCK
@@ -1,10 +1,3 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-RESOURCES_ROOT = 'src/main/resources/'
-
-CURRENT_NAME = 'onos-rest'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//incubator/api:onos-incubator-api',
@@ -16,26 +9,9 @@
     '//lib:TEST_REST',
 ]
 
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
-    resources = glob([RESOURCES_ROOT + '**']),
-    resources_root = RESOURCES_ROOT,
+osgi_jar_with_tests (
+    name = 'onos-rest',
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
-    debug = False,
-    web_context = '/onos/v1'
-)
-
-SOURCE_JAR = CURRENT_TARGET + '-jar'
-java_test(
-    name = 'onos-rest-tests',
-    srcs = glob([TEST + '/*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [SOURCE_JAR],
-    source_under_test = [SOURCE_JAR],
-    visibility = ['PUBLIC'],
-    resources_root = 'src/test/resources',
-    resources = glob(['src/test/resources/**']),
-)
+    test_deps = TEST_DEPS,
+    web_context = '/onos/v1',
+)
\ No newline at end of file
diff --git a/web/gui/BUCK b/web/gui/BUCK
index b1a9a7c..7230898 100644
--- a/web/gui/BUCK
+++ b/web/gui/BUCK
@@ -1,10 +1,3 @@
-SRC = 'src/main/java/org/onosproject/**/'
-TEST = 'src/test/java/org/onosproject/**/'
-RESOURCES_ROOT = 'src/main/resources/'
-
-CURRENT_NAME = 'onos-gui'
-CURRENT_TARGET = ':' + CURRENT_NAME
-
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:javax.ws.rs-api',
@@ -33,23 +26,10 @@
     'WEB-INF/classes/raw=src/main/webapp/raw',
 ]
 
-osgi_jar(
-    name = CURRENT_NAME,
-    srcs = glob([SRC + '/*.java']),
-    resources = glob([RESOURCES_ROOT + '**']),
-    resources_root = RESOURCES_ROOT,
+osgi_jar_with_tests (
+    name = 'onos-gui',
     deps = COMPILE_DEPS,
-    visibility = ['PUBLIC'],
+    test_deps = TEST_DEPS,
     include_resources = ','.join(RESOURCES),
     web_context = '/onos/ui',
-    debug = False,
-)
-
-java_test(
-    name = 'tests',
-    srcs = glob([TEST + '/*.java']),
-    deps = COMPILE_DEPS +
-           TEST_DEPS +
-           [CURRENT_TARGET],
-    source_under_test = [CURRENT_TARGET],
 )