1 | ###########################################################################
|
---|
2 | # A module to handle XML descriptors
|
---|
3 | #
|
---|
4 | # Copyright (C) 2016 Andrey Ponomarenko's ABI Laboratory
|
---|
5 | #
|
---|
6 | # Written by Andrey Ponomarenko
|
---|
7 | #
|
---|
8 | # This program is free software: you can redistribute it and/or modify
|
---|
9 | # it under the terms of the GNU General Public License or the GNU Lesser
|
---|
10 | # General Public License as published by the Free Software Foundation.
|
---|
11 | #
|
---|
12 | # This program is distributed in the hope that it will be useful,
|
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | # GNU General Public License for more details.
|
---|
16 | #
|
---|
17 | # You should have received a copy of the GNU General Public License
|
---|
18 | # and the GNU Lesser General Public License along with this program.
|
---|
19 | # If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | ###########################################################################
|
---|
21 | use strict;
|
---|
22 |
|
---|
23 | sub createDesc($$)
|
---|
24 | {
|
---|
25 | my ($Path, $LVer) = @_;
|
---|
26 |
|
---|
27 | if(not -e $Path) {
|
---|
28 | return undef;
|
---|
29 | }
|
---|
30 |
|
---|
31 | if(-d $Path or $Path=~/\.jar\Z/)
|
---|
32 | {
|
---|
33 | return "
|
---|
34 | <version>
|
---|
35 | ".$In::Desc{$LVer}{"TargetVersion"}."
|
---|
36 | </version>
|
---|
37 |
|
---|
38 | <archives>
|
---|
39 | $Path
|
---|
40 | </archives>";
|
---|
41 | }
|
---|
42 |
|
---|
43 | # standard XML-descriptor
|
---|
44 | return readFile($Path);
|
---|
45 | }
|
---|
46 |
|
---|
47 | sub readDesc($$)
|
---|
48 | {
|
---|
49 | my ($Content, $LVer) = @_;
|
---|
50 |
|
---|
51 | if(not $Content) {
|
---|
52 | exitStatus("Error", "XML descriptor is empty");
|
---|
53 | }
|
---|
54 |
|
---|
55 | if($Content!~/\</) {
|
---|
56 | exitStatus("Error", "descriptor should be one of the following: Java archive, XML descriptor, API dump or directory with Java archives.");
|
---|
57 | }
|
---|
58 |
|
---|
59 | $Content=~s/\/\*(.|\n)+?\*\///g;
|
---|
60 | $Content=~s/<\!--(.|\n)+?-->//g;
|
---|
61 | $In::Desc{$LVer}{"Version"} = parseTag(\$Content, "version");
|
---|
62 |
|
---|
63 | if(defined $In::Desc{$LVer}{"TargetVersion"}) {
|
---|
64 | $In::Desc{$LVer}{"Version"} = $In::Desc{$LVer}{"TargetVersion"};
|
---|
65 | }
|
---|
66 |
|
---|
67 | if($In::Desc{$LVer}{"Version"} eq "") {
|
---|
68 | exitStatus("Error", "version in the XML descriptor is not specified (<version> section)");
|
---|
69 | }
|
---|
70 |
|
---|
71 | if(my $Archives = parseTag(\$Content, "archives"))
|
---|
72 | {
|
---|
73 | foreach my $Path (split(/\s*\n\s*/, $Archives))
|
---|
74 | {
|
---|
75 | if(not -e $Path) {
|
---|
76 | exitStatus("Access_Error", "can't access \'$Path\'");
|
---|
77 | }
|
---|
78 | $Path = getAbsPath($Path);
|
---|
79 | $In::Desc{$LVer}{"Archives"}{$Path} = 1;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | else {
|
---|
83 | exitStatus("Error", "descriptor does not contain info about Java archives");
|
---|
84 | }
|
---|
85 |
|
---|
86 | foreach my $Package (split(/\s*\n\s*/, parseTag(\$Content, "skip_packages"))) {
|
---|
87 | $In::Desc{$LVer}{"SkipPackages"}{$Package} = 1;
|
---|
88 | }
|
---|
89 | foreach my $Package (split(/\s*\n\s*/, parseTag(\$Content, "packages"))) {
|
---|
90 | $In::Desc{$LVer}{"KeepPackages"}{$Package} = 1;
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | return 1;
|
---|