update to Java named module, Gradle 6.4.1, JUnit 5

This commit is contained in:
Jörg Prante 2020-05-26 14:14:46 +02:00
parent af0cb88ea6
commit bb36118fd2
32 changed files with 427 additions and 371 deletions

View file

@ -1,8 +1,3 @@
sudo: false
language: java language: java
jdk: jdk:
- oraclejdk8 - openjdk11
cache:
directories:
- $HOME/.m2

View file

@ -15,8 +15,9 @@ in migrating library data to Unicode, and UTF-8, respectively.
| Version | Release date | | Version | Release date |
| ------- | ------------ | | ------- | ------------ |
| 1.0.0 | Aug 18, 2016 | | 1.0.2 | Aug 30, 2016 |
| 1.0.1 | Aug 20, 2016 | | 1.0.1 | Aug 20, 2016 |
| 1.0.0 | Aug 18, 2016 |
## Usage ## Usage
@ -25,7 +26,7 @@ With Maven
<dependency> <dependency>
<groupId>org.xbib</groupId> <groupId>org.xbib</groupId>
<artifactId>bibliographic-character-sets</artifactId> <artifactId>bibliographic-character-sets</artifactId>
<version>1.0.1</version> <version>1.0.2</version>
</dependency> </dependency>
With Gradle With Gradle
@ -34,7 +35,7 @@ With Gradle
provided provided
} }
dependencies { dependencies {
provided 'org.xbib:bibliographic-character-sets:1.0.1' provided 'org.xbib:bibliographic-character-sets:1.0.2'
} }
You can also include this jar in the classpath, the Java CharsetProvider and You can also include this jar in the classpath, the Java CharsetProvider and

View file

