Search in sources :

Example 6 with ClientLibraryArtifact

use of com.webcohesion.enunciate.artifacts.ClientLibraryArtifact in project enunciate by stoicflame.

the class PHPXMLClientModule method call.

@Override
public void call(EnunciateContext context) {
    if (this.jaxbModule == null || this.jaxbModule.getJaxbContext() == null || this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
        info("No JAXB XML data types: PHP XML client will not be generated.");
        return;
    }
    if (usesUnmappableElements()) {
        warn("Web service API makes use of elements that cannot be handled by the PHP XML client. PHP XML client will not be generated.");
        return;
    }
    List<String> namingConflicts = JAXBCodeErrors.findConflictingAccessorNamingErrors(this.jaxbModule.getJaxbContext());
    if (namingConflicts != null && !namingConflicts.isEmpty()) {
        error("JAXB naming conflicts have been found:");
        for (String namingConflict : namingConflicts) {
            error(namingConflict);
        }
        error("These naming conflicts are often between the field and it's associated property, in which case you need to use one or two of the following strategies to avoid the conflicts:");
        error("1. Explicitly exclude one or the other.");
        error("2. Put the annotations on the property instead of the field.");
        error("3. Tell JAXB to use a different process for detecting accessors using the @XmlAccessorType annotation.");
        throw new EnunciateException("JAXB naming conflicts detected.");
    }
    Map<String, String> packageToNamespaceConversions = getPackageToNamespaceConversions();
    List<TypeDefinition> schemaTypes = new ArrayList<TypeDefinition>();
    ExtensionDepthComparator comparator = new ExtensionDepthComparator();
    EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
    for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
            String pckg = typeDefinition.getPackage().getQualifiedName().toString();
            if (!packageToNamespaceConversions.containsKey(pckg)) {
                packageToNamespaceConversions.put(pckg, packageToNamespace(pckg));
            }
            int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator);
            if (position < 0) {
                position = -position - 1;
            }
            schemaTypes.add(position, typeDefinition);
        }
    }
    File srcDir = getSourceDir();
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("schemaTypes", schemaTypes);
    model.put("namespaceFor", new ClientPackageForMethod(packageToNamespaceConversions, this.context));
    ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToNamespaceConversions, jaxbContext);
    model.put("classnameFor", classnameFor);
    model.put("typeNameFor", new TypeNameForMethod(packageToNamespaceConversions, jaxbContext));
    model.put("simpleNameFor", new SimpleNameWithParamsMethod(classnameFor));
    model.put("phpFileName", getSourceFileName());
    model.put("findRootElement", new FindRootElementMethod(jaxbContext));
    model.put("referencedNamespaces", new ReferencedNamespacesMethod(jaxbContext));
    model.put("prefix", new PrefixMethod(jaxbContext.getNamespacePrefixes()));
    model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
    model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
    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 PHP XML data 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 PHP XML code generation because everything appears up-to-date.");
    }
    File packageDir = getPackageDir();
    packageDir.mkdirs();
    File bundle = new File(packageDir, getBundleFileName());
    boolean anyFiles = bundle.exists();
    if (!isUpToDateWithSources(packageDir)) {
        try {
            anyFiles = enunciate.zip(bundle, srcDir);
        } catch (IOException e) {
            throw new EnunciateException(e);
        }
    }
    if (anyFiles) {
        ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "php.xml.client.library", "PHP XML Client Library");
        artifactBundle.setPlatform("PHP");
        FileArtifact sourceScript = new FileArtifact(getName(), "php.xml.client", bundle);
        // binaries and sources are the same thing in php
        sourceScript.setArtifactType(ArtifactType.binaries);
        sourceScript.setPublic(false);
        // read in the description from file
        String description = readResource("library_description.fmt", model);
        artifactBundle.setDescription(description);
        artifactBundle.addArtifact(sourceScript);
        this.enunciate.addArtifact(artifactBundle);
    }
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) URL(java.net.URL) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition) FindRootElementMethod(com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod) ReferencedNamespacesMethod(com.webcohesion.enunciate.modules.jaxb.util.ReferencedNamespacesMethod) EnunciateException(com.webcohesion.enunciate.EnunciateException) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) EnunciateJaxbContext(com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) PrefixMethod(com.webcohesion.enunciate.modules.jaxb.util.PrefixMethod) File(java.io.File)

