Push-to-Client の拡張

独立系ソフトウェア・ベンダー (ISV) は、追加の拡張機能を提供し、他のタイプの IDE 構成を伝搬させることができます。 ここでは、Push-to-Client 拡張機能を提供する方法について説明します。

Push-to-Client フィーチャーは、IDE 構成をユーザー間で共有する方法を提供します。 開発者は自身の構成をローカル側でエクスポートできるため、以前の IDE 環境を後で復元することができます。 開発者のチームは、1 つの IDE をセットアップしてから、Push-to-Client によって、その IDE を共通のサーバーで共有できます。 開発者がそのサーバーに接続すると、自身の IDE が自動的に、以前にエクスポートされた構成と同期します。 このようにして、共通の設定をチーム間で共有することができます。

このメカニズムは、ユーザー・インターフェースを処理する基本フレームワークと、特定のタイプの構成を処理する拡張機能を伴った大部分の処理から構成されます。 Push-to-Client はすぐに使用可能な状態になっていて、以下の拡張機能を提供します。

Push-to-Client を提供する方法

一般に、拡張機能のために新しいプラグイン・プロジェクトを作成したい場合があります。 マニフェストにおいて、少なくとも以下の依存関係を組み込むことが必要になります。
com.ibm.etools.systems.pushtoclient.core
org.eclipse.core.resources
org.eclipse.core.runtime
org.eclipse.ui
次に、configurationExtension 拡張ポイントをプロジェクト plugin.xml ファイルに定義する必要があります。 例えば、以下のとおりです。
<extension
      point="com.ibm.etools.systems.pushtoclient.core.configurationExtensions">
   <configurationExtension
         class="p2c.test.ConfigurationExtension1"
         description="Custom Elements"
         icon="icons/obj.gif"
         id="p2c.test.configurationExtension1"
         name="Test Extension">
   </configurationExtension>
</extension>
それぞれの拡張機能に classdescriptioniconid、および name が必要です。 このコントリビューションの機能は、クラスに組み込まれています。 クラスは IConfigurationExtension を実装している必要があります。 多くの場合、ConfigurationExtension 実装を拡張することが理想的です。
最初は、ご使用のコードは次の例のようになります。
package p2c.test;

import com.ibm.etools.systems.pushtoclient.core.extensions.IConfigurationElement;
import com.ibm.etools.systems.pushtoclient.core.extensions.ConfigurationElement;
import com.ibm.etools.systems.pushtoclient.core.extensions.ConfigurationExtension;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.IProgressMonitor;

public class ConfigurationExtension1 extends ConfigurationExtension {

