1
0

Introduce end-of-line normalization

This commit is contained in:
Alex Herbert
2023-09-02 13:36:58 +01:00
parent 2e0bd27487
commit acd4893d89
15 changed files with 3631 additions and 3630 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
* text=auto

View File

@@ -1,85 +1,85 @@
# Licensed to the Apache Software Foundation (ASF) under one or more # Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with # contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. # this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0 # The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with # (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at # the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
name: "CodeQL" name: "CodeQL"
on: on:
push: push:
branches: [ master ] branches: [ master ]
pull_request: pull_request:
# The branches below must be a subset of the branches above # The branches below must be a subset of the branches above
branches: [ master ] branches: [ master ]
schedule: schedule:
- cron: '33 9 * * 4' - cron: '33 9 * * 4'
permissions: permissions:
contents: read contents: read
jobs: jobs:
analyze: analyze:
name: Analyze name: Analyze
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
actions: read actions: read
contents: read contents: read
security-events: write security-events: write
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
language: [ 'java' ] language: [ 'java' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support # Learn more about CodeQL language support at https://git.io/codeql-language-support
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
with: with:
persist-credentials: false persist-credentials: false
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with: with:
path: ~/.m2/repository path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: | restore-keys: |
${{ runner.os }}-maven- ${{ runner.os }}-maven-
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.21.5 uses: github/codeql-action/init@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.21.5
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file. # If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file. # By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file. # Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main # queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below) # If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.21.5 uses: github/codeql-action/autobuild@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.21.5
# Command-line programs to run using the OS shell. # Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl # 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project # and modify them (or add more) to build your code if your project
# uses a compiled language # uses a compiled language
#- run: | #- run: |
# make bootstrap # make bootstrap
# make release # make release
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.21.5 uses: github/codeql-action/analyze@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.21.5

View File

@@ -1,52 +1,52 @@
# Licensed to the Apache Software Foundation (ASF) under one or more # Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with # contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. # this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0 # The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with # (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at # the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
name: Java CI name: Java CI
on: [push, pull_request] on: [push, pull_request]
permissions: permissions:
contents: read contents: read
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }} continue-on-error: ${{ matrix.experimental }}
strategy: strategy:
matrix: matrix:
java: [ 8, 11, 17 ] java: [ 8, 11, 17 ]
experimental: [false] experimental: [false]
# include: # include:
# - java: 18-ea # - java: 18-ea
# experimental: true # experimental: true
steps: steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
with: with:
persist-credentials: false persist-credentials: false
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with: with:
path: ~/.m2/repository path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: | restore-keys: |
${{ runner.os }}-maven- ${{ runner.os }}-maven-
- name: Set up JDK ${{ matrix.java }} - name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0 uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
with: with:
distribution: 'temurin' distribution: 'temurin'
java-version: ${{ matrix.java }} java-version: ${{ matrix.java }}
- name: Build with Maven - name: Build with Maven
run: mvn -V --no-transfer-progress -D doclint=none --file pom.xml run: mvn -V --no-transfer-progress -D doclint=none --file pom.xml

206
README.md
View File

