当前位置:文档之家› 软件著作权-代码

软件著作权-代码

Option.javapackage mon;public class Option {private String name;private String id;private String description;private OptionGroup group;public Option(String id, String name, String description,OptionGroup group) { this.id = id; = name;this.description = description;this.group = group;}public String getName() {return name;}public String getId() {return id;}public String getDescription() {return description.replaceAll("\\t", "").trim();}public OptionGroup getGroup(){return this.group;}}OptionGroup.javapackage mon;import java.util.ArrayList;import java.util.List;import .uestc.ablator.ui.util.XmlParser;/*** 选项组* @author Administrator**/public class OptionGroup {private String id;private String name;private List<Option> optionList;public OptionGroup(String id, String name){this.id = id; = name;this.optionList = new ArrayList<Option>();}public void addOption(Option o){if(optionList!=null)optionList.add(o);}public String getGroupPlaceHolder(){return XmlParser.getInstance().getGroupPlaceholder(id);}public String getName(){return ;}public List<Option> getOptionList(){return this.optionList;}}ProjectType.javapackage mon;/*** 工程类型枚举* @author Administrator**/public enum ProjectType {/*** 普通工程*/COMMOMAPPLICATION("commonApplication"),/*** 解决方案*/SOLUTION("solution"),/*** 模块程序*/MODULE("module"),/*** 原子库*/A TOM("atom");private String name;ProjectType(String name){ = name;}public String getName(){return ;}}Activator.javapackage .uestc.ablator.ui;import org.eclipse.ui.plugin.AbstractUIPlugin;import org.osgi.framework.BundleContext;/*** The activator class controls the plug-in life cycle*/public class Activator extends AbstractUIPlugin {// The plug-in IDpublic static final String PLUGIN_ID = ".uestc.ablator.ui";// The shared instanceprivate static Activator plugin;/*** The constructor*/public Activator() {}/** (non-Javadoc)* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */public void start(BundleContext context) throws Exception {super.start(context);plugin = this;}/** (non-Javadoc)* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */public void stop(BundleContext context) throws Exception {plugin = null;super.stop(context);}/*** Returns the shared instance** @return the shared instance*/public static Activator getDefault() {return plugin;}}ClientSocket.javapackage working;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import .Socket;import .SocketTimeoutException;import .UnknownHostException;import org.apache.log4j.Logger;import .uestc.ablator.ui.util.MessageConfig;class ClientSocket {private Logger logger = Logger.getLogger(MessageConfig.LOGGER_NAME);private String ip;private int port;private Socket socket;private ObjectOutputStream outputStream;private ObjectInputStream inputStream;public ClientSocket(String ip, int port) {this.ip = ip;this.port = port;}/*** 连接服务器* @return 连接成功返回true 否则返回false* @throws IOException* @throws UnknownHostException*/public boolean connect() throws UnknownHostException, IOException {try {boolean success = false;socket = new Socket(ip, port);//设置read超时socket.setSoTimeout(NetworkingConfig.TIME_OUT);success = true;return success;} catch(IOException e){throw new IOException("无法连接服务器,请检查端口和服务器地址");}}/*** 发送消息到服务器* @param message* @return 发送成功返回true 否则返回false*/public void sendMessage(Message message)throws IOException{try {outputStream = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream()));outputStream.writeObject(message);outputStream.flush();}catch (IOException e) {if(outputStream != null)try {outputStream.close();} catch (IOException ioe) {logger.error("关闭输出流失败");}throw new IOException("发送消息:"+message+" 失败");}}/*** 从服务器接受消息* @return 成功接受返回接受到的消息,否则返回null* @throws SocketTimeoutException*/public Message receiveMessage() throws SocketTimeoutException{Message receiveMessage = null;try {inputStream = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));receiveMessage = (Message)inputStream.readObject();} catch(SocketTimeoutException e){throw new SocketTimeoutException("读取数据超时");} catch (ClassCastException e) {logger.error("ClassCastException从服务器读取的数据不能转换为Message");} catch (IOException ioe){logger.error(ioe.getMessage());} catch (ClassNotFoundException e){logger.error(e.getMessage());}return receiveMessage;}/*** 关闭连接* @throws IOException*/public void shutdownConnection() throws IOException {if (outputStream != null)outputStream.close();if (inputStream != null)inputStream.close();if (socket != null)socket.close();}}Downloader.javapackage working;import java.io.File;import java.io.IOException;import .SocketException;import .SocketTimeoutException;import .UnknownHostException;import java.util.List;import org.apache.log4j.Logger;import org.dom4j.DocumentException;import org.eclipse.core.runtime.IProgressMonitor;import .uestc.ablator.ui.util.MessageConfig;import .uestc.ablator.ui.util.XmlParser;/*** 负责从服务器接受数据* @author Administrator**/public class Downloader {private Logger logger = Logger.getLogger(MessageConfig.LOGGER_NAME);private ClientSocket clientSocket = null;private FtpUtil ftpUtil;/*** 连接服务器* @throws IOException* @throws UnknownHostException* @throws LoginException*/public void connect() throws UnknownHostException, IOException, LoginException{clientSocket = new ClientSocket(NetworkingConfig.SERVER_IP, NetworkingConfig.SERVER_LISTENING_PORT);clientSocket.connect();ftpUtil = new FtpUtil();ftpUtil.connectAndLogin(NetworkingConfig.SERVER_IP, NetworkingConfig.FTP_SERVER_PORT, NetworkingConfig.FTP_CLIENT_USERNAME, NetworkingConfig.FTP_CLIENT_PASSWORD);}/*** 发送消息到服务器* @param message* @throws IOException*/private void sendMessage(Message message) throws IOException{clientSocket.sendMessage(message);}/*** 从服务器接受消息* @return 成功接受返回接收到的消息Message,否则返回null* @throws SocketTimeoutException*/private Message getMessageFromServer() throws SocketTimeoutException{return clientSocket.receiveMessage();}/** 发送消息格式:* Message* MessageType: GET_MANIFEST* data:从download文件夹下manifest.xml中读取versionID(若不存在则id号为-1)* paths:空** 接收消息格式:* 1. 没有更新manifest.xml* Message* MessageType: GET_MANIFEST* data: 服务器端manifest.xml版本号* paths: 空** 2.有更新manifest.xml* Message* MessageType: GET_MANIFEST* data: manifest.xml在ftp服务器端的目录* paths: 空*//*** 下载manifest.xml到本地目录savePath* @param savePath 存储目录* @return 下载成功返回true,否则返回false* @throws IOException* @throws LoginException 登录ftp异常,用户名密码错误* @throws SocketException ftp连接异常*/public void downloadManifest(String savePath) throws SocketTimeoutException,IOException{String manifestVersion = "";try{manifestVersion = XmlParser.getInstance().getVersion();}catch(NullPointerException e){manifestVersion = "-1";}sendMessage(new Message(MessageType.GET_MANIFEST , manifestVersion));Message message = getMessageFromServer();if(message != null){String remoteVersion = message.getData();if(remoteVersion.equals(manifestVersion)){("服务器端manifest.xml无更新版本,读取本地download文件夹下manifest.xml");return;}String remotePath = message.getData();if(ftpUtil.downloadFile(remotePath, savePath)){("成功下载manifest.xml,保存至"+savePath+File.separator+MessageConfig.MANIFEST_FILE_NAME);try {MessageConfig.setManifestPath(savePath+File.separator+MessageConfig.MANIFEST_FILE_NAME);} catch (DocumentException e) {//donothing,因为成功下载manifest,理论上该处不会抛出异常}}}}/** 发送消息格式:* Message* MessageType: GET_TEMPLATE* data: 要下载的template的ID* paths:空** 接收消息格式:* Message* MessageType: GET_TEMPLATE* data: template文件夹在ftp服务器的目录e.g. /AA/BB/CC/Target* paths: option文件在ftp服务器的路径/包含文件名(若有多个option,以";"分割)*//*** 下载template文件,保存至savePath* @param templateId 请求下载的templateID* @param savePath template文件夹保存目录* @throws IOException*/public void downTemplate(String templateId, String savePath, IProgressMonitor monitor) throws SocketTimeoutException,IOException{monitor.beginTask("下载模板文件", 70);sendMessage(new Message(MessageType.GET_TEMPLATE,templateId));monitor.worked(10);Message message = getMessageFromServer();if(message != null){String data = message.getData();if(data != null && !data.equals("")){ftpUtil.downloadFolder(data, savePath);monitor.worked(50);}List<String> paths = message.getPaths();if(paths!=null && paths.size()>0){for(String optionPath : paths){ftpUtil.downloadFile(optionPath, savePath);}}monitor.worked(10);}monitor.done();}public void disconnect() throws IOException{clientSocket.shutdownConnection();ftpUtil.loginoutAndDisconnect();}}FtpUtil.javapackage working;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStream;import .SocketException;import .ftp.FTPClient;import .ftp.FTPClientConfig;import .ftp.FTPFile;import .ftp.FTPReply;import org.apache.log4j.Logger;import .uestc.ablator.ui.util.MessageConfig;public class FtpUtil {private Logger logger = Logger.getLogger(MessageConfig.LOGGER_NAME);private FTPClient ftpClient;/*** 连接到FTP服务器并登录* @param ftpServerIp FTP服务器IP* @param ftpServerPort FTP服务器端口* @param user 用户名* @param password 密码* @throws SocketException* @throws IOException* @throws LoginException 用户名密码异常*/public void connectAndLogin(String ftpServerIp, int ftpServerPort, String user, String password) throws SocketException, IOException, LoginException{ftpClient = new FTPClient();ftpClient.setControlEncoding("GBK");FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT);conf.setServerLanguageCode("zh");try {ftpClient.connect( ftpServerIp, ftpServerPort);} catch (IOException e) {logger.error("尝试连接到FTP服务器失败,请检查端口和服务器地址");throw new IOException("尝试连接到FTP服务器失败,请检查端口和服务器地址");}int reply = ftpClient.getReplyCode();if (!FTPReply.isPositiveCompletion(reply)) {ftpClient.disconnect();logger.error("FTP 服务器拒绝连接");}if(!ftpClient.login(user, password)){throw new LoginException("登录FTP服务器失败,用户名密码错误");}ftpClient.enterLocalPassiveMode(); //active connection server mode}/*** 注销并关闭连接* @throws IOException*/public void loginoutAndDisconnect() throws IOException{ftpClient.logout();if(ftpClient.isConnected())ftpClient.disconnect();}/*** 下载指定文件* @param remoteFilePath 在ftp服务器上的路径,包含文件名 e.g./aa/bb/cc/dd.xml* @param localFileDir 下载文件保存在本地的目录* @throws IOException*/public boolean downloadFile(String remoteFilePath,String localFileDir){boolean result = false;String fileName = remoteFilePath.substring(stIndexOf("/")+1,remoteFilePath.length());String dir = remoteFilePath.substring(0, stIndexOf("/"));try{ftpClient.changeWorkingDirectory(dir);FTPFile files[] = ftpClient.listFiles();for(FTPFile f : files){if(f.getName().equals(fileName)){File localFile = new File(localFileDir+File.separator+fileName);OutputStream os = new FileOutputStream(localFile);ftpClient.retrieveFile(fileName, os);os.close();result = true;}}}catch(Exception e){System.out.println(e.getMessage());}return result;}/*** 载指定文件夹* @param remoteFolder FTP服务器文件夹/aa/bb/cc,目标文件夹* @param localDir下载到本地目录localDir* @throws IOException*/public void downloadFolder(String remoteFolder, String localDir) throws IOException{//文件夹名称String folderName = remoteFolder.substring(stIndexOf("/")+1,remoteFolder.length());File localFolder = new File(localDir+File.separator+folderName);//在本地以服务器端创建相应文件夹if(!localFolder.exists())localFolder.mkdirs();ftpClient.changeWorkingDirectory(remoteFolder);FTPFile[] files = ftpClient.listFiles();for(FTPFile file : files){if(!file.getName().equals(".") && !file.getName().equals("..")){String remoteFilePath = remoteFolder+NetworkingConfig.FTP_FILE_SEPERATOR+file.getName();if(file.isDirectory()){downloadFolder(remoteFilePath, localFolder.getAbsolutePath());}else{if(file.isFile()){downloadFile(remoteFilePath, localFolder.getAbsolutePath());}}}}}}LoginException.javapackage working;public class LoginException extends Exception {private static final long serialVersionUID = -4615049932628592182L;public LoginException(String message){super(message);}}Message.javapackage working;import java.io.Serializable;import java.util.ArrayList;import java.util.List;/*** 消息结构,用于在客户端和服务器之间传递控制信息* 实际的文件传输使用FTP* @author Administrator**/public class Message implements Serializable{private static final long serialVersionUID = 406680447556221555L;private MessageType type;private String data;private List<String> paths;//请求下载文件时,从服务器端返回的paths保存options在服务器ftp上的路径public Message(){}public Message(MessageType type){this.type = type;this.data = "";this.paths = new ArrayList<String>();}public Message(MessageType type, String data){this.type = type;this.data = data;this.paths = new ArrayList<String>();}public MessageType getType() {return type;}public void setType(MessageType type) {this.type = type;}public String getData() {return data;}public void setData(String data) {this.data = data;}public List<String> getPaths() {return paths;}public void setPaths(List<String> paths) {this.paths = paths;}public String toString() {return "消息类型: "+getType()+" 消息内容: "+((getData().equals("")||getData()==null)?"空":getData())+" 可选项: "+(paths.size()==0?"空":paths);}}MessageType.javapackage working;public enum MessageType {/*** 表示该消息类型为向服务器请求manifest.xml*/GET_MANIFEST,/*** 表示该消息类型为向服务器请求指定ID的模板文件*/GET_TEMPLATE;}NetworkingConfig.javapackage .uestc.ablator.ui;public class NetWorkingName {public static final String SERVER_LISTENING_PORT = "SERVER_LISTENING_PORT";public static final String SERVER_IP = "SERVER_IP";// public static final String SERVER_IP = "192.168.1.160";public static final String FTP_SERVER_PORT= "FTP_SERVER_PORT";public static final String FTP_CLIENT_USERNAME= "FTP_CLIENT_USERNAME";public static final String FTP_CLIENT_PASSWORD= "FTP_CLIENT_PASSWORD";public static final String TIME_OUT = "TIME_OUT";}NetWorkingConfigs.javapackage .uestc.ablator.ui;import org.eclipse.jface.preference.FieldEditorPreferencePage;import org.eclipse.jface.preference.IPreferenceStore;import org.eclipse.jface.preference.IntegerFieldEditor;import org.eclipse.jface.preference.StringFieldEditor;import org.eclipse.swt.SWT;import yout.GridLayout;import posite;import org.eclipse.swt.widgets.Text;import org.eclipse.ui.IWorkbench;import org.eclipse.ui.IWorkbenchPreferencePage;import workingConfig;public class NetWorkingConfigs extends FieldEditorPreferencePage implementsIWorkbenchPreferencePage {IPreferenceStore preferenceStore;private IntegerFieldEditor containerText;private IntegerFieldEditor ftpText;private StringFieldEditor userText;private StringFieldEditor pwdText;private IntegerFieldEditor timeText;private StringFieldEditor ipText;public NetWorkingConfigs(){super(GRID);setPreferenceStore(Activator.getDefault().getPreferenceStore());setDescription("请修改远程应用仓库配置信息!");//System.out.println(test);}@Overrideprotected void createFieldEditors() {addField(ipText=new StringFieldEditor(NetWorkingName.SERVER_IP, "服务器IP", 18, getFieldEditorParent()));addField(containerText=new IntegerFieldEditor(NetWorkingName.SERVER_LISTENING_PORT, "服务器端口", getFieldEditorParent(), 5));addField(ftpText=new IntegerFieldEditor(NetWorkingName.FTP_SERVER_PORT, "服务器FTP端口", getFieldEditorParent(), 5));addField(timeText=new IntegerFieldEditor(NetWorkingName.TIME_OUT, "超时时间/毫秒", getFieldEditorParent(), 6));addField(userText=new StringFieldEditor(NetWorkingName.FTP_CLIENT_USERNAME, "用户名", 18, getFieldEditorParent()));addField(pwdText=new StringFieldEditor(NetWorkingName.FTP_CLIENT_PASSWORD, "密码", 18, getFieldEditorParent()));}@Overridepublic void init(IWorkbench workbench) {// TODO Auto-generated method stubsetPreferenceStore(Activator.getDefault().getPreferenceStore());//System.out.println(test);//preferenceStore.getDefaultString(NetWorkingName.SERVER_IP);}public void ConnectionAll(){NetworkingConfig.setSERVER_IP(getPreferenceStore().getString(NetWorkingName.SERVER_IP));NetworkingConfig.setSERVER_LISTENING_PORT(getPreferenceStore().getInt(NetWorkingName.SERVE R_LISTENING_PORT));NetworkingConfig.setFTP_SERVER_PORT(getPreferenceStore().getInt(NetWorkingName.FTP_SERVER_ PORT));NetworkingConfig.setTIME_OUT(getPreferenceStore().getInt(NetWorkingName.TIME_OUT));NetworkingConfig.setFTP_CLIENT_USERNAME(getPreferenceStore().getString(NetWorkingName.FTP_ CLIENT_USERNAME));NetworkingConfig.setFTP_CLIENT_PASSWORD(getPreferenceStore().getString(NetWorkingName.FTP_ CLIENT_PASSWORD));}@Overridepublic boolean performOk() {// TODO Auto-generated method stub//performApply();return super.performOk();}@Overrideprotected void performApply() {// TODO Auto-generated method stub//preferenceStore.setValue(NetWorkingName.SERVER_IP, ""+ipText.getStringValue());//preferenceStore.setDefault(name, value)setValue();super.performApply();}public void setValue(){NetworkingConfig.setSERVER_IP(ipText.getStringValue());NetworkingConfig.setSERVER_LISTENING_PORT(containerText.getIntValue());NetworkingConfig.setFTP_SERVER_PORT(ftpText.getIntValue());NetworkingConfig.setTIME_OUT(timeText.getIntValue());NetworkingConfig.setFTP_CLIENT_USERNAME(userText.getStringValue());NetworkingConfig.setFTP_CLIENT_PASSWORD(pwdText.getStringValue());}@Overrideprotected void performDefaults() {// TODO Auto-generated method stubpreferenceStore=getPreferenceStore();super.performDefaults();}}TemplateInfo.javapackage .uestc.ablator.ui.template;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import org.apache.log4j.Logger;import org.eclipse.cdt.core.model.CModelException;import org.eclipse.cdt.core.model.CoreModel;import org.eclipse.cdt.core.model.ICProject;import org.eclipse.core.resources.IProject;import org.eclipse.core.runtime.IProgressMonitor;import mon.Option;import .uestc.ablator.ui.template.entry.AblatorFile;import .uestc.ablator.ui.template.entry.AblatorFolder;import .uestc.ablator.ui.template.entry.AblatorIncludePath;import .uestc.ablator.ui.template.entry.AblatorSourceFolder;import .uestc.ablator.ui.template.entry.Entry;import .uestc.ablator.ui.util.MessageConfig;/*** 模板信息,类似于CDT Template中的template.xml* 包含生成模板的所有信息* @author Administrator**/public class TemplateInfo {private Logger logger = Logger.getLogger(MessageConfig.LOGGER_NAME);//对于有可选项的Info该属性表示可选项,对于无可项的Info该项optionList.size()==0 //文件的替换变量在manifest.xml中指出选private List<Option> optionList;//对应模板文件中的所有实体private List<Entry> entryList;private String sourceFolderPath;private Entry projectEntry;//绝对路径前缀,即工程路径private String absPathPrefix;public String getAbsPathPrefix() {return absPathPrefix;}public void setAbsPathPrefix(String absPathPrefix) {this.absPathPrefix = absPathPrefix;}public TemplateInfo(){entryList = new ArrayList<Entry>();optionList = new ArrayList<Option>();}public List<Entry> getEntryList(){return this.entryList;}public String getSourceFolderPath(){return this.sourceFolderPath;}public void setSourceFolderPath(String path){this.sourceFolderPath = path;}public void addEntry(Entry entry){entryList.add(entry);}public Entry getLast(){if(entryList.size()>0)return entryList.get(entryList.size()-1);return null;}/*** 根据TemplateInfo保存的信息创建完整的工程* @param project*/public IProject createProject(IProject project,IProgressMonitor monitor){IProject newProject = project;ICProject cProject = CoreModel.getDefault().create(project);int totalWork = entryList.size();monitor.beginTask("TemplateInfo create", totalWork);//remove the Project EntryentryList.remove(projectEntry);for(Entry entry : entryList){//folderif(entry.isCommonFolder){//new AblatorFolder().createFolder(newProject, entry);AblatorFolder.createFolder(newProject, entry);//如果该实体是源文件夹,为工程添加该源文件夹if(entry.isSourceFolder){try {//new AblatorSourceFolder().setSourceFolder(cProject, entry);AblatorSourceFolder.setSourceFolder(cProject, entry);} catch (CModelException e) {logger.error(e);}}}//fileelse{if(this.optionList.size()>0)//if Options exist, need replaceAblatorFile.createFileWithReplacement(newProject,entry,getReplaceMap());elseAblatorFile.createFile(newProject, entry);}}try {//append include pathsAblatorIncludePath.addIncludePath(cProject);} catch (CModelException e) {logger.error("CModelException: "+e);}monitor.worked(totalWork);monitor.done();return newProject;}/*** 生成替换变量的map* @return*/private Map<String, String> getReplaceMap() {Map<String,String> map = new HashMap<String,String>();for(Option o:optionList)map.put(o.getGroup().getGroupPlaceHolder(), o.getName());return map;}/*** 通过List Options,添加Entry 到TemplateInfo* @param options*/public void addOptions(List<Option> options) {this.optionList = options;projectEntry = entryList.get(entryList.size()-1);Entry optionFolderEntry = new Entry("//"+MessageConfig.OPTION_FOLDER_NAME, MessageConfig.OPTION_FOLDER_NAME);optionFolderEntry.setParent(projectEntry);optionFolderEntry.isCommonFolder = true;entryList.add(optionFolderEntry);for(Option o : options){Entry optionEntry = new Entry(MessageConfig.OPTION_FOLDER_NAME+"\\"+o.getName(), o.getName());optionEntry.setParent(optionFolderEntry);optionEntry.setTemplateFileAbsolutePath(absPathPrefix+"\\"+optionEntry.getPath());entryList.add(optionEntry);}}}PerferenceInitializer.javapackage .uestc.ablator.ui;import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;import org.eclipse.jface.preference.IPreferenceStore;public class PerferenceInitializer extends AbstractPreferenceInitializer {@Overridepublic void initializeDefaultPreferences() {// TODO Auto-generated method stubIPreferenceStore store=Activator.getDefault().getPreferenceStore();store.setDefault(NetWorkingName.SERVER_IP, "192.168.1.110");store.setDefault(NetWorkingName.SERVER_LISTENING_PORT, 8821);store.setDefault(NetWorkingName.FTP_SERVER_PORT, 21);store.setDefault(NetWorkingName.TIME_OUT, 5000);store.setDefault(NetWorkingName.FTP_CLIENT_USERNAME, "rtlab");store.setDefault(NetWorkingName.FTP_CLIENT_PASSWORD, "rtlab");}}TemplateInfoFactory.javapackage .uestc.ablator.ui.template;import java.io.File;import org.eclipse.jface.dialogs.MessageDialog;import .uestc.ablator.ui.template.entry.Entry;import .uestc.ablator.ui.util.MessageConfig;import .uestc.ablator.ui.util.XmlParser;/*** 根据id 生成TemplateInfo*/public class TemplateInfoFactory {private TemplateInfo templateInfo;private String templateId;/*** 通过id生成模板的TemplateInfo,不包括options目录及其子文件* @param id*/public TemplateInfo createTemplateInfo(String id){this.templateId = id;XmlParser parser = XmlParser.getInstance();File file = parser.findFileById(templateId);if(!file.exists()){MessageDialog.openError(null, "error", "文件"+file.getAbsolutePath()+"不存在");return null;}createTargetTemplateInfo(file,null);return this.templateInfo;}/*** 创建TemplateInfo,其中entry保存源文件路径和目标文件路径,方便后期进行文件复制* 同时保存源文件夹名e.g. /src* @param inputFile* @param parent* @return*/private TemplateInfo createTargetTemplateInfo(File inputFile,Entry parent){TemplateInfo templateInfo= createTemplate(inputFile,parent);//递归栈Entry projectEntry = templateInfo.getLast();//绝对路径前缀String projectPath = projectEntry.getPath();// ("absolute path prefix: "+projectPath);for(Entry ed :templateInfo.getEntryList()){//保存模板文件的绝对路径,以便文件拷贝ed.setTemplateFileAbsolutePath(ed.getPath());String path = ed.getPath().substring(projectPath.length(), ed.getPath().length());ed.setPath(path);}templateInfo.setSourceFolderPath(XmlParser.getInstance().getSingleSourcePath(templateId));templateInfo.setAbsPathPrefix(projectPath);return templateInfo;}/*** 返回指定id的模板的TemplateInfo,其中Entry的Path为绝对路径* @param inputFile* @param parent* @return*/private TemplateInfo createTemplate(File inputFile,Entry parent){if(!inputFile.getName().equals(MessageConfig.OPTION_FOLDER_NAME)){if(templateInfo==null)templateInfo = new TemplateInfo();String path = inputFile.getAbsolutePath();Entry entry = new Entry(path, inputFile.getName());entry.setParent(parent);if(inputFile.isDirectory()){entry.isCommonFolder = true;//判断当前文件夹是否是源文件夹if(inputFile.getName().equals(XmlParser.getInstance().getSingleSourcePath(templateId)))entry.isSourceFolder = true;File[] fileArray = inputFile.listFiles();if(fileArray.length>0){for(File file : fileArray){createTemplate(file,entry);}}}templateInfo.addEntry(entry);}return templateInfo;}。

相关主题