update to OpenJDK 11, Gradle 5.3.1, xbib content 2.0.0

This commit is contained in:
Jörg Prante 2019-08-08 19:58:21 +02:00
parent d8426fcfc6
commit fac8020183
43 changed files with 10935 additions and 284 deletions

View file

@ -1,12 +0,0 @@
language: java
sudo: required
jdk:
- oraclejdk8
cache:
directories:
- $HOME/.m2
after_success:
- ./gradlew sonarqube -Dsonar.host.url=https://sonarqube.com -Dsonar.login=$SONAR_TOKEN
env:
global:
secure: n1Ai4q/yMLn/Pg5pA4lTavoJoe7mQYB1PSKnZAqwbgyla94ySzK6iyBCBiNs/foMPisB/x+DHvmUXTsjvquw9Ay48ZITCV3xhcWzD0eZM2TMoG19CpRAEe8L8LNuYiti9k89ijDdUGZ5ifsvQNTGNHksouayAuApC3PrTUejJfR6SYrp1ZsQTbsMlr+4XU3p7QknK5rGgOwATIMP28F+bVnB05WJtlJA3b0SeucCurn3wJ4FGBQXRYmdlT7bQhNE4QgZM1VzcUFD/K0TBxzzq/otb/lNRSifyoekktDmJwQnaT9uQ4R8R6KdQ2Kb38Rvgjur+TKm5i1G8qS2+6LnIxQJG1aw3JvKK6W0wWCgnAVVRrXaCLday9NuY59tuh1mfjQ10UcsMNKcTdcKEMrLow506wSETcXc7L/LEnneWQyJJeV4vhPqR7KJfsBbeqgz3yIfsCn1GZVWFlfegzYCN52YTl0Y0uRD2Z+TnzQu+Bf4DzaWXLge1rz31xkhyeNNspub4h024+XqBjcMm6M9mlMzmmK8t2DIwPy/BlQbFBUyhrxziuR/5/2NEDPyHltvWkRb4AUIa25WJqkV0gTBegbMadZ9DyOo6Ea7aoVFBae2WGR08F1kzABsWrd1S7UJmWxW35iyMEtoAIayXphIK98qO5aCutwZ+3iOQazxbAs=

View file

@ -1,67 +1,66 @@
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
plugins { plugins {
id "com.github.spotbugs" version "2.0.0"
id "org.sonarqube" version "2.6.1" id "org.sonarqube" version "2.6.1"
id "io.codearte.nexus-staging" version "0.11.0" id "io.codearte.nexus-staging" version "0.11.0"
id "org.xbib.gradle.plugin.asciidoctor" version "1.6.0.0" id "org.xbib.gradle.plugin.asciidoctor" version "1.6.0.1"
} }
printf "Date: %s\nHost: %s\nOS: %s %s %s\nJVM: %s %s %s %s\nGradle: %s Groovy: %s Java: %s\n" + apply plugin: 'java-library'
"Build: group: ${project.group} name: ${project.name} version: ${project.version}\n",
ZonedDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME),
InetAddress.getLocalHost(),
System.getProperty("os.name"),
System.getProperty("os.arch"),
System.getProperty("os.version"),
System.getProperty("java.version"),
System.getProperty("java.vm.version"),
System.getProperty("java.vm.vendor"),
System.getProperty("java.vm.name"),
gradle.gradleVersion, GroovySystem.getVersion(), JavaVersion.current()
apply plugin: 'java'
apply plugin: 'maven' apply plugin: 'maven'
apply plugin: 'signing' apply plugin: 'pmd'
apply plugin: 'checkstyle'
apply plugin: "com.github.spotbugs"
apply plugin: "io.codearte.nexus-staging" apply plugin: "io.codearte.nexus-staging"
apply plugin: 'org.xbib.gradle.plugin.asciidoctor' apply plugin: 'org.xbib.gradle.plugin.asciidoctor'
repositories {
mavenCentral()
}
configurations {
wagon
}
dependencies { dependencies {
testCompile "org.junit.vintage:junit-vintage-engine:${project.property('junit-vintage.version')}" testImplementation "org.junit.jupiter:junit-jupiter-api:${project.property('junit.version')}"
testCompile "org.xbib:bibliographic-character-sets:${project.property('xbib-bibliographic-character-sets.version')}" testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${project.property('junit.version')}"
testCompile "org.xbib:content-core:${project.property('xbib-content.version')}" testImplementation "junit:junit:4.12"
testCompile "xalan:xalan:${project.property('xalan.version')}" testImplementation "org.xbib:bibliographic-character-sets:${project.property('xbib-bibliographic-character-sets.version')}"
testCompile "org.xmlunit:xmlunit-matchers:${project.property('xmlunit-matchers.version')}" testImplementation "org.xbib:content-core:${project.property('xbib-content.version')}"
testCompile "com.github.stefanbirkner:system-rules:${project.property('system-rules.version')}" testImplementation "xalan:xalan:${project.property('xalan.version')}"
wagon "org.apache.maven.wagon:wagon-ssh:${project.property('wagon.version')}" testImplementation "org.xmlunit:xmlunit-matchers:${project.property('xmlunit-matchers.version')}"
testImplementation("com.github.stefanbirkner:system-rules:${project.property('system-rules.version')}") {
exclude module: 'junit'
}
} }
sourceCompatibility = JavaVersion.VERSION_1_9 compileJava {
targetCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
compileTestJava {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:all" // << "-profile" << "compact2" options.compilerArgs << "-Xlint:all"
if (JavaVersion.current().java9Compatible) { if (!options.compilerArgs.contains("-processor")) {
options.compilerArgs << '--release' << JavaVersion.toVersion(targetCompatibility).majorVersion options.compilerArgs << '-proc:none'
} }
} }
test { test {
useJUnitPlatform()
systemProperty 'java.util.logging.config.file', 'src/test/resources/logging.properties'
failFast = false
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"
}
}
// massive heap for for xmlunit DOM comparer // massive heap for for xmlunit DOM comparer
jvmArgs '-Xmx2048m' jvmArgs '-Xmx2048m'
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
}
} }
asciidoctor { asciidoctor {
@ -76,10 +75,6 @@ asciidoctor {
'source-highlighter': 'coderay' 'source-highlighter': 'coderay'
} }
clean {
delete 'out'
}
task sourcesJar(type: Jar, dependsOn: classes) { task sourcesJar(type: Jar, dependsOn: classes) {
classifier 'sources' classifier 'sources'
from sourceSets.main.allSource from sourceSets.main.allSource
@ -93,12 +88,114 @@ artifacts {
archives sourcesJar, javadocJar archives sourcesJar, javadocJar
} }
if (project.hasProperty('signing.keyId')) { ext {
signing { user = 'xbib'
sign configurations.archives projectName = 'marc'
projectDescription = 'MARC bibliographic data processing library for Java'
scmUrl = 'https://github.com/xbib/marc'
scmConnection = 'scm:git:git://github.com/xbib/marc.git'
scmDeveloperConnection = 'scm:git:git://github.com/xbib/marc.git'
}
spotbugs {
effort = "max"
reportLevel = "low"
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
ignoreFailures = true
reports {
xml.enabled = false
html.enabled = true
} }
} }
apply from: 'gradle/ext.gradle' tasks.withType(Pmd) {
apply from: 'gradle/publish.gradle' ignoreFailures = true
apply from: 'gradle/sourcequality.gradle' reports {
xml.enabled = true
html.enabled = true
}
}
tasks.withType(Checkstyle) {
ignoreFailures = true
reports {
xml.enabled = true
html.enabled = true
}
}
pmd {
toolVersion = '6.11.0'
ruleSets = ['category/java/bestpractices.xml']
}
checkstyle {
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
ignoreFailures = true
showViolations = true
}
sonarqube {
properties {
property "sonar.projectName", "${project.group} ${project.name}"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.tests", "src/test/java"
property "sonar.scm.provider", "git"
property "sonar.junit.reportsPath", "build/test-results/test/"
}
}
task sonatypeUpload(type: Upload) {
group = 'publish'
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 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
}
}
}
}
}
nexusStaging {
packageGroup = "org.xbib"
}