Example 7 with ClientLibraryArtifact

use of com.webcohesion.enunciate.artifacts.ClientLibraryArtifact in project enunciate by stoicflame.

the class CXMLClientModule method call.

@Override
public void call(EnunciateContext context) {
    if (this.jaxbModule == null || this.jaxbModule.getJaxbContext() == null || this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
        info("No JAXB XML data types: C XML client will not be generated.");
        return;
    }
    if (usesUnmappableElements()) {
        warn("Web service API makes use of elements that cannot be handled by the C XML client. C XML client will not be generated.");
        return;
    }
    List<String> namingConflicts = JAXBCodeErrors.findConflictingAccessorNamingErrors(this.jaxbModule.getJaxbContext());
    if (namingConflicts != null && !namingConflicts.isEmpty()) {
        error("JAXB naming conflicts have been found:");
        for (String namingConflict : namingConflicts) {
            error(namingConflict);
        }
        error("These naming conflicts are often between the field and it's associated property, in which case you need to use one or two of the following strategies to avoid the conflicts:");
        error("1. Explicitly exclude one or the other.");
        error("2. Put the annotations on the property instead of the field.");
        error("3. Tell JAXB to use a different process for detecting accessors using the @XmlAccessorType annotation.");
        throw new EnunciateException("JAXB naming conflicts detected.");
    }
    File srcDir = getSourceDir();
    srcDir.mkdirs();
    Map<String, Object> model = new HashMap<String, Object>();
    String slug = getSlug();
    Map<String, String> ns2prefix = this.jaxbModule.getJaxbContext().getNamespacePrefixes();
    NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod(getTypeDefinitionNamePattern(), slug, ns2prefix);
    model.put("nameForTypeDefinition", nameForTypeDefinition);
    model.put("nameForEnumConstant", new NameForEnumConstantMethod(getEnumConstantNamePattern(), slug, ns2prefix));
    TreeMap<String, String> conversions = new TreeMap<String, String>();
    for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
            if (typeDefinition.isEnum()) {
                conversions.put(typeDefinition.getQualifiedName().toString(), "enum " + nameForTypeDefinition.calculateName(typeDefinition));
            } else {
                conversions.put(typeDefinition.getQualifiedName().toString(), "struct " + nameForTypeDefinition.calculateName(typeDefinition));
            }
        }
    }
    ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, this.jaxbModule.getJaxbContext());
    model.put("classnameFor", classnameFor);
    String sourceFileName = getSourceFileName(slug);
    model.put("cFileName", sourceFileName);
    model.put("separateCommonCode", isSeparateCommonCode());
    model.put("findRootElement", new FindRootElementMethod(this.jaxbModule.getJaxbContext()));
    model.put("referencedNamespaces", new ReferencedNamespacesMethod(this.jaxbModule.getJaxbContext()));
    model.put("prefix", new PrefixMethod(ns2prefix));
    model.put("xmlFunctionIdentifier", new XmlFunctionIdentifierMethod(ns2prefix));
    model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
    model.put("filename", sourceFileName);
    model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
    model.put("schemas", this.jaxbModule.getJaxbContext().getSchemas().values());
    model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
    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 data structures and (de)serialization functions...");
        URL apiTemplate = 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.");
    }
    ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "c.client.library", "C Client Library");
    FileArtifact sourceScript = new FileArtifact(getName(), "c.client", new File(srcDir, sourceFileName));
    sourceScript.setArtifactType(ArtifactType.sources);
    sourceScript.setPublic(false);
    // read in the description from file
    String description = readResource("library_description.fmt", model, nameForTypeDefinition);
    artifactBundle.setDescription(description);
    artifactBundle.addArtifact(sourceScript);
    if (isSeparateCommonCode()) {
        FileArtifact commonSourceHeader = new FileArtifact(getName(), "c.common.client", new File(srcDir, "enunciate-common.c"));
        commonSourceHeader.setPublic(false);
        commonSourceHeader.setArtifactType(ArtifactType.sources);
        commonSourceHeader.setDescription("Common code needed for all projects.");
        artifactBundle.addArtifact(commonSourceHeader);
    }
    this.enunciate.addArtifact(artifactBundle);
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) IsFacetExcludedMethod(com.webcohesion.enunciate.util.freemarker.IsFacetExcludedMethod) URL(java.net.URL) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition) FindRootElementMethod(com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod) ReferencedNamespacesMethod(com.webcohesion.enunciate.modules.jaxb.util.ReferencedNamespacesMethod) EnunciateException(com.webcohesion.enunciate.EnunciateException) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo) FileDirective(com.webcohesion.enunciate.util.freemarker.FileDirective) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) AccessorOverridesAnotherMethod(com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) File(java.io.File)

