Commit 19878460 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Added erasing of old dependencies from persistent storage

parent fcd0f044
Loading
Loading
Loading
Loading
+57 −18
Original line number Diff line number Diff line
@@ -292,6 +292,7 @@ public class Tool extends Context implements Cloneable, Inheritable {
   

    public void clearDependStamps(){
    	DEBUG_PRINT("clearDependStamps() for "+getName());
    	dependStatesTimestamps.clear();
    	dependFilesTimestamps.clear();
    }
@@ -572,7 +573,7 @@ public class Tool extends Context implements Cloneable, Inheritable {
    public boolean isDisabled(){
    	if (abstractTool) return true; // abstract are always disabled
    	if (disabled==null) return false;
    	List<String> values=disabled.getValue(null); // null for topFormatProcessor
    	List<String> values=disabled.getValue(new FormatProcessor(this)); // null for topFormatProcessor
    	if ((values==null) || (values.size()==0)) return false;
    	return (!values.get(0).equals("true"));
    }
@@ -639,10 +640,11 @@ public class Tool extends Context implements Cloneable, Inheritable {
    	}
    }
    public List<String> getDependFiles(){
    	DEBUG_PRINT("------ getDependFiles()");
    	if ((dependFiles == null) || (dependFiles.size()==0)) return null;
    	List<String> list = new ArrayList<String>();
    	for (Iterator<Parameter> iter= dependFiles.iterator(); iter.hasNext();) {
    		List<String> vList=iter.next().getValue(null); // null for topFormatProcessor
    		List<String> vList=iter.next().getValue(new FormatProcessor(this)); // null for topFormatProcessor
    		if (vList!=null) {
    			for (String item:vList){
    				if ((item!=null) && (item.trim().length()>0)){
@@ -656,10 +658,11 @@ public class Tool extends Context implements Cloneable, Inheritable {
    }

    public List<String> getDependStates(){
    	DEBUG_PRINT("------ getDependStates() for "+getName());
    	if ((dependStates == null) || (dependStates.size()==0)) return null;
    	List<String> list = new ArrayList<String>();
    	for (Iterator<Parameter> iter= dependStates.iterator(); iter.hasNext();) {
    		List<String> vList=iter.next().getValue(null); // null for topFormatProcessor
    		List<String> vList=iter.next().getValue(new FormatProcessor(this)); // null for topFormatProcessor
			for (String item:vList){
				if ((item!=null) && (item.trim().length()>0)){
					list.add(item.trim());
@@ -715,14 +718,14 @@ public class Tool extends Context implements Cloneable, Inheritable {

    public boolean getAutoSave(){
    	if (autoSave==null) return false;
    	List<String>result=autoSave.getValue(null); // null for topFormatProcessor
    	List<String>result=autoSave.getValue(new FormatProcessor(this)); // null for topFormatProcessor
    	if (!result.isEmpty()) return result.get(0).equals("true");
    	return false;
    }
    
    public List<String> getResultNames(){
    	if (result==null) return null;
    	return result.getValue(null); // null for topFormatProcessor
    	return result.getValue(new FormatProcessor(this)); // null for topFormatProcessor
    }
    
    public void initRestore() throws ConfigException{
@@ -831,7 +834,7 @@ public class Tool extends Context implements Cloneable, Inheritable {
    public String getLogDir() {return getLogDir(true); } 
    public String getLogDir(boolean first) {
    	if (logDir!=null) { // has logDir specified, but may be empty
        	List<String> value=logDir.getValue(null); // null for topFormatProcessor
        	List<String> value=logDir.getValue(new FormatProcessor(this)); // null for topFormatProcessor
        	if (value.size()==0) return null; // overwrites with empty
        	return value.get(0);
    	}
@@ -844,7 +847,7 @@ public class Tool extends Context implements Cloneable, Inheritable {
    public String getStateDir() {return getStateDir(true); } 
    public String getStateDir(boolean first) {
    	if (stateDir!=null) { // has stateDir specified, but may be empty
        	List<String> value=stateDir.getValue(null); // null for topFormatProcessor
        	List<String> value=stateDir.getValue(new FormatProcessor(this)); // null for topFormatProcessor
        	if (value.size()==0) return null; // overwrites with empty
        	return value.get(0);
    	}
@@ -946,23 +949,47 @@ public class Tool extends Context implements Cloneable, Inheritable {
     * @param project where to attach properties
     */
    public void saveState(IProject project) {
//		if (getName().equals("ISExst")){
//			System.out.println("saveState(Project): Debugging ISExst");
//		}
    	QualifiedName qn= new QualifiedName(VDT.ID_VDT, PROJECT_TOOL_NAME+name+PROJECT_TOOL_PINNED);
    	try {project.setPersistentProperty(qn, new Boolean(isPinned()).toString());}
    	catch (CoreException e)  {System.out.println(project+"Failed setPersistentProperty("+qn+", "+isPinned()+", e="+e);}
    	qn= new QualifiedName(VDT.ID_VDT, PROJECT_TOOL_NAME+name+PROJECT_TOOL_STATE);
    	try {project.setPersistentProperty(qn, getState().toString());}
    	catch (CoreException e)  {System.out.println(project+"Failed setPersistentProperty("+qn+", "+getState()+", e="+e);}
        if (getTimeStamp()!=null) {

    	qn= new QualifiedName(VDT.ID_VDT, PROJECT_TOOL_NAME+name+PROJECT_TOOL_TIMESTAMP);
    	try {project.setPersistentProperty(qn, getTimeStamp());}
    	catch (CoreException e)  {System.out.println(project+"Failed setPersistentProperty("+qn+", "+getTimeStamp()+", e="+e);}
    	
        }
        if (getLastRunHash()!=0)  {
    	String lastHashString=(getLastRunHash()!=0)?(new Integer(getLastRunHash()).toString()):null;
    	qn= new QualifiedName(VDT.ID_VDT, PROJECT_TOOL_NAME+name+PROJECT_TOOL_LASTRUNHASH);
        	try {project.setPersistentProperty(qn, new Integer(getLastRunHash()).toString());}
        	catch (CoreException e)  {System.out.println(project+"Failed setPersistentProperty("+qn+", "+getLastRunHash()+", e="+e);}
    	try {project.setPersistentProperty(qn, lastHashString);}
    	catch (CoreException e)  {System.out.println(project+"Failed setPersistentProperty("+qn+", "+lastHashString+", e="+e);}

    	// Delete all old persistent dependencies for this tool before saving current ones (some dependencies might disappear)
    	Map<QualifiedName,String> pp;    
    	try {
    		pp=project.getPersistentProperties();
    	} catch (CoreException e){
    		System.out.println(project+": Failed getPersistentProperties(), e="+e);
    		return;
    	}
    	String statePrefix=PROJECT_TOOL_NAME+name+PROJECT_TOOL_DEPSTATE;
		String filePrefix= PROJECT_TOOL_NAME+name+PROJECT_TOOL_DEPFILE;
		for (QualifiedName qName: pp.keySet()){
			if (
					(qName.getLocalName().startsWith(statePrefix)) ||
					(qName.getLocalName().startsWith(filePrefix))) {
				try {
					project.setPersistentProperty(qName, null); // erase
				} catch (CoreException e)  {
					System.out.println(project+"Failed setPersistentProperty("+qName+", "+dependStatesTimestamps.get(state)+", e="+e);
				}
			}
		}
    	
        for(String state:dependStatesTimestamps.keySet()){
        	qn= new QualifiedName(VDT.ID_VDT, PROJECT_TOOL_NAME+name+PROJECT_TOOL_DEPSTATE+state);
        	try {project.setPersistentProperty(qn, dependStatesTimestamps.get(state));}
@@ -977,6 +1004,10 @@ public class Tool extends Context implements Cloneable, Inheritable {
    }

    public void restoreState(IProject project) {
//		if (getName().equals("ISExst")){
//			System.out.println("restoreState(Project): Debugging ISExst");
//		}

    	Map<QualifiedName,String> pp;    
    	try {
    	pp=project.getPersistentProperties();
@@ -1022,6 +1053,8 @@ public class Tool extends Context implements Cloneable, Inheritable {
    		clearDependStamps();
    		String statePrefix=PROJECT_TOOL_NAME+name+PROJECT_TOOL_DEPSTATE;
    		String filePrefix= PROJECT_TOOL_NAME+name+PROJECT_TOOL_DEPFILE;
// TODO: check dependency exists?    		
    		
    		for (QualifiedName qName: pp.keySet()){
    			//        	qn= new QualifiedName(VDT.ID_VDT, PROJECT_TOOL_NAME+name+PROJECT_TOOL_DEPSTATE+state);
    			if (qName.getLocalName().startsWith(statePrefix)){
@@ -1040,6 +1073,9 @@ public class Tool extends Context implements Cloneable, Inheritable {
    
    
    public void saveState(IMemento memento) {
//		if (getName().equals("ISExst")){
//			System.out.println("saveState(memento): Debugging ISExst");
//		}
    	IMemento toolMemento= memento.createChild(MEMENTO_TOOL_TYPE,name);
    	toolMemento.putBoolean(MEMENTO_TOOL_PINNED, new Boolean(pinned));
    	toolMemento.putString(MEMENTO_TOOL_STATE,  this.state.toString());
@@ -1063,6 +1099,9 @@ public class Tool extends Context implements Cloneable, Inheritable {
    }

    public void restoreState(IMemento memento) {
//		if (getName().equals("ISExst")){
//			System.out.println("restoreState(memento): Debugging ISExst");
//		}
    	IMemento[] toolMementos=memento.getChildren(MEMENTO_TOOL_TYPE);
    	IMemento toolMemento=null;
    	for (IMemento tm:toolMementos){
@@ -1602,7 +1641,7 @@ public class Tool extends Context implements Cloneable, Inheritable {
    //
    
    private String getResolvedExeName() {
        return ConditionUtils.resolveContextCondition(this, exeName, null); // null for topFormatProcessor 
        return ConditionUtils.resolveContextCondition(this, exeName, new FormatProcessor(this)); // null for topFormatProcessor 
    }
/*    
    private String getResolvedShellName() {
+30 −0
Original line number Diff line number Diff line
@@ -108,6 +108,30 @@ public class ToolSequence {
		toolFinished(null);
	}

	public void clearProjectStates(){
		IProject project= SelectedResourceManager.getDefault().getSelectedProject();
		if (project==null){
			System.out.println("Can not clear persistent properties for a non-existent project");
			return;
		}
    	Map<QualifiedName,String> pp;    
    	try {
    		pp=project.getPersistentProperties();
    	} catch (CoreException e){
    		System.out.println(project+": Failed getPersistentProperties(), e="+e);
    		return;
    	}
    	for(QualifiedName qn:pp.keySet()) {
    		DEBUG_PRINT("Clearing persistent property "+qn.toString()+" for project "+project.toString());
    		try {
				project.setPersistentProperty(qn, null);
			} catch (CoreException e) {
	    		System.out.println(project+": Failed setPersistentProperties("+qn.toString()+",null), e="+e);
			}
    	}
	}
	
	
	public Set<IFile> getOldFiles(Set<String> dirs){
		IProject project = SelectedResourceManager.getDefault().getSelectedProject(); // should not be null when we got here
		Set<String> linkFilesTargets=new HashSet<String>();
@@ -248,6 +272,7 @@ public class ToolSequence {
			putCurrentState(tool); // delegates to *Master
			// Set tool timestamps for states and source files
			if ((tool.getLastMode()==TOOL_MODE.RUN) || (tool.getLastMode()==TOOL_MODE.RESTORE)) {
		    	DEBUG_PRINT("doToolFinished(), will run setDependState("+tool.getName()+")");
				setDependState(tool); 
			}
			setToolsDirtyFlag(false); // no need to recalculate all parameters here
@@ -1430,6 +1455,9 @@ public class ToolSequence {
		IProject project = SelectedResourceManager.getDefault().getSelectedProject(); // should not be null when we got here
		for (Tool tool : ToolsCore.getConfig().getContextManager().getToolList()){
//			if (tool.getState()==TOOL_STATE.SUCCESS){
//			if (tool.getName().equals("ISExst")){
//				System.out.println("Debugging ISExst");
//			}
		        if (update){
		        	// tool.updateContextOptions(project) recalculates parameters, but not the hashcodes
		        	tool.updateContextOptions(project); // Fill in parameters - it parses here too - at least some parameters? (not in menu mode)
@@ -1520,6 +1548,7 @@ public class ToolSequence {
     * @param tool Reference to a tool to process
     */
    public void setDependState(Tool tool){
    	DEBUG_PRINT("++++++++ setDependState("+tool.getName()+")");
    	tool.clearDependStamps(); // is it needed?
    	Map <String,String> depStates=makeDependStates(tool);
    	for (String state:depStates.keySet()){
@@ -1600,6 +1629,7 @@ public class ToolSequence {
    	return depStates;
    }
    private  Map <String,String> makeDependFiles(Tool tool){
    	DEBUG_PRINT("++++++ makeDependFiles("+tool.getName()+")");
    	Map <String,String> depFiles=new Hashtable<String,String>();    	
    	List<String> dependFileNames=tool.getDependFiles();
    	if (dependFileNames!=null) {
+3 −1
Original line number Diff line number Diff line
@@ -73,7 +73,9 @@ public class VDTPluginImages {
    public static final ImageDescriptor DESC_INSTALL_PROPERTIES = create(ICONS_PATH, "obj16"+File.separator+"install_prop.gif", null);
    public static final ImageDescriptor DESC_PACKAGE_PROPERTIES = create(ICONS_PATH, "obj16"+File.separator+"package_prop.gif", null);
    public static final ImageDescriptor DESC_PROJECT_PROPERTIES = create(ICONS_PATH, "obj16"+File.separator+"project_prop.gif", null);
    public static final ImageDescriptor DESC_DESIGM_MENU = create(ICONS_PATH, "obj16"+File.separator+"design_menu.gif", null);
    public static final ImageDescriptor DESC_DESIGN_MENU =      create(ICONS_PATH, "obj16"+File.separator+"design_menu.gif", null);
    public static final ImageDescriptor DESC_ERASE =            create(ICONS_PATH, "obj16"+File.separator+"eraser.png", null);

    public static final ImageDescriptor DESC_TOOLS_LINKED =   create(ICONS_PATH, "obj16"+File.separator+"link.png", null);
    public static final ImageDescriptor DESC_TOOLS_UNLINKED = create(ICONS_PATH, "obj16"+File.separator+"broken_link.png", null);
    public static final ImageDescriptor DESC_TOOLS_SAVE = create(ICONS_PATH, "obj16"+File.separator+"save.png", null);
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public class Option implements IOption {
    }
    
    /**
     * Return core option (optiuon without UI elements)
     * Return core option (option without UI elements)
     */
    public Option getOption() {
        return this;
+36 −0
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2014 Elphel, Inc.
 * This file is a part of Eclipse/VDT plug-in.
 * Eclipse/VDT plug-in is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Eclipse/VDT plug-in is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *******************************************************************************/
package com.elphel.vdt.ui.views;

import org.eclipse.core.resources.IProject;

import com.elphel.vdt.core.tools.params.ToolSequence;

public class ClearProjectStates extends ClearAction {
	private ToolSequence toolSequence;

    public ClearProjectStates(String message, ToolSequence toolSequence) {
        super(message);
    	this. toolSequence= toolSequence;
    }

    public void clear() {
    	toolSequence.clearProjectStates();

    }
    
} // class ContextsAction
Loading