View file

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress checks="." files="[\\/]generated-src[\\/].*\.java$"/>
</suppressions>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,13 @@
#
# BSD-style license; for more info see http://pmd.sourceforge.net/license.html
#
rulesets.filenames=\
category/java/bestpractices.xml,\
category/java/codestyle.xml,\
category/java/design.xml,\
category/java/documentation.xml,\
category/java/errorprone.xml,\
category/java/multithreading.xml,\
category/java/performance.xml,\
category/java/security.xml

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,144 @@
<?xml version="1.0"?>
<ruleset name="Documentation"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>
Rules that are related to code documentation.
</description>
<rule name="CommentContent"
since="5.0"
message="Invalid words or phrases found"
class="net.sourceforge.pmd.lang.java.rule.documentation.CommentContentRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_documentation.html#commentcontent">
<description>
A rule for the politically correct... we don't want to offend anyone.
</description>
<priority>3</priority>
<example>
<![CDATA[
//OMG, this is horrible, Bob is an idiot !!!
]]>
</example>
</rule>
<rule name="CommentRequired"
since="5.1"
message="Comment is required"
class="net.sourceforge.pmd.lang.java.rule.documentation.CommentRequiredRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_documentation.html#commentrequired">
<description>
Denotes whether comments are required (or unwanted) for specific language elements.
</description>
<priority>3</priority>
<example>
<![CDATA[
/**
*
*
* @author Jon Doe
*/
]]>
</example>
</rule>
<rule name="CommentSize"
since="5.0"
message="Comment is too large"
class="net.sourceforge.pmd.lang.java.rule.documentation.CommentSizeRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_documentation.html#commentsize">
<description>
Determines whether the dimensions of non-header comments found are within the specified limits.
</description>
<priority>3</priority>
<example>
<![CDATA[
/**
*
* too many lines!
*
*
*
*
*
*
*
*
*
*
*
*
*/
]]>
</example>
</rule>
<rule name="UncommentedEmptyConstructor"
language="java"
since="3.4"
message="Document empty constructor"
class="net.sourceforge.pmd.lang.rule.XPathRule"
typeResolution="true"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_documentation.html#uncommentedemptyconstructor">
<description>
Uncommented Empty Constructor finds instances where a constructor does not
contain statements, but there is no comment. By explicitly commenting empty
constructors it is easier to distinguish between intentional (commented)
and unintentional empty constructors.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//ConstructorDeclaration[@Private='false']
[count(BlockStatement) = 0 and ($ignoreExplicitConstructorInvocation = 'true' or not(ExplicitConstructorInvocation)) and @containsComment = 'false']
[not(../Annotation/MarkerAnnotation/Name[pmd-java:typeIs('javax.inject.Inject')])]
]]>
</value>
</property>
<property name="ignoreExplicitConstructorInvocation" type="Boolean" description="Ignore explicit constructor invocation when deciding whether constructor is empty or not" value="false"/>
</properties>
<example>
<![CDATA[
public Foo() {
// This constructor is intentionally empty. Nothing special is needed here.
}
]]>
</example>
</rule>
<rule name="UncommentedEmptyMethodBody"
language="java"
since="3.4"
message="Document empty method body"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_documentation.html#uncommentedemptymethodbody">
<description>
Uncommented Empty Method Body finds instances where a method body does not contain
statements, but there is no comment. By explicitly commenting empty method bodies
it is easier to distinguish between intentional (commented) and unintentional
empty methods.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//MethodDeclaration/Block[count(BlockStatement) = 0 and @containsComment = 'false']
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
public void doSomething() {
}
]]>
</example>
</rule>
</ruleset>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,393 @@
<?xml version="1.0"?>
<ruleset name="Multithreading"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>
Rules that flag issues when dealing with multiple threads of execution.
</description>
<rule name="AvoidSynchronizedAtMethodLevel"
language="java"
since="3.0"
message="Use block level rather than method level synchronization"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#avoidsynchronizedatmethodlevel">
<description>
Method-level synchronization can cause problems when new code is added to the method.
Block-level synchronization helps to ensure that only the code that needs synchronization
gets it.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>//MethodDeclaration[@Synchronized='true']</value>
</property>
</properties>
<example>
<![CDATA[
public class Foo {
// Try to avoid this:
synchronized void foo() {
}
// Prefer this:
void bar() {
synchronized(this) {
}
}
// Try to avoid this for static methods:
static synchronized void fooStatic() {
}
// Prefer this:
static void barStatic() {
synchronized(Foo.class) {
}
}
}
]]>
</example>
</rule>
<rule name="AvoidThreadGroup"
language="java"
since="3.6"
message="Avoid using java.lang.ThreadGroup; it is not thread safe"
class="net.sourceforge.pmd.lang.rule.XPathRule"
typeResolution="true"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#avoidthreadgroup">
<description>
Avoid using java.lang.ThreadGroup; although it is intended to be used in a threaded environment
it contains methods that are not thread-safe.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//AllocationExpression/ClassOrInterfaceType[pmd-java:typeIs('java.lang.ThreadGroup')]|
//PrimarySuffix[contains(@Image, 'getThreadGroup')]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
public class Bar {
void buz() {
ThreadGroup tg = new ThreadGroup("My threadgroup");
tg = new ThreadGroup(tg, "my thread group");
tg = Thread.currentThread().getThreadGroup();
tg = System.getSecurityManager().getThreadGroup();
}
}
]]>
</example>
</rule>
<rule name="AvoidUsingVolatile"
language="java"
since="4.1"
class="net.sourceforge.pmd.lang.rule.XPathRule"
message="Use of modifier volatile is not recommended."
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#avoidusingvolatile">
<description>
Use of the keyword 'volatile' is generally used to fine tune a Java application, and therefore, requires
a good expertise of the Java Memory Model. Moreover, its range of action is somewhat misknown. Therefore,
the volatile keyword should not be used for maintenance purpose and portability.
</description>
<priority>2</priority>
<properties>
<property name="xpath">
<value>//FieldDeclaration[contains(@Volatile,'true')]</value>
</property>
</properties>
<example>
<![CDATA[
public class ThrDeux {
private volatile String var1; // not suggested
private String var2; // preferred
}
]]>
</example>
</rule>
<rule name="DoNotUseThreads"
language="java"
since="4.1"
class="net.sourceforge.pmd.lang.rule.XPathRule"
message="To be compliant to J2EE, a webapp should not use any thread."
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#donotusethreads">
<description>
The J2EE specification explicitly forbids the use of threads.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>//ClassOrInterfaceType[@Image = 'Thread' or @Image = 'Runnable']</value>
</property>
</properties>
<example>
<![CDATA[
// This is not allowed
public class UsingThread extends Thread {
}
// Neither this,
public class OtherThread implements Runnable {
// Nor this ...
public void methode() {
Runnable thread = new Thread(); thread.run();
}
}
]]>
</example>
</rule>
<rule name="DontCallThreadRun"
language="java"
since="4.3"
message="Don't call Thread.run() explicitly, use Thread.start()"
class="net.sourceforge.pmd.lang.rule.XPathRule"
typeResolution="true"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#dontcallthreadrun">
<description>
Explicitly calling Thread.run() method will execute in the caller's thread of control. Instead, call Thread.start() for the intended behavior.
</description>
<priority>4</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//StatementExpression/PrimaryExpression
[
PrimaryPrefix
[
./Name[ends-with(@Image, '.run') or @Image = 'run']
and substring-before(Name/@Image, '.') =//VariableDeclarator/VariableDeclaratorId/@Image
[../../../Type/ReferenceType/ClassOrInterfaceType[pmd-java:typeIs('java.lang.Thread')]]
or (./AllocationExpression/ClassOrInterfaceType[pmd-java:typeIs('java.lang.Thread')]
and ../PrimarySuffix[@Image = 'run'])
]
]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
Thread t = new Thread();
t.run(); // use t.start() instead
new Thread().run(); // same violation
]]>
</example>
</rule>
<rule name="DoubleCheckedLocking"
language="java"
since="1.04"
message="Double checked locking is not thread safe in Java."
class="net.sourceforge.pmd.lang.java.rule.multithreading.DoubleCheckedLockingRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#doublecheckedlocking">
<description>
Partially created objects can be returned by the Double Checked Locking pattern when used in Java.
An optimizing JRE may assign a reference to the baz variable before it calls the constructor of the object the
reference points to.
Note: With Java 5, you can make Double checked locking work, if you declare the variable to be `volatile`.
For more details refer to: &lt;http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html>
or &lt;http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html>
</description>
<priority>1</priority>
<example>
<![CDATA[
public class Foo {
/*volatile */ Object baz = null; // fix for Java5 and later: volatile
Object bar() {
if (baz == null) { // baz may be non-null yet not fully created
synchronized(this) {
if (baz == null) {
baz = new Object();
}
}
}
return baz;
}
}
]]>
</example>
</rule>
<rule name="NonThreadSafeSingleton"
since="3.4"
message="Singleton is not thread safe"
class="net.sourceforge.pmd.lang.java.rule.multithreading.NonThreadSafeSingletonRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#nonthreadsafesingleton">
<description>
Non-thread safe singletons can result in bad state changes. Eliminate
static singletons if possible by instantiating the object directly. Static
singletons are usually not needed as only a single instance exists anyway.
Other possible fixes are to synchronize the entire method or to use an
[initialize-on-demand holder class](https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom).
Refrain from using the double-checked locking pattern. The Java Memory Model doesn't
guarantee it to work unless the variable is declared as `volatile`, adding an uneeded
performance penalty. [Reference](http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html)
See Effective Java, item 48.
</description>
<priority>3</priority>
<example>
<![CDATA[
private static Foo foo = null;
//multiple simultaneous callers may see partially initialized objects
public static Foo getFoo() {
if (foo==null) {
foo = new Foo();
}
return foo;
}
]]>
</example>
</rule>
<rule name="UnsynchronizedStaticDateFormatter"
since="3.6"
deprecated="true"
message="Static DateFormatter objects should be accessed in a synchronized manner"
class="net.sourceforge.pmd.lang.java.rule.multithreading.UnsynchronizedStaticDateFormatterRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#unsynchronizedstaticdateformatter">
<description>
SimpleDateFormat instances are not synchronized. Sun recommends using separate format instances
for each thread. If multiple threads must access a static formatter, the formatter must be
synchronized either on method or block level.
This rule has been deprecated in favor of the rule {% rule UnsynchronizedStaticFormatter %}.
</description>
<priority>3</priority>
<example>
<![CDATA[
public class Foo {
private static final SimpleDateFormat sdf = new SimpleDateFormat();
void bar() {
sdf.format(); // poor, no thread-safety
}
synchronized void foo() {
sdf.format(); // preferred
}
}
]]>
</example>
</rule>
<rule name="UnsynchronizedStaticFormatter"
since="6.11.0"
message="Static Formatter objects should be accessed in a synchronized manner"
class="net.sourceforge.pmd.lang.java.rule.multithreading.UnsynchronizedStaticFormatterRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#unsynchronizedstaticformatter">
<description>
Instances of `java.text.Format` are generally not synchronized.
Sun recommends using separate format instances for each thread.
If multiple threads must access a static formatter, the formatter must be
synchronized either on method or block level.
</description>
<priority>3</priority>
<example>
<![CDATA[
public class Foo {
private static final SimpleDateFormat sdf = new SimpleDateFormat();
void bar() {
sdf.format(); // poor, no thread-safety
}
synchronized void foo() {
sdf.format(); // preferred
}
}
]]>
</example>
</rule>
<rule name="UseConcurrentHashMap"
language="java"
minimumLanguageVersion="1.5"
since="4.2.6"
message="If you run in Java5 or newer and have concurrent access, you should use the ConcurrentHashMap implementation"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#useconcurrenthashmap">
<description>
Since Java5 brought a new implementation of the Map designed for multi-threaded access, you can
perform efficient map reads without blocking other threads.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//Type[../VariableDeclarator/VariableInitializer//AllocationExpression/ClassOrInterfaceType[@Image != 'ConcurrentHashMap']]
/ReferenceType/ClassOrInterfaceType[@Image = 'Map']
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
public class ConcurrentApp {
public void getMyInstance() {
Map map1 = new HashMap(); // fine for single-threaded access
Map map2 = new ConcurrentHashMap(); // preferred for use with multiple threads
// the following case will be ignored by this rule
Map map3 = someModule.methodThatReturnMap(); // might be OK, if the returned map is already thread-safe
}
}
]]>
</example>
</rule>
<rule name="UseNotifyAllInsteadOfNotify"
language="java"
since="3.0"
message="Call Thread.notifyAll() rather than Thread.notify()"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#usenotifyallinsteadofnotify">
<description>
Thread.notify() awakens a thread monitoring the object. If more than one thread is monitoring, then only
one is chosen. The thread chosen is arbitrary; thus its usually safer to call notifyAll() instead.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//StatementExpression/PrimaryExpression
[PrimarySuffix/Arguments[@ArgumentCount = '0']]
[
PrimaryPrefix[
./Name[@Image='notify' or ends-with(@Image,'.notify')]
or ../PrimarySuffix/@Image='notify'
or (./AllocationExpression and ../PrimarySuffix[@Image='notify'])
]
]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
void bar() {
x.notify();
// If many threads are monitoring x, only one (and you won't know which) will be notified.
// use instead:
x.notifyAll();
}
]]>
</example>
</rule>
</ruleset>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,65 @@
<?xml version="1.0"?>
<ruleset name="Security" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>
Rules that flag potential security flaws.
</description>
<rule name="HardCodedCryptoKey"
since="6.4.0"
message="Do not use hard coded encryption keys"
class="net.sourceforge.pmd.lang.java.rule.security.HardCodedCryptoKeyRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_security.html#hardcodedcryptokey">
<description>
Do not use hard coded values for cryptographic operations. Please store keys outside of source code.
</description>
<priority>3</priority>
<example>
<![CDATA[
public class Foo {
void good() {
SecretKeySpec secretKeySpec = new SecretKeySpec(Properties.getKey(), "AES");
}
void bad() {
SecretKeySpec secretKeySpec = new SecretKeySpec("my secret here".getBytes(), "AES");
}
}
]]>
</example>
</rule>
<rule name="InsecureCryptoIv"
since="6.3.0"
message="Do not use hard coded initialization vector in crypto operations"
class="net.sourceforge.pmd.lang.java.rule.security.InsecureCryptoIvRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_security.html#insecurecryptoiv">
<description>
Do not use hard coded initialization vector in cryptographic operations. Please use a randomly generated IV.
</description>
<priority>3</priority>
<example>
<![CDATA[
public class Foo {
void good() {
SecureRandom random = new SecureRandom();
byte iv[] = new byte[16];
random.nextBytes(bytes);
}
void bad() {
byte[] iv = new byte[] { 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, };
}
void alsoBad() {
byte[] iv = "secret iv in here".getBytes();
}
}
]]>
</example>
</rule>
</ruleset>

