push-to-client 확장

솔루션파트너(ISV)는 다른 유형의 IDE 구성을 전파하도록 허용함으로써 추가적인 확장기능을 제공할 수 있습니다. 이 정보에서는 push-to-client 확장기능을 제공하는 방법에 대해 설명합니다.

push-to-client 기능은 사용자 간에 IDE 구성을 공유하는 수단을 제공합니다. 개발자는 나중에 이전 IDE 환경을 복원할 수 있도록 자신의 구성을 로컬로 내보낼 수 있습니다. 개발자 팀의 경우 단일 IDE를 설정한 후 push-to-client를 통해 공통 서버에서 해당 IDE를 공유할 수 있습니다. 개발자가 해당 서버에 연결하면 개발자의 IDE를 이전에 내보낸 구성과 자동으로 동기화하게 됩니다. 이러한 방식으로 팀 간에 공통 설정을 공유할 수 있습니다.

이 메커니즘은 사용자 인터페이스 및 대부분의 처리를 담당하는 기본 프레임워크와 특정 유형의 구성을 처리하는 확장기능으로 구성되어 있습니다. push-to-client는 별도의 설정 없이 즉시 다음과 같은 확장기능을 제공합니다.

push-to-client에 포함하는 방법

일반적으로 사용자는 확장기능을 위한 새 플러그인 프로젝트를 작성하게 됩니다. Manifest에는 최소한 다음과 같은 종속 항목을 포함시켜야 합니다.
com.ibm.etools.systems.pushtoclient.core
org.eclipse.core.resources
org.eclipse.core.runtime
org.eclipse.ui
그런 다음 프로젝트 plugin.xml에서 configurationExtension 확장점을 정의해야 합니다. 예를 들면 다음과 같습니다.
<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>
각 확장기능에는 class, description, icon, idname이 포함되어야 합니다. 참가 기능은 클래스에 임베드되어 있습니다. 클래스는 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입니다. 이러한 요소는 인접한 선택란을 선택 또는 선택 취소하기 위해 사용자에게 표시되는 정보의 단위를 표시합니다. 각 요소에는 설명 정보 및 선택적 하위가 있습니다. 구성 요소를 사용하여 다음 네 개의 메소드를 각각 정의해야 합니다.
  • 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()입니다. 이 메소드는 사용자가 가져오기 대화 상자에서 확인을 클릭하면 호출됩니다. 해당 구성에서 선택한 요소는 이 메소드에 제출되며 구성 확장기능 캐시 폴더에서 정보를 가져와 해당 정보를 작업공간에 적용하는 것은 구현자가 담당합니다.
@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					...
					}						
				}
			}
		}
	}
}

피드백