harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r804823 - in /harmony/enhanced/tools/trunk/minijre: ./ conf/ lib/ native/ script/ src/ src/org/ src/org/crazynut/ src/org/crazynut/harmony/ src/org/crazynut/harmony/minjre/ src/org/crazynut/harmony/minjre/anttask/ src/org/crazynut/harmony/m...
Date Mon, 17 Aug 2009 01:43:03 GMT
Author: regisxu
Date: Mon Aug 17 01:43:02 2009
New Revision: 804823

URL: http://svn.apache.org/viewvc?rev=804823&view=rev
Log:
Apply patch for HARMONY-6291: Smallest classes set for customer application

This tool is a project of Google Summer of Code 2009. It can genereate a minimized Harmony JRE for a given Java application.


Added:
    harmony/enhanced/tools/trunk/minijre/
    harmony/enhanced/tools/trunk/minijre/build.xml
    harmony/enhanced/tools/trunk/minijre/conf/
    harmony/enhanced/tools/trunk/minijre/conf/harmony.cns
    harmony/enhanced/tools/trunk/minijre/lib/
    harmony/enhanced/tools/trunk/minijre/native/
    harmony/enhanced/tools/trunk/minijre/native/ClassLoadTraceAgent.cpp
    harmony/enhanced/tools/trunk/minijre/native/ClassLoadTraceAgent.h
    harmony/enhanced/tools/trunk/minijre/native/Main.cpp
    harmony/enhanced/tools/trunk/minijre/script/
    harmony/enhanced/tools/trunk/minijre/script/analyze.bat
    harmony/enhanced/tools/trunk/minijre/script/analyze.cmd
    harmony/enhanced/tools/trunk/minijre/script/analyze.sh
    harmony/enhanced/tools/trunk/minijre/script/jregen.bat
    harmony/enhanced/tools/trunk/minijre/script/jregen.cmd
    harmony/enhanced/tools/trunk/minijre/script/jregen.sh
    harmony/enhanced/tools/trunk/minijre/src/
    harmony/enhanced/tools/trunk/minijre/src/org/
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/CNSFileFormatException.java
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/ClassNameSet.java
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/JreGenerator.java
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/StaticDependencyAnalyzer.java
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/anttask/
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/anttask/AnalyzeDependencyTask.java
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/anttask/GenerateJreTask.java
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/bin/
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/bin/AnalyzeDependency.java
    harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/bin/GenerateJre.java
    harmony/enhanced/tools/trunk/minijre/test/
    harmony/enhanced/tools/trunk/minijre/test/hello/
    harmony/enhanced/tools/trunk/minijre/test/hello/Hello.class   (with props)

Added: harmony/enhanced/tools/trunk/minijre/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/build.xml?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/build.xml (added)
+++ harmony/enhanced/tools/trunk/minijre/build.xml Mon Aug 17 01:43:02 2009
@@ -0,0 +1,199 @@
+<?xml version="1.0"?>
+<project name="MinJre Toolkit" default="dist">
+	
+	<property environment="env" />
+
+	<!-- build properies -->
+	<property name="src.dir" value="src" />
+	<property name="build.dir" value="build" />
+	<property name="lib.dir" value="lib" />
+	<property name="dist.dir" value="dist" />
+	<property name="native.dir" value="native" />
+	<property name="script.dir" value="script" />
+	<property name="conf.dir" value="conf" />
+
+	<!-- user properies -->
+	<property name="jdk.dir" value="${env.JAVA_HOME}" />
+	<property name="cns.dir" value="cns" />
+
+	<property name="agent.name" value="tracer" />
+	<property name="origin.dir" value="C:/java/harmony-jre" />
+	<property name="target.dir" value="C:/java/harmony-jre-min" />
+
+	<!-- test properies -->
+	<property name="test.dir" value="test" />
+	
+	<!-- os property, used for native compiling -->
+	<condition property="isWindows">    
+		<os family="windows" />   
+    </condition>
+    <condition property="isUnix"> 
+        <os family="unix" />
+    </condition>
+    <condition property="isOther">
+		<and>
+			<os family="dos" />
+			<os family="mac" />
+			<os family="netware" />
+			<os family="os 2" />
+		</and>
+    </condition>
+
+	<!-- check dependencies property, build will fail unless it is true -->
+	<!-- NOT IMPLEMENTED YET! -->
+	<!-- <condition property="all.dependencies.present">
+	</condition> -->
+
+	<!-- test unnecessary property, test will be ignored if it is true -->
+	<!-- NOT IMPLEMENTED YET! -->
+	<!-- <condition property="test.unnecessary">
+	</condition> -->
+
+	<!-- define classpath -->
+	<path id="classpath">
+		<fileset file="${lib.dir}/*.jar" />
+		<pathelement path="${build.dir}" />
+	</path>
+
+	<!-- initialize task -->
+	<target name="init">
+
+		<!-- <fail message="Missing dependencies. Building fails." unless="all.dependencies.present" /> -->
+	</target>
+
+	<target name="-compile-native-win" if="isWindows">
+		<exec dir="${native.dir}" executable="cl">
+			<arg line="/EHsc" />
+			<arg line="-I${jdk.dir}\include" />
+			<arg line="-I${jdk.dir}\include\win32" />
+			<arg line="-LD" />
+			<arg line="ClassLoadTraceAgent.cpp" />
+			<arg line="Main.cpp" />
+			<arg line="-Fe${agent.name}.dll" />
+		</exec>
+		<delete dir="${native.dir}" excludes="**\*.cpp **\*.h **\*.dll" />
+	</target>
+	
+	<target name="-compile-native-unix" if="isUnix">
+		<exec dir="${native.dir}" executable="g++">
+			<arg line="-I${jdk.dir}/include" />
+			<arg line="-I${jdk.dir}/include/linux" />
+			<arg line="ClassLoadTraceAgent.cpp" />
+			<arg line="Main.cpp" />
+			<arg line="-fPIC" />
+			<arg line="-shared" />
+			<arg line="-o lib${agent.name}.so" />
+		</exec>
+		<delete dir="${native.dir}" excludes="**\*.cpp **\*.h **\*.so" />
+	</target>
+
+	<target name="-compile-native-other" if="isOther">
+		<echo message="Dynamic tracer agent is not supported in this os and will not be included in the distribution." />
+	</target>
+
+	<target name="compile-native" depends="init, -compile-native-win, -compile-native-unix, -compile-native-other" />
+
+	<target name="compile-java" depends="init">
+		<mkdir dir="${build.dir}"/>
+		<javac srcdir="${src.dir}" destdir="${build.dir}" target="1.5">
+			<classpath refid="classpath"/>
+		</javac>
+		<mkdir dir="${build.dir}/org/crazynut/harmony/minjre/conf" />
+		<copy todir="${build.dir}/org/crazynut/harmony/minjre/conf">
+			<fileset file="${conf.dir}/*.cns" />
+		</copy>
+	</target>
+
+	<!-- compile -->
+	<target name="compile" depends="compile-native, compile-java" description="Compile the source files." />
+	
+	<!-- test the command line tool with helloworld -->
+	<target name="test-hello" depends="compile">
+    	<delete dir="${cns.dir}" />
+    	<mkdir dir="${cns.dir}" />
+		<delete dir="${target.dir}" />
+    	<mkdir dir="${target.dir}" />
+		<java classname="org.crazynut.harmony.minjre.bin.AnalyzeDependency">
+			<classpath refid="classpath"/>
+			<arg line="-jrelib=${origin.dir}/lib" />
+			<arg line="-classpath=${test.dir}/hello" />
+			<arg line="-aim=${cns.dir}/static.cns" />
+		</java>
+		<java classname="Hello" fork="true" dir="${test.dir}/hello">
+			<env key="PATH" path="${env.PATH}:${native.dir}" />
+			<env key="LD_LIBRARY_PATH" path="${env.LD_LIBRARY_PATH}:${native.dir}" />
+
+			<jvmarg line="-agentlib:${agent.name}=output=dynamic.cns" />
+		</java>
+		<copy file="${test.dir}/hello/dynamic.cns" toDir="${cns.dir}" />
+		<java classname="org.crazynut.harmony.minjre.bin.GenerateJre">
+			<classpath refid="classpath"/>
+			<arg line="-jre=harmony" />
+			<arg line="-cnspath=${cns.dir}" />
+			<arg line="-origin=${origin.dir}" />
+			<arg line="-target=${target.dir}" />
+		</java>
+    	<exec executable="${target.dir}/bin/java">
+    	    <arg line="-classpath ${test.dir}/hello Hello"/>
+    	</exec>
+	</target>
+
+	<!-- test the ant task with helloworld -->
+	
+<target name="test-task-hello" depends="compile">
+
+		<taskdef name="analyze" classname="org.crazynut.harmony.minjre.anttask.AnalyzeDependencyTask" classpath="${build.dir};${lib.dir}/bcel-5.2.jar" />
+		<taskdef name="jregen" classname="org.crazynut.harmony.minjre.anttask.GenerateJreTask" classpath="${build.dir}" />
+		<delete dir="${cns.dir}" />
+    	<mkdir dir="${cns.dir}" />
+		<delete dir="${target.dir}" />
+    	<mkdir dir="${target.dir}" />
+    	<analyze jrelib="${origin.dir}/lib" aim="${cns.dir}/static.cns">
+    		<classpath>
+				<pathelement location="${test.dir}/hello"/>
+			</classpath>
+    	</analyze>
+    	<jregen jre="harmony" origin="${origin.dir}" target="${target.dir}">
+    		<cnspath path="${cns.dir}" />
+    	</jregen>
+    	<exec executable="${target.dir}/bin/java">
+    	    <arg line="-classpath ${test.dir}/hello Hello"/>
+    	</exec>
+
+	</target>
+
+
+    <target name="test" depends="test-hello, test-task-hello" />
+	
+	<!-- create the distribution -->
+	<target name="dist" depends="test" description="Create everything for the MinJre Toolkit.">
+		<mkdir dir="${dist.dir}" />
+		<mkdir dir="${dist.dir}/bin" />
+		<copy todir="${dist.dir}/bin">
+			<fileset file="${script.dir}/*.*" />
+		</copy>
+		<mkdir dir="${dist.dir}/lib" />
+		<jar destfile="${dist.dir}/lib/minjre.jar" basedir="${build.dir}" />
+		<copy file="${lib.dir}/bcel-5.2.jar" todir="${dist.dir}/lib" />
+		<mkdir dir="${dist.dir}/agent" />
+		<copy todir="${dist.dir}/agent">
+			<fileset file="${native.dir}/*.so" />
+			<fileset file="${native.dir}/*.dll" />
+		</copy>
+		<mkdir dir="${dist.dir}/doc" />
+		<javadoc destdir="${dist.dir}/doc" author="true" version="true" use="true" windowtitle="MinJre Toolkit API">
+			<packageset dir="${src.dir}" defaultexcludes="yes" />
+			<doctitle><![CDATA[<h1>MinJre Toolkit API</h1>]]></doctitle>
+			<bottom><![CDATA[<i>Auther Daniel Gong.</i>]]></bottom>
+			<tag name="todo" scope="all" description="To do:" />
+		</javadoc>
+	</target>
+	
+	<target name="clean" description="Restore the project directory.">
+		<delete dir="${build.dir}" />
+		<delete dir="${cns.dir}" />
+		<delete dir="${dist.dir}" />
+		<delete dir="${native.dir}" excludes="**\*.cpp **\*.h" />
+	</target>
+
+</project>

