eclipse plugin: Polish a bit the project creation routines
This commit is contained in:
parent
0db32b1e32
commit
142a1895f5
2 changed files with 26 additions and 32 deletions
|
@ -14,6 +14,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IProjectDescription;
|
import org.eclipse.core.resources.IProjectDescription;
|
||||||
|
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
@ -81,13 +82,18 @@ public class ProjectUtils
|
||||||
public static IProject createWesnothProject( String name, String location,
|
public static IProject createWesnothProject( String name, String location,
|
||||||
String installName, IProgressMonitor monitor )
|
String installName, IProgressMonitor monitor )
|
||||||
{
|
{
|
||||||
IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject( name );
|
IWorkspaceRoot root = ResourcesPlugin.getWorkspace( ).getRoot( );
|
||||||
|
IProject newProject = root.getProject( name );
|
||||||
|
IProjectDescription description = null;
|
||||||
|
|
||||||
IProjectDescription description =
|
// set the path only if the project's location is outside the workspace root
|
||||||
ResourcesPlugin.getWorkspace().newProjectDescription( name );
|
if ( ! location.equals( root.getLocation( ).toOSString( ) ) )
|
||||||
description.setLocation( new Path( location ) );
|
{
|
||||||
|
description = ResourcesPlugin.getWorkspace().newProjectDescription( name );
|
||||||
|
description.setLocation( new Path( location ) );
|
||||||
|
}
|
||||||
|
|
||||||
createWesnothProject( newProject, description, installName, true, monitor );
|
createWesnothProject( newProject, description, installName, monitor );
|
||||||
|
|
||||||
return newProject;
|
return newProject;
|
||||||
}
|
}
|
||||||
|
@ -99,12 +105,11 @@ public class ProjectUtils
|
||||||
* @param handle the handle to the project
|
* @param handle the handle to the project
|
||||||
* @param description the default description used when the project is created
|
* @param description the default description used when the project is created
|
||||||
* @param installName The name of the install this project belongs to
|
* @param installName The name of the install this project belongs to
|
||||||
* @param open True to open the project after it was created
|
|
||||||
* @param monitor the monitor will do a 30 worked amount in the method
|
* @param monitor the monitor will do a 30 worked amount in the method
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
public static int createWesnothProject( IProject handle, IProjectDescription description,
|
public static int createWesnothProject( IProject handle, IProjectDescription description,
|
||||||
String installName, boolean open, IProgressMonitor monitor)
|
String installName, IProgressMonitor monitor)
|
||||||
{
|
{
|
||||||
if ( handle == null || handle.exists() )
|
if ( handle == null || handle.exists() )
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -113,9 +118,15 @@ public class ProjectUtils
|
||||||
String projectPath = null;
|
String projectPath = null;
|
||||||
|
|
||||||
if (handle.getLocation() == null && description != null)
|
if (handle.getLocation() == null && description != null)
|
||||||
projectPath = description.getLocationURI().toString();
|
projectPath = description.getLocationURI().toString( ).substring( 1 );
|
||||||
else
|
else if ( handle.getLocation( ) != null )
|
||||||
projectPath = handle.getLocation().toOSString();
|
projectPath = handle.getLocation().toOSString();
|
||||||
|
else // project is in workspace
|
||||||
|
projectPath =
|
||||||
|
ResourcesPlugin.getWorkspace( ).getRoot( ).getLocation( ).toOSString( )
|
||||||
|
+ "/" + handle.getProject( ).getName( );
|
||||||
|
|
||||||
|
System.out.println( projectPath );
|
||||||
|
|
||||||
monitor.subTask(Messages.ProjectUtils_0);
|
monitor.subTask(Messages.ProjectUtils_0);
|
||||||
|
|
||||||
|
@ -126,15 +137,14 @@ public class ProjectUtils
|
||||||
monitor.worked(5);
|
monitor.worked(5);
|
||||||
|
|
||||||
monitor.subTask(String.format(Messages.ProjectUtils_4, handle.getName()));
|
monitor.subTask(String.format(Messages.ProjectUtils_4, handle.getName()));
|
||||||
// create the project
|
|
||||||
|
|
||||||
|
// create the project
|
||||||
if (description == null)
|
if (description == null)
|
||||||
handle.create(monitor);
|
handle.create(monitor);
|
||||||
else
|
else
|
||||||
handle.create(description, monitor);
|
handle.create(description, monitor);
|
||||||
|
|
||||||
if (open)
|
handle.open(monitor);
|
||||||
handle.open(monitor);
|
|
||||||
monitor.worked(10);
|
monitor.worked(10);
|
||||||
|
|
||||||
monitor.subTask(Messages.ProjectUtils_6);
|
monitor.subTask(Messages.ProjectUtils_6);
|
||||||
|
|
|
@ -11,8 +11,6 @@ package org.wesnoth.wizards;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IProjectDescription;
|
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
|
@ -100,23 +98,9 @@ public class WizardProjectPageTemplate extends WizardNewProjectCreationPage
|
||||||
{
|
{
|
||||||
monitor.subTask( "Creating the project structure");
|
monitor.subTask( "Creating the project structure");
|
||||||
|
|
||||||
IProject currentProject = getProjectHandle();
|
IProject currentProject = ProjectUtils.createWesnothProject(
|
||||||
|
getProjectName( ), getLocationPath( ).toOSString( ),
|
||||||
// the project
|
getSelectedInstallName( ), monitor );
|
||||||
if ( getLocationPath().equals(ResourcesPlugin.getWorkspace().getRoot().getLocation()))
|
|
||||||
{
|
|
||||||
ProjectUtils.createWesnothProject(currentProject, null,
|
|
||||||
getSelectedInstallName( ), true, monitor);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IProjectDescription newDescription = ResourcesPlugin.getWorkspace().
|
|
||||||
newProjectDescription(getProjectName());
|
|
||||||
newDescription.setLocation(getLocationPath());
|
|
||||||
ProjectUtils.createWesnothProject(currentProject, newDescription,
|
|
||||||
getSelectedInstallName( ), true, monitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
monitor.worked(2);
|
monitor.worked(2);
|
||||||
|
|
||||||
String projectTemplate =
|
String projectTemplate =
|
||||||
|
|
Loading…
Add table
Reference in a new issue