	public ConfigurationExtension1(String id, String name, String description){
		super(id, name, description);
	}
構成拡張において、操作するモデル・オブジェクトは IConfigurationElement で、そのデフォルト実装は ConfigurationElement です。 これらのエレメントは、近隣のチェック・ボックスを選択または選択解除することを目的に、ユーザーに表示される情報の単位を表します。 それぞれのエレメントが、記述情報とオプションの子を持っています。 構成エレメントを使用して、以下の 4 つのメソッドそれぞれを定義する必要があります。
  • public void populateExportElements(IConfigurationElement parent)
  • public void exportToCache(IConfigurationElement element,IFolder cacheFolder, IProgressMonitor monitor)
  • public void populateImportElements(IConfigurationElement parent)
  • public void importToWorkspace(IConfigurationElement element, IProgressMonitor monitor)
メソッド populateExportElements() によって、ユーザーは、ウィザードでエクスポートされる構成のエレメントを決定できます。 最も単純なケースでは、親がデフォルトでエクスポートに設定されるかどうかを指示することのみ必要になります。 例えば、以下のとおりです。
public void populateExportElements(IConfigurationElement parent){
	parent.setToExport(true);
}
この場合、ユーザーは、すべての構成情報を取り出すか、または何も取り出さないかだけを選択できます。
もう少し複雑な次の例では、エクスポートにおける個別の成果物を表すエレメントが作成されます。
@Override
public void populateExportElements(
		IConfigurationElement parent) {
	// folder representing one category of items
	ConfigurationElement folderElement = new ConfigurationElement("Element X", "Custom properties X");
	parent.add(folderElement);

	// contents of first category
	ConfigurationElement stuff = new ConfigurationElement("X child element", "");
	stuff.setToExport(true);
	folderElement.add(stuff);
	folderElement.setToExport(true);

	// folder representing another category of items
	ConfigurationElement folderElement2 = new ConfigurationElement("Element Y", "Custom properties Y");
	parent.add(folderElement2);

	// contents of the second category
	ConfigurationElement thing1 = new ConfigurationElement("Y child element 1", "");
	folderElement2.add(thing1);
	thing1.setToExport(true);

	ConfigurationElement thing2 = new ConfigurationElement("Y child element 2", "");
	folderElement2.add(thing2);
	folderElement2.setToExport(true);

	parent.setToExport(true);
}

Push-to-Client ウィザードによるエクスポートでは、エレメントは次のように表示されます。

「エクスポート」ウィザードのカスタマイズ

拡張機能「Test Extension」のルート・エレメントの名前および説明は拡張ポイントから取られますが、子エレメントは populateExportElements() の実装によって作成されます。

exportToCache() メソッドは、ユーザーがエクスポート・ウィザードを終了したときに呼び出されます。 構成拡張のエレメントが渡され、選択された項目に応じて、対応する構成成果物が、指定された cachedFolder ディレクトリーの下のフォーマットで保存されます。 このフォーマットは、インプリメンターによって決定されます。 この cachedFolder ディレクトリーは、構成拡張ごとに固有のもので、構成 id を名前として使用します。

exportToCache() の実装の例:
@Override
public void exportToCache(IConfigurationElement element,
		IFolder cacheFolder, IProgressMonitor monitor) {			
	// find all the elements that are "set to export" and
	// then save to the cache folder
	if (element.hasChildren()){			
		IConfigurationElement[] folders = element.getChildren();
		for (IConfigurationElement folder: folders){
			if (folder.isSetToExport()){
				IConfigurationElement[] children = folder.getChildren();
				for (IConfigurationElement child: children){
					if (child.isSetToExport()){
						// store in model for export
						...
					}						
				}
			}
		}
		
		// create file to store exported information
		IFile file = cacheFolder.getFile(new Path("test.properties"));
		...
	}
}

構成がキャッシュ・ディレクトリーにエクスポートされた後、基本 Push-to-Client フレームワークは残りの操作を処理します。 ローカル・ロケーションにエクスポートする場合、キャッシュされた情報はそのロケーションにアーカイブされます。共通サーバーにエクスポートする場合、変更された情報がアーカイブされ、そのサーバーに転送されます。

構成をインポートするとき、Push-to-Client フレームワークは、エクスポートされた構成アーカイブをまず Eclipse ワークスペースにダウンロードしてから、アーカイブの内容を RemoteSystemsTempFiles フォルダーに解凍します。 エクスポートと同様、インポートでも、構成拡張ごとにキャッシュ・フォルダーがあります。これは、エクスポートに使用されるものと同じフォルダーです。 インポート・ウィザードは、インポートするエレメントについてユーザーにプロンプトを出す必要があります。 populateExportElements() と同様に、それぞれの構成拡張は、受信する情報を表す構成エレメントを作成することによって、populateImportElements() を実装しています。 このメソッド用の唯一のパラメーターは、ご使用の構成拡張のキャッシュ・フォルダーを返すエレメントです。

次の例では、情報を test.properties ファイルから取り出すことによって、構成のエレメント階層が作成されます。
@Override
public void populateImportElements(
		IConfigurationElement parent) {

	// parent file is the cached folder for this configuration
	File parentFile = parent.getFile();
	
	// test.properties is contained in the parent folder
	File testFile = new File(parentFile, "test.properties");
	
	// read and parse the file and populate import elements based on contents of testFile
	...

インポートへの応答として、次のダイアログが表示されます。 通常、インポートされるものすべてがデフォルトで選択されています。

カスタマイズされた「インポート」ウィザード

実装する最後のメソッドは importToWorkspace() です。 このメソッドは、ユーザーがインポート・ダイアログで「OK」をクリックした後で呼び出されます。 構成用に選択されたエレメントは、このメソッドに受け渡されます。情報を構成拡張キャッシュ・フォルダーから取り出して、それをワークスペースに適用するのは、インプリメンターのジョブです。
@Override
public void importToWorkspace(IConfigurationElement element,
		IProgressMonitor monitor) {
	// find all the elements that are "set to export" (same as "set to import")
	if (element.hasChildren()){			
		IConfigurationElement[] folders = element.getChildren();
		for (IConfigurationElement folder: folders){
			if (folder.isSetToExport()){
				IConfigurationElement[] children = folder.getChildren();
				for (IConfigurationElement child: children){
					if (child.isSetToExport()){
						// transfer the corresponding information to the workspace					...
					}						
				}
			}
		}
	}
}

フィードバック