Added: harmony/enhanced/tools/trunk/minijre/conf/harmony.cns
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/conf/harmony.cns?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/conf/harmony.cns (added)
+++ harmony/enhanced/tools/trunk/minijre/conf/harmony.cns Mon Aug 17 01:43:02 2009
@@ -0,0 +1,332 @@
+Class Name Set File
+
+java.lang.Object
+java.io.Serializable
+java.lang.reflect.AnnotatedElement
+java.lang.reflect.GenericDeclaration
+java.lang.reflect.Type
+java.lang.Class
+java.lang.Cloneable
+java.lang.Comparable
+java.lang.CharSequence
+java.lang.String
+org.apache.harmony.kernel.vm.VM
+java.lang.Throwable
+java.lang.StackTraceElement
+java.lang.Error
+java.lang.LinkageError
+java.lang.ExceptionInInitializerError
+java.lang.NoClassDefFoundError
+java.lang.Exception
+java.lang.ClassNotFoundException
+java.lang.RuntimeException
+java.lang.NullPointerException
+java.lang.VirtualMachineError
+java.lang.StackOverflowError
+java.lang.IndexOutOfBoundsException
+java.lang.ArrayIndexOutOfBoundsException
+java.lang.ArrayStoreException
+java.lang.ArithmeticException
+java.lang.ClassCastException
+java.lang.OutOfMemoryError
+java.lang.InternalError
+java.lang.ThreadDeath
+java.lang.IllegalMonitorStateException
+java.lang.IncompatibleClassChangeError
+java.util.Comparator
+java.lang.String$CaseInsensitiveComparator
+org.apache.harmony.kernel.vm.InternMap
+java.lang.ref.Reference
+java.lang.ref.WeakReference
+org.apache.harmony.kernel.vm.InternMap$Entry
+java.lang.ref.ReferenceQueue
+java.lang.Runnable
+java.lang.Thread
+java.lang.Thread$UncaughtExceptionHandler
+java.lang.ThreadGroup
+java.lang.Iterable
+java.util.Collection
+java.util.AbstractCollection
+java.util.List
+java.util.AbstractList
+java.util.AbstractSequentialList
+java.util.Queue
+java.util.LinkedList
+java.util.Date
+java.util.Dictionary
+java.util.Map
+java.util.Hashtable
+java.util.Properties
+java.lang.Runtime
+java.lang.reflect.AccessibleObject
+java.lang.reflect.Member
+java.lang.reflect.Constructor
+java.lang.reflect.Field
+java.lang.reflect.Method
+org.apache.harmony.vm.VMStack
+java.lang.VMClassRegistry
+java.lang.VMExecutionEngine
+java.util.RandomAccess
+java.util.Vector
+java.lang.Enum
+java.io.Externalizable
+java.lang.annotation.Annotation
+java.lang.annotation.Inherited
+java.lang.Boolean
+java.lang.Number
+java.lang.Byte
+java.lang.Character
+java.lang.Short
+java.lang.Integer
+java.lang.Long
+java.lang.Float
+java.lang.Double
+java.lang.IllegalArgumentException
+java.lang.IllegalStateException
+java.lang.AbstractStringBuilder
+java.lang.Appendable
+java.lang.StringBuilder
+java.lang.System
+java.io.Closeable
+java.io.Flushable
+java.io.OutputStream
+java.io.FilterOutputStream
+java.io.PrintStream
+java.io.Writer
+java.io.PrintWriter
+java.lang.StringBuffer
+java.io.IOException
+java.io.DataOutput
+java.io.ObjectOutput
+java.io.ObjectStreamConstants
+java.io.ObjectOutputStream
+org.apache.harmony.drlvm.VMHelper
+org.vmmagic.pragma.Inline
+org.apache.harmony.drlvm.thread.ThreadHelper
+org.apache.harmony.drlvm.VMHelperFastPath
+org.apache.harmony.drlvm.gc_gen.GCHelper
+java.io.BufferedOutputStream
+java.io.FileOutputStream
+java.io.FileDescriptor
+org.apache.harmony.luni.platform.Platform
+org.apache.harmony.luni.platform.IFileSystem
+org.apache.harmony.luni.platform.OSFileSystem
+org.apache.harmony.luni.platform.IMemorySystem
+org.apache.harmony.luni.platform.OSMemory
+org.apache.harmony.luni.platform.Endianness
+org.apache.harmony.luni.platform.INetworkSystem
+org.apache.harmony.luni.platform.OSNetworkSystem
+org.apache.harmony.nio.FileChannelFactory
+java.nio.channels.Channel
+java.nio.channels.InterruptibleChannel
+java.nio.channels.spi.AbstractInterruptibleChannel
+java.nio.channels.WritableByteChannel
+java.nio.channels.GatheringByteChannel
+java.nio.channels.ReadableByteChannel
+java.nio.channels.ScatteringByteChannel
+java.nio.channels.ByteChannel
+java.nio.channels.FileChannel
+org.apache.harmony.nio.internal.FileChannelImpl
+org.apache.harmony.nio.internal.WriteOnlyFileChannel
+java.security.PrivilegedActionException
+java.security.PrivilegedExceptionAction
+java.nio.channels.spi.AbstractInterruptibleChannel$1
+java.security.AccessController
+java.util.AbstractMap
+java.util.WeakHashMap
+java.util.Map$Entry
+java.util.WeakHashMap$Entry
+java.lang.VMThreadManager
+java.lang.Class$ReflectionData
+org.apache.harmony.lang.reflect.ReflectAccessor
+java.lang.reflect.ReflectExporter
+org.apache.harmony.lang.reflect.Reflection
+java.lang.reflect.Method$MethodData
+java.lang.NoSuchMethodException
+java.lang.VMMemoryManager
+java.io.ObjectStreamField
+org.apache.harmony.nio.internal.LockManager
+org.apache.harmony.nio.internal.LockManager$1
+java.util.Set
+java.util.AbstractSet
+java.util.SortedSet
+java.util.TreeSet
+java.util.SortedMap
+java.util.TreeMap
+org.apache.harmony.nio.internal.FileChannelImpl$RepositioningLock
+java.security.PrivilegedAction
+org.apache.harmony.luni.util.PriviAction
+java.util.Enumeration
+java.util.Hashtable$1
+java.util.Iterator
+java.util.Hashtable$2
+java.util.MapEntry
+java.util.Hashtable$Entry
+java.io.InputStream
+java.io.FilterInputStream
+java.io.BufferedInputStream
+java.io.FileInputStream
+java.io.FileInputStream$RepositioningLock
+org.apache.harmony.nio.internal.ReadOnlyFileChannel
+java.util.ArrayList
+java.lang.UnsatisfiedLinkError
+java.lang.ThreadGroup$ThreadGroupLock
+java.util.LinkedList$Link
+java.lang.ThreadWeakRef
+java.security.ProtectionDomain
+java.lang.reflect.VMReflection
+java.security.AccessControlContext
+org.apache.harmony.security.fortress.SecurityUtils
+java.lang.FinalizerThread
+java.lang.FinalizerThread$FinalizerWorkLock
+java.lang.FinalizerThread$FinalizerWaitFinishLock
+java.lang.ClassLoader
+java.security.cert.Certificate
+java.security.SecureClassLoader
+java.net.URLClassLoader
+java.lang.ClassLoader$SystemClassLoader
+java.net.MalformedURLException
+java.io.File
+org.apache.harmony.luni.util.Util
+java.io.UnsupportedEncodingException
+java.nio.charset.IllegalCharsetNameException
+java.nio.charset.UnsupportedCharsetException
+java.nio.charset.Charset
+java.util.HashMap
+java.util.HashMap$Entry
+java.nio.charset.Charset$1
+java.nio.charset.spi.CharsetProvider
+org.apache.harmony.niochar.CharsetProviderImpl
+java.security.Guard
+java.security.Permission
+java.security.BasicPermission
+java.lang.RuntimePermission
+java.util.Collections
+java.util.Collections$EmptyList
+java.util.Collections$EmptySet
+java.util.Collections$EmptyMap
+java.util.Collections$SynchronizedMap
+java.util.Locale
+com.ibm.icu.util.ULocale
+com.ibm.icu.impl.ICUCache
+com.ibm.icu.impl.SimpleCache
+java.lang.ref.SoftReference
+com.ibm.icu.util.ULocale$IDParser
+com.ibm.icu.util.ULocale$Type
+java.util.PropertyPermission
+java.util.StringTokenizer
+org.apache.harmony.niochar.CharsetProviderImpl$1
+org.apache.harmony.niochar.charset.UTF_8
+java.lang.reflect.Constructor$ConstructorData
+java.lang.reflect.Modifier
+java.util.HashSet
+java.util.Collections$UnmodifiableCollection
+java.util.Collections$UnmodifiableSet
+java.util.Collections$UnmodifiableCollection$1
+java.util.HashMap$1
+java.util.HashMap$AbstractMapIterator
+java.util.HashMap$KeyIterator
+java.nio.Buffer
+java.lang.Readable
+java.nio.CharBuffer
+java.nio.BufferFactory
+java.nio.CharArrayBuffer
+java.nio.ReadWriteCharArrayBuffer
+java.nio.charset.CharacterCodingException
+java.nio.charset.CharsetEncoder
+org.apache.harmony.niochar.charset.UTF_8$Encoder
+java.nio.charset.CodingErrorAction
+java.nio.charset.CharsetDecoder
+org.apache.harmony.niochar.charset.UTF_8$Decoder
+java.nio.ByteBuffer
+java.nio.BaseByteBuffer
+java.nio.HeapByteBuffer
+java.nio.ReadWriteHeapByteBuffer
+java.nio.BufferOverflowException
+java.nio.BufferUnderflowException
+java.nio.charset.CoderResult
+java.net.URISyntaxException
+java.net.URI
+java.net.URIEncoderDecoder
+java.net.URI$Helper
+java.lang.NumberFormatException
+java.net.URL
+java.net.NetPermission
+java.lang.IllegalAccessException
+java.lang.InstantiationException
+java.net.URLStreamHandler
+org.apache.harmony.luni.internal.net.www.protocol.file.Handler
+java.lang.SecurityException
+java.lang.reflect.InvocationTargetException
+java.lang.Class$1
+java.util.Collections$SynchronizedCollection
+java.util.Collections$SynchronizedList
+java.util.Collections$SynchronizedRandomAccessList
+org.apache.harmony.luni.internal.net.www.protocol.jar.Handler
+java.lang.VMStart
+java.lang.EMThreadSupport
+java.lang.EMThreadSupport$1
+java.lang.InterruptedException
+java.lang.VMStart$DefaultShutDownHook
+java.lang.Thread$State
+java.util.Hashtable$HashIterator
+java.util.Hashtable$HashEnumIterator
+java.util.MapEntry$Type
+java.util.Hashtable$5
+org.apache.harmony.niochar.charset.ISO_8859_1
+org.apache.harmony.niochar.charset.ISO_8859_1$Decoder
+java.net.URLClassLoader$4
+java.net.URLConnection
+java.net.JarURLConnection
+org.apache.harmony.luni.internal.net.www.protocol.jar.JarURLConnection
+java.net.ContentHandler
+java.net.URLConnection$DefaultContentHandler
+org.apache.harmony.luni.internal.net.www.protocol.file.FileURLConnection
+java.util.zip.ZipConstants
+java.util.zip.ZipFile
+java.util.jar.JarFile
+java.util.zip.ZipEntry
+java.util.zip.ZipFile$ZFEnum
+java.util.jar.JarVerifier
+org.apache.harmony.archive.util.Util
+java.io.ByteArrayInputStream
+java.net.URLClassLoader$URLHandler
+java.net.URLClassLoader$URLJarHandler
+java.util.jar.Manifest
+java.util.jar.Attributes$Name
+java.util.jar.Attributes
+java.lang.UnsupportedOperationException
+org.apache.harmony.luni.util.InputStreamExposer
+org.apache.harmony.luni.util.InputStreamExposer$1
+java.lang.NoSuchFieldException
+java.lang.reflect.Field$FieldData
+org.apache.harmony.luni.util.ExposedByteArrayInputStream
+java.lang.reflect.VMField
+java.util.jar.InitManifest
+org.apache.harmony.luni.util.ThreadLocalCache
+org.apache.harmony.luni.util.ThreadLocalCache$1
+org.apache.harmony.luni.util.ThreadLocalCache$2
+org.apache.harmony.luni.util.ThreadLocalCache$3
+org.apache.harmony.luni.util.ThreadLocalCache$4
+java.lang.ThreadLocal
+org.apache.harmony.luni.util.ThreadLocalCache$5
+java.util.concurrent.atomic.AtomicInteger
+sun.misc.Unsafe
+org.apache.harmony.util.concurrent.Atomics
+java.lang.ThreadLocal$Values
+java.util.jar.Manifest$Chunk
+java.net.URLClassLoader$URLFileHandler
+java.io.FileNotFoundException
+java.net.URLDecoder
+java.io.ByteArrayOutputStream
+java.security.CodeSource
+java.security.PermissionCollection
+java.security.Permissions
+java.io.FilePermission
+java.io.FilePermission$1
+java.io.FilePermissionCollection
+java.security.AllPermission
+org.apache.harmony.lang.RuntimePermissionCollection
+java.security.BasicPermissionCollection
+java.util.AbstractList$SimpleListIterator
+org.apache.harmony.niochar.charset.*
\ No newline at end of file

