Search in sources :

Example 16 with EnunciateException

use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.

the class WebParam method getXmlType.

/**
 * Gets the xml type for this web parameter.
 *
 * @return The xml type.
 */
public XmlType getXmlType() {
    XmlType xmlType = XmlTypeFactory.findSpecifiedType(this, this.context.getJaxbContext());
    if (xmlType == null) {
        TypeMirror type = getType();
        if (isHolder()) {
            List<? extends TypeMirror> typeArgs = ((DeclaredType) type).getTypeArguments();
            if ((typeArgs == null) || (typeArgs.size() == 0)) {
                throw new EnunciateException("Parameter " + getSimpleName() + ": unable to get the type of the holder.");
            }
            type = typeArgs.iterator().next();
        }
        xmlType = XmlTypeFactory.getXmlType(type, this.context.getJaxbContext());
    }
    return xmlType;
}
Also used : DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) EnunciateException(com.webcohesion.enunciate.EnunciateException) XmlType(com.webcohesion.enunciate.modules.jaxb.model.types.XmlType) DeclaredType(javax.lang.model.type.DeclaredType)

Example 17 with EnunciateException

use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.

the class CSharpXMLClientModule method compileSources.

private File compileSources(File srcDir) {
    File compileDir = getCompileDir();
    compileDir.mkdirs();
    if (!isDisableCompile()) {
        if (!isUpToDateWithSources(compileDir)) {
            String compileExectuable = getCompileExecutable();
            if (compileExectuable == null) {
                String osName = System.getProperty("os.name");
                if (osName != null && osName.toUpperCase().contains("WINDOWS")) {
                    // try the "csc" command on Windows environments.
                    debug("Attempting to execute command \"csc /help\" for the current environment (%s).", osName);
                    try {
                        Process process = new ProcessBuilder("csc", "/help").redirectErrorStream(true).start();
                        InputStream in = process.getInputStream();
                        byte[] buffer = new byte[1024];
                        int len = in.read(buffer);
                        while (len > -0) {
                            len = in.read(buffer);
                        }
                        int exitCode = process.waitFor();
                        if (exitCode != 0) {
                            debug("Command \"csc /help\" failed with exit code " + exitCode + ".");
                        } else {
                            compileExectuable = "csc";
                            debug("C# compile executable to be used: csc");
                        }
                    } catch (Throwable e) {
                        debug("Command \"csc /help\" failed (" + e.getMessage() + ").");
                    }
                }
                if (compileExectuable == null) {
                    // try the "gmcs" command (Mono)
                    debug("Attempting to execute command \"gmcs /help\" for the current environment (%s).", osName);
                    try {
                        Process process = new ProcessBuilder("gmcs", "/help").redirectErrorStream(true).start();
                        InputStream in = process.getInputStream();
                        byte[] buffer = new byte[1024];
                        int len = in.read(buffer);
                        while (len > -0) {
                            len = in.read(buffer);
                        }
                        int exitCode = process.waitFor();
                        if (exitCode != 0) {
                            debug("Command \"gmcs /help\" failed with exit code " + exitCode + ".");
                        } else {
                            compileExectuable = "gmcs";
                            debug("C# compile executable to be used: %s", compileExectuable);
                        }
                    } catch (Throwable e) {
                        debug("Command \"gmcs /help\" failed (" + e.getMessage() + ").");
                    }
                }
                if (compileExectuable == null) {
                    // try the "mcs" command (Mono)
                    debug("Attempting to execute command \"mcs /help\" for the current environment (%s).", osName);
                    try {
                        Process process = new ProcessBuilder("mcs", "/help").redirectErrorStream(true).start();
                        InputStream in = process.getInputStream();
                        byte[] buffer = new byte[1024];
                        int len = in.read(buffer);
                        while (len > -0) {
                            len = in.read(buffer);
                        }
                        int exitCode = process.waitFor();
                        if (exitCode != 0) {
                            debug("Command \"mcs /help\" failed with exit code " + exitCode + ".");
                        } else {
                            compileExectuable = "mcs";
                            debug("C# compile executable to be used: %s", compileExectuable);
                        }
                    } catch (Throwable e) {
                        debug("Command \"mcs /help\" failed (" + e.getMessage() + ").");
                    }
                }
                if (compileExectuable == null && isRequire()) {
                    throw new EnunciateException("C# client code generation is required, but there was no valid compile executable found. " + "Please supply one in the configuration file, or set it up on your system path.");
                }
            }
            String compileCommand = getCompileCommand();
            if (compileCommand == null) {
                throw new IllegalStateException("Somehow the \"compile\" step was invoked on the C# module without a valid compile command.");
            }
            // replace all spaces with the null character, so the command can be tokenized later.
            compileCommand = compileCommand.replace(' ', '\0');
            File dll = new File(compileDir, getDLLFileName());
            File docXml = new File(compileDir, getDocXmlFileName());
            File sourceFile = new File(srcDir, getSourceFileName());
            compileCommand = String.format(compileCommand, compileExectuable, dll.getAbsolutePath(), docXml.getAbsolutePath(), sourceFile.getAbsolutePath());
            // tokenize on the null character to preserve the spaces in the command.
            StringTokenizer tokenizer = new StringTokenizer(compileCommand, "\0");
            List<String> command = new ArrayList<String>();
            while (tokenizer.hasMoreElements()) {
                command.add((String) tokenizer.nextElement());
            }
            try {
                Process process = new ProcessBuilder(command).redirectErrorStream(true).directory(compileDir).start();
                BufferedReader procReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                String line = procReader.readLine();
                while (line != null) {
                    info(line);
                    line = procReader.readLine();
                }
                int procCode;
                try {
                    procCode = process.waitFor();
                } catch (InterruptedException e1) {
                    throw new EnunciateException("Unexpected inturruption of the C# compile process.");
                }
                if (procCode != 0) {
                    throw new EnunciateException("C# compile failed.");
                }
            } catch (IOException e) {
                throw new EnunciateException(e);
            }
            FileArtifact assembly = new FileArtifact(getName(), "csharp.assembly", dll);
            assembly.setPublic(false);
            enunciate.addArtifact(assembly);
            if (docXml.exists()) {
                FileArtifact docs = new FileArtifact(getName(), "csharp.docs.xml", docXml);
                docs.setPublic(false);
                enunciate.addArtifact(docs);
            }
        } else {
            info("Skipping C# compile because everything appears up-to-date.");
        }
    } else {
        debug("Skipping C# compile because a compile executable was neither found nor provided.  The C# bundle will only include the sources.");
    }
    return compileDir;
}
Also used : EnunciateException(com.webcohesion.enunciate.EnunciateException) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact)