View file

@ -1,11 +1,18 @@
group = org.xbib group = org.xbib
name = marc name = marc
version = 1.2.1 version = 2.0.0
xbib-content.version = 1.3.0 # main
xbib-content.version = 2.0.0
# runtime
xbib-bibliographic-character-sets.version = 1.0.0 xbib-bibliographic-character-sets.version = 1.0.0
# test
junit.version = 5.5.1
xalan.version = 2.7.2 xalan.version = 2.7.2
xmlunit-matchers.version = 2.3.0 xmlunit-matchers.version = 2.3.0
system-rules.version = 1.16.0 system-rules.version = 1.16.0
junit-vintage.version = 4.12.0
wagon.version = 3.0.0 org.gradle.warning.mode = all
org.gradle.daemon = false

View file

@ -1,8 +0,0 @@
ext {
user = 'xbib'
projectName = 'marc'
projectDescription = 'MARC bibliographic data processing library for Java'
scmUrl = 'https://github.com/xbib/marc'
scmConnection = 'scm:git:git://github.com/xbib/marc.git'
scmDeveloperConnection = 'scm:git:git://github.com/xbib/marc.git'
}

View file

@ -1,70 +0,0 @@
task xbibUpload(type: Upload) {
group = 'publish'
configuration = configurations.archives
uploadDescriptor = true
repositories {
if (project.hasProperty('xbibUsername')) {
mavenDeployer {
configuration = configurations.wagon
repository(url: uri(project.property('xbibUrl'))) {
authentication(userName: xbibUsername, privateKey: xbibPrivateKey)
}
}
}
}
}
task sonatypeUpload(type: Upload) {
group = 'publish'
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 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
}
}
}
}
}
nexusStaging {
packageGroup = "org.xbib"
}

