Ignore:
Timestamp:
2018-04-02T23:20:00+02:00 (6 years ago)
Author:
Don-vip
Message:

tools update: Groovy 2.4.15, PMD 6.2.0, JAPICC 2.4

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/japicc/modules/Internals/APIDump.pm

    r12872 r13595  
    22# A module to create API dump from disassembled code
    33#
    4 # Copyright (C) 2016-2017 Andrey Ponomarenko's ABI Laboratory
     4# Copyright (C) 2016-2018 Andrey Ponomarenko's ABI Laboratory
    55#
    66# Written by Andrey Ponomarenko
    77#
    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.
     8# This library is free software; you can redistribute it and/or
     9# modify it under the terms of the GNU Lesser General Public
     10# License as published by the Free Software Foundation; either
     11# version 2.1 of the License, or (at your option) any later version.
    1112#
    12 # This program is distributed in the hope that it will be useful,
     13# This library is distributed in the hope that it will be useful,
    1314# 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.
     15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16# Lesser General Public License for more details.
    1617#
    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/>.
     18# You should have received a copy of the GNU Lesser General Public
     19# License along with this library; if not, write to the Free Software
     20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
     21# MA  02110-1301  USA.
    2022###########################################################################
    2123use strict;
     
    110112{ # 1, 2 - library, 0 - client
    111113    my ($LVer, $Path) = @_;
    112    
    113114    $Path = getAbsPath($Path);
    114     my $JarCmd = getCmdPath("jar");
    115     if(not $JarCmd) {
    116         exitStatus("Not_Found", "can't find \"jar\" command");
    117     }
     115   
     116    my $ExtractCmd = undef;
     117   
     118    if($Path=~/\.jar\Z/)
     119    {
     120        $ExtractCmd = getCmdPath("jar");
     121        if(not $ExtractCmd) {
     122            exitStatus("Not_Found", "can't find \"jar\" command");
     123        }
     124        $ExtractCmd .= " -xf \"$Path\"";
     125    }
     126    elsif($Path=~/\.jmod\Z/)
     127    {
     128        $ExtractCmd = getCmdPath("jmod");
     129        if(not $ExtractCmd) {
     130            exitStatus("Not_Found", "can't find \"jmod\" command");
     131        }
     132        $ExtractCmd .= " extract \"$Path\"";
     133    }
     134    else {
     135        exitStatus("Error", "unknown format of \'$Path\'");
     136    }
     137   
    118138    my $ExtractPath = join_P($In::Opt{"Tmp"}, $ExtractCounter);
    119139    if(-d $ExtractPath) {
     
    121141    }
    122142    mkpath($ExtractPath);
     143   
    123144    chdir($ExtractPath);
    124     system($JarCmd." -xf \"$Path\"");
     145    system($ExtractCmd);
    125146    if($?) {
    126147        exitStatus("Error", "can't extract \'$Path\'");
    127148    }
    128149    chdir($In::Opt{"OrigDir"});
     150   
    129151    my @Classes = ();
    130152    foreach my $ClassPath (cmdFind($ExtractPath, "", "*\\.class"))
     
    177199    {
    178200        foreach my $SubArchive (cmdFind($ExtractPath, "", "*\\.jar"))
     201        { # recursive step
     202            readArchive($LVer, $SubArchive);
     203        }
     204       
     205        foreach my $SubArchive (cmdFind($ExtractPath, "", "*\\.jmod"))
    179206        { # recursive step
    180207            readArchive($LVer, $SubArchive);
     
    305332   
    306333    my $TmpDir = $In::Opt{"Tmp"};
     334    my $DumpFile = undef;
     335   
     336    if(defined $In::Opt{"Debug"})
     337    {
     338        if(my $DebugDir = getDebugDir($LVer))
     339        {
     340            mkpath($DebugDir);
     341            $DumpFile = $DebugDir."/class-dump.txt";
     342        }
     343    }
    307344   
    308345    # ! private info should be processed
     
    315352   
    316353    chdir($TmpDir."/".$ExtractCounter);
     354   
     355    my ($Err, $ErrMsg) = ();
     356   
    317357    my $Pid = open3(*IN, *OUT, *ERR, @Cmd);
     358    ($Err, $ErrMsg) = ($?, $!);
     359   
    318360    close(IN);
     361    close(ERR);
     362   
     363    chdir($In::Opt{"OrigDir"});
     364   
     365    if($Err==-1 and $Err>>8 and $ErrMsg) {
     366        exitStatus("Error", "failed to run javap (".$ErrMsg.")");
     367    }
    319368   
    320369    my (%TypeAttr, $CurrentMethod, $CurrentPackage, $CurrentClass, $CurrentClass_Short) = ();
     
    324373    my $InAnnotations_Class = undef;
    325374    my $InAnnotations_Method = undef;
    326     my %AnnotationName = ();
     375    my %ConstantTypeName = ();
    327376    my %AnnotationNum = (); # support for Java 7
     377    my %ConstantName = ();
    328378   
    329379    my ($ParamPos, $FieldPos) = (0, 0);
     
    331381   
    332382    my $DContent = "";
    333     my $Debug = (defined $In::Opt{"Debug"});
    334383   
    335384    while($Run)
     
    343392            }
    344393           
    345             if($Debug) {
     394            if(defined $In::Opt{"Debug"}) {
    346395                $DContent .= $LINE;
    347396            }
     
    463512                    $AName=~s/\//./g;
    464513                   
    465                     $AnnotationName{$CNum} = $AName;
     514                    $ConstantTypeName{$CNum} = $AName;
    466515                   
    467516                    if(defined $AnnotationNum{$CNum})
     
    471520                        }
    472521                        delete($AnnotationNum{$CNum});
     522                    }
     523                }
     524                elsif($LINE=~/=\s*(Utf8|Integer|Long|Float|Double)\s+(.*?)\Z/)
     525                {
     526                    if($1 eq "Utf8") {
     527                        $ConstantName{$CNum} = "\"".$2."\"";
     528                    }
     529                    else {
     530                        $ConstantName{$CNum} = $2;
    473531                    }
    474532                }
     
    557615                if($LINE=~/\A\s*\d+\:\s*#(\d+)/)
    558616                {
    559                     if(my $AName = $AnnotationName{$1})
     617                    if(my $AName = $ConstantTypeName{$1})
    560618                    {
    561619                        if($InAnnotations_Class) {
     
    678736            my $LINE_N = <OUT>;
    679737           
    680             if($Debug) {
     738            if(defined $In::Opt{"Debug"}) {
    681739                $DContent .= $LINE_N;
    682740            }
     
    758816           
    759817            my $LINE_NP = <OUT>;
    760             if($Debug) {
     818            if(defined $In::Opt{"Debug"}) {
    761819                $DContent .= $LINE_NP;
    762820            }
     
    773831           
    774832            $LINE_NP = <OUT>;
    775             if($Debug) {
     833            if(defined $In::Opt{"Debug"}) {
    776834                $DContent .= $LINE_NP;
    777835            }
     
    780838            { # flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL, ACC_ANNOTATION
    781839                $LINE_NP = <OUT>;
    782                 if($Debug) {
     840                if(defined $In::Opt{"Debug"}) {
    783841                    $DContent .= $LINE_NP;
    784842                }
     
    821879           
    822880            %TypeAttr = ("Type"=>$2, "Name"=>$3); # reset previous class
    823             %AnnotationName = (); # reset annotations of the class
     881            %ConstantTypeName = (); # reset annotations of the class
    824882            %AnnotationNum = (); # support for Java 7
     883            %ConstantName = ();
    825884            $InAnnotations_Class = 1;
    826885           
     
    923982            $InAnnotations = undef;
    924983        }
     984        elsif($CurrentMethod and index($LINE, "default_value")!=-1)
     985        {
     986            if($LINE=~/default_value:\s*[sISJBFDCZ]#(\d+)/)
     987            {
     988                if(defined $ConstantName{$1}) {
     989                    $MethodInfo{$LVer}{$MName_Mid{$CurrentMethod}}{"Default"} = $ConstantName{$1};
     990                }
     991            }
     992            elsif($LINE=~/default_value:\s*e#(\d+)\.#(\d+)/)
     993            {
     994                my ($ET, $EV) = ($1, $2);
     995                if(defined $ConstantTypeName{$ET} and defined $ConstantName{$EV})
     996                {
     997                    $ET = $ConstantTypeName{$ET};
     998                    $EV = $ConstantName{$EV};
     999                    $EV=~s/\"//g;
     1000                    $MethodInfo{$LVer}{$MName_Mid{$CurrentMethod}}{"Default"} = $ET.".".$EV;
     1001                }
     1002            }
     1003            elsif($LINE=~/default_value:\s*\[(.*)\]/)
     1004            {
     1005                my $Arr = $1;
     1006                if($Arr)
     1007                {
     1008                    my @ArrU = ();
     1009                    foreach my $ArrP (split(/\s*,\s*/, $Arr))
     1010                    {
     1011                        if($ArrP=~/[sISJBFDCZ]#(\d+)/) {
     1012                            push(@ArrU, $ConstantName{$1});
     1013                        }
     1014                    }
     1015                    $MethodInfo{$LVer}{$MName_Mid{$CurrentMethod}}{"Default"} = "{".join(",", @ArrU)."}";
     1016                }
     1017                else {
     1018                    $MethodInfo{$LVer}{$MName_Mid{$CurrentMethod}}{"Default"} = "{}";
     1019                }
     1020            }
     1021        }
    9251022        else
    9261023        {
     
    9351032   
    9361033    waitpid($Pid, 0);
    937     chdir($In::Opt{"OrigDir"});
    938    
    939     if(my $Err = $?>>8) {
    940         exitStatus("Error", "failed to run javap");
    941     }
     1034    close(OUT);
    9421035   
    9431036    if(not $NonEmpty) {
     
    9451038    }
    9461039   
    947     if($Debug) {
    948         appendFile(getDebugDir($LVer)."/class-dump.txt", $DContent);
     1040    if(defined $In::Opt{"Debug"}) {
     1041        appendFile($DumpFile, $DContent);
    9491042    }
    9501043}
Note: See TracChangeset for help on using the changeset viewer.