############################################################################### # CLASS BuildFile # Processes & Stores information from the build.pl file # # # By convention all members/methods that begin with an '_' are private. # ############################################################################### package DeployUtils::BuildFile; use strict; use File::Basename; use DeployUtils::Logger; #============================================================================== # Constructor #============================================================================== sub new { my $obclass = shift; my $class = ref($obclass) || $obclass; my $buildFile = shift; $buildFile = "build.pl" if ( ! defined($buildFile) ); LogDebug("BuildFile::new Instantiating new object of class $class"); bless my $self = { _FILENAME => $buildFile, _BUILDNAME => "", _BUILDNAME_LC => "", _BUILDVERSION => "", _PLATFORMS => [], _INTERFACE => "", _DIRTREE => [], _PREVVERSION => "", _DPKGARCHIVE => {} } => ( $class ); $self->_buildInfo(); return($self); } # new sub _buildInfo { my $self = shift; my $temp; open( BUILD, $self->{_FILENAME}) || LogError("Cannot Open $self->{_FILENAME}"); nextline: while ( ) { chomp; goto nextline if ( /^\s*(\#|$)/ ); if ( /BuildName\s*\(\s*[\'\"](.+?)[\'\"]\s*,\s*[\'\"](.+?)[\'\"]/) { $self->{_BUILDNAME} = $self->{_BUILDNAME_LC} = $1; $self->{_BUILDNAME_LC} =~ tr/A-Z/a-z/; $self->{_BUILDVERSION} = $2; LogDebug("BuildFile::_buildInfo Set BuildName = $self->{_BUILDNAME}"); LogDebug("BuildFile::_buildInfo Set BuildNameLc = $self->{_BUILDNAME_LC}"); LogDebug("BuildFile::_buildInfo Set BuildVersion = $self->{_BUILDVERSION}"); } elsif ( /(BuildPkgArchive|LinkPkgArchive)\s*\(\s*\'([^\'\"]*)\'\s*,\s*\'([^\'\"]*).*$/ ) { my ( $type, $module, $version ) = ( $1, $2, $3 ); LogError("BuildFile::_buildInfo Duplicate Dpkg_Archive found $module") if ( defined($self->{_DPKGARCHIVE}{$module}) ); # we assume the version string could contain the following # format types # # N.N.N.pp # N.N.N.ppp # N.N.N.pppp # N.N.N # beta # beta.ppp # *.cots # *.singapore # my ( $proj, $versionNum ) = ( "", ""); if ( $version =~ m/^([0-9]*\.[0-9]*\.[0-9]*)\.([a-z]{2,4})$/ ) # N.N.N.pp, N.N.N.ppp, N.N.N.pppp { $versionNum = "$1"; $proj = "$2"; } elsif ( $version =~ m/^[0-9]*\.[0-9]*\.[0-9]*$/ ) # N.N.N { $versionNum = "$version"; } elsif ( $version =~ m/^[aA-zZ]*\.[a-z][a-z][a-z]$/ ) # beta.ppp { ($versionNum, $proj) = split /\./, $version; } elsif ( $version =~ m/^[aA-zZ]*$/ ) # beta { $versionNum = "$version"; } elsif ( $version =~ m/^(.*)\.(cots|singapore)$/ ) # *.cots, #.singapore { $versionNum = "$1"; $proj = "$2"; } else { # here we just assume the version is the version # what else can we do... $versionNum = $version; } $self->{_DPKGARCHIVE}{$module}{type} = $type; $self->{_DPKGARCHIVE}{$module}{version} = $versionNum; $self->{_DPKGARCHIVE}{$module}{versionFull} = $version; $self->{_DPKGARCHIVE}{$module}{proj} = $proj; LogDebug("BuildFile::_buildInfo Set Added dpkg Archive $module = $type, $versionNum, $proj"); } elsif ( /BuildPlatforms\s*\(\s*(.*)\s*\)/ ) { $temp = $1; $temp =~ s/[\'\"]//g; $temp =~ s/\s//g; push(@{$self->{_PLATFORMS}}, split(",", $temp)); LogDebug("BuildFile::_buildInfo Set Platforms $temp"); } elsif ( /BuildInterface\s*\(\s*[\'\"](.+?)[\'\"]/ ) { $self->{_INTERFACE} = $1; LogDebug("BuildFile::_buildInfo Set Interface to $self->{_INTERFACE}"); } elsif ( /BuildDirTree\s*\(\s*(.*)\s*\)/ ) { $temp = $1; $temp =~ s/[\'\"]//g; $temp =~ s/\s//g; push(@{$self->{_DIRTREE}}, split(",", $temp)); LogDebug("BuildFile::_buildInfo Set DirTree to $temp"); } elsif ( /BuildPreviousVersion\s*\(\s*[\'\"](.+?)[\'\"]/ ) { $self->{_PREVVERSION} = $1; LogDebug("BuildFile::_buildInfo Set BuildPrevVersion = $self->{_PREVVERSION}"); } } } #============================================================================== # dumpSelf, debugging member to dump selfs hash #============================================================================== sub dumpSelf { use Data::Dumper; my $self = shift; print Data::Dumper->Dump([$self], [ref($self)]); } # dumpSelf # Returns the buildName as a string sub getBuildName { my $self = shift; return $self->{_BUILDNAME}; } # Returns the buildName in Lower case as a string sub getBuildNameLc { my $self = shift; return $self->{_BUILDNAME_LC}; } # Returns the buildVersion as a string sub getBuildVersion { my $self = shift; return $self->{_BUILDVERSION}; } # Returns the Interface as a string sub getInterface { my $self = shift; return $self->{_INTERFACE}; } # Returns the previous Version as a string sub getPreviousVersion { my $self = shift; return $self->{_PREVVERSION}; } # Returns an array containing the platforms defined sub getPlatforms { my $self = shift; return @{$self->{_PLATFORMS}}; } # Returns an array containing the DirTree sub getDirTree { my $self = shift; return @{$self->{_DIRTREE}}; } # returns a list of Modules in the DpkgArchive Hash sub getDpkgArchiveList { my $self = shift; return sort keys %{$self->{_DPKGARCHIVE}}; } # returns a reference to a hash that contains the details of for the module passed # The hash contains keys for type, version, proj sub getDpkgArchiveInfo { my $self = shift; my $module = shift; if ( ! defined($module) || ! defined($self->{_DPKGARCHIVE}{$module}) ) { return undef; } else { return \%{$self->{_DPKGARCHIVE}{$module}}; } } # Returns a complete copy of the DPKG_Archive hash sub getDpkgArchiveHash { my $self = shift; return %{$self->{_DPKGARCHIVE}}; } sub getDpkgArchiveType { my $self = shift; my $module = shift; if ( ! defined($module) || ! defined($self->{_DPKGARCHIVE}{$module}) ) { return undef; } else { return $self->{_DPKGARCHIVE}{$module}{type}; } } sub getDpkgArchiveVersionNum { my $self = shift; my $module = shift; if ( ! defined($module) || ! defined($self->{_DPKGARCHIVE}{$module}) ) { return undef; } else { return $self->{_DPKGARCHIVE}{$module}{version}; } } sub getDpkgArchiveVersionFull { my $self = shift; my $module = shift; if ( ! defined($module) || ! defined($self->{_DPKGARCHIVE}{$module}) ) { return undef; } else { return $self->{_DPKGARCHIVE}{$module}{versionFull}; } } sub getDpkgArchiveVersionProj { my $self = shift; my $module = shift; if ( ! defined($module) || ! defined($self->{_DPKGARCHIVE}{$module}) ) { return undef; } else { return $self->{_DPKGARCHIVE}{$module}{proj}; } } 1;