Bug 73683 - [Apply Patch] Add URL option Apply Patch dialog
Summary: [Apply Patch] Add URL option Apply Patch dialog
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Compare (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P5 enhancement with 2 votes (vote)
Target Milestone: 3.6 M5   Edit
Assignee: Tomasz Zarna CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed, helpwanted
Depends on:
Blocks: 288561
  Show dependency tree
 
Reported: 2004-09-10 12:16 EDT by Gary Gregory CLA
Modified: 2010-01-28 09:43 EST (History)
6 users (show)

See Also:


Attachments
applypatch_handle_url.diff (13.36 KB, patch)
2006-12-09 00:05 EST, Benjamin Muskalla CLA
tomasz.zarna: iplog+
Details | Diff
Patch v02 (23.92 KB, patch)
2009-12-17 07:43 EST, Tomasz Zarna CLA
no flags Details | Diff
mylyn/context/zip (71.56 KB, application/octet-stream)
2009-12-17 07:44 EST, Tomasz Zarna CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gary Gregory CLA 2004-09-10 12:16:54 EDT
Currently, you can specify a patch as a File path or Clipboard contents. All of
the patches I apply come from Bugzilla links. 

For exanmple:

http://issues.apache.org/bugzilla/showattachment.cgi?attach_id=12697

It would save a manual download step and a copy step if I could paste the URL in
the dialog. 

Thanks.
Gary
Comment 1 Michael Valenta CLA 2004-09-10 16:03:59 EDT
We're looking into better integration between Eclipse and Bugzilla. I can't 
say if we'll provide this exact support but we definitely want to do something 
that simplifies applying patches. We will update this bug with any approaches 
we are considering.
Comment 2 Silvio Böhler CLA 2005-01-13 15:38:31 EST
The Bugzilla plugin is not developed further so this should go into the Apply
Patch dialog.
Comment 3 Dirk Baeumer CLA 2005-06-23 17:38:13 EDT
Retagging as 3.2 since it will not make it into 3.1.
Comment 4 Dani Megert CLA 2006-10-25 07:56:25 EDT
Yes please add this since it makes life much easier:
1. copy bugzilla patch URL
2. paste into Apply Patch wizard

Instead of saving and selecting the file again using a dialog.
Comment 5 Michael Valenta CLA 2006-10-30 12:48:45 EST
I agree that it would be useful but we do not plan on addressing this in 3.3. Patches will be accepted.
Comment 6 Benjamin Muskalla CLA 2006-12-09 00:05:25 EST
Created attachment 55350 [details]
applypatch_handle_url.diff

Here is the first version of a patch to support applying patches directly from URLs.

* new URL combo with history (like file)
* validation of the url
* automatic recognation of urls in clipboard

comment on the last point:
the behavior at the moment doesn't make much sense to me. it's like this:
if(workbench selection == file)
   // check file related patch stuff
   // if file is not a patch, break
else
  // check clipboard

In my eyes, we should check the clipboard too when the selected file in the workbench is not a patch. This is also done with this patch. Additionally, if you have a URL in your clipboard, the Apply Patch wizard will recognize it, will select the URL-option for you and paste it into the combo. Nothing to do for you :)

As I mentioned, this is the first version of the patch and i hope to get some feedback how we could improve it. Patch is against current HEAD.
Comment 7 Michael Valenta CLA 2006-12-11 10:13:07 EST
Thanks for the patch. I took a quick look at the patch and it looks consistent with the code that already exists in the file. I agree with your suggestion that the else should just happen if the target file isn't a patch (i.e. you can take out the "if (1 = 1)". I'm curious why you took out the null check on the Control in that same method. Is it 100% guaranteed that the control won;t be null when that method is called. From my standpoint, it seems the safest to leave it in (i.e. because the cost is low and I don't really want to go through all the possible scenarios for the method to see if the null check was actually required.

There is one really tricky issue that you have not addressed. When connecting to remote systems, it is very easy to get caught in a situation where the connection blocks. I haven't done a lot with URLs but with Sockets, you need to do a bunch of things to ensure that the connection does not block the users:

1) You need to make the connection and fetch the contents in a background thread. You can use the getContainer#run(true, true, runnable) method for this.

2) You need to support cancelation. We have special stream in Team/Core that do this for Sockets but, unfortunately, Compare does not depend on Team/Core. It is possible that it could but we would need to determine whether this would be a problem for clients that may use Compare in an RCP app. The easiest thing to begin with would be to set the socket timeout to a reasonable value (say 60 seconds) so that the read won;t block indefinitely.

3) I don't know about URLs, but with Sockets there is no connection timeout so we needed to make sure that the connection attempt didn't block indefinitely. You can see what the code looks like by looking in the Util#createSocket method of the org.eclipse.team.cvs.ui method.