@@ -1,103 +1,103 @@
<!--- <!---
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<!--- <!---
+======================================================================+ +======================================================================+
|**** ****| |**** ****|
|**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****| |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****|
|**** DO NOT EDIT DIRECTLY ****| |**** DO NOT EDIT DIRECTLY ****|
|**** ****| |**** ****|
+======================================================================+ +======================================================================+
| TEMPLATE FILE: readme-md-template.md | | TEMPLATE FILE: readme-md-template.md |
| commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates | | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates |
+======================================================================+ +======================================================================+
| | | |
| 1) Re-generate using: mvn commons:readme-md | | 1) Re-generate using: mvn commons:readme-md |
| | | |
| 2) Set the following properties in the component's pom: | | 2) Set the following properties in the component's pom: |
| - commons.componentid (required, alphabetic, lower case) | | - commons.componentid (required, alphabetic, lower case) |
| - commons.release.version (required) | | - commons.release.version (required) |
| | | |
| 3) Example Properties | | 3) Example Properties |
| | | |
| <properties> | | <properties> |
| <commons.componentid>math</commons.componentid> | | <commons.componentid>math</commons.componentid> |
| <commons.release.version>1.2</commons.release.version> | | <commons.release.version>1.2</commons.release.version> |
| </properties> | | </properties> |
| | | |
+======================================================================+ +======================================================================+
---> --->
Apache Commons Logging Apache Commons Logging
=================== ===================
[![GitHub Actions Status](https://github.com/apache/commons-logging/workflows/Java%20CI/badge.svg)](https://github.com/apache/commons-logging/actions) [![GitHub Actions Status](https://github.com/apache/commons-logging/workflows/Java%20CI/badge.svg)](https://github.com/apache/commons-logging/actions)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/commons-logging/commons-logging/badge.svg?gav=true)](https://maven-badges.herokuapp.com/maven-central/commons-logging/commons-logging/?gav=true) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/commons-logging/commons-logging/badge.svg?gav=true)](https://maven-badges.herokuapp.com/maven-central/commons-logging/commons-logging/?gav=true)
[![CodeQL](https://github.com/apache/commons-logging/workflows/CodeQL/badge.svg)](https://github.com/apache/commons-logging/actions/workflows/codeql-analysis.yml?query=workflow%3ACodeQL) [![CodeQL](https://github.com/apache/commons-logging/workflows/CodeQL/badge.svg)](https://github.com/apache/commons-logging/actions/workflows/codeql-analysis.yml?query=workflow%3ACodeQL)
Apache Commons Logging is a thin adapter allowing configurable bridging to other, well known logging systems. Apache Commons Logging is a thin adapter allowing configurable bridging to other, well known logging systems.
Documentation Documentation
------------- -------------
More information can be found on the [Apache Commons Logging homepage](https://commons.apache.org/proper/commons-logging). More information can be found on the [Apache Commons Logging homepage](https://commons.apache.org/proper/commons-logging).
The [Javadoc](https://commons.apache.org/proper/commons-logging/javadocs/api-release) can be browsed. The [Javadoc](https://commons.apache.org/proper/commons-logging/javadocs/api-release) can be browsed.
Questions related to the usage of Apache Commons Logging should be posted to the [user mailing list][ml]. Questions related to the usage of Apache Commons Logging should be posted to the [user mailing list][ml].
Where can I get the latest release? Where can I get the latest release?
----------------------------------- -----------------------------------
You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-logging/download_logging.cgi). You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-logging/download_logging.cgi).
Alternatively, you can pull it from the central Maven repositories: Alternatively, you can pull it from the central Maven repositories:
```xml ```xml
<dependency> <dependency>
<groupId>commons-logging</groupId> <groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId> <artifactId>commons-logging</artifactId>
<version>1.2</version> <version>1.2</version>
</dependency> </dependency>
``` ```
Contributing Contributing
------------ ------------
We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors. We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors.
There are some guidelines which will make applying PRs easier for us: There are some guidelines which will make applying PRs easier for us:
+ No tabs! Please use spaces for indentation. + No tabs! Please use spaces for indentation.
+ Respect the code style. + Respect the code style.
+ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change. + Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
+ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn```. + Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn```.
If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas). If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas).
You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md). You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md).
License License
------- -------
This code is under the [Apache License v2](https://www.apache.org/licenses/LICENSE-2.0). This code is under the [Apache License v2](https://www.apache.org/licenses/LICENSE-2.0).
See the `NOTICE.txt` file for required notices and attributions. See the `NOTICE.txt` file for required notices and attributions.
Donations Donations
--------- ---------
You like Apache Commons Logging? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development. You like Apache Commons Logging? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development.
Additional Resources Additional Resources
-------------------- --------------------
+ [Apache Commons Homepage](https://commons.apache.org/) + [Apache Commons Homepage](https://commons.apache.org/)
+ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/LOGGING) + [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/LOGGING)
+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) + [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
+ `#apache-commons` IRC channel on `irc.freenode.org` + `#apache-commons` IRC channel on `irc.freenode.org`
[ml]:https://commons.apache.org/mail-lists.html [ml]:https://commons.apache.org/mail-lists.html

View File

@@ -1,191 +1,191 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- <!--
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<!-- <!--
This file is also used by the maven-changes-plugin to generate the release notes. This file is also used by the maven-changes-plugin to generate the release notes.
Useful ways of finding items to add to this file are: Useful ways of finding items to add to this file are:
1. Add items when you fix a bug or add a feature (this makes the 1. Add items when you fix a bug or add a feature (this makes the
release process easy :-). release process easy :-).
2. Do a JIRA search for tickets closed since the previous release. 2. Do a JIRA search for tickets closed since the previous release.
3. Use the report generated by the maven-changelog-plugin to see all 3. Use the report generated by the maven-changelog-plugin to see all
SVN commits. TBA how to use this with SVN. SVN commits. TBA how to use this with SVN.
To generate the release notes from this file: To generate the release notes from this file:
mvn changes:announcement-generate -Prelease-notes [-Dchanges.version=nn] mvn changes:announcement-generate -Prelease-notes [-Dchanges.version=nn]
then tweak the formatting if necessary then tweak the formatting if necessary
and commit and commit
The <action> type attribute can be add,update,fix,remove. The <action> type attribute can be add,update,fix,remove.
--> -->
<document xmlns="http://maven.apache.org/changes/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/xsd/changes-1.0.0.xsd"> <document xmlns="http://maven.apache.org/changes/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/xsd/changes-1.0.0.xsd">
<properties> <properties>
<title>Release Notes</title> <title>Release Notes</title>
</properties> </properties>
<body> <body>
<release version="1.3.0" date="TBD" description="This is a maintenance release containing bug fixes. Java 8 or later is required."> <release version="1.3.0" date="TBD" description="This is a maintenance release containing bug fixes. Java 8 or later is required.">
<!-- FIXES --> <!-- FIXES -->
<action issue="LOGGING-165" dev="britter" type="add"> <action issue="LOGGING-165" dev="britter" type="add">
Add Automatic-Module-Name Manifest Header for Java 9 compatibility. Add Automatic-Module-Name Manifest Header for Java 9 compatibility.
</action> </action>
<action issue="LOGGING-163" dev="ggregory" type="fix" due-to="Kaloyan Spiridonov"> <action issue="LOGGING-163" dev="ggregory" type="fix" due-to="Kaloyan Spiridonov">
BufferedReader is not closed properly. BufferedReader is not closed properly.
</action> </action>
<action issue="LOGGING-177" dev="ggregory" type="fix" due-to="Arturo Bernal"> <action issue="LOGGING-177" dev="ggregory" type="fix" due-to="Arturo Bernal">
Remove redundant initializer #46 Remove redundant initializer #46
</action> </action>
<action dev="ggregory" type="fix" due-to="Jakob van Kruijssen, Bruno P. Kinoshita, Gary Gregory"> <action dev="ggregory" type="fix" due-to="Jakob van Kruijssen, Bruno P. Kinoshita, Gary Gregory">
Use a weak reference for the cached class loader #71. Use a weak reference for the cached class loader #71.
</action> </action>
<action dev="ggregory" type="fix" due-to="xiaozhiliaoo"> <action dev="ggregory" type="fix" due-to="xiaozhiliaoo">
Add more entries to .gitignore file #25. Add more entries to .gitignore file #25.
</action> </action>
<action dev="ggregory" type="fix" due-to="Arturo Bernal"> <action dev="ggregory" type="fix" due-to="Arturo Bernal">
Minor Improvements #34. Minor Improvements #34.
</action> </action>
<action type="fix" dev="ggregory" due-to="step-security-bot, Gary Gregory"> <action type="fix" dev="ggregory" due-to="step-security-bot, Gary Gregory">
[StepSecurity] ci: Harden GitHub Actions #145. [StepSecurity] ci: Harden GitHub Actions #145.
</action> </action>
<!-- UPDATES --> <!-- UPDATES -->
<action dev="ggregory" type="update" due-to="Gary Gregory"> <action dev="ggregory" type="update" due-to="Gary Gregory">
Bump Java from 6 to 8. Bump Java from 6 to 8.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory"> <action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory">
Bump actions/cache from 2 to 3.0.10 #50, #77, #95, #98, #107, #110. Bump actions/cache from 2 to 3.0.10 #50, #77, #95, #98, #107, #110.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory"> <action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory">
Bump actions/checkout from 2.3.1 to 3.1.0, #24, #63, #75, #109. Bump actions/checkout from 2.3.1 to 3.1.0, #24, #63, #75, #109.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory"> <action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory">
Bump actions/setup-java from 1.4.0 to 3.5.1 #21. Bump actions/setup-java from 1.4.0 to 3.5.1 #21.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory"> <action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory">
Bump junit from 3.8.1 to 5.9.1 Vintage #23, #38. Bump junit from 3.8.1 to 5.9.1 Vintage #23, #38.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot"> <action dev="ggregory" type="update" due-to="Dependabot">
Bump clirr-maven-plugin from 2.2.2 to 2.8 #14. Bump clirr-maven-plugin from 2.2.2 to 2.8 #14.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot"> <action dev="ggregory" type="update" due-to="Dependabot">
Bump findbugs-maven-plugin from 2.5.2 to 3.0.5 #8. Bump findbugs-maven-plugin from 2.5.2 to 3.0.5 #8.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory"> <action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory">
Bump maven-failsafe-plugin from 2.12 to 3.0.0-M7 #31, #91. Bump maven-failsafe-plugin from 2.12 to 3.0.0-M7 #31, #91.
</action> </action>
<action dev="ggregory" type="update" due-to="Gary Gregory"> <action dev="ggregory" type="update" due-to="Gary Gregory">
Bump spotbugs-surefire-plugin from 2.22.2 to 3.0.0-M5. Bump spotbugs-surefire-plugin from 2.22.2 to 3.0.0-M5.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot"> <action dev="ggregory" type="update" due-to="Dependabot">
Bump maven-dependency-plugin from 2.4 to 3.5.0 #29, #79, #117, #131. Bump maven-dependency-plugin from 2.4 to 3.5.0 #29, #79, #117, #131.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot"> <action dev="ggregory" type="update" due-to="Dependabot">
Bump maven-pmd-plugin from 3.3 to 3.19.0 #28, #90, #100, #103. Bump maven-pmd-plugin from 3.3 to 3.19.0 #28, #90, #100, #103.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot"> <action dev="ggregory" type="update" due-to="Dependabot">
Bump maven-assembly-plugin from 2.5 to 3.4.2 #30, #94, #96. Bump maven-assembly-plugin from 2.5 to 3.4.2 #30, #94, #96.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot"> <action dev="ggregory" type="update" due-to="Dependabot">
Bump servlet-api from 2.3 to 2.5 #27. Bump servlet-api from 2.3 to 2.5 #27.
</action> </action>
<action dev="ggregory" type="update" due-to="Gary Gregory, Dependabot"> <action dev="ggregory" type="update" due-to="Gary Gregory, Dependabot">
Bump maven-checkstyle-plugin from 2.7 to 3.2.1 #35, #101, #130. Bump maven-checkstyle-plugin from 2.7 to 3.2.1 #35, #101, #130.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot"> <action dev="ggregory" type="update" due-to="Dependabot">
Bump spotbugs-maven-plugin from 4.1.4 to 4.7.2.1 #33, #70, #78, #93, #97, #102, #112. Bump spotbugs-maven-plugin from 4.1.4 to 4.7.2.1 #33, #70, #78, #93, #97, #102, #112.
</action> </action>
<action dev="ggregory" type="update" due-to="Dependabot"> <action dev="ggregory" type="update" due-to="Dependabot">
Bump spotbugs from 4.5.3 to 4.7.3 #81, #87, #92, #104, #115. Bump spotbugs from 4.5.3 to 4.7.3 #81, #87, #92, #104, #115.
</action> </action>
<action dev="kinow" type="update" due-to="Dependabot, Gary Gregory"> <action dev="kinow" type="update" due-to="Dependabot, Gary Gregory">
Bump commons-parent from 52 to 59 #82, #106, #122, #126, #143. Bump commons-parent from 52 to 59 #82, #106, #122, #126, #143.
</action> </action>
<action dev="kinow" type="update" due-to="Dependabot"> <action dev="kinow" type="update" due-to="Dependabot">
Bump github/codeql-action from 1 to 2 #86. Bump github/codeql-action from 1 to 2 #86.
</action> </action>
</release> </release>
<release version="1.2" date="2014-07-11" description="This is a maintenance release containing bug fixes. Java 6 or later is required."> <release version="1.2" date="2014-07-11" description="This is a maintenance release containing bug fixes. Java 6 or later is required.">
<action issue="LOGGING-37" dev="tn" type="fix" due-to="Matthias Ernst,Archie Cobbs"> <action issue="LOGGING-37" dev="tn" type="fix" due-to="Matthias Ernst,Archie Cobbs">
Improve performance of LogFactory#getFactory() by calling Thread#currentThread()#getContextClassLoader() Improve performance of LogFactory#getFactory() by calling Thread#currentThread()#getContextClassLoader()
directly instead of using reflection. As a consequence support for JDK 1.1 has been dropped. directly instead of using reflection. As a consequence support for JDK 1.1 has been dropped.
</action> </action>
<action issue="LOGGING-156" dev="tn" type="fix" due-to="Mikolaj Izdebski"> <action issue="LOGGING-156" dev="tn" type="fix" due-to="Mikolaj Izdebski">
Fix SecurityAllowedTestCase when executed with OpenJDK 1.7 due to an additional required RuntimePermission. Fix SecurityAllowedTestCase when executed with OpenJDK 1.7 due to an additional required RuntimePermission.
</action> </action>
<action issue="LOGGING-157" dev="tn" type="fix" due-to="Ville Skyttä"> <action issue="LOGGING-157" dev="tn" type="fix" due-to="Ville Skyttä">
Fix javadoc to comply with javadoc tool from jdk 1.8. Fix javadoc to comply with javadoc tool from jdk 1.8.
</action> </action>
</release> </release>
<release version="1.1.3" date="2013-05-23" description="This is a maintenance release containing bug fixes."> <release version="1.1.3" date="2013-05-23" description="This is a maintenance release containing bug fixes.">
<action issue="LOGGING-151" dev="tn" type="fix" due-to="Krzysztof Daniel"> <action issue="LOGGING-151" dev="tn" type="fix" due-to="Krzysztof Daniel">
Use "org.apache.commons.logging" as bundle symbolic name. Use "org.apache.commons.logging" as bundle symbolic name.
</action> </action>
</release> </release>
<release version="1.1.2" date="2013-03-20" description="This is a maintenance release containing bug fixes."> <release version="1.1.2" date="2013-03-20" description="This is a maintenance release containing bug fixes.">
<action issue="LOGGING-124" dev="tn" type="fix" due-to="Christian Schneider"> <action issue="LOGGING-124" dev="tn" type="fix" due-to="Christian Schneider">
The jar manifest now contains proper OSGi-related metadata information. The jar manifest now contains proper OSGi-related metadata information.
</action> </action>
<action issue="LOGGING-144" dev="tn" type="fix" due-to="Sebastian Bazley"> <action issue="LOGGING-144" dev="tn" type="fix" due-to="Sebastian Bazley">
LogFactory and LogFactoryImpl will not swallow certain errors anymore (ThreadDeath LogFactory and LogFactoryImpl will not swallow certain errors anymore (ThreadDeath
and VirtualMachineError). and VirtualMachineError).
</action> </action>
<action issue="LOGGING-135" dev="tn" type="update" due-to="Sebastian Bazley"> <action issue="LOGGING-135" dev="tn" type="update" due-to="Sebastian Bazley">
Improved thread-safety for several log adapters, including AvalonLogger, SimpleLog, Improved thread-safety for several log adapters, including AvalonLogger, SimpleLog,
Log4JLogger, LogKitLogger. Log4JLogger, LogKitLogger.
</action> </action>
<action issue="LOGGING-138" dev="tn" type="update" due-to="Luke Lu"> <action issue="LOGGING-138" dev="tn" type="update" due-to="Luke Lu">
In case of a discovery failure now also the stacktrace of the cause will be In case of a discovery failure now also the stacktrace of the cause will be
added to the diagnostic message. added to the diagnostic message.
</action> </action>
<action issue="LOGGING-132" dev="tn" type="fix" due-to="Nathan Niesen"> <action issue="LOGGING-132" dev="tn" type="fix" due-to="Nathan Niesen">
Jdk14Logger now correctly uses the specified logger name. Jdk14Logger now correctly uses the specified logger name.
</action> </action>
<action issue="LOGGING-133" dev="tn" type="update" due-to="Shevek"> <action issue="LOGGING-133" dev="tn" type="update" due-to="Shevek">
Change scope of Jdk14Logger.log(Level, String, Throwable) to protected, allowing Change scope of Jdk14Logger.log(Level, String, Throwable) to protected, allowing
subclasses to modify the logging output. subclasses to modify the logging output.
</action> </action>
<action issue="LOGGING-146" dev="tn" type="fix" due-to="Sebastian Bazley"> <action issue="LOGGING-146" dev="tn" type="fix" due-to="Sebastian Bazley">
Properly synchronize access to protected static field LogFactory.nullClassLoaderFactory. Properly synchronize access to protected static field LogFactory.nullClassLoaderFactory.
</action> </action>
<action issue="LOGGING-119" dev="tn" type="fix" due-to="Nitzan Niv, Philippe Mouawad"> <action issue="LOGGING-119" dev="tn" type="fix" due-to="Nitzan Niv, Philippe Mouawad">
Prevent potential deadlock scenario in WeakHashtable. Prevent potential deadlock scenario in WeakHashtable.
</action> </action>
<action issue="LOGGING-130" dev="sebb" type="fix" due-to="Matthew P. Del Buono"> <action issue="LOGGING-130" dev="sebb" type="fix" due-to="Matthew P. Del Buono">
Potential missing privileged block for class loader. Potential missing privileged block for class loader.
</action> </action>
<action issue="LOGGING-145" dev="sebb" type="fix"> <action issue="LOGGING-145" dev="sebb" type="fix">
LogFactoryImpl.setAttribute - possible NPE. LogFactoryImpl.setAttribute - possible NPE.
</action> </action>
<action issue="LOGGING-142" dev="sebb" type="fix" due-to="Jingguo Yao"> <action issue="LOGGING-142" dev="sebb" type="fix" due-to="Jingguo Yao">
Log4JLogger uses deprecated static members of Priority such as INFO. Log4JLogger uses deprecated static members of Priority such as INFO.
</action> </action>
<action issue="LOGGING-128" dev="sebb" type="fix" due-to="Peter Lawrey"> <action issue="LOGGING-128" dev="sebb" type="fix" due-to="Peter Lawrey">
Static analysis suggests a number of potential improvements. Static analysis suggests a number of potential improvements.
</action> </action>
<action issue="LOGGING-147" dev="sebb" type="fix"> <action issue="LOGGING-147" dev="sebb" type="fix">
SimpleLog.log - unsafe update of shortLogName. SimpleLog.log - unsafe update of shortLogName.
</action> </action>
<action issue="LOGGING-148" dev="sebb" type="fix"> <action issue="LOGGING-148" dev="sebb" type="fix">
LogFactory.diagnosticPrefix and diagnosticsStream could be final. LogFactory.diagnosticPrefix and diagnosticsStream could be final.
</action> </action>
</release> </release>
</body> </body>
</document> </document>

File diff suppressed because it is too large Load Diff

View File

@@ -1,66 +1,66 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging; package org.apache.commons.logging;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
* Generic tests that can be applied to any log adapter by * Generic tests that can be applied to any log adapter by
* subclassing this class and defining method getLogObject * subclassing this class and defining method getLogObject
* appropriately. * appropriately.
*/ */
public abstract class AbstractLogTest extends TestCase { public abstract class AbstractLogTest extends TestCase {
public abstract Log getLogObject(); public abstract Log getLogObject();
public void testLoggingWithNullParameters() public void testLoggingWithNullParameters()
{ {
final Log log = this.getLogObject(); final Log log = this.getLogObject();
assertNotNull(log); assertNotNull(log);
log.debug(null); log.debug(null);
log.debug(null, null); log.debug(null, null);
log.debug(log.getClass().getName() + ": debug statement"); log.debug(log.getClass().getName() + ": debug statement");
log.debug(log.getClass().getName() + ": debug statement w/ null exception", new RuntimeException()); log.debug(log.getClass().getName() + ": debug statement w/ null exception", new RuntimeException());
log.error(null); log.error(null);
log.error(null, null); log.error(null, null);
log.error(log.getClass().getName() + ": error statement"); log.error(log.getClass().getName() + ": error statement");
log.error(log.getClass().getName() + ": error statement w/ null exception", new RuntimeException()); log.error(log.getClass().getName() + ": error statement w/ null exception", new RuntimeException());
log.fatal(null); log.fatal(null);
log.fatal(null, null); log.fatal(null, null);
log.fatal(log.getClass().getName() + ": fatal statement"); log.fatal(log.getClass().getName() + ": fatal statement");
log.fatal(log.getClass().getName() + ": fatal statement w/ null exception", new RuntimeException()); log.fatal(log.getClass().getName() + ": fatal statement w/ null exception", new RuntimeException());
log.info(null); log.info(null);
log.info(null, null); log.info(null, null);
log.info(log.getClass().getName() + ": info statement"); log.info(log.getClass().getName() + ": info statement");
log.info(log.getClass().getName() + ": info statement w/ null exception", new RuntimeException()); log.info(log.getClass().getName() + ": info statement w/ null exception", new RuntimeException());
log.trace(null); log.trace(null);
log.trace(null, null); log.trace(null, null);
log.trace(log.getClass().getName() + ": trace statement"); log.trace(log.getClass().getName() + ": trace statement");
log.trace(log.getClass().getName() + ": trace statement w/ null exception", new RuntimeException()); log.trace(log.getClass().getName() + ": trace statement w/ null exception", new RuntimeException());
log.warn(null); log.warn(null);
log.warn(null, null); log.warn(null, null);
log.warn(log.getClass().getName() + ": warn statement"); log.warn(log.getClass().getName() + ": warn statement");
log.warn(log.getClass().getName() + ": warn statement w/ null exception", new RuntimeException()); log.warn(log.getClass().getName() + ": warn statement w/ null exception", new RuntimeException());
} }
} }

View File

@@ -1,216 +1,216 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging; package org.apache.commons.logging;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
* test to emulate container and application isolated from container * test to emulate container and application isolated from container
*/ */
public class LoadTestCase extends TestCase{ public class LoadTestCase extends TestCase{
//TODO: need some way to add service provider packages //TODO: need some way to add service provider packages
static private String[] LOG_PCKG = {"org.apache.commons.logging", static private String[] LOG_PCKG = {"org.apache.commons.logging",
"org.apache.commons.logging.impl"}; "org.apache.commons.logging.impl"};
/** /**
* A custom classloader which "duplicates" logging classes available * A custom classloader which "duplicates" logging classes available
* in the parent classloader into itself. * in the parent classloader into itself.
* <p> * <p>
* When asked to load a class that is in one of the LOG_PCKG packages, * When asked to load a class that is in one of the LOG_PCKG packages,
* it loads the class itself (child-first). This class doesn't need * it loads the class itself (child-first). This class doesn't need
* to be set up with a classpath, as it simply uses the same classpath * to be set up with a classpath, as it simply uses the same classpath
* as the classloader that loaded it. * as the classloader that loaded it.
*/ */
static class AppClassLoader extends ClassLoader { static class AppClassLoader extends ClassLoader {
java.util.Map classes = new java.util.HashMap(); java.util.Map classes = new java.util.HashMap();
AppClassLoader(final ClassLoader parent) { AppClassLoader(final ClassLoader parent) {
super(parent); super(parent);
} }
private Class def(final String name) throws ClassNotFoundException { private Class def(final String name) throws ClassNotFoundException {
Class result = (Class) classes.get(name); Class result = (Class) classes.get(name);
if (result != null) { if (result != null) {
return result; return result;
} }
try { try {
final ClassLoader cl = this.getClass().getClassLoader(); final ClassLoader cl = this.getClass().getClassLoader();
final String classFileName = name.replace('.', '/') + ".class"; final String classFileName = name.replace('.', '/') + ".class";
final java.io.InputStream is = cl.getResourceAsStream(classFileName); final java.io.InputStream is = cl.getResourceAsStream(classFileName);
final java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(); final java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
while (is.available() > 0) { while (is.available() > 0) {
out.write(is.read()); out.write(is.read());
} }
final byte[] data = out.toByteArray(); final byte[] data = out.toByteArray();
result = super.defineClass(name, data, 0, data.length); result = super.defineClass(name, data, 0, data.length);
classes.put(name, result); classes.put(name, result);
return result; return result;
} catch (final java.io.IOException ioe) { } catch (final java.io.IOException ioe) {
throw new ClassNotFoundException(name + " caused by " + ioe.getMessage()); throw new ClassNotFoundException(name + " caused by " + ioe.getMessage());
} }
} }
// not very trivial to emulate we must implement "findClass", // not very trivial to emulate we must implement "findClass",
// but it will delegate to JUnit class loader first // but it will delegate to JUnit class loader first
@Override @Override
public Class loadClass(final String name) throws ClassNotFoundException { public Class loadClass(final String name) throws ClassNotFoundException {
// isolates all logging classes, application in the same classloader too. // isolates all logging classes, application in the same classloader too.
// filters exceptions to simplify handling in test // filters exceptions to simplify handling in test
for (final String element : LOG_PCKG) { for (final String element : LOG_PCKG) {
if (name.startsWith(element) && name.indexOf("Exception") == -1) { if (name.startsWith(element) && name.indexOf("Exception") == -1) {
return def(name); return def(name);
} }
} }
return super.loadClass(name); return super.loadClass(name);
} }
} }
/** /**
* Call the static setAllowFlawedContext method on the specified class * Call the static setAllowFlawedContext method on the specified class
* (expected to be a UserClass loaded via a custom classloader), passing * (expected to be a UserClass loaded via a custom classloader), passing
* it the specified state parameter. * it the specified state parameter.
*/ */
private void setAllowFlawedContext(final Class c, final String state) throws Exception { private void setAllowFlawedContext(final Class c, final String state) throws Exception {
final Class[] params = {String.class}; final Class[] params = {String.class};
final java.lang.reflect.Method m = c.getDeclaredMethod("setAllowFlawedContext", params); final java.lang.reflect.Method m = c.getDeclaredMethod("setAllowFlawedContext", params);
m.invoke(null, state); m.invoke(null, state);
} }
/** /**
* Test what happens when we play various classloader tricks like those * Test what happens when we play various classloader tricks like those
* that happen in web and j2ee containers. * that happen in web and j2ee containers.
* <p> * <p>
* Note that this test assumes that commons-logging.jar and log4j.jar * Note that this test assumes that commons-logging.jar and log4j.jar
* are available via the system classpath. * are available via the system classpath.
*/ */
public void testInContainer()throws Exception{ public void testInContainer()throws Exception{
//problem can be in this step (broken app container or missconfiguration) //problem can be in this step (broken app container or missconfiguration)
//1. Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); //1. Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
//2. Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); //2. Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
// we expect this : // we expect this :
// 1. Thread.currentThread().setContextClassLoader(appLoader); // 1. Thread.currentThread().setContextClassLoader(appLoader);
// 2. Thread.currentThread().setContextClassLoader(null); // 2. Thread.currentThread().setContextClassLoader(null);
// Context classloader is same as class calling into log // Context classloader is same as class calling into log
Class cls = reload(); Class cls = reload();
Thread.currentThread().setContextClassLoader(cls.getClassLoader()); Thread.currentThread().setContextClassLoader(cls.getClassLoader());
execute(cls); execute(cls);
// Context classloader is the "bootclassloader". This is technically // Context classloader is the "bootclassloader". This is technically
// bad, but LogFactoryImpl.ALLOW_FLAWED_CONTEXT defaults to true so // bad, but LogFactoryImpl.ALLOW_FLAWED_CONTEXT defaults to true so
// this test should pass. // this test should pass.
cls = reload(); cls = reload();
Thread.currentThread().setContextClassLoader(null); Thread.currentThread().setContextClassLoader(null);
execute(cls); execute(cls);
// Context classloader is the "bootclassloader". This is same as above // Context classloader is the "bootclassloader". This is same as above
// except that ALLOW_FLAWED_CONTEXT is set to false; an error should // except that ALLOW_FLAWED_CONTEXT is set to false; an error should
// now be reported. // now be reported.
cls = reload(); cls = reload();
Thread.currentThread().setContextClassLoader(null); Thread.currentThread().setContextClassLoader(null);
try { try {
setAllowFlawedContext(cls, "false"); setAllowFlawedContext(cls, "false");
execute(cls); execute(cls);
fail("Logging config succeeded when context classloader was null!"); fail("Logging config succeeded when context classloader was null!");
} catch (final LogConfigurationException ex) { } catch (final LogConfigurationException ex) {
// expected; the boot classloader doesn't *have* JCL available // expected; the boot classloader doesn't *have* JCL available
} }
// Context classloader is the system classloader. // Context classloader is the system classloader.
// //
// This is expected to cause problems, as LogFactoryImpl will attempt // This is expected to cause problems, as LogFactoryImpl will attempt
// to use the system classloader to load the Log4JLogger class, which // to use the system classloader to load the Log4JLogger class, which
// will then be unable to cast that object to the Log interface loaded // will then be unable to cast that object to the Log interface loaded
// via the child classloader. However as ALLOW_FLAWED_CONTEXT defaults // via the child classloader. However as ALLOW_FLAWED_CONTEXT defaults
// to true this test should pass. // to true this test should pass.
cls = reload(); cls = reload();
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
execute(cls); execute(cls);
// Context classloader is the system classloader. This is the same // Context classloader is the system classloader. This is the same
// as above except that ALLOW_FLAWED_CONTEXT is set to false; an error // as above except that ALLOW_FLAWED_CONTEXT is set to false; an error
// should now be reported. // should now be reported.
cls = reload(); cls = reload();
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
try { try {
setAllowFlawedContext(cls, "false"); setAllowFlawedContext(cls, "false");
execute(cls); execute(cls);
fail("Error: somehow downcast a Logger loaded via system classloader" fail("Error: somehow downcast a Logger loaded via system classloader"
+ " to the Log interface loaded via a custom classloader"); + " to the Log interface loaded via a custom classloader");
} catch (final LogConfigurationException ex) { } catch (final LogConfigurationException ex) {
// expected // expected
} }
} }
/** /**
* Load class UserClass via a temporary classloader which is a child of * Load class UserClass via a temporary classloader which is a child of
* the classloader used to load this test class. * the classloader used to load this test class.
*/ */
private Class reload() throws Exception { private Class reload() throws Exception {
Class testObjCls = null; Class testObjCls = null;
final AppClassLoader appLoader = new AppClassLoader(this.getClass().getClassLoader()); final AppClassLoader appLoader = new AppClassLoader(this.getClass().getClassLoader());
try { try {
testObjCls = appLoader.loadClass(UserClass.class.getName()); testObjCls = appLoader.loadClass(UserClass.class.getName());
} catch (final ClassNotFoundException cnfe) { } catch (final ClassNotFoundException cnfe) {
throw cnfe; throw cnfe;
} catch (final Throwable t) { } catch (final Throwable t) {
t.printStackTrace(); t.printStackTrace();
fail("AppClassLoader failed "); fail("AppClassLoader failed ");
} }
assertSame("app isolated", testObjCls.getClassLoader(), appLoader); assertSame("app isolated", testObjCls.getClassLoader(), appLoader);
return testObjCls; return testObjCls;
} }
private void execute(final Class cls) throws Exception { private void execute(final Class cls) throws Exception {
cls.newInstance(); cls.newInstance();
} }
@Override @Override
public void setUp() { public void setUp() {
// save state before test starts so we can restore it when test ends // save state before test starts so we can restore it when test ends
origContextClassLoader = Thread.currentThread().getContextClassLoader(); origContextClassLoader = Thread.currentThread().getContextClassLoader();
} }
@Override @Override
public void tearDown() { public void tearDown() {
// restore original state so a test can't stuff up later tests. // restore original state so a test can't stuff up later tests.
Thread.currentThread().setContextClassLoader(origContextClassLoader); Thread.currentThread().setContextClassLoader(origContextClassLoader);
} }
private ClassLoader origContextClassLoader; private ClassLoader origContextClassLoader;
} }

View File

@@ -1,43 +1,43 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.avalon; package org.apache.commons.logging.avalon;
import org.apache.avalon.framework.logger.NullLogger; import org.apache.avalon.framework.logger.NullLogger;
import org.apache.commons.logging.impl.AvalonLogger; import org.apache.commons.logging.impl.AvalonLogger;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.AbstractLogTest; import org.apache.commons.logging.AbstractLogTest;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
/** /**
*/ */
public class AvalonLoggerTestCase extends AbstractLogTest { public class AvalonLoggerTestCase extends AbstractLogTest {
public static Test suite() { public static Test suite() {
final TestSuite suite = new TestSuite(); final TestSuite suite = new TestSuite();
suite.addTestSuite(AvalonLoggerTestCase.class); suite.addTestSuite(AvalonLoggerTestCase.class);
return suite; return suite;
} }
@Override @Override
public Log getLogObject() { public Log getLogObject() {
// Output does not seem to be used, so don't display it. // Output does not seem to be used, so don't display it.
final Log log = new AvalonLogger(new NullLogger()); final Log log = new AvalonLogger(new NullLogger());
return log; return log;
} }
} }

View File

@@ -1,396 +1,396 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.jdk14; package org.apache.commons.logging.jdk14;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Iterator; import java.util.Iterator;
import java.util.logging.Handler; import java.util.logging.Handler;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogManager; import java.util.logging.LogManager;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
import java.util.logging.Logger; import java.util.logging.Logger;
import junit.framework.Test; import junit.framework.Test;
import org.apache.commons.logging.DummyException; import org.apache.commons.logging.DummyException;
import org.apache.commons.logging.PathableClassLoader; import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite; import org.apache.commons.logging.PathableTestSuite;
/** /**
* <p>TestCase for JDK 1.4 logging when running on a JDK 1.4 system with * <p>TestCase for JDK 1.4 logging when running on a JDK 1.4 system with
* custom configuration, so that JDK 1.4 should be selected and an appropriate * custom configuration, so that JDK 1.4 should be selected and an appropriate
* logger configured per the configuration properties.</p> * logger configured per the configuration properties.</p>
*/ */
public class CustomConfigTestCase extends DefaultConfigTestCase { public class CustomConfigTestCase extends DefaultConfigTestCase {
protected static final String HANDLER_NAME = "org.apache.commons.logging.jdk14.TestHandler"; protected static final String HANDLER_NAME = "org.apache.commons.logging.jdk14.TestHandler";
// ----------------------------------------------------------- Constructors // ----------------------------------------------------------- Constructors
/** /**
* <p>Construct a new instance of this test case.</p> * <p>Construct a new instance of this test case.</p>
* *
* @param name Name of the test case * @param name Name of the test case
*/ */
public CustomConfigTestCase(final String name) { public CustomConfigTestCase(final String name) {
super(name); super(name);
} }
// ----------------------------------------------------- Instance Variables // ----------------------------------------------------- Instance Variables
/** /**
* <p>The customized {@code Handler} we will be using.</p> * <p>The customized {@code Handler} we will be using.</p>
*/ */
protected TestHandler handler; protected TestHandler handler;
/** /**
* <p>The underlying {@code Handler}s we will be using.</p> * <p>The underlying {@code Handler}s we will be using.</p>
*/ */
protected Handler handlers[]; protected Handler handlers[];
/** /**
* <p>The underlying {@code Logger} we will be using.</p> * <p>The underlying {@code Logger} we will be using.</p>
*/ */
protected Logger logger; protected Logger logger;
/** /**
* <p>The underlying {@code LogManager} we will be using.</p> * <p>The underlying {@code LogManager} we will be using.</p>
*/ */
protected LogManager manager; protected LogManager manager;
/** /**
* <p>The message levels that should have been logged.</p> * <p>The message levels that should have been logged.</p>
*/ */
protected Level[] testLevels = protected Level[] testLevels =
{ Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE, Level.SEVERE }; { Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE, Level.SEVERE };
/** /**
* <p>The message strings that should have been logged.</p> * <p>The message strings that should have been logged.</p>
*/ */
protected String[] testMessages = protected String[] testMessages =
{ "debug", "info", "warn", "error", "fatal" }; { "debug", "info", "warn", "error", "fatal" };
// ------------------------------------------- JUnit Infrastructure Methods // ------------------------------------------- JUnit Infrastructure Methods
/** /**
* Given the name of a class that is somewhere in the classpath of the provided * Given the name of a class that is somewhere in the classpath of the provided
* classloader, return the contents of the corresponding .class file. * classloader, return the contents of the corresponding .class file.
*/ */
protected static byte[] readClass(final String name, final ClassLoader srcCL) throws Exception { protected static byte[] readClass(final String name, final ClassLoader srcCL) throws Exception {
final String resName = name.replace('.', '/') + ".class"; final String resName = name.replace('.', '/') + ".class";
System.err.println("Trying to load resource [" + resName + "]"); System.err.println("Trying to load resource [" + resName + "]");
final InputStream is = srcCL.getResourceAsStream(resName); final InputStream is = srcCL.getResourceAsStream(resName);
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.err.println("Reading resource [" + resName + "]"); System.err.println("Reading resource [" + resName + "]");
final byte[] buf = new byte[1000]; final byte[] buf = new byte[1000];
for(;;) { for(;;) {
final int read = is.read(buf); final int read = is.read(buf);
if (read <= 0) { if (read <= 0) {
break; break;
} }
baos.write(buf, 0, read); baos.write(buf, 0, read);
} }
is.close(); is.close();
return baos.toByteArray(); return baos.toByteArray();
} }
/** /**
* Make a class available in the system classloader even when its classfile is * Make a class available in the system classloader even when its classfile is
* not present in the classpath configured for that classloader. This only * not present in the classpath configured for that classloader. This only
* works for classes for which all dependencies are already loaded in * works for classes for which all dependencies are already loaded in
* that classloader. * that classloader.
*/ */
protected static void loadTestHandler(final String className, final ClassLoader targetCL) { protected static void loadTestHandler(final String className, final ClassLoader targetCL) {
try { try {
targetCL.loadClass(className); targetCL.loadClass(className);
// fail("Class already in target classloader"); // fail("Class already in target classloader");
return; return;
} catch (final ClassNotFoundException ex) { } catch (final ClassNotFoundException ex) {
// ok, go ahead and load it // ok, go ahead and load it
} }
try { try {
final ClassLoader srcCL = CustomConfigAPITestCase.class.getClassLoader(); final ClassLoader srcCL = CustomConfigAPITestCase.class.getClassLoader();
final byte[] classData = readClass(className, srcCL); final byte[] classData = readClass(className, srcCL);
final Class[] params = new Class[] { String.class, classData.getClass(), Integer.TYPE, Integer.TYPE }; final Class[] params = new Class[] { String.class, classData.getClass(), Integer.TYPE, Integer.TYPE };
final Method m = ClassLoader.class.getDeclaredMethod("defineClass", params); final Method m = ClassLoader.class.getDeclaredMethod("defineClass", params);
final Object[] args = new Object[4]; final Object[] args = new Object[4];
args[0] = className; args[0] = className;
args[1] = classData; args[1] = classData;
args[2] = new Integer(0); args[2] = new Integer(0);
args[3] = new Integer(classData.length); args[3] = new Integer(classData.length);
m.setAccessible(true); m.setAccessible(true);
m.invoke(targetCL, args); m.invoke(targetCL, args);
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
fail("Unable to load class " + className); fail("Unable to load class " + className);
} }
} }
/** /**
* Set up instance variables required by this test case. * Set up instance variables required by this test case.
*/ */
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
setUpManager setUpManager
("org/apache/commons/logging/jdk14/CustomConfig.properties"); ("org/apache/commons/logging/jdk14/CustomConfig.properties");
setUpLogger(this.getClass().getName()); setUpLogger(this.getClass().getName());
setUpHandlers(); setUpHandlers();
setUpFactory(); setUpFactory();
setUpLog(this.getClass().getName()); setUpLog(this.getClass().getName());
} }
/** /**
* Return the tests included in this test suite. * Return the tests included in this test suite.
*/ */
public static Test suite() throws Exception { public static Test suite() throws Exception {
final PathableClassLoader cl = new PathableClassLoader(null); final PathableClassLoader cl = new PathableClassLoader(null);
cl.useExplicitLoader("junit.", Test.class.getClassLoader()); cl.useExplicitLoader("junit.", Test.class.getClassLoader());
// the TestHandler class must be accessable from the System classloader // the TestHandler class must be accessable from the System classloader
// in order for java.util.logging.LogManager.readConfiguration to // in order for java.util.logging.LogManager.readConfiguration to
// be able to instantiate it. And this test case must see the same // be able to instantiate it. And this test case must see the same
// class in order to be able to access its data. Yes this is ugly // class in order to be able to access its data. Yes this is ugly
// but the whole jdk14 API is a ******* mess anyway. // but the whole jdk14 API is a ******* mess anyway.
final ClassLoader scl = ClassLoader.getSystemClassLoader(); final ClassLoader scl = ClassLoader.getSystemClassLoader();
loadTestHandler(HANDLER_NAME, scl); loadTestHandler(HANDLER_NAME, scl);
cl.useExplicitLoader(HANDLER_NAME, scl); cl.useExplicitLoader(HANDLER_NAME, scl);
cl.addLogicalLib("commons-logging"); cl.addLogicalLib("commons-logging");
cl.addLogicalLib("testclasses"); cl.addLogicalLib("testclasses");
final Class testClass = cl.loadClass(CustomConfigTestCase.class.getName()); final Class testClass = cl.loadClass(CustomConfigTestCase.class.getName());
return new PathableTestSuite(testClass, cl); return new PathableTestSuite(testClass, cl);
} }
/** /**
* Tear down instance variables required by this test case. * Tear down instance variables required by this test case.
*/ */
@Override @Override
public void tearDown() { public void tearDown() {
super.tearDown(); super.tearDown();
handlers = null; handlers = null;
logger = null; logger = null;
manager = null; manager = null;
} }
// ----------------------------------------------------------- Test Methods // ----------------------------------------------------------- Test Methods
// Test logging message strings with exceptions // Test logging message strings with exceptions
public void testExceptionMessages() throws Exception { public void testExceptionMessages() throws Exception {
logExceptionMessages(); logExceptionMessages();
checkLogRecords(true); checkLogRecords(true);
} }
// Test logging plain message strings // Test logging plain message strings
public void testPlainMessages() throws Exception { public void testPlainMessages() throws Exception {
logPlainMessages(); logPlainMessages();
checkLogRecords(false); checkLogRecords(false);
} }
// Test pristine Handlers instances // Test pristine Handlers instances
public void testPristineHandlers() { public void testPristineHandlers() {
assertNotNull(handlers); assertNotNull(handlers);
assertEquals(1, handlers.length); assertEquals(1, handlers.length);
assertTrue(handlers[0] instanceof TestHandler); assertTrue(handlers[0] instanceof TestHandler);
assertNotNull(handler); assertNotNull(handler);
} }
// Test pristine Logger instance // Test pristine Logger instance
public void testPristineLogger() { public void testPristineLogger() {
assertNotNull("Logger exists", logger); assertNotNull("Logger exists", logger);
assertEquals("Logger name", this.getClass().getName(), logger.getName()); assertEquals("Logger name", this.getClass().getName(), logger.getName());
// Assert which logging levels have been enabled // Assert which logging levels have been enabled
assertTrue(logger.isLoggable(Level.SEVERE)); assertTrue(logger.isLoggable(Level.SEVERE));
assertTrue(logger.isLoggable(Level.WARNING)); assertTrue(logger.isLoggable(Level.WARNING));
assertTrue(logger.isLoggable(Level.INFO)); assertTrue(logger.isLoggable(Level.INFO));
assertTrue(logger.isLoggable(Level.CONFIG)); assertTrue(logger.isLoggable(Level.CONFIG));
assertTrue(logger.isLoggable(Level.FINE)); assertTrue(logger.isLoggable(Level.FINE));
assertFalse(logger.isLoggable(Level.FINER)); assertFalse(logger.isLoggable(Level.FINER));
assertFalse(logger.isLoggable(Level.FINEST)); assertFalse(logger.isLoggable(Level.FINEST));
} }
// Test Serializability of Log instance // Test Serializability of Log instance
@Override @Override
public void testSerializable() throws Exception { public void testSerializable() throws Exception {
super.testSerializable(); super.testSerializable();
testExceptionMessages(); testExceptionMessages();
} }
// -------------------------------------------------------- Support Methods // -------------------------------------------------------- Support Methods
// Check the log instance // Check the log instance
@Override @Override
protected void checkLog() { protected void checkLog() {
assertNotNull("Log exists", log); assertNotNull("Log exists", log);
assertEquals("Log class", assertEquals("Log class",
"org.apache.commons.logging.impl.Jdk14Logger", "org.apache.commons.logging.impl.Jdk14Logger",
log.getClass().getName()); log.getClass().getName());
// Assert which logging levels have been enabled // Assert which logging levels have been enabled
assertTrue(log.isFatalEnabled()); assertTrue(log.isFatalEnabled());
assertTrue(log.isErrorEnabled()); assertTrue(log.isErrorEnabled());
assertTrue(log.isWarnEnabled()); assertTrue(log.isWarnEnabled());
assertTrue(log.isInfoEnabled()); assertTrue(log.isInfoEnabled());
assertTrue(log.isDebugEnabled()); assertTrue(log.isDebugEnabled());
assertFalse(log.isTraceEnabled()); assertFalse(log.isTraceEnabled());
} }
// Check the recorded messages // Check the recorded messages
protected void checkLogRecords(final boolean thrown) { protected void checkLogRecords(final boolean thrown) {
final Iterator records = handler.records(); final Iterator records = handler.records();
for (int i = 0; i < testMessages.length; i++) { for (int i = 0; i < testMessages.length; i++) {
assertTrue(records.hasNext()); assertTrue(records.hasNext());
final LogRecord record = (LogRecord) records.next(); final LogRecord record = (LogRecord) records.next();
assertEquals("LogRecord level", assertEquals("LogRecord level",
testLevels[i], record.getLevel()); testLevels[i], record.getLevel());
assertEquals("LogRecord message", assertEquals("LogRecord message",
testMessages[i], record.getMessage()); testMessages[i], record.getMessage());
assertTrue("LogRecord class", assertTrue("LogRecord class",
record.getSourceClassName().startsWith( record.getSourceClassName().startsWith(
"org.apache.commons.logging.jdk14.CustomConfig")); "org.apache.commons.logging.jdk14.CustomConfig"));
if (thrown) { if (thrown) {
assertEquals("LogRecord method", assertEquals("LogRecord method",
"logExceptionMessages", "logExceptionMessages",
record.getSourceMethodName()); record.getSourceMethodName());
} else { } else {
assertEquals("LogRecord method", assertEquals("LogRecord method",
"logPlainMessages", "logPlainMessages",
record.getSourceMethodName()); record.getSourceMethodName());
} }
if (thrown) { if (thrown) {
assertNotNull("LogRecord thrown", record.getThrown()); assertNotNull("LogRecord thrown", record.getThrown());
assertTrue("LogRecord thrown type", assertTrue("LogRecord thrown type",
record.getThrown() instanceof DummyException); record.getThrown() instanceof DummyException);
} else { } else {
assertNull("LogRecord thrown", assertNull("LogRecord thrown",
record.getThrown()); record.getThrown());
} }
} }
assertFalse(records.hasNext()); assertFalse(records.hasNext());
handler.flush(); handler.flush();
} }
// Log the messages with exceptions // Log the messages with exceptions
protected void logExceptionMessages() { protected void logExceptionMessages() {
final Throwable t = new DummyException(); final Throwable t = new DummyException();
log.trace("trace", t); // Should not actually get logged log.trace("trace", t); // Should not actually get logged
log.debug("debug", t); log.debug("debug", t);
log.info("info", t); log.info("info", t);
log.warn("warn", t); log.warn("warn", t);
log.error("error", t); log.error("error", t);
log.fatal("fatal", t); log.fatal("fatal", t);
} }
// Log the plain messages // Log the plain messages
protected void logPlainMessages() { protected void logPlainMessages() {
log.trace("trace"); // Should not actually get logged log.trace("trace"); // Should not actually get logged
log.debug("debug"); log.debug("debug");
log.info("info"); log.info("info");
log.warn("warn"); log.warn("warn");
log.error("error"); log.error("error");
log.fatal("fatal"); log.fatal("fatal");
} }
// Set up handlers instance // Set up handlers instance
protected void setUpHandlers() throws Exception { protected void setUpHandlers() throws Exception {
Logger parent = logger; Logger parent = logger;
while (parent.getParent() != null) { while (parent.getParent() != null) {
parent = parent.getParent(); parent = parent.getParent();
} }
handlers = parent.getHandlers(); handlers = parent.getHandlers();
// The CustomConfig.properties file explicitly defines one handler class // The CustomConfig.properties file explicitly defines one handler class
// to be attached to the root logger, so if it isn't there then // to be attached to the root logger, so if it isn't there then
// something is badly wrong... // something is badly wrong...
// //
// Yes this testing is also done in testPristineHandlers but // Yes this testing is also done in testPristineHandlers but
// unfortunately: // unfortunately:
// * we need to set up the handlers variable here, // * we need to set up the handlers variable here,
// * we don't want that to be set up incorrectly, as that can // * we don't want that to be set up incorrectly, as that can
// produce weird error messages in other tests, and // produce weird error messages in other tests, and
// * we can't rely on testPristineHandlers being the first // * we can't rely on testPristineHandlers being the first
// test to run. // test to run.
// so we need to test things here too. // so we need to test things here too.
assertNotNull("No Handlers defined for JDK14 logging", handlers); assertNotNull("No Handlers defined for JDK14 logging", handlers);
assertEquals("Unexpected number of handlers for JDK14 logging", 1, handlers.length); assertEquals("Unexpected number of handlers for JDK14 logging", 1, handlers.length);
assertNotNull("Handler is null", handlers[0]); assertNotNull("Handler is null", handlers[0]);
assertTrue("Handler not of expected type", handlers[0] instanceof TestHandler); assertTrue("Handler not of expected type", handlers[0] instanceof TestHandler);
handler = (TestHandler) handlers[0]; handler = (TestHandler) handlers[0];
} }
// Set up logger instance // Set up logger instance
protected void setUpLogger(final String name) throws Exception { protected void setUpLogger(final String name) throws Exception {
logger = Logger.getLogger(name); logger = Logger.getLogger(name);
} }
// Set up LogManager instance // Set up LogManager instance
protected void setUpManager(final String config) throws Exception { protected void setUpManager(final String config) throws Exception {
manager = LogManager.getLogManager(); manager = LogManager.getLogManager();
final InputStream is = final InputStream is =
this.getClass().getClassLoader().getResourceAsStream(config); this.getClass().getClassLoader().getResourceAsStream(config);
manager.readConfiguration(is); manager.readConfiguration(is);
is.close(); is.close();
} }
} }

View File

@@ -1,158 +1,158 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.jdk14; package org.apache.commons.logging.jdk14;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.PathableClassLoader; import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite; import org.apache.commons.logging.PathableTestSuite;
/** /**
* <p>TestCase for JDK 1.4 logging when running on a JDK 1.4 system with * <p>TestCase for JDK 1.4 logging when running on a JDK 1.4 system with
* zero configuration, and with Log4J not present (so JDK 1.4 logging * zero configuration, and with Log4J not present (so JDK 1.4 logging
* should be automatically configured.</p> * should be automatically configured.</p>
*/ */
public class DefaultConfigTestCase extends TestCase { public class DefaultConfigTestCase extends TestCase {
/** /**
* <p>Construct a new instance of this test case.</p> * <p>Construct a new instance of this test case.</p>
* *
* @param name Name of the test case * @param name Name of the test case
*/ */
public DefaultConfigTestCase(final String name) { public DefaultConfigTestCase(final String name) {
super(name); super(name);
} }
/** /**
* <p>The {@link LogFactory} implementation we have selected.</p> * <p>The {@link LogFactory} implementation we have selected.</p>
*/ */
protected LogFactory factory; protected LogFactory factory;
/** /**
* <p>The {@link Log} implementation we have selected.</p> * <p>The {@link Log} implementation we have selected.</p>
*/ */
protected Log log; protected Log log;
/** /**
* Set up instance variables required by this test case. * Set up instance variables required by this test case.
*/ */
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
setUpFactory(); setUpFactory();
setUpLog("TestLogger"); setUpLog("TestLogger");
} }
/** /**
* Return the tests included in this test suite. * Return the tests included in this test suite.
*/ */
public static Test suite() throws Exception { public static Test suite() throws Exception {
final PathableClassLoader loader = new PathableClassLoader(null); final PathableClassLoader loader = new PathableClassLoader(null);
loader.useExplicitLoader("junit.", Test.class.getClassLoader()); loader.useExplicitLoader("junit.", Test.class.getClassLoader());
loader.addLogicalLib("testclasses"); loader.addLogicalLib("testclasses");
loader.addLogicalLib("commons-logging"); loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(DefaultConfigTestCase.class.getName()); final Class testClass = loader.loadClass(DefaultConfigTestCase.class.getName());
return new PathableTestSuite(testClass, loader); return new PathableTestSuite(testClass, loader);
} }
/** /**
* Tear down instance variables required by this test case. * Tear down instance variables required by this test case.
*/ */
@Override @Override
public void tearDown() { public void tearDown() {
log = null; log = null;
factory = null; factory = null;
LogFactory.releaseAll(); LogFactory.releaseAll();
} }
// Test pristine Log instance // Test pristine Log instance
public void testPristineLog() { public void testPristineLog() {
checkLog(); checkLog();
} }
// Test pristine LogFactory instance // Test pristine LogFactory instance
public void testPristineFactory() { public void testPristineFactory() {
assertNotNull("LogFactory exists", factory); assertNotNull("LogFactory exists", factory);
assertEquals("LogFactory class", assertEquals("LogFactory class",
"org.apache.commons.logging.impl.LogFactoryImpl", "org.apache.commons.logging.impl.LogFactoryImpl",
factory.getClass().getName()); factory.getClass().getName());
final String[] names = factory.getAttributeNames(); final String[] names = factory.getAttributeNames();
assertNotNull("Names exists", names); assertNotNull("Names exists", names);
assertEquals("Names empty", 0, names.length); assertEquals("Names empty", 0, names.length);
} }
// Test Serializability of Log instance // Test Serializability of Log instance
public void testSerializable() throws Exception { public void testSerializable() throws Exception {
// Serialize and deserialize the instance // Serialize and deserialize the instance
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos); final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(log); oos.writeObject(log);
oos.close(); oos.close();
final ByteArrayInputStream bais = final ByteArrayInputStream bais =
new ByteArrayInputStream(baos.toByteArray()); new ByteArrayInputStream(baos.toByteArray());
final ObjectInputStream ois = new ObjectInputStream(bais); final ObjectInputStream ois = new ObjectInputStream(bais);
log = (Log) ois.readObject(); log = (Log) ois.readObject();
ois.close(); ois.close();
// Check the characteristics of the resulting object // Check the characteristics of the resulting object
checkLog(); checkLog();
} }
// Check the log instance // Check the log instance
protected void checkLog() { protected void checkLog() {
assertNotNull("Log exists", log); assertNotNull("Log exists", log);
assertEquals("Log class", assertEquals("Log class",
"org.apache.commons.logging.impl.Jdk14Logger", "org.apache.commons.logging.impl.Jdk14Logger",
log.getClass().getName()); log.getClass().getName());
// Can we call level checkers with no exceptions? // Can we call level checkers with no exceptions?
log.isDebugEnabled(); log.isDebugEnabled();
log.isErrorEnabled(); log.isErrorEnabled();
log.isFatalEnabled(); log.isFatalEnabled();
log.isInfoEnabled(); log.isInfoEnabled();
log.isTraceEnabled(); log.isTraceEnabled();
log.isWarnEnabled(); log.isWarnEnabled();
} }
// Set up factory instance // Set up factory instance
protected void setUpFactory() throws Exception { protected void setUpFactory() throws Exception {
factory = LogFactory.getFactory(); factory = LogFactory.getFactory();
} }
// Set up log instance // Set up log instance
protected void setUpLog(final String name) throws Exception { protected void setUpLog(final String name) throws Exception {
log = LogFactory.getLog(name); log = LogFactory.getLog(name);
} }
} }

View File

@@ -1,53 +1,53 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.jdk14; package org.apache.commons.logging.jdk14;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.logging.Handler; import java.util.logging.Handler;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
/** /**
* <p>Test implementation of {@code java.util.logging.Handler}.</p> * <p>Test implementation of {@code java.util.logging.Handler}.</p>
*/ */
public class TestHandler extends Handler { public class TestHandler extends Handler {
// The set of logged records for this handler // The set of logged records for this handler
private final List records = new ArrayList(); private final List records = new ArrayList();
public Iterator records() { public Iterator records() {
return records.iterator(); return records.iterator();
} }
@Override @Override
public void close() { public void close() {
} }
@Override @Override
public void flush() { public void flush() {
records.clear(); records.clear();
} }
@Override @Override
public void publish(final LogRecord record) { public void publish(final LogRecord record) {
records.add(record); records.add(record);
} }
} }

View File

@@ -1,244 +1,244 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.simple; package org.apache.commons.logging.simple;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import junit.framework.Test; import junit.framework.Test;
import org.apache.commons.logging.DummyException; import org.apache.commons.logging.DummyException;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.PathableClassLoader; import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite; import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.impl.SimpleLog; import org.apache.commons.logging.impl.SimpleLog;
/** /**
* <p>TestCase for simple logging when running with custom configuration * <p>TestCase for simple logging when running with custom configuration
* properties.</p> * properties.</p>
*/ */
public class CustomConfigTestCase extends DefaultConfigTestCase { public class CustomConfigTestCase extends DefaultConfigTestCase {
/** /**
* <p>The expected log records.</p> * <p>The expected log records.</p>
*/ */
protected List expected; protected List expected;
/** /**
* <p>The message levels that should have been logged.</p> * <p>The message levels that should have been logged.</p>
*/ */
/* /*
protected Level[] testLevels = protected Level[] testLevels =
{ Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE, Level.SEVERE }; { Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE, Level.SEVERE };
*/ */
/** /**
* <p>The message strings that should have been logged.</p> * <p>The message strings that should have been logged.</p>
*/ */
protected String[] testMessages = protected String[] testMessages =
{ "debug", "info", "warn", "error", "fatal" }; { "debug", "info", "warn", "error", "fatal" };
/** /**
* Set system properties that will control the LogFactory/Log objects * Set system properties that will control the LogFactory/Log objects
* when they are created. Subclasses can override this method to * when they are created. Subclasses can override this method to
* define properties that suit them. * define properties that suit them.
*/ */
@Override @Override
public void setProperties() { public void setProperties() {
System.setProperty( System.setProperty(
"org.apache.commons.logging.Log", "org.apache.commons.logging.Log",
"org.apache.commons.logging.simple.DecoratedSimpleLog"); "org.apache.commons.logging.simple.DecoratedSimpleLog");
System.setProperty( System.setProperty(
"org.apache.commons.logging.simplelog.defaultlog", "org.apache.commons.logging.simplelog.defaultlog",
"debug"); "debug");
} }
/** /**
* Set up instance variables required by this test case. * Set up instance variables required by this test case.
*/ */
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
LogFactory.releaseAll(); LogFactory.releaseAll();
setProperties(); setProperties();
expected = new ArrayList(); expected = new ArrayList();
setUpFactory(); setUpFactory();
setUpLog("DecoratedLogger"); setUpLog("DecoratedLogger");
} }
/** /**
* Return the tests included in this test suite. * Return the tests included in this test suite.
* <p> * <p>
* We need to use a PathableClassLoader here because the SimpleLog class * We need to use a PathableClassLoader here because the SimpleLog class
* is a pile of junk and chock-full of static variables. Any other test * is a pile of junk and chock-full of static variables. Any other test
* (like simple.CustomConfigTestCase) that has used the SimpleLog class * (like simple.CustomConfigTestCase) that has used the SimpleLog class
* will already have caused it to do once-only initialization that we * will already have caused it to do once-only initialization that we
* can't reset, even by calling LogFactory.releaseAll, because of those * can't reset, even by calling LogFactory.releaseAll, because of those
* ugly statics. The only clean solution is to load a clean copy of * ugly statics. The only clean solution is to load a clean copy of
* commons-logging including SimpleLog via a nice clean class loader. * commons-logging including SimpleLog via a nice clean class loader.
* Or we could fix SimpleLog to be sane... * Or we could fix SimpleLog to be sane...
*/ */
public static Test suite() throws Exception { public static Test suite() throws Exception {
final Class thisClass = CustomConfigTestCase.class; final Class thisClass = CustomConfigTestCase.class;
final PathableClassLoader loader = new PathableClassLoader(null); final PathableClassLoader loader = new PathableClassLoader(null);
loader.useExplicitLoader("junit.", Test.class.getClassLoader()); loader.useExplicitLoader("junit.", Test.class.getClassLoader());
loader.addLogicalLib("testclasses"); loader.addLogicalLib("testclasses");
loader.addLogicalLib("commons-logging"); loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(thisClass.getName()); final Class testClass = loader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, loader); return new PathableTestSuite(testClass, loader);
} }
/** /**
* Tear down instance variables required by this test case. * Tear down instance variables required by this test case.
*/ */
@Override @Override
public void tearDown() { public void tearDown() {
super.tearDown(); super.tearDown();
expected = null; expected = null;
} }
// Test logging message strings with exceptions // Test logging message strings with exceptions
public void testExceptionMessages() throws Exception { public void testExceptionMessages() throws Exception {
((DecoratedSimpleLog) log).clearCache(); ((DecoratedSimpleLog) log).clearCache();
logExceptionMessages(); logExceptionMessages();
checkExpected(); checkExpected();
} }
// Test logging plain message strings // Test logging plain message strings
public void testPlainMessages() throws Exception { public void testPlainMessages() throws Exception {
((DecoratedSimpleLog) log).clearCache(); ((DecoratedSimpleLog) log).clearCache();
logPlainMessages(); logPlainMessages();
checkExpected(); checkExpected();
} }
// Test Serializability of standard instance // Test Serializability of standard instance
@Override @Override
public void testSerializable() throws Exception { public void testSerializable() throws Exception {
((DecoratedSimpleLog) log).clearCache(); ((DecoratedSimpleLog) log).clearCache();
logPlainMessages(); logPlainMessages();
super.testSerializable(); super.testSerializable();
logExceptionMessages(); logExceptionMessages();
checkExpected(); checkExpected();
} }
// Check the decorated log instance // Check the decorated log instance
@Override @Override
protected void checkDecorated() { protected void checkDecorated() {
assertNotNull("Log exists", log); assertNotNull("Log exists", log);
assertEquals("Log class", assertEquals("Log class",
"org.apache.commons.logging.simple.DecoratedSimpleLog", "org.apache.commons.logging.simple.DecoratedSimpleLog",
log.getClass().getName()); log.getClass().getName());
// Can we call level checkers with no exceptions? // Can we call level checkers with no exceptions?
assertTrue(log.isDebugEnabled()); assertTrue(log.isDebugEnabled());
assertTrue(log.isErrorEnabled()); assertTrue(log.isErrorEnabled());
assertTrue(log.isFatalEnabled()); assertTrue(log.isFatalEnabled());
assertTrue(log.isInfoEnabled()); assertTrue(log.isInfoEnabled());
assertFalse(log.isTraceEnabled()); assertFalse(log.isTraceEnabled());
assertTrue(log.isWarnEnabled()); assertTrue(log.isWarnEnabled());
// Can we retrieve the current log level? // Can we retrieve the current log level?
assertEquals(SimpleLog.LOG_LEVEL_DEBUG, ((SimpleLog) log).getLevel()); assertEquals(SimpleLog.LOG_LEVEL_DEBUG, ((SimpleLog) log).getLevel());
// Can we validate the extra exposed properties? // Can we validate the extra exposed properties?
checkDecoratedDateTime(); checkDecoratedDateTime();
assertEquals("DecoratedLogger", assertEquals("DecoratedLogger",
((DecoratedSimpleLog) log).getLogName()); ((DecoratedSimpleLog) log).getLogName());
checkShowDateTime(); checkShowDateTime();
assertTrue(((DecoratedSimpleLog) log).getShowShortName()); assertTrue(((DecoratedSimpleLog) log).getShowShortName());
} }
/** Hook for subclassses */ /** Hook for subclassses */
protected void checkShowDateTime() { protected void checkShowDateTime() {
assertFalse(((DecoratedSimpleLog) log).getShowDateTime()); assertFalse(((DecoratedSimpleLog) log).getShowDateTime());
} }
/** Hook for subclasses */ /** Hook for subclasses */
protected void checkDecoratedDateTime() { protected void checkDecoratedDateTime() {
assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz", assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz",
((DecoratedSimpleLog) log).getDateTimeFormat()); ((DecoratedSimpleLog) log).getDateTimeFormat());
} }
// Check the actual log records against the expected ones // Check the actual log records against the expected ones
protected void checkExpected() { protected void checkExpected() {
final List acts = ((DecoratedSimpleLog) log).getCache(); final List acts = ((DecoratedSimpleLog) log).getCache();
final Iterator exps = expected.iterator(); final Iterator exps = expected.iterator();
int n = 0; int n = 0;
while (exps.hasNext()) { while (exps.hasNext()) {
final LogRecord exp = (LogRecord) exps.next(); final LogRecord exp = (LogRecord) exps.next();
final LogRecord act = (LogRecord) acts.get(n++); final LogRecord act = (LogRecord) acts.get(n++);
assertEquals("Row " + n + " type", exp.type, act.type); assertEquals("Row " + n + " type", exp.type, act.type);
assertEquals("Row " + n + " message", exp.message, act.message); assertEquals("Row " + n + " message", exp.message, act.message);
assertEquals("Row " + n + " throwable", exp.t, act.t); assertEquals("Row " + n + " throwable", exp.t, act.t);
} }
} }
// Check the standard log instance // Check the standard log instance
@Override @Override
protected void checkStandard() { protected void checkStandard() {
checkDecorated(); checkDecorated();
} }
// Log the messages with exceptions // Log the messages with exceptions
protected void logExceptionMessages() { protected void logExceptionMessages() {
// Generate log records // Generate log records
final Throwable t = new DummyException(); final Throwable t = new DummyException();
log.trace("trace", t); // Should not actually get logged log.trace("trace", t); // Should not actually get logged
log.debug("debug", t); log.debug("debug", t);
log.info("info", t); log.info("info", t);
log.warn("warn", t); log.warn("warn", t);
log.error("error", t); log.error("error", t);
log.fatal("fatal", t); log.fatal("fatal", t);
// Record the log records we expect // Record the log records we expect
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_DEBUG, "debug", t)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_DEBUG, "debug", t));
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_INFO, "info", t)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_INFO, "info", t));
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_WARN, "warn", t)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_WARN, "warn", t));
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_ERROR, "error", t)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_ERROR, "error", t));
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_FATAL, "fatal", t)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_FATAL, "fatal", t));
} }
// Log the plain messages // Log the plain messages
protected void logPlainMessages() { protected void logPlainMessages() {
// Generate log records // Generate log records
log.trace("trace"); // Should not actually get logged log.trace("trace"); // Should not actually get logged
log.debug("debug"); log.debug("debug");
log.info("info"); log.info("info");
log.warn("warn"); log.warn("warn");
log.error("error"); log.error("error");
log.fatal("fatal"); log.fatal("fatal");
// Record the log records we expect // Record the log records we expect
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_DEBUG, "debug", null)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_DEBUG, "debug", null));
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_INFO, "info", null)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_INFO, "info", null));
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_WARN, "warn", null)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_WARN, "warn", null));
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_ERROR, "error", null)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_ERROR, "error", null));
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_FATAL, "fatal", null)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_FATAL, "fatal", null));
} }
} }

View File

@@ -1,109 +1,109 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.simple; package org.apache.commons.logging.simple;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import junit.framework.Test; import junit.framework.Test;
import org.apache.commons.logging.PathableClassLoader; import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite; import org.apache.commons.logging.PathableTestSuite;
/** /**
* Tests custom date time format configuration * Tests custom date time format configuration
*/ */
public class DateTimeCustomConfigTestCase extends CustomConfigTestCase { public class DateTimeCustomConfigTestCase extends CustomConfigTestCase {
// ----------------------------------------------------------- Constructors // ----------------------------------------------------------- Constructors
/** /**
* Return the tests included in this test suite. * Return the tests included in this test suite.
* <p> * <p>
* We need to use a PathableClassLoader here because the SimpleLog class * We need to use a PathableClassLoader here because the SimpleLog class
* is a pile of junk and chock-full of static variables. Any other test * is a pile of junk and chock-full of static variables. Any other test
* (like simple.CustomConfigTestCase) that has used the SimpleLog class * (like simple.CustomConfigTestCase) that has used the SimpleLog class
* will already have caused it to do once-only initialization that we * will already have caused it to do once-only initialization that we
* can't reset, even by calling LogFactory.releaseAll, because of those * can't reset, even by calling LogFactory.releaseAll, because of those
* ugly statics. The only clean solution is to load a clean copy of * ugly statics. The only clean solution is to load a clean copy of
* commons-logging including SimpleLog via a nice clean class loader. * commons-logging including SimpleLog via a nice clean class loader.
* Or we could fix SimpleLog to be sane... * Or we could fix SimpleLog to be sane...
*/ */
public static Test suite() throws Exception { public static Test suite() throws Exception {
final Class thisClass = DateTimeCustomConfigTestCase.class; final Class thisClass = DateTimeCustomConfigTestCase.class;
final PathableClassLoader loader = new PathableClassLoader(null); final PathableClassLoader loader = new PathableClassLoader(null);
loader.useExplicitLoader("junit.", Test.class.getClassLoader()); loader.useExplicitLoader("junit.", Test.class.getClassLoader());
loader.addLogicalLib("testclasses"); loader.addLogicalLib("testclasses");
loader.addLogicalLib("commons-logging"); loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(thisClass.getName()); final Class testClass = loader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, loader); return new PathableTestSuite(testClass, loader);
} }
/** /**
* Set up system properties required by this unit test. Here, we * Set up system properties required by this unit test. Here, we
* set up the props defined in the parent class setProperties method, * set up the props defined in the parent class setProperties method,
* and add a few to configure the SimpleLog class date/time output. * and add a few to configure the SimpleLog class date/time output.
*/ */
@Override @Override
public void setProperties() { public void setProperties() {
super.setProperties(); super.setProperties();
System.setProperty( System.setProperty(
"org.apache.commons.logging.simplelog.dateTimeFormat", "org.apache.commons.logging.simplelog.dateTimeFormat",
"dd.mm.yyyy"); "dd.mm.yyyy");
System.setProperty( System.setProperty(
"org.apache.commons.logging.simplelog.showdatetime", "org.apache.commons.logging.simplelog.showdatetime",
"true"); "true");
} }
/** /**
* Set up instance variables required by this test case. * Set up instance variables required by this test case.
*/ */
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
} }
// ----------------------------------------------------------- Methods // ----------------------------------------------------------- Methods
/** Checks that the date time format has been successfully set */ /** Checks that the date time format has been successfully set */
@Override @Override
protected void checkDecoratedDateTime() { protected void checkDecoratedDateTime() {
assertEquals("Expected date format to be set", "dd.mm.yyyy", assertEquals("Expected date format to be set", "dd.mm.yyyy",
((DecoratedSimpleLog) log).getDateTimeFormat()); ((DecoratedSimpleLog) log).getDateTimeFormat());
// try the formatter // try the formatter
final Date now = new Date(); final Date now = new Date();
final DateFormat formatter = ((DecoratedSimpleLog) log).getDateTimeFormatter(); final DateFormat formatter = ((DecoratedSimpleLog) log).getDateTimeFormatter();
final SimpleDateFormat sampleFormatter = new SimpleDateFormat("dd.mm.yyyy"); final SimpleDateFormat sampleFormatter = new SimpleDateFormat("dd.mm.yyyy");
assertEquals("Date should be formatters to pattern dd.mm.yyyy", assertEquals("Date should be formatters to pattern dd.mm.yyyy",
sampleFormatter.format(now), formatter.format(now)); sampleFormatter.format(now), formatter.format(now));
} }
/** Hook for subclassses */ /** Hook for subclassses */
@Override @Override
protected void checkShowDateTime() { protected void checkShowDateTime() {
assertTrue(((DecoratedSimpleLog) log).getShowDateTime()); assertTrue(((DecoratedSimpleLog) log).getShowDateTime());
} }
} }

