public void testBeansReferenceCopy() {

    PrimitiveBean row1 = new PrimitiveBean();
    PrimitiveBean row2;

    TimeMeasure.begin("testBeansReferenceCopy"); // $NON-NLS-1$

    for (int i = 0; i < N_ITERATION; i++) {

      row2 = row1;
    }

    TimeMeasure.end("testBeansReferenceCopy"); // $NON-NLS-1$
    System.out.println();
  }
  public void testPrimitivePropertiesCopyWithStaticBeans() {

    TimeMeasure.begin("testPrimitivePropertiesCopyWithStaticBeans"); // $NON-NLS-1$

    for (int i = 0; i < N_ITERATION; i++) {

      StaticPrimitiveBeanOutput.intVar0 = StaticPrimitiveBeanInput.intVar0;
      StaticPrimitiveBeanOutput.intVar1 = StaticPrimitiveBeanInput.intVar1;
      StaticPrimitiveBeanOutput.intVar2 = StaticPrimitiveBeanInput.intVar2;
      StaticPrimitiveBeanOutput.intVar3 = StaticPrimitiveBeanInput.intVar3;
      StaticPrimitiveBeanOutput.intVar4 = StaticPrimitiveBeanInput.intVar4;
      StaticPrimitiveBeanOutput.intVar5 = StaticPrimitiveBeanInput.intVar5;
      StaticPrimitiveBeanOutput.intVar6 = StaticPrimitiveBeanInput.intVar6;
      StaticPrimitiveBeanOutput.intVar7 = StaticPrimitiveBeanInput.intVar7;
      StaticPrimitiveBeanOutput.intVar8 = StaticPrimitiveBeanInput.intVar8;
      StaticPrimitiveBeanOutput.intVar9 = StaticPrimitiveBeanInput.intVar9;
    }

    TimeMeasure.end("testPrimitivePropertiesCopyWithStaticBeans"); // $NON-NLS-1$
    System.out.println();
  }
  public void testPrimitiveIntPropertiesCopyWithInstanceBeansWithOperations() {

    beanInput = new PrimitiveBean();

    TimeMeasure.begin("testPrimitiveIntPropertiesCopyWithLocalBeansWithOperations"); // $NON-NLS-1$

    for (int i = 0; i < N_ITERATION; i++) {

      beanInput.intVar0 = beanInput.intVar0 + Integer.MIN_VALUE;
      beanInput.intVar1 = beanInput.intVar1 + Integer.MIN_VALUE;
      beanInput.intVar2 = beanInput.intVar2 + Integer.MIN_VALUE;
      beanInput.intVar3 = beanInput.intVar3 + Integer.MIN_VALUE;
      beanInput.intVar4 = beanInput.intVar4 + Integer.MIN_VALUE;
      beanInput.intVar5 = beanInput.intVar5 + Integer.MIN_VALUE;
      beanInput.intVar6 = beanInput.intVar6 + Integer.MIN_VALUE;
      beanInput.intVar7 = beanInput.intVar7 + Integer.MIN_VALUE;
      beanInput.intVar8 = beanInput.intVar8 + Integer.MIN_VALUE;
      beanInput.intVar9 = beanInput.intVar9 + Integer.MIN_VALUE;
    }

    TimeMeasure.end("testPrimitiveIntPropertiesCopyWithLocalBeansWithOperations"); // $NON-NLS-1$
    System.out.println();
  }
  public void testCopyFirstPrimitiveArrayValueInFirstPrimitiveArrayValue() {

    NullablePrimitiveBean beanInput = new NullablePrimitiveBean();
    NullablePrimitiveBean beanOutput = new NullablePrimitiveBean();

    TimeMeasure.begin("testCopyFirstPrimitiveArrayValueInFirstPrimitiveArrayValue"); // $NON-NLS-1$

    for (int i = 0; i < N_ITERATION; i++) {

      beanOutput.intVar0[0] = beanInput.intVar0[0];
      beanOutput.intVar1[0] = beanInput.intVar1[0];
      beanOutput.intVar2[0] = beanInput.intVar2[0];
      beanOutput.intVar3[0] = beanInput.intVar3[0];
      beanOutput.intVar4[0] = beanInput.intVar4[0];
      beanOutput.intVar5[0] = beanInput.intVar5[0];
      beanOutput.intVar6[0] = beanInput.intVar6[0];
      beanOutput.intVar7[0] = beanInput.intVar7[0];
      beanOutput.intVar8[0] = beanInput.intVar8[0];
      beanOutput.intVar9[0] = beanInput.intVar9[0];
    }

    TimeMeasure.end("testCopyFirstPrimitiveArrayValueInFirstPrimitiveArrayValue"); // $NON-NLS-1$
    System.out.println();
  }
  public void testPrimitiveIntArrayCopyWithLocalBeans() {

    int[] intArrayInput = new int[10];
    int[] intArrayOutput = new int[10];

    TimeMeasure.begin("testPrimitiveIntArrayCopyWithLocalBeans"); // $NON-NLS-1$

    for (int i = 0; i < N_ITERATION; i++) {

      intArrayOutput[0] = intArrayInput[0];
      intArrayOutput[1] = intArrayInput[1];
      intArrayOutput[2] = intArrayInput[2];
      intArrayOutput[3] = intArrayInput[3];
      intArrayOutput[4] = intArrayInput[4];
      intArrayOutput[5] = intArrayInput[5];
      intArrayOutput[6] = intArrayInput[6];
      intArrayOutput[7] = intArrayInput[7];
      intArrayOutput[8] = intArrayInput[8];
      intArrayOutput[9] = intArrayInput[9];
    }

    TimeMeasure.end("testPrimitiveIntArrayCopyWithLocalBeans"); // $NON-NLS-1$
    System.out.println();
  }
  public void testIntegerPropertiesCopyWithLocalBeans() {

    IntegerBean beanInput = new IntegerBean();
    IntegerBean beanOutput = new IntegerBean();

    TimeMeasure.begin("testIntegerPropertiesCopyWithLocalBeans"); // $NON-NLS-1$

    for (int i = 0; i < N_ITERATION; i++) {

      beanOutput.integerVar0 = beanInput.integerVar0;
      beanOutput.integerVar1 = beanInput.integerVar1;
      beanOutput.integerVar2 = beanInput.integerVar2;
      beanOutput.integerVar3 = beanInput.integerVar3;
      beanOutput.integerVar4 = beanInput.integerVar4;
      beanOutput.integerVar5 = beanInput.integerVar5;
      beanOutput.integerVar6 = beanInput.integerVar6;
      beanOutput.integerVar7 = beanInput.integerVar7;
      beanOutput.integerVar8 = beanInput.integerVar8;
      beanOutput.integerVar9 = beanInput.integerVar9;
    }

    TimeMeasure.end("testIntegerPropertiesCopyWithLocalBeans"); // $NON-NLS-1$
    System.out.println();
  }