View file

@ -1,45 +0,0 @@
/*spotbugs {
ignoreFailures = false
sourceSets = [sourceSets.main]
effort = "max"
reportLevel = "high"
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
reports {
xml.enabled = false
html.enabled = true
}
}
tasks.withType(Pmd) {
ignoreFailures = true
reports {
xml.enabled = true
html.enabled = true
}
}
tasks.withType(Checkstyle) {
ignoreFailures = true
reports {
xml.enabled = true
html.enabled = true
}
}
jacocoTestReport {
reports {
xml.enabled = true
csv.enabled = false
}
}
*/
sonarqube {
properties {
property "sonar.projectName", "${project.group} ${project.name}"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.tests", "src/test/java"
property "sonar.scm.provider", "git"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.junit.reportsPath", "build/test-results/test/"
}
}

Binary file not shown.

View file

@ -1,6 +1,6 @@
#Wed Mar 14 10:32:45 CET 2018 #Thu Aug 08 19:51:59 CEST 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-all.zip
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip zipStoreBase=GRADLE_USER_HOME

18
gradlew vendored
View file

@ -1,5 +1,21 @@
#!/usr/bin/env sh #!/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
#
# http://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.
#
############################################################################## ##############################################################################
## ##
## Gradle start up script for UN*X ## Gradle start up script for UN*X
@ -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"

