Skip to content

Commit da171e5

Browse files
committed
Switch from Maven to a Gradle build.
1 parent 8f6efac commit da171e5

File tree

10 files changed

+693
-122
lines changed

10 files changed

+693
-122
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

README.md

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,83 @@
11
# css4j - agent module
22

3-
This provides user agent-related functionality to CSS4J. Licence is BSD 3-clause, but includes a file with another licence (see `LICENSES.txt`).
3+
This provides user agent-related functionality to CSS4J.
44

5-
Refer to the `css4j` or `css4j-dist` repositores for build instructions.
5+
[License](LICENSE.txt) is BSD 3-clause, but includes a file with another license
6+
(see [`LICENSES.txt`](LICENSES.txt)).
67

8+
<br/>
9+
10+
## Java™ Runtime Environment requirements
11+
All the classes in the binary package have been compiled with a [Java compiler](https://adoptium.net/)
12+
set to 1.7 compiler compliance level, except the `module-info.java` file.
13+
14+
Building this module requires JDK 11 or higher.
15+
16+
<br/>
17+
18+
## Build from source
19+
To build css4j-agent from the code that is currently at the Git repository, Java 11 or later is needed.
20+
You can run a variety of Gradle tasks with the Gradle wrapper (on Windows shells you can omit the `./`):
21+
22+
- `./gradlew build` (normal build)
23+
- `./gradlew build publishToMavenLocal` (to install in local Maven repository)
24+
- `./gradlew lineEndingConversion` (to convert line endings of top-level text files to CRLF)
25+
- `./gradlew publish` (to deploy to a Maven repository, as described in the `publishing.repositories.maven` block of
26+
[build.gradle](https://github.com/css4j/css4j-agent/blob/1-stable/build.gradle))
27+
28+
<br/>
29+
30+
## Usage from a Gradle project
31+
If your Gradle project depends on css4j-agent, you can use this project's own Maven repository in a `repositories` section of
32+
your build file:
33+
```groovy
34+
repositories {
35+
maven {
36+
url "https://css4j.github.io/maven/"
37+
mavenContent {
38+
releasesOnly()
39+
}
40+
content {
41+
includeGroup 'io.sf.carte'
42+
includeGroup 'io.sf.jclf'
43+
}
44+
}
45+
}
46+
```
47+
please use this repository **only** for the artifact groups listed in the `includeGroup` statements.
48+
49+
Then, in your `build.gradle` file:
50+
```groovy
51+
dependencies {
52+
api "io.sf.carte:css4j-agent:${css4jAgentVersion}"
53+
}
54+
```
55+
where `css4jAgentVersion` would be defined in a `gradle.properties` file.
56+
57+
<br/>
58+
59+
## Software dependencies
60+
61+
In case that you do not use a Gradle or Maven build (which would manage the
62+
dependencies according to the relevant `.module` or `.pom` files), the required
63+
and optional library packages are the following:
64+
65+
### Compile-time dependencies
66+
67+
- The [css4j](https://github.com/css4j/css4j/releases) library (and its transitive
68+
dependencies); version 1.3.1 or higher (but below 2.x) is recommended.
69+
70+
- The [validator.nu html5 parser](https://about.validator.nu/htmlparser/).
71+
72+
- [SLF4J](http://www.slf4j.org/), which is a logging package.
73+
74+
### Test dependencies
75+
76+
- A recent version of [JUnit 4](https://junit.org/junit4/).
77+
78+
- The [validator.nu html5 parser](https://about.validator.nu/htmlparser/).
79+
80+
<br/>
81+
82+
## Website
83+
For more information please visit https://css4j.github.io/

build.gradle

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