Commit f6a3d842 by TongZuu

init commit

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path=""/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="output" path=""/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>UtilitySupport</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
package com.csc.library.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Pattern;
public class ClassFileUtil {
private static Pattern pClass = Pattern.compile(".*?.class\\z" , Pattern.CASE_INSENSITIVE);
public static boolean isClassFile(String path){
return ClassFileUtil.pClass.matcher(path).find();
}
public static JavaVersion getJavaVersion(InputStream is) throws IOException{
// Create a buffer to store the first 8 bytes of a file.
byte[] buffer = new byte[8];
// Create an InputStream from the file provided as an argument.
//InputStream is = new DataInputStream(new FileInputStream(new File(path)));
// Read the first 8 bytes of the file.
is.read(buffer);
// Print the major version number.
String result = buffer[7]+"";
return JavaVersion.getJavaVersion(Integer.parseInt(result));
}
}
package com.csc.library.util;
import java.io.File;
import java.io.FileFilter;
public class FileJarFilter implements FileFilter{
public boolean accept(File pathname) {
return JarFileUtil.isJarFile(pathname);
}
}
package com.csc.library.util;
import java.io.File;
import java.util.regex.Pattern;
public class JarFileUtil {
private static Pattern pJar = Pattern.compile(".*?.jar\\z" , Pattern.CASE_INSENSITIVE);
public static boolean isJarFile(String path){
return JarFileUtil.pJar.matcher(path).find();
}
public static boolean isJarFile(File file){
return JarFileUtil.pJar.matcher(file.getPath()).find();
}
}
package com.csc.library.util;
public enum JavaVersion{
java11(45 , "Java 1.1"),
java12(46 , "Java 1.2"),
java13(47 , "Java 1.3"),
java14(48 , "Java 1.4"),
java5(49 , "Java 5"),
java6(50 , "Java 6"),
java7(51 , "Java 7"),
java8(52 , "Java 8");
int majorVersion = 0;
String javaVersion = "";
private JavaVersion(int major , String javaVersion){
this.majorVersion = major;
this.javaVersion = javaVersion;
}
public int getMajorVersion(){
return this.majorVersion;
}
public String getJavaVersion(){
return this.javaVersion;
}
public static JavaVersion getJavaVersion(String javaVersion){
for(JavaVersion j : JavaVersion.values()){
if(javaVersion.equalsIgnoreCase(j.getJavaVersion())){
return j;
}
}
return null;
}
public static JavaVersion getJavaVersion(int major){
for(JavaVersion j : JavaVersion.values()){
if(major == j.getMajorVersion()){
return j;
}
}
return null;
}
}
\ No newline at end of file
package com.csc.library.util.scanner;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;
import com.csc.library.util.FileJarFilter;
import com.csc.library.util.JarFileUtil;
public class FindClassInJarFile {
private String pathApp = "";
public FindClassInJarFile(String path){
this.setPath(path);
}
public void setPath(String path){
this.pathApp = path;
}
public void scan(String className){
List<File> jarList = this.getListFileJar();
JarFile jf = null;
Pattern pJar = Pattern.compile(".*?"+className+".class\\z" , Pattern.CASE_INSENSITIVE);
StringBuffer sb = new StringBuffer();
int count = 0;
for(File jFile : jarList){
try{
jf = new JarFile(jFile);
Enumeration<JarEntry> enu = jf.entries();
while(enu.hasMoreElements()){
JarEntry je = enu.nextElement();
if(pJar.matcher(je.getName()).find()){
sb.append(count+" : "+jFile.getPath());
break;
}
}
}catch(Exception e){
e.printStackTrace();
}
}
if(sb.length() > 0){
System.out.println("List Jar File is found class ["+className+"] in Path ["+this.pathApp+"]\r\n"+sb.toString());
}else{
System.out.println("Cannot find class ["+className+"] in Path ["+this.pathApp+"]");
}
}
private List<File> getListFileJar(){
File f = new File(this.pathApp);
if( f.isDirectory() ){
return Arrays.asList(f.listFiles(new FileJarFilter()));
}else if(JarFileUtil.isJarFile(f)){
return Arrays.asList(f);
}else{
return new ArrayList<File>();
}
}
public static void main(String[] args) {
String strPath = "D:\\EnterprisePT\\Programmer\\myHRAppServer\\webapps\\Essilor\\hrAppWeb.war\\WEB-INF\\lib";
String className = "com.csc.library.databean.ttime_current1";
FindClassInJarFile fc = new FindClassInJarFile(strPath);
fc.scan(className);
}
}
package com.csc.library.util.scanner;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import com.csc.library.util.ClassFileUtil;
import com.csc.library.util.JarFileUtil;
import com.csc.library.util.JavaVersion;
public class FindMajorVersionNumber{
private String pathApp = "";
private JavaVersion jbossVersion = JavaVersion.java5;
public FindMajorVersionNumber(String path){
this.pathApp = path;
}
public FindMajorVersionNumber(String path , JavaVersion jversion){
this.pathApp = path;
this.jbossVersion = jversion;
}
public FindMajorVersionNumber(String path , int version){
this.pathApp = path;
JavaVersion tmp = JavaVersion.getJavaVersion(version);
if( tmp != null ){
this.jbossVersion = tmp;
}
}
public void scan() throws Exception{
System.out.println("Start...............");
List<File> listJarFile = this.getListJarFile(this.pathApp);
StringBuffer sb = new StringBuffer();
for(int i = 0; i<listJarFile.size(); i++){
JarFile jarFile = new JarFile(listJarFile.get(i));
Enumeration allEntries = jarFile.entries();
while (allEntries.hasMoreElements()) {
JarEntry entry = (JarEntry) allEntries.nextElement();
InputStream in = jarFile.getInputStream(entry);
if(ClassFileUtil.isClassFile(entry.getName())){
JavaVersion j = ClassFileUtil.getJavaVersion(in);
if( this.jbossVersion.getMajorVersion() < j.getMajorVersion() ){
sb.append(jarFile.getName()+" : "+entry.getName() +" : "+ j.getJavaVersion()+"\n");
}
}
in.close();
}
}
System.out.println(sb.toString());
System.out.println("Define Jboss version is : "+this.jbossVersion.getJavaVersion());
System.out.println("end...............");
}
private List<File> getListJarFile(String pathBase){
ArrayList<File> arr = new ArrayList<File>();
File path = new File(pathBase);
if(path.isDirectory()){
File[] files = path.listFiles();
for(int i = 0;i < files.length; i ++){
String pathFile = files[i].getPath();
if(JarFileUtil.isJarFile(pathFile)){
arr.add(files[i]);
// System.out.println(pathFile);
}
}
}else{
arr.add(path);
}
return arr;
}
public static void main(String[] args) throws Exception {
String strPath = "D:\\EnterprisePT\\Programmer\\myHRAppServer\\webapps\\Essilor\\hrAppWeb.war\\WEB-INF\\lib";
//FindMajorVersionNumber findMajor = new FindMajorVersionNumber(strPath);
FindMajorVersionNumber findMajor = new FindMajorVersionNumber(strPath , JavaVersion.java6);
findMajor.scan();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment