Ori Liel has uploaded a new change for review. Change subject: restapi: Add ability to extract rsdl.xml from jar ......................................................................
restapi: Add ability to extract rsdl.xml from jar A previous patch moved RSDL generation to build time. This patch adds a class with a main() method which copies rsdl.xml, rsdl_gluster.xml to the desired directory. The idea behind this, is that sdk generation will be done completely automatically by maven goals. To copy the files mentioned above (to a directory named, for example, '/service') - add the following configuration to pom.xml of any project that depends on restapi-definition: <profile> <id>build-rsdl</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <executions> <execution> <phase>compile</phase> <goals> <goal>java</goal> </goals> <configuration> <mainClass>org.ovirt.engine.api.rsdl.RsdlIOManager</mainClass> <arguments> <argument>/service</argument> </arguments> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> Change-Id: I11834dac081e17c702c614ae923575a3debba6eb Signed-off-by: Ori Liel <ol...@redhat.com> --- M backend/manager/modules/pom.xml A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/rsdl/RsdlIOManager.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/rsdl/RsdlManager.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java 4 files changed, 46 insertions(+), 11 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/85/24385/1 diff --git a/backend/manager/modules/pom.xml b/backend/manager/modules/pom.xml index 51ea485..476d645 100644 --- a/backend/manager/modules/pom.xml +++ b/backend/manager/modules/pom.xml @@ -45,7 +45,7 @@ <plugin> <artifactId>maven-checkstyle-plugin</artifactId> <configuration> - <excludes>**/RsdlManager.java</excludes> + <excludes>**/RsdlManager.java,**/RsdlIOManager.java</excludes> </configuration> </plugin> </plugins> diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/rsdl/RsdlIOManager.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/rsdl/RsdlIOManager.java new file mode 100644 index 0000000..31ab843 --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/rsdl/RsdlIOManager.java @@ -0,0 +1,38 @@ +package org.ovirt.engine.api.rsdl; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Writer; + +public class RsdlIOManager { + + private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; + public static final String RSDL_FILE_NAME = "/rsdl.xml"; + public static final String GLUSTER_RSDL_FILE_NAME = "/rsdl_gluster.xml"; + + public static void main(String[] args) throws IOException { + System.out.println("Copying rsdl.xml, rsdl_gluster.xml to: " + args[0]); + copyRsdl(args[0]); + } + + public static void copyRsdl(String outputDirectory) throws IOException { + copy(loadAsStream(RSDL_FILE_NAME), new FileWriter(new File(outputDirectory + RSDL_FILE_NAME))); + copy(loadAsStream(GLUSTER_RSDL_FILE_NAME), new FileWriter(new File(outputDirectory + GLUSTER_RSDL_FILE_NAME))); + } + + public static InputStream loadAsStream(String fileName) { + return RsdlIOManager.class.getResourceAsStream(fileName); + } + + public static void copy(InputStream input, Writer output) throws IOException { + InputStreamReader in = new InputStreamReader(input); + char[] buffer = new char[DEFAULT_BUFFER_SIZE]; + int n = 0; + while (-1 != (n = in.read(buffer))) { + output.write(buffer, 0, n); + } + } +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/rsdl/RsdlManager.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/rsdl/RsdlManager.java index c2342b1..76c2336 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/rsdl/RsdlManager.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/rsdl/RsdlManager.java @@ -29,8 +29,6 @@ private static final String GENERAL_METADATA_DESCRIPTION = "These options are valid for entire application."; private static final String METADATA_FILE_NAME = "/rsdl_metadata.yaml"; - private static final String RSDL_FILE_NAME = "/rsdl.xml"; - private static final String GLUSTER_RSDL_FILE_NAME = "/rsdl_gluster.xml"; public static void main(String[] args) throws ClassNotFoundException, IOException { System.out.println("Generating RSDL files..."); @@ -52,12 +50,12 @@ serializeRsdl(rsdl, outputFileName); } - public RSDL loadRsdl(ApplicationMode applicationMode) throws IOException { - InputStream stream = - applicationMode == ApplicationMode.GlusterOnly ? - this.getClass().getResourceAsStream(GLUSTER_RSDL_FILE_NAME) : - this.getClass().getResourceAsStream(RSDL_FILE_NAME); - return JAXB.unmarshal(stream, RSDL.class); + public static RSDL loadRsdl(ApplicationMode applicationMode) throws IOException { + String fileName = + applicationMode == ApplicationMode.AllModes ? RsdlIOManager.RSDL_FILE_NAME + : RsdlIOManager.GLUSTER_RSDL_FILE_NAME; + InputStream rsdlAsStrem = RsdlIOManager.loadAsStream(fileName); + return JAXB.unmarshal(rsdlAsStrem, RSDL.class); } private static void serializeRsdl(RSDL rsdl, String rsdlLocation) { diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java index 4641b07..ea6e903 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java @@ -273,8 +273,7 @@ public synchronized RSDL getRSDL() throws ClassNotFoundException, IOException { if (rsdl == null) { - RsdlManager rsdlManager = new RsdlManager(); - rsdl = rsdlManager.loadRsdl(getCurrent().get(ApplicationMode.class)); + rsdl = RsdlManager.loadRsdl(getCurrent().get(ApplicationMode.class)); } return rsdl; } -- To view, visit http://gerrit.ovirt.org/24385 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I11834dac081e17c702c614ae923575a3debba6eb Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Ori Liel <ol...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches