mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-02 01:00:02 +00:00
eclipse plugin: use a '.wesnoth' file than '.ignore'...
...so we can put more information in the file
This commit is contained in:
parent
ca613f847d
commit
82cc16252f
@ -33,12 +33,11 @@ import wesnoth_eclipse_plugin.Logger;
|
||||
import wesnoth_eclipse_plugin.globalactions.PreprocessorActions;
|
||||
import wesnoth_eclipse_plugin.preferences.Preferences;
|
||||
import wesnoth_eclipse_plugin.utils.AntUtils;
|
||||
import wesnoth_eclipse_plugin.utils.Pair;
|
||||
import wesnoth_eclipse_plugin.utils.ProjectUtils;
|
||||
import wesnoth_eclipse_plugin.utils.ResourceUtils;
|
||||
import wesnoth_eclipse_plugin.utils.StringUtils;
|
||||
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
|
||||
|
||||
//TODO: rewrite and use a ".wesnoth" file to store additional infos instead of just ".ignore"
|
||||
public class WesnothProjectBuilder extends IncrementalProjectBuilder
|
||||
{
|
||||
public static final String WESNOTH_BUILDER_ID = "Wesnoth_Eclipse_Plugin.projectBuilder";
|
||||
@ -47,65 +46,9 @@ public class WesnothProjectBuilder extends IncrementalProjectBuilder
|
||||
private static final String MARKER_TYPE = "Wesnoth_Eclipse_Plugin.configProblem";
|
||||
|
||||
/**
|
||||
* The key is the project name
|
||||
* The value is:
|
||||
* - the last modified date for the .ignore file
|
||||
* - the list with ignored directories names
|
||||
* The 'last modified' timestamp of the '.wesnoth' file
|
||||
*/
|
||||
private static HashMap<String, Pair<Long, List<String>>> ignoreCache_;
|
||||
|
||||
public WesnothProjectBuilder() {
|
||||
if (ignoreCache_ == null)
|
||||
ignoreCache_ = new HashMap<String, Pair<Long, List<String>>>();
|
||||
}
|
||||
|
||||
class SampleDeltaVisitor implements IResourceDeltaVisitor
|
||||
{
|
||||
private IProgressMonitor monitor_;
|
||||
|
||||
public SampleDeltaVisitor(IProgressMonitor monitor) {
|
||||
monitor_ = monitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(IResourceDelta delta) throws CoreException
|
||||
{
|
||||
IResource resource = delta.getResource();
|
||||
switch (delta.getKind())
|
||||
{
|
||||
case IResourceDelta.ADDED:
|
||||
// handle added resource
|
||||
checkResource(resource, monitor_);
|
||||
break;
|
||||
case IResourceDelta.REMOVED:
|
||||
// handle removed resource
|
||||
break;
|
||||
case IResourceDelta.CHANGED:
|
||||
// handle changed resource
|
||||
checkResource(resource, monitor_);
|
||||
break;
|
||||
}
|
||||
// return true to continue visiting children.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class SampleResourceVisitor implements IResourceVisitor
|
||||
{
|
||||
private IProgressMonitor monitor_;
|
||||
|
||||
public SampleResourceVisitor(IProgressMonitor monitor) {
|
||||
monitor_ = monitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(IResource resource)
|
||||
{
|
||||
checkResource(resource, monitor_);
|
||||
// return true to continue visiting children.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
private long wesnothFileLastModified_ = 0;
|
||||
|
||||
protected void fullBuild(final IProgressMonitor monitor) throws CoreException
|
||||
{
|
||||
@ -150,22 +93,7 @@ public class WesnothProjectBuilder extends IncrementalProjectBuilder
|
||||
}
|
||||
monitor.worked(2);
|
||||
|
||||
// get the directories list to ignore
|
||||
File ignoreFile = new File(getProject().getLocation().toOSString() + Path.SEPARATOR + ".ignore");
|
||||
if (!ignoreCache_.containsKey(getProject().getName()) || ignoreFile.lastModified() != ignoreCache_.get(getProject().getName()).First)
|
||||
{
|
||||
String contents = ResourceUtils.getFileContents(ignoreFile);
|
||||
if (contents != null)
|
||||
{
|
||||
List<String> list = new ArrayList<String>();
|
||||
String[] lines = StringUtils.getLines(contents);
|
||||
for (String line : lines)
|
||||
list.add(line);
|
||||
|
||||
ignoreCache_.remove(getProject().getName());
|
||||
ignoreCache_.put(getProject().getName(), new Pair<Long, List<String>>(ignoreFile.lastModified(), list));
|
||||
}
|
||||
}
|
||||
readWesnothFile();
|
||||
monitor.worked(5);
|
||||
|
||||
// Ant copy
|
||||
@ -272,18 +200,65 @@ public class WesnothProjectBuilder extends IncrementalProjectBuilder
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the .wesnoth file and memorizes the information
|
||||
*/
|
||||
private void readWesnothFile()
|
||||
{
|
||||
File wesnothFile = new File(getProject().getLocation().toOSString() + Path.SEPARATOR + ".wesnoth");
|
||||
if (!wesnothFile.exists() || wesnothFile.lastModified() == wesnothFileLastModified_)
|
||||
return;
|
||||
|
||||
HashMap<String, List<String>> preferences = new HashMap<String, List<String>>();
|
||||
|
||||
String contents = ResourceUtils.getFileContents(wesnothFile);
|
||||
if (contents != null)
|
||||
{
|
||||
List<String> ignoreList = new ArrayList<String>();
|
||||
List<String> projSettings = new ArrayList<String>();
|
||||
String[] lines = StringUtils.getLines(contents);
|
||||
// 1 - ignore list | 2 - project settings
|
||||
int step = 0;
|
||||
for (String line : lines)
|
||||
{
|
||||
if (StringUtils.startsWith(line, "#") || line.matches("^[\t ]*$"))
|
||||
continue;
|
||||
|
||||
if (line.startsWith("ignore"))
|
||||
{
|
||||
step = 1; continue;
|
||||
}
|
||||
else if (line.startsWith("settings"))
|
||||
{
|
||||
step = 2; continue;
|
||||
}
|
||||
else if (line.startsWith("end_"))
|
||||
{
|
||||
step = 0; continue;
|
||||
}
|
||||
|
||||
if (step == 1)
|
||||
ignoreList.add(line);
|
||||
if (step == 2)
|
||||
projSettings.add(line);
|
||||
}
|
||||
|
||||
preferences.put("ignore", ignoreList);
|
||||
preferences.put("settings", projSettings);
|
||||
}
|
||||
ProjectUtils.setPreferencesForProject(getProject(), preferences);
|
||||
}
|
||||
|
||||
private boolean isResourceIgnored(IResource res)
|
||||
{
|
||||
// we have an ignore cache
|
||||
if (ignoreCache_.containsKey(getProject().getName()))
|
||||
if (ProjectUtils.getPreferencesForProject(getProject()) == null)
|
||||
return false;
|
||||
List<String> ignoredFiles = ProjectUtils.getPreferencesForProject(getProject()).get("ignore");
|
||||
for (String path : ignoredFiles)
|
||||
{
|
||||
List<String> ignoreList = ignoreCache_.get(getProject().getName()).Second;
|
||||
for (String path : ignoreList)
|
||||
{
|
||||
if (StringUtils.normalizePath(WorkspaceUtils.getPathRelativeToUserDir(res))
|
||||
.contains(StringUtils.normalizePath(path)))
|
||||
return true;
|
||||
}
|
||||
if (StringUtils.normalizePath(WorkspaceUtils.getPathRelativeToUserDir(res))
|
||||
.contains(StringUtils.normalizePath(path)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -316,4 +291,53 @@ public class WesnothProjectBuilder extends IncrementalProjectBuilder
|
||||
Logger.getInstance().logException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SampleDeltaVisitor implements IResourceDeltaVisitor
|
||||
{
|
||||
private IProgressMonitor monitor_;
|
||||
|
||||
public SampleDeltaVisitor(IProgressMonitor monitor) {
|
||||
monitor_ = monitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(IResourceDelta delta) throws CoreException
|
||||
{
|
||||
IResource resource = delta.getResource();
|
||||
switch (delta.getKind())
|
||||
{
|
||||
case IResourceDelta.ADDED:
|
||||
// handle added resource
|
||||
checkResource(resource, monitor_);
|
||||
break;
|
||||
case IResourceDelta.REMOVED:
|
||||
// handle removed resource
|
||||
break;
|
||||
case IResourceDelta.CHANGED:
|
||||
// handle changed resource
|
||||
checkResource(resource, monitor_);
|
||||
break;
|
||||
}
|
||||
// return true to continue visiting children.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class SampleResourceVisitor implements IResourceVisitor
|
||||
{
|
||||
private IProgressMonitor monitor_;
|
||||
|
||||
public SampleResourceVisitor(IProgressMonitor monitor) {
|
||||
monitor_ = monitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(IResource resource)
|
||||
{
|
||||
checkResource(resource, monitor_);
|
||||
// return true to continue visiting children.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,10 @@
|
||||
package wesnoth_eclipse_plugin.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
@ -21,8 +25,48 @@ import wesnoth_eclipse_plugin.Logger;
|
||||
|
||||
public class ProjectUtils
|
||||
{
|
||||
private static HashMap<IProject, HashMap<String, List<String>>> projectPreferences_ =
|
||||
new HashMap<IProject, HashMap<String, List<String>>>();
|
||||
|
||||
public static HashMap<String, List<String>> getPreferencesForProject(IProject project)
|
||||
{
|
||||
return projectPreferences_.get(project);
|
||||
}
|
||||
|
||||
public static void setPreferencesForProject(IProject project, HashMap<String,
|
||||
List<String>> prefs)
|
||||
{
|
||||
projectPreferences_.put(project, prefs);
|
||||
}
|
||||
|
||||
public static HashMap<String, String> getSettingsForProject(IProject project)
|
||||
{
|
||||
HashMap<String, List<String>> pref = getPreferencesForProject(project);
|
||||
if (pref == null)
|
||||
return null;
|
||||
List<String> settingsList = pref.get("settings");
|
||||
HashMap<String, String> settings = new HashMap<String, String>();
|
||||
for (String string : settingsList)
|
||||
{
|
||||
settings.put(string.split("=")[0], string.split("=")[1]);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static void setSettingsForProject(IProject project,HashMap<String, String> settings)
|
||||
{
|
||||
List<String> settingsList = new ArrayList<String>();
|
||||
for (Entry<String,String> key : settings.entrySet())
|
||||
{
|
||||
settingsList.add(key.getKey() + "=" + key.getValue());
|
||||
}
|
||||
HashMap<String, List<String>> prefs = getPreferencesForProject(project);
|
||||
prefs.put("settings",settingsList);
|
||||
setPreferencesForProject(project, prefs);
|
||||
}
|
||||
|
||||
//TODO: create a simple java wmlparsers in order to get the right values
|
||||
public static String getPropertyValue(String fileName, String propertyName)
|
||||
public static String getConfigKeyValue(String fileName, String propertyName)
|
||||
{
|
||||
if (fileName == null || propertyName.isEmpty())
|
||||
return null;
|
||||
@ -102,11 +146,11 @@ public class ProjectUtils
|
||||
|
||||
public static String getCampaignID(IResource resource)
|
||||
{
|
||||
return getPropertyValue(getMainConfigLocation(resource),"id");
|
||||
return getConfigKeyValue(getMainConfigLocation(resource),"id");
|
||||
}
|
||||
public static String getScenarioID(String fileName)
|
||||
{
|
||||
return getPropertyValue(fileName,"id");
|
||||
return getConfigKeyValue(fileName,"id");
|
||||
}
|
||||
|
||||
public static boolean isCampaignFile(String fileName)
|
||||
@ -123,4 +167,6 @@ public class ProjectUtils
|
||||
String fileContentString = ResourceUtils.getFileContents(new File(fileName));
|
||||
return (fileContentString.contains("[scenario]") && fileContentString.contains("[/scenario]"));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -242,7 +242,7 @@ public class WorkspaceUtils
|
||||
TemplateProvider.getInstance().getProcessedTemplate("build_xml", param), true);
|
||||
|
||||
// we need to skip the already created projects (if any) in the addons directory
|
||||
String skipList = "";
|
||||
String skipList = "ignore\n";
|
||||
for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects())
|
||||
{
|
||||
if (project.getName().equals("User Addons"))
|
||||
@ -250,7 +250,8 @@ public class WorkspaceUtils
|
||||
|
||||
skipList += (StringUtils.trimPathSeparators(getPathRelativeToUserDir(project)) + "\n");
|
||||
}
|
||||
ResourceUtils.createFile(proj, ".ignore", skipList, true);
|
||||
skipList += "end_ignore\n";
|
||||
ResourceUtils.createFile(proj, ".wesnoth", skipList, true);
|
||||
}
|
||||
|
||||
Logger.getInstance().log("setupWorkspace was successful",
|
||||
|
Loading…
x
Reference in New Issue
Block a user