Michael Pasternak has uploaded a new change for review. Change subject: codegen: implement generated code compilation ......................................................................
codegen: implement generated code compilation Change-Id: Ib4a86d9f91b6ce47ae76128f7faabf52dfd401d5 Signed-off-by: Michael pasternak <[email protected]> --- M ovirt-engine-sdk-java-codegen/pom.xml M ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/Main.java M ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/common/AbstractCodegen.java A ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/compile/CodeCompiler.java M ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/rsdl/ApiCodegen.java 5 files changed, 112 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk-java refs/changes/79/16879/1 diff --git a/ovirt-engine-sdk-java-codegen/pom.xml b/ovirt-engine-sdk-java-codegen/pom.xml index f6d9736..b27e646 100644 --- a/ovirt-engine-sdk-java-codegen/pom.xml +++ b/ovirt-engine-sdk-java-codegen/pom.xml @@ -37,6 +37,21 @@ <version>1.8.3</version> <type>jar</type> <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-embedder</artifactId> + <version>3.0.5</version> + </dependency> + <dependency> + <groupId>org.sonatype.aether</groupId> + <artifactId>aether-connector-wagon</artifactId> + <version>1.13.1</version> + </dependency> + <dependency> + <groupId>org.apache.maven.wagon</groupId> + <artifactId>wagon-http</artifactId> + <version>2.1</version> </dependency> </dependencies> <url>http://www.ovirt.org/Java-sdk</url> diff --git a/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/Main.java b/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/Main.java index cb9bd7a..e90adc9 100644 --- a/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/Main.java +++ b/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/Main.java @@ -21,6 +21,7 @@ import javax.xml.bind.JAXBException; import org.apache.http.client.ClientProtocolException; +import org.apache.maven.cli.MavenCli; import org.ovirt.engine.sdk.codegen.rsdl.RsdlCodegen; import org.ovirt.engine.sdk.codegen.xsd.XsdCodegen; import org.ovirt.engine.sdk.exceptions.ServerException; @@ -48,14 +49,10 @@ // #1 - generate api entities from the XSD schema new XsdCodegen(httpProxyBroker).generate(); - // #2 - compile ovirt-engine-sdk-java - - // #3 - generate api entities decorators by RSDL and SDK entry point + // #2 - generate api entities decorators by RSDL and SDK entry point new RsdlCodegen(httpProxyBroker).generate(); - // #4 - compile ovirt-engine-sdk-java - - // #5 - exit + // #3 - exit System.exit(0); } } diff --git a/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/common/AbstractCodegen.java b/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/common/AbstractCodegen.java index be4b9ce..582eac0 100644 --- a/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/common/AbstractCodegen.java +++ b/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/common/AbstractCodegen.java @@ -16,11 +16,13 @@ package org.ovirt.engine.sdk.codegen.common; +import java.io.File; import java.io.IOException; import javax.xml.bind.JAXBException; import org.apache.http.client.ClientProtocolException; +import org.ovirt.engine.sdk.codegen.compile.CodeCompiler; import org.ovirt.engine.sdk.codegen.utils.FileUtils; import org.ovirt.engine.sdk.exceptions.ServerException; @@ -29,7 +31,10 @@ */ public abstract class AbstractCodegen implements ICodegen { - private String distPath; + private final String distPath; + + private final CodeCompiler codeCompiler; + private boolean dontCompile = false; /** * @param distPath @@ -38,6 +43,20 @@ public AbstractCodegen(String distPath) { super(); this.distPath = distPath; + this.codeCompiler = new CodeCompiler(getPackagePath()); + } + + /** + * @param distPath + * path to generate the code in + * @param dontCompile + * disables compilation post gen() + */ + public AbstractCodegen(String distPath, boolean dontCompile) { + super(); + this.distPath = distPath; + this.codeCompiler = new CodeCompiler(getPackagePath()); + this.dontCompile = dontCompile; } /** @@ -48,10 +67,22 @@ * @throws IOException * @throws JAXBException */ + @Override public void generate() throws ClientProtocolException, ServerException, IOException, JAXBException { doCleanPackage(this.distPath); doGenerate(this.distPath); + if (!this.dontCompile) { + codeCompiler.compile(); + } + } + + /** + * @return root package path + */ + private String getPackagePath() { + String[] split = this.distPath.split(File.separator); + return split[0] + File.separator + split[1]; } /** diff --git a/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/compile/CodeCompiler.java b/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/compile/CodeCompiler.java new file mode 100644 index 0000000..08634de --- /dev/null +++ b/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/compile/CodeCompiler.java @@ -0,0 +1,61 @@ +// +// Copyright (c) 2012 Red Hat, Inc. +// +// 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. +// + +package org.ovirt.engine.sdk.codegen.compile; + +import org.apache.maven.cli.MavenCli; + +/** + * Provides compilation services + */ +public class CodeCompiler { + + private static final String GOAL = "compile"; + + private final String path; + private final MavenCli mavenCli; + + public CodeCompiler(String path) { + super(); + this.path = path; + this.mavenCli = new MavenCli(); + } + + /** + * Compiles java code where default goal is compile. + * + * @return compilation status. + */ + public int compile() { + return compile(GOAL); + } + + /** + * Compiles java code + * + * @param goal + * compilation goal + * + * @return compilation status. + */ + public int compile(String goal) { + return this.mavenCli.doMain( + new String[] { goal }, + this.path, + System.out, + System.out); + } +} diff --git a/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/rsdl/ApiCodegen.java b/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/rsdl/ApiCodegen.java index 27d2b04..8008e52 100644 --- a/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/rsdl/ApiCodegen.java +++ b/ovirt-engine-sdk-java-codegen/src/main/java/org/ovirt/engine/sdk/codegen/rsdl/ApiCodegen.java @@ -64,7 +64,7 @@ public ApiCodegen(Map<String, CollectionHolder> collectionsHolder, VariableTemplate variableTemplate, CollectionGetterTemplate collectionGetterTemplate) { - super(getApiPath()); + super(getApiPath(), true); this.apiTemplate = new ApiTemplate(); this.rootResourceStaticTemplate = new RootResourceStaticTemplate(); this.rootResourceDynamicTemplate = new RootResourceDynamicTemplate(); -- To view, visit http://gerrit.ovirt.org/16879 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib4a86d9f91b6ce47ae76128f7faabf52dfd401d5 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-sdk-java Gerrit-Branch: master Gerrit-Owner: Michael Pasternak <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
