Skip to content

Commit 1eac211

Browse files
committed
Gradle: stand-alone build, independent from css4j-dist.
1 parent 7ff1bec commit 1eac211

File tree

9 files changed

+632
-16
lines changed

9 files changed

+632
-16
lines changed

.gitignore

+4-1
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

+43-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,47 @@
22

33
AWT utilities for CSS4J. Licence is BSD 3-clause.
44

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

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

RELEASE_NOTES.txt

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
CSS4J-AWT 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 AWT helper classes. Unless otherwise noted, this software is provided under
20+
a BSD-style licence (see the LICENSE.txt file).
21+
22+
23+
Java(tm) Runtime Environment requirements
24+
-----------------------------------------
25+
All the classes in the binary package have been compiled with a Java compiler
26+
set to 1.8 compiler compliance level, except the module-info file.
27+
28+
Building the library requires JDK 15 or higher, although the resulting jar
29+
files can be run with a 1.8 JRE.
30+
31+
32+
Software dependencies
33+
=====================
34+
35+
To build this library you need the css4j artifact (and its transitive
36+
dependencies); version 3.6.0 or higher is recommended (compatibility with 4.0 or
37+
higher is not guaranteed): https://github.com/css4j/css4j/releases
38+
39+
40+
Optional packages:
41+
42+
To run the unit tests you need a recent version of JUnit 4. Tests also require
43+
other packages, please see the Gradle build file for details.
44+
45+
46+
Project Sites
47+
=============
48+
Project home: https://css4j.github.io/
49+
Development site: https://github.com/css4j/css4j-awt

build.gradle

+203-14
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,218 @@
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-awt'
11+
612
dependencies {
7-
api project(':css4j')
8-
testImplementation project(path: ':css4j', configuration: 'tests')
9-
testImplementation "io.sf.carte:xml-dtd:${xmldtdVersion}"
10-
testImplementation "nu.validator:htmlparser:${htmlparserVersion}"
11-
testImplementation "org.slf4j:slf4j-api:${slf4jVersion}"
13+
api('io.sf.carte:css4j') {
14+
version {
15+
strictly '[3.4.0,4.0['
16+
prefer '3.6.0'
17+
}
18+
}
19+
testImplementation(group: 'io.sf.carte', name: 'css4j', classifier: 'tests') {
20+
version {
21+
strictly '[3.4.0,4.0['
22+
prefer '3.6.0'
23+
}
24+
}
25+
testImplementation('io.sf.carte:xml-dtd') {
26+
version {
27+
strictly '[3.4.0,)'
28+
prefer '3.5.1'
29+
}
30+
}
31+
testImplementation 'nu.validator:htmlparser:1.4.16'
32+
testImplementation('org.slf4j:slf4j-api') {
33+
version {
34+
strictly '[1.7.28,)'
35+
prefer '1.7.32'
36+
}
37+
}
38+
testImplementation 'junit:junit:4.13.1'
1239
}
1340

1441
extraJavaModuleInfo {
1542
failOnMissingModuleInfo.set(false)
16-
automaticModule("htmlparser-${htmlparserVersion}.jar", 'htmlparser')
43+
automaticModule('htmlparser-1.4.16.jar', 'htmlparser')
1744
}
1845

19-
description = 'css4j-awt'
46+
java {
47+
sourceCompatibility = JavaVersion.VERSION_1_8
48+
targetCompatibility = JavaVersion.VERSION_1_8
49+
withJavadocJar()
50+
withSourcesJar()
51+
}
2052

21-
compileJava.dependsOn tasks.jvmVersionAttribute
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+
}
2268

23-
publishing.publications.maven(MavenPublication).pom {
24-
description = "CSS4J AWT module"
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+
}
2590
}
2691