@ -1,71 +1,31 @@
plugins { plugins {
id "org.sonarqube" version "2.1-rc1" id "de.marcphilipp.nexus-publish" version "0.4.0"
id "io.codearte.nexus-staging" version "0.21.1"
} }
println "Host: " + java.net.InetAddress.getLocalHost() wrapper {
println "Gradle: " + gradle.gradleVersion + " JVM: " + org.gradle.internal.jvm.Jvm.current() + " Groovy: " + GroovySystem.getVersion() gradleVersion = "${project.property('gradle.wrapper.version')}"
println "Build: group: '${project.group}', name: '${project.name}', version: '${project.version}'" distributionType = Wrapper.DistributionType.ALL
apply from: 'gradle/ext.gradle'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'findbugs'
apply plugin: 'pmd'
apply plugin: 'checkstyle'
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven {
url "http://xbib.org/repository"
}
} }
configurations { ext {
wagon user = 'xbib'
name = 'bibliographic-character-sets'
description = 'Bibliographic character sets for Java'
inceptionYear = '2016'
url = 'https://github.com/' + user + '/' + name
scmUrl = 'https://github.com/' + user + '/' + name
scmConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git'
scmDeveloperConnection = 'scm:git:ssh://git@github.com:' + user + '/' + name + '.git'
issueManagementSystem = 'Github'
issueManagementUrl = ext.scmUrl + '/issues'
licenseName = 'Affero GNU Public License Version 3'
licenseUrl = 'http://www.gnu.org/licenses/agpl-3.0.html'
} }
dependencies { apply plugin: 'java-library'
testCompile "org.apache.logging.log4j:log4j-core:2.5" apply from: rootProject.file('gradle/ide/idea.gradle')
testCompile('junit:junit:4.12') apply from: rootProject.file('gradle/compile/java.gradle')
wagon 'org.apache.maven.wagon:wagon-ssh-external:2.10' apply from: rootProject.file('gradle/test/junit5.gradle')
} apply from: rootProject.file('gradle/publishing/publication.gradle')
apply from: rootProject.file('gradle/publishing/sonatype.gradle')
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation,unchecked"
}
test {
testLogging {
showStandardStreams = false
exceptionFormat = 'full'
}
}
tasks.withType(FindBugs) {
ignoreFailures = true
reports {
xml.enabled = false
html.enabled = true
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier 'javadoc'
}
artifacts {
archives sourcesJar, javadocJar
}
if (project.hasProperty('signing.keyId')) {
signing {
sign configurations.archives
}
}
apply from: 'gradle/publish.gradle'

View file

@ -1,3 +1,5 @@
group = org.xbib group = org.xbib
version = 1.0.2 name = bibliographic-character-sets
org.gradle.daemon = true version = 2.0.0
gradle.wrapper.version = 6.4.1

View file

@ -0,0 +1,35 @@
apply plugin: 'java-library'
java {
modularity.inferModulePath.set(true)
}
compileJava {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
compileTestJava {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
jar {
manifest {
attributes('Implementation-Version': project.version)
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier 'javadoc'
}
artifacts {
archives sourcesJar, javadocJar
}

View file

@ -0,0 +1,55 @@
apply plugin: 'org.xbib.gradle.plugin.asciidoctor'
configurations {
asciidoclet
}
dependencies {
asciidoclet "org.asciidoctor:asciidoclet:${project.property('asciidoclet.version')}"
}
asciidoctor {
backends 'html5'
outputDir = file("${rootProject.projectDir}/docs")
separateOutputDirs = false
attributes 'source-highlighter': 'coderay',
idprefix: '',
idseparator: '-',
toc: 'left',
doctype: 'book',
icons: 'font',
encoding: 'utf-8',
sectlink: true,
sectanchors: true,
linkattrs: true,
imagesdir: 'img',
stylesheet: "${projectDir}/src/docs/asciidoc/css/foundation.css"
}
/*javadoc {
options.docletpath = configurations.asciidoclet.files.asType(List)
options.doclet = 'org.asciidoctor.Asciidoclet'
//options.overview = "src/docs/asciidoclet/overview.adoc"
options.addStringOption "-base-dir", "${projectDir}"
options.addStringOption "-attribute",
"name=${project.name},version=${project.version},title-link=https://github.com/xbib/${project.name}"
configure(options) {
noTimestamp = true
}
}*/
/*javadoc {
options.docletpath = configurations.asciidoclet.files.asType(List)
options.doclet = 'org.asciidoctor.Asciidoclet'
options.overview = "${rootProject.projectDir}/src/docs/asciidoclet/overview.adoc"
options.addStringOption "-base-dir", "${projectDir}"
options.addStringOption "-attribute",
"name=${project.name},version=${project.version},title-link=https://github.com/xbib/${project.name}"
options.destinationDirectory(file("${projectDir}/docs/javadoc"))
configure(options) {
noTimestamp = true
}
}*/

View file

@ -1,8 +0,0 @@
ext {
user = 'xbib'
projectName = 'bibliographic-character-sets'
projectDescription = 'Bibliographic character sets'
scmUrl = 'https://github.com/xbib/bibliographic-character-sets'
scmConnection = 'scm:git:git://github.com/xbib/bibliographic-character-sets.git'
scmDeveloperConnection = 'scm:git:git://github.com/xbib/bibliographic-character-sets.git'
}

13
gradle/ide/idea.gradle Normal file
View file

@ -0,0 +1,13 @@
apply plugin: 'idea'
idea {
module {
outputDir file('build/classes/java/main')
testOutputDir file('build/classes/java/test')
}
}
if (project.convention.findPlugin(JavaPluginConvention)) {
//sourceSets.main.output.classesDirs = file("build/classes/java/main")
//sourceSets.test.output.classesDirs = file("build/classes/java/test")
}

View file

@ -1,96 +0,0 @@
task xbibUpload(type: Upload) {
configuration = configurations.archives
uploadDescriptor = true
repositories {
if (project.hasProperty("xbibUsername")) {
mavenDeployer {
configuration = configurations.wagon
repository(url: uri('scpexe://xbib.org/repository')) {
authentication(userName: xbibUsername, privateKey: xbibPrivateKey)
}
snapshotRepository(url: uri('scpexe://xbib.org/repository/snapshots')) {
authentication(userName: xbibUsername, privateKey: xbibPrivateKey)
}
pom.project {
name projectName
description projectDescription
packaging 'jar'
inceptionYear '2016'
url scmUrl
organization {
name 'xbib'
url 'http://xbib.org'
}
developers {
developer {
id user
name 'Jörg Prante'
email 'joergprante@gmail.com'
url 'https://github.com/jprante'
}
}
scm {
url scmUrl
connection scmConnection
developerConnection scmDeveloperConnection
}
licenses {
license {
name 'Affero GNU Public License Version 3'
url 'http://www.gnu.org/licenses/agpl-3.0.html'
}
}
}
}
}
}
}
task mavenCentralUpload(type: Upload) {
configuration = configurations.archives
uploadDescriptor = true
repositories {
if (project.hasProperty('ossrhUsername')) {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: uri(ossrhReleaseUrl)) {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: uri(ossrhSnapshotUrl)) {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name projectName
description projectDescription
packaging 'jar'
inceptionYear '2016'
url scmUrl
organization {
name 'xbib'
url 'http://xbib.org'
}
developers {
developer {
id user
name 'Jörg Prante'
email 'joergprante@gmail.com'
url 'https://github.com/jprante'
}
}
scm {
url scmUrl
connection scmConnection
developerConnection scmDeveloperConnection
}
licenses {
license {
name 'Affero GNU Public License Version 3'
url 'http://www.gnu.org/licenses/agpl-3.0.html'
}
}
}
}
}
}
}

View file

@ -0,0 +1,64 @@
apply plugin: "de.marcphilipp.nexus-publish"
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom {
name = project.name
description = rootProject.ext.description
url = rootProject.ext.url
inceptionYear = rootProject.ext.inceptionYear
packaging = 'jar'
organization {
name = 'xbib'
url = 'https://xbib.org'
}
developers {
developer {
id = 'jprante'
name = 'Jörg Prante'
email = 'joergprante@gmail.com'
url = 'https://github.com/jprante'
}
}
scm {
url = rootProject.ext.scmUrl
connection = rootProject.ext.scmConnection
developerConnection = rootProject.ext.scmDeveloperConnection
}
issueManagement {
system = rootProject.ext.issueManagementSystem
url = rootProject.ext.issueManagementUrl
}
licenses {
license {
name = rootProject.ext.licenseName
url = rootProject.ext.licenseUrl
distribution = 'repo'
}
}
}
}
}
}
if (project.hasProperty("signing.keyId")) {
apply plugin: 'signing'
signing {
sign publishing.publications.mavenJava
}
}
nexusPublishing {
repositories {
sonatype {
username = project.property('ossrhUsername')
password = project.property('ossrhPassword')
packageGroup = "org.xbib"
}
}
}

