Bug 516048 - Copy preferences leads to lost target platform
Summary: Copy preferences leads to lost target platform
Status: VERIFIED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.7   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.7 M7   Edit
Assignee: Lars Vogel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 432006
Blocks:
  Show dependency tree
 
Reported: 2017-05-02 09:20 EDT by Lars Vogel CLA
Modified: 2017-05-10 12:00 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2017-05-02 09:20:15 EDT
Plug-ins store their preferences in org.eclipse.core.runtime/.settings.

If we copy these folders to a new workspace a local target platform breaks, as it references to a file in /home/vogella/workspace/eclipse.platform/.metadata/.plugins/org.eclipse.pde.core/.local_targets

This is exposed via Bug 432006.
Comment 1 Eclipse Genie CLA 2017-05-02 11:10:02 EDT
New Gerrit change created: https://git.eclipse.org/r/96179
Comment 3 Lars Vogel CLA 2017-05-02 12:29:07 EDT
Merging as this is M7 related and I want to test this on Wednesdays build
Comment 4 Lars Vogel CLA 2017-05-03 04:03:30 EDT
Verified in Eclipse SDK
Version: Oxygen (4.7)
Build id: I20170502-2000
OS: Linux, v.4.4.0-75-generic, x86_64 / gtk 3.18.9

After switching to a new workspace with the "Copy preferences" flag the resulting target platform is still valid.
Comment 7 Eclipse Genie CLA 2017-05-03 05:53:44 EDT
New Gerrit change created: https://git.eclipse.org/r/96270
Comment 8 Eclipse Genie CLA 2017-05-03 05:53:45 EDT
New Gerrit change created: https://git.eclipse.org/r/96269
Comment 9 Lars Vogel CLA 2017-05-03 05:56:21 EDT
https://git.eclipse.org/r/#/c/96270/ contains a fix for the unit tests. 

@Vikas, any objections to apply it again?
Comment 10 Vikas Chandra CLA 2017-05-03 06:09:09 EDT
>>@Vikas, any objections to apply it again?

