eclipse plugin: let the createProject method...

...decide if we need a build.xml instead of needing the caller to decide
This commit is contained in:
Timotei Dolean 2011-07-30 07:55:11 +00:00
parent a65b020516
commit b097137520

View file

@ -21,9 +21,12 @@ import org.eclipse.core.runtime.Path;
import org.wesnoth.Constants;
import org.wesnoth.Logger;
import org.wesnoth.Messages;
import org.wesnoth.preferences.Preferences;
import org.wesnoth.preferences.Preferences.Paths;
import org.wesnoth.templates.ReplaceableParameter;
import org.wesnoth.templates.TemplateProvider;
import org.wesnoth.utils.ResourceUtils;
import org.wesnoth.utils.StringUtils;
public class ProjectUtils
{
@ -71,11 +74,12 @@ public class ProjectUtils
* and on the specified location on disk
* @param name The name of the new project
* @param location The location of the new project
* @param installName The name of the install this project belongs to
* @return A project handle
* @throws CoreException
*/
public static IProject createWesnothProject( String name, String location,
boolean createBuildXML, IProgressMonitor monitor )
String installName, IProgressMonitor monitor )
{
IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject( name );
@ -83,7 +87,7 @@ public class ProjectUtils
ResourcesPlugin.getWorkspace().newProjectDescription( name );
description.setLocation( new Path( location ) );
createWesnothProject( newProject, description, true, createBuildXML, monitor );
createWesnothProject( newProject, description, installName, true, monitor );
return newProject;
}
@ -94,11 +98,13 @@ public class ProjectUtils
* no modifications done by this method.
* @param handle the handle to the project
* @param description the default description used when the project is created
* @param the monitor will do a 30 worked amount in the method
* @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
* @throws CoreException
*/
public static int createWesnothProject(IProject handle, IProjectDescription description,
boolean open, boolean createBuildXML, IProgressMonitor monitor)
public static int createWesnothProject( IProject handle, IProjectDescription description,
String installName, boolean open, IProgressMonitor monitor)
{
if ( handle == null || handle.exists() )
return -1;
@ -108,17 +114,15 @@ public class ProjectUtils
if (handle.getLocation() == null && description != null)
projectPath = description.getLocationURI().toString();
else if (handle.getLocation() != null)
else
projectPath = handle.getLocation().toOSString();
monitor.subTask(Messages.ProjectUtils_0);
if (projectPath != null)
{
// cleanup existing files
ResourceUtils.removeFile(projectPath + "/.wesnoth"); //$NON-NLS-1$
ResourceUtils.removeFile(projectPath + "/.project"); //$NON-NLS-1$
ResourceUtils.removeFile(projectPath + "/.build.xml"); //$NON-NLS-1$
}
// cleanup existing files
ResourceUtils.removeFile(projectPath + "/.wesnoth"); //$NON-NLS-1$
ResourceUtils.removeFile(projectPath + "/.project"); //$NON-NLS-1$
ResourceUtils.removeFile(projectPath + "/.build.xml"); //$NON-NLS-1$
monitor.worked(5);
monitor.subTask(String.format(Messages.ProjectUtils_4, handle.getName()));
@ -127,9 +131,7 @@ public class ProjectUtils
if (description == null)
handle.create(monitor);
else
{
handle.create(description, monitor);
}
if (open)
handle.open(monitor);
@ -143,8 +145,12 @@ public class ProjectUtils
handle.setDescription(tmpDescription, monitor);
monitor.worked(5);
// add the build.xml file
if (createBuildXML)
// add the build.xml file, but only if the project is not located
// into the data/campaigns or user's /addons directory
Paths paths = Preferences.getPaths( installName );
String normalizedPath = StringUtils.normalizePath( projectPath );
if ( ! normalizedPath.contains( StringUtils.normalizePath( paths.getCampaignDir( ) ) ) &&
! normalizedPath.contains( StringUtils.normalizePath( paths.getAddonsDir( ) ) ) )
{
ArrayList<ReplaceableParameter> param = new ArrayList<ReplaceableParameter>();
param.add(new ReplaceableParameter("$$project_name", handle.getName())); //$NON-NLS-1$