This is pretty messy stuff but it (or something similar) needs to be done since any failure in the connection that causes an indefinite block will make the user very unhappy. I've copied John because he mentioned recently that he may be adding support to the Jobs framework that would help in this situation. We should probably wait for his reply since tis may simplify the situation greatly.
Comment 8 Willian Mitsuda CLA 2007-01-07 16:06:39 EST
FYI, for those using Mylar (http://www.eclipse.org/mylar), the latest version supports applying patches directly from bug reports.

See: http://www.jroller.com/page/eu?entry=no_more_excuses_to_not
Comment 9 Peter Westwood CLA 2009-03-04 07:31:28 EST
What work is needed to champion this patch and get it progressed.

I use eclipse as part of my workflow for patch/review approval on the WordPress project and at the moment I find myself switching back to the commandline where I can use curl + patch to apply a patch directly to a svn checkout from a url.

For bigger patches I really want to work in eclipse but having to download the patch first is a real pain - i have tried using the clipboard method but it seems to choke on the svn generated patches which have revision info in them.
Comment 10 Tomasz Zarna CLA 2009-03-04 07:45:57 EST
(In reply to comment #9)
> What work is needed to champion this patch and get it progressed.

I belive that Michael clearly explained (comment 7) what need to be done to make Benjamin's patch fully operational. Currently, we don't have the manpower to address it, but patches will be accepted.

> i have tried using the clipboard method but it
> seems to choke on the svn generated patches which have revision info in them.

Why don't you file a bug for this particular issue?
Comment 11 Tomasz Zarna CLA 2009-12-16 07:17:58 EST
(In reply to comment #7)
> 1) You need to make the connection and fetch the contents in a background
> thread. (...)
> 2) You need to support cancelation. (...)
> 3) (...) make sure that the connection attempt didn't block indefinitely. (...)

The first two are rather straightforward. The third one seems to be a hard nut to crack with the EE limitation we have. The simplest solution would be to call setReadTimeout/setConnectTimeout on URLConnection but given the fact that both methods are available since J2SE-1.5[1] and o.e.compare requires J2SE-1.4 this won't happen :/ . Here are our options:

a) set J2SE-1.5 as EE for o.e.compare
b) wrap the connection in a timer thread
c) set system-wide properties: sun.net.client.defaultConnectTimeout and sun.net.client.defaultReadTimeout[2] (global settings and don't work for HTTPS afaik)
d) write an HTTP handler to set a timeout value, something similar to what Mike Reiche suggested here[3]
e) use HTTPClient[4] from the Apache Foundation
f) check if 1.5 API exist and call via reflection

I think I will try combination of f) and e) marking Apache packages optional. This way I'm sure the o.e.compare plug-in will run even if the package dependency is missing. On the other hand, if neither 1.5 API nor HTTPClient lib is available the option to apply patch using an URL won't show up.

[1] http://javadiff.sourceforge.net/jdiff/reports/j2se142_j2se150b1/changes/java.net.URLConnection.html
[2] http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html
[3] http://objectmix.com/weblogic/568262-weblogic-net-httpurlconnection-settimeout-int-i-not-there.html
[4] http://jakarta.apache.org/commons/httpclient/
Comment 12 Gary Gregory CLA 2009-12-16 11:38:08 EST
>a) set J2SE-1.5 as EE for o.e.compare

This seems like the best. People are really going to require running E on top of Java 1.4? This feels like bending over backwards to support a dead platform. I say we welcome them to the 21st century and Java 5! :)
Comment 13 Dani Megert CLA 2009-12-16 12:08:15 EST
Switching to 1.5 is not an option - at least not for 3.6 as 1.4 us one of the officially supported target environments for 1.4.
Comment 14 Tomasz Zarna CLA 2009-12-17 07:43:55 EST
Created attachment 154650 [details]
Patch v02

Here is Benjamin's updated patch. I added support for cancelation and made the connection/fetching run in a background. Regarding the timeout issue I decided to go only with f) (see comment 11) for now. As a user I would like to be able to use an URL to apply a patch even though it can hang the app, so the option is there even if you don't run on 1.5 API. I will open a separate bug for those who think this should be more robust (turn it off for 1.4 and/or use httpclient).
Comment 15 Tomasz Zarna CLA 2009-12-17 07:44:09 EST
Created attachment 154651 [details]
mylyn/context/zip
Comment 16 Tomasz Zarna CLA 2009-12-23 07:21:37 EST
(In reply to comment #14)
> I will open a separate bug for those who
> think this should be more robust (turn it off for 1.4 and/or use httpclient).

It's bug 298460.
Comment 17 Tomasz Zarna CLA 2009-12-23 08:11:59 EST
Latest patch applied to HEAD (with minor changes made on the fly). Available in builds >N20091217-2000. Benjamin, thanks for the initial version of the patch.