View File

@@ -1,216 +1,216 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.simple; package org.apache.commons.logging.simple;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.PathableClassLoader; import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite; import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.impl.SimpleLog; import org.apache.commons.logging.impl.SimpleLog;
/** /**
* <p>TestCase for simple logging when running with zero configuration * <p>TestCase for simple logging when running with zero configuration
* other than selecting the SimpleLog implementation.</p> * other than selecting the SimpleLog implementation.</p>
*/ */
public class DefaultConfigTestCase extends TestCase { public class DefaultConfigTestCase extends TestCase {
/** /**
* <p>The {@link LogFactory} implementation we have selected.</p> * <p>The {@link LogFactory} implementation we have selected.</p>
*/ */
protected LogFactory factory; protected LogFactory factory;
/** /**
* <p>The {@link Log} implementation we have selected.</p> * <p>The {@link Log} implementation we have selected.</p>
*/ */
protected Log log; protected Log log;
/** /**
* Return the tests included in this test suite. * Return the tests included in this test suite.
* <p> * <p>
* We need to use a PathableClassLoader here because the SimpleLog class * We need to use a PathableClassLoader here because the SimpleLog class
* is a pile of junk and chock-full of static variables. Any other test * is a pile of junk and chock-full of static variables. Any other test
* (like simple.CustomConfigTestCase) that has used the SimpleLog class * (like simple.CustomConfigTestCase) that has used the SimpleLog class
* will already have caused it to do once-only initialization that we * will already have caused it to do once-only initialization that we
* can't reset, even by calling LogFactory.releaseAll, because of those * can't reset, even by calling LogFactory.releaseAll, because of those
* ugly statics. The only clean solution is to load a clean copy of * ugly statics. The only clean solution is to load a clean copy of
* commons-logging including SimpleLog via a nice clean class loader. * commons-logging including SimpleLog via a nice clean class loader.
* Or we could fix SimpleLog to be sane... * Or we could fix SimpleLog to be sane...
*/ */
public static Test suite() throws Exception { public static Test suite() throws Exception {
final Class thisClass = DefaultConfigTestCase.class; final Class thisClass = DefaultConfigTestCase.class;
final PathableClassLoader loader = new PathableClassLoader(null); final PathableClassLoader loader = new PathableClassLoader(null);
loader.useExplicitLoader("junit.", Test.class.getClassLoader()); loader.useExplicitLoader("junit.", Test.class.getClassLoader());
loader.addLogicalLib("testclasses"); loader.addLogicalLib("testclasses");
loader.addLogicalLib("commons-logging"); loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(thisClass.getName()); final Class testClass = loader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, loader); return new PathableTestSuite(testClass, loader);
} }
/** /**
* Set system properties that will control the LogFactory/Log objects * Set system properties that will control the LogFactory/Log objects
* when they are created. Subclasses can override this method to * when they are created. Subclasses can override this method to
* define properties that suit them. * define properties that suit them.
*/ */
public void setProperties() { public void setProperties() {
System.setProperty( System.setProperty(
"org.apache.commons.logging.Log", "org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.SimpleLog"); "org.apache.commons.logging.impl.SimpleLog");
} }
/** /**
* Set up instance variables required by this test case. * Set up instance variables required by this test case.
*/ */
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
LogFactory.releaseAll(); LogFactory.releaseAll();
setProperties(); setProperties();
setUpFactory(); setUpFactory();
setUpLog("TestLogger"); setUpLog("TestLogger");
} }
/** /**
* Tear down instance variables required by this test case. * Tear down instance variables required by this test case.
*/ */
@Override @Override
public void tearDown() { public void tearDown() {
log = null; log = null;
factory = null; factory = null;
LogFactory.releaseAll(); LogFactory.releaseAll();
} }
// Test pristine DecoratedSimpleLog instance // Test pristine DecoratedSimpleLog instance
public void testPristineDecorated() { public void testPristineDecorated() {
setUpDecorated("DecoratedLogger"); setUpDecorated("DecoratedLogger");
checkDecorated(); checkDecorated();
} }
// Test pristine Log instance // Test pristine Log instance
public void testPristineLog() { public void testPristineLog() {
checkStandard(); checkStandard();
} }
// Test pristine LogFactory instance // Test pristine LogFactory instance
public void testPristineFactory() { public void testPristineFactory() {
assertNotNull("LogFactory exists", factory); assertNotNull("LogFactory exists", factory);
assertEquals("LogFactory class", assertEquals("LogFactory class",
"org.apache.commons.logging.impl.LogFactoryImpl", "org.apache.commons.logging.impl.LogFactoryImpl",
factory.getClass().getName()); factory.getClass().getName());
final String[] names = factory.getAttributeNames(); final String[] names = factory.getAttributeNames();
assertNotNull("Names exists", names); assertNotNull("Names exists", names);
assertEquals("Names empty", 0, names.length); assertEquals("Names empty", 0, names.length);
} }
// Test Serializability of standard instance // Test Serializability of standard instance
public void testSerializable() throws Exception { public void testSerializable() throws Exception {
// Serialize and deserialize the instance // Serialize and deserialize the instance
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos); final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(log); oos.writeObject(log);
oos.close(); oos.close();
final ByteArrayInputStream bais = final ByteArrayInputStream bais =
new ByteArrayInputStream(baos.toByteArray()); new ByteArrayInputStream(baos.toByteArray());
final ObjectInputStream ois = new ObjectInputStream(bais); final ObjectInputStream ois = new ObjectInputStream(bais);
log = (Log) ois.readObject(); log = (Log) ois.readObject();
ois.close(); ois.close();
// Check the characteristics of the resulting object // Check the characteristics of the resulting object
checkStandard(); checkStandard();
} }
// Check the decorated log instance // Check the decorated log instance
protected void checkDecorated() { protected void checkDecorated() {
assertNotNull("Log exists", log); assertNotNull("Log exists", log);
assertEquals("Log class", assertEquals("Log class",
"org.apache.commons.logging.simple.DecoratedSimpleLog", "org.apache.commons.logging.simple.DecoratedSimpleLog",
log.getClass().getName()); log.getClass().getName());
// Can we call level checkers with no exceptions? // Can we call level checkers with no exceptions?
assertFalse(log.isDebugEnabled()); assertFalse(log.isDebugEnabled());
assertTrue(log.isErrorEnabled()); assertTrue(log.isErrorEnabled());
assertTrue(log.isFatalEnabled()); assertTrue(log.isFatalEnabled());
assertTrue(log.isInfoEnabled()); assertTrue(log.isInfoEnabled());
assertFalse(log.isTraceEnabled()); assertFalse(log.isTraceEnabled());
assertTrue(log.isWarnEnabled()); assertTrue(log.isWarnEnabled());
// Can we retrieve the current log level? // Can we retrieve the current log level?
assertEquals(SimpleLog.LOG_LEVEL_INFO, ((SimpleLog) log).getLevel()); assertEquals(SimpleLog.LOG_LEVEL_INFO, ((SimpleLog) log).getLevel());
// Can we validate the extra exposed properties? // Can we validate the extra exposed properties?
assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz", assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz",
((DecoratedSimpleLog) log).getDateTimeFormat()); ((DecoratedSimpleLog) log).getDateTimeFormat());
assertEquals("DecoratedLogger", assertEquals("DecoratedLogger",
((DecoratedSimpleLog) log).getLogName()); ((DecoratedSimpleLog) log).getLogName());
assertFalse(((DecoratedSimpleLog) log).getShowDateTime()); assertFalse(((DecoratedSimpleLog) log).getShowDateTime());
assertTrue(((DecoratedSimpleLog) log).getShowShortName()); assertTrue(((DecoratedSimpleLog) log).getShowShortName());
} }
// Check the standard log instance // Check the standard log instance
protected void checkStandard() { protected void checkStandard() {
assertNotNull("Log exists", log); assertNotNull("Log exists", log);
assertEquals("Log class", assertEquals("Log class",
"org.apache.commons.logging.impl.SimpleLog", "org.apache.commons.logging.impl.SimpleLog",
log.getClass().getName()); log.getClass().getName());
// Can we call level checkers with no exceptions? // Can we call level checkers with no exceptions?
assertFalse(log.isDebugEnabled()); assertFalse(log.isDebugEnabled());
assertTrue(log.isErrorEnabled()); assertTrue(log.isErrorEnabled());
assertTrue(log.isFatalEnabled()); assertTrue(log.isFatalEnabled());
assertTrue(log.isInfoEnabled()); assertTrue(log.isInfoEnabled());
assertFalse(log.isTraceEnabled()); assertFalse(log.isTraceEnabled());
assertTrue(log.isWarnEnabled()); assertTrue(log.isWarnEnabled());
// Can we retrieve the current log level? // Can we retrieve the current log level?
assertEquals(SimpleLog.LOG_LEVEL_INFO, ((SimpleLog) log).getLevel()); assertEquals(SimpleLog.LOG_LEVEL_INFO, ((SimpleLog) log).getLevel());
} }
// Set up decorated log instance // Set up decorated log instance
protected void setUpDecorated(final String name) { protected void setUpDecorated(final String name) {
log = new DecoratedSimpleLog(name); log = new DecoratedSimpleLog(name);
} }
// Set up factory instance // Set up factory instance
protected void setUpFactory() throws Exception { protected void setUpFactory() throws Exception {
factory = LogFactory.getFactory(); factory = LogFactory.getFactory();
} }
// Set up log instance // Set up log instance
protected void setUpLog(final String name) throws Exception { protected void setUpLog(final String name) throws Exception {
log = LogFactory.getLog(name); log = LogFactory.getLog(name);
} }
} }