I have RCP application that uses headless update with p2 repository, written in eclipse 3.6. After decission to be migrated to Eclipse 3.7 it turned out my workarround would not work, as some classes are no more there in 3.7. What was the issue in 3.6?
The issue in Eclipse 3.6: The application is checking for updates before the start of the core plugin. It tries to connect to the p2 repository. If there is connection to it, it searches for updates, if there are such, updates, if not it says nothing for update and continue. If there is no connection, there was exception that is deep in equinox/eclipse framework, that has been handled by the framework and it never appear to us, thus the application cannot say wheter there is connection or not, as result it says there is nothing to update.
The solution: After some days speding in solutions for this i found a workarround for this. Solution was creating a class for validating the "Status" of the repository, e.g. do i have connection to it or not. Here is my class:
public class RepositoryValidator {
private final static String urlExtension = "artifacts.jar"; //$NON-NLS-1$
private static RepositoryValidator instance;
private RepositoryValidator() {
}
public static RepositoryValidator sharedInstance() {
if (instance == null) {
instance = new RepositoryValidator();
}
return instance;
}
public IStatus checkRepositoryStatus(URI repoURI) {
try {
URI checkURI = new URI(repoURI.toString() + urlExtension);
ILog logger = Activator.getDefault().getLog();
logger.log(new Status(IStatus.INFO, Activator.PLUGIN_ID,
"CHECK REPOSITORY \"artifacts.jar\" - " //$NON-NLS-1$
+ checkURI.toString()));
long result = RepositoryTransport.getInstance().getLastModified(
checkURI, new NullProgressMonitor());
if (result == 0) {
logger.log(new Status(IStatus.INFO, Activator.PLUGIN_ID,
"RESULT FROM CHECK - " + result)); //$NON-NLS-1$
return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
"WRONG SERVER RESPONCE!!!"); //$NON-NLS-1$
}
} catch (Exception e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
"CONNECTION EXCEPTION", e); //$NON-NLS-1$
}
return new Status(IStatus.OK, Activator.PLUGIN_ID,
"REPOSITORY IS REACHABLE AND OK!!!"); //$NON-NLS-1$
}
}
What i basically do here is checking when the artifacts.jar has been modified, if i can access it i have connection, if not i dont.
The Issue in Eclipse 3.7: In the solution for Eclipse 3.6 i was using RepositoryTransport class, which is no more available in 3.7. I was trying to find out whether this class have been replaced by other, or is there a method in the available class i could reach similar functionality. I could not find anything related to the subject, nor for the class, neither for the solution for the issue in 3.6.
Deos anybody know anything related to this issue? Is there fix for the solution in 3.6 itself, or does they decide to replace this class with any similar funcionali开发者_开发百科ty? Or if anybody has an idea for other workarround for this issue?
Thanks in advace.
First of all, RepositoryTransport is moved to package org.eclipse.equinox.internal.p2.transport.ecf in a newly introduced bundle after code refactoring in 3.7.
Secondly, I don't think your workaround is a good way to check whether it has updates or not. You should use p2 API to load your repository, then query whether it contains updates for your installation.
精彩评论