Java UpdateAction Example

说明

java updateaction示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Java

类/类型: UpdateAction

示例#1
文件: UpdateActionTest.java项目: pkdevboxy/sonar-intellij

  @Test
  public void testEnabled() {
    SonarLintStatus status = mock(SonarLintStatus.class);

    when(status.isRunning()).thenReturn(false);
    assertThat(action.isEnabled(status)).isTrue();

    when(status.isRunning()).thenReturn(true);
    assertThat(action.isEnabled(status)).isFalse();
  }

示例#2
文件: SetupMenuActions.java项目: norain2050/daima111

 public void init(Context context) {
   mContext = context;
   SystemAction.Init();
   DesktopAction.Init();
   EffectAction.Init();
   StatusBarAction.Init();
   ThemeAction.Init();
   SystemPlugAction.Init();
   ShareAction.Init();
   UpdateAction.Init();
   FeedBackAction.Init();
   BackupDesktopAction.Init();
   LockEditAction.Init();
   ScreenEditAction.Init();
   UpdateFeedbackAction.Init();
   InstallHelpAction.Init();
   ResetClingAction.Init();
   LockerSettingAction.Init();
   DefaultSceneAction.Init(); // xiatian add //DefaultScene
   // wanghongjian add start //enable_DefaultScene
   ChangeSceneAction.Init();
   SceneMainAction.Init();
   SceneClassicAction.Init();
   SceneSettingAction.Init();
   // wanghongjian add end
   // zqh add ,for test
   DesktopEffect.Init();
   SuggestFeedback.Init();
   ShowDesktop.Init();
 }

示例#3
文件: SVNUpdater.java项目: juancadavid/papyrus

  @Override
  public IStatus update() {
    IFile[] resourcesToProcess = getTargetFiles(getTargetResources());
    // The all project of each file shall be updated (In order to see if new files appeared (New
    // control))
    Set<IProject> projects = new HashSet<IProject>();
    for (IFile f : resourcesToProcess) {
      projects.add(f.getProject());
    }

    IProject[] projectsToUpdate = new IProject[projects.size()];
    projects.toArray(projectsToUpdate);
    if (ITracingConstant.UPDATE_TRACING) {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.append("Updating projects: ").append("\n");
      for (IProject p : projectsToUpdate) {
        stringBuilder.append(p.getFullPath()).append("\n");
      }
      Tracer.logInfo(stringBuilder.toString());
    }
    CompositeOperation op = UpdateAction.getUpdateOperation(projectsToUpdate, SVNRevision.HEAD);
    ICancellableOperationWrapper runnable = UIMonitorUtility.doTaskNowDefault(op, false);
    IActionOperation resultStatus = runnable.getOperation();

    return resultStatus.getStatus();
  }

示例#4
文件: UpdateActionTest.java项目: hutea/sonarqube

  @Test
  public void IAE_is_raised_when_there_is_no_plugin_update_for_the_key() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("No plugin with key 'pluginKey'");

    underTest.handle(validRequest, response);
  }

示例#5
文件: UpdateActionTest.java项目: hutea/sonarqube

  @Test
  public void IAE_is_raised_when_key_param_is_not_provided() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Parameter 'key' is missing");

    underTest.handle(invalidRequest, response);
  }

示例#6
文件: UpdateActionTest.java项目: hutea/sonarqube

  @Test
  public void user_must_have_system_admin_permission() throws Exception {
    expectedException.expect(ForbiddenException.class);
    expectedException.expectMessage("Insufficient privileges");

    // no permission on user
    userSessionRule.setGlobalPermissions();

    underTest.handle(validRequest, response);
  }

示例#7
文件: UpdateActionTest.java项目: hutea/sonarqube

  @Test
  public void IAE_is_raised_when_update_center_is_unavailable() throws Exception {
    when(updateCenterFactory.getUpdateCenter(anyBoolean()))
        .thenReturn(Optional.<UpdateCenter>absent());

    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("No plugin with key 'pluginKey'");

    underTest.handle(validRequest, response);
  }

示例#8
文件: UpdateActionTest.java项目: pkdevboxy/sonar-intellij

  @Test
  public void testAction() {
    action.actionPerformed(SonarLintTestUtils.createAnActionEvent(getProject()));

    verify(runner).tryUpdate();
    verify(runner).getVersion();
    verifyNoMoreInteractions(runner);

    SonarLintStatus status = getProject().getComponent(SonarLintStatus.class);
    assertThat(status.isRunning()).isFalse();
  }

