├── src ├── test │ ├── resources │ │ ├── subdirs │ │ │ └── x2 │ │ │ │ └── x3 │ │ │ │ └── sub.properties │ │ └── xxx.properties │ └── java │ │ └── org │ │ └── codehaus │ │ └── mojo │ │ └── native2ascii │ │ ├── Native2AsciiTest.java │ │ └── mojo │ │ └── Native2AsciiMojoTest.java ├── it │ ├── default_encoding │ │ ├── src │ │ │ └── main │ │ │ │ └── resources │ │ │ │ └── resource_ru.properties │ │ ├── verify.bsh │ │ └── pom.xml │ ├── filtering │ │ ├── src │ │ │ └── main │ │ │ │ └── resources │ │ │ │ └── resource_ru.properties │ │ ├── verify.bsh │ │ └── pom.xml │ ├── typical_usage │ │ ├── src │ │ │ └── main │ │ │ │ └── mycustomdir │ │ │ │ └── resource_ru.properties │ │ ├── verify.bsh │ │ └── pom.xml │ ├── typical_usage_test │ │ ├── src │ │ │ └── test │ │ │ │ └── native2ascii │ │ │ │ └── resource_ru.properties │ │ ├── verify.bsh │ │ └── pom.xml │ ├── includes_excludes │ │ ├── src │ │ │ └── main │ │ │ │ └── resources │ │ │ │ ├── included │ │ │ │ ├── resource_ru.properties │ │ │ │ └── excluded_resource_ru.properties │ │ │ │ └── not_included_resource_ru.properties │ │ ├── verify.bsh │ │ └── pom.xml │ ├── settings.xml │ └── no_classes │ │ └── pom.xml ├── site │ ├── apt │ │ ├── index.apt │ │ └── examples │ │ │ ├── resources2ascii.apt │ │ │ ├── inplace2ascii.apt │ │ │ └── test-resources2ascii.apt │ └── site.xml └── main │ ├── resources │ └── META-INF │ │ └── m2e │ │ └── lifecycle-mapping-metadata.xml │ └── java │ └── org │ └── codehaus │ └── mojo │ └── native2ascii │ ├── PropertyEscaper.java │ ├── mojo │ ├── Native2AsciiTestMojo.java │ ├── Native2AsciiMojo.java │ ├── Native2AsciiInplaceMojo.java │ └── AbstractNative2AsciiMojo.java │ └── Native2Ascii.java ├── .gitignore ├── .github ├── dependabot.yml └── workflows │ ├── linux-jdks-with-current-maven-ci.yml │ └── codeql-analysis.yml ├── LICENSE ├── README.md └── pom.xml /src/test/resources/subdirs/x2/x3/sub.properties: -------------------------------------------------------------------------------- 1 | crazy=šílené! 2 | -------------------------------------------------------------------------------- /src/it/default_encoding/src/main/resources/resource_ru.properties: -------------------------------------------------------------------------------- 1 | hello=Привет 2 | -------------------------------------------------------------------------------- /src/it/filtering/src/main/resources/resource_ru.properties: -------------------------------------------------------------------------------- 1 | hello=Привет ${name} 2 | -------------------------------------------------------------------------------- /src/it/typical_usage/src/main/mycustomdir/resource_ru.properties: -------------------------------------------------------------------------------- 1 | hello=Привет 2 | -------------------------------------------------------------------------------- /src/it/typical_usage_test/src/test/native2ascii/resource_ru.properties: -------------------------------------------------------------------------------- 1 | hello=Привет 2 | -------------------------------------------------------------------------------- /src/it/includes_excludes/src/main/resources/included/resource_ru.properties: -------------------------------------------------------------------------------- 1 | hello=Привет 2 | -------------------------------------------------------------------------------- /src/it/includes_excludes/src/main/resources/not_included_resource_ru.properties: -------------------------------------------------------------------------------- 1 | hello=Привет 2 | -------------------------------------------------------------------------------- /src/it/includes_excludes/src/main/resources/included/excluded_resource_ru.properties: -------------------------------------------------------------------------------- 1 | hello=Привет 2 | -------------------------------------------------------------------------------- /src/test/resources/xxx.properties: -------------------------------------------------------------------------------- 1 | 1=~ 2 | 2=\u007F 3 | 4 | 4=粗 Řízeček utíká a řeže zatáčky! § 5 | #comment 6 | 6=more tests needed! 7 | 7= 8 | -------------------------------------------------------------------------------- /src/it/default_encoding/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.codehaus.plexus.util.*; 3 | 4 | String buildLog = FileUtils.fileRead( new File( basedir, "build.log" ) ); 5 | if ( buildLog.indexOf( "actually) to convert resources!" ) < 0 ) { 6 | throw new RuntimeException( "No warning about encoding in log" ); 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | .svn 3 | .project 4 | .settings 5 | .classpath 6 | 7 | # Mobile Tools for Java (J2ME) 8 | .mtj.tmp/ 9 | 10 | # Package Files # 11 | *.jar 12 | *.war 13 | *.ear 14 | 15 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 16 | hs_err_pid* 17 | /target 18 | .idea 19 | -------------------------------------------------------------------------------- /src/it/filtering/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.codehaus.plexus.util.*; 3 | 4 | String resource = FileUtils.fileRead( new File( basedir, "target/classes/resource_ru.properties" ) ); 5 | if ( resource.indexOf( "hello=\\u041F\\u0440\\u0438\\u0432\\u0435\\u0442 world" ) < 0 ) { 6 | throw new RuntimeException( "Resource was not converted" ); 7 | } 8 | -------------------------------------------------------------------------------- /src/it/typical_usage/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.codehaus.plexus.util.*; 3 | 4 | String resource = FileUtils.fileRead( new File( basedir, "target/classes/i18n/resource_ru.properties" ) ); 5 | if ( resource.indexOf( "hello=\\u041F\\u0440\\u0438\\u0432\\u0435\\u0442" ) < 0 ) { 6 | throw new RuntimeException( "Resource was not converted" ); 7 | } 8 | String buildLog = FileUtils.fileRead( new File( basedir, "build.log" ) ); 9 | if ( buildLog.indexOf( "Converting '" ) < 0 ) { 10 | throw new RuntimeException( "No info log message about conversions" ); 11 | } 12 | -------------------------------------------------------------------------------- /src/it/typical_usage_test/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.codehaus.plexus.util.*; 3 | 4 | String resource = FileUtils.fileRead( new File( basedir, "target/test-classes/resource_ru.properties" ) ); 5 | if ( resource.indexOf( "hello=\\u041F\\u0440\\u0438\\u0432\\u0435\\u0442" ) < 0 ) { 6 | throw new RuntimeException( "Resource was not converted" ); 7 | } 8 | String buildLog = FileUtils.fileRead( new File( basedir, "build.log" ) ); 9 | if ( buildLog.indexOf( "Converting '" ) < 0 ) { 10 | throw new RuntimeException( "No info log message about conversions" ); 11 | } 12 | -------------------------------------------------------------------------------- /src/site/apt/index.apt: -------------------------------------------------------------------------------- 1 | ------ 2 | Introduction 3 | ------ 4 | David Matejcek 5 | 6 | ------ 7 | 2017-12-23 8 | ------ 9 | 10 | Native2Ascii Maven Plugin 11 | 12 | This plugin provides solution for developers who maintain property files in UTF-8 encoding 13 | but runtime needs ASCII and supports Unicode-escaped characters just like Java's 14 | java.util.Properties class. 15 | 16 | This plugin converts files in any supported character encoding to one with ASCII 17 | and/or Unicode escapes. 18 | 19 | See {{{./plugin-info.html}Goals}} and Examples to see more. 20 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "maven" 9 | directory: "/" 10 | schedule: 11 | interval: "weekly" 12 | - package-ecosystem: "github-actions" 13 | directory: "/" 14 | schedule: 15 | interval: "weekly" 16 | -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | resources 8 | testResources 9 | 10 | 11 | 12 | 13 | true 14 | true 15 | 16 | 17 | 18 | 19 | 20 | 21 | inplace 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/it/includes_excludes/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.codehaus.plexus.util.*; 3 | 4 | String resource = FileUtils.fileRead( new File( basedir, "target/classes/native2asciified/included/resource_ru.properties" ) ); 5 | if ( resource.indexOf( "hello=\\u041F\\u0440\\u0438\\u0432\\u0435\\u0442" ) < 0 ) { 6 | throw new RuntimeException( "Resource was not converted" ); 7 | } 8 | 9 | File file = new File( basedir, "target/classes/native2asciified/not_included_resource_ru.properties" ); 10 | if ( file.exists() ) { 11 | throw new RuntimeException( "Not included resource was converted" ); 12 | } 13 | 14 | file = new File( basedir, "target/classes/native2asciified/included/excluded_resource_ru.properties" ); 15 | if ( file.exists() ) { 16 | throw new RuntimeException( "Excluded resource was converted" ); 17 | } 18 | 19 | String buildLog = FileUtils.fileRead( new File( basedir, "build.log" ) ); 20 | if ( buildLog.indexOf( "Converting '" ) < 0 ) { 21 | throw new RuntimeException( "No info log message about conversions" ); 22 | } 23 | -------------------------------------------------------------------------------- /src/it/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | it-repo 6 | 7 | true 8 | 9 | 10 | 11 | local.central 12 | @localRepositoryUrl@ 13 | 14 | true 15 | 16 | 17 | true 18 | 19 | 20 | 21 | 22 | 23 | local.central 24 | @localRepositoryUrl@ 25 | 26 | true 27 | 28 | 29 | true 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/it/no_classes/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.example 6 | noclasses 7 | 1.0-SNAPSHOT 8 | 9 | target/classes does not exist 10 | 11 | 12 | UTF-8 13 | 14 | 15 | 16 | 17 | 18 | @project.groupId@ 19 | @project.artifactId@ 20 | @project.version@ 21 | 22 | 23 | 24 | resources 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/it/default_encoding/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.example 6 | noencoding 7 | 1.0-SNAPSHOT 8 | 9 | project.build.sourceEncoding not specified 10 | 11 | 12 | 13 | 14 | @project.groupId@ 15 | @project.artifactId@ 16 | @project.version@ 17 | 18 | ${project.build.outputDirectory} 19 | 20 | 21 | 22 | 23 | inplace 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2007 The Codehaus. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/it/typical_usage_test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.example 6 | example 7 | 1.0-SNAPSHOT 8 | 9 | 10 | 11 | 12 | UTF-8 13 | 14 | 15 | 16 | 17 | 18 | @project.groupId@ 19 | @project.artifactId@ 20 | @project.version@ 21 | 22 | 23 | 24 | 25 | testResources 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Native2ascii Maven Plugin 2 | 3 | [![License: MIT](https://img.shields.io/github/license/mojohaus/native2ascii-maven-plugin)](https://opensource.org/licenses/MIT) 4 | [![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.mojo/native2ascii-maven-plugin.svg?label=Maven%20Central)](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.codehaus.mojo%22%20AND%20a%3A%22native2ascii-maven-plugin%22) 5 | [![JDK Compatibility](https://github.com/mojohaus/native2ascii-maven-plugin/actions/workflows/linux-jdks-with-current-maven-ci.yml/badge.svg)](https://github.com/mojohaus/native2ascii-maven-plugin/actions/workflows/linux-jdks-with-current-maven-ci.yml) 6 | [![CodeQL Analysis](https://github.com/mojohaus/native2ascii-maven-plugin/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/mojohaus/native2ascii-maven-plugin/actions/workflows/codeql-analysis.yml) 7 | 8 | Converts files with characters in any supported character encoding to one with ASCII and/or Unicode escapes. 9 | 10 | # Howto 11 | 12 | Look here for the usage: https://github.com/mojohaus/native2ascii/wiki/_pages 13 | 14 | Also note this issue: https://bugs.openjdk.java.net/browse/JDK-8074431 - this plugin is not affected and works even with JDK18. 15 | -------------------------------------------------------------------------------- /src/it/typical_usage/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.example 6 | example 7 | 1.0-SNAPSHOT 8 | 9 | 10 | 11 | 12 | UTF-8 13 | 14 | 15 | 16 | 17 | 18 | @project.groupId@ 19 | @project.artifactId@ 20 | @project.version@ 21 | 22 | 23 | 24 | resources 25 | 26 | 27 | src/main/mycustomdir 28 | ${project.build.outputDirectory}/i18n 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/site/apt/examples/resources2ascii.apt: -------------------------------------------------------------------------------- 1 | ------ 2 | Converting Resources 3 | ------ 4 | David Matejcek 5 | ------ 6 | 2017-12-23 7 | ------ 8 | 9 | Converting UTF-8 properties to standard 10 | 11 | This goal targets the basic scenario - conversion of UTF-8 files to Unicode-escaped files 12 | without any change of the originals. 13 | 14 | --- 15 | 16 | org.codehaus.mojo 17 | native2ascii-maven-plugin 18 | ____ 19 | 20 | 21 | utf8-to-latin1 22 | 23 | resources 24 | 25 | process-resources 26 | 27 | src/main/native2ascii 28 | ${project.build.outputDirectory} 29 | ${project.build.sourceEncoding} 30 | 31 | **/*.properties 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | --- 41 | -------------------------------------------------------------------------------- /src/site/apt/examples/inplace2ascii.apt: -------------------------------------------------------------------------------- 1 | ------ 2 | Converting Resources Inplace 3 | ------ 4 | David Matejcek 5 | ------ 6 | 2017-12-23 7 | ------ 8 | 9 | Converting UTF-8 properties to standard inplace 10 | 11 | This goal targets the scenario known from 1-beta version - conversion of 12 | UTF-8 file content to Unicode-escaped content on the same file. 13 | 14 | Note that this target is not covered by eclipse lifecycle. 15 | 16 | --- 17 | 18 | org.codehaus.mojo 19 | native2ascii-maven-plugin 20 | ____ 21 | 22 | 23 | utf8-to-latin1 24 | 25 | inplace 26 | 27 | process-resources 28 | 29 | ${project.build.testOutputDirectory}/localized 30 | ${project.build.sourceEncoding} 31 | 32 | **/*.properties 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | --- 42 | -------------------------------------------------------------------------------- /src/site/apt/examples/test-resources2ascii.apt: -------------------------------------------------------------------------------- 1 | ------ 2 | Converting Test Resources 3 | ------ 4 | David Matejcek 5 | ------ 6 | 2017-12-23 7 | ------ 8 | 9 | Converting UTF-8 properties to standard 10 | 11 | This goal targets the basic testing scenario - conversion of UTF-8 files to Unicode-escaped files 12 | without any change of the originals or the target artifact. 13 | 14 | --- 15 | 16 | org.codehaus.mojo 17 | native2ascii-maven-plugin 18 | ____ 19 | 20 | 21 | utf8-to-latin1 22 | 23 | testResources 24 | 25 | process-test-resources 26 | 27 | src/test/native2ascii 28 | ${project.build.testOutputDirectory} 29 | ${project.build.sourceEncoding} 30 | 31 | **/*.properties 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | --- 41 | -------------------------------------------------------------------------------- /src/it/filtering/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.example 6 | filtering 7 | 1.0-SNAPSHOT 8 | 9 | 10 | 11 | 12 | UTF-8 13 | ${project.build.outputDirectory} 14 | world 15 | 16 | 17 | 18 | 19 | 20 | src/main/resources 21 | true 22 | 23 | 24 | 25 | 26 | 27 | @project.groupId@ 28 | @project.artifactId@ 29 | @project.version@ 30 | 31 | 32 | 33 | inplace 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/it/includes_excludes/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.example 6 | includesexcludes 7 | 1.0-SNAPSHOT 8 | 9 | 10 | 11 | 12 | UTF-8 13 | 14 | 15 | 16 | 17 | 18 | @project.groupId@ 19 | @project.artifactId@ 20 | @project.version@ 21 | 22 | ${project.build.outputDirectory} 23 | ${project.build.outputDirectory}/native2asciified 24 | 25 | included/** 26 | 27 | 28 | **/excluded* 29 | 30 | 31 | 32 | 33 | package 34 | 35 | resources 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /.github/workflows/linux-jdks-with-current-maven-ci.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | name: Compatibility 19 | 20 | on: 21 | push: 22 | branches: 23 | - master 24 | - '*' 25 | pull_request: 26 | branches: 27 | - '*' 28 | 29 | jobs: 30 | openjdk: 31 | strategy: 32 | matrix: 33 | platform: [3.6-openjdk-8-slim, 3.9-eclipse-temurin-8, 3.6-openjdk-11-slim, 3.8-eclipse-temurin-17-alpine, 3.9-eclipse-temurin-20-alpine] 34 | name: "Platform ${{ matrix.platform }}" 35 | runs-on: ubuntu-latest 36 | container: "maven:${{ matrix.platform }}" 37 | steps: 38 | - uses: actions/checkout@v6 39 | - name: 'Build' 40 | run: mvn -B -V clean verify --fail-at-end 41 | 42 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/mojo/native2ascii/PropertyEscaper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * Copyright (c) 2014-2022 MojoHaus 4 | * Copyright (c) 2007 The Codehaus 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | * associated documentation files (the "Software"), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all copies or 11 | * substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 13 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | */ 18 | package org.codehaus.mojo.native2ascii; 19 | 20 | import org.apache.commons.text.translate.UnicodeEscaper; 21 | 22 | /** 23 | * Uses {@link UnicodeEscaper} to translate strings with bytes over \u007F to unicode. 24 | * 25 | * @author David Matějček 26 | */ 27 | public class PropertyEscaper extends UnicodeEscaper { 28 | 29 | /** 30 | * Constructor using {@link UnicodeEscaper#UnicodeEscaper(int, int, boolean)} 31 | */ 32 | public PropertyEscaper() { 33 | super(0x007F, Integer.MAX_VALUE, true); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/mojo/native2ascii/Native2AsciiTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * Copyright (c) 2014-2022 MojoHaus 4 | * Copyright (c) 2007 The Codehaus 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | * associated documentation files (the "Software"), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all copies or 11 | * substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 13 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | */ 18 | package org.codehaus.mojo.native2ascii; 19 | 20 | import org.apache.maven.plugin.logging.SystemStreamLog; 21 | import org.junit.jupiter.api.Test; 22 | 23 | import static org.junit.jupiter.api.Assertions.assertEquals; 24 | 25 | public class Native2AsciiTest { 26 | 27 | private final Native2Ascii native2Ascii = new Native2Ascii(new SystemStreamLog()); 28 | 29 | @Test 30 | public void test() { 31 | assertEquals(null, this.native2Ascii.nativeToAscii(null)); 32 | assertEquals("~", this.native2Ascii.nativeToAscii("~")); 33 | assertEquals("\\u007F", this.native2Ascii.nativeToAscii("")); 34 | // chinese character is random since I don't understand it 35 | assertEquals("\\u7C97", this.native2Ascii.nativeToAscii("粗")); 36 | assertEquals( 37 | "\\u0158\\u00EDze\\u010Dek ut\\u00EDk\\u00E1 a \\u0159e\\u017Ee zat\\u00E1\\u010Dky! \\u00A7", 38 | this.native2Ascii.nativeToAscii("Řízeček utíká a řeže zatáčky! §")); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/mojo/native2ascii/mojo/Native2AsciiTestMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * Copyright (c) 2007 The Codehaus 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 5 | * associated documentation files (the "Software"), to deal in the Software without restriction, 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * The above copyright notice and this permission notice shall be included in all copies or 10 | * substantial portions of the Software. 11 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 12 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 13 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 14 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | */ 17 | package org.codehaus.mojo.native2ascii.mojo; 18 | 19 | import java.io.File; 20 | 21 | import org.apache.maven.plugins.annotations.LifecyclePhase; 22 | import org.apache.maven.plugins.annotations.Mojo; 23 | import org.apache.maven.plugins.annotations.Parameter; 24 | 25 | /** 26 | * Converts files with characters in any supported character encoding to one with ASCII and/or 27 | * Unicode escapes. 28 | * 29 | * @author David Matějček 30 | */ 31 | @Mojo(name = "testResources", threadSafe = true, defaultPhase = LifecyclePhase.PROCESS_TEST_RESOURCES) 32 | public class Native2AsciiTestMojo extends Native2AsciiMojo { 33 | 34 | /** 35 | * Target directory. 36 | */ 37 | @Parameter(defaultValue = "${project.build.testOutputDirectory}") 38 | public File targetDir; 39 | 40 | /** 41 | * Source directory. 42 | */ 43 | @Parameter(defaultValue = "src/test/native2ascii") 44 | public File srcDir; 45 | 46 | @Override 47 | protected File getSourceDirectory() { 48 | return srcDir; 49 | } 50 | 51 | /** 52 | * @return the target directory 53 | */ 54 | @Override 55 | protected File getTargetDirectory() { 56 | return targetDir; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ "master" ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ "master" ] 20 | schedule: 21 | - cron: '20 18 * * 5' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'java' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v6 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v4 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | 52 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 53 | # queries: security-extended,security-and-quality 54 | 55 | 56 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 57 | # If this step fails, then you should remove it and run the build manually (see below) 58 | - name: Autobuild 59 | uses: github/codeql-action/autobuild@v4 60 | 61 | # ℹ️ Command-line programs to run using the OS shell. 62 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 63 | 64 | # If the Autobuild fails above, remove it and uncomment the following three lines. 65 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 66 | 67 | # - run: | 68 | # echo "Run, Build Application using script" 69 | # ./location_of_script_within_repo/buildscript.sh 70 | 71 | - name: Perform CodeQL Analysis 72 | uses: github/codeql-action/analyze@v4 73 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/mojo/native2ascii/mojo/Native2AsciiMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * Copyright (c) 2014-2023 MojoHaus 4 | * Copyright (c) 2007 The Codehaus 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | * associated documentation files (the "Software"), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all copies or 11 | * substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 13 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | */ 18 | package org.codehaus.mojo.native2ascii.mojo; 19 | 20 | import java.io.File; 21 | import java.io.IOException; 22 | import java.util.Iterator; 23 | 24 | import org.apache.commons.lang3.StringUtils; 25 | import org.apache.maven.plugin.MojoExecutionException; 26 | import org.apache.maven.plugins.annotations.LifecyclePhase; 27 | import org.apache.maven.plugins.annotations.Mojo; 28 | import org.apache.maven.plugins.annotations.Parameter; 29 | import org.codehaus.mojo.native2ascii.Native2Ascii; 30 | 31 | /** 32 | * Converts files with characters in any supported character encoding to one with ASCII and/or 33 | * Unicode escapes. 34 | */ 35 | @Mojo(name = "resources", threadSafe = true, defaultPhase = LifecyclePhase.PROCESS_RESOURCES) 36 | public class Native2AsciiMojo extends AbstractNative2AsciiMojo { 37 | 38 | /** 39 | * Target directory. 40 | */ 41 | @Parameter(defaultValue = "${project.build.outputDirectory}") 42 | public File targetDir; 43 | 44 | /** 45 | * Source directory. 46 | */ 47 | @Parameter(defaultValue = "src/main/native2ascii") 48 | public File srcDir; 49 | 50 | @Override 51 | protected File getSourceDirectory() { 52 | return srcDir; 53 | } 54 | 55 | /** 56 | * @return the target directory 57 | */ 58 | protected File getTargetDirectory() { 59 | return targetDir; 60 | } 61 | 62 | @Override 63 | public void executeTransformation(final Iterator files) throws MojoExecutionException { 64 | if (!getTargetDirectory().exists()) { 65 | getTargetDirectory().mkdirs(); 66 | } 67 | 68 | while (files.hasNext()) { 69 | final File file = files.next(); 70 | try { 71 | File targetFile = getTargetFile(file); 72 | getLog().info("Converting '" + file + "' to '" + targetFile + "'"); 73 | new Native2Ascii(getLog()).nativeToAscii(file, targetFile, encoding); 74 | } catch (final IOException e) { 75 | throw new MojoExecutionException("Unable to convert " + file.getAbsolutePath(), e); 76 | } 77 | } 78 | } 79 | 80 | private File getTargetFile(final File sourceFile) throws IOException { 81 | return new File(StringUtils.replace( 82 | sourceFile.getCanonicalPath(), 83 | getSourceDirectory().getCanonicalPath(), 84 | getTargetDirectory().getCanonicalPath())); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/mojo/native2ascii/Native2Ascii.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * Copyright (c) 2014-2023 MojoHaus 4 | * Copyright (c) 2007 The Codehaus 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | * associated documentation files (the "Software"), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all copies or 11 | * substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 13 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | */ 18 | package org.codehaus.mojo.native2ascii; 19 | 20 | import java.io.BufferedReader; 21 | import java.io.BufferedWriter; 22 | import java.io.File; 23 | import java.io.FileInputStream; 24 | import java.io.FileOutputStream; 25 | import java.io.IOException; 26 | import java.io.InputStreamReader; 27 | import java.io.OutputStreamWriter; 28 | import java.nio.CharBuffer; 29 | 30 | import org.apache.commons.text.translate.CharSequenceTranslator; 31 | import org.apache.maven.plugin.logging.Log; 32 | 33 | import static java.nio.charset.StandardCharsets.ISO_8859_1; 34 | 35 | /** 36 | * @author Evgeny Mandrikov 37 | * @author David Matejcek 38 | */ 39 | public final class Native2Ascii { 40 | 41 | private final Log log; 42 | private final CharSequenceTranslator escaper; 43 | 44 | /** 45 | * @param log - used for logging 46 | */ 47 | public Native2Ascii(final Log log) { 48 | this.log = log; 49 | this.escaper = new PropertyEscaper(); 50 | } 51 | 52 | /** 53 | * Converts given CharSequence into unicode escaped ASCII String. 54 | * 55 | * @param string - native string 56 | * @return unicode escaped string 57 | */ 58 | public String nativeToAscii(final String string) { 59 | if (string == null) { 60 | return null; 61 | } 62 | if (this.log.isDebugEnabled()) { 63 | this.log.debug("Converting string: '" + string + "'"); 64 | } 65 | return this.escaper.translate(string); 66 | } 67 | 68 | /** 69 | * Converts given file into file unicode escaped ASCII file. 70 | * 71 | * @param src 72 | * @param dst 73 | * @param encoding 74 | * @throws IOException 75 | */ 76 | public void nativeToAscii(final File src, final File dst, final String encoding) throws IOException { 77 | this.log.debug("Processing '" + src + "' to '" + dst + "'"); 78 | if (!dst.getParentFile().exists()) { 79 | dst.getParentFile().mkdirs(); 80 | } 81 | try (BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(src), encoding)); 82 | BufferedWriter output = 83 | new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dst), ISO_8859_1))) { 84 | final char[] buffer = new char[4096]; 85 | int len; 86 | while ((len = input.read(buffer)) != -1) { 87 | output.write(nativeToAscii(CharBuffer.wrap(buffer, 0, len).toString())); 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/mojo/native2ascii/mojo/Native2AsciiInplaceMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * Copyright (c) 2023 MojoHaus 4 | * Copyright (c) 2007 The Codehaus 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | * associated documentation files (the "Software"), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all copies or 11 | * substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 13 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | */ 18 | package org.codehaus.mojo.native2ascii.mojo; 19 | 20 | import java.io.File; 21 | import java.io.IOException; 22 | import java.nio.file.Files; 23 | import java.nio.file.Path; 24 | import java.util.Iterator; 25 | 26 | import org.apache.maven.plugin.MojoExecutionException; 27 | import org.apache.maven.plugins.annotations.LifecyclePhase; 28 | import org.apache.maven.plugins.annotations.Mojo; 29 | import org.apache.maven.plugins.annotations.Parameter; 30 | import org.codehaus.mojo.native2ascii.Native2Ascii; 31 | import org.codehaus.plexus.util.FileUtils; 32 | 33 | /** 34 | * Converts files with characters in any supported character encoding to one with ASCII and/or 35 | * Unicode escapes. 36 | *

