-
Notifications
You must be signed in to change notification settings - Fork 96
[MWAR-450] ISO-8859-1 properties files get changed into UTF-8 when fi… #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bf5a235
f3aead9
f0ccbbf
136f2df
41f4875
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. 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 obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
| --> | ||
|
|
||
| <project> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>org.apache.maven.its.war</groupId> | ||
| <artifactId>mwar450</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <packaging>war</packaging> | ||
|
|
||
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
|
|
||
| <build> | ||
| <finalName>mwar450</finalName> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-war-plugin</artifactId> | ||
| <version>@project.version@</version> | ||
| <configuration> | ||
| <!-- Without this configuration the test fails --> | ||
| <propertiesEncoding>ISO-8859-1</propertiesEncoding> | ||
| <webResources> | ||
| <resource> | ||
| <targetPath>WEB-INF/classes</targetPath> | ||
| <filtering>true</filtering> | ||
| <directory>src/main/webapp/WEB-INF/classes</directory> | ||
| </resource> | ||
| </webResources> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. 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 obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
| --> | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd"> | ||
| <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> | ||
| <appender name="console" class="org.apache.log4j.ConsoleAppender"> | ||
| <!-- This file is encoded in UTF-8 and should remain so after filtering - åäö --> | ||
| </appender> | ||
| <root> | ||
| <priority value="info"/> | ||
| <appender-ref ref="console"/> | ||
| </root> | ||
| </log4j:configuration> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. 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 obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| my.property=Characters that should be encoded in ISO-8859-1: ��� |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. 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 obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| Characters that should be encoded in UTF-8: åäö |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. 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 obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
| --> | ||
| <!DOCTYPE web-app PUBLIC | ||
| "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" | ||
| "http://java.sun.com/dtd/web-app_2_3.dtd" > | ||
|
|
||
| <web-app> | ||
| <display-name>Archetype Created Web Application</display-name> | ||
| </web-app> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. 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 obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| <html> | ||
| <body> | ||
| <h2>Hello World!</h2> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
|
|
||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. 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 obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import java.io.*; | ||
|
|
||
| import org.codehaus.plexus.util.*; | ||
|
|
||
| boolean result = true; | ||
|
|
||
| try | ||
| { | ||
| File target = new File( basedir, "target/mwar450/WEB-INF/classes" ); | ||
| if ( !target.exists() || !target.isDirectory() ) | ||
| { | ||
| System.err.println( "target/mwar450/WEB-INF/classes is missing or is not a directory." ); | ||
| return false; | ||
| } | ||
|
|
||
| // Load and check log4j.xml | ||
| File log4jxml = new File( target, "log4j.xml" ); | ||
| if ( !log4jxml.exists() || log4jxml.isDirectory() ) | ||
| { | ||
| System.err.println( "log4j.xml is missing or is a directory." ); | ||
| return false; | ||
| } | ||
| FileInputStream fis = new FileInputStream ( log4jxml ); | ||
| String paramContent = IOUtil.toString ( fis, "UTF-8" ); | ||
| System.out.println( "content='" + paramContent + "'" ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This output will be mangled if run on non-UTF-8.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have tried this on both Windows (CP-1252) and Linux (UTF-8), and the output from the integration test looks fine for us, without mangled characters. Which platform did you have problems on? |
||
| int indexOf = paramContent.indexOf( "This file is encoded in UTF-8 and should remain so after filtering - åäö" ); | ||
| if ( indexOf < 0 ) | ||
| { | ||
| System.err.println( "Non-ascii characters changed encoding during filtering" ); | ||
| return false; | ||
| } | ||
|
|
||
| // Load and check my.properties | ||
| File myProperties = new File( target, "my.properties" ); | ||
| if ( !myProperties.exists() || myProperties.isDirectory() ) | ||
| { | ||
| System.err.println( "my.properties is missing or is a directory." ); | ||
| return false; | ||
| } | ||
| Properties properties = new Properties(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In jdk9 encoding of properties was changed. Maybe good assertions will be length of file?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is true that changes were made in Java 9. From what I understand the changes were made with regards to internationalization in PropertyResourceBundle, but not to regular Properties. https://docs.oracle.com/javase/9/docs/api/java/util/Properties.html The assertions that are in place should work fine regardless of Java version since we specify the encoding to use when reading the files, in the plugin's code. The only exception som that rule is when reading the properties file in the verify.bsh file in the integration test. |
||
| FileInputStream fis = new FileInputStream( myProperties ); | ||
| properties.load( fis ); | ||
| fis.close(); | ||
| String property = properties.get( "my.property" ); | ||
| System.out.println( "my.property='" + property + "'" ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
| if ( !"Characters that should be encoded in ISO-8859-1: åäö".equals( property ) ) | ||
| { | ||
| System.err.println( "Non-ascii characters has wrong encoding after filtering" ); | ||
| return false; | ||
| } | ||
|
|
||
| File myfile = new File( target, "myfile.txt" ); | ||
| if ( !myfile.exists() || myfile.isDirectory() ) | ||
| { | ||
| System.err.println( "myfile.txt is missing or is a directory." ); | ||
| return false; | ||
| } | ||
| FileInputStream fis = new FileInputStream ( myfile ); | ||
| String paramContent = IOUtil.toString ( fis, "UTF-8" ); | ||
| System.out.println( "content='" + paramContent + "'" ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
| int indexOf = paramContent.indexOf( "Characters that should be encoded in UTF-8: åäö" ); | ||
| if ( indexOf < 0 ) | ||
| { | ||
| System.err.println( "Non-ascii characters changed encoding during filtering" ); | ||
| return false; | ||
| } | ||
| } | ||
| catch( IOException e ) | ||
| { | ||
| e.printStackTrace(); | ||
| result = false; | ||
| } | ||
|
|
||
| return result; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't they in
src/main/resources?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No they don't in our use case. We like to separate our config files from our resources. This way the config files end up readable in the exploded war, instead of being packaged in the jar file of the project.