18
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 http://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
@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@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

View file

@ -62,7 +62,13 @@ public class MarcRecord extends LinkedHashMap<String, Object> {
this.format = format; this.format = format;
this.type = type; this.type = type;
this.recordLabel = recordLabel; this.recordLabel = recordLabel;
if (recordLabel == null) {
throw new NullPointerException("record label must not be null");
}
this.marcFields = marcFields; this.marcFields = marcFields;
if (marcFields == null) {
throw new NullPointerException("fields must not be null");
}
if (!lightweight) { if (!lightweight) {
createMap(); createMap();
} }

View file

@ -46,7 +46,7 @@ public interface BytesReference {
int indexOf(byte b, int offset, int len); int indexOf(byte b, int offset, int len);
/** /**
* Slice the bytes from the <tt>from</tt> index up to <tt>length</tt>. * Slice the bytes from the {@code from} index up to {@code length}.
* *
* @param from from * @param from from
* @param length length * @param length length

View file

@ -16,6 +16,9 @@
*/ */
package org.xbib.marc.label; package org.xbib.marc.label;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Bibliographic level * Bibliographic level
* *
@ -71,6 +74,7 @@ package org.xbib.marc.label;
*/ */
public enum BibliographicLevel { public enum BibliographicLevel {
UNSPECIFIED(' '),
MONOGRPAHIC_COMPONENT_PART('a'), MONOGRPAHIC_COMPONENT_PART('a'),
SERIAL_COMPONENT_PART('b'), SERIAL_COMPONENT_PART('b'),
COLLECTION('c'), COLLECTION('c'),
@ -79,14 +83,22 @@ public enum BibliographicLevel {
MONOGRAPH('m'), MONOGRAPH('m'),
SERIAL('s'); SERIAL('s');
char ch; private static final Logger logger = Logger.getLogger(BibliographicLevel.class.getName());
private final char ch;
BibliographicLevel(char ch) { BibliographicLevel(char ch) {
this.ch = ch; this.ch = ch;
} }
static BibliographicLevel from(char ch) { public char getChar() {
return ch;
}
public static BibliographicLevel from(char ch) {
switch (ch) { switch (ch) {
case ' ':
return UNSPECIFIED;
case 'a': case 'a':
return MONOGRPAHIC_COMPONENT_PART; return MONOGRPAHIC_COMPONENT_PART;
case 'b': case 'b':
@ -102,12 +114,8 @@ public enum BibliographicLevel {
case 's': case 's':
return SERIAL; return SERIAL;
default: default:
break; logger.log(Level.FINEST, "unknown bibliographic level: " + ch);
} return UNSPECIFIED;
return null; }
}
public char getChar() {
return ch;
} }
} }

View file

@ -16,6 +16,9 @@
*/ */
package org.xbib.marc.label; package org.xbib.marc.label;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Descriptive cataloging form * Descriptive cataloging form
* *
@ -51,10 +54,12 @@ public enum DescriptiveCatalogingForm {
AACR2('a'), AACR2('a'),
ISBD_PUNCTUATION_OMITTED('c'), ISBD_PUNCTUATION_OMITTED('c'),
ISBD_PUNCTUATION_INCLUDED('i'), ISBD_PUNCTUATION_INCLUDED('i'),
UNKNOWN('u') UNKNOWN('u');
;
private static final Logger logger = Logger.getLogger(DescriptiveCatalogingForm.class.getName());
private final char ch;
char ch;
DescriptiveCatalogingForm(char ch) { DescriptiveCatalogingForm(char ch) {
this.ch = ch; this.ch = ch;
} }
@ -62,4 +67,22 @@ public enum DescriptiveCatalogingForm {
public char getChar() { public char getChar() {
return ch; return ch;
} }
public static DescriptiveCatalogingForm from(char ch) {
switch (ch) {
case ' ':
return NON_ISBD;
case 'a':
return AACR2;
case 'c':
return ISBD_PUNCTUATION_OMITTED;
case 'i':
return ISBD_PUNCTUATION_INCLUDED;
case 'u':
return UNKNOWN;
default:
logger.log(Level.FINEST, "unknown descriptive cataloging form: " + ch);
return NON_ISBD;
}
}
} }

View file

@ -16,6 +16,9 @@
*/ */
package org.xbib.marc.label; package org.xbib.marc.label;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Character encoding * Character encoding
* *
@ -41,7 +44,10 @@ public enum Encoding {
MARC8(' '), MARC8(' '),
UCS_UNICODE('a'); UCS_UNICODE('a');
char ch; private static final Logger logger = Logger.getLogger(Encoding.class.getName());
private final char ch;
Encoding(char ch) { Encoding(char ch) {
this.ch = ch; this.ch = ch;
} }
@ -49,4 +55,16 @@ public enum Encoding {
public char getChar() { public char getChar() {
return ch; return ch;
} }
public static Encoding from(char ch) {
switch (ch) {
case ' ':
return MARC8;
case 'a':
return UCS_UNICODE;
default:
logger.log(Level.FINEST, "unknown encoding: " + ch);
return MARC8;
}
}
} }

View file

@ -16,6 +16,9 @@
*/ */
package org.xbib.marc.label; package org.xbib.marc.label;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Encoding level * Encoding level
* *
@ -86,10 +89,12 @@ public enum EncodingLevel {
MINIMAL('7'), MINIMAL('7'),
PREPUBLICATION('8'), PREPUBLICATION('8'),
UNKNOWN('u'), UNKNOWN('u'),
NOT_APPLICABLE('z') NOT_APPLICABLE('z');
;
private static final Logger logger = Logger.getLogger(EncodingLevel.class.getName());
private final char ch;
char ch;
EncodingLevel(char ch) { EncodingLevel(char ch) {
this.ch = ch; this.ch = ch;
} }
@ -97,4 +102,32 @@ public enum EncodingLevel {
public char getChar() { public char getChar() {
return ch; return ch;
} }
public static EncodingLevel from(char ch) {
switch (ch) {
case ' ':
return FULL;
case '1':
return FULL_NOT_EXAMINED;
case '2':
return LESS_THAN_FULL_NOT_EXAMINED;
case '3':
return ABBREV;
case '4':
return CORE;
case '5':
return PARTIAL;
case '7':
return MINIMAL;
case '8':
return PREPUBLICATION;
case 'u':
return UNKNOWN;
case 'z':
return NOT_APPLICABLE;
default:
logger.log(Level.FINEST,"unknown encoding level " + ch);
return FULL;
}
}
} }

View file

@ -16,6 +16,9 @@
*/ */
package org.xbib.marc.label; package org.xbib.marc.label;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Multipart resource record level * Multipart resource record level
* Record level to which a resource pertains and any record dependencies. * Record level to which a resource pertains and any record dependencies.
@ -43,10 +46,12 @@ public enum MultipartResourceRecordLevel {
NOT_SPECIFIED(' '), NOT_SPECIFIED(' '),
SET('a'), SET('a'),
PART_WITH_INDEPENDENT_TITLE('b'), PART_WITH_INDEPENDENT_TITLE('b'),
PART_WITH_DEPENDENT_TITLE('c') PART_WITH_DEPENDENT_TITLE('c');
;
private static final Logger logger = Logger.getLogger(MultipartResourceRecordLevel.class.getName());
private final char ch;
char ch;
MultipartResourceRecordLevel(char ch) { MultipartResourceRecordLevel(char ch) {
this.ch = ch; this.ch = ch;
} }
@ -54,4 +59,20 @@ public enum MultipartResourceRecordLevel {
public char getChar() { public char getChar() {
return ch; return ch;
} }
public static MultipartResourceRecordLevel from(char ch) {
switch (ch) {
case ' ':
return NOT_SPECIFIED;
case 'a':
return SET;
case 'b':
return PART_WITH_INDEPENDENT_TITLE;
case 'c':
return PART_WITH_DEPENDENT_TITLE;
default:
logger.log(Level.FINEST, "unknown multipart resource record level: " + ch);
return NOT_SPECIFIED;
}
}
} }

View file

@ -502,7 +502,6 @@ public class RecordLabel {
label = newLabel; label = newLabel;
} }
System.arraycopy(label, 0, cfix, 0, LENGTH); System.arraycopy(label, 0, cfix, 0, LENGTH);
repair();
return this; return this;
} }
@ -516,32 +515,28 @@ public class RecordLabel {
pos = new int[] { 5, 6, 7, 8, 9, 17, 18, 19, 23 }; pos = new int[] { 5, 6, 7, 8, 9, 17, 18, 19, 23 };
for (int i : pos) { for (int i : pos) {
if (cfix[i] == '^' || cfix[i] == '-') { if (cfix[i] == '^' || cfix[i] == '-') {
cfix[i] = ' '; cfix[i] = ' '; // unspecified
} }
// suppress C0 control chars (for XML 1.0 output) // suppress C0 control chars (for XML 1.0 output)
if (cfix[i] < 32) { if (cfix[i] < 32) {
cfix[i] = ' '; cfix[i] = ' '; // unspecified
} }
} }
} }
private void assign() { private void assign() {
this.recordLength = Integer.parseInt(new StringBuilder() this.recordLength = Integer.parseInt(String.valueOf(cfix[0]) + cfix[1] + cfix[2] + cfix[3] + cfix[4]);
.append(cfix[0])
.append(cfix[1])
.append(cfix[2])
.append(cfix[3])
.append(cfix[4]).toString());
this.recordStatus = RecordStatus.from(cfix[5]); this.recordStatus = RecordStatus.from(cfix[5]);
this.typeOfRecord = TypeOfRecord.from(cfix[6]);
this.bibliographicLevel = BibliographicLevel.from(cfix[7]); this.bibliographicLevel = BibliographicLevel.from(cfix[7]);
this.typeOfControl = TypeOfControl.from(cfix[8]);
this.encoding = Encoding.from(cfix[9]);
this.indicatorLength = cfix[10] - '0'; this.indicatorLength = cfix[10] - '0';
this.subfieldIdentifierLength = cfix[11] - '0'; this.subfieldIdentifierLength = cfix[11] - '0';
this.baseAddressOfData = Integer.parseInt(new StringBuilder() this.baseAddressOfData = Integer.parseInt(String.valueOf(cfix[12]) + cfix[13] + cfix[14] + cfix[15] + cfix[16]);
.append(cfix[12]) this.encodingLevel = EncodingLevel.from(cfix[17]);
.append(cfix[13]) this.descriptiveCatalogingForm = DescriptiveCatalogingForm.from(cfix[18]);
.append(cfix[14]) this.multipartResourceRecordLevel = MultipartResourceRecordLevel.from(cfix[19]);
.append(cfix[15])
.append(cfix[16]).toString());
this.dataFieldLength = cfix[20] - '0'; this.dataFieldLength = cfix[20] - '0';
this.startingCharacterPositionLength = cfix[21] - '0'; this.startingCharacterPositionLength = cfix[21] - '0';
this.segmentIdentifierLength = cfix[22] - '0'; this.segmentIdentifierLength = cfix[22] - '0';
@ -552,6 +547,7 @@ public class RecordLabel {
* @return the record label * @return the record label
*/ */
public RecordLabel build() { public RecordLabel build() {
repair();
assign(); assign();
return new RecordLabel(this, new String(cfix)); return new RecordLabel(this, new String(cfix));
} }

View file

@ -16,6 +16,9 @@
*/ */
package org.xbib.marc.label; package org.xbib.marc.label;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Record status * Record status
* *
@ -45,20 +48,29 @@ package org.xbib.marc.label;
*/ */
public enum RecordStatus { public enum RecordStatus {
UNKNOWN(' '),
INCREASE_IN_ENCODING_LEVEL('a'), INCREASE_IN_ENCODING_LEVEL('a'),
CORRECTED_OR_REVISED('c'), CORRECTED_OR_REVISED('c'),
DELETED('d'), DELETED('d'),
NEW('n'), NEW('n'),
INCREASE_IN_ENCODING_LEVEL_FROM_PREPUBLICATION('p'); INCREASE_IN_ENCODING_LEVEL_FROM_PREPUBLICATION('p');
char ch; private static final Logger logger = Logger.getLogger(RecordStatus.class.getName());
private final char ch;
RecordStatus(char ch) { RecordStatus(char ch) {
this.ch = ch; this.ch = ch;
} }
static RecordStatus from(char ch) { public char getChar() {
return ch;
}
public static RecordStatus from(char ch) {
switch (ch) { switch (ch) {
case ' ':
return UNKNOWN;
case 'a': case 'a':
return INCREASE_IN_ENCODING_LEVEL; return INCREASE_IN_ENCODING_LEVEL;
case 'c': case 'c':
@ -70,12 +82,8 @@ public enum RecordStatus {
case 'p': case 'p':
return INCREASE_IN_ENCODING_LEVEL_FROM_PREPUBLICATION; return INCREASE_IN_ENCODING_LEVEL_FROM_PREPUBLICATION;
default: default:
break; logger.log(Level.FINEST,"unknown record status: " + ch);
} return UNKNOWN;
return null; }
}
public char getChar() {
return ch;
} }
} }

View file

@ -16,6 +16,9 @@
*/ */
package org.xbib.marc.label; package org.xbib.marc.label;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Type of control * Type of control
* *
@ -30,11 +33,13 @@ package org.xbib.marc.label;
*/ */
public enum TypeOfControl { public enum TypeOfControl {
NO_SPECIFIED_TYPE(' '), UNSPECIFIED(' '),
ARCHIVAL('a') ARCHIVAL('a');
;
private static final Logger logger = Logger.getLogger(TypeOfControl.class.getName());
private final char ch;
char ch;
TypeOfControl(char ch) { TypeOfControl(char ch) {
this.ch = ch; this.ch = ch;
} }
@ -42,4 +47,16 @@ public enum TypeOfControl {
public char getChar() { public char getChar() {
return ch; return ch;
} }
public static TypeOfControl from(char ch) {
switch (ch) {
case ' ' :
return UNSPECIFIED;
case 'a' :
return ARCHIVAL;
default:
logger.log(Level.FINEST,"unknown type of control: " + ch);
return UNSPECIFIED;
}
}
} }

View file

@ -16,6 +16,9 @@
*/ */
package org.xbib.marc.label; package org.xbib.marc.label;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Type of record * Type of record
* *
@ -130,6 +133,7 @@ package org.xbib.marc.label;
*/ */
public enum TypeOfRecord { public enum TypeOfRecord {
UNSPECIFIED(' '),
LANGUAGE_MATERIAL('a'), LANGUAGE_MATERIAL('a'),
LANGUAGE_MATERIAL_MANUSCRIPT('b'), LANGUAGE_MATERIAL_MANUSCRIPT('b'),
NOTATED_MUSIC('c'), NOTATED_MUSIC('c'),
@ -145,10 +149,11 @@ public enum TypeOfRecord {
KIT('o'), KIT('o'),
MIXED_MATERIALS('p'), MIXED_MATERIALS('p'),
ARTIFACT('r'), ARTIFACT('r'),
LANGUAGE_MATERIAL_MANUSCRIPT_MARC21('t') LANGUAGE_MATERIAL_MANUSCRIPT_MARC21('t');
;
char ch; private static final Logger logger = Logger.getLogger(TypeOfRecord.class.getName());
private final char ch;
TypeOfRecord(char ch) { TypeOfRecord(char ch) {
this.ch = ch; this.ch = ch;
@ -158,4 +163,45 @@ public enum TypeOfRecord {
return ch; return ch;
} }
static TypeOfRecord from(char ch) {
switch (ch) {
case ' ':
return UNSPECIFIED;
case 'a':
return LANGUAGE_MATERIAL;
case 'b':
return LANGUAGE_MATERIAL_MANUSCRIPT;
case 'c':
return NOTATED_MUSIC;
case 'd':
return NOTATED_MUSIC_MANUSCRIPT;
case 'e':
return CARTOGRAPHIC_MATERIAL;
case 'f':
return CARTOGRAPHIC_MATERIAL_MANUSCRIPT;
case 'g':
return PROJECTED_MEDIUM;
case 'i':
return NONMUSICAL_SOUND_RECORDING;
case 'j':
return MUSICAL_SOUND_RECORDING;
case 'k':
return PICTURE;
case 'l':
return ELECTRONIC_RESOURCE;
case 'm':
return COMPUTER_FILE;
case 'o':
return KIT;
case 'p':
return MIXED_MATERIALS;
case 'r':
return ARTIFACT;
case 't':
return LANGUAGE_MATERIAL_MANUSCRIPT_MARC21;
default:
logger.log(Level.FINEST,"unknown type of record: " + ch);
return UNSPECIFIED;
}
}
} }

View file

@ -1,3 +0,0 @@
/**
*/
package org.xbib.helper;

View file

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
*/ */
package org.xbib.helper; package org.xbib.marc;
import org.junit.Assert; import org.junit.Assert;
@ -37,11 +37,10 @@ public class StreamMatcher extends Assert {
public static void assertStream(String name, InputStream expected, InputStream actual) throws IOException { public static void assertStream(String name, InputStream expected, InputStream actual) throws IOException {
int offset = 0; int offset = 0;
ReadableByteChannel ch1 = Channels.newChannel(expected); try (ReadableByteChannel ch1 = Channels.newChannel(expected);
ReadableByteChannel ch2 = Channels.newChannel(actual); ReadableByteChannel ch2 = Channels.newChannel(actual)) {
ByteBuffer buf1 = ByteBuffer.allocateDirect(4096); ByteBuffer buf1 = ByteBuffer.allocateDirect(4096);
ByteBuffer buf2 = ByteBuffer.allocateDirect(4096); ByteBuffer buf2 = ByteBuffer.allocateDirect(4096);
try {
while (true) { while (true) {
int n1 = ch1.read(buf1); int n1 = ch1.read(buf1);
int n2 = ch2.read(buf2); int n2 = ch2.read(buf2);
@ -68,9 +67,6 @@ public class StreamMatcher extends Assert {
buf2.compact(); buf2.compact();
offset += Math.min(n1, n2); offset += Math.min(n1, n2);
} }
} finally {
expected.close();
actual.close();
} }
} }
} }

View file

@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.xbib.helper.StreamMatcher.assertStream; import static org.xbib.marc.StreamMatcher.assertStream;
import org.junit.Test; import org.junit.Test;
import org.xbib.marc.json.MarcJsonWriter; import org.xbib.marc.json.MarcJsonWriter;

View file

@ -10,15 +10,12 @@ import org.xbib.marc.MarcRecord;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
/** /**
* *
*/ */
public class HBZTest { public class HBZTest {
private static final Logger logger = Logger.getLogger(HBZTest.class.getName());
@Test @Test
public void testMarcStream() throws Exception { public void testMarcStream() throws Exception {
String[] files = { String[] files = {
@ -54,7 +51,6 @@ public class HBZTest {
.setCharset(Charset.forName("x-MAB")); .setCharset(Charset.forName("x-MAB"));
for (MarcRecord marcRecord : builder.iterable()) { for (MarcRecord marcRecord : builder.iterable()) {
count++; count++;
logger.info("record = " + marcRecord);
} }
} }
assertEquals(1, count); assertEquals(1, count);

View file

@ -18,7 +18,7 @@ package org.xbib.marc.dialects.mab;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.xbib.helper.StreamMatcher.assertStream; import static org.xbib.marc.StreamMatcher.assertStream;
import static org.xbib.marc.transformer.field.MarcFieldTransformer.Operator.HEAD; import static org.xbib.marc.transformer.field.MarcFieldTransformer.Operator.HEAD;
import static org.xbib.marc.transformer.field.MarcFieldTransformer.Operator.TAIL; import static org.xbib.marc.transformer.field.MarcFieldTransformer.Operator.TAIL;

View file

@ -1,7 +1,7 @@
package org.xbib.marc.dialects.mab; package org.xbib.marc.dialects.mab;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.xbib.helper.StreamMatcher.assertStream; import static org.xbib.marc.StreamMatcher.assertStream;
import org.junit.Test; import org.junit.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;

View file

@ -17,7 +17,7 @@
package org.xbib.marc.dialects.pica; package org.xbib.marc.dialects.pica;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.xbib.helper.StreamMatcher.assertStream; import static org.xbib.marc.StreamMatcher.assertStream;
import org.junit.Test; import org.junit.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;

View file

@ -16,7 +16,7 @@
*/ */
package org.xbib.marc.io; package org.xbib.marc.io;
import static org.xbib.helper.StreamMatcher.assertStream; import static org.xbib.marc.StreamMatcher.assertStream;
import org.junit.Test; import org.junit.Test;

View file

@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.xbib.helper.StreamMatcher.assertStream; import static org.xbib.marc.StreamMatcher.assertStream;
import org.junit.Test; import org.junit.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;

View file

@ -140,7 +140,7 @@ public class RecordLabelTest {
.setDescriptiveCatalogingForm(DescriptiveCatalogingForm.ISBD_PUNCTUATION_INCLUDED) .setDescriptiveCatalogingForm(DescriptiveCatalogingForm.ISBD_PUNCTUATION_INCLUDED)
.setMultipartResourceRecordLevel(MultipartResourceRecordLevel.PART_WITH_DEPENDENT_TITLE) .setMultipartResourceRecordLevel(MultipartResourceRecordLevel.PART_WITH_DEPENDENT_TITLE)
.setTypeOfRecord(TypeOfRecord.ARTIFACT) .setTypeOfRecord(TypeOfRecord.ARTIFACT)
.setTypeOfControl(TypeOfControl.NO_SPECIFIED_TYPE) .setTypeOfControl(TypeOfControl.UNSPECIFIED)
.build(); .build();
assertEquals(RecordStatus.DELETED, recordLabel.getRecordStatus()); assertEquals(RecordStatus.DELETED, recordLabel.getRecordStatus());
assertEquals(BibliographicLevel.INTEGRATING_RESOURCE, recordLabel.getBibliographicLevel()); assertEquals(BibliographicLevel.INTEGRATING_RESOURCE, recordLabel.getBibliographicLevel());
@ -148,7 +148,20 @@ public class RecordLabelTest {
assertEquals(DescriptiveCatalogingForm.ISBD_PUNCTUATION_INCLUDED, recordLabel.getDescriptiveCatalogingForm()); assertEquals(DescriptiveCatalogingForm.ISBD_PUNCTUATION_INCLUDED, recordLabel.getDescriptiveCatalogingForm());
assertEquals(MultipartResourceRecordLevel.PART_WITH_DEPENDENT_TITLE, recordLabel.getMultipartResourceRecordLevel()); assertEquals(MultipartResourceRecordLevel.PART_WITH_DEPENDENT_TITLE, recordLabel.getMultipartResourceRecordLevel());
assertEquals(TypeOfRecord.ARTIFACT, recordLabel.getTypeOfRecord()); assertEquals(TypeOfRecord.ARTIFACT, recordLabel.getTypeOfRecord());
assertEquals(TypeOfControl.NO_SPECIFIED_TYPE, recordLabel.getTypeOfControl()); assertEquals(TypeOfControl.UNSPECIFIED, recordLabel.getTypeOfControl());
}
@Test
public void testRecordLabelCharArray() {
char[] ch = "01723nam a22004818c 4500".toCharArray();
RecordLabel recordLabel = RecordLabel.builder().from(ch).build();
assertEquals(RecordStatus.NEW, recordLabel.getRecordStatus());
assertEquals(BibliographicLevel.MONOGRAPH, recordLabel.getBibliographicLevel());
assertEquals(EncodingLevel.PREPUBLICATION, recordLabel.getEncodingLevel());
assertEquals(DescriptiveCatalogingForm.ISBD_PUNCTUATION_OMITTED, recordLabel.getDescriptiveCatalogingForm());
assertEquals(MultipartResourceRecordLevel.NOT_SPECIFIED, recordLabel.getMultipartResourceRecordLevel());
assertEquals(TypeOfRecord.LANGUAGE_MATERIAL, recordLabel.getTypeOfRecord());
assertEquals(TypeOfControl.UNSPECIFIED, recordLabel.getTypeOfControl());
} }
@Test @Test

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="debug">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</configuration>

View file

@ -0,0 +1,5 @@
handlers = java.util.logging.ConsoleHandler
.level = FINE
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format = %1$tFT%1$tT.%1$tL%1$tz [%4$-11s] [%3$s] %5$s %6$s%n