[openrtm-commit:00488] r223 - in trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder: . nl ui/editors ui/preference util

openrtm @ openrtm.org openrtm @ openrtm.org
2011年 12月 17日 (土) 12:59:17 JST


Author: sakamoto
Date: 2011-12-17 12:59:17 +0900 (Sat, 17 Dec 2011)
New Revision: 223

Modified:
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/Generator.java
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/nl/messages.properties
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/BasicEditorFormPage.java
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/IMessageConstants.java
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/preference/CodeGeneratePreferencePage.java
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/preference/ComponentPreferenceManager.java
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/preference/IPreferenceMessageConstants.java
   trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/util/FileUtil.java
Log:
Modified Backup File #2298

Modified: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/Generator.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/Generator.java	2011-12-17 03:58:52 UTC (rev 222)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/Generator.java	2011-12-17 03:59:17 UTC (rev 223)
@@ -477,6 +477,8 @@
 					} catch (CoreException e) {
 						e.printStackTrace();
 					}
+					//バックアップファイルの整理
+					FileUtil.removeBackupFiles(outputProject, generatedResult.getName());
 				}
 			}
 		} else {

Modified: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/nl/messages.properties
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/nl/messages.properties	2011-12-17 03:58:52 UTC (rev 222)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/nl/messages.properties	2011-12-17 03:59:17 UTC (rev 223)
@@ -408,15 +408,13 @@
 
 IMessageConstants.CREATE_FILE_ERROR=Failed to create file.
 
-
 IMessageConstants.FILETYPE_YAML=YAML format
 
-
 IMessageConstants.COMPARE_TITLE=Result Comparison :
 
-
 IMessageConstants.COMMON_LABEL_UPDATE=Update
 
+IMessageConstants.BACKUP_FILE_NUM=Backup File Max Number :
 
 IMessageConstants.TITLE_FONT=MS Gothic
 
@@ -468,6 +466,8 @@
 IPreferenceMessageConstants.CODE_GEN_TITLE_CONFIG=Configuration
 IPreferenceMessageConstants.CODE_GEN_TITLE_PRESUFFIX=Prefix,Suffix
 
+IPreferenceMessageConstants.CODE_GEN_TITLE_BACKUP=Backup
+
 IPreferenceMessageConstants.CONFIG_CLMN_CONFIGURATION=Configuration
 IPreferenceMessageConstants.CONFIG_CLMN_DEFAUT_VALUE=Default Value
 IPreferenceMessageConstants.CONFIG_BTN_ADD=Add

Modified: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/BasicEditorFormPage.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/BasicEditorFormPage.java	2011-12-17 03:58:52 UTC (rev 222)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/BasicEditorFormPage.java	2011-12-17 03:59:17 UTC (rev 223)
@@ -1,7 +1,11 @@
 package jp.go.aist.rtm.rtcbuilder.ui.editors;
 
 import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.GregorianCalendar;
 import java.util.Iterator;
 import java.util.List;
@@ -21,9 +25,11 @@
 import jp.go.aist.rtm.rtcbuilder.ui.Perspective.LanguageProperty;
 import jp.go.aist.rtm.rtcbuilder.ui.preference.ComponentPreferenceManager;
 import jp.go.aist.rtm.rtcbuilder.ui.wizard.RtcExportWizard;
+import jp.go.aist.rtm.rtcbuilder.util.FileUtil;
 import jp.go.aist.rtm.rtcbuilder.util.StringUtil;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IProjectDescription;
 import org.eclipse.core.resources.IResource;
@@ -390,6 +396,8 @@
 					if (orgRtcxml.exists()) {
 						IFile renameFile = project.getFile(IRtcBuilderConstants.DEFAULT_RTC_XML + DATE_FORMAT.format(new GregorianCalendar().getTime()) );
 						orgRtcxml.move(renameFile.getFullPath(), true, null);
+						//バックアップ最大数以上のファイルは削除
+						FileUtil.removeBackupFiles(project, IRtcBuilderConstants.DEFAULT_RTC_XML);
 					}
 					IFile saveRtcxml = project.getFile(IRtcBuilderConstants.DEFAULT_RTC_XML);
 					saveRtcxml.create(new ByteArrayInputStream(strXml.getBytes("UTF-8")), true, null);

Modified: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/IMessageConstants.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/IMessageConstants.java	2011-12-17 03:58:52 UTC (rev 222)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/editors/IMessageConstants.java	2011-12-17 03:59:17 UTC (rev 223)
@@ -454,17 +454,12 @@
 	public static final String PROFILE_COMPARE_MESSAGE = StringUtil.connectMessageWithSepalator( new String[]{PROFILE_COMPARE_MESSAGE_P1, PROFILE_COMPARE_MESSAGE_P2});
 
 	public static final String CREATE_FILE_ERROR = Messages.getString("IMessageConstants.CREATE_FILE_ERROR"); //$NON-NLS-1$
-
-
 	public static final String FILETYPE_YAML = Messages.getString("IMessageConstants.FILETYPE_YAML"); //$NON-NLS-1$
-
-
 	public static final String COMPARE_TITLE = Messages.getString("IMessageConstants.COMPARE_TITLE"); //$NON-NLS-1$
-
-
 	public static final String COMMON_LABEL_UPDATE = Messages.getString("IMessageConstants.COMMON_LABEL_UPDATE"); //$NON-NLS-1$
 
-
+	public static final String BACKUP_FILE_NUM = Messages.getString("IMessageConstants.BACKUP_FILE_NUM"); //$NON-NLS-1$
+	
 	public static final String TITLE_FONT = Messages.getString("IMessageConstants.TITLE_FONT"); //$NON-NLS-1$
 
 	public static final String PROFILE_VALIDATE_ERROR_MESSAGE = Messages.getString("IMessageConstants.PROFILE_VALIDATE_ERROR_MESSAGE"); //$NON-NLS-1$

Modified: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/preference/CodeGeneratePreferencePage.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/preference/CodeGeneratePreferencePage.java	2011-12-17 03:58:52 UTC (rev 222)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/preference/CodeGeneratePreferencePage.java	2011-12-17 03:59:17 UTC (rev 223)
@@ -46,6 +46,7 @@
 		IPreferenceStore store = RtcBuilderPlugin.getDefault().getPreferenceStore();
 		storeComponentInitialSetting(store);
 		storeConfigurationSetInitialSetting(store);
+		storeBackupInitialSetting(store);
 	}
 
 	@Override
