970N/A#! /usr/perl5/bin/perl
970N/A#
1339N/A# Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
970N/A#
970N/A# Permission is hereby granted, free of charge, to any person obtaining a
970N/A# copy of this software and associated documentation files (the "Software"),
970N/A# to deal in the Software without restriction, including without limitation
970N/A# the rights to use, copy, modify, merge, publish, distribute, sublicense,
970N/A# and/or sell copies of the Software, and to permit persons to whom the
970N/A# Software is furnished to do so, subject to the following conditions:
970N/A#
970N/A# The above copyright notice and this permission notice (including the next
970N/A# paragraph) shall be included in all copies or substantial portions of the
970N/A# Software.
970N/A#
970N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
970N/A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
970N/A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
970N/A# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
970N/A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
970N/A# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
970N/A# DEALINGS IN THE SOFTWARE.
970N/A#
970N/A#
970N/A
970N/A#
970N/A# Merge pkg(5) metadata files to reduce duplicates and combine attribute
970N/A# values for the same attribute name into a single line
970N/A#
970N/A
970N/Ause strict;
970N/Ause warnings;
970N/Ause diagnostics;
970N/A
970N/Amy %attributes = ();
1339N/Amy %licenses = ();
970N/A
970N/Awhile (my $in = <>) {
970N/A chomp $in;
970N/A if ($in =~ m{^set name=(\S+) value="(.*)"$}) {
970N/A my ($name, $value) = ($1, $2);
970N/A $attributes{$name}->{$value} = 1;
1339N/A } elsif ($in =~ m{^license }) {
1339N/A $licenses{$in} = 1;
970N/A } else {
970N/A # Pass through other lines unchanged
970N/A print $in, "\n";
970N/A }
970N/A}
970N/A
970N/Aforeach my $n (sort keys %attributes) {
970N/A print qq(set name="$n");
970N/A foreach my $v (sort keys %{$attributes{$n}}) {
970N/A print qq( value="$v");
970N/A }
970N/A print "\n";
970N/A}
1339N/A
1339N/A# If there's just one license for the whole package, we promote some of the
1339N/A# license attributes to be package level attributes.
1339N/A# If there's more than one license, and not all licenses are the same,
1339N/A# just pass all the lines through as we got them.
1339N/A
1339N/Amy $license_count = scalar(keys %licenses);
1339N/Amy $license_lines = join("\n", sort keys %licenses);
1339N/Aif ($license_count == 1) {
1339N/A while ($license_lines =~
1339N/A s{^(license\s+.*?)\s+
1339N/A (com\.oracle\.info\.(?:name|version|description|tpno))="([^"]*)"
1339N/A (.*)}{$1$4\nset name=$2 value="$3"}gmx)
1339N/A {
1339N/A # all the work is done in the while (...) statement
1339N/A }
1339N/A # if no description is provided, copy the pkg.summary for it
1339N/A $license_lines =~
1339N/A s{set name=com.oracle.info.description value=""}
1339N/A {<transform set name=pkg.summary -> emit set name=com.oracle.info.description value=%{pkg.summary}>};
1339N/A}
1339N/Aprint "\n", $license_lines, "\n";