Can you also do some manual testing in and around this area?
Comment 11 Lars Vogel CLA 2017-05-03 06:45:02 EDT
(In reply to Vikas Chandra from comment #10)
> >>@Vikas, any objections to apply it again?
> 
> Can you also do some manual testing in and around this area?

I tested:
- Scenario with preference copy from Bug 432006 now works
- Target definition creation still works
- Deletion still works
- Setting no target and restarting still works
Comment 12 Lars Vogel CLA 2017-05-03 09:00:16 EDT
Vikas, I plan to commit the change today, if I do not hear something against it from you.
Comment 13 Vikas Chandra CLA 2017-05-03 09:34:40 EDT
I plan to try out this patch in the next 2 hours. If you don't hear anything from me, you can go ahead with the fix.
Comment 14 Lars Vogel CLA 2017-05-03 09:46:05 EDT
(In reply to Vikas Chandra from comment #13)
> I plan to try out this patch in the next 2 hours. If you don't hear anything
> from me, you can go ahead with the fix.

Thanks.
Comment 15 Vikas Chandra CLA 2017-05-03 10:42:47 EDT
I find the new code very confusing. The method is to initialize a default target and most of the start, we try to fix  invalid target.

I suggest something 

	String memento = PDECore.getDefault().getPreferencesManager().getString(ICoreConstants.WORKSPACE_TARGET_HANDLE);

		boolean updated = updateInvalidTargetMemento(memento);
		if(updated)
			 memento = PDECore.getDefault().getPreferencesManager().getString(ICoreConstants.WORKSPACE_TARGET_HANDLE);


updateInvalidTargetMemento could look something like

private boolean updateInvalidTargetMemento(String memento) {
		boolean updated =false;
		PDEPreferencesManager preferenceManager = PDECore.getDefault().getPreferencesManager();
		// check if preference entry is valid
		if (memento != null ) {
			ITargetHandle handle;
			try {
				handle = getTarget(memento);
				if (!handle.exists()) {
						// preferences points to invalid target definition remove preference entry
							preferenceManager.setValueOrRemove(ICoreConstants.WORKSPACE_TARGET_HANDLE,
									preferenceManager.getDefaultString(ICoreConstants.WORKSPACE_TARGET_HANDLE));
							preferenceManager.flush();
							updated =true;
					}
			}
		 catch (CoreException e) {
						PDECore.log(e);
					}
			catch (BackingStoreException e) {
						PDECore.log(e);
					}
		}
		return updated;


updateInvalidTargetMemento could probably be better named as removeInvalidTargetMementoInPreference.


Also TargetPlatformService is at the core of things, we should make minimum change as possible.


I think this is good to go for 4.7 but it will be better if this is organized.
Comment 16 Vikas Chandra CLA 2017-05-03 10:44:14 EDT
I hope comment#15 captures what was intended to fix this issue. In case it doesn't, the additional logic should be put in too.
Comment 17 Lars Vogel CLA 2017-05-03 11:09:39 EDT
(In reply to Vikas Chandra from comment #16)
> I hope comment#15 captures what was intended to fix this issue. In case it
> doesn't, the additional logic should be put in too.

Thanks Vikas, great suggestion. I adjusted the Gerrit.
Comment 18 Vikas Chandra CLA 2017-05-03 11:19:31 EDT
Which is the current gerrit patch?
Comment 19 Lars Vogel CLA 2017-05-03 11:42:29 EDT
(In reply to Vikas Chandra from comment #18)
> Which is the current gerrit patch?

https://git.eclipse.org/r/#/c/96270

I'm still testing the updated change.
Comment 20 Lars Vogel CLA 2017-05-03 11:46:00 EDT
(In reply to Lars Vogel from comment #19)
> (In reply to Vikas Chandra from comment #18)
> > Which is the current gerrit patch?
> 
> https://git.eclipse.org/r/#/c/96270

Works fine for me. Let me know if I captured your suggestions correctly.
Comment 21 Dani Megert CLA 2017-05-03 11:52:41 EDT
Lars, when you prepare a change for PDE you *must* run AllPDETests. Gerrit does not run all tests.
Comment 22 Lars Vogel CLA 2017-05-03 12:02:04 EDT
(In reply to Dani Megert from comment #21)
> Lars, when you prepare a change for PDE you *must* run AllPDETests. Gerrit
> does not run all tests.

Thanks Dani, didn't know that about the PDE Gerrit. I see that my proposed change creates a test error. I move this out of M7.
Comment 23 Vikas Chandra CLA 2017-05-04 04:52:50 EDT
This is what I do

If I change pde.core, I run
1) AllPDETests
2) ApiToolsPluginTestSuite
3) ApiToolsTestSuite ( as Junit test and not plugin test)


If change is pde.ui, I run 
1) AllPDETests

If change is in api.tools
1) ApiToolsPluginTestSuite
2) ApiToolsTestSuite ( as Junit test and not plugin test)
Comment 24 Vikas Chandra CLA 2017-05-04 05:23:54 EDT
>>creates a test error.

this was happening because when memento was empty string, removeInvalidTargetMementoInPreference returned false

	if (!removeInvalidTargetMementoInPreference(preferenceManager, memento)) {
			return;
		}

ensured that the function returned instead of creating a default target.

I have changed the code to

	if (removeInvalidTargetMementoInPreference(preferenceManager, memento)) {
			memento = preferenceManager.getString(ICoreConstants.WORKSPACE_TARGET_HANDLE);
		}

and kept all of original line statements of the function.

As I said in comment#15, we don't change anything in the original function. We just removeInvalidTargetMementoInPreference and if removed, memento is updated.

Does the latest patch solve comment#0?
Comment 25 Lars Vogel CLA 2017-05-04 06:29:43 EDT
(In reply to Vikas Chandra from comment #24)

> Does the latest patch solve comment#0?

Thanks. Change looks good and solve the original problem. I leave it to you to merge it or not.
Comment 26 Vikas Chandra CLA 2017-05-04 06:39:53 EDT
I believe that the change is safe but I will back it up with some more testing.
If testing goes fine, I will merge it in 4.7
Comment 27 Vikas Chandra CLA 2017-05-05 06:45:55 EDT
I will have a look at this later today.
Comment 29 Vikas Chandra CLA 2017-05-08 05:37:48 EDT
A minor issue, I was getting coreexception while setting empty platform.

Fixed via
http://git.eclipse.org/c/pde/eclipse.pde.ui.git/patch/?id=406d9d8e74d3db52c47969f2c8a1618584c4d3be

Lars, It looks like I missed this check from your patch.
Comment 30 Vikas Chandra CLA 2017-05-10 10:55:17 EDT
Lars, can you please verify comment#0
Comment 31 Lars Vogel CLA 2017-05-10 12:00:32 EDT
(In reply to Vikas Chandra from comment #30)
> Lars, can you please verify comment#0

Verified with Eclipse SDK
Version: Oxygen (4.7)
Build id: I20170509-2000
OS: Linux, v.4.4.0-75-generic, x86_64 / gtk 3.18.9, WebKit 2.16.1