Skip to content

Commit 0e83c9e

Browse files
committed
Switch from Maven to a Gradle build.
1 parent 18e8af2 commit 0e83c9e

File tree

7 files changed

+605
-2
lines changed

7 files changed

+605
-2
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
/javadoc.xml
88
*.class
99
/*.jardesc
10-
*.jar
1110
*.war
1211
*.ear
1312
/local.properties
@@ -17,5 +16,9 @@
1716
*.iml
1817
*.iws
1918

20-
# Maven
19+
# Gradle
20+
**/.gradle
2121
/build/
22+
/buildSrc/build/
23+
24+
/CHANGES.txt

build.gradle

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
plugins {
2+
id 'java-library'
3+
id 'maven-publish'
4+
id 'de.jjohannes.extra-java-module-info' version '0.11'
5+
}
6+
7+
group = 'io.sf.carte'
8+
version = '1.3.0'
9+
10+
description = 'css4j-awt'
11+
12+
dependencies {
13+
api('io.sf.carte:css4j') {
14+
version {
15+
strictly '[1.3.0,2.0['
16+
prefer '1.3.1'
17+
}
18+
}
19+
testImplementation(group: 'io.sf.carte', name: 'css4j', classifier: 'tests') {
20+
version {
21+
strictly '[1.3.0,2.0['
22+
prefer '1.3.1'
23+
}
24+
}
25+
testImplementation 'nu.validator:htmlparser:1.4.16'
26+
testImplementation('org.slf4j:slf4j-api') {
27+
version {
28+
strictly '[1.7.28,)'
29+
prefer '1.7.35'
30+
}
31+
}
32+
testImplementation 'junit:junit:4.13.2'
33+
}
34+
35+
extraJavaModuleInfo {
36+
failOnMissingModuleInfo.set(false)
37+
automaticModule('htmlparser-1.4.16.jar', 'htmlparser')
38+
automaticModule('sac-1.3.jar', 'sac')
39+
}
40+
41+
java {
42+
sourceCompatibility = JavaVersion.VERSION_1_7
43+
targetCompatibility = JavaVersion.VERSION_1_7
44+
withJavadocJar()
45+
withSourcesJar()
46+
}
47+
48+
repositories {
49+
maven {
50+
url = uri('https://repo.maven.apache.org/maven2/')
51+
}
52+
maven {
53+
url "https://css4j.github.io/maven/"
54+
mavenContent {
55+
releasesOnly()
56+
}
57+
content {
58+
includeGroup 'io.sf.carte'
59+
includeGroup 'io.sf.jclf'
60+
}
61+
}
62+
}
63+
64+
sourceSets {
65+
main {
66+
java {
67+
srcDirs = ['src']
68+
includes += ["**/*.java"]
69+
}
70+
resources {
71+
srcDirs = ['src']
72+
excludes += ["**/*.java"]
73+
}
74+
}
75+
test {
76+
java {
77+
srcDirs = ['junit']
78+
includes += ["**/*.java"]
79+
}
80+
resources {
81+
srcDirs = ['junit']
82+
excludes += ["**/*.java"]
83+
}
84+
}
85+
}
86+
87+
tasks.compileJava {
88+
excludes += ['module-info.java']
89+
modularity.inferModulePath = false
90+
}
91+
92+
tasks.register('compileModuleInfo', JavaCompile) {
93+
description = 'Compile module-info to Java 11 bytecode'
94+
dependsOn tasks.compileJava
95+
sourceCompatibility = JavaVersion.VERSION_11
96+
targetCompatibility = JavaVersion.VERSION_11
97+
source = sourceSets.main.java
98+
classpath = sourceSets.main.compileClasspath
99+
destinationDirectory = sourceSets.main.java.destinationDirectory
100+
modularity.inferModulePath = true
101+
includes = ['module-info.java']
102+
}
103+
104+
classes.dependsOn compileModuleInfo
105+
106+
// Check bytecode version, in case some other task screws it
107+
tasks.register('checkLegacyJava') {
108+
description = 'Check that classes are Java 7 bytecode (except module-info)'
109+
def classdir = sourceSets.main.output.classesDirs.files.stream().findAny().get()
110+
def classfiles = fileTree(classdir).matching({it.exclude('module-info.class')}).files
111+
doFirst() {
112+
if (!classfiles.isEmpty()) {
113+
def classfile = classfiles.stream().findAny().get()
114+
if (classfile != null) {
115+
def classbytes = classfile.bytes
116+
def bcversion = classbytes[6] * 128 + classbytes[7]
117+
if (bcversion != 51) {
118+
throw new GradleException("Bytecode on " + classfile +
119+
" is not valid Java 7. Version should be 51, instead is " + bcversion)
120+
}
121+
}
122+
}
123+
}
124+
}
125+
126+
classes.finalizedBy checkLegacyJava
127+
128+
tasks.register('lineEndingConversion', CRLFConvert) {
129+
file "$rootDir/LICENSE.txt"
130+
file "$rootDir/CHANGES.txt"
131+
file "$rootDir/RELEASE_NOTES.txt"
132+
}
133+
134+
tasks.register('cleanBuildSrc') {
135+
description = 'Clean the buildSrc directory'
136+
doLast {
137+
delete("$rootDir/buildSrc/build")
138+
}
139+
}
140+
141+
tasks.named('clean') {
142+
finalizedBy('cleanBuildSrc')
143+
}
144+
145+
tasks.withType(JavaCompile) {
146+
options.encoding = 'UTF-8'
147+
}
148+
149+
tasks.withType(Javadoc) {
150+
options.addStringOption('Xdoclint:none', '-quiet')
151+
options.addStringOption('encoding', 'UTF-8')
152+
options.addStringOption('charset', 'UTF-8')
153+
options.links 'https://docs.oracle.com/en/java/javase/11/docs/api/'
154+
options.links 'https://css4j.github.io/api/1.0/'
155+
}
156+
157+
tasks.withType(AbstractArchiveTask).configureEach {
158+
// Reproducible build
159+
preserveFileTimestamps = false
160+
reproducibleFileOrder = true
161+
// Copy license file
162+
dependsOn lineEndingConversion
163+
from ('LICENSE.txt') {
164+
into 'META-INF'
165+
}
166+
}
167+
168+
tasks.withType(PublishToMavenRepository) { task ->
169+
doFirst {
170+
if (repository == publishing.repositories.getByName('mavenRepo')) {
171+
logger.lifecycle "Deploying artifacts to \"${it.repository.url}\""
172+
}
173+
}
174+
}
175+
176+
publishing {
177+
publications {
178+
maven(MavenPublication) {
179+
description = 'css4j AWT module'
180+
from(components.java)
181+
pom {
182+
description = 'css4j AWT module'
183+
url = "https://github.com/css4j/css4j-awt/"
184+
licenses {
185+
license {
186+
name = "BSD 3-clause license"
187+
url = "https://css4j.github.io/LICENSE.txt"
188+
}
189+
}
190+
}
191+
}
192+
}
193+
repositories {
194+
maven {
195+
name = 'mavenRepo'
196+
/*
197+
* The following section applies to the 'publish' task:
198+
*
199+
* If you plan to deploy to a repository, please configure the
200+
* 'mavenReleaseRepoUrl' and/or 'mavenSnapshotRepoUrl' properties
201+
* (for example in GRADLE_USER_HOME/gradle.properties).
202+
*
203+
* Otherwise, Gradle shall create a 'build/repository' subdirectory
204+
* at ${rootDir} and deploy there.
205+
*
206+
* Properties 'mavenRepoUsername' and 'mavenRepoPassword' can also
207+
* be set (generally from command line).
208+
*/
209+
def releasesUrl
210+
def snapshotsUrl
211+
if (project.hasProperty('mavenReleaseRepoUrl') && project.mavenReleaseRepoUrl) {
212+
releasesUrl = mavenReleaseRepoUrl
213+
} else {
214+
releasesUrl = "${buildDir}/repository/releases"
215+
}
216+
if (project.hasProperty('mavenSnapshotRepoUrl') && project.mavenSnapshotRepoUrl) {
217+
snapshotsUrl = mavenSnapshotRepoUrl
218+
} else {
219+
snapshotsUrl = "${buildDir}/repository/snapshots"
220+
}
221+
url = version.endsWith('-SNAPSHOT') ? snapshotsUrl : releasesUrl
222+
if (project.hasProperty('mavenRepoUsername') &&
223+
project.hasProperty('mavenRepoPassword')) {
224+
credentials.username = mavenRepoUsername
225+
credentials.password = mavenRepoPassword
226+
}
227+
}
228+
}
229+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import org.gradle.api.DefaultTask
2+
import org.gradle.api.tasks.TaskAction
3+
4+
/**
5+
* Converts line endings to CRLF (Windows)
6+
* <p>
7+
* Usage:
8+
* </p>
9+
* <code>
10+
* tasks.register('lineEndingConversion', CRLFConvert) {
11+
* file "path/to/file1.txt"
12+
* file "path/to/fileN.txt"
13+
* }
14+
* </code>
15+
*/
16+
class CRLFConvert extends DefaultTask {
17+
18+
private static final String CRLF = "\r\n"
19+
private static final String LF = "\n"
20+
21+
private files = []
22+
23+
@TaskAction
24+
def action() {
25+
files.each { path ->
26+
File file = new File(path)
27+
if (file.exists()) {
28+
String content = file.text
29+
String newContent = content.replaceAll(/\r\n/, LF)
30+
newContent = newContent.replaceAll(/\n|\r/, CRLF)
31+
if (content != newContent) {
32+
file.write(newContent)
33+
}
34+
} else {
35+
logger.warn('File ' + path + ' does not exist.')
36+
}
37+
}
38+
}
39+
40+
def file(String path) {
41+
this.files << path
42+
}
43+
}

gradle/wrapper/gradle-wrapper.jar

58.4 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)