Java Code Examples for org.netbeans.api.autoupdate.InstallSupport#doValidate()

The following examples show how to use org.netbeans.api.autoupdate.InstallSupport#doValidate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MissingModuleProblemsProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static InstallationResult installUpdate(@NonNull final UpdateElement update) {
    final ProgressHandle installHandle = ProgressHandle.createHandle(NbBundle.getMessage(
            MissingModuleProblemsProvider.class,
            "TXT_InstallModule",
            update.getDisplayName()));
    installHandle.start();
    try {
        final OperationContainer<InstallSupport> container = OperationContainer.createForInstall();
        container.add(Collections.singleton(update));
        final InstallSupport support = container.getSupport();
        try {
            final InstallSupport.Validator v = support.doDownload(installHandle, true, true);
            final InstallSupport.Installer i = support.doValidate(v, installHandle);
            final Restarter r = support.doInstall(i, installHandle);
            return InstallationResult.success(support, r);
        } catch (OperationException ex) {
            Exceptions.printStackTrace(ex);
        }
    } finally {
        installHandle.finish();
    }
    return InstallationResult.failure();
}
 
Example 2
Source File: NbmExternalTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void doInstall(OperationContainer<InstallSupport> installContainer) throws OperationException {
    InstallSupport support = installContainer.getSupport();
    assertNotNull(support);

    InstallSupport.Validator v = support.doDownload(null, false);
    assertNotNull(v);
    InstallSupport.Installer i = support.doValidate(v, null);
    assertNotNull(i);
    Restarter r = null;
    try {
        r = support.doInstall(i, null);
    } catch (OperationException ex) {
        if (OperationException.ERROR_TYPE.INSTALL == ex.getErrorType()) {
            // can ingore
            // module system cannot load the module either
        } else {
            fail(ex.toString());
        }
    }
    assertNull("Installing new element require restarting though it should not", r);
}
 
Example 3
Source File: UpdateDisabledModuleTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testSelf() throws Exception {
    File f = new File(new File(new File(ud, "config"), "Modules"), "com-example-testmodule-cluster.xml");
    f.delete();

    assertFalse("No Config file before: " + f, f.exists());

    MockServices.setServices(UP.class);
    UpdateUnit update = UpdateManagerImpl.getInstance().getUpdateUnit(moduleCodeNameBaseForTest());

    assertNotNull("There is an NBM to update", update);
    OperationContainer<InstallSupport> oc = OperationContainer.createForUpdate();
    oc.add(update, update.getAvailableUpdates().get(0));
    final InstallSupport support = oc.getSupport();
    Validator down = support.doDownload(null, true);
    Installer inst = support.doValidate(down, null);
    Restarter res = support.doInstall(inst, null);
    System.setProperty("netbeans.close.no.exit", "true");
    support.doRestart(res, null);
    UpdaterInternal.update(null, null, null);

    assertFalse("No Config file created in for upgrade: " + f, f.exists());
}
 
Example 4
Source File: NbmAdvancedTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected UpdateElement installUpdateUnit (UpdateUnit unit) {
    OperationContainer ic = OperationContainer.createForInstall ();
    assertNotNull (unit + " has available update.", unit.getAvailableUpdates ());
    ic.add (unit.getAvailableUpdates ().get (0));
    OperationInfo requiresInfo = (OperationInfo) ic.listAll ().iterator ().next ();
    assertNotNull (requiresInfo);
    ic.add (requiresInfo.getRequiredElements ());
    
    assertTrue ("Install operation on " + unit + " is valid.", ic.listInvalid ().isEmpty ());
    assertFalse ("Something will be installed for " + unit, ic.listAll ().isEmpty ());
    InstallSupport is = (InstallSupport) ic.getSupport ();
    try {
        
        InstallSupport.Validator v = is.doDownload (null, false);
        InstallSupport.Installer i = is.doValidate (v, null);
        is.doInstall (i, null);
        
    } catch (OperationException ex) {
        if (OperationException.ERROR_TYPE.INSTALL == ex.getErrorType ()) {
            // can ingore
            // module system cannot load the module either
        } else {
            fail (ex.toString ());
        }
    }
    
    // check if unit was installed
    assertNotNull (unit + " is installed.", unit.getInstalled ());
    
    return unit.getInstalled ();
}
 