Example #7
0
 /* right now main() can't log to file,if want to test log file,run application CommandLineTestApplication */
 public static void main(String[] args) {
   try {
     TimeMeasure.begin("a"); // $NON-NLS-1$
     // TimeMeasure.end("b");
     Thread.sleep(500);
     TimeMeasure.step("a", "1"); // $NON-NLS-1$ //$NON-NLS-2$
     Thread.sleep(800);
     TimeMeasure.pause("a"); // $NON-NLS-1$
     Thread.sleep(600);
     TimeMeasure.step("a", "2"); // $NON-NLS-1$ //$NON-NLS-2$
     TimeMeasure.resume("a"); // $NON-NLS-1$
     Thread.sleep(2000);
     TimeMeasure.end("a"); // $NON-NLS-1$
   } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Example #8
0
  public void importItemRecords(
      final IProgressMonitor progressMonitor,
      final ResourcesManager resManager,
      final List<ImportItem> checkedItemRecords,
      final boolean overwrite,
      final ImportItem[] allImportItemRecords,
      final IPath destinationPath)
      throws InvocationTargetException {
    TimeMeasure.display = CommonsPlugin.isDebugMode();
    TimeMeasure.displaySteps = CommonsPlugin.isDebugMode();
    TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
    TimeMeasure.begin("ImportingItems"); // $NON-NLS-1$

    /*
     * Re-order the import items according to the priority of extension point.
     */
    final List<IImportItemsHandler> importItemHandlersList =
        new ArrayList<IImportItemsHandler>(Arrays.asList(getImportHandlers()));
    Collections.sort(
        checkedItemRecords,
        new Comparator<ImportItem>() {

          @Override
          public int compare(ImportItem o1, ImportItem o2) {
            IImportItemsHandler importHandler1 = o1.getImportHandler();
            IImportItemsHandler importHandler2 = o2.getImportHandler();
            if (importHandler1 != null && importHandler2 != null) {
              int index1 = importItemHandlersList.indexOf(importHandler1);
              int index2 = importItemHandlersList.indexOf(importHandler2);
              if (index1 > -1 && index2 > -1) { // both found
                return index1 - index2;
              }
            }
            return 0;
          }
        });

    ImportCacheHelper importCacheHelper = ImportCacheHelper.getInstance();
    try {
      // cache
      importCacheHelper.beforeImportItems();

      if (resManager == null || checkedItemRecords.isEmpty()) {
        return;
      }
      progressMonitor.beginTask(
          Messages.getString("ImportExportHandlersManager_importingItemsMessage"),
          checkedItemRecords.size() * 2 + 1); // $NON-NLS-1$

      /*
       * FIXME ????? why need sort it?
       *
       * Maybe, Have done by priority for import handler, so no need.
       */
      // Collections.sort(itemRecords, new Comparator<ImportItem>() {
      //
      // @Override
      // public int compare(ImportItem o1, ImportItem o2) {
      // if (o1.getProperty().getItem() instanceof RoutineItem && o2.getProperty().getItem()
      // instanceof
      // RoutineItem) {
      // return 0;
      // } else if (!(o1.getProperty().getItem() instanceof RoutineItem)
      // && !(o2.getProperty().getItem() instanceof RoutineItem)) {
      // return 0;
      // } else if (o1.getProperty().getItem() instanceof RoutineItem) {
      // return -1;
      // } else {
      // return 1;
      // }
      // }
      // });

      //

      RepositoryWorkUnit repositoryWorkUnit =
          new RepositoryWorkUnit(
              Messages.getString(
                  "ImportExportHandlersManager_importingItemsMessage")) { //$NON-NLS-1$

            @Override
            public void run() throws PersistenceException {
              final IWorkspaceRunnable op =
                  new IWorkspaceRunnable() {

                    @Override
                    public void run(final IProgressMonitor monitor) throws CoreException {
                      // pre import
                      preImport(
                          monitor,
                          resManager,
                          checkedItemRecords.toArray(new ImportItem[0]),
                          allImportItemRecords);

                      // bug 10520
                      final Set<String> overwriteDeletedItems = new HashSet<String>();
                      final Set<String> idDeletedBeforeImport = new HashSet<String>();

                      Map<String, String> nameToIdMap = new HashMap<String, String>();

                      for (ImportItem itemRecord : checkedItemRecords) {
                        if (monitor.isCanceled()) {
                          return;
                        }
                        if (itemRecord.isValid()) {
                          if (itemRecord.getState() == State.ID_EXISTED) {
                            String id =
                                nameToIdMap.get(
                                    itemRecord.getProperty().getLabel()
                                        + ERepositoryObjectType.getItemType(
                                                itemRecord.getProperty().getItem())
                                            .toString());
                            if (id == null) {
                              /*
                               * if id exsist then need to genrate new id for this job,in this case the
                               * job won't override the old one
                               */
                              id = EcoreUtil.generateUUID();
                              nameToIdMap.put(
                                  itemRecord.getProperty().getLabel()
                                      + ERepositoryObjectType.getItemType(
                                              itemRecord.getProperty().getItem())
                                          .toString(),
                                  id);
                            }
                            itemRecord.getProperty().setId(id);
                          }
                        }
                      }

                      try {
                        importItemRecordsWithRelations(
                            monitor,
                            resManager,
                            checkedItemRecords,
                            overwrite,
                            allImportItemRecords,
                            destinationPath,
                            overwriteDeletedItems,
                            idDeletedBeforeImport);
                      } catch (Exception e) {
                        if (Platform.inDebugMode()) {
                          ExceptionHandler.process(e);
                        }
                        throw new CoreException(
                            new Status(
                                IStatus.ERROR,
                                FrameworkUtil.getBundle(this.getClass()).getSymbolicName(),
                                Messages.getString(
                                    "ImportExportHandlersManager_importingItemsError"),
                                e)); //$NON-NLS-1$
                      }

                      if (PluginChecker.isJobLetPluginLoaded()) {
                        IJobletProviderService service =
                            (IJobletProviderService)
                                GlobalServiceRegister.getDefault()
                                    .getService(IJobletProviderService.class);
                        if (service != null) {
                          service.loadComponentsFromProviders();
                        }
                      }
                      ImportCacheHelper.getInstance().checkDeletedFolders();
                      monitor.done();

                      TimeMeasure.step(
                          "importItemRecords", "before save"); // $NON-NLS-1$ //$NON-NLS-2$

                      if (RelationshipItemBuilder.getInstance().isNeedSaveRelations()) {
                        RelationshipItemBuilder.getInstance().saveRelations();

                        TimeMeasure.step(
                            "importItemRecords", "save relations"); // $NON-NLS-1$ //$NON-NLS-2$
                      } else {
                        // only save the project here if no relation need to be saved, since project
                        // will
                        // already be
                        // saved
                        // with relations
                        try {
                          final IProxyRepositoryFactory factory =
                              CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
                          factory.saveProject(ProjectManager.getInstance().getCurrentProject());
                        } catch (PersistenceException e) {
                          if (Platform.inDebugMode()) {
                            ExceptionHandler.process(e);
                          }
                          throw new CoreException(
                              new Status(
                                  IStatus.ERROR,
                                  FrameworkUtil.getBundle(this.getClass()).getSymbolicName(),
                                  Messages.getString(
                                      "ImportExportHandlersManager_importingItemsError"),
                                  e)); //$NON-NLS-1$
                        }
                        TimeMeasure.step(
                            "importItemRecords", "save project"); // $NON-NLS-1$//$NON-NLS-2$
                      }

                      // post import
                      List<ImportItem> importedItemRecords =
                          ImportCacheHelper.getInstance().getImportedItemRecords();
                      postImport(
                          monitor, resManager, importedItemRecords.toArray(new ImportItem[0]));
                    }

                    private void importItemRecordsWithRelations(
                        final IProgressMonitor monitor,
                        final ResourcesManager manager,
                        final List<ImportItem> processingItemRecords,
                        final boolean overwriting,
                        ImportItem[] allPopulatedImportItemRecords,
                        IPath destinationPath,
                        final Set<String> overwriteDeletedItems,
                        final Set<String> idDeletedBeforeImport)
                        throws Exception {
                      for (ImportItem itemRecord : processingItemRecords) {
                        if (monitor.isCanceled()) {
                          return;
                        }
                        if (itemRecord.isImported()) {
                          continue; // have imported
                        }
                        try {
                          final IImportItemsHandler importHandler = itemRecord.getImportHandler();
                          if (importHandler != null && itemRecord.isValid()) {
                            List<ImportItem> relatedItemRecord =
                                importHandler.findRelatedImportItems(
                                    monitor, manager, itemRecord, allPopulatedImportItemRecords);
                            // import related items first
                            if (importHandler.isPriorImportRelatedItem()) {
                              if (!relatedItemRecord.isEmpty()) {
                                importItemRecordsWithRelations(
                                    monitor,
                                    manager,
                                    relatedItemRecord,
                                    overwriting,
                                    allPopulatedImportItemRecords,
                                    destinationPath,
                                    overwriteDeletedItems,
                                    idDeletedBeforeImport);
                              }
                            }
                            if (monitor.isCanceled()) {
                              return;
                            }

                            // will import
                            importHandler.doImport(
                                monitor,
                                manager,
                                itemRecord,
                                overwriting,
                                destinationPath,
                                overwriteDeletedItems,
                                idDeletedBeforeImport);

                            if (monitor.isCanceled()) {
                              return;
                            }
                            // if import related items behind current item
                            if (!importHandler.isPriorImportRelatedItem()) {
                              if (!relatedItemRecord.isEmpty()) {
                                importItemRecordsWithRelations(
                                    monitor,
                                    manager,
                                    relatedItemRecord,
                                    overwriting,
                                    allPopulatedImportItemRecords,
                                    destinationPath,
                                    overwriteDeletedItems,
                                    idDeletedBeforeImport);
                              }
                            }

                            importHandler.afterImportingItems(monitor, manager, itemRecord);

                            // record the imported items with related items too.
                            ImportCacheHelper.getInstance()
                                .getImportedItemRecords()
                                .add(itemRecord);

                            monitor.worked(1);
                          }
                        } catch (Exception e) {
                          // ???, PTODO if there one error, need throw error or not.
                          if (Platform.inDebugMode()) {
                            // FIXME, catch the exception, and don't block others to import
                            itemRecord.addError(e.getMessage());
                            // same the the ImportBasicHandler.logError
                            ImportCacheHelper.getInstance().setImportingError(true);
                            ExceptionHandler.process(e);
                          }
                        }
                      }
                    }
                  };
              IWorkspace workspace = ResourcesPlugin.getWorkspace();
              try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                // the update the project files need to be done in the workspace runnable to avoid
                // all
                // notification
                // of changes before the end of the modifications.
                workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, progressMonitor);
              } catch (CoreException e) {
                if (Platform.inDebugMode()) {
                  ExceptionHandler.process(e);
                }
              }
            }
          };
      repositoryWorkUnit.setAvoidUnloadResources(true);
      repositoryWorkUnit.setUnloadResourcesAfterRun(true);
      ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);

      progressMonitor.done();

      if (ImportCacheHelper.getInstance().hasImportingError()) {
        throw new InvocationTargetException(
            new CoreException(
                new Status(
                    IStatus.ERROR,
                    FrameworkUtil.getBundle(this.getClass()).getSymbolicName(),
                    Messages.getString(
                        "ImportExportHandlersManager_importingItemsError")))); //$NON-NLS-1$
      }
    } finally {
      // cache
      importCacheHelper.afterImportItems();
      //
      TimeMeasure.end("ImportingItems"); // $NON-NLS-1$
      TimeMeasure.display = false;
      TimeMeasure.displaySteps = false;
      TimeMeasure.measureActive = false;
    }
  }
