-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.pm
117 lines (89 loc) · 2.2 KB
/
file.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
#!/usr/bin/perl
use warnings;
use strict;
package File;
use LicenseStrategy;
sub new()
{
my $class = shift;
my $filename = shift;
my @fileContentsArray = ();
my $fileContentsString = "";
my $self =
{
_filePath => $filename,
_fileContentsArray => \@fileContentsArray,
_fileContentsString => \$fileContentsString
};
bless( $self , $class );
return $self;
}
sub open
{
my $self = shift;
Logger->new()->log( 3 , "\nopened: " . $self->{ _filePath } );
@{ $self->{ _fileContentsArray } } = FileManager->new()->readFile( $self->{ _filePath } );
$self->{ _fileContentsString } = Utils->new()->arrayToString( \@{ $self->{ _fileContentsArray } } );
}
sub close
{
my $self = shift;
FileManager->new()->writeFile( $self->{ _filePath } , $self->{ _fileContentsString } );
@{ $self->{ _fileContentsArray } } = undef;
$self->{ _fileContentsString } = undef;
Logger->new()->log( 3 , "closed: " . $self->{ _filePath } );
}
sub scan
{
my $self = shift;
$self->open();
Logger->new()->log( 3 , "scanning: " . $self->{ _filePath } );
my $strategy = LicenseStrategy::getStategyInstance($self);
my $headerReplaced = 0;
my $defineReplaced;
my $lineNum = 0;
foreach my $line ( @{ $self->{ _fileContentsArray } } )
{
if( $line =~ m/Wind\s?River/ig )
{
if ( $headerReplaced != 1 && $line =~ m/(?<!define).*?copyright.*?/i )
{
$headerReplaced = $strategy->replaceHeader($self); #returns 1 if regex substitution occurs
if ($headerReplaced == 1) #prevent windriver log for occurrence if it has been acted upon
{
next;
}
}
if( $line =~ m/(?<=define).*?copyright.*?/i)
{
$defineReplaced = $strategy->replaceDefine($self);
if ($defineReplaced == 1) #prevent windriver logging for occurence if it has been acted upon
{
next;
}
}
Logger->new()->log( 2 , "Line:" . $lineNum . "," . $self->{ _filePath } . "\n" );
Logger->new()->log( 2 , "\t$line\n" );
}
$lineNum++;
}
if ( $headerReplaced != 1 )
{
$strategy->addHeader($self);
}
$self->close();
}
sub set
{
my $self = shift;
my $key = shift;
my $value = shift;
$self->{ $key } = $value;
}
sub get
{
my $self = shift;
my $key = shift;
return $self->{ $key };
}
1;