Added: harmony/enhanced/tools/trunk/minijre/native/ClassLoadTraceAgent.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/native/ClassLoadTraceAgent.cpp?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/native/ClassLoadTraceAgent.cpp (added)
+++ harmony/enhanced/tools/trunk/minijre/native/ClassLoadTraceAgent.cpp Mon Aug 17 01:43:02 2009
@@ -0,0 +1,94 @@
+#include <string>
+#include <string.h>
+
+#include "ClassLoadTraceAgent.h"
+
+using namespace std;
+
+jvmtiEnv* ClassLoadTraceAgent::m_jvmti = 0;
+char* ClassLoadTraceAgent::m_option = 0;
+ofstream* ClassLoadTraceAgent::out = 0;
+
+ClassLoadTraceAgent::~ClassLoadTraceAgent() throw(AgentException)
+{
+    // Free allocated memory
+    m_jvmti->Deallocate(reinterpret_cast<unsigned char*>(m_option));
+	out->close();
+}
+
+void ClassLoadTraceAgent::Init(JavaVM *vm) const throw(AgentException){
+    jvmtiEnv *jvmti = 0;
+	jint ret = (vm)->GetEnv(reinterpret_cast<void**>(&jvmti), JVMTI_VERSION_1_0);
+	if (ret != JNI_OK || jvmti == 0) {
+		throw AgentException(JVMTI_ERROR_INTERNAL);
+	}
+	m_jvmti = jvmti;
+}
+
+bool ClassLoadTraceAgent::ParseOptions(const char* str) const throw(AgentException)
+{
+    if (str == 0)
+        return false;
+	const size_t len = strlen(str);
+	if (len == 0) 
+		return false;
+
+  	// Copy str to m_filepath
+	jvmtiError error;
+    error = m_jvmti->Allocate(len + 1,reinterpret_cast<unsigned char**>(&m_option));
+	CheckException(error);
+    strcpy(m_option, str);
+	if (strcmp(m_option, "help") == 0) {
+		cout << "Usage: java -agentlib:tracer=[help]|[output=filename]" << endl;
+		return false;
+	}
+	string option(m_option);
+	out = new ofstream(option.substr(option.find('=') + 1).c_str());
+	if (!out->is_open()) {
+		throw AgentException(JVMTI_ERROR_INTERNAL);
+	}
+	
+	*out << "Class Name Set File\n" << endl;
+	return true;
+}
+  
+void ClassLoadTraceAgent::RegisterEvent() const throw(AgentException)
+{
+    // Create a new callback
+    jvmtiEventCallbacks callbacks;
+    memset(&callbacks, 0, sizeof(callbacks));
+    callbacks.ClassLoad = &ClassLoadTraceAgent::HandleClassLoad;
+    
+    // Set callback
+    jvmtiError error;
+    error = m_jvmti->SetEventCallbacks(&callbacks, static_cast<jint>(sizeof(callbacks)));
+	CheckException(error);
+
+	// Set event notification mode
+	error = m_jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD, 0);
+	CheckException(error);
+}
+
+void JNICALL ClassLoadTraceAgent::HandleClassLoad(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jclass klass)
+{
+	try {
+        jvmtiError error;
+		char* signature;
+        
+        // Get class signature
+        error = m_jvmti->GetClassSignature(klass, &signature, 0);
+        CheckException(error);
+		
+		transform(signature);
+		
+		*out << signature << endl;
+
+        error = m_jvmti->Deallocate(reinterpret_cast<unsigned char*>(signature));
+		CheckException(error);
+
+	} catch (AgentException& e) {
+		cout << "Error when enter HandleMethodEntry: " << e.what() << " [" << e.ErrCode() << "]";
+    }
+}
+
+

