Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 154482

Summary: [Misc] CVS UI error running in headless mode
Product: [Eclipse Project] Platform Reporter: Alain Picard <picard>
Component: CVSAssignee: Platform Team Inbox <platform-team-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 Keywords: helpwanted
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Alain Picard CLA 2006-08-20 16:48:19 EDT
Quite similarly to Bug#76384, this also looks for the workbench when running in headless mode.

From CVSCoreFileModificationValidator.edit the comment clearly shows that it should be able to run without a UI. But we can see that the getUIValidator makes a request for to CVSCoreFileModificationValidator.getPluggedInValidator() which seems directly responsible to trigger the creation of an extension and finally down the road a display while setting preferences.

Even in FileModificationValidator.edit it checks if the task is running in the ui thread, but the test fails since a display has been created by the above mentioned code.

Here is the stacktrace:
org.eclipse.core.internal.resources.ResourceException(null)[4]: java.lang.IllegalStateException: Workbench has not been created yet.
	at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:92)
	at org.eclipse.team.internal.ccvs.ui.UserValidationDialog.configureShell(UserValidationDialog.java:71)
	at org.eclipse.jface.window.Window.createShell(Window.java:497)
	at org.eclipse.jface.window.Window.create(Window.java:425)
	at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1124)
	at org.eclipse.team.internal.ccvs.ui.UserValidationDialog.create(UserValidationDialog.java:77)
	at org.eclipse.jface.window.Window.open(Window.java:785)
	at org.eclipse.team.internal.ccvs.ui.WorkbenchUserAuthenticator.promptForPassword(WorkbenchUserAuthenticator.java:120)
	at org.eclipse.team.internal.ccvs.ui.WorkbenchUserAuthenticator.promptForUserInfo(WorkbenchUserAuthenticator.java:66)
	at org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation.promptForUserInfo(CVSRepositoryLocation.java:811)
	at org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation.openConnection(CVSRepositoryLocation.java:789)
	at org.eclipse.team.internal.ccvs.core.client.Session.open(Session.java:159)
	at org.eclipse.team.internal.ccvs.core.CVSTeamProvider$6.run(CVSTeamProvider.java:605)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1737)
	at org.eclipse.team.internal.ccvs.core.CVSTeamProvider.notifyEditUnedit(CVSTeamProvider.java:628)
	at org.eclipse.team.internal.ccvs.core.CVSTeamProvider.edit(CVSTeamProvider.java:535)
	at org.eclipse.team.internal.ccvs.core.CVSCoreFileModificationValidator.performEdit(CVSCoreFileModificationValidator.java:129)
	at org.eclipse.team.internal.ccvs.ui.FileModificationValidator.access$1(FileModificationValidator.java:1)
	at org.eclipse.team.internal.ccvs.ui.FileModificationValidator$2.run(FileModificationValidator.java:102)
	at org.eclipse.team.internal.ui.Utils$2.run(Utils.java:213)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	at org.eclipse.team.internal.ui.Utils.runWithProgress(Utils.java:209)
	at org.eclipse.team.internal.ccvs.ui.CVSUIPlugin.runWithProgress(CVSUIPlugin.java:236)
	at org.eclipse.team.internal.ccvs.ui.FileModificationValidator.edit(FileModificationValidator.java:110)
	at org.eclipse.team.internal.ccvs.ui.FileModificationValidator.edit(FileModificationValidator.java:47)
	at org.eclipse.team.internal.ccvs.core.CVSCoreFileModificationValidator.validateEdit(CVSCoreFileModificationValidator.java:45)
	at org.eclipse.team.internal.ccvs.core.CVSCoreFileModificationValidator.edit(CVSCoreFileModificationValidator.java:73)
	at org.eclipse.team.internal.ccvs.core.CVSCoreFileModificationValidator.validateSave(CVSCoreFileModificationValidator.java:58)
	at org.eclipse.team.internal.core.FileModificationValidatorManager.validateSave(FileModificationValidatorManager.java:99)
	at org.eclipse.core.internal.resources.Workspace$6.run(Workspace.java:2039)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.core.internal.resources.Workspace.validateSave(Workspace.java:2042)
	at org.eclipse.core.internal.resources.File.setContents(File.java:355)