Example 5
Source File: FragmentModuleTestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected UpdateElement installModuleWithRestart(UpdateUnit toInstall, UpdateElement installElement, AtomicReference<OperationSupport.Restarter> restarterOut) throws Exception {
    installElement = (installElement != null) ? installElement : toInstall.getAvailableUpdates ().get (0);
    assertNull (getModuleInfos ().get (toInstall.getCodeName ()));
    assertNotNull (toInstall);

    OperationSupport.Restarter r = null;

    OperationContainer<InstallSupport> container = OperationContainer.createForInstall ();
    OperationContainer.OperationInfo<InstallSupport> info = container.add (installElement);
    assertNotNull (info);
    container.add (info.getRequiredElements ());

    InstallSupport support = container.getSupport ();
    assertNotNull (support);

    InstallSupport.Validator v = support.doDownload (null, false);
    assertNotNull (v);
    InstallSupport.Installer i = support.doValidate (v, null);
    assertNotNull (i);
    assertNull (support.getCertificate (i, installElement)); // Test NBM is not signed nor certificate
    assertFalse (support.isTrusted (i, installElement));
    assertFalse (support.isSigned (i, installElement));
    try {
        r = support.doInstall (i, null);
    } catch (OperationException ex) {
        if (OperationException.ERROR_TYPE.INSTALL == ex.getErrorType ()) {
            // can ingore
            // module system cannot load the module either
        } else {
            fail (ex.toString ());
        }
    }
    if (restarterOut != null) {
        restarterOut.set(r);
    }
    return installElement;
}
 
Example 6
Source File: UpdateHandler.java    From netbeans-wakatime with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static Installer doVerify(InstallSupport support, Validator validator) throws OperationException {
    final String displayName = "Validating WakaTime plugin...";
    ProgressHandle validateHandle = ProgressHandleFactory.createHandle(
        displayName,
        new Cancellable () {
            @Override
            public boolean cancel () {
                return true;
            }
        }
    );
    Installer installer = support.doValidate(validator, validateHandle);
    return installer;
}
 
Example 7
Source File: UpdateFromNbmTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testSelf() throws Exception {
    UpdateUnit toUpdate = UpdateManagerImpl.getInstance().getUpdateUnit(moduleCodeNameBaseForTest());
    assertNotNull(toUpdate);
    assertEquals(2, toUpdate.getAvailableUpdates ().size());
    UpdateElement engine1_0 = toUpdate.getAvailableUpdates ().get (1);
    assertNotNull(engine1_0);
    assertEquals("1.0",engine1_0.getSpecificationVersion().toString());
    installModule(toUpdate, engine1_0);
    toUpdate = UpdateManagerImpl.getInstance().getUpdateUnit(moduleCodeNameBaseForTest());
    assertNotNull(toUpdate.getInstalled());

    MockServices.setServices(MyProvider.class, CustomItemsProvider.class);
    URL engineURL = TestUtils.class.getResource("data/org-yourorghere-engine-1-2.nbm");
    assertNotNull(engineURL);
    File engineFile = TestUtils.getFile(this, engineURL);
    assertTrue(engineFile.exists());

    URL independentURL = TestUtils.class.getResource("data/org-yourorghere-independent-1-1.nbm");
    assertNotNull(independentURL);
    File independentFile = TestUtils.getFile(this, independentURL);
    assertTrue(independentFile.exists());

    String source = "local-downloaded";
    List<UpdateUnit> units =  UpdateUnitProviderFactory.getDefault ().create (source, new File[] {engineFile, independentFile}).
            getUpdateUnits (UpdateManager.TYPE.MODULE);
    assertEquals(2, units.size());
    UpdateUnit nbmsEngine =  null;
    if (units.get(0).getCodeName().indexOf("engine") != -1) {
        nbmsEngine = units.get (0);
    } else if (units.get(1).getCodeName().indexOf("engine") != -1) {
        nbmsEngine = units.get (1);
    }
    assertNotNull (nbmsEngine);
    assertNotNull(nbmsEngine.getInstalled());
    assertEquals(1, nbmsEngine.getAvailableUpdates().size());
    UpdateElement engine1_2 = nbmsEngine.getAvailableUpdates().get(0);
    assertEquals(source,engine1_2.getSource());
    assertEquals("1.2",engine1_2.getSpecificationVersion().toString());
    OperationContainer<InstallSupport> oc =  OperationContainer.createForUpdate();
    OperationContainer.OperationInfo info = oc.add(nbmsEngine, engine1_2);
    assertNotNull(info);
    final Set brokeDeps = info.getBrokenDependencies();
    assertEquals("One broken dep: " + brokeDeps, 1, brokeDeps.size());
    String brokenDep = (String)brokeDeps.toArray()[0];
    assertEquals("module org.yourorghere.independent > 1.1",brokenDep);
    assertEquals(0, info.getRequiredElements().size());
    UpdateUnit independentEngine =  null;
    if (units.get(0).getCodeName().indexOf("independent") != -1) {
        independentEngine = units.get (0);
    } else if (units.get(1).getCodeName().indexOf("independent") != -1) {
        independentEngine = units.get (1);
    }
    assertNotNull (independentEngine);
    assertNotNull(independentEngine.getInstalled());

    UpdateElement independent1_1 = independentEngine.getAvailableUpdates().get(0);
    assertEquals(source,independent1_1.getSource());
    assertEquals("1.1",independent1_1.getSpecificationVersion().toString());

    OperationContainer.OperationInfo info2 = oc.add(independentEngine, independent1_1);
    assertEquals(0, info.getBrokenDependencies().size());
    assertEquals(0, info.getRequiredElements().size());
    assertEquals(0, info2.getBrokenDependencies().size());
    assertEquals(0, info2.getRequiredElements().size());

    InstallSupport support = oc.getSupport();
    assertNotNull(support);

    InstallSupport.Validator v = support.doDownload(null, false);
    assertNotNull(v);
    InstallSupport.Installer i = support.doValidate(v, null);
    assertNotNull(i);
    //assertNotNull(support.getCertificate(i, upEl));
    Restarter r = null;
    try {
        r = support.doInstall(i, null);
    } catch (OperationException ex) {
        if (OperationException.ERROR_TYPE.INSTALL == ex.getErrorType ()) {
            // can ingore
            // module system cannot load the module either
        } else {
            fail (ex.toString ());
        }
    }
    assertNotNull ("Install update " + engine1_2 + " needs restart.", r);
    support.doRestartLater (r);

    MockServices.setServices(MyProvider.class, CustomItemsProvider.class);
    assertTrue (nbmsEngine + " is waiting for Restart IDE.", nbmsEngine.isPending ());
}
 