Added: harmony/enhanced/tools/trunk/minijre/native/ClassLoadTraceAgent.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/native/ClassLoadTraceAgent.h?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/native/ClassLoadTraceAgent.h (added)
+++ harmony/enhanced/tools/trunk/minijre/native/ClassLoadTraceAgent.h Mon Aug 17 01:43:02 2009
@@ -0,0 +1,72 @@
+#include <iostream>
+#include <fstream>
+#include <string>
+
+#include "jvmti.h"
+
+using namespace std;
+
+class AgentException 
+{
+ public:
+	AgentException(jvmtiError err) {
+		m_error = err;
+	}
+
+	const char* what() const throw() { 
+		return "AgentException";
+	}
+
+	jvmtiError ErrCode() const throw() {
+		return m_error;
+	}
+
+ private:
+	jvmtiError m_error;
+};
+
+
+class ClassLoadTraceAgent 
+{
+ public:
+
+	ClassLoadTraceAgent() throw(AgentException){}
+
+	~ClassLoadTraceAgent() throw(AgentException);
+
+	void Init(JavaVM *vm) const throw(AgentException);
+        
+	bool ParseOptions(const char* str) const throw(AgentException);
+        
+	void RegisterEvent() const throw(AgentException);
+    
+	static void JNICALL HandleClassLoad(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jclass klass);
+
+ private:
+	
+	static void transform(char *sig) {
+		int i = 0;
+		while (sig[i] != '\0') {
+			if (sig[i+1] == '/')
+				sig[i] = '.';
+			else
+				sig[i] = sig[i + 1];
+			i++;
+		}
+		sig[i-2] = '\0';
+	}
+	 
+	static void CheckException(jvmtiError error) throw(AgentException)
+	{
+		if (error != JVMTI_ERROR_NONE) {
+			throw AgentException(error);
+		}
+	}
+    
+	static jvmtiEnv* m_jvmti;
+	
+	static char* m_option;
+	
+	static ofstream* out;
+	
+};

Added: harmony/enhanced/tools/trunk/minijre/native/Main.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/native/Main.cpp?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/native/Main.cpp (added)
+++ harmony/enhanced/tools/trunk/minijre/native/Main.cpp Mon Aug 17 01:43:02 2009
@@ -0,0 +1,28 @@
+#include "ClassLoadTraceAgent.h"
+
+using namespace std;
+
+JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
+{
+    try{
+        bool flag;
+        ClassLoadTraceAgent* agent = new ClassLoadTraceAgent();
+		agent->Init(vm);
+        flag = agent->ParseOptions(options);
+
+		if (flag == false) {
+
+			return JNI_OK;
+
+		}
+        agent->RegisterEvent();
+        
+    } catch (AgentException& e) {
+        cout << "Error when enter HandleMethodEntry: " << e.what() << " [" << e.ErrCode() << "]";
+		return JNI_ERR;
+	}
+    
+	return JNI_OK;
+}
+
+JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm) {}

Added: harmony/enhanced/tools/trunk/minijre/script/analyze.bat
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/script/analyze.bat?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/script/analyze.bat (added)
+++ harmony/enhanced/tools/trunk/minijre/script/analyze.bat Mon Aug 17 01:43:02 2009
@@ -0,0 +1 @@
+@java -Xms128m -Xmx256m -classpath %~dp0\..\lib\minjre.jar;%~dp0\..\lib\bcel-5.2.jar org.crazynut.harmony.minjre.bin.AnalyzeDependency %*
\ No newline at end of file

Added: harmony/enhanced/tools/trunk/minijre/script/analyze.cmd
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/script/analyze.cmd?rev=804823&view=auto
==============================================================================
    (empty)

Added: harmony/enhanced/tools/trunk/minijre/script/analyze.sh
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/script/analyze.sh?rev=804823&view=auto
==============================================================================
    (empty)

Added: harmony/enhanced/tools/trunk/minijre/script/jregen.bat
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/script/jregen.bat?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/script/jregen.bat (added)
+++ harmony/enhanced/tools/trunk/minijre/script/jregen.bat Mon Aug 17 01:43:02 2009
@@ -0,0 +1 @@
+@java -Xms128m -Xmx256m -classpath %~dp0\..\lib\minjre.jar org.crazynut.harmony.minjre.bin.GenerateJre %*
\ No newline at end of file

Added: harmony/enhanced/tools/trunk/minijre/script/jregen.cmd
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/script/jregen.cmd?rev=804823&view=auto
==============================================================================
    (empty)

Added: harmony/enhanced/tools/trunk/minijre/script/jregen.sh
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/script/jregen.sh?rev=804823&view=auto
==============================================================================
    (empty)

Added: harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/CNSFileFormatException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/CNSFileFormatException.java?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/CNSFileFormatException.java (added)
+++ harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/CNSFileFormatException.java Mon Aug 17 01:43:02 2009
@@ -0,0 +1,19 @@
+package org.crazynut.harmony.minjre;
+
+/** 
+ * Thrown when trying to read a .cns file and determines
+ * that the file is malformed or otherwise cannot be interpreted as a
+ * class name set file.
+ *
+ * @author  <A HREF="mailto:daniel.gong.fudan@gmail.com">Ling-Hui Gong</A>
+ */
+public class CNSFileFormatException extends RuntimeException {
+    
+	public CNSFileFormatException() {
+        super();
+    }
+
+    public CNSFileFormatException(String s) {
+        super(s);
+    }
+}

Added: harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/ClassNameSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/ClassNameSet.java?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/ClassNameSet.java (added)
+++ harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/ClassNameSet.java Mon Aug 17 01:43:02 2009
@@ -0,0 +1,298 @@
+package org.crazynut.harmony.minjre;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.HashMap;
+import java.util.regex.Pattern;
+
+/**
+ * The data structure designed to contain a set of class & pack names 
+ * and support fast class name retrieval. <p>
+ * The data structure is associated with a type of file with the suffix 
+ * of .cns, which contains a list of class & pack names. The format of
+ * cns file is as following: <p>
+ * =======================<p>
+ * &nbspClass Name Set File<p>
+ *
+ * &nbspjava.io.File<p>
+ * &nbspjava.util.HashMap<p>
+ * &nbspjava.lang.*<p>
+ * &nbsp.................<p>
+ * =======================<p>
+ * 
+ * @author  <A HREF="mailto:daniel.gong.fudan@gmail.com">Ling-Hui Gong</A>
+ */
+public class ClassNameSet {
+	
+	/**
+	 * The class name set.
+	 */
+	private HashMap<String, Object> classSet;
+	
+	/**
+	 * The package list.
+	 */
+	private LinkedList<String> packList;
+	
+	/**
+	 * The class name pattern.
+	 */
+	private static Pattern classNamePattern = 
+		Pattern.compile("([a-z0-9]+\\.)*[A-Z][a-zA-Z0-9_]*(\\$[a-zA-Z0-9][a-zA-Z0-9_]*)*(\\$[1-9][0-9]*)*");
+	
+	/**
+	 * The package name pattern.
+	 */
+	private static Pattern packNamePatter = 
+		Pattern.compile("([a-z0-9]+\\.)+\\*");
+	
+	/**
+	 * Decide whether the name is a valid class name.
+	 * 
+	 * @param name name
+	 * @return True if the name is a valid class name
+	 */
+	private boolean isClassName(String name) {
+		return classNamePattern.matcher(name).matches();
+	}
+	
+	/**
+	 * Decide whether the name is a valid package name.
+	 * 
+	 * @param name name
+	 * @return True if the name is a valid package name
+	 */
+	private boolean isPackName(String name) {
+		return packNamePatter.matcher(name).matches();
+	}
+	
+	/**
+	 * Add a package name to the list.<p>
+	 * If there are some package that covers the package, 
+	 * it will not be added to the list; if there are some
+	 * package covered by the package, it will be added and
+	 * replace the covered one.
+	 * 
+	 * @param packName
+	 */
+	private void addPack(String packName) {
+		Iterator<String> i = packList.iterator();
+		while (i.hasNext()) {
+			String pack = i.next();
+			if (packName.equals(pack)) {
+				return;
+			}
+		}
+		packList.add(packName);
+	}
+	
+	/**
+	 * Create new empty class name set.
+	 */
+	public ClassNameSet() {
+		classSet = new HashMap<String, Object>();
+		packList = new LinkedList<String>();
+	}
+	
+	public ClassNameSet(InputStream is) throws IOException, CNSFileFormatException {
+		this();
+		BufferedReader in = new BufferedReader(new InputStreamReader(is));
+		String newLine;
+		if (!(newLine = in.readLine()).equals("Class Name Set File")) {
+			in.close();
+			throw new CNSFileFormatException("The type of jre does not have a valid cns file.");
+		} else {
+			newLine = in.readLine();
+			while (newLine != null) {
+				// Ignore the empty lines
+				while (newLine != null && newLine.equals("\n")) {
+					newLine = in.readLine();
+				}
+				addName(newLine);
+				newLine = in.readLine();
+			}
+			in.close();
+		}
+	}
+
+	/**
+	 * Create new class name set from the given file.
+	 * 
+	 * @param file The java.io.File instance of the file
+	 * @throws FileNotFoundException
+	 * @throws IOException
+	 * @throws CNSFileFormatException
+	 */
+	public ClassNameSet(File file) throws FileNotFoundException, IOException, CNSFileFormatException {
+		this();
+		if (null == file) {
+			return;
+		}
+		if (file.exists() && file.isFile()) {
+			BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
+			String newLine;
+			if (!(newLine = in.readLine()).equals("Class Name Set File")) {
+				in.close();
+				throw new CNSFileFormatException("The file " + 
+						file.getPath() + " cannot be interpreted as a csn file.");
+			} else {
+				newLine = in.readLine();
+				while (newLine != null) {
+					// Ignore the empty lines
+					while (newLine != null && newLine.equals("\n")) {
+						newLine = in.readLine();
+					}
+					addName(newLine);
+					newLine = in.readLine();
+				}
+				in.close();
+			}
+		} else {
+			throw new FileNotFoundException("The file " + 
+					file.getPath() + " does not exist.");
+		}	
+	}
+	
+	/**
+	 * Create new class name set from the file at the given path.
+	 * 
+	 * @param fileName The path of the file
+	 * @throws FileNotFoundException
+	 * @throws IOException
+	 * @throws CNSFileFormatException
+	 */
+	public ClassNameSet(String fileName) throws FileNotFoundException, IOException, CNSFileFormatException {
+		this(null == fileName ? (File) null : new File(fileName));
+	}
+	
+	/**
+	 * Output the class name set to a cns file.
+	 * 
+	 * @param file The java.io.File instance of the file
+	 * @throws FileNotFoundException 
+	 */
+	public void toClassListFile(File file) throws FileNotFoundException, IOException {
+		if (null == file) {
+			return;
+		}
+		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
+		out.write("Class Name Set File\n\n");
+		Iterator<String> i = classSet.keySet().iterator();
+		while (i.hasNext()) {
+			out.write(i.next() + "\n");
+		}
+		i = packList.iterator();
+		while (i.hasNext()) {
+			out.write(i.next() + "\n");
+		}
+		out.close();
+	}
+	
+	/**
+	 * Output the class name set to a cns file.
+	 * 
+	 * @param fileName The path of the file
+	 * @throws IOException 
+	 * @throws FileNotFoundException 
+	 */
+	public void toClassListFile(String fileName) throws FileNotFoundException, IOException {
+		toClassListFile(new File(fileName));
+	}
+	
+	/**
+	 * Add a name (class or package) to the class name set.<p>
+	 * If the name exists in the set or covered by some 
+	 * package in the set, it will not be added.
+	 * 
+	 * @param name The name to add
+	 */
+	public void addName(String name) {
+		// If the newline is a package name
+		if (isPackName(name)) {
+			addPack(name);
+		} else if (isClassName(name)){
+			classSet.put(name, null);
+		}
+	}
+	
+	/**
+	 * Merge another class name set to the current set.
+	 * 
+	 * @param anotherSet
+	 */
+	public void merge(ClassNameSet anotherSet) {
+		classSet.putAll(anotherSet.classSet);
+		Iterator<String> i = anotherSet.packList.iterator();
+		while (i.hasNext()) {
+			String newPack = i.next();
+			Iterator<String> j = packList.iterator();
+			while (j.hasNext()) {
+				if (newPack.equals(j.next())) {
+					i.remove();
+					break;
+				}
+			}
+		}
+		packList.addAll(anotherSet.packList);
+	}
+	
+	/**
+	 * Merge another class name set to the current set.
+	 * 
+	 * @param file The java.io.File instance of the file 
+	 * that contains the class name set
+	 * @throws IOException 
+	 * @throws CNSFileFormatException 
+	 * @throws FileNotFoundException 
+	 */
+	public void merge(File file) throws FileNotFoundException, CNSFileFormatException, IOException {
+		merge(new ClassNameSet(file));
+	}
+	
+	/**
+	 * Merge another class name set to the current set.
+	 * 
+	 * @param fileName The path of the file 
+	 * that contains the class name set
+	 * @throws IOException 
+	 * @throws CNSFileFormatException 
+	 * @throws FileNotFoundException 
+	 */
+	public void merge(String fileName) throws FileNotFoundException, CNSFileFormatException, IOException {
+		merge(null == fileName ? (File) null : new File(fileName));
+	}
+	
+	/**
+	 * Decide whether a class name exists in the set.
+	 * 
+	 * @param className The class name
+	 * @return True if the class name exists
+	 */
+	public boolean isClassIn(String className) {
+		if (false == isClassName(className)) {
+			return false;
+		}
+		if (classSet.containsKey(className)) {
+			return true;
+		}
+		Iterator<String> i = packList.iterator();
+		while (i.hasNext()) {
+			String packName = i.next();
+			if (packName.substring(0, packName.lastIndexOf('*'))
+					.equals(className.substring(0, className.lastIndexOf('.') + 1))) {
+				return true;
+			}
+		}
+		return false;
+	}
+}