示例#9
文件: UpdateActionTest.java项目: pkdevboxy/sonar-intellij

 @Test
 public void testFailIfRunning() {
   SonarLintStatus status = getProject().getComponent(SonarLintStatus.class);
   status.tryRun();
   try {
     action.actionPerformed(SonarLintTestUtils.createAnActionEvent(getProject()));
     fail("Should throw exception");
   } catch (IllegalStateException e) {
     assertThat(e.getMessage()).isEqualTo("Unable to update SonarLint as an analysis is on-going");
   } finally {
     status.stopRun();
   }
 }

示例#10
文件: UpdateActionTest.java项目: hutea/sonarqube

  @Test
  public void if_plugin_has_an_update_download_is_triggered_with_latest_version_from_updatecenter()
      throws Exception {
    Version version = Version.create("1.0");
    when(updateCenter.findPluginUpdates())
        .thenReturn(
            ImmutableList.of(
                PluginUpdate.createWithStatus(
                    new Release(new Plugin(PLUGIN_KEY), version), Status.COMPATIBLE)));

    underTest.handle(validRequest, response);

    verify(pluginDownloader).download(PLUGIN_KEY, version);
    assertThat(response.outputAsString()).isEmpty();
  }

示例#11
文件: UpdateActionTest.java项目: hutea/sonarqube

  @Test
  public void action_update_is_defined() {
    WsTester wsTester = new WsTester();
    WebService.NewController newController =
        wsTester.context().createController(DUMMY_CONTROLLER_KEY);

    underTest.define(newController);
    newController.done();

    WebService.Controller controller = wsTester.controller(DUMMY_CONTROLLER_KEY);
    assertThat(controller.actions()).extracting("key").containsExactly(ACTION_KEY);

    WebService.Action action = controller.actions().iterator().next();
    assertThat(action.isPost()).isTrue();
    assertThat(action.description()).isNotEmpty();
    assertThat(action.responseExample()).isNull();

    assertThat(action.params()).hasSize(1);
    WebService.Param key = action.param(KEY_PARAM);
    assertThat(key).isNotNull();
    assertThat(key.isRequired()).isTrue();
    assertThat(key.description()).isNotNull();
  }

示例#12
文件: ToolsMenu.java项目: rplabon/frostwire-desktop

 @Override
 protected void refresh() {
   updateAction.refresh();
 }

