Fixing onos-lib-gen to correct buildifier error
and to support future local_jar workspace rule.

Change-Id: I2376223534e1f686f03d7a466a314f4f9c0932ae
diff --git a/tools/build/libgen/pom.xml b/tools/build/libgen/pom.xml
index 057dfa7..b21e009 100644
--- a/tools/build/libgen/pom.xml
+++ b/tools/build/libgen/pom.xml
@@ -29,7 +29,7 @@
     <groupId>org.onosproject</groupId>
     <artifactId>onos-libgen</artifactId>
     <packaging>jar</packaging>
-    <version>1.3-SNAPSHOT</version>
+    <version>1.3</version>
 
     <description>Third-party library generator for Buck and Bazel workspaces</description>
     <url>http://onosproject.org/</url>
diff --git a/tools/build/libgen/src/main/java/org/onosproject/libgen/BuckArtifact.java b/tools/build/libgen/src/main/java/org/onosproject/libgen/BuckArtifact.java
index be336c8..63136e6 100644
--- a/tools/build/libgen/src/main/java/org/onosproject/libgen/BuckArtifact.java
+++ b/tools/build/libgen/src/main/java/org/onosproject/libgen/BuckArtifact.java
@@ -89,23 +89,6 @@
         return fileName().endsWith(".jar");
     }
 
-    private boolean isHttp() {
-        return url().startsWith("http");
-    }
-
-    String getBazelJavaLibraryFragment() {
-        if (isJar()) {
-            String format =
-                    "\n    native.java_library(\n" +
-                            "        name = \"%s\",\n" +
-                            "        visibility = [\"//visibility:public\"],\n" +
-                            "        exports = [\"@%s//jar\"],\n" +
-                            "    )\n";
-            return String.format(format, jarTarget(), jarTarget());
-        }
-        return "";
-    }
-
     private String extractRepo() {
         // This is a hack because the code above us already got rid of the maven repo
         // info for artifacts
@@ -122,24 +105,25 @@
             String repo = extractRepo();
             String repoAttribute = "";
             if (!"".equals(repo)) {
-                repoAttribute = "        repository = \"" + repo + "\",\n";
+                repoAttribute = "            repository = \"" + repo + "\",\n";
             }
-            String format =
-                    "\n    native.maven_jar(\n" +
-                            "        name = \"%s\",\n" +
-                            "        artifact = \"%s\",\n" +
-                            "        sha1 = \"%s\",\n" +
-                            "%s" +
-                            "    )\n";
-            return String.format(format, jarTarget(), mavenCoords(), sha, repoAttribute);
+            String format = "\n" +
+                    "    if \"%s\" not in native.existing_rules():\n" +
+                    "        native.maven_jar(\n" +
+                    "            name = \"%s\",\n" +
+                    "            artifact = \"%s\",\n" +
+                    "            sha1 = \"%s\",\n%s" +
+                    "        )\n";
+            return String.format(format, jarTarget(), jarTarget(), mavenCoords(), sha, repoAttribute);
         } else {
-            String format =
-                    "\n    native.http_file(\n" +
-                            "        name = \"%s\",\n" +
-                            "        url = \"%s\",\n" +
-                            "        sha256 = \"%s\",\n" +
-                            "    )\n";
-            return String.format(format, jarTarget(), url(), sha);
+            String format = "\n" +
+                    "    if \"%s\" not in native.existing_rules():\n" +
+                    "        native.http_file(\n" +
+                    "            name = \"%s\",\n" +
+                    "            url = \"%s\",\n" +
+                    "            sha256 = \"%s\",\n" +
+                    "        )\n";
+            return String.format(format, jarTarget(), jarTarget(), url(), sha);
         }
     }
 
diff --git a/tools/build/libgen/src/main/java/org/onosproject/libgen/BuckLibGenerator.java b/tools/build/libgen/src/main/java/org/onosproject/libgen/BuckLibGenerator.java
index 9355079..1de8b67 100644
--- a/tools/build/libgen/src/main/java/org/onosproject/libgen/BuckLibGenerator.java
+++ b/tools/build/libgen/src/main/java/org/onosproject/libgen/BuckLibGenerator.java
@@ -182,17 +182,11 @@
             artifacts.forEach(artifact -> sb.append(artifact.getBuckFragment()));
         } else {
             StringBuilder mavenJars = new StringBuilder();
-            StringBuilder javaLibraries = new StringBuilder();
-
             mavenJars.append("\ndef generated_maven_jars():");
-            javaLibraries.append("\ndef generated_java_libraries():");
-
             artifacts.forEach(artifact -> {
                 mavenJars.append(artifact.getBazelMavenJarFragment());
-                javaLibraries.append(artifact.getBazelJavaLibraryFragment());
             });
-
-            sb.append(mavenJars).append(javaLibraries);
+            sb.append(mavenJars);
         }
         return sb.toString();
     }
@@ -218,7 +212,7 @@
                 "            return artifact_map[label_string]\n" +
                 "    if type(label) == \"string\":\n" +
                 "        return \"mvn:%s:%s:%s\" % (ONOS_GROUP_ID, label_string, ONOS_VERSION)\n" +
-                "    return \"mvn:%s:%s:%s\" % (ONOS_GROUP_ID, label.name, ONOS_VERSION)\n\n"
+                "    return \"mvn:%s:%s:%s\" % (ONOS_GROUP_ID, label.name, ONOS_VERSION)\n"
         );
 
         return artifactMap.toString();
diff --git a/tools/build/onos-lib-gen b/tools/build/onos-lib-gen
index e3bc403..1e24bb3 100755
--- a/tools/build/onos-lib-gen
+++ b/tools/build/onos-lib-gen
@@ -9,7 +9,7 @@
 cd $ONOS_ROOT
 
 REPO=${M2_REPO:-~/.m2/repository}
-VER=1.2
+VER=1.3
 ARTIFACT=org/onosproject/onos-libgen/$VER/onos-libgen-$VER.jar
 JAR=$REPO/$ARTIFACT