Author: timotei
Date: Sat Jul 30 09:55:11 2011
New Revision: 50469

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50469&view=rev
Log:
eclipse plugin: let the createProject method
decide if we need a build.xml instead of
needing the caller to decide

Modified:
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/projects/ProjectUtils.java

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/projects/ProjectUtils.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/projects/ProjectUtils.java?rev=50469&r1=50468&r2=50469&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/projects/ProjectUtils.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/projects/ProjectUtils.java 
Sat Jul 30 09:55:11 2011
@@ -21,9 +21,12 @@
 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 @@
         * 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 @@
             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 @@
         * 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 @@
 
                    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 @@
                    if (description == null)
                        handle.create(monitor);
                    else
-                   {
                        handle.create(description, monitor);
-                   }
 
                    if (open)
                        handle.open(monitor);
@@ -143,8 +145,12 @@
                    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$


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to