Example 18 with EnunciateException

use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.

the class CSharpXMLClientModule method readLibraryDescription.

protected String readLibraryDescription(Map<String, Object> model) {
    model.put("sample_service_method", findExampleWebMethod());
    model.put("sample_resource", findExampleResourceMethod());
    URL res = CSharpXMLClientModule.class.getResource("library_description.fmt");
    try {
        return processTemplate(res, model);
    } catch (TemplateException e) {
        throw new EnunciateException(e);
    } catch (IOException e) {
        throw new EnunciateException(e);
    }
}
Also used : TemplateException(freemarker.template.TemplateException) EnunciateException(com.webcohesion.enunciate.EnunciateException) URL(java.net.URL)

Example 19 with EnunciateException

use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.

the class CSharpXMLClientModule method packageArtifacts.

private void packageArtifacts(File srcDir, File compileDir) {
    File packageDir = getPackageDir();
    packageDir.mkdirs();
    if (!isUpToDateWithSources(packageDir)) {
        try {
            // we want to zip up the source file, too, so we'll just copy it to the compile dir.
            enunciate.copyDir(srcDir, compileDir);
            File bundle = new File(packageDir, getBundleFileName());
            boolean anyFiles = enunciate.zip(bundle, compileDir);
            if (anyFiles) {
                ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "csharp.client.library", "C# Client Library");
                artifactBundle.setPlatform(".NET 2.0");
                StringBuilder builder = new StringBuilder("C# source code");
                boolean docsExist = new File(compileDir, getDocXmlFileName()).exists();
                boolean dllExists = new File(compileDir, getDLLFileName()).exists();
                if (docsExist && dllExists) {
                    builder.append(", the assembly, and the XML docs");
                } else if (dllExists) {
                    builder.append("and the assembly");
                }
                artifactBundle.setDescription((String) context.getProperty(LIRBARY_DESCRIPTION_PROPERTY));
                FileArtifact binariesJar = new FileArtifact(getName(), "dotnet.client.bundle", bundle);
                binariesJar.setArtifactType(ArtifactType.binaries);
                binariesJar.setDescription(String.format("The %s for the C# client library.", builder.toString()));
                binariesJar.setPublic(false);
                artifactBundle.addArtifact(binariesJar);
                enunciate.addArtifact(artifactBundle);
            }
        } catch (IOException e) {
            throw new EnunciateException(e);
        }
    }
}
Also used : EnunciateException(com.webcohesion.enunciate.EnunciateException) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact)