Example 8 with ClientLibraryArtifact

use of com.webcohesion.enunciate.artifacts.ClientLibraryArtifact in project enunciate by stoicflame.

the class JavaScriptClientModule method call.

@Override
public void call(EnunciateContext context) {
    if ((this.jacksonModule == null || this.jacksonModule.getJacksonContext() == null || this.jacksonModule.getJacksonContext().getTypeDefinitions().isEmpty()) && (this.jackson1Module == null || this.jackson1Module.getJacksonContext() == null || this.jackson1Module.getJacksonContext().getTypeDefinitions().isEmpty())) {
        info("No Jackson JSON data types: JavaScript client will not be generated.");
        return;
    }
    detectAccessorNamingErrors();
    Map<String, String> packageToNamespaceConversions = getPackageToNamespaceConversions();
    List<DecoratedTypeElement> schemaTypes = new ArrayList<DecoratedTypeElement>();
    ExtensionDepthComparator comparator = new ExtensionDepthComparator();
    EnunciateJacksonContext jacksonContext = null;
    EnunciateJackson1Context jackson1Context = null;
    if (this.jacksonModule != null) {
        jacksonContext = this.jacksonModule.getJacksonContext();
        for (TypeDefinition typeDefinition : jacksonContext.getTypeDefinitions()) {
            String pckg = typeDefinition.getPackage().getQualifiedName().toString();
            if (!packageToNamespaceConversions.containsKey(pckg)) {
                packageToNamespaceConversions.put(pckg, packageToNamespace(pckg));
            }
            int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator);
            if (position < 0) {
                position = -position - 1;
            }
            schemaTypes.add(position, typeDefinition);
        }
    }
    if (this.jackson1Module != null) {
        jackson1Context = this.jackson1Module.getJacksonContext();
        for (com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition typeDefinition : jackson1Context.getTypeDefinitions()) {
            String pckg = typeDefinition.getPackage().getQualifiedName().toString();
            if (!packageToNamespaceConversions.containsKey(pckg)) {
                packageToNamespaceConversions.put(pckg, packageToNamespace(pckg));
            }
            schemaTypes.add(typeDefinition);
        }
    }
    File srcDir = getSourceDir();
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("globalName", this.config.getString("[@global]", "javascriptClient"));
    model.put("schemaTypes", schemaTypes);
    model.put("namespaceFor", new ClientPackageForMethod(packageToNamespaceConversions, this.context));
    ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToNamespaceConversions, jacksonContext, jackson1Context);
    model.put("classnameFor", classnameFor);
    model.put("typeNameFor", new TypeNameForMethod(packageToNamespaceConversions, jacksonContext, jackson1Context));
    model.put("simpleNameFor", new SimpleNameWithParamsMethod(classnameFor));
    model.put("jsFileName", getSourceFileName());
    model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
    model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
    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 JavaScript data classes...");
        URL apiTemplate = getTemplateURL("api.fmt");
        try {
            processTemplate(apiTemplate, model);
        } catch (IOException e) {
            throw new EnunciateException(e);
        } catch (TemplateException e) {
            throw new EnunciateException(e);
        }
    } else {
        info("Skipping JavaScript code generation because everything appears up-to-date.");
    }
    File packageDir = getPackageDir();
    packageDir.mkdirs();
    File bundle = new File(packageDir, getBundleFileName());
    boolean anyFiles = bundle.exists();
    if (!isUpToDateWithSources(packageDir)) {
        try {
            anyFiles = enunciate.zip(bundle, srcDir);
        } catch (IOException e) {
            throw new EnunciateException(e);
        }
    }
    if (anyFiles) {
        ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "js.client.library", "JavaScript Client Library");
        artifactBundle.setPlatform("JavaScript");
        FileArtifact sourceScript = new FileArtifact(getName(), "javascript.client", bundle);
        // binaries and sources are the same thing in js
        sourceScript.setArtifactType(ArtifactType.binaries);
        sourceScript.setPublic(false);
        // read in the description from file
        String description = readResource("library_description.fmt", model);
        artifactBundle.setDescription(description);
        artifactBundle.addArtifact(sourceScript);
        this.enunciate.addArtifact(artifactBundle);
    }
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) URL(java.net.URL) TypeDefinition(com.webcohesion.enunciate.modules.jackson.model.TypeDefinition) DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) EnunciateException(com.webcohesion.enunciate.EnunciateException) EnunciateJackson1Context(com.webcohesion.enunciate.modules.jackson1.EnunciateJackson1Context) TemplateException(freemarker.template.TemplateException) EnunciateJacksonContext(com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext) IOException(java.io.IOException) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) File(java.io.File)