示例#13
文件: ItemUpdate.java项目: divinoirj/DSpaceOSUKB

  /** @param argv */
  public static void main(String[] argv) {
    // create an options object and populate it
    CommandLineParser parser = new PosixParser();

    Options options = new Options();

    // processing basis for determining items
    // item-specific changes with metadata in source directory with dublin_core.xml files
    options.addOption("s", "source", true, "root directory of source dspace archive ");

    // actions  on items
    options.addOption(
        "a",
        "addmetadata",
        true,
        "add metadata specified for each item; multiples separated by semicolon ';'");
    options.addOption("d", "deletemetadata", true, "delete metadata specified for each item");

    options.addOption("A", "addbitstreams", false, "add bitstreams as specified for each item");

    // extra work to get optional argument
    Option delBitstreamOption =
        new Option("D", "deletebitstreams", true, "delete bitstreams as specified for each item");
    delBitstreamOption.setOptionalArg(true);
    delBitstreamOption.setArgName("BitstreamFilter");
    options.addOption(delBitstreamOption);

    // other params
    options.addOption("e", "eperson", true, "email of eperson doing the update");
    options.addOption(
        "i",
        "itemfield",
        true,
        "optional metadata field that containing item identifier; default is dc.identifier.uri");
    options.addOption(
        "F", "filter-properties", true, "filter class name; only for deleting bitstream");
    options.addOption("v", "verbose", false, "verbose logging");

    // special run states
    options.addOption("t", "test", false, "test run - do not actually import items");
    options.addOption(
        "P", "provenance", false, "suppress altering provenance field for bitstream changes");
    options.addOption("h", "help", false, "help");

    int status = 0;
    boolean isTest = false;
    boolean alterProvenance = true;
    String itemField = null;
    String metadataIndexName = null;

    Context context = null;
    ItemUpdate iu = new ItemUpdate();

    try {
      CommandLine line = parser.parse(options, argv);

      if (line.hasOption('h')) {
        HelpFormatter myhelp = new HelpFormatter();
        myhelp.printHelp("ItemUpdate", options);
        pr("");
        pr("Examples:");
        pr(
            "  adding metadata:     ItemUpdate -e [email protected] -s sourcedir -a dc.contributor -a dc.subject ");
        pr(
            "  deleting metadata:   ItemUpdate -e [email protected] -s sourcedir -d dc.description.other");
        pr("  adding bitstreams:   ItemUpdate -e [email protected] -s sourcedir -A -i dc.identifier");
        pr("  deleting bitstreams: ItemUpdate -e [email protected] -s sourcedir -D ORIGINAL ");
        pr("");

        System.exit(0);
      }

      if (line.hasOption('v')) {
        verbose = true;
      }

      if (line.hasOption('P')) {
        alterProvenance = false;
        pr("Suppressing changes to Provenance field option");
      }

      iu.eperson = line.getOptionValue('e'); // db ID or email

      if (!line.hasOption('s')) // item specific changes from archive dir
      {
        pr("Missing source archive option");
        System.exit(1);
      }
      String sourcedir = line.getOptionValue('s');

      if (line.hasOption('t')) // test
      {
        isTest = true;
        pr("**Test Run** - not actually updating items.");
      }

      if (line.hasOption('i')) {
        itemField = line.getOptionValue('i');
      }

      if (line.hasOption('d')) {
        String[] targetFields = line.getOptionValues('d');

        DeleteMetadataAction delMetadataAction =
            (DeleteMetadataAction) iu.actionMgr.getUpdateAction(DeleteMetadataAction.class);
        delMetadataAction.addTargetFields(targetFields);

        // undo is an add
        for (String field : targetFields) {
          iu.undoActionList.add(" -a " + field + " ");
        }

        pr("Delete metadata for fields: ");
        for (String s : targetFields) {
          pr("    " + s);
        }
      }

      if (line.hasOption('a')) {
        String[] targetFields = line.getOptionValues('a');

        AddMetadataAction addMetadataAction =
            (AddMetadataAction) iu.actionMgr.getUpdateAction(AddMetadataAction.class);
        addMetadataAction.addTargetFields(targetFields);

        // undo is a delete followed by an add of a replace record for target fields
        for (String field : targetFields) {
          iu.undoActionList.add(" -d " + field + " ");
        }

        for (String field : targetFields) {
          iu.undoActionList.add(" -a " + field + " ");
        }

        pr("Add metadata for fields: ");
        for (String s : targetFields) {
          pr("    " + s);
        }
      }

      if (line.hasOption('D')) // undo not supported
      {
        pr("Delete bitstreams ");

        String[] filterNames = line.getOptionValues('D');
        if ((filterNames != null) && (filterNames.length > 1)) {
          pr("Error: Only one filter can be a used at a time.");
          System.exit(1);
        }

        String filterName = line.getOptionValue('D');
        pr("Filter argument: " + filterName);

        if (filterName == null) // indicates using delete_contents files
        {
          DeleteBitstreamsAction delAction =
              (DeleteBitstreamsAction) iu.actionMgr.getUpdateAction(DeleteBitstreamsAction.class);
          delAction.setAlterProvenance(alterProvenance);
        } else {
          // check if param is on ALIAS list
          String filterClassname = filterAliases.get(filterName);

          if (filterClassname == null) {
            filterClassname = filterName;
          }

          BitstreamFilter filter = null;

          try {
            Class<?> cfilter = Class.forName(filterClassname);
            pr("BitstreamFilter class to instantiate: " + cfilter.toString());

            filter =
                (BitstreamFilter) cfilter.newInstance(); // unfortunate cast, an erasure consequence
          } catch (Exception e) {
            pr("Error:  Failure instantiating bitstream filter class: " + filterClassname);
            System.exit(1);
          }

          String filterPropertiesName = line.getOptionValue('F');
          if (filterPropertiesName != null) // not always required
          {
            try {
              // TODO try multiple relative locations, e.g. source dir
              if (!filterPropertiesName.startsWith("/")) {
                filterPropertiesName = sourcedir + File.separator + filterPropertiesName;
              }

              filter.initProperties(filterPropertiesName);
            } catch (Exception e) {
              pr(
                  "Error:  Failure finding properties file for bitstream filter class: "
                      + filterPropertiesName);
              System.exit(1);
            }
          }

          DeleteBitstreamsByFilterAction delAction =
              (DeleteBitstreamsByFilterAction)
                  iu.actionMgr.getUpdateAction(DeleteBitstreamsByFilterAction.class);
          delAction.setAlterProvenance(alterProvenance);
          delAction.setBitstreamFilter(filter);
          // undo not supported
        }
      }

      if (line.hasOption('A')) {
        pr("Add bitstreams ");
        AddBitstreamsAction addAction =
            (AddBitstreamsAction) iu.actionMgr.getUpdateAction(AddBitstreamsAction.class);
        addAction.setAlterProvenance(alterProvenance);

        iu.undoActionList.add(" -D "); // delete_contents file will be written, no arg required
      }

      if (!iu.actionMgr.hasActions()) {
        pr("Error - an action must be specified");
        System.exit(1);
      } else {
        pr("Actions to be performed: ");

        for (UpdateAction ua : iu.actionMgr) {
          pr("    " + ua.getClass().getName());
        }
      }

      pr("ItemUpdate - initializing run on " + (new Date()).toString());

      context = new Context();
      iu.setEPerson(context, iu.eperson);
      context.setIgnoreAuthorization(true);

      HANDLE_PREFIX = ConfigurationManager.getProperty("handle.canonical.prefix");
      if (HANDLE_PREFIX == null || HANDLE_PREFIX.length() == 0) {
        HANDLE_PREFIX = "http://hdl.handle.net/";
      }

      iu.processArchive(context, sourcedir, itemField, metadataIndexName, alterProvenance, isTest);

      context.complete(); // complete all transactions
      context.setIgnoreAuthorization(false);
    } catch (Exception e) {
      if (context != null && context.isValid()) {
        context.abort();
        context.setIgnoreAuthorization(false);
      }
      e.printStackTrace();
      pr(e.toString());
      status = 1;
    }

    if (isTest) {
      pr("***End of Test Run***");
    } else {
      pr("End.");
    }
    System.exit(status);
  }