37 | * This mojo converts files inplace, it is not recommended to execute it on src subdirectories. 38 | */ 39 | @Mojo(name = "inplace", threadSafe = true, defaultPhase = LifecyclePhase.PROCESS_RESOURCES) 40 | public class Native2AsciiInplaceMojo extends AbstractNative2AsciiMojo { 41 | 42 | /** 43 | * Both source and target directory. 44 | */ 45 | @Parameter(required = true, defaultValue = "${native2ascii.dir}") 46 | protected File dir; 47 | 48 | /** 49 | * The project's target directory. 50 | */ 51 | @Parameter(required = true, readonly = true, property = "project.build.directory") 52 | private File targetDir; 53 | 54 | @Override 55 | protected File getSourceDirectory() { 56 | return dir; 57 | } 58 | 59 | @Override 60 | public void executeTransformation(final Iterator files) throws MojoExecutionException { 61 | Path tmpDir = createTmpDir(); 62 | while (files.hasNext()) { 63 | File file = files.next(); 64 | getLog().info("Converting " + file); 65 | try { 66 | File tempFile = Files.createTempFile(tmpDir, file.getName(), "native2ascii") 67 | .toFile(); 68 | new Native2Ascii(getLog()).nativeToAscii(file, tempFile, encoding); 69 | FileUtils.rename(tempFile, file); 70 | getLog().debug("File converted successfuly: " + file); 71 | } catch (IOException e) { 72 | throw new MojoExecutionException("Unable to convert " + file.getAbsolutePath(), e); 73 | } 74 | } 75 | } 76 | 77 | private Path createTmpDir() throws MojoExecutionException { 78 | try { 79 | return Files.createTempDirectory(targetDir.toPath(), "tmp"); 80 | } catch (IOException e) { 81 | throw new MojoExecutionException("Could not create temporary directory under the " + targetDir, e); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/test/java/org/codehaus/mojo/native2ascii/mojo/Native2AsciiMojoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * Copyright (c) 2014-2022 MojoHaus 4 | * Copyright (c) 2007 The Codehaus 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | * associated documentation files (the "Software"), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all copies or 11 | * substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 13 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | */ 18 | package org.codehaus.mojo.native2ascii.mojo; 19 | 20 | import java.io.File; 21 | import java.io.FileInputStream; 22 | import java.io.IOException; 23 | import java.net.URISyntaxException; 24 | import java.util.Properties; 25 | 26 | import org.junit.jupiter.api.Test; 27 | 28 | import static org.junit.jupiter.api.Assertions.assertEquals; 29 | import static org.junit.jupiter.api.Assertions.assertNull; 30 | import static org.junit.jupiter.api.Assertions.assertTrue; 31 | 32 | /** 33 | * @author David Matějček 34 | */ 35 | public class Native2AsciiMojoTest { 36 | 37 | @Test 38 | public void testFile() throws Exception { 39 | final Native2AsciiMojo mojo = new Native2AsciiMojo(); 40 | mojo.encoding = "UTF-8"; 41 | mojo.srcDir = getSourceDirectory(); 42 | mojo.targetDir = mojo.srcDir.getParentFile(); 43 | mojo.includes = new String[] {"xxx.properties"}; 44 | mojo.excludes = new String[0]; 45 | mojo.execute(); 46 | 47 | final Properties properties = loadFile(new File(mojo.targetDir, "xxx.properties")); 48 | assertEquals("~", properties.get("1")); 49 | assertEquals("", properties.get("2")); 50 | assertNull(properties.get("3")); 51 | assertEquals("粗 Řízeček utíká a řeže zatáčky! §", properties.get("4")); 52 | assertNull(properties.get("5")); 53 | assertEquals("more tests needed!", properties.get("6")); 54 | assertEquals("", properties.get("7")); 55 | } 56 | 57 | @Test 58 | public void testSubdirectories() throws Exception { 59 | final Native2AsciiMojo mojo = new Native2AsciiMojo(); 60 | mojo.encoding = "UTF-8"; 61 | mojo.srcDir = getSourceDirectory(); 62 | mojo.targetDir = mojo.srcDir.getParentFile(); 63 | mojo.includes = new String[] {"subdirs/**/*"}; 64 | mojo.excludes = new String[0]; 65 | mojo.execute(); 66 | 67 | final File file = new File(mojo.targetDir.getCanonicalPath() + File.separator + "subdirs/x2/x3/sub.properties"); 68 | assertTrue(file.exists(), "file does not exist: " + file); 69 | final Properties properties = loadFile(file); 70 | assertEquals("šílené!", properties.get("crazy")); 71 | } 72 | 73 | private File getSourceDirectory() throws URISyntaxException { 74 | return new File(Native2AsciiMojoTest.class 75 | .getClassLoader() 76 | .getResource("xxx.properties") 77 | .toURI()) 78 | .getParentFile(); 79 | } 80 | 81 | private Properties loadFile(final File file) throws IOException { 82 | final Properties properties = new Properties(); 83 | final FileInputStream inputStream = new FileInputStream(file); 84 | try { 85 | properties.load(inputStream); 86 | return properties; 87 | } finally { 88 | inputStream.close(); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/codehaus/mojo/native2ascii/mojo/AbstractNative2AsciiMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * Copyright (c) 2014-2023 MojoHaus 4 | * Copyright (c) 2007 The Codehaus 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | * associated documentation files (the "Software"), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all copies or 11 | * substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 13 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | */ 18 | package org.codehaus.mojo.native2ascii.mojo; 19 | 20 | import java.io.File; 21 | import java.io.IOException; 22 | import java.nio.charset.Charset; 23 | import java.util.Arrays; 24 | import java.util.Iterator; 25 | 26 | import org.apache.commons.lang3.StringUtils; 27 | import org.apache.maven.plugin.AbstractMojo; 28 | import org.apache.maven.plugin.MojoExecutionException; 29 | import org.apache.maven.plugin.MojoFailureException; 30 | import org.apache.maven.plugins.annotations.Parameter; 31 | import org.codehaus.plexus.util.FileUtils; 32 | 33 | /** 34 | * @author David Matějček 35 | */ 36 | public abstract class AbstractNative2AsciiMojo extends AbstractMojo { 37 | 38 | /** 39 | * The native encoding the files are in. 40 | */ 41 | @Parameter(defaultValue = "${project.build.sourceEncoding}") 42 | public String encoding; 43 | 44 | /** 45 | * Patterns of files to include. Default is "**\/*.properties". 46 | */ 47 | @Parameter 48 | public String[] includes; 49 | 50 | /** 51 | * Patterns of files that must be excluded. 52 | */ 53 | @Parameter 54 | public String[] excludes; 55 | 56 | @Override 57 | public final void execute() throws MojoExecutionException, MojoFailureException { 58 | if (!checkParameters()) { 59 | return; 60 | } 61 | final Iterator files = findFiles(); 62 | executeTransformation(files); 63 | } 64 | 65 | /** 66 | * @return the root directory where the plugin should look for files. 67 | */ 68 | protected abstract File getSourceDirectory(); 69 | 70 | /** 71 | * Executes the transformation of files. 72 | * 73 | * @param files 74 | * @throws MojoExecutionException 75 | */ 76 | protected abstract void executeTransformation(Iterator files) throws MojoExecutionException; 77 | 78 | /** 79 | * Checks all attributes. Override if needed. 80 | * 81 | * @return true if we can continue 82 | */ 83 | protected boolean checkParameters() { 84 | if (!getSourceDirectory().exists()) { 85 | getLog().warn("Source directory does not exist: " 86 | + getSourceDirectory().getAbsolutePath()); 87 | return false; 88 | } 89 | if (this.includes == null) { 90 | this.includes = new String[] {"**/*.properties"}; 91 | } 92 | if (this.excludes == null) { 93 | this.excludes = new String[0]; 94 | } 95 | if (StringUtils.isEmpty(this.encoding)) { 96 | this.encoding = Charset.defaultCharset().displayName(); 97 | getLog().warn("Using platform encoding (" + this.encoding + " actually) to convert resources!"); 98 | } 99 | return true; 100 | } 101 | 102 | private Iterator findFiles() throws MojoExecutionException { 103 | try { 104 | if (getLog().isDebugEnabled()) { 105 | getLog().debug("Includes: " + Arrays.asList(this.includes)); 106 | getLog().debug("Excludes: " + Arrays.asList(this.excludes)); 107 | } 108 | final String incl = StringUtils.join(this.includes, ","); 109 | final String excl = StringUtils.join(this.excludes, ","); 110 | final Iterator files = 111 | FileUtils.getFiles(getSourceDirectory(), incl, excl).iterator(); 112 | return files; 113 | } catch (final IOException e) { 114 | throw new MojoExecutionException("Unable to get list of files"); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.codehaus.mojo 7 | mojo-parent 8 | 94 9 | 10 | 11 | native2ascii-maven-plugin 12 | 2.1.2-SNAPSHOT 13 | maven-plugin 14 | 15 | Native2Ascii Maven Plugin 16 | Converts files with characters in any supported character encoding to 17 | one with ASCII and/or Unicode escapes. 18 | 19 | https://github.com/mojohaus/native2ascii-maven-plugin/wiki 20 | 2007 21 | 22 | 23 | The MIT License 24 | http://www.opensource.org/licenses/mit-license.php 25 | repo 26 | 27 | 28 | 29 | 30 | 31 | dmatej 32 | David Matějček 33 | dmatej@seznam.cz 34 | 35 | Developer 36 | 37 | +1 38 | 39 | 40 | godin 41 | Evgeny Mandrikov 42 | mandrikov@gmail.com 43 | SonarSource 44 | http://sonarsource.com 45 | +3 46 | 47 | 48 | dantran 49 | Dan Tran 50 | dtran@gmail.com 51 | 52 | Developer 53 | 54 | 55 | 56 | Martin Thelian 57 | 58 | Contributer 59 | 60 | 61 | 62 | 63 | 64 | scm:git:https://github.com/mojohaus/native2ascii.git 65 | scm:git:ssh://git@github.com/mojohaus/native2ascii.git 66 | HEAD 67 | https://github.com/mojohaus/native2ascii 68 | 69 | 70 | GitHub 71 | https://github.com/mojohaus/native2ascii/issues 72 | 73 | 74 | GitHub 75 | https://github.com/mojohaus/native2ascii-maven-plugin/actions 76 | 77 | 78 | 79 | ossrh-staging 80 | https://oss.sonatype.org/service/local/staging/deploy/maven2 81 | 82 | 83 | ossrh-snapshots 84 | https://oss.sonatype.org/content/repositories/snapshots 85 | 86 | 87 | 88 | 89 | 90 | org.codehaus.plexus 91 | plexus-utils 92 | 4.0.2 93 | 94 | 95 | org.apache.maven 96 | maven-plugin-api 97 | 3.9.11 98 | provided 99 | 100 | 101 | org.apache.maven.plugins 102 | maven-plugin-plugin 103 | 3.15.2 104 | provided 105 | 106 | 107 | org.codehaus.plexus 108 | * 109 | 110 | 111 | org.apache.velocity 112 | * 113 | 114 | 115 | 116 | 117 | org.apache.commons 118 | commons-text 119 | 1.15.0 120 | 121 | 122 | org.apache.commons 123 | commons-lang3 124 | 3.20.0 125 | 126 | 127 | org.junit.jupiter 128 | junit-jupiter-api 129 | test 130 | 131 | 132 | org.junit.jupiter 133 | junit-jupiter-engine 134 | test 135 | 136 | 137 | 138 | 139 | 140 | 141 | org.apache.maven.plugins 142 | maven-plugin-plugin 143 | 144 | 145 | 146 | org.apache.maven.plugins 147 | maven-invoker-plugin 148 | 149 | false 150 | src/it 151 | ${project.build.directory}/it 152 | 153 | */pom.xml 154 | 155 | verify 156 | ${project.build.directory}/local-repo 157 | 158 | clean 159 | install 160 | 161 | src/it/settings.xml 162 | 163 | 164 | 165 | 166 | install 167 | run 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | --------------------------------------------------------------------------------