-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-jar.gradle
228 lines (180 loc) · 8.44 KB
/
build-jar.gradle
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/***************************************************************************
* Copyright (C) 2021 by Kyle Hayes *
* Author Kyle Hayes kyle.hayes@gmail.com *
* *
* This software is available under either the Mozilla Public License *
* version 2.0 or the GNU LGPL version 2 (or later) license, whichever *
* you choose. *
* *
* MPL 2.0: *
* *
* This Source Code Form is subject to the terms of the Mozilla Public *
* License, v. 2.0. If a copy of the MPL was not distributed with this *
* file, You can obtain one at http://mozilla.org/MPL/2.0/. *
* *
* *
* LGPL 2: *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
plugins {
id 'com.github.johnrengelman.shadow' version '6.0.0'
id 'maven-publish'
id 'java'
}
// The version is a little tricky because there are two parts:
// - The first part is the API version for Java.
// - The second part is the C DLL API supported.
version = "${project.libplctag4jProjectVersion}-${project.libplctagProjectVersion}"
group = "${project.projectGroupId}"
repositories {
jcenter()
google()
mavenCentral()
}
dependencies {
// we need JNA at compile time.
//implementation 'net.java.dev.jna:jna:5.6.0'
implementation group: 'net.java.dev.jna', name: 'jna', version: '5.8.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
// use the libplctag4j jar when testing. This gets the native DLLs.
testImplementation fileTree(dir: 'build/libs', include: ['*.jar'])
}
def getNativeLibrary(String srcZipBase) {
def srcZipUrl = "https://github.com/libplctag/libplctag/releases/download/v${project.libplctagProjectVersion}/${srcZipBase}"
def zipDirBase = "${rootDir}/external_zips"
def zipDir = new File(zipDirBase)
def localZipFile = new File("${zipDirBase}/${srcZipBase}")
def extractDirBase = zipDirBase + "/" + srcZipBase.take(srcZipBase.lastIndexOf('.'))
def extractDir = new File(extractDirBase)
// if zip folder does not exist, then make the folder
if (!zipDir.exists()) {
// need to make the directory in which we will check out the ZIPs.
zipDir.mkdirs()
}
// download
if (!localZipFile.exists()) {
ant.get(src: "${srcZipUrl}", dest: zipDir)
}
// unzip it.
if (localZipFile.exists() && !extractDir.exists()) {
extractDir.mkdirs()
ant.unzip(src: localZipFile, dest: extractDir)
}
//System.err.println("Returning extract dir base=" + extractDirBase)
return extractDirBase
}
task getLinuxX64NativeLibrary(type: Copy) {
def zipName = "libplctag_${project.libplctagProjectVersion}_ubuntu_x64.zip"
def targetFolderPath = "${rootDir}/native_libs/linux-x86-64/"
def targetFolder = new File(targetFolderPath)
def extractPathBase = getNativeLibrary("${zipName}")
def extractFileBase = "${extractPathBase}/libplctag.so"
def extractFile = new File(extractFileBase)
//System.err.println("extractFile=" + extractFile.path.toString())
from extractFile
into targetFolder
}
task getLinuxX86NativeLibrary(type: Copy) {
def zipName = "libplctag_${project.libplctagProjectVersion}_ubuntu_x86.zip"
def targetFolderPath = "${rootDir}/native_libs/linux-x86/"
def targetFolder = new File(targetFolderPath)
def extractPathBase = getNativeLibrary("${zipName}")
def extractFileBase = "${extractPathBase}/libplctag.so"
def extractFile = new File(extractFileBase)
//System.err.println("extractFile=" + extractFile.path.toString())
from extractFile
into targetFolder
}
task getWindowsX64NativeLibrary(type: Copy) {
def zipName = "libplctag_${project.libplctagProjectVersion}_windows_x64.zip"
def targetFolderPath = "${rootDir}/native_libs/win32-x86-64/"
def targetFolder = new File(targetFolderPath)
def extractPathBase = getNativeLibrary("${zipName}")
def extractFileBase = "${extractPathBase}/Release/plctag.dll"
def extractFile = new File(extractFileBase)
//System.err.println("extractFile=" + extractFile.path.toString())
from extractFile
into targetFolder
}
task getWindowsX86NativeLibrary(type: Copy) {
def zipName = "libplctag_${project.libplctagProjectVersion}_windows_x86.zip"
def targetFolderPath = "${rootDir}/native_libs/win32-x86/"
def targetFolder = new File(targetFolderPath)
def extractPathBase = getNativeLibrary("${zipName}")
def extractFileBase = "${extractPathBase}/Release/plctag.dll"
def extractFile = new File(extractFileBase)
//System.err.println("extractFile=" + extractFile.path.toString())
from extractFile
into targetFolder
}
task getMacOSX64NativeLibrary(type: Copy) {
def zipName = "libplctag_${project.libplctagProjectVersion}_macos_x64.zip"
def targetFolderPath = "${rootDir}/native_libs/darwin/"
def targetFolder = new File(targetFolderPath)
def extractPathBase = getNativeLibrary("${zipName}")
def extractFileBase = "${extractPathBase}/libplctag.dylib"
def extractFile = new File(extractFileBase)
//System.err.println("extractFile=" + extractFile.path.toString())
from extractFile
into targetFolder
}
shadowJar {
dependsOn classes, getLinuxX64NativeLibrary, getLinuxX86NativeLibrary, getWindowsX64NativeLibrary, getWindowsX86NativeLibrary, getMacOSX64NativeLibrary
archivesBaseName = 'libplctag4j'
archiveClassifier = ''
archiveVersion = "${project.libplctag4jProjectVersion}-${project.libplctagProjectVersion}"
// get the license files.
from {
["LICENSE-2.LGPL","LICENSE-1.MPL"]
}
from "${rootDir}/native_libs/"
}
publishing {
publications {
mavenJava(MavenPublication) {
pom {
name = "${project.projectName}"
description = 'A library for PLC communication'
url = "${project.projectOrg}"
licenses {
license {
name = 'MPL 2.0'
url = 'https://www.mozilla.org/en-US/MPL/2.0/'
}
license {
name = 'LGPL 2.1'
url = 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html'
}
}
developers {
developer {
name = 'Kyle Hayes'
email = 'kyle.hayes@gmail.com'
}
}
scm {
connection = "${project.projectScn}"
developerConnection = "${project.projectScn}"
projectIssueTracker = "${project.projectIssueTracker}"
url = "${project.projectUrl}"
}
}
from components.java
}
}
}