@@ -57,8 +58,16 @@
 		composite.setLayoutData(gd);
 		createComponentPart(composite);
 		createConfigurationSetParts(composite);
+		createBackupParts(composite);
 	}
 
+	private void createBackupParts(Composite composite) {
+		Composite backupGroup = createGroup(composite, IPreferenceMessageConstants.CODE_GEN_TITLE_BACKUP);
+		IntegerFieldEditor moduleMaxInstanceTextEditor = new IntegerFieldEditor(ComponentPreferenceManager.Generate_Backup_Num,
+				IMessageConstants.BACKUP_FILE_NUM, backupGroup);
+		addField(moduleMaxInstanceTextEditor);
+	}
+	
 	private void createConfigurationSetParts(Composite composite) {
 		Composite configGroup = createGroup(composite, IPreferenceMessageConstants.CODE_GEN_TITLE_CONFIG);
 		DigitAlphabetStringFieldEditor configurationNameEditor = 
@@ -154,6 +163,10 @@
 		addField(commonSuffixEditor);
 	}
 	
+	private void storeBackupInitialSetting(IPreferenceStore store) {
+		store.setDefault(ComponentPreferenceManager.Generate_Backup_Num, ComponentPreferenceManager.DEFAULT_BACKUP_NUM);
+	}
+
 	private void storeConfigurationSetInitialSetting(IPreferenceStore store) {
 		store.setDefault(ComponentPreferenceManager.Generate_Configuration_Name, ComponentPreferenceManager.DEFAULT_CONFIGURATION_NAME);
 		store.setDefault(ComponentPreferenceManager.Generate_Configuration_Type, ComponentPreferenceManager.DEFAULT_CONFIGURATION_TYPE);

Modified: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/preference/ComponentPreferenceManager.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/preference/ComponentPreferenceManager.java	2011-12-17 03:58:52 UTC (rev 222)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/preference/ComponentPreferenceManager.java	2011-12-17 03:59:17 UTC (rev 223)
@@ -153,6 +153,11 @@
 	 * ServiceInterfacet Instance 接尾語のキー
 	 */
 	public static final String Generate_ServiceIF_Suffix = getClassName() + "GENERATE_SERVICEIF_SUFFIX";
+	//
+	/**
+	 * バックアップファイル設定数のキー
+	 */
+	public static final String Generate_Backup_Num = getClassName() + "GENERATE_BACKUP_NUM";
 	
 	//デフォルト値を空白から変更する場合には,getterの定義が必要
 	public static final String DEFAULT_COMPONENT_NAME = "ModuleName";
@@ -195,6 +200,8 @@
 	public static final String DEFAULT_SERVICEIF_VARNAME = "";
 	public static final String DEFAULT_SERVICEIF_PREFIX = "";
 	public static final String DEFAULT_SERVICEIF_SUFFIX = "";
+	//
+	public static final int DEFAULT_BACKUP_NUM = 3;
 	
 	/**
 	 * コード生成時の ModuleName デフォルト値を取得する
@@ -356,6 +363,17 @@
 	public String getServiceIF_Name() {
 		return getStringStoreValue(Generate_ServiceIF_Name, DEFAULT_SERVICEIF_NAME);
 	}
+	//
+	/**
+	 * コード生成時の バックアップファイル数を取得する
+	 * 
+	 * @param key キー
+	 * @return バックアップファイル数 デフォルト値
+	 */
+	public int getBackup_Num() {
+		return getIntegaerStoreValue(Generate_Backup_Num, DEFAULT_BACKUP_NUM);
+	}
+
 	/////
 	private String getStringStoreValue(String key, String defaultValue) {
 		RtcBuilderPlugin.getDefault().getPreferenceStore().setDefault(key, "");

Modified: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/preference/IPreferenceMessageConstants.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/preference/IPreferenceMessageConstants.java	2011-12-17 03:58:52 UTC (rev 222)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/ui/preference/IPreferenceMessageConstants.java	2011-12-17 03:59:17 UTC (rev 223)
@@ -26,6 +26,7 @@
 	public static final String CODE_GEN_TITLE_DOCUMENT = Messages.getString("IPreferenceMessageConstants.CODE_GEN_TITLE_DOCUMENT"); //$NON-NLS-1$
 	public static final String CODE_GEN_TITLE_CONFIG = Messages.getString("IPreferenceMessageConstants.CODE_GEN_TITLE_CONFIG"); //$NON-NLS-1$
 	public static final String CODE_GEN_TITLE_PRESUFFIX = Messages.getString("IPreferenceMessageConstants.CODE_GEN_TITLE_PRESUFFIX"); //$NON-NLS-1$
+	public static final String CODE_GEN_TITLE_BACKUP = Messages.getString("IPreferenceMessageConstants.CODE_GEN_TITLE_BACKUP"); //$NON-NLS-1$
 
 	public static final String CONFIG_CLMN_CONFIGURATION = Messages.getString("IPreferenceMessageConstants.CONFIG_CLMN_CONFIGURATION"); //$NON-NLS-1$
 	public static final String CONFIG_CLMN_DEFAUT_VALUE = Messages.getString("IPreferenceMessageConstants.CONFIG_CLMN_DEFAUT_VALUE"); //$NON-NLS-1$

Modified: trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/util/FileUtil.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/util/FileUtil.java	2011-12-17 03:58:52 UTC (rev 222)
+++ trunk/rtmtools/jp.go.aist.rtm.rtcbuilder/src/jp/go/aist/rtm/rtcbuilder/util/FileUtil.java	2011-12-17 03:59:17 UTC (rev 223)
@@ -5,11 +5,16 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
 import jp.go.aist.rtm.rtcbuilder.IRtcBuilderConstants;
 import jp.go.aist.rtm.rtcbuilder.nl.Messages;
+import jp.go.aist.rtm.rtcbuilder.ui.preference.ComponentPreferenceManager;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.swt.SWT;
@@ -109,4 +114,28 @@
 
 		return result == null ? null : result.toString();
 	}
+	
+	/**
+	 * バックアップファイルの整理を行う
+	 * 
+	 * @param project 対象プロジェクト
+	 * @param targetFile 対象ファイル名
+	 */
+	public static void removeBackupFiles(IProject project, String targetFile) {
+		File dir = new File(project.getLocation().toOSString());
+		File[] files = dir.listFiles();
+		List<String> targets = new ArrayList<String>();
+		for(File target : files) {
+			if( target.getName().startsWith(targetFile) ) {
+				targets.add(target.getName());
+			}
+		}
+		if(ComponentPreferenceManager.getInstance().getBackup_Num() < targets.size()) {
+			Collections.sort(targets);
+			for(int index=0;index<targets.size()-ComponentPreferenceManager.getInstance().getBackup_Num();index++) {
+				File remTarget = new File(project.getLocation().toOSString() + File.separator + targets.get(index));
+				remTarget.delete();
+			}
+		}
+	}
 }



openrtm-commit メーリングリストの案内