Auto upload on save - bug?

A place for those developing Aptana plugins, scripts or extending the IDE to gather and discuss extending Studio beyond the standard features.

Moderator: Aptana Staff

Auto upload on save - bug?

Postby a1dams » Wed Aug 08, 2007 10:40 pm

I just installed M9 (0.2.9.16204) and am having a few problems with the auto upload on save feature (one may just be with sync manager).

1) The first problem I found is that out of the box I could not get the auto upload script to work. When I chose "Scripts > Synchronize > Upload Current File on Save" I got an error complaining that the script file didn't define a function "main()". I added this:
Code: Select all
function main() {
   sync.uploadCurrentEditor();
}

to the upload_current_file_on_save.js file and it seemed to work. Maybe this is the root of the problem?

2) The next thing I found is that when I upload it seems to upload fine, but when I look at the server the file did not upload. If I CTL+s again and upload it gets uploaded properly. This happens every time.

3) The sftp connection seems to have a slight problem making the connection at times. I can save/upload a file just fine, then a couple minutes later try again and I get an error: "Could not connect. Error message is The connection has been closed. [Unnamed Channel]". I have to then go into the sync manager and hit OK before it will connect again.

4) The final problem I found (or maybe this was a design choice) was that if I use the save button or "File > Save" it does not prompt to upload.
a1dams
 
Posts: 9
Joined: Tue May 08, 2007 8:42 pm

Postby ingo » Thu Aug 09, 2007 4:42 pm

Hi Aadams,

So I think what's going on is that we intended people to use the script as a sample, not as is. The way to use it is to copy it into a "scripts" folder under any project (you can create a new one), and then modify the header to look like this:

Code: Select all
/*
* Currently an example script (disabled)> Copy as your own script, and modify
* the Listener command as shown below
*
* Menu: Synchronize > Upload Current File On Save Enabled
* Kudos: Ingo Muschenetz
* License: EPL 1.0
* Listener: commandService().addExecutionListener(this);
* DOM: http://localhost/com.aptana.ide.syncing
* DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
*/


That would make _any_ file upload on Save (no matter how you saved it).

What it sounds like is that you want to make it such that for the life of the current editing session, you want just this file to auto-upload on save. Is that correct?

Thanks,
Ingo
ingo
 
Posts: 1503
Joined: Thu Jul 13, 2006 6:05 pm

Postby a1dams » Thu Aug 09, 2007 5:45 pm

Thanks for the response Ingo. I actually want it to upload any file on save.

I'm pretty new to Aptana (this feature was what I was waiting for to dump dreamweaver), so I'm a little green when it comes to setting up the scripts. So you mean I create a scripts folder in each project and save this script there? Is there plans to make that a configuration in the project properties? Is there a help doc on this?

Do you have any ideas on the two major problems ( #2 & #3 ) I posted?

Thanks again!
a1dams
 
Posts: 9
Joined: Tue May 08, 2007 8:42 pm

Solution

Postby shadowyee » Fri Sep 07, 2007 4:15 am

aadams, I noticed the same behavior as your second issue (2). I fixed this by moving all the code in the current preExecute function to the postExecuteSuccess function.

I think what was happening is the latest changes are not uploaded because the file is not done saving yet. By moving the code to postExecuteSuccess, you are basically handling the sync after Save has happened.

I am also new to the whole Aptana and Eclipse scene, but as far as (4) goes, it looks like the events are only being triggered from the Workbench (after some research on the Eclipse side). I'm sure there are other Java classes you can throw in there, but I'm not too worried about using File > Save. It takes too long anyways. :)

Hope this helps you with what you want.
shadowyee
 
Posts: 1
Joined: Fri Sep 07, 2007 4:02 am

Postby xino » Wed Oct 24, 2007 3:29 pm

I had the same problem as you had (problem 1)... i fixed it with your code... thanks for that..

Now i want to upload the file automaticly when i save the file (ctrl + s) as you describe in (2).

