Skip to content

Commit

Permalink
Gradle: stand-alone build, independent from css4j-dist.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosame committed Jul 30, 2021
1 parent b07a3c1 commit 784e740
Show file tree
Hide file tree
Showing 9 changed files with 645 additions and 19 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
*.iws

# Gradle
/.gradle
**/.gradle
/build/
/buildSrc/build/

/CHANGES.txt
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,47 @@
This provides user agent-related functionality to CSS4J. Licence is BSD 3-clause, but includes a file with another licence
(see `LICENSES.txt`).

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

- `gradlew build` (normal build)
- `gradlew build publishToMavenLocal` (to install in local Maven repository)
- `gradlew copyJars` (to copy jar files into a top-level _jar_ directory)
- `gradlew lineEndingConversion` (to convert line endings of top-level text files to CRLF)
- `gradlew publish` (to deploy to a Maven repository, as described in the `publishing.repositories.maven` block of
[build.gradle](https://github.com/css4j/css4j/blob/master/build.gradle))

<br/>

## Usage from a Gradle project
If your Gradle project depends on css4j-agent, you can use this project's own Maven repository in a `repositories` section of
your build file:
```groovy
repositories {
maven {
url "https://css4j.github.io/maven/"
mavenContent {
releasesOnly()
}
content {
includeGroup 'io.sf.carte'
includeGroup 'io.sf.jclf'
}
}
}
```
please use this repository **only** for the artifact groups listed in the `includeGroup` statements.

Then, in your `build.gradle` file:
```groovy
dependencies {
api "io.sf.carte:css4j-agent:${css4jAgentVersion}"
}
```
where `css4jAgentVersion` would be defined in a `gradle.properties` file.

<br/>

## Website
For more information please visit https://css4j.github.io/
58 changes: 58 additions & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

CSS4J AGENT MODULE RELEASE NOTES
================================

Release 3.6.0 - July 30, 2021
-----------------------------

Release Highlights
------------------

* Build improvements.

The Gradle build is now independent from css4j-dist.


Description
-----------
This software contains Java(tm) classes that extend the CSS4J library with a
few user agent helper classes. Unless otherwise noted, this software is provided
under a BSD-style licence (see the LICENSE.txt file, and also LICENSES.txt for
included files that have a different licensing).


Java(tm) Runtime Environment requirements
-----------------------------------------
All the classes in the binary package have been compiled with a Java compiler
set to 1.8 compiler compliance level, except the module-info file.

Building the library requires JDK 15 or higher, although the resulting jar
files can be run with a 1.8 JRE.


Software dependencies
=====================

- The css4j artifact (and its transitive dependencies); version 3.6.0 or higher
is recommended (compatibility with 4.0 or higher is not guaranteed):
https://github.com/css4j/css4j/releases

- The xml-dtd artifact; version 3.5.1 or higher is recommended:
https://github.com/css4j/xml-dtd/releases

- The validator.nu html5 parser: https://about.validator.nu/htmlparser/

- The SLF4J package, which is a logging package. See http://www.slf4j.org/
for more information.


Optional packages:

To run the unit tests you need a recent version of JUnit 4. Tests also require
other packages, please see the Gradle build file for details.


Project Sites
=============
Project home: https://css4j.github.io/
Development site: https://github.com/css4j/css4j-agent
224 changes: 207 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,34 +1,224 @@
plugins {
id 'css4j.java-conventions'
id 'de.jjohannes.extra-java-module-info'
id 'java-library'
id 'maven-publish'
id 'de.jjohannes.extra-java-module-info' version '0.9'
}

group = 'io.sf.carte'
version = '3.6.0'

description = 'css4j-agent'

dependencies {
api project(':css4j')
api "io.sf.carte:xml-dtd:${xmldtdVersion}"
api "nu.validator:htmlparser:${htmlparserVersion}"
api('io.sf.carte:css4j') {
version {
strictly '[3.4.0,4.0['
prefer '3.6.0'
}
}
api('io.sf.carte:xml-dtd') {
version {
require '[3.4.0,)'
prefer '3.5.1'
}
}
api 'nu.validator:htmlparser:1.4.16'
/*
* The next dependency is not required for compiling, but this one was
* optional in the core module and it is mandatory for user agents. So it is
* set as a mandatory dependency here.
* The next dependency is not required for compiling, but it was optional
* in the core module and is mandatory for user agents. So it is set as a
* mandatory dependency here.
*/
api "org.slf4j:slf4j-api:${slf4jVersion}"
testImplementation project(path: ':css4j', configuration: 'tests')
api('org.slf4j:slf4j-api') {
version {
require '[1.7.28,)'
prefer '1.7.32'
}
}
testImplementation(group: 'io.sf.carte', name: 'css4j', classifier: 'tests') {
version {
strictly '[3.4.0,4.0['
prefer '3.6.0'
}
}
testImplementation 'junit:junit:4.13.1'
}

extraJavaModuleInfo {
failOnMissingModuleInfo.set(false)
automaticModule("htmlparser-${htmlparserVersion}.jar", 'htmlparser')
automaticModule('htmlparser-1.4.16.jar', 'htmlparser')
}

description = 'css4j-agent'
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}

compileJava.dependsOn tasks.jvmVersionAttribute
repositories {
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
maven {
url "https://css4j.github.io/maven/"
mavenContent {
releasesOnly()
}
content {
includeGroup 'io.sf.carte'
includeGroup 'io.sf.jclf'
}
}
}

publishing.publications.maven(MavenPublication).pom {
description = "CSS4J agent module"
sourceSets {
main {
java {
srcDirs = ['src']
includes += ["**/*.java"]
}
resources {
srcDirs = ['src']
excludes += ["**/*.java"]
}
}
test {
java {
srcDirs = ['junit']
includes += ["**/*.java"]
}
resources {
srcDirs = ['junit']
excludes += ["**/*.java"]
}
}
}

java {
withJavadocJar()
tasks.compileJava {
excludes += ['module-info.java']
modularity.inferModulePath = false
}

tasks.register('compileModuleInfo', JavaCompile) {
description = 'Compile module-info to Java 11 bytecode'
dependsOn tasks.compileJava
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
source = sourceSets.main.java
classpath = sourceSets.main.compileClasspath
destinationDirectory = sourceSets.main.java.destinationDirectory
modularity.inferModulePath = true
includes = ['module-info.java']
}

classes.dependsOn compileModuleInfo

// Check bytecode version, in case some other task screws it
tasks.register('checkLegacyJava') {
description = 'Check that classes are Java 8 bytecode (except module-info)'
def classdir = sourceSets.main.output.classesDirs.files.stream().findAny().get()
def classfiles = fileTree(classdir).matching({it.exclude('module-info.class')}).files
doFirst() {
if (!classfiles.isEmpty()) {
def classfile = classfiles.stream().findAny().get()
if (classfile != null) {
def classbytes = classfile.bytes
def bcversion = classbytes[6] * 128 + classbytes[7]
if (bcversion != 52) {
throw new GradleException("Bytecode on " + classfile +
" is not valid Java 8. Version should be 52, instead is " + bcversion)
}
}
}
}
}

classes.finalizedBy checkLegacyJava

tasks.register('lineEndingConversion', CRLFConvert) {
file "$rootDir/LICENSE.txt"
file "$rootDir/LICENSES.txt"
file "$rootDir/CHANGES.txt"
file "$rootDir/RELEASE_NOTES.txt"
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

tasks.withType(Javadoc) {
failOnError false
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charset', 'UTF-8')
options.links 'https://docs.oracle.com/en/java/javase/11/docs/api/'
}

// Reproducible build
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}

tasks.withType(PublishToMavenRepository) { task ->
doFirst {
if (repository == publishing.repositories.getByName('mavenRepo')) {
logger.lifecycle "Deploying artifacts to \"${it.repository.url}\""
}
}
}

publishing {
publications {
maven(MavenPublication) {
description = 'css4j agent module'
from(components.java)
pom {
description = 'css4j agent module'
url = "https://github.com/css4j/css4j-agent/"
licenses {
license {
name = "BSD 3-clause license"
url = "https://css4j.github.io/LICENSE.txt"
}
}
}
}
}
repositories {
maven {
name = 'mavenRepo'
/*
* The following section applies to the 'publish' task:
*
* If you plan to deploy to a repository, please configure the
* 'mavenReleaseRepoUrl' and/or 'mavenSnapshotRepoUrl' properties
* (for example in GRADLE_USER_HOME/gradle.properties).
*
* Otherwise, Gradle shall create a 'build/repository' subdirectory
* at ${rootDir} and deploy there.
*
* Properties 'mavenRepoUsername' and 'mavenRepoPassword' can also
* be set (generally from command line).
*/
def releasesUrl
def snapshotsUrl
if (project.hasProperty('mavenReleaseRepoUrl') && project.mavenReleaseRepoUrl) {
releasesUrl = mavenReleaseRepoUrl
} else {
releasesUrl = "${buildDir}/repository/releases"
}
if (project.hasProperty('mavenSnapshotRepoUrl') && project.mavenSnapshotRepoUrl) {
snapshotsUrl = mavenSnapshotRepoUrl
} else {
snapshotsUrl = "${buildDir}/repository/snapshots"
}
url = version.endsWith('-SNAPSHOT') ? snapshotsUrl : releasesUrl
if (project.hasProperty('mavenRepoUsername') &&
project.hasProperty('mavenRepoPassword')) {
credentials.username = mavenRepoUsername
credentials.password = mavenRepoPassword
}
}
}
}
36 changes: 36 additions & 0 deletions buildSrc/src/main/groovy/CRLFConvert.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

/**
* Converts line endings to CRLF (Windows)
* <p>
* Usage:
* </p>
* <code>
* tasks.register('lineEndingConversion', CRLFConvert) {
* file "path/to/file1.txt"
* file "path/to/fileN.txt"
* }
* </code>
*/
class CRLFConvert extends DefaultTask {

private static final String CRLF = "\r\n"
private static final String LF = "\n"

private files = []

@TaskAction
def action() {
files.each { path ->
File file = new File(path)
String content = file.text
content = content.replaceAll(/\r\n/, LF)
file.write(content.replaceAll(/\n|\r/, CRLF))
}
}

def file(String path) {
this.files << path
}
}
Loading

0 comments on commit 784e740

Please sign in to comment.