Example 9 with ClientLibraryArtifact

use of com.webcohesion.enunciate.artifacts.ClientLibraryArtifact in project enunciate by stoicflame.

the class DeployArtifactBaseMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (this.enunciateArtifactId == null) {
        throw new MojoExecutionException("An id of the enunciate artifact to be deployed must be configured.");
    }
    Enunciate enunciate = (Enunciate) getPluginContext().get(ConfigMojo.ENUNCIATE_PROPERTY);
    if (enunciate == null) {
        throw new MojoExecutionException("No enunciate mechanism found in the project!");
    }
    com.webcohesion.enunciate.artifacts.Artifact enunciateArtifact = enunciate.findArtifact(this.enunciateArtifactId);
    if (enunciateArtifact == null) {
        throw new MojoExecutionException("Unknown Enunciate artifact: " + this.enunciateArtifactId + ".");
    }
    File mainArtifact = null;
    File sources = null;
    File javadocs = null;
    if (enunciateArtifact instanceof ClientLibraryArtifact) {
        for (com.webcohesion.enunciate.artifacts.Artifact childArtifact : ((ClientLibraryArtifact) enunciateArtifact).getArtifacts()) {
            if (childArtifact instanceof FileArtifact) {
                ArtifactType artifactType = ((FileArtifact) childArtifact).getArtifactType();
                if (artifactType != null) {
                    switch(artifactType) {
                        case binaries:
                            mainArtifact = ((FileArtifact) childArtifact).getFile();
                            break;
                        case sources:
                            sources = ((FileArtifact) childArtifact).getFile();
                            break;
                        case javadocs:
                            javadocs = ((FileArtifact) childArtifact).getFile();
                            break;
                    }
                }
            }
        }
    } else if (enunciateArtifact instanceof FileArtifact) {
        mainArtifact = ((FileArtifact) enunciateArtifact).getFile();
    } else {
        try {
            mainArtifact = enunciate.createTempFile(this.enunciateArtifactId, "artifact");
            enunciateArtifact.exportTo(mainArtifact, enunciate);
        } catch (IOException e) {
            throw new MojoExecutionException("Unable to create a temp file.", e);
        }
    }
    if (mainArtifact == null) {
        if (sources != null) {
            mainArtifact = sources;
            sources = null;
        }
    }
    if (mainArtifact == null) {
        throw new MojoExecutionException("Unable to determine the file to deploy from enunciate artifact " + enunciateArtifactId + ".");
    }
    // Process the supplied POM (if there is one)
    Model model = null;
    if (pomFile != null) {
        generatePom = false;
        model = readModel(pomFile);
        processModel(model);
    }
    if (this.packaging == null) {
        String artifactName = mainArtifact.getName();
        int dotIndex = artifactName.indexOf('.');
        if (dotIndex > 0 && (dotIndex + 1 < artifactName.length())) {
            this.packaging = artifactName.substring(dotIndex + 1);
        }
    }
    if (this.packaging == null) {
        throw new MojoExecutionException("Unable to determine the packaging of enunciate artifact " + enunciateArtifactId + ". Please specify it in the configuration.");
    }
    if (this.version == null) {
        throw new MojoExecutionException("Null version.");
    }
    if (model == null) {
        model = new Model();
        model.setModelVersion("4.0.0");
        model.setGroupId(this.groupId);
        model.setArtifactId(this.artifactId);
        model.setVersion(this.version);
        model.setPackaging(this.packaging);
        model.setDescription(this.description);
    }
    ArtifactRepository repo = getDeploymentRepository();
    String protocol = repo.getProtocol();
    if (protocol.equals("scp")) {
        File sshFile = new File(System.getProperty("user.home"), ".ssh");
        if (!sshFile.exists()) {
            sshFile.mkdirs();
        }
    }
    Artifact artifact = this.artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier);
    // Upload the POM if requested, generating one if need be
    if (generatePom) {
        ArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, generatePomFile(model));
        artifact.addMetadata(metadata);
    } else {
        ArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, pomFile);
        artifact.addMetadata(metadata);
    }
    try {
        getDeployer().deploy(mainArtifact, artifact, repo, this.localRepository);
        if (sources != null || javadocs != null) {
            MavenProject project = new MavenProject(model);
            project.setArtifact(artifact);
            if (sources != null) {
                // we have to do it this way because of classloading issues.
                this.projectHelper.attachArtifact(project, artifact.getType(), "sources", sources);
                getDeployer().deploy(sources, (Artifact) project.getAttachedArtifacts().get(0), repo, this.localRepository);
            }
            if (javadocs != null) {
                // we have to do it this way because of classloading issues.
                this.projectHelper.attachArtifact(project, artifact.getType(), "javadoc", javadocs);
                getDeployer().deploy(javadocs, (Artifact) project.getAttachedArtifacts().get(0), repo, this.localRepository);
            }
        }
    } catch (ArtifactDeploymentException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : ProjectArtifactMetadata(org.apache.maven.project.artifact.ProjectArtifactMetadata) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactDeploymentException(org.apache.maven.artifact.deployer.ArtifactDeploymentException) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) IOException(java.io.IOException) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) Artifact(org.apache.maven.artifact.Artifact) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) Enunciate(com.webcohesion.enunciate.Enunciate) MavenProject(org.apache.maven.project.MavenProject) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) ArtifactType(com.webcohesion.enunciate.artifacts.ArtifactType) Model(org.apache.maven.model.Model) File(java.io.File) ArtifactMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) ProjectArtifactMetadata(org.apache.maven.project.artifact.ProjectArtifactMetadata)

