-
Notifications
You must be signed in to change notification settings - Fork 37
/
InspectHeadersNet.groovy
179 lines (154 loc) · 6.22 KB
/
InspectHeadersNet.groovy
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env groovy
package com.itextpdf.copyright
import groovy.cli.commons.CliBuilder
import groovy.ant.FileNameFinder
void processScript(String... args) {
def time = System.currentTimeMillis()
def date = Calendar.getInstance()
def scriptDir = ""
def inclList = ""
def cli = new CliBuilder()
cli.h(type: Boolean, 'help')
cli.i(type: String, longOpt: 'includePattern', 'pattern in Ant\'s fileset format')
cli.d(type: String, longOpt: 'dir', 'base dir for search (LICENSE.md should be present in destination folder)')
def options = cli.parse(args)
if (options == null) {
throw new ScriptException("", 101)
}
if ( options.h ) {
cli.usage()
throw new ScriptException("", 0)
}
if ( options.i ) {
inclListFile = options.i
println "Including files in list '$inclListFile'"
new File(inclListFile).eachLine { line ->
inclList = inclList + " " + line
}
} else {
println "Including all files"
inclList = '**/*.java **/*.cs **/*.nuspec'
}
if ( options.arguments()[0] ) {
scriptDir = options.arguments()[0].trim()
} else if (options.d) {
scriptDir = options.d.trim()
} else {
scriptDir = new File("").getAbsolutePath()
}
println "Starting groovy script @ $scriptDir"
def licenseFile = new File("${scriptDir}/LICENSE.md")
println "licenseFile is ${licenseFile.canonicalPath}"
copyrightYear = "Copyright (c) 1998-" + date.get(Calendar.YEAR) + " Apryse Group NV"
def sb = new StringBuilder()
sb << "/*\n"
sb << "This file is part of the iText (R) project.\n"
sb << "" + copyrightYear
sb << "\n"
sb << "Authors: Apryse Software.\n\n"
sb << licenseFile.text
sb << " \n*/\n"
copyrightText = sb.toString()
def producerLine = /private static final String producerLine = iTextProductName \+ " " \+ release \+ " \\u00a92000-.*?Apryse Group NV";/
def sourceFolder = new File(scriptDir)
if ( ! sourceFolder.directory ) {
println "${sourceFolder.name} is not an existing folder"
println "Aborting port attempt"
return
} else {
println "Source folder is ${sourceFolder.canonicalPath}"
}
def other_copyrights = [
"Adobe" : /Copyright .* Adobe Systems Incorporated/,
"Apache" : /Copyright .* Apache Software Foundation/,
"AL2.0" : /Apache License, Version 2.0/,
"ZXing" : /Copyright .* ZXing authors/,
"Sun" : /Copyright .* Sun Microsystems, Inc./,
"Fontbox" : /Copyright .* www.fontbox.org/,
"SGI" : /Copyright .* Silicon Graphics, Inc./,
"Clipper" : /Copyright .* Angus Johnson/,
"Oracle" : /Copyright .* Oracle/,
"Zlib" : /Copyright .* ymnk, JCraft,Inc./,
"zlib" : /Copyright .* Lapo Luchini/,
"sboxes" : /Copyright: .* Dr B. R Gladman/,
"iharder" : /@author Robert Harder/,
"Google" : /Copyright .* Google Inc./,
"MIT" : /Distributed under MIT license/
]
// needed when run on Windows
if ( File.separator.equals("\\") ) {
inclList = inclList.replace("/", "\\\\")
}
fileList = new FileNameFinder().getFileNames(scriptDir, inclList)
fileList.each {fileStr ->
File file = new File(fileStr)
skip = false
def content = new StringBuilder()
def changed = false
if ( file.name.endsWith("package-info.java") ) {
skip = true
}
if ( file.canonicalPath.contains("itext.kernel/bouncycastle") ) {
skip = true
}
other_copyrights.each { author, copyright ->
if ( file.text.find(copyright) ) {
skip = true
}
}
if ( !skip ) {
copyright = /Copyright .* Apryse/
if ( file.text.find(copyright) ) {
file.eachLine('UTF-8') { line ->
if ( line.find(copyright) && !line.find(date.get(Calendar.YEAR) + "") ) {
println "[YEAR] ${line} - ${file.canonicalPath}"
if ( file.name.endsWith("AssemblyInfo.cs") ) {
content << "[assembly: AssemblyCopyright(\"" + copyrightYear + "\")]"
} else if ( file.name.endsWith(".nuspec") ) {
content << "" + "<copyright>${copyrightYear}</copyright>"
} else {
content << "" + copyrightYear
}
changed = true
} else {
content << line
}
content << "\n"
}
} else {
println "[MISSING] Copyright added to ${file.canonicalPath}"
content << copyrightText
content << file.getText('UTF-8')
changed = true
}
if ( changed ) {
file.write(content.toString(), "UTF8")
}
}
copyrightTo = "COPYRIGHT_TO = .*?;"
if (file.name.contains("ProductData")) {
String contents = file.getText('UTF-8')
contents = contents.replaceAll( copyrightTo , "COPYRIGHT_TO = " + date.get(Calendar.YEAR) + ";")
file.write(contents, "UTF-8")
}
// the following block of code makes sense only for 7.1. Drop these lines when 7.1 is no longer supported
if ( file.absolutePath.endsWith("kernel" + File.separator + "Version.java") ) {
String contents = file.getText('UTF-8')
contents = contents.replaceAll( producerLine, 'private static final String producerLine = iTextProductName + " " + release + " \\\\u00a92000-' + date.get(Calendar.YEAR) + ' iText Group NV";' )
file.write(contents, "UTF-8")
}
}
println "\nCopyright check took " + ( ( System.currentTimeMillis() - time ) / 1000 ) + " seconds."
}
class ScriptException extends Exception {
int exitCode
ScriptException(String message, int exitCode) {
super(message)
this.exitCode = exitCode
}
}
try {
processScript(args)
} catch (ScriptException e) {
System.exit(e.exitCode)
}