-
Notifications
You must be signed in to change notification settings - Fork 0
/
XMLLicenseStrategy.pm
83 lines (56 loc) · 1.35 KB
/
XMLLicenseStrategy.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl
use warnings;
use strict;
package XMLLicenseStrategy;
use LicenseStrategy;
our @ISA = ( "LicenseStrategy" );
sub new()
{
my ( $class ) = @_;
my $self = $class->SUPER::new();
bless( $self , $class );
return $self;
}
sub replaceHeader
{
my $self = shift;
my $file = shift;
Logger->new()->log( 3 , "replace header: " . $file->{ _filePath } );
if ( $file->{ _fileContentsString } =~ m/<!--.*copyright.*wind river.[^\n]*\.\s?-->/is )
{
my $license = $self->prepareLicense( $file->{ _filePath });
$file->{ _fileContentsString } =~ s/(<!--.*copyright.*wind river.[^\n]*\.\s?-->)/$license/is;
Logger->new()->log( 1 , "REPLACED HEADER: " . $file->{ _filePath } . "\n" );
return 1;
}
return 0;
}
sub addHeader
{
return 0;
}
sub replaceDefine
{
return 0;
}
sub prepareLicense
{
my $self = shift;
my $filename = shift;
my $licensePath = LicenseStrategy::getLicense($filename);
Logger->new()->log( 3 , "use license: $licensePath" );
my @licenseText = FileManager->new()->readFile( $licensePath );
my $start_year = $self->{ _StartYear };
my $curr_year = $self->{ _CurrYear };
my $retVal = "<!--\n";
foreach my $line( @licenseText )
{
$line =~ s/STARTDATE/\Q$start_year/g;
$line =~ s/ENDDATE/\Q$curr_year/g;
$retVal .= "\t" . $line;
$retVal .= "\n";
}
$retVal .= "-->";
return $retVal;
}
1;