Example 20 with EnunciateException

use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.

the class CSharpXMLClientModule method generateSources.

private File generateSources(Map<String, String> packageToNamespaceConversions) {
    File srcDir = getSourceDir();
    srcDir.mkdirs();
    Map<String, Object> model = new HashMap<String, Object>();
    ClientPackageForMethod namespaceFor = new ClientPackageForMethod(packageToNamespaceConversions, this.context);
    Collection<WsdlInfo> wsdls = new ArrayList<WsdlInfo>();
    if (this.jaxwsModule != null) {
        wsdls = this.jaxwsModule.getJaxwsContext().getWsdls().values();
    }
    model.put("wsdls", wsdls);
    EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
    model.put("schemas", jaxbContext.getSchemas().values());
    model.put("baseUri", this.enunciate.getConfiguration().getApplicationRoot());
    model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
    model.put("namespaceFor", namespaceFor);
    model.put("findRootElement", new FindRootElementMethod(jaxbContext));
    model.put("requestDocumentQName", new RequestDocumentQNameMethod());
    model.put("responseDocumentQName", new ResponseDocumentQNameMethod());
    ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToNamespaceConversions, jaxbContext);
    model.put("classnameFor", classnameFor);
    model.put("listsAsArraysClassnameFor", new ListsAsArraysClientClassnameForMethod(packageToNamespaceConversions, jaxbContext));
    model.put("simpleNameFor", new SimpleNameFor(classnameFor));
    model.put("csFileName", getSourceFileName());
    model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
    model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
    Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes());
    facetIncludes.addAll(getFacetIncludes());
    Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes());
    facetExcludes.addAll(getFacetExcludes());
    FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes);
    model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter));
    if (!isUpToDateWithSources(srcDir)) {
        debug("Generating the C# client classes...");
        URL apiTemplate = isSingleFilePerClass() ? getTemplateURL("api-multiple-files.fmt") : getTemplateURL("api.fmt");
        try {
            processTemplate(apiTemplate, model);
        } catch (IOException e) {
            throw new EnunciateException(e);
        } catch (TemplateException e) {
            throw new EnunciateException(e);
        }
    } else {
        info("Skipping C# code generation because everything appears up-to-date.");
    }
    this.context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model));
    return srcDir;
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) IsFacetExcludedMethod(com.webcohesion.enunciate.util.freemarker.IsFacetExcludedMethod) ClientPackageForMethod(com.webcohesion.enunciate.util.freemarker.ClientPackageForMethod) URL(java.net.URL) FindRootElementMethod(com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod) EnunciateException(com.webcohesion.enunciate.EnunciateException) FileDirective(com.webcohesion.enunciate.util.freemarker.FileDirective) TemplateException(freemarker.template.TemplateException) EnunciateJaxbContext(com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext) AccessorOverridesAnotherMethod(com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod) WsdlInfo(com.webcohesion.enunciate.modules.jaxws.WsdlInfo)

Aggregations

EnunciateException (com.webcohesion.enunciate.EnunciateException)53 URL (java.net.URL)21 TemplateException (freemarker.template.TemplateException)19 IOException (java.io.IOException)16 FileArtifact (com.webcohesion.enunciate.artifacts.FileArtifact)12 File (java.io.File)12 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)11 ClientLibraryArtifact (com.webcohesion.enunciate.artifacts.ClientLibraryArtifact)8 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)7 TypeElement (javax.lang.model.element.TypeElement)7 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)6 FindRootElementMethod (com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod)6 IsFacetExcludedMethod (com.webcohesion.enunciate.util.freemarker.IsFacetExcludedMethod)6 VariableElement (javax.lang.model.element.VariableElement)6 EnunciateJacksonContext (com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext)5 TypeDefinition (com.webcohesion.enunciate.modules.jackson.model.TypeDefinition)5 EnunciateJackson1Context (com.webcohesion.enunciate.modules.jackson1.EnunciateJackson1Context)5 SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)5 AccessorOverridesAnotherMethod (com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod)5 FileDirective (com.webcohesion.enunciate.util.freemarker.FileDirective)5