|
1 # Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # Script to send XML data to diamonds |
|
15 # |
|
16 # |
|
17 use HTTP::Request::Common qw(POST); |
|
18 use LWP::UserAgent; |
|
19 |
|
20 use Getopt::Long; |
|
21 |
|
22 my $iServer; |
|
23 my $iUrl; |
|
24 my $iFile; |
|
25 my $iHelp; |
|
26 my $res; |
|
27 |
|
28 my $import_failed_message = "XML was not sent successfully to Diamonds via REST interface!\n"; |
|
29 my $import_succeed_message = "XML was sent successfully to Diamonds via REST interface.\n"; |
|
30 |
|
31 my $ua = LWP::UserAgent->new(); |
|
32 |
|
33 GetOptions('s=s' => \$iServer, 'u=s' => \$iUrl, 'f=s' => \$iFile, 'h' => \$iHelp); |
|
34 if ((!defined $iServer) || (!defined $iUrl) || (!defined $iFile) || ($iHelp)) |
|
35 { |
|
36 Usage(); |
|
37 } |
|
38 |
|
39 my $absoluteUrl = "http://".$iServer.$iUrl; |
|
40 my $request = HTTP::Request->new(POST => $absoluteUrl); |
|
41 $request->header('Content-Type' => 'text/xml'); |
|
42 |
|
43 open (FH,"<$iFile") or die "$iFile:$!\n"; |
|
44 my @filecon = <FH>; |
|
45 my $XmlContent = join("",@filecon); |
|
46 $request->content($XmlContent); |
|
47 $res = $ua->request($request); |
|
48 |
|
49 print "Response status:".$res->code()."\n"; |
|
50 print "Response reason:".$res->message()."\n"; |
|
51 |
|
52 if ($res->code() != 200) |
|
53 { |
|
54 print "ERROR in sending XML data\n"; |
|
55 } |
|
56 else |
|
57 { |
|
58 print "Server response:".$res->content()."\n"; |
|
59 } |
|
60 |
|
61 sub Usage() |
|
62 { |
|
63 print <<USE; |
|
64 Use: |
|
65 send_xml_to_diamonds.pl options |
|
66 |
|
67 Mandatory options: |
|
68 -s Server address |
|
69 -u Url |
|
70 -f path of XML file |
|
71 |
|
72 -h help |
|
73 |
|
74 Examples: |
|
75 Sending a new build to release instance of Diamonds |
|
76 send_xml_to_diamonds.pl -s diamonds.nmp.nokia.com -u /diamonds/builds/ -f c:\\build.xml |
|
77 |
|
78 Updating test results to existing build |
|
79 send_xml_to_diamonds.pl -s diamonds.nmp.nokia.com -u /diamonds/builds/123/ -f c:\\test.xml |
|
80 |
|
81 Sending data for Relative Change in SW Asset metrics |
|
82 send_xml_to_diamonds.pl -s diamonds.nmp.nokia.com -u /diamonds/metrics/ -f c:\\relative.xml |
|
83 |
|
84 Sending data for Function Coverage |
|
85 send_xml_to_diamonds.pl -s diamonds.nmp.nokia.com -u /diamonds/tests/coverage/ -f c:\\coverage.xml |
|
86 |
|
87 Note: If you want to send XML to development version of Diamonds in testing purposes, use |
|
88 address: trdeli02.nmp.nokia.com:9001 in the server address: |
|
89 send_xml_to_diamonds.pl -s trdeli02.nmp.nokia.com:9001 -u /diamonds/builds/ -f c:\\build.xml |
|
90 USE |
|
91 exit; |
|
92 } |