示例#14
文件: ItemUpdate.java项目: divinoirj/DSpaceOSUKB

  private void processArchive(
      Context context,
      String sourceDirPath,
      String itemField,
      String metadataIndexName,
      boolean alterProvenance,
      boolean isTest)
      throws Exception {
    // open and process the source directory
    File sourceDir = new File(sourceDirPath);

    if ((sourceDir == null) || !sourceDir.exists() || !sourceDir.isDirectory()) {
      pr("Error, cannot open archive source directory " + sourceDirPath);
      throw new Exception("error with archive source directory " + sourceDirPath);
    }

    String[] dircontents = sourceDir.list(directoryFilter); // just the names, not the path
    Arrays.sort(dircontents);

    // Undo is suppressed to prevent undo of undo
    boolean suppressUndo = false;
    File fSuppressUndo = new File(sourceDir, SUPPRESS_UNDO_FILENAME);
    if (fSuppressUndo.exists()) {
      suppressUndo = true;
    }

    File undoDir = null; // sibling directory of source archive

    if (!suppressUndo && !isTest) {
      undoDir = initUndoArchive(sourceDir);
    }

    int itemCount = 0;
    int successItemCount = 0;

    for (String dirname : dircontents) {
      itemCount++;
      pr("");
      pr("processing item " + dirname);

      try {
        ItemArchive itarch = ItemArchive.create(context, new File(sourceDir, dirname), itemField);

        for (UpdateAction action : actionMgr) {
          pr("action: " + action.getClass().getName());
          action.execute(context, itarch, isTest, suppressUndo);
          if (!isTest && !suppressUndo) {
            itarch.writeUndo(undoDir);
          }
        }
        if (!isTest) {
          Item item = itarch.getItem();
          item.update(); // need to update before commit
          context.commit();
          item.decache();
        }
        ItemUpdate.pr("Item " + dirname + " completed");
        successItemCount++;
      } catch (Exception e) {
        pr("Exception processing item " + dirname + ": " + e.toString());
      }
    }

    if (!suppressUndo && !isTest) {
      StringBuilder sb = new StringBuilder("dsrun org.dspace.app.itemupdate.ItemUpdate ");
      sb.append(" -e ").append(this.eperson);
      sb.append(" -s ").append(undoDir);

      if (itemField != null) {
        sb.append(" -i ").append(itemField);
      }

      if (!alterProvenance) {
        sb.append(" -P ");
      }
      if (isTest) {
        sb.append(" -t ");
      }

      for (String actionOption : undoActionList) {
        sb.append(actionOption);
      }

      PrintWriter pw = null;
      try {
        File cmdFile = new File(undoDir.getParent(), undoDir.getName() + "_command.sh");
        pw = new PrintWriter(new BufferedWriter(new FileWriter(cmdFile)));
        pw.println(sb.toString());
      } finally {
        pw.close();
      }
    }

    pr("");
    pr(
        "Done processing.  Successful items: "
            + successItemCount
            + " of "
            + itemCount
            + " items in source archive");
    pr("");
  }

示例#15
文件: UpdateStatusControl.java项目: aam/dartdev

 private void setAction(UpdateAction action, boolean enabled) {
   this.updateAction = action;
   updateStatusButton.setText(action.getText());
   updateStatusButton.setEnabled(enabled);
   updateStatusButton.getParent().layout();
 }

示例#16
文件: UpdateStatusControl.java项目: aam/dartdev

 private void performAction(SelectionEvent e) {
   if (updateAction != null) {
     updateAction.runWithSelectionEvent(e);
   }
 }

展开阅读全文