Added: harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/JreGenerator.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/JreGenerator.java?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/JreGenerator.java (added)
+++ harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/JreGenerator.java Mon Aug 17 01:43:02 2009
@@ -0,0 +1,312 @@
+package org.crazynut.harmony.minjre;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
+import java.util.Iterator;
+import java.util.Vector;
+import java.util.HashMap;
+import java.util.Enumeration;
+import java.util.Map.Entry;
+import java.util.jar.JarFile;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+/**
+ * The minimum JRE generator, which generate a new JRE
+ * from a complete JRE according to a reserved class list.
+ * 
+ * @author  <A HREF="mailto:daniel.gong.fudan@gmail.com">Ling-Hui Gong</A>
+ */
+public class JreGenerator {
+	
+	/**
+	 * The class set which should be reserved in jre.
+	 */
+	private ClassNameSet reservedClasses = null;
+	
+	/**
+	 * The length of the buffer used in jar file IO.
+	 */
+	private static final int BUFF_LEN = 1024;
+	
+	/**
+	 * Repack jar file according to the reserved class list.
+	 * 
+	 * @param fromPath the origin jar file path
+	 * @param toPath the new jar file path
+	 */
+	private void repackJar(final String fromPath, final String toPath) {
+		int count = 0;
+		HashMap<String, Boolean> isDirEmpty = new HashMap<String, Boolean>(); 
+		Vector<JarEntry> entryList = new Vector<JarEntry>();
+		try {
+			JarFile jar = new JarFile(fromPath);
+			Enumeration<JarEntry> entries = jar.entries();
+			while (entries.hasMoreElements()) {
+				JarEntry entry = (JarEntry) entries.nextElement();
+				if (entry.getName().endsWith(".class")) {
+					String classFileName = entry.getName().replace('/', '.');
+					String className = classFileName.substring(0,
+							classFileName.lastIndexOf('.'));
+					if (!reservedClasses.isClassIn(className)) {
+						continue;
+					} else {
+						count++;
+					}
+				}
+				if (entry.isDirectory()) {
+					Boolean isEmpty = Boolean.TRUE;
+					Iterator<JarEntry> i = entryList.iterator();
+					while (i.hasNext()) {
+						JarEntry temp = i.next();
+						if (!temp.isDirectory() 
+								&& temp.getName().startsWith(entry.getName())) {
+							isEmpty = Boolean.FALSE;
+						}
+					}
+					isDirEmpty.put(entry.getName(), isEmpty);
+				} else {
+					entryList.add(entry);
+					Iterator<Entry<String, Boolean>> i = 
+						isDirEmpty.entrySet().iterator();
+					while (i.hasNext()) {
+						Entry<String, Boolean> dirEntry = i.next();
+						String dirName = dirEntry.getKey();
+						if (entry.getName().startsWith(dirName) 
+							&& isDirEmpty.containsKey(dirName) 
+							&& isDirEmpty.get(dirName).equals(Boolean.TRUE)) {
+							isDirEmpty.put(dirName, Boolean.FALSE);
+						}
+					}
+				}
+			}
+			if (count != 0 && isDirEmpty.containsValue(Boolean.FALSE)) {
+				int byteRead = 0;
+				byte[] buffer = new byte[BUFF_LEN];
+				Iterator<JarEntry> i = entryList.iterator();
+				JarOutputStream out = 
+					new JarOutputStream(new FileOutputStream(toPath));
+				while (i.hasNext()) {
+					JarEntry temp = i.next();
+					if (temp.isDirectory() && isDirEmpty.get(temp.getName())
+							.equals(Boolean.TRUE)) {
+						continue;
+					}
+					InputStream in = jar.getInputStream(temp);
+					//out.putNextEntry(temp);
+
+					JarEntry newTemp = new JarEntry(temp);
+
+					newTemp.setCompressedSize(-1);
+					out.putNextEntry(newTemp);
+					while ((byteRead = in.read(buffer)) != -1) {
+						out.write(buffer, 0, byteRead);
+					}
+					in.close();
+					out.flush();
+					out.closeEntry();
+				}
+				out.close();
+			}
+		} catch (IOException e) {
+			System.err.println("Repacking from " + fromPath 
+					+ " to " + toPath + " fails with IO problem.");
+			e.printStackTrace();
+		}
+	}
+	
+	/**
+	 * Copy directory to another place.
+	 * 
+	 * @param fromPath the origin directory path
+	 * @param toPath the aim directory path
+	 * @param jarNeedRepack set true if jar files
+	 *  in the directory need repacking
+	 * @throws Exception Throws when the directory toPath cannot be created
+	 */
+	private void copyDirectory(final String fromPath, 
+			final String toPath, final boolean jarNeedRepack) throws Exception {
+		if (!(new File(toPath).mkdirs())) {
+			throw new Exception("Directory " + toPath 
+					+ "cannot be created. JRE generation fails.");
+		}
+		File[] fileList = new File(fromPath).listFiles();
+		for (int i = 0; i < fileList.length; i++) {
+			if (fileList[i].isFile() 
+				&& !fileList[i].getName().endsWith("-src.jar") 
+				&& !fileList[i].getName().equals("luni-kernel-stubs.jar")) {
+				if (jarNeedRepack && fileList[i].getName().endsWith("jar")) {
+					repackJar(fileList[i].getAbsolutePath(), 
+							toPath + File.separator + fileList[i].getName());
+				} else {
+					copyFile(fileList[i].getAbsolutePath(), 
+							toPath + File.separator + fileList[i].getName());
+				}
+			} else if (fileList[i].isDirectory()) {
+				copyDirectory(fileList[i].getAbsolutePath(), 
+						toPath + File.separator + fileList[i].getName(), 
+						jarNeedRepack);
+			}
+		}
+	}
+	
+	/**
+	 * Copy file to another place.
+	 * 
+	 * @param fromPath the origin file path
+	 * @param toPath the aim file path
+	 */
+	private void copyFile(final String fromPath, final String toPath) {
+        try {
+        	int byteread = 0;
+            byte[] buffer = new byte[BUFF_LEN];
+        	InputStream in = new FileInputStream(fromPath);
+            OutputStream out = new FileOutputStream(toPath);
+            while ((byteread = in.read(buffer)) != -1) {
+            	out.write(buffer, 0, byteread);
+            }
+            in.close();
+            out.close();
+        } catch (IOException e) {
+        	System.err.println("IO problem encountered when trying copy file " 
+        			+ fromPath + " to " + toPath + ".");
+            e.printStackTrace();
+        } 
+	}
+	
+	/**
+	 * Constructor.
+	 * 
+	 * @param jre the jre type
+	 *
+	 */
+	public JreGenerator(final String jre) {
+		try {
+			reservedClasses = new ClassNameSet(this.getClass().getResourceAsStream("conf/" + jre + ".cns"));
+		} catch (CNSFileFormatException e) {
+			System.err.println("This type of jre does not has a valid cns file.");
+			e.printStackTrace();
+		} catch (IOException e) {
+			System.err.println("This type of jre is not supported.");
+			e.printStackTrace();
+		}
+	}
+
+	
+	/**
+	 * Add reserved classes from a ClassNameSet file.
+	 * 
+	 * @param fileName the file path of the cns file
+	 */
+	public final void addReservedClasses(final String fileName) {
+		addReservedClasses(null == fileName ? (File) null : new File(fileName));
+	}
+	
+	/**
+	 * Add reserved classes from a ClassNameSet file.
+	 * 
+	 * @param file the java.io.File instance of the cns file
+	 */
+	public final void addReservedClasses(final File file) {
+		try {
+			reservedClasses.merge(file);
+		} catch (FileNotFoundException e) {
+			System.err.println("The file " 
+					+ file.getAbsolutePath() + " does not exist.");
+			e.printStackTrace(); 
+		} catch (CNSFileFormatException e) {
+			System.err.println("The file " 
+					+ file.getAbsolutePath() + " is not a valid cns file.");
+			e.printStackTrace();
+		} catch (IOException e) {
+			System.err.println("IO problem encountered " 
+					+ "when trying to open and read from "  
+					+ file.getAbsolutePath() + ".");
+			e.printStackTrace();
+		}
+	}
+	
+	/**
+	 * Add reserved classes from a ClassNameSet instance.
+	 * 
+	 * @param cns the ClassNameSet instance
+	 */
+	public final void addReservedClasses(final ClassNameSet cns) {
+		reservedClasses.merge(cns);
+	}
+	
+	/**
+	 * Set the reserved classes set to the ClassNameSet 
+	 * instance built from a cns file.
+	 * 
+	 * @param fileName the path of the cns file
+	 */
+	public final void setReservedClasses(final String fileName) {
+		setReservedClasses(null == fileName ? (File) null : new File(fileName));
+	}
+	
+	/**
+	 * Set the reserved classes set to the ClassNameSet 
+	 * instance built from a cns file.
+	 * 
+	 * @param file the java.io.File instance of the cns file
+	 */
+	public final void setReservedClasses(final File file) {
+		try {
+			reservedClasses = new ClassNameSet(file);
+		} catch (FileNotFoundException e) {
+			System.err.println("The file " 
+					+ file.getAbsolutePath() + " does not exist.");
+			e.printStackTrace(); 
+		} catch (CNSFileFormatException e) {
+			System.err.println("The file " 
+					+ file.getAbsolutePath() + " is not a valid cns file.");
+			e.printStackTrace();
+		} catch (IOException e) {
+			System.err.println("IO problem encountered " 
+					+ "when trying to open and read from "  
+					+ file.getAbsolutePath() + ".");
+			e.printStackTrace();
+		}
+	}
+	
+	/**
+	 * Set the reserved classes set to the ClassNameSet instance.
+	 * 
+	 * @param cns the ClassNameSet instance
+	 */
+	public final void setReservedClasses(final ClassNameSet cns) {
+		reservedClasses = cns;
+	}
+	
+	/**
+	 * Generate minimum jre from the origin jre 
+	 * according to the reserved class list.
+	 * 
+	 * @param fromPath the origin jre path
+	 * @param toPath the aim jre path
+	 */
+	public final void generateMinJre(final String fromPath, 
+			final String toPath) {
+		File[] fileList = new File(fromPath).listFiles();
+		for (int i = 0; i < fileList.length; i++) {
+			if (fileList[i].isDirectory()) {
+				try {
+					copyDirectory(fileList[i].getAbsolutePath(), 
+							toPath + File.separator + fileList[i].getName(), 
+							fileList[i].getName().equals("lib"));
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			} else if (fileList[i].isFile()) {
+				copyFile(fileList[i].getAbsolutePath(), 
+						toPath + File.separator + fileList[i].getName());
+			}
+		}
+	}
+}

Added: harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/StaticDependencyAnalyzer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/StaticDependencyAnalyzer.java?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/StaticDependencyAnalyzer.java (added)
+++ harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/StaticDependencyAnalyzer.java Mon Aug 17 01:43:02 2009
@@ -0,0 +1,304 @@
+package org.crazynut.harmony.minjre;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Vector;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.ClassParser;
+import org.apache.bcel.classfile.Constant;
+import org.apache.bcel.classfile.ConstantClass;
+import org.apache.bcel.classfile.ConstantPool;
+import org.apache.bcel.classfile.ConstantUtf8;
+import org.apache.bcel.classfile.ClassFormatException;
+
+/**
+ * A dependency analyzer implementation to examine 
+ * what jre classes a certain java application depends on.
+ * 
+ * @author  <A HREF="mailto:daniel.gong.fudan@gmail.com">Ling-Hui Gong</A>
+ */
+public class StaticDependencyAnalyzer {
+	
+	/**
+	 * The application class set.
+	 */
+	private Vector<JavaClass> rootClasses;
+	
+	/**
+	 * The jre class set.
+	 */
+	private HashMap<String, JavaClass> jreClasses;
+	
+	/**
+	 * The class paths, including jars and directories 
+	 * containing the application classes.
+	 */
+	private Vector<File> classPaths;
+	
+	/**
+	 * The jre path.
+	 */
+	private File jrePath;
+	
+	/**
+	 * True if the root class set has been built already.<p>
+	 * False if the root class set has not been built yet.
+	 */
+	private boolean isRootClassesBuilt;
+	
+	/**
+	 * True if the jre class set has been built already.<p>
+	 * False if the jre class set has been built yet.
+	 */
+	private boolean isJreClassesBuilt;
+	
+	/**
+	 * Constructor.
+	 */
+	public StaticDependencyAnalyzer() {
+		rootClasses = new Vector<JavaClass>();
+		jreClasses = new HashMap<String, JavaClass>();
+		classPaths = new Vector<File>();
+		jrePath = null;
+		isRootClassesBuilt = false;
+		isJreClassesBuilt = false;
+	}
+	
+	/**
+	 * Get class set from a directory.
+	 * 
+	 * @param dirPath the directory path that we get java classes from
+	 * @return the java classes we get from the directory
+	 */
+	private Vector<JavaClass> getJavaClassFromDir(final File dirpath) {
+		Vector<JavaClass> dirClasses = new Vector<JavaClass>();
+		File[] fileList = dirpath.listFiles();
+		for (int i = 0; i < fileList.length; i++) {
+			if (fileList[i].isFile()) {
+				if (fileList[i].getPath().endsWith(".class")) {
+					try {
+						dirClasses.add(new ClassParser(
+								fileList[i].getPath()).parse());
+					} catch (ClassFormatException e) {
+						System.err.println("The file " + fileList[i].getPath() +
+								"ends with .class " +
+								"but cannot be interpreted as a class file.");
+						e.printStackTrace();
+					} catch (IOException e) {
+						System.err.println("IO problem(s) detected when paring " 
+								+ "the file " + fileList[i].getPath() + ".");
+						e.printStackTrace();
+					}
+				} else if (fileList[i].getPath().endsWith(".jar")) {
+					dirClasses.addAll(getJavaClassFromJar(fileList[i]));
+				}
+			} else if (fileList[i].isDirectory()) {
+				dirClasses.addAll(getJavaClassFromDir(fileList[i]));
+			}
+		}
+		return dirClasses;
+	}
+	/**
+	 * Get JavaClass object list from a jar file.
+	 * 
+	 * @param jarPath the jar file path that we get java classes from
+	 * @return the java classes we get from jarPath
+	 */
+	private Vector<JavaClass> getJavaClassFromJar(final File jarPath) {
+		Vector<JavaClass> jarClasses = new Vector<JavaClass>();
+		if (!jarPath.getPath().endsWith(".jar")) {
+			return null;
+		}
+		try {
+			JarFile jarFile = new JarFile(jarPath);
+			Enumeration<JarEntry> entries = jarFile.entries();
+			while (entries.hasMoreElements()) {
+				JarEntry entry = entries.nextElement();
+				String name = entry.getName();
+				if (name.endsWith(".class")) {
+					jarClasses.add(new ClassParser(
+							jarFile.getInputStream(entry), 
+							name.substring(name.lastIndexOf('/') + 1)).parse());
+				}
+			}
+		} catch (IOException e) {
+			System.err.println("IO problem encountered " 
+					+ "when trying to get classes from " + jarPath + ".");
+			e.printStackTrace();
+		}
+		return jarClasses;
+	}
+	
+	/**
+	 * Build class set from the class paths added before.
+	 */
+	private void buildRootClasses() {
+		Iterator<File> i = classPaths.iterator();
+		while (i.hasNext()) {
+			File classPath = i.next();
+			if (classPath.isFile()) {
+				if (classPath.getName().endsWith(".jar")) {
+					rootClasses.addAll(getJavaClassFromJar(classPath));
+				} else if (classPath.getName().endsWith(".class")) {
+					try {
+						rootClasses.add(new ClassParser(
+								classPath.getAbsolutePath()).parse());
+					} catch (ClassFormatException e) {
+						System.err.println(classPath.getAbsolutePath()  
+								+ " is not a valid class file.");
+						e.printStackTrace();
+					} catch (IOException e) {
+						System.err.println("IO problem encountered " 
+								+ "when trying to parse " 
+								+ classPath.getAbsolutePath() + ".");
+						e.printStackTrace();
+					}
+				}
+			} else if (classPath.isDirectory()) {
+				rootClasses.addAll(getJavaClassFromDir(classPath));
+			}
+		}
+		isRootClassesBuilt = true;
+	}
+	
+	/**
+	 * Build class set from the jre path set before.
+	 */
+	private void buildJreClasses() {
+		if (jrePath != null) {
+			Vector<JavaClass> jreClassList = getJavaClassFromDir(jrePath);
+			Iterator<JavaClass> i = jreClassList.iterator();
+			while (i.hasNext()) {
+				JavaClass javaClazz = i.next();
+				jreClasses.put(javaClazz.getClassName(), javaClazz);
+			}
+			isJreClassesBuilt = true;
+		}
+	}
+	
+	/**
+	 * Add a class path to class path set. A class path can be 
+	 * a file directory or a jar file.
+	 * 
+	 * @param pathName The name of the class path add to class path set
+	 */
+	public final void addClassPath(final String pathName) {
+		File newpath = new File(pathName);
+		if (newpath.exists()) {
+			classPaths.add(newpath);
+			// Root class path is modified, 
+			// set it to false to require rebuilding.
+			isRootClassesBuilt = false;
+		}
+	}
+	
+	/**
+	 * Set the path of the lib directory in JRE.
+	 * 
+	 * @param dirName The path of the lib directory in JRE
+	 */
+	public final void setJreLibPath(final String dirName) {
+		File jreDir = new File(dirName);
+		if (jreDir.exists() && jreDir.isDirectory()) {
+			jrePath = jreDir;
+			// Jre class path is modified, 
+			// set it to false to require rebuilding.
+			isJreClassesBuilt = false;
+		}
+	}
+	
+	/**
+	 * Get the dependent class set.
+	 * 
+	 * @return the dependent class set
+	 */
+	public final ClassNameSet getDependentClasses() {
+		Vector<JavaClass> workList = new Vector<JavaClass>();
+		ClassNameSet result = new ClassNameSet();
+		
+		// Build root classes and jre classes in the first time
+		// or rebuild them when they are modified.
+		if (!isRootClassesBuilt) {
+			buildRootClasses();
+		}
+		if (!isJreClassesBuilt) {
+			buildJreClasses();
+		}
+		
+		// Add basic dependency 
+		workList.addAll(rootClasses);
+		Iterator<String> keyIterator = jreClasses.keySet().iterator();
+		while (keyIterator.hasNext()) {
+			String className = keyIterator.next();
+			if (className.startsWith("java.lang.")) {
+				workList.add(jreClasses.get(className));
+				result.addName(className);
+			}
+		}
+		
+		// Traverse the worklist to decide the classes that each class depends on in the worklist.
+		// These "depended" classes are added into the worklist and result if they have not been in the result yet.
+		// The algorithm ends when the index pointer reach the end of the worklist.
+		// A dependency closure will be built with the above algorithm.
+		int i = 0;
+		while (i < workList.size()) {
+			JavaClass javaClazz = workList.elementAt(i);
+			// Get depended classes from the constant pool
+			ConstantPool cp = javaClazz.getConstantPool();
+			Constant[] carray = cp.getConstantPool();
+			for (int j = 0; j < carray.length; j++) {
+				if (carray[j] instanceof ConstantClass) {
+					int index = ((ConstantClass) carray[j]).getNameIndex();
+					String className = ((ConstantUtf8) carray[index])
+						.getBytes().replace('/', '.');
+					if (!result.isClassIn(className) 
+							&& jreClasses.containsKey(className)) {
+						workList.add(jreClasses.get(className));
+						result.addName(className);
+					}
+				}
+			}
+			// Get interfaces
+			String[] interfaceNames = javaClazz.getInterfaceNames();
+			for (int j = 0; j < interfaceNames.length; j++) {
+				if (!result.isClassIn(interfaceNames[j]) 
+						&& jreClasses.containsKey(interfaceNames[j])) {
+					workList.add(jreClasses.get(interfaceNames[j]));
+					result.addName(interfaceNames[j]);
+				}
+			}
+			// Get superclass
+			String superClassName = javaClazz.getSuperclassName();
+			if (!result.isClassIn(superClassName) 
+					&& jreClasses.containsKey(superClassName)) {
+				workList.add(jreClasses.get(superClassName));
+				result.addName(superClassName);
+			}
+			i++;
+		}
+		return result;
+	}
+	
+	/**
+	 * Get the dependent class set and write it to file.
+	 * 
+	 * @param fileName the file that will contain the dependent class set
+	 */
+	public final void getDependentClasses(final String fileName) {
+		ClassNameSet result = getDependentClasses();
+		try {
+			result.toClassListFile(fileName);
+		} catch (IOException e) {
+			System.err.println("Problem encoutered " 
+					+ "when trying to create file " 
+					+ fileName + " or write to it.");
+			e.printStackTrace();
+		}
+	}
+}

Added: harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/anttask/AnalyzeDependencyTask.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/anttask/AnalyzeDependencyTask.java?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/anttask/AnalyzeDependencyTask.java (added)
+++ harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/anttask/AnalyzeDependencyTask.java Mon Aug 17 01:43:02 2009
@@ -0,0 +1,76 @@
+package org.crazynut.harmony.minjre.anttask;
+
+import java.util.Vector;
+import java.io.File;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.Ant.Reference;
+import org.apache.tools.ant.types.Path;
+import org.crazynut.harmony.minjre.StaticDependencyAnalyzer;
+
+/**
+ * The ant task that can analyze static dependency of a set of classes.
+ * 
+ * @author  <A HREF="mailto:daniel.gong.fudan@gmail.com">Ling-Hui Gong</A>
+ *
+ */
+public class AnalyzeDependencyTask extends Task{
+	
+	private File aim = null;
+	
+	private File jrelib = null;
+	
+	private Path path = null;
+	
+	public void execute() {
+		if (null == aim || null == jrelib || 0 == path.size()) {
+			log("Incorrect use of this task.\n");
+			throw new BuildException();
+		}
+
+		String[] list = path.list();
+		for (int i = 0; i < list.length; i++) {
+			File file = new File(list[i]);
+			if (file.isFile() && (!file.getName().endsWith(".jar") || !file.getName().endsWith(".class"))) {
+				throw new BuildException(list[i] 
+				        + " is not a valid classpath.");
+			}
+		}
+		log("Start to analyze static dependency.\n");
+		log("Analyzing ...\n");
+		StaticDependencyAnalyzer ana = new StaticDependencyAnalyzer();
+		ana.setJreLibPath(jrelib.getAbsolutePath());
+		for (int i = 0; i < list.length; i++) {
+			ana.addClassPath(list[i]);
+		}
+		ana.getDependentClasses(aim.getAbsolutePath());
+		log("Analyzing complete.\n");
+	}
+	
+	public void setAim(File aim) {
+		if (aim.isFile() || aim.getName().endsWith(".cns")) {
+			this.aim = aim;
+		} else {
+			throw new BuildException(aim.getAbsolutePath() 
+					+ " is not a valid cns file.");
+		}
+	}
+	
+	public void setJrelib(File jrelib) {
+		if (jrelib.isDirectory()) {
+			this.jrelib = jrelib;
+		} else {
+			throw new BuildException(jrelib.getAbsolutePath()
+					+ " is not a valid directory.");
+		}
+	}
+
+	public Path createClasspath() {
+        if (path == null) {
+            path = new Path(getProject());
+        }
+        return path.createPath();
+	}
+
+}

Added: harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/anttask/GenerateJreTask.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/anttask/GenerateJreTask.java?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/anttask/GenerateJreTask.java (added)
+++ harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/anttask/GenerateJreTask.java Mon Aug 17 01:43:02 2009
@@ -0,0 +1,92 @@
+package org.crazynut.harmony.minjre.anttask;
+
+import java.io.File;
+import java.util.Vector;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.Ant.Reference;
+import org.apache.tools.ant.types.Path;
+import org.crazynut.harmony.minjre.JreGenerator;
+
+/**
+ * The ant task that can generate a new JRE from a set of cns files.
+ * 
+ * @author  <A HREF="mailto:daniel.gong.fudan@gmail.com">Ling-Hui Gong</A>
+ *
+ */
+public class GenerateJreTask extends Task {
+	
+	private File origin = null;
+	
+	private File target = null;
+	
+	private String jre = null;
+	
+	private Path path = null;
+	
+	public void execute() {
+		if (null == origin || null == target 
+				|| null == jre || 0 == path.size()) {
+			log("Incorrect use of this task.\n");
+			throw new BuildException();
+		}
+		JreGenerator gen = new JreGenerator(jre);
+		String[] list = path.list();
+		for (int i = 0; i < list.length; i++) {
+			File current = new File(list[i]);
+			if (current.isFile()) {
+				if (current.getName().endsWith(".cns")) {
+					gen.addReservedClasses(current);
+				} else {
+					throw new BuildException(list[i] 
+				        + " is not a valid cns file.");
+				}
+			} else if (current.isDirectory()) {
+				File[] files = current.listFiles();
+				for (int j = 0; j < files.length; j++) {
+					if (files[j].isFile() && files[j].getName().endsWith(".cns")) {
+						gen.addReservedClasses(files[j]);
+					}
+				}
+			} else {
+				throw new BuildException(list[i]
+			        + " does not exist.");
+			}
+		}
+		log("Start to generate JRE.\n");
+		log("Generating ...\n");
+		gen.generateMinJre(origin.getAbsolutePath(), target.getAbsolutePath());
+		log("Generating complete.\n");
+	}
+
+	public void setJre(String jre) {
+		this.jre = jre;
+	}
+	
+	public void setOrigin(File origin) {
+		if (origin.isDirectory()) {
+			this.origin = origin;
+		} else {
+			throw new BuildException(origin.getAbsolutePath() 
+					+ " is not a valid existing directory.");
+		}
+	}
+	
+	public void setTarget(File target) {
+		if (target.isDirectory() || target.mkdir()) {
+			this.target = target;
+		} else {
+			throw new BuildException(target.getAbsolutePath()
+					+ " does not exist or can not be created.");
+		}
+	}
+	
+	public Path createCnspath() {
+        if (path == null) {
+            path = new Path(getProject());
+        }
+        return path.createPath();
+	}
+
+}

Added: harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/bin/AnalyzeDependency.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/bin/AnalyzeDependency.java?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/bin/AnalyzeDependency.java (added)
+++ harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/bin/AnalyzeDependency.java Mon Aug 17 01:43:02 2009
@@ -0,0 +1,101 @@
+package org.crazynut.harmony.minjre.bin;
+
+import java.io.File;
+
+import org.crazynut.harmony.minjre.StaticDependencyAnalyzer;
+
+/**
+ * The main class of the static dependency analyzer of MinJre Toolkit.<p>
+ * 
+ * @author <A HREF="mailto:daniel.gong.fudan@gmail.com">Ling-Hui Gong</A>
+ *
+ */
+public class AnalyzeDependency {
+
+	private static String jreLibPath = null;
+	
+	private static String[] rootPath = null;
+	
+	private static String aimFile = null;
+	
+	private static String msg = "";
+	
+	/**
+	 * Parse the arguments.
+	 * 
+	 * @param args the arguments
+	 * @return parsing result
+	 */
+	private static int parseArgs(final String[] args) {
+		if (args.length < 3) {
+			return -1;
+		} else {
+			String[] libArg = args[0].split("=");
+			String[] pathArg = args[1].split("=");
+			String[] aimArg = args[2].split("=");
+			if (!libArg[0].equals("-jrelib") || !pathArg[0].equals("-classpath") || !aimArg[0].equals("-aim") 
+					|| libArg.length != 2 || pathArg.length != 2 || aimArg.length != 2) {
+				return -1;
+			} else {
+				File libFile = new File(libArg[1]);
+				if (!libFile.exists() || libFile.isFile()) {
+					msg = libArg[1] + " does not exists as a directory.";
+					return 0;
+				}
+				jreLibPath = libArg[1];
+				String[] paths = pathArg[1].split(";");
+				for (int i = 0; i < paths.length; i++) {
+					File file = new File(paths[i]);
+					if (!file.exists() || (file.isFile() && !paths[i].endsWith(".jar"))) {
+						msg = file + " is not a valid class path.";
+						return 0;
+					}
+				}
+				rootPath = paths;
+			}
+			if (aimArg[1].endsWith(".cns")) {
+				aimFile = aimArg[1];
+			} else {
+				msg = aimArg[1] + " should be a cns file.";
+				return 0;
+			}
+		}
+		return 1;
+	}
+	
+	/**
+	 * 
+	 */
+	private static void printUsage() {
+		System.out.println(
+				"Usage: analyze -jrelib=<jre lib dir> -classpath=<root path list> -aim=<aim file path>\n" 
+				+ "\tThe root path list is a ; seperated list of directories or jar files or just class files, which containing all classes in the application.\n" 
+				+ "\tExample: analyze -jrelib=%JRE_HOME%\\lib -classpath=c:\\app\\module1;c:\\app\\lib\\lib1.jar c:\\app\\cns\\static.cns"
+				);
+	}
+	
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		int flag = parseArgs(args);
+		switch (flag) {
+			case -1:
+				printUsage();
+				break;
+			case  0:
+				System.out.println(msg);
+				break;
+			case  1:
+				StaticDependencyAnalyzer ana = new StaticDependencyAnalyzer();
+				ana.setJreLibPath(jreLibPath);
+				for (int i = 0; i < rootPath.length; i++) {
+					ana.addClassPath(rootPath[i]);
+				}
+				ana.getDependentClasses(aimFile);
+				break;
+		default:
+			break;
+		}
+	}
+}

