Implement bazel rules for generation of swagger files
Change-Id: I0e5d33174898cc6a1bbca475f2e1696c4fdda1ca
diff --git a/tools/build/buck-plugin/BUILD b/tools/build/buck-plugin/BUILD
new file mode 100644
index 0000000..1c07690
--- /dev/null
+++ b/tools/build/buck-plugin/BUILD
@@ -0,0 +1,16 @@
+SWAGGER_EXECUTABLE = "swagger_generator"
+
+COMPILE_DEPS = JACKSON + [
+ "@guava//jar",
+ "@qdox//jar",
+ "@org_apache_felix_scr_bnd//jar",
+]
+
+java_binary(
+ name = SWAGGER_EXECUTABLE,
+ srcs = glob(["src/main/java/org/onosproject/onosjar/SwaggerGenerator.java"]),
+ main_class = "org.onosproject.onosjar.SwaggerGenerator",
+ resources = glob(["src/main/resources/registrator.javat"]),
+ visibility = ["//visibility:public"],
+ deps = COMPILE_DEPS,
+)
diff --git a/tools/build/buck-plugin/src/main/java/org/onosproject/onosjar/SwaggerGenerator.java b/tools/build/buck-plugin/src/main/java/org/onosproject/onosjar/SwaggerGenerator.java
index e567c81..518bf8c 100644
--- a/tools/build/buck-plugin/src/main/java/org/onosproject/onosjar/SwaggerGenerator.java
+++ b/tools/build/buck-plugin/src/main/java/org/onosproject/onosjar/SwaggerGenerator.java
@@ -19,6 +19,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableList;
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;
import com.thoughtworks.qdox.JavaProjectBuilder;
@@ -34,6 +35,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.time.Year;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -78,6 +80,10 @@
private final String apiPackage;
private final String apiDescription;
+ private String x(File f) {
+ return f == null ? "null" : f.getAbsolutePath();
+ }
+
public SwaggerGenerator(List<File> srcs, List<File> resources,
File srcDirectory, File resourceDirectory,
File genSrcOutputDirectory, File genResourcesOutputDirectory,
@@ -523,4 +529,38 @@
public static String apiRegistratorPath(String apiPackage) {
return apiPackage.replaceAll("\\.", "/") + "/ApiDocRegistrator.java";
}
+
+ private static List<File> getFiles(String commaSeparatedList) {
+ String[] fileNames = commaSeparatedList.split(",");
+ ImmutableList.Builder<File> files = ImmutableList.builder();
+ Arrays.stream(fileNames).forEach(filename -> files.add(new File(filename)));
+ return files.build();
+ }
+
+ public static void main(String args[]) {
+ List<File> srcs = getFiles(args[0]);
+ List<File> resources = getFiles(args[1]);
+ File srcDirectory = null;//new File(args[2]);
+ File resourceDirectory = new File(args[3]);
+ File genSrcOutputDirectory = new File(args[4]);
+ File genResourcesOutputDirectory = new File(args[5]);
+ String webContext = args[6];
+ String apiTitle = args[7];
+ String apiVersion = args[8];
+ String apiPackage = args[9];
+ String apiDescription = args[10];
+
+ SwaggerGenerator generator = new SwaggerGenerator(
+ srcs,
+ resources,
+ srcDirectory, resourceDirectory,
+ genSrcOutputDirectory,
+ genResourcesOutputDirectory,
+ webContext,
+ apiTitle,
+ apiVersion,
+ apiPackage,
+ apiDescription);
+ generator.execute();
+ }
}
\ No newline at end of file