eclipse plugin: On full build, clear all previously cached information.

This commit is contained in:
Timotei Dolean 2011-07-13 20:47:53 +00:00
parent 62a75d7a08
commit 53402340cb
3 changed files with 260 additions and 219 deletions

View file

@ -56,22 +56,24 @@ import org.wesnoth.wml.core.ConfigFile;
public class WesnothProjectBuilder extends IncrementalProjectBuilder
{
private ProjectCache projectCache_;
private IProject project_;
@SuppressWarnings("rawtypes")
@Override
protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
throws CoreException
{
if ( WesnothInstallsUtils.setupInstallForResource( getProject() ) == false )
project_ = getProject( );
if ( WesnothInstallsUtils.setupInstallForResource( project_ ) == false )
return null;
if ( projectCache_ == null )
projectCache_ = ProjectUtils.getCacheForProject( getProject() );
projectCache_ = ProjectUtils.getCacheForProject( project_ );
Logger.getInstance().log( "Building project " + getProject( ).getName( ) + " ..." ); //$NON-NLS-1$
monitor.beginTask(String.format(Messages.WesnothProjectBuilder_1, getProject().getName()), 100);
monitor.beginTask(String.format(Messages.WesnothProjectBuilder_1, project_.getName()), 100);
String installName = WesnothInstallsUtils.getInstallNameForResource( getProject() );
String installName = WesnothInstallsUtils.getInstallNameForResource( project_ );
Paths paths = Preferences.getPaths( installName );
monitor.subTask(Messages.WesnothProjectBuilder_3);
@ -100,7 +102,7 @@ public class WesnothProjectBuilder extends IncrementalProjectBuilder
readDefines = fullBuild(monitor);
else
{
IResourceDelta delta = getDelta(getProject());
IResourceDelta delta = getDelta(project_);
if (delta == null)
readDefines = fullBuild(monitor);
else
@ -130,6 +132,10 @@ public class WesnothProjectBuilder extends IncrementalProjectBuilder
*/
protected boolean fullBuild(final IProgressMonitor monitor) throws CoreException
{
// clean all project cache
projectCache_.clear( );
PreprocessorUtils.getInstance( ).clearTimestampsForPath( project_.getLocation( ).toOSString( ) );
projectCache_.getDependencyList( ).createDependencyList( true );
boolean foundCfg = false;
@ -245,7 +251,7 @@ public class WesnothProjectBuilder extends IncrementalProjectBuilder
*/
private boolean runAntJob( Paths paths, IProgressMonitor monitor )
{
String buildXMLPath = getProject().getLocation().toOSString() + "/build.xml";
String buildXMLPath = project_.getLocation().toOSString() + "/build.xml";
// check for 'build.xml' existance
if ( new File( buildXMLPath ).exists() == true )
{
@ -390,10 +396,10 @@ public class WesnothProjectBuilder extends IncrementalProjectBuilder
*/
private boolean isResourceIgnored(IResource res)
{
if (ProjectUtils.getPropertiesForProject(getProject()) == null)
if (ProjectUtils.getPropertiesForProject(project_) == null)
return false;
String[] ignored = ProjectUtils.getPropertiesForProject(getProject()).getArray("ignored"); //$NON-NLS-1$
String[] ignored = ProjectUtils.getPropertiesForProject(project_).getArray("ignored"); //$NON-NLS-1$
if (ignored == null)
return false;

View file

@ -15,6 +15,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
@ -301,4 +302,21 @@ public class PreprocessorUtils
Logger.getInstance().logException(e);
}
}
/**
* Clears all timestamps cached for files that are located in that path
* @param path The path to match the files to clear their timestamp
*/
public void clearTimestampsForPath( String path )
{
Iterator<Entry<String, Long>> itor = filesTimeStamps_.entrySet( ).iterator( );
while ( itor.hasNext( ) ) {
Entry<String, Long> entry = itor.next( );
if ( entry.getKey( ).startsWith( path ) )
itor.remove( );
}
saveTimestamps( );
}
}

View file

@ -38,262 +38,279 @@ import org.wesnoth.wml.core.Variable;
*/
public class ProjectCache
{
private long propertiesTimetamp_;
private long definesTimetamp_;
private long propertiesTimestamp_;
private long definesTimestamp_;
private DialogSettings properties_;
private DialogSettings properties_;
private File wesnothFile_;
private File definesFile_;
private File treeCacheFile_;
private File wesnothFile_;
private File definesFile_;
private File treeCacheFile_;
private Map< String, ConfigFile > configFiles_;
private Map< String, Define > defines_;
private DependencyListBuilder dependTree_;
private Map< String, ConfigFile > configFiles_;
private Map< String, Define > defines_;
private DependencyListBuilder dependTree_;
private IProject project_;
private IProject project_;
public ProjectCache(IProject project)
{
project_ = project;
public ProjectCache(IProject project)
{
project_ = project;
configFiles_ = new HashMap<String, ConfigFile>();
defines_ = new HashMap<String, Define>(0);
configFiles_ = new HashMap<String, ConfigFile>();
defines_ = new HashMap<String, Define>(0);
dependTree_ = new DependencyListBuilder( project_ );
dependTree_ = new DependencyListBuilder( project_ );
propertiesTimetamp_ = 0;
properties_ = new DialogSettings("project"); //$NON-NLS-1$
propertiesTimestamp_ = 0;
properties_ = new DialogSettings("project"); //$NON-NLS-1$
wesnothFile_ = new File(project.getLocation().toOSString() +
"/.wesnoth"); //$NON-NLS-1$
wesnothFile_ = new File(project.getLocation().toOSString() +
"/.wesnoth"); //$NON-NLS-1$
definesFile_ = new File (PreprocessorUtils.getInstance().getDefinesLocation( project ));
treeCacheFile_ = new File ( WorkspaceUtils.getProjectTemporaryFolder( project ) + "/_TREE_CACHE_.bin" ); //$NON-NLS-1$
definesFile_ = new File (PreprocessorUtils.getInstance().getDefinesLocation( project ));
treeCacheFile_ = new File ( WorkspaceUtils.getProjectTemporaryFolder( project ) + "/_TREE_CACHE_.bin" ); //$NON-NLS-1$
ResourceUtils.createWesnothFile(wesnothFile_.getAbsolutePath(), false);
readProperties(true);
readDefines(true);
}
ResourceUtils.createWesnothFile(wesnothFile_.getAbsolutePath(), false);
readProperties(true);
readDefines(true);
}
/**
* Reads the properties from the file only if the
* file changed.
* @param force True to skip checking for modifications
*/
private void readProperties(boolean force)
{
if (force == false &&
wesnothFile_.lastModified() <= propertiesTimetamp_)
return;
/**
* Reads the properties from the file only if the
* file changed.
* @param force True to skip checking for modifications
*/
private void readProperties(boolean force)
{
if (force == false &&
wesnothFile_.lastModified() <= propertiesTimestamp_)
return;
try
{
ResourceUtils.createWesnothFile(wesnothFile_.getAbsolutePath(), false);
try
{
ResourceUtils.createWesnothFile(wesnothFile_.getAbsolutePath(), false);
try
{
properties_.load( wesnothFile_.getAbsolutePath() );
}
catch(ClassCastException ex)
{
// backward compatiblity
// we already have an xml format used by Properties.
// convert it to DialogSettings
ResourceUtils.createWesnothFile(wesnothFile_.getAbsolutePath(), true);
properties_.load( wesnothFile_.getAbsolutePath() );
}
try
{
properties_.load( wesnothFile_.getAbsolutePath() );
}
catch(ClassCastException ex)
{
// backward compatiblity
// we already have an xml format used by Properties.
// convert it to DialogSettings
ResourceUtils.createWesnothFile(wesnothFile_.getAbsolutePath(), true);
properties_.load( wesnothFile_.getAbsolutePath() );
}
if (properties_.getSection("configs") != null) //$NON-NLS-1$
{
for(IDialogSettings config : properties_.getSection("configs").getSections()) //$NON-NLS-1$
{
if (config.getName().startsWith("config") == false) //$NON-NLS-1$
continue;
if (properties_.getSection("configs") != null) //$NON-NLS-1$
{
for(IDialogSettings config : properties_.getSection("configs").getSections()) //$NON-NLS-1$
{
if (config.getName().startsWith("config") == false) //$NON-NLS-1$
continue;
ConfigFile tmp = new ConfigFile(config.get("filename")); //$NON-NLS-1$
tmp.ScenarioId = config.get( "scenario_id" ); //$NON-NLS-1$
tmp.CampaignId = config.get( "campaign_id" ); //$NON-NLS-1$
ConfigFile tmp = new ConfigFile(config.get("filename")); //$NON-NLS-1$
tmp.ScenarioId = config.get( "scenario_id" ); //$NON-NLS-1$
tmp.CampaignId = config.get( "campaign_id" ); //$NON-NLS-1$
for(IDialogSettings variable : config.getSection("variables").getSections()) //$NON-NLS-1$
{
if (variable.getName().startsWith("var") == false) //$NON-NLS-1$
continue;
tmp.getVariables().add(
new Variable(variable.get("name"), //$NON-NLS-1$
variable.get("location"), //$NON-NLS-1$
variable.getInt("offset"))); //$NON-NLS-1$
}
configFiles_.put(config.get("filename"), tmp); //$NON-NLS-1$
}
}
for(IDialogSettings variable : config.getSection("variables").getSections()) //$NON-NLS-1$
{
if (variable.getName().startsWith("var") == false) //$NON-NLS-1$
continue;
tmp.getVariables().add(
new Variable(variable.get("name"), //$NON-NLS-1$
variable.get("location"), //$NON-NLS-1$
variable.getInt("offset"))); //$NON-NLS-1$
}
configFiles_.put(config.get("filename"), tmp); //$NON-NLS-1$
}
}
// unserialize the tree builder
if ( treeCacheFile_.exists( ) ) {
FileInputStream inStream = new FileInputStream( treeCacheFile_ );
// unserialize the tree builder
if ( treeCacheFile_.exists( ) ) {
FileInputStream inStream = new FileInputStream( treeCacheFile_ );
ObjectInputStream deserializer = new ObjectInputStream( inStream );
dependTree_.deserialize( deserializer );
}
}
propertiesTimetamp_ = wesnothFile_.lastModified();
}
catch (Exception e)
{
Logger.getInstance().logException(e);
propertiesTimetamp_ = 0; // force to re-read the file
}
}
propertiesTimestamp_ = wesnothFile_.lastModified();
}
catch (Exception e)
{
Logger.getInstance().logException(e);
propertiesTimestamp_ = 0; // force to re-read the file
}
}
/**
* Gets the properties store for the associated Project.
* If the store doesn't exist it will be created.
* This method ensures it will get the latest up-to-date '.wesnoth' file
* @return
*/
public DialogSettings getProperties()
{
readProperties(false);
return properties_;
}
/**
* Gets the properties store for the associated Project.
* If the store doesn't exist it will be created.
* This method ensures it will get the latest up-to-date '.wesnoth' file
* @return
*/
public DialogSettings getProperties()
{
readProperties(false);
return properties_;
}
/**
* Gets the map with the Configs
* The key represent the filenames of the files
* and the value the scenarioId from that file
* @return
*/
public Map<String, ConfigFile> getConfigs()
{
return configFiles_;
}
/**
* Gets the map with the Configs
* The key represent the filenames of the files
* and the value the scenarioId from that file
* @return
*/
public Map<String, ConfigFile> getConfigs()
{
return configFiles_;
}
/**
* Gets the Config by it's filename.
* If the Config doesn't exist it will be created
* @param name
* @return
*/
public ConfigFile getConfig(String name)
{
ConfigFile config = configFiles_.get( name );
if ( config == null ){
config = new ConfigFile( name );
configFiles_.put( name, config );
}
/**
* Gets the Config by it's filename.
* If the Config doesn't exist it will be created
* @param name
* @return
*/
public ConfigFile getConfig(String name)
{
ConfigFile config = configFiles_.get( name );
if ( config == null ){
config = new ConfigFile( name );
configFiles_.put( name, config );
}
return config;
}
return config;
}
/**
* Saves the cache to disk.
* Saves:
* - properties
* - existing scenarios
* @return
*/
public boolean saveCache()
{
ResourceUtils.createWesnothFile(wesnothFile_.getAbsolutePath(), false);
try
{
// save config files info
int configCnt = 0;
IDialogSettings configsSection = properties_.addNewSection("configs"); //$NON-NLS-1$
for(ConfigFile config : configFiles_.values())
{
IDialogSettings configSection = configsSection.addNewSection("config" + configCnt); //$NON-NLS-1$
configSection.put("scenario_id", config.ScenarioId); //$NON-NLS-1$
configSection.put("campaign_id", config.CampaignId); //$NON-NLS-1$
configSection.put("filename", config.getFilename()); //$NON-NLS-1$
/**
* Saves the cache to disk.
* Saves:
* - properties
* - existing scenarios
* @return
*/
public boolean saveCache()
{
ResourceUtils.createWesnothFile(wesnothFile_.getAbsolutePath(), false);
try
{
// save config files info
int configCnt = 0;
IDialogSettings configsSection = properties_.addNewSection("configs"); //$NON-NLS-1$
for(ConfigFile config : configFiles_.values())
{
IDialogSettings configSection = configsSection.addNewSection("config" + configCnt); //$NON-NLS-1$
configSection.put("scenario_id", config.ScenarioId); //$NON-NLS-1$
configSection.put("campaign_id", config.CampaignId); //$NON-NLS-1$
configSection.put("filename", config.getFilename()); //$NON-NLS-1$
IDialogSettings variablesSection = configSection.addNewSection("variables"); //$NON-NLS-1$
int varCnt = 0;
for(Variable var : config.getVariables())
{
IDialogSettings varSection = variablesSection.addNewSection("var" + varCnt); //$NON-NLS-1$
varSection.put("name", var.getName()); //$NON-NLS-1$
varSection.put("location", var.getLocation()); //$NON-NLS-1$
varSection.put("offset", var.getOffset()); //$NON-NLS-1$
IDialogSettings variablesSection = configSection.addNewSection("variables"); //$NON-NLS-1$
int varCnt = 0;
for(Variable var : config.getVariables())
{
IDialogSettings varSection = variablesSection.addNewSection("var" + varCnt); //$NON-NLS-1$
varSection.put("name", var.getName()); //$NON-NLS-1$
varSection.put("location", var.getLocation()); //$NON-NLS-1$
varSection.put("offset", var.getOffset()); //$NON-NLS-1$
++varCnt;
}
++configCnt;
}
++varCnt;
}
++configCnt;
}
// store properties
properties_.save( wesnothFile_.getAbsolutePath() );
propertiesTimetamp_ = wesnothFile_.lastModified();
// store properties
properties_.save( wesnothFile_.getAbsolutePath() );
propertiesTimestamp_ = wesnothFile_.lastModified();
// save the PDT tree
ResourceUtils.createNewFile( treeCacheFile_.getAbsolutePath( ) );
ResourceUtils.createNewFile( treeCacheFile_.getAbsolutePath( ) );
FileOutputStream outStream = new FileOutputStream( treeCacheFile_ );
ObjectOutputStream serializer = new ObjectOutputStream( outStream );
serializer.writeObject( dependTree_ );
serializer.close( );
return true;
}
catch (Exception e)
{
Logger.getInstance().logException(e);
return false;
}
}
return true;
}
catch (Exception e)
{
Logger.getInstance().logException(e);
return false;
}
}
/**
* Reads the defines files for this project
* @param force skip checking for last modified timestamp
*/
public void readDefines(boolean force)
{
if (force == false &&
definesFile_.lastModified() <= definesTimetamp_)
return;
if (definesFile_.exists() == false)
return;
defines_ = Define.readDefines(definesFile_.getAbsolutePath());
definesTimetamp_ = definesFile_.lastModified( );
}
/**
* Reads the defines files for this project
* @param force skip checking for last modified timestamp
*/
public void readDefines(boolean force)
{
if (force == false &&
definesFile_.lastModified() <= definesTimestamp_)
return;
if (definesFile_.exists() == false)
return;
defines_ = Define.readDefines(definesFile_.getAbsolutePath());
definesTimestamp_ = definesFile_.lastModified( );
}
public void setDefines(Map<String, Define> defines)
{
defines_ = defines;
}
public void setDefines(Map<String, Define> defines)
{
defines_ = defines;
}
/**
* Returns the defines associated with this project
* @return
*/
public Map<String, Define> getDefines()
{
return defines_;
}
/**
* Returns the defines associated with this project
* @return
*/
public Map<String, Define> getDefines()
{
return defines_;
}
/**
/**
* The name of the install used in the project
*/
public String getInstallName()
{
return Preferences.getString( Constants.P_INST_NAME_PREFIX + project_.getName( ) );
}
public String getInstallName()
{
return Preferences.getString( Constants.P_INST_NAME_PREFIX + project_.getName( ) );
}
/**
* Sets the new install used in the project
* @param newInstallName The new install name
*/
public void setInstallName( String newInstallName )
{
Preferences.getPreferences( ).setValue(
Constants.P_INST_NAME_PREFIX + project_.getName( ),
newInstallName );
}
/**
* Sets the new install used in the project
* @param newInstallName The new install name
*/
public void setInstallName( String newInstallName )
{
Preferences.getPreferences( ).setValue(
Constants.P_INST_NAME_PREFIX + project_.getName( ),
newInstallName );
}
/**
* Returns the current dependency tree builder for this project
* @return A dependency tree
*/
public DependencyListBuilder getDependencyList()
/**
* Returns the current dependency tree builder for this project
* @return A dependency tree
*/
public DependencyListBuilder getDependencyList()
{
return dependTree_;
}
/**
* Clears all the project cache
*/
public void clear()
{
properties_ = new DialogSettings("project"); //$NON-NLS-1$
configFiles_.clear( );
defines_.clear( );
dependTree_ = new DependencyListBuilder( project_ );
propertiesTimestamp_ = -1;
definesTimestamp_ = -1;
saveCache( );
}
}