Skip to content

Commit 784e740

Browse files
committed
Gradle: stand-alone build, independent from css4j-dist.
1 parent b07a3c1 commit 784e740

File tree

9 files changed

+645
-19
lines changed

9 files changed

+645
-19
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
*.iws
1919

2020
# Gradle
21-
/.gradle
21+
**/.gradle
2222
/build/
23+
/buildSrc/build/
24+
25+
/CHANGES.txt

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,47 @@
33
This provides user agent-related functionality to CSS4J. Licence is BSD 3-clause, but includes a file with another licence
44
(see `LICENSES.txt`).
55

6-
Refer to the `css4j` or `css4j-dist` repositories for build instructions.
6+
## Build from source
7+
To build css4j-agent from the code that is currently at the Git repository, you need a current JDK (the build is tested with
8+
version 16). You can run a variety of Gradle tasks with the Gradle wrapper (on Unix-like systems you may need to type `./gradlew`):
79

10+
- `gradlew build` (normal build)
11+
- `gradlew build publishToMavenLocal` (to install in local Maven repository)
12+
- `gradlew copyJars` (to copy jar files into a top-level _jar_ directory)
13+
- `gradlew lineEndingConversion` (to convert line endings of top-level text files to CRLF)
14+
- `gradlew publish` (to deploy to a Maven repository, as described in the `publishing.repositories.maven` block of
15+
[build.gradle](https://github.com/css4j/css4j/blob/master/build.gradle))
16+
17+
<br/>
18+
19+
## Usage from a Gradle project
20+
If your Gradle project depends on css4j-agent, you can use this project's own Maven repository in a `repositories` section of
21+
your build file:
22+
```groovy
23+
repositories {
24+
maven {
25+
url "https://css4j.github.io/maven/"
26+
mavenContent {
27+
releasesOnly()
28+
}
29+
content {
30+
includeGroup 'io.sf.carte'
31+
includeGroup 'io.sf.jclf'
32+
}
33+
}
34+
}
35+
```
36+
please use this repository **only** for the artifact groups listed in the `includeGroup` statements.
37+
38+
Then, in your `build.gradle` file:
39+
```groovy
40+
dependencies {
41+
api "io.sf.carte:css4j-agent:${css4jAgentVersion}"
42+
}
43+
```
44+
where `css4jAgentVersion` would be defined in a `gradle.properties` file.
45+
46+
<br/>
47+
48+
## Website
49+
For more information please visit https://css4j.github.io/

RELEASE_NOTES.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
CSS4J AGENT MODULE RELEASE NOTES
3+
================================
4+
5+
Release 3.6.0 - July 30, 2021
6+
-----------------------------
7+
8+
Release Highlights
9+
------------------
10+
11+
* Build improvements.
12+
13+
The Gradle build is now independent from css4j-dist.
14+
15+
16+
Description
17+
-----------
18+
This software contains Java(tm) classes that extend the CSS4J library with a
19+
few user agent helper classes. Unless otherwise noted, this software is provided
20+
under a BSD-style licence (see the LICENSE.txt file, and also LICENSES.txt for
21+
included files that have a different licensing).
22+
23+
24+
Java(tm) Runtime Environment requirements
25+
-----------------------------------------
26+
All the classes in the binary package have been compiled with a Java compiler
27+
set to 1.8 compiler compliance level, except the module-info file.
28+
29+
Building the library requires JDK 15 or higher, although the resulting jar
30+
files can be run with a 1.8 JRE.
31+
32+
33+
Software dependencies
34+
=====================
35+
36+
- The css4j artifact (and its transitive dependencies); version 3.6.0 or higher
37+
is recommended (compatibility with 4.0 or higher is not guaranteed):
38+
https://github.com/css4j/css4j/releases
39+
40+
- The xml-dtd artifact; version 3.5.1 or higher is recommended:
41+
https://github.com/css4j/xml-dtd/releases
42+
43+
- The validator.nu html5 parser: https://about.validator.nu/htmlparser/
44+
45+
- The SLF4J package, which is a logging package. See http://www.slf4j.org/
46+
for more information.
47+
48+
49+
Optional packages:
50+
51+
To run the unit tests you need a recent version of JUnit 4. Tests also require
52+
other packages, please see the Gradle build file for details.
53+
54+
55+
Project Sites
56+
=============
57+
Project home: https://css4j.github.io/
58+
Development site: https://github.com/css4j/css4j-agent

build.gradle

Lines changed: 207 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,224 @@
11
plugins {
2-
id 'css4j.java-conventions'
3-
id 'de.jjohannes.extra-java-module-info'
2+
id 'java-library'
3+
id 'maven-publish'
4+
id 'de.jjohannes.extra-java-module-info' version '0.9'
45
}
56

7+
group = 'io.sf.carte'
8+
version = '3.6.0'
9+
10+
description = 'css4j-agent'
11+
612
dependencies {
7-
api project(':css4j')
8-
api "io.sf.carte:xml-dtd:${xmldtdVersion}"
9-
api "nu.validator:htmlparser:${htmlparserVersion}"
13+
api('io.sf.carte:css4j') {
14+
version {
15+
strictly '[3.4.0,4.0['
16+
prefer '3.6.0'
17+
}
18+
}
19+
api('io.sf.carte:xml-dtd') {
20+
version {
21+
require '[3.4.0,)'
22+
prefer '3.5.1'
23+
}
24+
}
25+
api 'nu.validator:htmlparser:1.4.16'
1026
/*
11-
* The next dependency is not required for compiling, but this one was
12-
* optional in the core module and it is mandatory for user agents. So it is
13-
* set as a mandatory dependency here.
27+
* The next dependency is not required for compiling, but it was optional
28+
* in the core module and is mandatory for user agents. So it is set as a
29+
* mandatory dependency here.
1430
*/
15-
api "org.slf4j:slf4j-api:${slf4jVersion}"
16-
testImplementation project(path: ':css4j', configuration: 'tests')
31+
api('org.slf4j:slf4j-api') {
32+
version {
33+
require '[1.7.28,)'
34+
prefer '1.7.32'
35+
}
36+
}
37+
testImplementation(group: 'io.sf.carte', name: 'css4j', classifier: 'tests') {
38+
version {
39+
strictly '[3.4.0,4.0['
40+
prefer '3.6.0'
41+
}
42+
}
43+
testImplementation 'junit:junit:4.13.1'
1744
}
1845

1946
extraJavaModuleInfo {
2047
failOnMissingModuleInfo.set(false)
21-
automaticModule("htmlparser-${htmlparserVersion}.jar", 'htmlparser')
48+
automaticModule('htmlparser-1.4.16.jar', 'htmlparser')
2249
}
2350

24-
description = 'css4j-agent'
51+
java {
52+
sourceCompatibility = JavaVersion.VERSION_1_8
53+
targetCompatibility = JavaVersion.VERSION_1_8
54+
withJavadocJar()
55+
withSourcesJar()
56+
}
2557

26-
compileJava.dependsOn tasks.jvmVersionAttribute
58+
repositories {
59+
maven {
60+
url = uri('https://repo.maven.apache.org/maven2/')
61+
}
62+
maven {
63+
url "https://css4j.github.io/maven/"
64+
mavenContent {
65+
releasesOnly()
66+
}
67+
content {
68+
includeGroup 'io.sf.carte'
69+
includeGroup 'io.sf.jclf'
70+
}
71+
}
72+
}
2773

28-
publishing.publications.maven(MavenPublication).pom {
29-
description = "CSS4J agent module"
74+
sourceSets {
75+
main {
76+
java {
77+
srcDirs = ['src']
78+
includes += ["**/*.java"]
79+
}
80+
resources {
81+
srcDirs = ['src']
82+
excludes += ["**/*.java"]
83+
}
84+
}
85+
test {
86+
java {
87+
srcDirs = ['junit']
88+
includes += ["**/*.java"]
89+
}
90+
resources {
91+
srcDirs = ['junit']
92+
excludes += ["**/*.java"]
93+
}
94+
}
3095
}
3196

32-
java {
33-
withJavadocJar()
97+
tasks.compileJava {
98+
excludes += ['module-info.java']
99+
modularity.inferModulePath = false
100+
}
101+
102+
tasks.register('compileModuleInfo', JavaCompile) {
103+
description = 'Compile module-info to Java 11 bytecode'
104+
dependsOn tasks.compileJava
105+
sourceCompatibility = JavaVersion.VERSION_11
106+
targetCompatibility = JavaVersion.VERSION_11
107+
source = sourceSets.main.java
108+
classpath = sourceSets.main.compileClasspath
109+
destinationDirectory = sourceSets.main.java.destinationDirectory
110+
modularity.inferModulePath = true
111+
includes = ['module-info.java']
112+
}
113+
114+
classes.dependsOn compileModuleInfo
115+
116+
// Check bytecode version, in case some other task screws it
117+
tasks.register('checkLegacyJava') {
118+
description = 'Check that classes are Java 8 bytecode (except module-info)'
119+
def classdir = sourceSets.main.output.classesDirs.files.stream().findAny().get()
120+
def classfiles = fileTree(classdir).matching({it.exclude('module-info.class')}).files
121+
doFirst() {
122+
if (!classfiles.isEmpty()) {
123+
def classfile = classfiles.stream().findAny().get()
124+
if (classfile != null) {
125+
def classbytes = classfile.bytes
126+
def bcversion = classbytes[6] * 128 + classbytes[7]
127+
if (bcversion != 52) {
128+
throw new GradleException("Bytecode on " + classfile +
129+
" is not valid Java 8. Version should be 52, instead is " + bcversion)
130+
}
131+
}
132+
}
133+
}
134+
}
135+
136+
classes.finalizedBy checkLegacyJava
137+
138+
tasks.register('lineEndingConversion', CRLFConvert) {
139+
file "$rootDir/LICENSE.txt"
140+
file "$rootDir/LICENSES.txt"
141+
file "$rootDir/CHANGES.txt"
142+
file "$rootDir/RELEASE_NOTES.txt"
143+
}
144+
145+
tasks.withType(JavaCompile) {
146+
options.encoding = 'UTF-8'
147+
}
148+
149+
tasks.withType(Javadoc) {
150+
failOnError false
151+
options.addStringOption('Xdoclint:none', '-quiet')
152+
options.addStringOption('encoding', 'UTF-8')
153+
options.addStringOption('charset', 'UTF-8')
154+
options.links 'https://docs.oracle.com/en/java/javase/11/docs/api/'
155+
}
156+
157+
// Reproducible build
158+
tasks.withType(AbstractArchiveTask).configureEach {
159+
preserveFileTimestamps = false
160+
reproducibleFileOrder = true
161+
}
162+
163+
tasks.withType(PublishToMavenRepository) { task ->
164+
doFirst {
165+
if (repository == publishing.repositories.getByName('mavenRepo')) {
166+
logger.lifecycle "Deploying artifacts to \"${it.repository.url}\""
167+
}
168+
}
169+
}
170+
171+
publishing {
172+
publications {
173+
maven(MavenPublication) {
174+
description = 'css4j agent module'
175+
from(components.java)
176+
pom {
177+
description = 'css4j agent module'
178+
url = "https://github.com/css4j/css4j-agent/"
179+
licenses {
180+
license {
181+
name = "BSD 3-clause license"
182+
url = "https://css4j.github.io/LICENSE.txt"
183+
}
184+
}
185+
}
186+
}
187+
}
188+
repositories {
189+
maven {
190+
name = 'mavenRepo'
191+
/*
192+
* The following section applies to the 'publish' task:
193+
*
194+
* If you plan to deploy to a repository, please configure the
195+
* 'mavenReleaseRepoUrl' and/or 'mavenSnapshotRepoUrl' properties
196+
* (for example in GRADLE_USER_HOME/gradle.properties).
197+
*
198+
* Otherwise, Gradle shall create a 'build/repository' subdirectory
199+
* at ${rootDir} and deploy there.
200+
*
201+
* Properties 'mavenRepoUsername' and 'mavenRepoPassword' can also
202+
* be set (generally from command line).
203+
*/
204+
def releasesUrl
205+
def snapshotsUrl
206+
if (project.hasProperty('mavenReleaseRepoUrl') && project.mavenReleaseRepoUrl) {
207+
releasesUrl = mavenReleaseRepoUrl
208+
} else {
209+
releasesUrl = "${buildDir}/repository/releases"
210+
}
211+
if (project.hasProperty('mavenSnapshotRepoUrl') && project.mavenSnapshotRepoUrl) {
212+
snapshotsUrl = mavenSnapshotRepoUrl
213+
} else {
214+
snapshotsUrl = "${buildDir}/repository/snapshots"
215+
}
216+
url = version.endsWith('-SNAPSHOT') ? snapshotsUrl : releasesUrl
217+
if (project.hasProperty('mavenRepoUsername') &&
218+
project.hasProperty('mavenRepoPassword')) {
219+
credentials.username = mavenRepoUsername
220+
credentials.password = mavenRepoPassword
221+
}
222+
}
223+
}
34224
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
String content = file.text
28+
content = content.replaceAll(/\r\n/, LF)
29+
file.write(content.replaceAll(/\n|\r/, CRLF))
30+
}
31+
}
32+
33+
def file(String path) {
34+
this.files << path
35+
}
36+
}

0 commit comments

Comments
 (0)