2008년 04월 15일
local filesystem에 프로젝트 생성하기
eclipse는 resourcesplugin을 통해 workspace에 프로젝트를 생성한다.
하지만 local filesystem에 생성할수도 있다.
어떻게 하면 될까?
IProjectDescription IWorkspace.newProjectDescription(String projectName)
Creates and returns a new project description for a project with the given name.
IProjectDescription IWorkspace.loadProjectDescription(IPath projectDescriptionFile)
Reads the project description file (".project") from the given location in the local file system.
void IProject.create(IProjectDescription description, IProgressMonitor monitor)
Creates a new project resource in the workspace using the given project description. Upon successful completion, the project will exist but be closed.
String strName = page.getProjectName();
monitor.beginTask("Creating " + strName + " Forrest Project", 3);
IProject project = page.getProjectHandle();
IPath locationPath = page.getLocationPath();
// create the project
IProjectDescription desc = project.getWorkspace()
.newProjectDescription(project.getName());
if (!page.useDefaults()) {
desc.setLocation(locationPath);
}
project.create(desc, new SubProgressMonitor(monitor, 1));
project.open(new SubProgressMonitor(monitor, 1));
# by | 2008/04/15 01:09 | Eclipse | 트랙백 | 덧글(5)




☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
public IStatus validatePath(IPath path, int type, boolean lastSegmentOnly) {
String message;
/* path must not be null */
if (path == null) {
message = Messages.resources_pathNull;
return new ResourceStatus(IResourceStatus.INVALID_VALUE, null, message);
}
/* path must not have a device separator */
if (path.getDevice() != null) {
message = NLS.bind(Messages.resources_invalidCharInPath, String.valueOf(IPath.DEVICE_SEPARATOR), path);
return new ResourceStatus(IResourceStatus.INVALID_VALUE, null, message);
}
/* path must not be the root path */
if (path.isRoot()) {
message = Messages.resources_invalidRoot;
return new ResourceStatus(IResourceStatus.INVALID_VALUE, null, message);
}
/* path must be absolute */
if (!path.isAbsolute()) {
message = NLS.bind(Messages.resources_mustBeAbsolute, path);
return new ResourceStatus(IResourceStatus.INVALID_VALUE, null, message);
}
IProjectDescription projectDesc = workspace.newProjectDescription
("MyProject");
projectDesc.setLocation ("My_Path");
projectDesc.setComment ("Desc of My Project");
IProject project = workspace.getRoot().getProject ("MyProject");
project.create (projectDesc, null);
[OR]
project.create (null, null);
Note: When i create the project with project description gives error as
invalid project description....
this result creates the project in my workspace directory of the RCP
application
please help me out to create the project in my own specified path...
monitor.subTask("´´½¨Ä¿Â¼");
BaseModuleElement element=page1.getBaseModuleElement();
IProject project = root.getProject(element.getIdentifier());
IProjectDescription description=
ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
System.out.println("page1;>>>>"+page1.getLocation());
System.out.println("platform:location>>>"+Platform.getLocation());
//
if(!Platform.getLocation().toOSString().equals(page1.getLocation())){
// description.setLocation(new Path(page1.getLocation()));
IPath path=new Path(page1.getLocation()+"/"+project.getName());
path.toFile().mkdirs();
description.setLocation(path);
description.setComment(page1.getProjectDesc());
description.setNatureIds(new
String[{"com.mbi.designer.plugin.FlowchartPlugin.workflowProjectnature",Java
Core.NATURE_ID});
ICommand command = description.newCommand();
command.setBuilderName("workflowAuditor");
description.setBuildSpec(new ICommand[] { command });
try {
project.create(description,monitor);
// project.create(monitor);
} catch (CoreException e) {
e.printStackTrace();
}
monitor.worked(5);
try {
project.open(monitor);
project.setPersistentProperty(new QualifiedName ("com.mbi.designer",
"project"),"src");
IPath
projectPath=project.getFullPath(),srcPath1=projectPath.append("src"),binPath
1=projectPath.append("bin");
IFolder srcFolder1=root.getFolder(srcPath1);
IFolder binFolder=root.getFolder(binPath1);
IJavaElement javaSrcFolder=JavaCore.create(srcFolder1);
IClasspathEntry srcEntry1 = JavaCore.newSourceEntry(srcPath1,new
Path[]{(Path) binPath1},binPath1);
srcFolder1.create(true,true,monitor);
binFolder.create(true,true,monitor);
IJavaProject javaProj=JavaCore.create(project);
IClasspathEntry[] entries=null;
List cpEntries= new ArrayList();
cpEntries.add(JavaCore.newSourceEntry(projectPath.append(srcPath1)));
IClasspathEntry[] defaultJRELibrary=
PreferenceConstants.getDefaultJRELibrary();
cpEntries.addAll(Arrays.asList(defaultJRELibrary));
entries= (IClasspathEntry[]) cpEntries.toArray(new
IClasspathEntry[cpEntries.size()]);
javaProj.setRawClasspath(entries, null);
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
// if the file is in the default location, use the directory
// name as the project name
if (isDefaultLocation(path)) {
projectName = path.segment(path.segmentCount() - 2);
newDescription = IDEWorkbenchPlugin
.getPluginWorkspace().newProjectDescription(
projectName);
} else {
newDescription = IDEWorkbenchPlugin
.getPluginWorkspace().loadProjectDescription(
path);
}
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProject project = workspace.getRoot().getProject(projectName);
if (record.description == null) {
// error case
record.description = workspace.newProjectDescription(projectName);
IPath locationPath = new Path(record.projectSystemFile
.getAbsolutePath());
// If it is under the root use the default location
if (Platform.getLocation().isPrefixOf(locationPath)) {
record.description.setLocation(null);
} else {
record.description.setLocation(locationPath);
}
}