Example #9
0
  public List<ImportItem> populateImportingItems(
      ResourcesManager resManager,
      boolean overwrite,
      IProgressMonitor progressMonitor,
      boolean enableProductChecking)
      throws Exception {
    IProgressMonitor monitor = progressMonitor;
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    TimeMeasure.display = CommonsPlugin.isDebugMode();
    TimeMeasure.displaySteps = CommonsPlugin.isDebugMode();
    TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
    TimeMeasure.begin("populateItems"); // $NON-NLS-1$

    try {
      // pre populate
      prePopulate(monitor, resManager);

      ImportCacheHelper.getInstance().beforePopulateItems();

      if (resManager == null) {
        return Collections.emptyList();
      }

      Set<IPath> resPaths = resManager.getPaths();

      monitor.beginTask(
          Messages.getString("ImportExportHandlersManager_populatingItemsMessage"),
          resPaths.size()); // $NON-NLS-1$

      List<ImportItem> items = new ArrayList<ImportItem>();

      ImportHandlerHelper importHandlerHelper = new ImportHandlerHelper();
      for (IPath path : resPaths) {
        if (monitor.isCanceled()) {
          return Collections.emptyList(); //
        }
        ImportItem importItem =
            importHandlerHelper.computeImportItem(monitor, resManager, path, overwrite);
        if (importItem != null) {
          IImportItemsHandler importHandler =
              findValidImportHandler(importItem, enableProductChecking);
          if (importHandler != null) {
            if (importHandler instanceof ImportBasicHandler) {
              // save as the createImportItem of ImportBasicHandler
              ImportBasicHandler importBasicHandler = (ImportBasicHandler) importHandler;
              if (importBasicHandler.checkItem(resManager, importItem, overwrite)) {
                importBasicHandler.checkAndSetProject(resManager, importItem);
              }
            }
          } else {
            // if don't find valid handler, will try to check by noraml path of items, so set null
            // here.
            importItem = null;
          }
        }

        // if can't load rightly via *.properties, try to check another way for normal files.
        if (importItem == null) {
          IImportItemsHandler importHandler =
              findValidImportHandler(resManager, path, enableProductChecking);
          if (importHandler != null) {
            importItem =
                importHandler.createImportItem(progressMonitor, resManager, path, overwrite, items);
          }
        }

        if (importItem != null) {
          items.add(importItem);
        }
        monitor.worked(1);
      }

      // post populate
      postPopulate(monitor, resManager, items.toArray(new ImportItem[0]));

      return items;
    } finally {

      ImportCacheHelper.getInstance().afterPopulateItems();
      //
      TimeMeasure.end("populateItems"); // $NON-NLS-1$
      TimeMeasure.display = false;
      TimeMeasure.displaySteps = false;
      TimeMeasure.measureActive = false;
    }
  }