Added: harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/bin/GenerateJre.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/bin/GenerateJre.java?rev=804823&view=auto
==============================================================================
--- harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/bin/GenerateJre.java (added)
+++ harmony/enhanced/tools/trunk/minijre/src/org/crazynut/harmony/minjre/bin/GenerateJre.java Mon Aug 17 01:43:02 2009
@@ -0,0 +1,119 @@
+package org.crazynut.harmony.minjre.bin;
+
+import java.io.File;
+
+import org.crazynut.harmony.minjre.JreGenerator;
+
+/**
+ * The main class of the JRE generator of MinJre Toolkit.<p>
+ * 
+ * @author <A HREF="mailto:daniel.gong.fudan@gmail.com">Ling-Hui Gong</A>
+ *
+ */
+public class GenerateJre {
+
+	private static String jre = null;
+	
+	private static File[] cnsPath = null;
+	
+	private static String toPath = null;
+	
+	private static String fromPath = null;
+	
+	private static String msg = "";
+	
+	/**
+	 * Parse the arguments.
+	 * 
+	 * @param args the arguments
+	 * @return parsing result
+	 */
+	private static int parseArgs(final String[] args) {
+		if (args.length < 4) {
+			return -1;
+		} else {
+			String[] typeArg = args[0].split("=");
+			String[] pathArg = args[1].split("=");
+			String[] originArg = args[2].split("=");
+			String[] targetArg = args[3].split("=");
+			if (!typeArg[0].equals("-jre") || !pathArg[0].equals("-cnspath") || !originArg[0].equals("-origin") || !targetArg[0].equals("-target") 
+					|| typeArg.length != 2 || pathArg.length != 2 || originArg.length != 2 || targetArg.length != 2) {
+				return -1;
+			} else {
+				//File ini = new File("conf" + File.separator + typeArg[1] + ".cns");
+				//iniFile = ini.getAbsolutePath();
+				jre = typeArg[1];
+				String[] paths = pathArg[1].split(";");
+				cnsPath = new File[paths.length];
+				for (int i = 0; i < paths.length; i++) {
+					cnsPath[i] = new File(paths[i]);
+					if (!cnsPath[i].exists()) {
+						msg = paths[i] + " does not exist.";
+						return 0;
+					}
+					if (cnsPath[i].isFile() && !cnsPath[i].getName().endsWith(".cns")) {
+						msg = paths[i] + " is not a cns file.";
+						return 0;
+					}
+				}
+			}
+			if (new File(originArg[1]).isDirectory()) {
+				fromPath = originArg[1];
+			} else {
+				msg = originArg[1] + " does not exist as a directory.";
+				return 0;
+			}
+			if (new File(targetArg[1]).isDirectory()) {
+				toPath = targetArg[1];
+			} else {
+				msg = targetArg[1] + " does not exist as a directory.";
+				return 0;
+			}
+		}
+		return 1;
+	}
+	
+	/**
+	 * Print out usage of the program.
+	 */
+	private static void printUsage() {
+		System.out.println(
+				"Usage: jregen -jre=<jretype> -cnspath=<cns path list> -origin=<originjre> -target=<targetdir>\n" 
+				+ "\tThe cns path list is a ; seperated list of cns files and directories which containing cns files needed to generate the jre.\n" 
+				+ "\tExample: jregen -jre=harmony -cnspath=c:\\app\\module1\\cns;c:\\app\\module2\\cns -origin=%JRE_HOME% -target=c:\\java\\minjre"
+				);
+	}
+	
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		int flag = parseArgs(args);
+		switch (flag) {
+			case -1:
+				printUsage();
+				break;
+			case  0:
+				System.out.println(msg);
+				break;
+			case  1:
+				JreGenerator gen = new JreGenerator(jre);			
+				for (int i = 0; i < cnsPath.length; i++) {
+					if (cnsPath[i].isDirectory()) {
+						File[] list = cnsPath[i].listFiles();
+						for (int j = 0; j < list.length; j++) {
+							if (list[j].getName().endsWith(".cns")) {
+								gen.addReservedClasses(list[j]);
+							}
+						}
+					} else if (cnsPath[i].isFile()) {
+							gen.addReservedClasses(cnsPath[i]);
+					}
+				}
+				gen.generateMinJre(fromPath, toPath);
+				break;
+		default:
+			break;
+		}
+	}
+}

Added: harmony/enhanced/tools/trunk/minijre/test/hello/Hello.class
URL: http://svn.apache.org/viewvc/harmony/enhanced/tools/trunk/minijre/test/hello/Hello.class?rev=804823&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/tools/trunk/minijre/test/hello/Hello.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message