-
Notifications
You must be signed in to change notification settings - Fork 0
/
LicenseStrategy.pm
147 lines (115 loc) · 2.28 KB
/
LicenseStrategy.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/perl
use warnings;
use strict;
package LicenseStrategy;
use CLicenseStrategy;
use PythonLicenseStrategy;
use MakefileLicenseStrategy;
use XMLLicenseStrategy;
use CopyingLicenseStrategy;
sub new()
{
my $class = shift;
my $file = shift;
my $curr_year = Utils->new()->getTime("year");
my $self =
{
_StartYear => 2011,
_CurrYear => $curr_year
};
bless( $self , $class );
return $self;
}
sub getStategyInstance
{
my $file = shift;
my $ext = "";
if( $file->{ _filePath } =~ m/(\.[^.]+)$/ )
{
$ext = $1;
}
my $strategy;
if( $ext eq ".cpp" || $ext eq ".c" || $ext eq ".h" || $ext eq ".onsi" || $ext eq ".i" )
{
$strategy = new CLicenseStrategy();
}
elsif( $ext eq ".py" || $ext eq ".mk" )
{
$strategy = new PythonLicenseStrategy();
}
elsif( $ext eq ".am" || $ext eq ".ac")
{
$strategy = new MakefileLicenseStrategy();
}
elsif( $ext eq ".xml" )
{
$strategy = new XMLLicenseStrategy();
}
elsif( $file->{ _filePath } =~ m/\/COPYING$/i )
{
$strategy = new CopyingLicenseStrategy();
}
else
{
$strategy = new LicenseStrategy();
}
return $strategy;
}
sub getLicense
{
my $filename = shift;
my $license = "source_code_license";
my $keyHolder = undef;
foreach my $key ( keys %{ ${ BillOfMaterials->new()->{ _licensingListing } } })
{
if ($filename =~ m/($key)/i)
{
if(defined $keyHolder)
{
if (length($1) > length($keyHolder))
{
$keyHolder = $1;
$license = ${ BillOfMaterials->new()->{ _licensingListing } }->{ $key }
}
}
else
{
$keyHolder = $1;
$license = ${ BillOfMaterials->new()->{ _licensingListing } }->{ $key };
}
}
}
my $licensePath = $Utils::scriptPath . "/licenses/" . $license;
return $licensePath;
}
sub replaceHeader
{
return 0;
}
sub addHeader
{
return 0;
}
sub replaceDefine
{
return 0;
}
sub prepareLicense
{
my $self = shift;
my $filename = shift;
my $licensePath = LicenseStrategy::getLicense($filename);
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";
}
return $retVal;
}
1;