View file

@ -0,0 +1,11 @@
if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) {
apply plugin: 'io.codearte.nexus-staging'
nexusStaging {
username = project.property('ossrhUsername')
password = project.property('ossrhPassword')
packageGroup = "org.xbib"
}
}

27
gradle/test/junit5.gradle Normal file
View file

@ -0,0 +1,27 @@
def junitVersion = project.hasProperty('junit.version')?project.property('junit.version'):'5.6.2'
def hamcrestVersion = project.hasProperty('hamcrest.version')?project.property('hamcrest.version'):'2.2'
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
testImplementation "org.hamcrest:hamcrest-library:${hamcrestVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
}
test {
useJUnitPlatform()
failFast = true
testLogging {
events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED'
}
afterSuite { desc, result ->
if (!desc.parent) {
println "\nTest result: ${result.resultType}"
println "Test summary: ${result.testCount} tests, " +
"${result.successfulTestCount} succeeded, " +
"${result.failedTestCount} failed, " +
"${result.skippedTestCount} skipped"
}
}
}

Binary file not shown.

View file

@ -1,6 +1,5 @@
#Thu Aug 18 20:34:33 CEST 2016
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-bin.zip

66
gradlew vendored
View file

@ -1,4 +1,20 @@
#!/usr/bin/env bash #!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################################## ##############################################################################
## ##
@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"` APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS="" DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum" MAX_FD="maximum"
@ -66,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@ -109,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi fi
# For Cygwin, switch paths to Windows format before running java # For Cygwin or MSYS, switch paths to Windows format before running java
if $cygwin ; then if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"` JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath # We build the pattern for arguments to be converted via cygpath
@ -138,32 +156,30 @@ if $cygwin ; then
else else
eval `echo args$i`="\"$arg\"" eval `echo args$i`="\"$arg\""
fi fi
i=$((i+1)) i=`expr $i + 1`
done done
case $i in case $i in
(0) set -- ;; 0) set -- ;;
(1) set -- "$args0" ;; 1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;; 2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;; 3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;; 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac esac
fi fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules # Escape application args
function splitJvmOpts() { save () {
JVM_OPTS=("$@") for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
} }
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS APP_ARGS=`save "$@"`
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong # Collect all arguments for the java command, following the shell quoting and substitution rules
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" exec "$JAVACMD" "$@"

22
gradlew.bat vendored
View file

@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@ -13,8 +29,11 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS= set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome
@ -65,6 +84,7 @@ set CMD_LINE_ARGS=%*
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

View file

@ -0,0 +1,8 @@
module org.xbib.charset {
exports org.xbib.charset;
requires java.xml;
provides java.nio.charset.spi.CharsetProvider with
org.xbib.charset.BibliographicCharsetProvider;
}

View file