27-
java {
28-
withJavadocJar()
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 8 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 != 52) {
123+
throw new GradleException("Bytecode on " + classfile +
124+
" is not valid Java 8. Version should be 52, 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/CHANGES.txt"
136+
file "$rootDir/RELEASE_NOTES.txt"
137+
}
138+
139+
tasks.withType(JavaCompile) {
140+
options.encoding = 'UTF-8'
141+
}
142+
143+
tasks.withType(Javadoc) {
144+
failOnError false
145+
options.addStringOption('Xdoclint:none', '-quiet')
146+
options.addStringOption('encoding', 'UTF-8')
147+
options.addStringOption('charset', 'UTF-8')
148+
options.links 'https://docs.oracle.com/en/java/javase/11/docs/api/'
149+
}
150+
151+
// Reproducible build
152+
tasks.withType(AbstractArchiveTask).configureEach {
153+
preserveFileTimestamps = false
154+
reproducibleFileOrder = true
155+
}
156+
157+
tasks.withType(PublishToMavenRepository) { task ->
158+
doFirst {
159+
if (repository == publishing.repositories.getByName('mavenRepo')) {
160+
logger.lifecycle "Deploying artifacts to \"${it.repository.url}\""
161+
}
162+
}
163+
}
164+
165+
publishing {
166+
publications {
167+
maven(MavenPublication) {
168+
description = 'css4j AWT module'
169+
from(components.java)
170+
pom {
171+
description = 'css4j AWT module'
172+
url = "https://github.com/css4j/css4j-awt/"
173+
licenses {
174+
license {
175+
name = "BSD 3-clause license"
176+
url = "https://css4j.github.io/LICENSE.txt"
177+
}
178+
}
179+
}
180+
}
181+
}
182+
repositories {
183+
maven {
184+
name = 'mavenRepo'
185+
/*
186+
* The following section applies to the 'publish' task:
187+
*
188+
* If you plan to deploy to a repository, please configure the
189+
* 'mavenReleaseRepoUrl' and/or 'mavenSnapshotRepoUrl' properties
190+
* (for example in GRADLE_USER_HOME/gradle.properties).
191+
*
192+
* Otherwise, Gradle shall create a 'build/repository' subdirectory
193+
* at ${rootDir} and deploy there.
194+
*
195+
* Properties 'mavenRepoUsername' and 'mavenRepoPassword' can also
196+
* be set (generally from command line).
197+
*/
198+
def releasesUrl
199+
def snapshotsUrl
200+
if (project.hasProperty('mavenReleaseRepoUrl') && project.mavenReleaseRepoUrl) {
201+
releasesUrl = mavenReleaseRepoUrl
202+
} else {
203+
releasesUrl = "${buildDir}/repository/releases"
204+
}
205+
if (project.hasProperty('mavenSnapshotRepoUrl') && project.mavenSnapshotRepoUrl) {
206+
snapshotsUrl = mavenSnapshotRepoUrl
207+
} else {
208+
snapshotsUrl = "${buildDir}/repository/snapshots"
209+
}
210+
url = version.endsWith('-SNAPSHOT') ? snapshotsUrl : releasesUrl
211+
if (project.hasProperty('mavenRepoUsername') &&
212+
project.hasProperty('mavenRepoPassword')) {
213+
credentials.username = mavenRepoUsername
214+
credentials.password = mavenRepoPassword
215+
}
216+
}
217+
}
29218
}
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+
}

changes.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
#
3+
# This script writes the changelog in a human-readable format.
4+
#
5+
# You'll probably want to edit manually the result of executing the script.
6+
#
7+
if [[ $# -eq 0 ]] ; then
8+
echo "No version supplied (e.g. '3.7.0')"
9+
exit 1
10+
fi
11+
OLDTAG=`git tag -l --merged master --sort=-taggerdate|head -1`
12+
echo "Writing changes from tag $OLDTAG"
13+
TITLE="CSS4J AWT Module changes"
14+
VERHDR="Version ${1}"
15+
OUTFILE="CHANGES.txt"
16+
echo -en "${TITLE}\\r\\n${TITLE//?/=}\\r\\n\\r\\n${VERHDR}\\r\\n${VERHDR//?/-}\\r\\n\\r\\n">${OUTFILE}
17+
git log --reverse --pretty=format:%s ${OLDTAG}..|sed -e 's/^/- /'|fold -s|sed -r 's/^([^-])/ \1/'|sed -e 's/$/\r/'>>${OUTFILE}
18+
echo -en "\\n">>${OUTFILE}

0 commit comments

Comments
 (0)