SourceForge.net Logo

Properties2Java

Download Site:
https://sourceforge.net/project/showfiles.php?group_id=140213

DESCRIPTION
-------------------------
Properties2Java is an Ant task for automatic conversion of 
java ".properties" files to ".java" files extending the 
java.util.ListResourceBundle. 

INSTALL
-------------------------
Requirements:
	* JDK 1.4 or above
	* Ant Version 1.6 or above
	
Usage:
	* Copy 'dist/lib/properties2java.jar' to your own project lib
	  directory (e.g. ./lib/ant relative to your build file)
	* to make the new task available for Ant you have to declare it
	  in your build file:
		<taskdef name="properties2java"
			classname="de.jayefem.ant.properties2java.taskdefs.Properties2Java"
			classpath="./lib/ant/properties2java.jar"/>
	* Example usage
		<properties2java 
			file="test/simple/source/Dummy.properties"
			toDir="test/simple/target/" 
			packagename="de.jayefem" 
			filecomment = "true"
			crlf = "true"
			verbose="true" />
	* Task attributes:
	  o file (mandatory)
	  		The properties file to convert
	  o toDir (mandatory)
	  		The target directory of the converted java file. The directory
	  		must exist.
	  o packagename (mandatory)
	  		Used to generate the java code 
	  o filecomment (optional)
	  		If set to "true", the task will put a "DO NOT EDIT" comment 
	  		in the generated java source. No comment will be generated
	  		if set to "false".
			Default is "true". 
	  o crlf (optional)
	  		If set to "true", the java file will be generated with '\r\n' 
	  		as line delimiter. If set to "false", '\n' is used.
	  		Default is "false".
	  o verbose (optional)
	  		Verbose output while running the task.

RESULT EXAMPLE 
-------------------------

Dummy.properties: 
	test.simple=simple
	test.quotes="quotes"
	test.lf=before\nafter
	test.crlf=before\r\nafter
	test.tab=before\tafter

=>
	
Dummy.java:
	/*
	 * DO NOT EDIT!
	 * Automatic generated java file from original source:
	 * C:\properties2java\test\simple\source\Dummy.properties 
	 */
	package de.jayefem;
	
	import java.util.ListResourceBundle;

	public class Dummy extends ListResourceBundle {
		/**
		 * @see java.util.ListResourceBundle#getContents()
		 */
		public Object[][] getContents() {
			return contents;
		}
	
		static final Object[][] contents = {
			{"test.simple","simple"},
			{"test.quotes","\"quotes\""},
			{"test.crlf","before\r\nafter"},
			{"test.lf","before\nafter"},
			{"test.tab","before\tafter"}
		};
	}
	
WHY USING THAT TASK?
-------------------------
	If you're using an obfuscator which is not able to encode 
	the contents of an properties file, it would be useful
	to convert the properties to java files which can be handled
	by an obfuscator easily.
	
	Generally when using that task in combination with an obfuscator, 
	you have to modify your sourcecode
	from:
	ResourceBundle.getBundle("de.jayefem.Dummy");
	to:
	ResourceBundle.getBundle(de.jayefem.Dummy.class.getName());

COMPILATION
-------------------------
Requirements:
	* JDK 1.4 or above
	* Ant Version 1.6 or greater to compile and build the
	  package.

Building the project:
	* Check out CVS source as described on the sourceforge site
	* Create the directory './lib'
	* Copy all jars of APACHE Ant Version 1.6 or above to './lib'
	* invoke Ant task "all" on the build.xml of this project
	* to test the output invoke the Ant task "test" and check the contents of
	  './test/simple/target/Dummy.java'
	  
	-----------------------------------------------
	Development contribution is HIGHLY APPRECIATED!
	-----------------------------------------------
	
LICENSE
-------------------------
	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

		http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.





June 2005, Jan-Friedrich Mutter
p2j@jayefem.de