@ -43,43 +43,30 @@ import java.nio.charset.CoderResult;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.stream.XMLStreamException;
/** /**
* *
*/ */
public class AnselCharset extends Charset { public class AnselCharset extends Charset {
private static final Logger logger = Logger.getLogger(AnselCharset.class.getName()); private final Map<String, AnselCodeTableParser.CharacterSet> characterSetMap;
private static final Map<String, AnselCodeTableParser.CharacterSet> characterSetMap; private final Charset encodeCharset;
static { public AnselCharset() throws IOException {
super("ANSEL", BibliographicCharsetProvider.aliasesFor("ANSEL"));
this.encodeCharset = StandardCharsets.UTF_8;
characterSetMap = new LinkedHashMap<>(); characterSetMap = new LinkedHashMap<>();
ClassLoader cl = Thread.currentThread().getContextClassLoader(); try (InputStream inputStream = AnselCharset.class.getResourceAsStream(("codetables.xml"))) {
try (InputStream inputStream = cl.getResource("org/xbib/charset/codetables.xml").openStream()) {
AnselCodeTableParser anselCodeTableParser = new AnselCodeTableParser(inputStream); AnselCodeTableParser anselCodeTableParser = new AnselCodeTableParser(inputStream);
for (AnselCodeTableParser.CodeTable codeTable : anselCodeTableParser.getCodeTables()) { for (AnselCodeTableParser.CodeTable codeTable : anselCodeTableParser.getCodeTables()) {
for (AnselCodeTableParser.CharacterSet characterSet : codeTable.getCharacterSets()) { for (AnselCodeTableParser.CharacterSet characterSet : codeTable.getCharacterSets()) {
characterSetMap.put(characterSet.getName(), characterSet); characterSetMap.put(characterSet.getName(), characterSet);
} }
} }
} catch (Exception e) {
// sonar wants logging
logger.log(Level.SEVERE, e.getMessage(), e);
} }
} }
private Charset encodeCharset;
public AnselCharset() throws XMLStreamException {
super("ANSEL", BibliographicCharsetProvider.aliasesFor("ANSEL"));
this.encodeCharset = StandardCharsets.UTF_8;
}
@Override @Override
public boolean contains(Charset charset) { public boolean contains(Charset charset) {
return charset instanceof AnselCharset; return charset instanceof AnselCharset;
@ -95,14 +82,17 @@ public class AnselCharset extends Charset {
private static class Decoder extends CharsetDecoder { private static class Decoder extends CharsetDecoder {
String g0; private String g0;
String g1;
Decoder(Charset cs, CharsetDecoder baseDecoder) { private String g1;
Decoder(AnselCharset cs, CharsetDecoder baseDecoder) {
super(cs, baseDecoder.averageCharsPerByte(), baseDecoder.maxCharsPerByte()); super(cs, baseDecoder.averageCharsPerByte(), baseDecoder.maxCharsPerByte());
} }
@Override
protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) { protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
AnselCharset charset = (AnselCharset) charset();
g0 = "Basic Latin (ASCII)"; g0 = "Basic Latin (ASCII)";
g1 = "Extended Latin (ANSEL)"; g1 = "Extended Latin (ANSEL)";
CharArrayWriter w = new CharArrayWriter(); CharArrayWriter w = new CharArrayWriter();
@ -121,8 +111,9 @@ public class AnselCharset extends Charset {
return CoderResult.UNDERFLOW; return CoderResult.UNDERFLOW;
} }
} }
AnselCodeTableParser.CharacterSet characterSet = isG0(oldChar) ? characterSetMap.get(g0) : AnselCodeTableParser.CharacterSet characterSet = isG0(oldChar) ?
isG1(oldChar) ? characterSetMap.get(g1) : null; charset.characterSetMap.get(g0) :
isG1(oldChar) ? charset.characterSetMap.get(g1) : null;
int len = characterSet != null ? characterSet.getLength() : 1; int len = characterSet != null ? characterSet.getLength() : 1;
String str = len == 1 ? "" + oldChar : "" + oldChar + (char) (in.get() & 0xFF) + (char) (in.get() & 0xFF); String str = len == 1 ? "" + oldChar : "" + oldChar + (char) (in.get() & 0xFF) + (char) (in.get() & 0xFF);
AnselCodeTableParser.Code code = characterSet != null ? characterSet.getMarc().get(str) : null; AnselCodeTableParser.Code code = characterSet != null ? characterSet.getMarc().get(str) : null;
@ -141,8 +132,6 @@ public class AnselCharset extends Charset {
try { try {
w.write(diacritics.toCharArray()); w.write(diacritics.toCharArray());
} catch (IOException e) { } catch (IOException e) {
// sonar wants logging
logger.log(Level.SEVERE, e.getMessage(), e);
w.flush(); w.flush();
} }
diacritics = new CharArrayWriter(); diacritics = new CharArrayWriter();
@ -258,22 +247,14 @@ public class AnselCharset extends Charset {
break; break;
case '$': case '$':
oneByte = in.get(); oneByte = in.get();
switch (oneByte) { if (oneByte == '1') {
case '1':
g0 = "Chinese, Japanese, Korean (EACC)"; g0 = "Chinese, Japanese, Korean (EACC)";
break;
default:
break;
} }
break; break;
case '!': case '!':
oneByte = in.get(); oneByte = in.get();
switch (oneByte) { if (oneByte == 'E') {
case 'E':
g0 = "Extended Latin (ANSEL)"; g0 = "Extended Latin (ANSEL)";
break;
default:
break;
} }
break; break;
default: default:

View file

@ -37,8 +37,6 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLEventReader;
@ -52,8 +50,6 @@ import javax.xml.stream.events.XMLEvent;
class AnselCodeTableParser { class AnselCodeTableParser {
private static final Logger logger = Logger.getLogger(AnselCodeTableParser.class.getName());
private final List<CodeTable> codeTables; private final List<CodeTable> codeTables;
private CodeTable codeTable; private CodeTable codeTable;
@ -69,7 +65,6 @@ class AnselCodeTableParser {
try { try {
codeTables = createCodeTables(inputStream); codeTables = createCodeTables(inputStream);
} catch (XMLStreamException e) { } catch (XMLStreamException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
codeTables = null; codeTables = null;
} }
this.codeTables = codeTables; this.codeTables = codeTables;

View file

@ -37,26 +37,27 @@ import java.nio.charset.spi.CharsetProvider;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Extra bibliographic character sets. * Extra bibliographic character sets.
*/ */
public class BibliographicCharsetProvider extends CharsetProvider { public class BibliographicCharsetProvider extends CharsetProvider {
private static final Logger logger = Logger.getLogger(BibliographicCharsetProvider.class.getName());
/** /**
* The reference to the character set instance. * The reference to the character set instance.
* If there are no remaining references to this instance, * If there are no remaining references to this instance,
* the character set will be removed by the garbage collector. * the character set will be removed by the garbage collector.
*/ */
private static volatile BibliographicCharsetProvider instance = new BibliographicCharsetProvider(); private static final BibliographicCharsetProvider instance = new BibliographicCharsetProvider();
private final Map<String, String> classMap; private final Map<String, String> classMap;
private final Map<String, String> aliasMap; private final Map<String, String> aliasMap;
private final Map<String, String[]> aliasNameMap; private final Map<String, String[]> aliasNameMap;
private final Map<String, SoftReference<Charset>> cache; private final Map<String, SoftReference<Charset>> cache;
private final String packagePrefix; private final String packagePrefix;
/** /**
@ -96,9 +97,9 @@ public class BibliographicCharsetProvider extends CharsetProvider {
@Override @Override
public final Iterator<Charset> charsets() { public final Iterator<Charset> charsets() {
return new Iterator<Charset>() { return new Iterator<>() {
Iterator<String> iterator = classMap.keySet().iterator(); final Iterator<String> iterator = classMap.keySet().iterator();
@Override @Override
public boolean hasNext() { public boolean hasNext() {
@ -144,16 +145,11 @@ public class BibliographicCharsetProvider extends CharsetProvider {
} }
try { try {
Class<?> cl = Class.forName(packagePrefix + "." + className, true, getClass().getClassLoader()); Class<?> cl = Class.forName(packagePrefix + "." + className, true, getClass().getClassLoader());
Charset charset = (Charset) cl.newInstance(); Charset charset = (Charset) cl.getDeclaredConstructor().newInstance();
cache.put(charsetName, new SoftReference<>(charset)); cache.put(charsetName, new SoftReference<>(charset));
return charset; return charset;
} catch (ClassNotFoundException e1) { } catch (Exception e) {
logger.log(Level.WARNING, "Class not found: " + packagePrefix + "." + className, e1);
} catch (IllegalAccessException e2) {
logger.log(Level.WARNING, "Illegal access: " + packagePrefix + "." + className, e2);
} catch (InstantiationException e3) {
logger.log(Level.WARNING, "Instantiation failed: " + packagePrefix + "." + className, e3);
}
return null; return null;
} }
} }
}

View file

@ -1,4 +1,4 @@
/** /*
* Licensed to Jörg Prante and xbib under one or more contributor * Licensed to Jörg Prante and xbib under one or more contributor
* license agreements. See the NOTICE.txt file distributed with this work * license agreements. See the NOTICE.txt file distributed with this work
* for additional information regarding copyright ownership. * for additional information regarding copyright ownership.
@ -29,7 +29,6 @@
* feasible for technical reasons, the Appropriate Legal Notices must display * feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by xbib". * the words "Powered by xbib".
* *
*
* Derived from * Derived from
* *
* ByteCharset.java -- Abstract class for generic 1-byte encodings. * ByteCharset.java -- Abstract class for generic 1-byte encodings.
@ -68,7 +67,6 @@
* this exception to your version of the library, but you are not * this exception to your version of the library, but you are not
* obligated to do so. If you do not wish to do so, delete this * obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*//**
* *
* Derived from * Derived from
* *
@ -157,7 +155,7 @@ abstract class ByteCharset extends Charset {
private static final class Decoder extends CharsetDecoder { private static final class Decoder extends CharsetDecoder {
private char[] lookup; private final char[] lookup;
Decoder(ByteCharset cs) { Decoder(ByteCharset cs) {
super(cs, 1.0f, 1.0f); super(cs, 1.0f, 1.0f);
@ -182,19 +180,18 @@ abstract class ByteCharset extends Charset {
private static final class Encoder extends CharsetEncoder { private static final class Encoder extends CharsetEncoder {
private byte[] lookup; private final byte[] lookup;
Encoder(ByteCharset cs) { Encoder(ByteCharset cs) {
super(cs, 1.0f, 1.0f); super(cs, 1.0f, 1.0f);
char[] lookuptable = cs.getLookupTable(); char[] lookuptable = cs.getLookupTable();
int max = 0; int max = 0;
for (char ch : lookuptable) { for (char ch : lookuptable) {
int c = (int) ch; max = (int) ch > max && (int) ch < NONE ? (int) ch : max;
max = c > max && c < NONE ? c : max;
} }
lookup = new byte[max + 1]; lookup = new byte[max + 1];
for (int i = 0; i < lookuptable.length; i++) { for (int i = 0; i < lookuptable.length; i++) {
int c = (int) lookuptable[i]; int c = lookuptable[i];
if (c != 0 && c < NONE) { if (c != 0 && c < NONE) {
lookup[c] = (byte) i; lookup[c] = (byte) i;
} }
@ -203,7 +200,7 @@ abstract class ByteCharset extends Charset {
protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) { protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
while (in.hasRemaining()) { while (in.hasRemaining()) {
int c = (int) in.get(); int c = in.get();
if (!out.hasRemaining()) { if (!out.hasRemaining()) {
in.position(in.position() - 1); in.position(in.position() - 1);
return CoderResult.OVERFLOW; return CoderResult.OVERFLOW;

View file

@ -68,7 +68,7 @@ public class ISO5426 extends Charset {
private static final Map<Character, Byte> charToByteTable = newMabByteToCharMap(); private static final Map<Character, Byte> charToByteTable = newMabByteToCharMap();
private boolean isNFCOutput; private final boolean isNFCOutput;
public ISO5426() { public ISO5426() {
this(true); this(true);

View file

@ -53,6 +53,7 @@ import java.util.Map;
public class Pica extends Charset { public class Pica extends Charset {
private static final Map<Character, Character> encodeMap = new HashMap<>(); private static final Map<Character, Character> encodeMap = new HashMap<>();
private static final Map<Character, Character> decodeMap = new HashMap<>(); private static final Map<Character, Character> decodeMap = new HashMap<>();
/* /*
@ -62,8 +63,7 @@ public class Pica extends Charset {
* which are different from ISO-8859-1. * which are different from ISO-8859-1.
*/ */
static { static {
Pica.charTable(encodeMap, decodeMap, '\u00a0', '\u00ff', Pica.charTable(new char[] {
new char[]{
'\u00a0', '\u0141', '\u00d8', '\u0110', '\u00de', '\u00c6', '\u00a0', '\u0141', '\u00d8', '\u0110', '\u00de', '\u00c6',
'\u0152', '\u02b9', '\u00b7', '\u266d', '\u00ae', '\u00b1', '\u0152', '\u02b9', '\u00b7', '\u266d', '\u00ae', '\u00b1',
'\u01a0', '\u01af', '\u02be', '\u00c5', '\u02bf', '\u0142', '\u01a0', '\u01af', '\u02be', '\u00c5', '\u02bf', '\u0142',
@ -86,7 +86,7 @@ public class Pica extends Charset {
// Handle to the real charset we'll use for transcoding between // Handle to the real charset we'll use for transcoding between
// characters and bytes. Doing this allows applying the Pica // characters and bytes. Doing this allows applying the Pica
// charset to multi-byte charset encodings like UTF-8. // charset to multi-byte charset encodings like UTF-8.
private Charset encodeCharset; private final Charset encodeCharset;
/** /**
* Constructor for the Pica charset. Call the superclass * Constructor for the Pica charset. Call the superclass
@ -101,16 +101,13 @@ public class Pica extends Charset {
/** /**
* Fill the conversion tables. * Fill the conversion tables.
*/ */
private static void charTable(Map<Character, Character> encodeMap, Map<Character, Character> decodeMap, char from, char to, private static void charTable(char[] code) {
char[] code) {
int i = 0; int i = 0;
for (char c = '\u00a0'; c <= '\u00ff'; c++) {
for (char c = from; c <= to; c++) {
if (code[i] != '\u0000') { if (code[i] != '\u0000') {
encodeMap.put(code[i], c); encodeMap.put(code[i], c);
decodeMap.put(c, code[i]); decodeMap.put(c, code[i]);
} }
i++; i++;
} }
} }
@ -143,7 +140,7 @@ public class Pica extends Charset {
private static class PicaEncoder extends CharsetEncoder { private static class PicaEncoder extends CharsetEncoder {
private CharsetEncoder baseEncoder; private final CharsetEncoder baseEncoder;
/** /**
* Constructor, call the superclass constructor with the * Constructor, call the superclass constructor with the
@ -225,4 +222,3 @@ public class Pica extends Charset {
} }
} }
} }

View file

@ -47,7 +47,7 @@ public class PicaCharset extends Charset {
private static final Map<Character, Byte> CHAR_TO_BYTE_MAP = newCharToByteMap(); private static final Map<Character, Byte> CHAR_TO_BYTE_MAP = newCharToByteMap();
private boolean isNFCOutput; private final boolean isNFCOutput;
public PicaCharset() { public PicaCharset() {
this(true); this(true);

View file

@ -45,9 +45,8 @@ import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* This is a simplified version of "ANSEL charset" at http://anselcharset.sourceforge.net/ * This is a simplified version of "ANSEL charset" at http://anselcharset.sourceforge.net/
@ -57,11 +56,13 @@ import java.util.logging.Logger;
public class SimpleAnselCharset extends Charset { public class SimpleAnselCharset extends Charset {
private final Map<Character, byte[]> mapping; private final Map<Character, byte[]> mapping;
private final Map<Byte, ReverseMappingEntity> reverseMapping; private final Map<Byte, ReverseMappingEntity> reverseMapping;
public SimpleAnselCharset() { public SimpleAnselCharset() {
super("SIMPLE_ANSEL", BibliographicCharsetProvider.aliasesFor("SIMPLE_ANSEL")); super("SIMPLE_ANSEL", BibliographicCharsetProvider.aliasesFor("SIMPLE_ANSEL"));
mapping = createMapping(getClass().getResourceAsStream("ansel-mapping.txt")); this.mapping = createMapping(getClass().getResourceAsStream("ansel-mapping.txt"));
Objects.requireNonNull(this.mapping);
reverseMapping = createReverseMapping(mapping); reverseMapping = createReverseMapping(mapping);
} }
@ -90,10 +91,30 @@ public class SimpleAnselCharset extends Charset {
mapping.put(uniCode, ansCodes); mapping.put(uniCode, ansCodes);
} }
} }
} catch (IOException e) {
Logger.getLogger(SimpleAnselCharset.class.getName()).log(Level.WARNING, e.getMessage(), e);
}
return mapping; return mapping;
} catch (IOException e) {
return null;
}
}
@Override
public boolean canEncode() {
return true;
}
@Override
public CharsetDecoder newDecoder() {
return new Decoder(this, reverseMapping);
}
@Override
public CharsetEncoder newEncoder() {
return new Encoder(this);
}
@Override
public boolean contains(Charset cs) {
return displayName().equals(cs.displayName());
} }
private static Map<Byte, ReverseMappingEntity> createReverseMapping(Map<Character, byte[]> mapping) { private static Map<Byte, ReverseMappingEntity> createReverseMapping(Map<Character, byte[]> mapping) {
@ -118,28 +139,10 @@ public class SimpleAnselCharset extends Charset {
return rev; return rev;
} }
@Override
public boolean canEncode() {
return true;
}
@Override
public CharsetDecoder newDecoder() {
return new Decoder(this);
}
@Override
public CharsetEncoder newEncoder() {
return new Encoder(this);
}
@Override
public boolean contains(Charset cs) {
return displayName().equals(cs.displayName());
}
private static class ReverseMappingEntity { private static class ReverseMappingEntity {
private TreeMap<Byte, ReverseMappingEntity> mapping = new TreeMap<>();
private final TreeMap<Byte, ReverseMappingEntity> mapping = new TreeMap<>();
private Character character; private Character character;
public Character getCharacter() { public Character getCharacter() {
@ -155,11 +158,15 @@ public class SimpleAnselCharset extends Charset {
} }
} }
private class Decoder extends CharsetDecoder { private static class Decoder extends CharsetDecoder {
private LinkedList<Byte> buffer = new LinkedList<>();
Decoder(Charset charset) { private final Map<Byte, ReverseMappingEntity> reverseMapping;
private final LinkedList<Byte> buffer = new LinkedList<>();
Decoder(Charset charset, Map<Byte, ReverseMappingEntity> reverseMapping) {
super(charset, 2.2f, 3.0f); super(charset, 2.2f, 3.0f);
this.reverseMapping = reverseMapping;
} }
@Override @Override
@ -219,9 +226,11 @@ public class SimpleAnselCharset extends Charset {
} }
} }
abstract class ReverseMappingBuffer { abstract static class ReverseMappingBuffer {
private Map<Byte, ReverseMappingEntity> rm;
private LinkedList<Byte> buffer; private final Map<Byte, ReverseMappingEntity> rm;
private final LinkedList<Byte> buffer;
ReverseMappingBuffer(Map<Byte, ReverseMappingEntity> rm, LinkedList<Byte> buffer) { ReverseMappingBuffer(Map<Byte, ReverseMappingEntity> rm, LinkedList<Byte> buffer) {
this.rm = rm; this.rm = rm;

View file

@ -31,23 +31,23 @@
*/ */
package org.xbib.charset; package org.xbib.charset;
import org.junit.Assert; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetDecoder;
import java.nio.charset.StandardCharsets;
import java.text.Normalizer; import java.text.Normalizer;
/** /**
* *
*/ */
public class AnselCharsetTest extends Assert { public class AnselCharsetTest {
@Test @Test
public void testAnsel() throws Exception { public void testAnsel() throws Exception {
ByteBuffer buf = ByteBuffer.wrap("\u00e8\u0075".getBytes("ISO-8859-1")); ByteBuffer buf = ByteBuffer.wrap("\u00e8\u0075".getBytes(StandardCharsets.ISO_8859_1));
Charset charset = Charset.forName("ANSEL"); Charset charset = Charset.forName("ANSEL");
CharsetDecoder decoder = charset.newDecoder(); CharsetDecoder decoder = charset.newDecoder();
CharBuffer cbuf = decoder.decode(buf); CharBuffer cbuf = decoder.decode(buf);
@ -59,7 +59,8 @@ public class AnselCharsetTest extends Assert {
@Test @Test
public void testAnsel2() throws Exception { public void testAnsel2() throws Exception {
ByteBuffer buf = ByteBuffer.wrap("\u00AC\u00E2\u0041\u00ED\u0042\u00E2\u0043\u00E2\u0044".getBytes("ISO-8859-1")); ByteBuffer buf =
ByteBuffer.wrap("\u00AC\u00E2\u0041\u00ED\u0042\u00E2\u0043\u00E2\u0044".getBytes(StandardCharsets.ISO_8859_1));
Charset charset = Charset.forName("ANSEL"); Charset charset = Charset.forName("ANSEL");
CharsetDecoder decoder = charset.newDecoder(); CharsetDecoder decoder = charset.newDecoder();
CharBuffer cbuf = decoder.decode(buf); CharBuffer cbuf = decoder.decode(buf);

View file

@ -31,10 +31,8 @@
*/ */
package org.xbib.charset; package org.xbib.charset;
import org.apache.logging.log4j.LogManager; import org.junit.jupiter.api.Test;
import org.apache.logging.log4j.Logger; import java.util.logging.Logger;
import org.junit.Test;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
/** /**
@ -42,14 +40,12 @@ import javax.xml.stream.XMLStreamException;
*/ */
public class AnselCodeTableParserTest { public class AnselCodeTableParserTest {
private Logger logger = LogManager.getLogger(AnselCodeTableParserTest.class);
@Test @Test
public void test() throws XMLStreamException { public void test() throws XMLStreamException {
AnselCodeTableParser anselCodeTableParser = new AnselCodeTableParser(getClass().getResourceAsStream("codetables.xml")); AnselCodeTableParser anselCodeTableParser = new AnselCodeTableParser(getClass().getResourceAsStream("codetables.xml"));
for (AnselCodeTableParser.CodeTable codeTable : anselCodeTableParser.getCodeTables()) { for (AnselCodeTableParser.CodeTable codeTable : anselCodeTableParser.getCodeTables()) {
for (AnselCodeTableParser.CharacterSet characterSet : codeTable.getCharacterSets()) { for (AnselCodeTableParser.CharacterSet characterSet : codeTable.getCharacterSets()) {
logger.info("{} {}", characterSet.getName(), characterSet.getLength()); Logger.getLogger(AnselCodeTableParserTest.class.getName()).info(characterSet.getName() + " " + characterSet.getLength());
} }
} }
} }

View file

@ -31,10 +31,8 @@
*/ */
package org.xbib.charset; package org.xbib.charset;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;

View file

@ -31,9 +31,9 @@
*/ */
package org.xbib.charset; package org.xbib.charset;
import org.junit.Assert; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -44,12 +44,12 @@ import java.util.SortedMap;
/** /**
* *
*/ */
public class ISO5426Test extends Assert { public class ISO5426Test {
@Test @Test
public void listCharsets() throws Exception { public void listCharsets() throws Exception {
SortedMap<String, Charset> map = Charset.availableCharsets(); SortedMap<String, Charset> map = Charset.availableCharsets();
assertTrue(map.keySet().contains("ISO-5426")); assertTrue(map.containsKey("ISO-5426"));
} }
@Test @Test
@ -81,5 +81,4 @@ public class ISO5426Test extends Assert {
String output = cbuf.toString(); String output = cbuf.toString();
assertEquals(output, "£"); assertEquals(output, "£");
} }
} }

View file

@ -31,20 +31,20 @@
*/ */
package org.xbib.charset; package org.xbib.charset;
import org.junit.Assert; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.text.Normalizer; import java.text.Normalizer;
/** /**
* *
*/ */
public class NormalizerTest extends Assert { public class NormalizerTest {
@Test @Test
public void testNormalizer() throws Exception { public void testNormalizer() {
byte[] b = new byte[]{(byte) 103, (byte) 101, (byte) 109, (byte) 97, (byte) 204, (byte) 136, (byte) 195, (byte) 159}; byte[] b = new byte[]{(byte) 103, (byte) 101, (byte) 109, (byte) 97, (byte) 204, (byte) 136, (byte) 195, (byte) 159};
String input = new String(b, "UTF-8"); String input = new String(b, StandardCharsets.UTF_8);
String norm = Normalizer.normalize(input, Normalizer.Form.NFC); String norm = Normalizer.normalize(input, Normalizer.Form.NFC);
assertEquals("gemäß", norm); assertEquals("gemäß", norm);
} }
@ -56,5 +56,4 @@ public class NormalizerTest extends Assert {
String norm = Normalizer.normalize(s, Normalizer.Form.NFC); String norm = Normalizer.normalize(s, Normalizer.Form.NFC);
assertEquals(56, norm.length()); assertEquals(56, norm.length());
} }
} }

View file

@ -31,34 +31,34 @@
*/ */
package org.xbib.charset; package org.xbib.charset;
import org.junit.Assert; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetDecoder;
import java.nio.charset.StandardCharsets;
import java.util.SortedMap; import java.util.SortedMap;
/** /**
* *
*/ */
public class SimpleAnselCharsetTest extends Assert { public class SimpleAnselCharsetTest {
@Test @Test
public void listCharsets() throws Exception { public void listCharsets() {
SortedMap<String, Charset> map = Charset.availableCharsets(); SortedMap<String, Charset> map = Charset.availableCharsets();
assertTrue(map.keySet().contains("SIMPLE_ANSEL")); assertTrue(map.containsKey("SIMPLE_ANSEL"));
} }
@Test @Test
public void testSimpleAnsel() throws Exception { public void testSimpleAnsel() throws Exception {
ByteBuffer buf = ByteBuffer.wrap("\u00e8\u0075".getBytes("ISO-8859-1")); ByteBuffer buf = ByteBuffer.wrap("\u00e8\u0075".getBytes(StandardCharsets.ISO_8859_1));
Charset charset = Charset.forName("SIMPLE_ANSEL"); Charset charset = Charset.forName("SIMPLE_ANSEL");
CharsetDecoder decoder = charset.newDecoder(); CharsetDecoder decoder = charset.newDecoder();
CharBuffer cbuf = decoder.decode(buf); CharBuffer cbuf = decoder.decode(buf);
String output = cbuf.toString(); String output = cbuf.toString();
assertEquals("\u00fc", output); assertEquals("\u00fc", output);
} }
} }

View file

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%-25c][%t] %m%n"/>
</Console>
</appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</configuration>