All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tsc9526.monalisa.tools.clazz.CompilePackage Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
/*******************************************************************************************
 *	Copyright (c) 2016, zzg.zhou([email protected])
 * 
 *  Monalisa is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU Lesser General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.

 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU Lesser General Public License for more details.

 *	You should have received a copy of the GNU Lesser General Public License
 *	along with this program.  If not, see .
 *******************************************************************************************/
package com.tsc9526.monalisa.tools.clazz;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.tsc9526.monalisa.tools.agent.AgentJavaFile;
import com.tsc9526.monalisa.tools.io.JavaFile;
import com.tsc9526.monalisa.tools.io.MelpFile;

/**
 * 
 * @author zzg.zhou([email protected])
 */
public class CompilePackage{
	private String javaSourceDir;
	private String classOutputDir;
	
	private Map hjfs=null;
	 
	public CompilePackage(String javaSourceDir,String classOutputDir){
		this.javaSourceDir =MelpFile.combinePath(javaSourceDir);
		this.classOutputDir=MelpFile.combinePath(classOutputDir);
	}
	
	public synchronized void scan(){
		if(hjfs==null){
			hjfs=new LinkedHashMap();
		}
		
		List jfs=new ArrayList();
		
		File dir=new File(javaSourceDir);
		if(dir.exists()){
			fetchJavaFiles(dir,jfs);
		}
		
		Set rs=new HashSet(); 
		for(AgentJavaFile j:jfs){
			String key=j.getJavaFile().getAbsolutePath();
			hjfs.put(key, j); 
			
			rs.add(key);
		}
		
		Set rm=new HashSet(); 
		for(String x:hjfs.keySet()){
			if(!rs.contains(x)){
				rm.add(x);
			}
		}
		
		for(String key:rm){
			hjfs.remove(key);
		}
	}
	
	protected void fetchJavaFiles(File f,List jfs){
		if(f.isFile()){
			if(f.getName().endsWith(".java")){
				long lastModified=f.lastModified();
				
				String key=f.getAbsolutePath();
				AgentJavaFile jf=hjfs.get(key);
				if(jf==null || jf.getLastModified() getJavaFiles() {
		if(hjfs==null){
			scan();
		}
		return hjfs.values();
	} 
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy