-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLicenseStrategy.pm
130 lines (78 loc) · 2.24 KB
/
CLicenseStrategy.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl
use warnings;
use strict;
package CLicenseStrategy;
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.*?\*\//is )
{
my $license = $self->prepareLicense( $file->{ _filePath });
$file->{ _fileContentsString } =~ s/(\/\*.*?copyright.*?wind river.*?\*\/)/$license/is;
Logger->new()->log( 1 , "REPLACED HEADER: " . $file->{ _filePath } . "\n" );
return 1;
}
return 0;
}
sub addHeader
{
my $self = shift;
my $file = shift;
my $license = $self->prepareLicense( $file->{ _filePath } );
if( $file->{ _fileContentsString } =~ m/\Q$license/s )
{
return 0;
}
Logger->new()->log( 3 , "add header: " . $file->{ _filePath } );
$file->{ _fileContentsString } = $license . $file->{ _fileContentsString };
Logger->new()->log( 1 , "ADDED HEADER: " . $file->{ _filePath } . "\n" );
return 1;
}
sub replaceDefine
{
my $self = shift;
my $file = shift;
Logger->new()->log( 3 , "replace define: " . $file->{ _filePath } );
if ( $file->{ _fileContentsString } =~ m/(?<=define).*?\".*?Wind River.*?\"/i )
{
my $copyrightDefine = "Copyright (c) $self->{ _StartYear }-$self->{ _CurrYear }, Intel Corporation";
if( $file->{ _fileContentsString } =~ s/\".*?Copyright.*?Wind River.*?\"/"$copyrightDefine"/ig )
{
Logger->new()->log( 1 , "REPLACED DEFINE: " . $file->{ _filePath } . "\n" );
return 1;
}
}
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 = "/*";
foreach my $line( @licenseText )
{
$line =~ s/STARTDATE/\Q$start_year/g;
$line =~ s/ENDDATE/\Q$curr_year/g;
$retVal .= " " . $line;
$retVal .= "\n *";
}
$retVal .= "/\n";
return $retVal;
}
1;