Example 8
Source File: InstallTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void installPlugin(UpdateElement updateElement) {
    log("");
    log("-----------------------------------------------------------");
    log("|  INSTALLING FOLLOWING PLUGIN :                          |");
    log("-----------------------------------------------------------");
    log("[" + updateElement.getDisplayName() + "]" + updateElement.getCodeName());


    int numberOfPluginsToInstall = 0;

    OperationContainer<InstallSupport> install = OperationContainer.createForInstall();

    OperationInfo info = null;
    try {
        info = install.add(updateElement);
    } catch (IllegalArgumentException illegalArgumentException) {
        fail("Cannot install plugin [" + updateElement.getDisplayName() + "] " + updateElement.getCodeName() + " - probably it has already been installed by some other test. Check .log files of previously executed tests.");
        illegalArgumentException.printStackTrace();
    }

    log("Broken dependencies:");
    log(info.getBrokenDependencies().toString());
    numberOfPluginsToInstall++;
    for (OperationInfo i : install.listAll()) {
        Set<UpdateElement> reqElements = i.getRequiredElements();
        log("List of required plugins is:");
        for (UpdateElement reqElm : reqElements) {
            if (!currentlyUpdatePlugins.contains(reqElm) &&
                    !currentlyInstalledPlugins.contains(reqElm) &&
                    !currentlyPendingInstalls.contains(reqElm)) {
                install.add(reqElm);
                log("[" + reqElm.getDisplayName() + "]" + reqElm.getCodeName());
                numberOfPluginsToInstall++;
            }
        }
    }
    log("Number Of Plugins to install:" + numberOfPluginsToInstall);
    List<OperationInfo<InstallSupport>> lst = install.listAll();
    assertTrue("List of invalid is not empty.", install.listInvalid().isEmpty());
    assertTrue("Dependencies broken for plugin '" + updateElement.getDisplayName() + "'." + info.getBrokenDependencies().toString(), info.getBrokenDependencies().size() == 0);
    InstallSupport is = install.getSupport();
    try {
        Validator v = is.doDownload(null, true);
        assertNotNull("Validator for " + updateElement + " is not null.", v);
        Installer installer;
        try {
            installer = is.doValidate(v, null);
            Restarter r = is.doInstall(installer, null);
            if (r == null) {
            } else {
                is.doRestartLater(r);

            }
        } catch (OperationException oex) {
            fail("Unsuccessful operation!");
            oex.printStackTrace();
        }
    } catch (Exception e) {
        fail("Cannot download required plugin or some dependency - probably it doesn't exist");
        e.printStackTrace();
    }
    log("-----------------------------------------------------------");
}
 
Example 9
Source File: UpdateHandler.java    From jeddict with Apache License 2.0 4 votes vote down vote up
static Installer doVerify(InstallSupport support, Validator validator) throws OperationException {
    final String displayName = "Validating Jeddict plugin...";
    ProgressHandle validateHandle = ProgressHandleFactory.createHandle(displayName, () -> true);
    Installer installer = support.doValidate(validator, validateHandle);
    return installer;
}