Comment 1 Michael Valenta CLA 2006-08-21 10:25:37 EDT
The error is occuring because CVs is trying to prompt to get the password for the repository location. It is doin this because a read-only file is being modified and such a file must be "cvs edit"ed before being modified. 

One way to get around the problem would be to set the Team>CVS>Watch/Edit preference to edit the file without contacting the server. This would avoid the connection attempt. The connection can also be avoided by making the file writtable before trying to edit it.

Why is the file read-only in the first place? This should only happen if the repository is configured to use watch/edit. If you are supposed to use watch/edit, then you will need to ensure that you have a password associated with the repository location before you attempt to modify a file.
Comment 2 Alain Picard CLA 2006-08-21 10:33:27 EDT
You are correct in that CVS is setup to use watch/edit and that is why the file is read-only. But the password is already saved and if I go to that file and open it in an editor and start editing it, I am not getting prompted for a password, nor am I being shown the edit window in this case. So no UI prompts or display are showing.

If this is the case, shouldn't this work in a headless fashion and the bug be reopened?

Comment 3 Michael Valenta CLA 2006-08-21 10:57:02 EDT
The prompt only occurs when authentication fails. If we changed the code to avoid prompting, a CVSAuthenticationException would still be thrown so you wouldn't be any better off. Somehow, the password you are providing is not being used when you are running headless. How are you providing the password?
Comment 4 Alain Picard CLA 2006-08-21 11:25:09 EDT
My password as been saved long ago as part of the CVS repository location setup. The only time I am prompted for a password is usually after an Eclipse upgrade.

That is why i don't understand the "only when authentication fails" here. From a user perspective it doesn't fail authentication for sure.

I surely understand that if the password is required and needs to be prompted for, the only better solution would be a CVSAuthenticationException instead of the current error, but that the end result would be the same and thus a pretty minor improvement.

But that being said, this is not the case here and we would not expect the headless operation to work if the password is required.
Comment 5 Michael Valenta CLA 2006-08-21 11:35:05 EDT
I'm not sure I know what you mean by your last sentence. All I can say is that, from the stack trace you have provided, it is pretty clear that authentication is failing and that is what is causing the attempt to prompt. How do you check the projects out for your headless application? Is it possible that the authentication information or connection method is different?
Comment 6 Alain Picard CLA 2006-08-21 12:53:55 EDT
You are right that from the stacktrace the code is prompting for a password. I can see by stepping through some of the code that the CVSRepositoryLocation object is built from the return of fromString() in KnownRepositories. This location string doesn't contain the password and thus when Session calls openConnection, the password is not part of the object passed. The openConnection does look for a cached password, but I believe that this is different from a saved password.

But when I go in and look at my CVS Repository location properties, I see that a password is specified and the save password checkbox is selected.

I am by no means an expert in this complex part of Eclipse but I can surely run any debug test that you want me to conduct.
Comment 7 Michael Valenta CLA 2006-08-21 13:04:21 EDT
The password is retrieved from the keyring file in the CVSRepositoryLocation#openConnecton method. You could debug that to see if the password is being retrieved. If not, you may want to use a custom location for the keyring file (using the -keyring command line option). That way, you can ensure that the keyring file that you use in the Workbench is also available when running headless.
Comment 8 Alain Picard CLA 2006-08-21 14:41:51 EDT
Right on. That was the issue. 

When running with the launch configuration, I was using the default configuration area, instead of setting it to the "normal" default. I have now set it to "${eclipse_home}/configuration" and everything is now running smoothly. BTW, there seems to be no documentation on the configuration tab of the launch configuration. Not that I would have magically caught it, but I would surely at some point have better understood what it was used for.

Thanks for all the help and keep up the good work.