Example 10 with ClientLibraryArtifact

use of com.webcohesion.enunciate.artifacts.ClientLibraryArtifact in project enunciate by stoicflame.

the class RubyJSONClientModule method call.

@Override
public void call(EnunciateContext context) {
    if ((this.jacksonModule == null || this.jacksonModule.getJacksonContext() == null || this.jacksonModule.getJacksonContext().getTypeDefinitions().isEmpty()) && (this.jackson1Module == null || this.jackson1Module.getJacksonContext() == null || this.jackson1Module.getJacksonContext().getTypeDefinitions().isEmpty())) {
        info("No Jackson JSON data types: Ruby JSON client will not be generated.");
        return;
    }
    detectAccessorNamingErrors();
    if (usesUnmappableElements()) {
        warn("Web service API makes use of elements that cannot be handled by the Ruby JSON client. Ruby JSON client will not be generated.");
        return;
    }
    Map<String, String> packageToModuleConversions = getPackageToModuleConversions();
    List<DecoratedTypeElement> schemaTypes = new ArrayList<DecoratedTypeElement>();
    ExtensionDepthComparator comparator = new ExtensionDepthComparator();
    EnunciateJacksonContext jacksonContext = null;
    EnunciateJackson1Context jackson1Context = null;
    if (this.jacksonModule != null) {
        jacksonContext = this.jacksonModule.getJacksonContext();
        for (TypeDefinition typeDefinition : jacksonContext.getTypeDefinitions()) {
            String pckg = typeDefinition.getPackage().getQualifiedName().toString();
            if (!packageToModuleConversions.containsKey(pckg)) {
                packageToModuleConversions.put(pckg, packageToModule(pckg));
            }
            int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator);
            if (position < 0) {
                position = -position - 1;
            }
            schemaTypes.add(position, typeDefinition);
        }
    }
    if (this.jackson1Module != null) {
        jackson1Context = this.jackson1Module.getJacksonContext();
        for (com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition typeDefinition : jackson1Context.getTypeDefinitions()) {
            String pckg = typeDefinition.getPackage().getQualifiedName().toString();
            if (!packageToModuleConversions.containsKey(pckg)) {
                packageToModuleConversions.put(pckg, packageToModule(pckg));
            }
            schemaTypes.add(typeDefinition);
        }
    }
    File srcDir = getSourceDir();
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("schemaTypes", schemaTypes);
    model.put("schemaTypes", schemaTypes);
    model.put("packages2modules", packageToModuleConversions);
    model.put("moduleFor", new ClientPackageForMethod(packageToModuleConversions, this.context));
    ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToModuleConversions, jacksonContext, jackson1Context);
    model.put("classnameFor", classnameFor);
    SimpleNameWithParamsMethod simpleNameFor = new SimpleNameWithParamsMethod(classnameFor);
    model.put("simpleNameFor", simpleNameFor);
    model.put("rubyFileName", getSourceFileName());
    model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
    model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
    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 Ruby JSON data classes...");
        URL apiTemplate = getTemplateURL("api.fmt");
        try {
            processTemplate(apiTemplate, model);
        } catch (IOException e) {
            throw new EnunciateException(e);
        } catch (TemplateException e) {
            throw new EnunciateException(e);
        }
    } else {
        info("Skipping Ruby code generation because everything appears up-to-date.");
    }
    ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "ruby.json.client.library", "Ruby JSON Client Library");
    artifactBundle.setPlatform("Ruby");
    FileArtifact sourceScript = new FileArtifact(getName(), "ruby.json.client", new File(srcDir, getSourceFileName()));
    // binaries and sources are the same thing in ruby
    sourceScript.setArtifactType(ArtifactType.binaries);
    sourceScript.setPublic(false);
    // read in the description from file
    String description = readResource("library_description.fmt", model);
    artifactBundle.setDescription(description);
    artifactBundle.addArtifact(sourceScript);
    this.enunciate.addArtifact(artifactBundle);
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) URL(java.net.URL) TypeDefinition(com.webcohesion.enunciate.modules.jackson.model.TypeDefinition) DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) EnunciateException(com.webcohesion.enunciate.EnunciateException) EnunciateJackson1Context(com.webcohesion.enunciate.modules.jackson1.EnunciateJackson1Context) TemplateException(freemarker.template.TemplateException) EnunciateJacksonContext(com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext) IOException(java.io.IOException) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) File(java.io.File)

Aggregations

ClientLibraryArtifact (com.webcohesion.enunciate.artifacts.ClientLibraryArtifact)10 FileArtifact (com.webcohesion.enunciate.artifacts.FileArtifact)10 EnunciateException (com.webcohesion.enunciate.EnunciateException)7 File (java.io.File)7 IOException (java.io.IOException)7 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)6 URL (java.net.URL)6 TemplateException (freemarker.template.TemplateException)5 DecoratedTypeElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement)3 EnunciateJacksonContext (com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext)3 TypeDefinition (com.webcohesion.enunciate.modules.jackson.model.TypeDefinition)3 EnunciateJackson1Context (com.webcohesion.enunciate.modules.jackson1.EnunciateJackson1Context)3 SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)3 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)3 FindRootElementMethod (com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod)3 Enunciate (com.webcohesion.enunciate.Enunciate)2 ArtifactType (com.webcohesion.enunciate.artifacts.ArtifactType)2 EnunciateJaxbContext (com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext)2 AccessorOverridesAnotherMethod (com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod)2 ReferencedNamespacesMethod (com.webcohesion.enunciate.modules.jaxb.util.ReferencedNamespacesMethod)2