Subversion Repositories DevTools

Rev

Blame | Last modification | View Log | RSS feed

########################################################################
# Copyright (C) 2008 ERG Limited, All rights reserved
#
# Module name   : wsdl-tools
# Module type   : JATS Plugin
# Compiler(s)   : Perl
# Environment(s): JATS
#
# Description   : This package extends the JATS toolset at build time
#                 It provides additional directives to the JATS makefiles
#                 to simplify the directives.
#
#                 The directive matches up with a run-time tool to
#                 do the bulk of the work.
#
# Operation     : This package adds the JATS directive GenerateWsdls
#                 When used the directive will use GenerateFiles to invoke
#                 a program at make-time to actually do the hard work.
#
# Directives    : GenerateWsdls (platform, Library, ... )
#                 GenerateWSClasses (platform, Wsdl, ... )
#
#......................................................................#

use strict;
use warnings;
use File::Basename;
use JatsError;

#
#   Global JATS-internal variables
#
our @WSDLS;                         # Complete list of WSDLs defined in makefile
our $so;                            # Toolset dependent shared library suffix
our %SHLIB_LIBS;                    # Hash keyed by known Shared Libraries

#-------------------------------------------------------------------------------
# Function        : GenerateWsdls
#
# Description     : Generate WSDL files from a Web Services DLL
#                   This directive simplifies the process of invoking the
#                   utility
#
# Inputs          : platform          - Standard Platform Specifier
#                   dll               - Name of the source DLL
#                   uargs             - User options
#
#                     --Wsdl=Name     - Name of WSDL that will be generated
#                                       Multiple allowed
#                                       .WSDL suffix will be added if not present
#                                       Names will be added to the @WSDL array
#                                       This can be used to simplify packaging
#                     --Url=url       - URL Used in the creation of the WSDL
#                                       Optional
#                     --EnvVar=Name   - Name of EnvVar to scan looking for dependent
#                                       DLLs. Optional. Multiple allowed
#                     --NoSuffix      - Do not append P or D to the name of the
#                                       DLL. Optional.
#                     --Verbose       - Increase execution messages
#
# Returns         : Nothing
#                   Creates a WSDL array to simplify Packaging
#                   Will contain the list of created WSDL files.
#
sub GenerateWsdls
{
    my ($platforms, $dll, @uargs) = @_;
    my @wsdls;
    my @envvar;
    my $url;
    my $suffix = '$(GBE_TYPE)';
    my $prefix = '';
    my @args;

    return if ( ! ActivePlatform($platforms) );

    #
    #   Parse arguments
    #
    foreach ( @uargs )
    {
        if ( /^--Wsdl=(.+)/i ) {
            my $name = $1;
            $name .= '.wsdl' unless ( $name =~ m~\.wsdl~i );
            push @wsdls, $name;

        } elsif ( /^--EnvVar=(.+)/i ) {
            push @envvar, $1;

        } elsif ( /^--Url=(.+)/i ) {
            $url = $1;

        } elsif ( /--NoSuffix/i ) {
            $suffix = '';

        } elsif ( /--Verbose/i ) {
            push @args, '/v';

        } else {
            Error ("GenerateWsdls: Unknown option: $_");
        }
    }

    Error ("GenerateWsdls: No DLL specified" )
        unless ( $dll );
    Error ("GenerateWsdls: No WSDLs specified" )
        unless ( @wsdls );

    #
    #   Attempt to locate the source DLL
    #       - It may be created within this make file
    #       - It may be within this package (not handled)
    #       - May be in an external package (not handled)
    #
    if ( exists $SHLIB_LIBS{$dll} )
    {
        #
        #   Is a locally generated DLL
        #   We make assumptions about its name and location
        #
        $prefix = '$(LIBDIR)/';
    }

    #
    #   Generate a nice command for the user
    #
    push @args, '--Prerequisite[' . $prefix . $dll . $suffix . '.' . $so . ']';
    push @args, '/r:' . $url if ( $url );
    push @args, '/o:--Var(ObjDir,--notag)/';
    push @args, '/p:' . $_ foreach ( @envvar );
    push @args, '--Created=' . $_  foreach ( @wsdls );

    #
    #   Generate the files
    #   Use standard JATS directive
    #
    GenerateFiles ('*', '--Tool=WsdlExtract', '--AutoGenerate', @args );

    #
    #   Add wsdl files created by this instance of the directive to the
    #   global list of all WSDLs created within the users makefile.pl
    #
    push @WSDLS, @wsdls;

}

#-------------------------------------------------------------------------------
# Function        : GenerateWSClasses
#
# Description     : Generate Csharp proxy from a WSDL
#
# Inputs          : $platforms              - Platform selector
#                   $wsdl                   - Source file
#                   Options
#                           --Namespace=NameSpace
#
# Returns         : 
#
sub GenerateWSClasses
{
    my ($platforms, $wsdl, @uargs) = @_;
    my $namespace;
    my @args;

    return if ( ! ActivePlatform($platforms) );

    #
    #   Parse arguments
    #
    foreach ( @uargs )
    {
        if ( /^--NameSpace=(.+)/i ) {
            $namespace = $1;

        } else {
            Error ("GenerateProxy: Unknown option: $_");
        }
    }

    Error ("GenerateProxy: No WSDL specified" )
        unless ( $wsdl );

    #
    #   Create a nice name for output file
    #       Prepend Jats_
    #       Append .cs - as it will be C# source
    #
    my $name =  'Jats_' . fileparse($wsdl, '\.[^.]+$') . '.cs';

    #
    #   Create command line
    #
    push @args, '--Prerequisite[' . $wsdl . ']';
    push @args, '/namespace:' . $namespace if ( $namespace );
    push @args, '/out:--Generated(' . $name . ')';

    #
    #   Generate the files
    #   Use standard JATS directive
    #
    GenerateFiles ('*', '--Tool=wsdl', '/nologo', @args );
}

1;