Я добавляю функцию обновления в своем приложении Eclipse E4. Для этого я использовал исходный код и tutorial от Lars Vogel. Когда я проверяю свое приложение, инициализацияJob всегда равна нулю. Он должен быть равен нулю, когда он запускается в Eclipse. Но когда я пытаюсь обновить экспортированное приложение, инициализация job по-прежнему равна нулю. Что я делаю неправильно?Обновление приложения Eclipse E4 с использованием p2
public class UpdateHandler {
private static final String REPOSITORY_LOC = System.getProperty("UpdateHandler.Repo",
"file:////updateServer/repository");
@Execute
public void execute(final IProvisioningAgent agent, final Shell shell, final UISynchronize sync,
final IWorkbench workbench) {
Job updateJob = new Job("Update Job") {
@Override
protected IStatus run(final IProgressMonitor monitor) {
return checkForUpdates(agent, shell, sync, workbench, monitor);
}
};
updateJob.schedule();
}
private IStatus checkForUpdates(final IProvisioningAgent agent, final Shell shell, final UISynchronize sync,
final IWorkbench workbench, IProgressMonitor monitor) {
// configure update operation
final ProvisioningSession session = new ProvisioningSession(agent);
final UpdateOperation operation = new UpdateOperation(session);
configureUpdate(operation);
// check for updates, this causes I/O
final IStatus status = operation.resolveModal(monitor);
// failed to find updates (inform user and exit)
if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
LogModule.log(LogLevel.INFO, "No updated has been found");
showMessage(shell, sync);
return Status.CANCEL_STATUS;
}
else
{
LogModule.log(LogLevel.INFO, "Updates are found");
}
// run installation
final ProvisioningJob provisioningJob = operation.getProvisioningJob(monitor);
// updates cannot run from within Eclipse IDE!!!
if (provisioningJob == null) {
System.err.println("Trying to update from the Eclipse IDE? This won't work!");
LogModule.log(LogLevel.WARNING, "Trying to update from the Eclipse IDE? This won't work!");
return Status.CANCEL_STATUS;
}
configureProvisioningJob(provisioningJob, shell, sync, workbench);
//provisioningJob.schedule();
provisioningJob.run(monitor);
return Status.OK_STATUS;
}
private void configureProvisioningJob(ProvisioningJob provisioningJob, final Shell shell, final UISynchronize sync,
final IWorkbench workbench) {
// register a job change listener to track
// installation progress and notify user upon success
provisioningJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
//if (event.getResult().isOK()) {
sync.syncExec(new Runnable() {
@Override
public void run() {
LogModule.log(LogLevel.INFO, "Update ready to install");
boolean restart = MessageDialog.openQuestion(shell, "Updates installed, restart?",
"Updates have been installed. Do you want to restart?");
if (restart) {
workbench.restart();
}
}
});
// }
super.done(event);
}
});
}
private void showMessage(final Shell parent, final UISynchronize sync) {
sync.syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(parent, "No update",
"No updates for the current installation have been found.");
}
});
}
private UpdateOperation configureUpdate(final UpdateOperation operation) {
// create uri and check for validity
URI uri = null;
try {
uri = new URI(REPOSITORY_LOC);
} catch (final URISyntaxException e) {
System.err.println(e.getMessage());
LogModule.log(LogLevel.ERROR, e.getMessage());
return null;
}
// set location of artifact and metadata repo
operation.getProvisioningContext().setArtifactRepositories(new URI[] { uri });
operation.getProvisioningContext().setMetadataRepositories(new URI[] { uri });
return operation;
}
}
Как насчет вашей проблемы? Я столкнулся с той же проблемой. Код работал в этой ветке: if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) { – aviit
Я перестал смотреть на это. Усилия сделать эту работу были высокими. Мы используем внешний файл обновления для нашего приложения, созданного в настройках Inno. – JimmyD