eclipse plugin: if the paths object is not valid stop creating the project

This commit is contained in:
Timotei Dolean 2012-04-08 19:45:21 +00:00
parent 74beb3d229
commit a2280d0f71
5 changed files with 28 additions and 13 deletions

View file

@ -164,6 +164,7 @@ public class Messages extends NLS
public static String ProjectUtils_0;
public static String ProjectUtils_4;
public static String ProjectUtils_6;
public static String ProjectUtils_7;
public static String ResourceUtils_5;
public static String ScenarioNewWizard_0;
public static String ScenarioNewWizard_2;

View file

@ -189,9 +189,8 @@ public class WesnothInstallsUtils
}
if( GUIUtils
.showMessageBox( String.format(
Messages.WesnothInstallsUtils_1, resource
.getProject( ).getName( ) ),
.showMessageBox( String.format( Messages.WesnothInstallsUtils_1,
resource.getProject( ).getName( ) ),
SWT.ICON_QUESTION | SWT.YES | SWT.NO ) == SWT.NO ) {
return false; // no hope :(
}

View file

@ -147,6 +147,7 @@ PreprocessorUtils_12=The file is null or does not exist
ProjectUtils_0=Cleaning files...
ProjectUtils_4=Creating project '%s' ...
ProjectUtils_6=Configuring project...
ProjectUtils_7=Please select a valid install, or create one if none exists.
ResourceUtils_5=Error creating the resource
ScenarioNewWizard_0=Create a new scenario
ScenarioNewWizard_2=Creating

View file

@ -315,6 +315,11 @@ public class Preferences extends AbstractPreferenceInitializer
installName_ = installName;
}
public boolean isValid( )
{
return installName_ != null && ! installName_.isEmpty( );
}
/**
* Returns the install name associated with this instance
*

View file

@ -31,6 +31,7 @@ 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.GUIUtils;
import org.wesnoth.utils.ResourceUtils;
import org.wesnoth.utils.StringUtils;
import org.wesnoth.views.WesnothProjectsExplorer;
@ -106,6 +107,11 @@ public class ProjectUtils
{
ProjectCache cache = getCacheForProject( project );
Paths paths = Preferences.getPaths( cache.getInstallName( ) );
if( ! paths.isValid( ) ) {
return false;
}
IFolder coreLibrary = project
.getFolder( WesnothProjectsExplorer.CORE_LIBRARY_NAME );
@ -115,17 +121,15 @@ public class ProjectUtils
if( coreLibrary.exists( ) ) {
// the new Core Library will point to the same location.
// Skip it then.
if( coreLibrary.getLocation( ).equals(
paths.getCoreDirPath( ) ) ) {
if( coreLibrary.getLocation( ).equals( paths.getCoreDirPath( ) ) ) {
return true;
}
coreLibrary.delete( true, new NullProgressMonitor( ) );
}
coreLibrary
.createLink( paths.getCoreDirPath( ), updateFlags,
new NullProgressMonitor( ) );
coreLibrary.createLink( paths.getCoreDirPath( ), updateFlags,
new NullProgressMonitor( ) );
coreLibrary.setDerived( true, new NullProgressMonitor( ) );
} catch( CoreException e ) {
@ -135,10 +139,10 @@ public class ProjectUtils
}
else {
Logger.getInstance( ).log(
"Couldn't create link on:" + paths.getCoreDir( )
+ "; project: " + project.getName( ),
"Cannot create the Wesnoth Core Library folder for project "
+ project.getName( ) + "!" );
"Couldn't create link on:" + paths.getCoreDir( ) //$NON-NLS-1$
+ "; project: " + project.getName( ), //$NON-NLS-1$
"Cannot create the Wesnoth Core Library folder for project " //$NON-NLS-1$
+ project.getName( ) + "!" ); //$NON-NLS-1$
return false;
}
@ -237,6 +241,11 @@ public class ProjectUtils
return - 1;
}
if( installName.isEmpty( ) ) {
GUIUtils.showErrorMessageBox( Messages.ProjectUtils_7 );
return - 1;
}
try {
String projectPath = null;
@ -251,7 +260,7 @@ public class ProjectUtils
// project is in workspace
projectPath = ResourcesPlugin.getWorkspace( ).getRoot( )
.getLocation( ).toOSString( )
+ "/" + handle.getProject( ).getName( );
+ "/" + handle.getProject( ).getName( ); //$NON-NLS-1$
}
monitor.subTask( Messages.ProjectUtils_0 );