Commits

ryanackley committed 5ed1a0f

More reliable content matching on startup

Comments (0)

Files changed (4)

AtlassianPluginProject.js

 	this.locationType = 'local';
 };
 AtlassianPluginProject.prototype = {
-	load : function(root, callback){
+	load : function(root, url, callback){
 		var resourceMap = this.resourceMap;
 		Gito.FileUtils.readFile(root, 'pom.xml', 'Text', function(pomText){
 			var p = new DOMParser();
 				}
 				else{
 					$.ajax({type: 'GET',
-							url: url + '?r=' + ran,
+							url: url + (url.indexOf('?') != -1 ? '&' : '?') + 'r=' + ran,
 							dataType: 'text',
 							success: sendContentToDevtools,
 							error: done});

ProjectManager.js

 			if (path){
 				Gito.FileUtils.readFile(this.fsRoot, path, 'Text', function(localContent){
 					if (content != localContent){
-						sendResponse({success: false, msg: 'Content for url ' + url + ' doesn\'t match local file ' + path}); 
-						delete currentProject.matchedResourceMap[url];
+					
+						var ran = Math.round(Math.random()*10000000);
+						var handleError = function(){
+							sendResponse({success: false, msg: 'Content for url ' + url + ' doesn\'t match local file ' + path});
+							delete currentProject.matchedResourceMap[url];
+						}
+						
+						var handleContent = function(newContent){
+							if (localContent != newContent){
+								handleError();
+							}else{
+								sendResponse({success: true, msg: 'Content for url ' + url + ' was reloaded and it matches local file ' + path, content: newContent });
+							}
+						}
+						
+						$.ajax({type: 'GET',
+							url: url + (url.indexOf('?') != -1 ? '&' : '?') + 'r=' + ran,
+							dataType: 'text',
+							success: handleContent,
+							error: handleError}); 
+						
 					}
 					else{
 						sendResponse({success: true, msg: 'Content for url ' + url + ' matches local file ' + path });

ResourceChecker.js

 				if (data.success){
 					logMessage(data.msg);
 					matchedUrls[resource.url] = true;
+					if (data.content){
+						doResourceUpdate(resource, data.content);
+					}
 				}
 				else{
 					logError(data.msg);
 		backgroundMsgSupport.updateResource(resource.url, content);
 	}
 });
-
+var doResourceUpdate = function(resource, newContent){
+	recentUpdateHandler.addRecentUpdate(resource.url);
+	resource.setContent(newContent, true);
+};
 var fileChangeListener = function(data){
 	// resource content seems to be naively cached. No way to get the most recent content without
 	// storing it ourselves. Does it matter that much?
 		if (resourceCache[i].url === data.url){
 			//setContent(resourceCache[i], data);
 			var resource = resourceCache[i];
-			recentUpdateHandler.addRecentUpdate(resource.url);
-			resource.setContent(data.content, true);
+			doResourceUpdate(resource, data.content);
 		}
 	}
 };
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.