2016-12-01 7 views
1

Eclipse E4 애플리케이션에 업데이트 기능을 추가하고 있습니다. 여기서는 Lars Vogel의 소스 코드 tutorial을 사용했습니다. 애플리케이션을 테스트 할 때 provisioningJob은 항상 null입니다. Eclipse로 실행될 때만 null이어야합니다. 그러나 내 보낸 응용 프로그램을 업데이트하려고 할 때 provisioningJob은 여전히 ​​null입니다. 내가 뭘 잘못하고있어?p2를 사용하여 Eclipse E4 애플리케이션 업데이트

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; 
} 

은}

+0

문제는 어떻습니까? 같은 문제가 발생했습니다. 이 브랜치는 다음 코드를 실행했다 : if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) { – aviit

+0

나는 그걸 보지 않았다. 이 일을하기위한 노력은 높았습니다. 우리는 Inno 설치 프로그램에서 만든 응용 프로그램에 외부 업데이터를 사용하고 있습니다. – JimmyD

답변

1

P2는 내부적으로 서비스를 많이 사용하고, 그 명시 적으로 번들 종속성으로 참조되지 않습니다. 따라서 필요한 추가 서비스가 누락 될 수 있습니다. PDE 시작 안의 "Add required ..."를 통해 이들을 추가하는 것이 작동하지 않습니다. 시작 또는 제품에 실제로 모든 요구 사항이 포함되어 있는지 확인하십시오. 내용은 org.eclipse.equinox.p2.sdk부터 시작합니다. 이것은 확실히 작동해야합니다. 그런 다음 요구 사항을 org.eclipse.equinox.p2.core.feature 또는 그 이하로 줄이려고 시도 할 수 있습니다.

+0

org.eclipse.equinox.p2.sdk가 없습니다. org.eclipse.equinox.p2.ui.sdk 만 ​​찾을 수 있습니다. – JimmyD

+0

[Eclipse 타겟] (http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.pde.doc.user%2Fconcepts%2Ftarget.htm)을 사용합니까? 그렇다면 업데이트 사이트 'http : // download'에서 IU 기능인'org.eclipse.equinox.p2.sdk (.feature.group)'또는 'Equinox p2, SDK'이름을 선택할 수 있어야합니다. .eclipse.org/releases/neon /' p2 카테고리뿐만 아니라 IU 이름을 보려면 "카테고리로 항목 그룹화"를 선택 취소하십시오. –