Do you have found a sollution for that? Or how can i fix this otherwise?

Thanks!
xino
 
Posts: 6
Joined: Wed Oct 24, 2007 9:45 am

Postby mpetersen » Thu Oct 25, 2007 12:53 am

Hi xino,

You should be able to add a line of "KEY" metadata to the metadata section of your script. That will execute your script when you type your shortcut key combination.

Hope this helps,
Michelle
mpetersen
 
Posts: 1800
Joined: Thu Jul 13, 2006 6:43 pm

Postby xino » Thu Oct 25, 2007 7:24 am

Thanks for your post...

I've searched on aptana wiki and found this page:
http://www.aptana.com/docs/index.php/As ... _a_snippet
and http://www.aptana.com/docs/index.php/Ad ... y_metadata

My metadata contains the following code:
Code: Select all
/*
* Currently an example script (disabled)> Copy as your own script, and modify
* the Listener command as shown below
*
* Menu: Synchronize > Upload Current File On Save
* Key: M1+S
* Kudos: Ingo Muschenetz
* License: EPL 1.0
* DOM: http://localhost/com.aptana.ide.syncing
* DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
*/


I've tried to refresh the script view and i've restarted Aptana but nothing hapens when i press Ctrl+S... it only saves the file but doesnt upload anything. If i execute the script manualy it works... so i know for sure the keyboard assignment is broken

How can i fix this?
[/code]
xino
 
Posts: 6
Joined: Wed Oct 24, 2007 9:45 am

Postby leon1638 » Thu Oct 25, 2007 4:15 pm

All you have to do is add this to the top of your file under the Metadata

* Listener: commandService().addExecutionListener(this);

Then after it saves it will correctly upload
leon1638
 
Posts: 5
Joined: Thu Oct 25, 2007 3:45 pm

Postby xino » Fri Oct 26, 2007 7:06 am

Ok thank you! Now it works :)

But i have another question now, when i save the page, a popup comes telling me it's uploading files... is it possible to minimize this popup so i don't see it anymore? (It's even better to see it in your status bar below your screen)... hope this is possible :)
xino
 
Posts: 6
Joined: Wed Oct 24, 2007 9:45 am

Postby yanno » Mon Jan 21, 2008 8:18 pm

HI,

i meet another problem with this script . here is the error :

Code: Select all
org.eclipse.eclipsemonkey.RunMonkeyException: org.mozilla.javascript.EcmaError: TypeError: getWorkbench n'est pas une fonction, est un org.mozilla.javascript.NativeJavaPackage C:/Program Files/Eclipse/configuration/org.eclipse.osgi/bundles/38/1/.cp/scripts/upload_current_file_on_save.js #24


anyone has an idea to fix this ?

thanks

Yanno
yanno
 
Posts: 1
Joined: Mon Jan 21, 2008 8:16 pm

Postby mpetersen » Mon Jan 21, 2008 8:48 pm

Hi Yanno,

Can you file a support request for this in ASAP?

http://support.aptana.com/asap/secure/Dashboard.jspa

Include a copy of the script that you're using so that we can see if it's an issue with the script itself or with something else?

Thanks,
Michelle
mpetersen
 
Posts: 1800
Joined: Thu Jul 13, 2006 6:43 pm

Postby c1cculloh » Wed Jan 23, 2008 6:59 pm

It took me about 30 minutes to figure this out. I just discovered the whole "Scripts" part of Aptana today. It was kind of complicated, so I'll just describe what I actually had to do here:

1. If you don't have a project, create one.

2. If you don't have a "scripts" folder in your project, create one (I put mine in the root directory of my project. No clue if it will work from anywhere else).

3. Create a new file inside your scripts folder with a .js extension (I named mine "upload_current_file_on_save.js", not sure if it will work with any other name).

4. Place this code inside the file:

Code: Select all
/*
* Menu: gMan > Upload On Save
* Kudos: Ingo Muschenetz
* License: EPL 1.0
* Listener: commandService().addExecutionListener(this);
* DOM: http://localhost/com.aptana.ide.syncing
* DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
*/

// Add  * Listener: commandService().addExecutionListener(this); to the top of this file to enable it

/**
* Returns a reference to the workspace command service
*/
function commandService()
{
   var commandServiceClass = Packages.org.eclipse.ui.commands.ICommandService;
   
   // same as doing ICommandService.class
    var commandService = Packages.org.eclipse.ui.PlatformUI.getWorkbench().getAdapter(commandServiceClass);
    return commandService;
}

/**
* Called before any/every command is executed, so we must filter on command ID
*/
function preExecute(commandId, event) {}

/* Add in all methods required by the interface, even if they are unused */
function postExecuteSuccess(commandId, returnValue)
{
   
   // if we see a save command
   if (commandId == "org.eclipse.ui.file.save")
   {
      sync.uploadCurrentEditor();
      
      /* Replace above line if you'd like to limit it to just certain projects
      var fileName = editors.activeEditor.uri;
      if(fileName.match(/projectName/ig))
      {
         sync.uploadCurrentEditor();   
      }
      */
    }
}

function notHandled(commandId, exception) {}

function postExecuteFailure(commandId, exception) {}


5. Save the file.

A few notes on what needed changed in this file from the sample:

1. Added this line of code to the comment block at the top:

Code: Select all
* Listener: commandService().addExecutionListener(this);


I know there is a comment in this file that tells you to "add this to the top of this file", but since I'm new to the whole scripts thing I didn't get that when it said "top of the file" it meant "the middle of the comment block at the top of this file". I thought I was literally supposed to make that line the very first line in the file... Which didn't work at all...

2. Changed the "menu" line to:

Code: Select all
* Menu: gMan > Upload On Save

from:

Code: Select all
* Menu: Synchronize > Upload Current File On Save Enabled


For some reason it didn't work until I changed this line. Since my project is code named "gMan" (It's a user management system, you'll make the connection...) I just named the menu item "gMan" after my project. Then the command is to upload on save, so that's what I named it. As soon as I made this change is when the whole thing started working. Could be coincidence, or could be that you have to do this for the script to work (rename the menu command something other than what the sample is named).

3. In case you haven't figured it out, you run the script by going to the "Scripts" menu in the toolbar at the top of Apatan (and selecting the script, whatever you named it in the previous step).

Hope this helps someone...
c1cculloh
 
Posts: 4
Joined: Wed Jan 23, 2008 6:29 pm

Postby ziebold » Wed Mar 05, 2008 6:16 pm

This looks as if it has broken with the latest Aptana update (1.1.4.008288, Pro 1.1.11.200802281132) I get the error:

Code: Select all
org.eclipse.eclipsemonkey.RunMonkeyException: org.mozilla.javascript.WrappedException: java.lang.NullPointerException /Users/gregz/Projects/pb/opensocial/scripts/upload_on_save.js #33
ziebold
 
Posts: 3
Joined: Thu Feb 28, 2008 11:23 pm

Postby mpetersen » Wed Mar 05, 2008 6:52 pm

Hi ziebold,

Can you file a bug report for this, and we'll try to get it fixed.

http://support.aptana.com/asap/secure/Dashboard.jspa

Thanks,
Michelle
mpetersen
 
Posts: 1800
Joined: Thu Jul 13, 2006 6:43 pm

Re: Auto upload on save - bug?

Postby sshyh » Wed Aug 26, 2009 6:39 pm

I just recently update to aptana 1.5 from 1.2.

My upload on save script was working in 1.2, but after the upgrade to 1.5 it's no longer working.
The script I am using is consistent with the examples/recommendation that have been outlined in the previous posts.

Has anyone gotten their upload on save scripts to work properly on aptana 1.5?

Thanks for your help.

-Shawn
sshyh
 
Posts: 2
Joined: Sat Mar 21, 2009 4:01 pm

Next

Return to Customizing and Extending Studio