protected void addConnectorImplementation(
     ConnectorImplementation impl, List<IResource> resourcesToExport, boolean includeSources)
     throws FileNotFoundException, CoreException {
   final IRepositoryStore store = getImplementationStore();
   String fileName = NamingUtils.getEResourceFileName(impl, true);
   final EMFFileStore fileStore = (EMFFileStore) store.getChild(fileName);
   if (!fileStore.canBeShared()) {
     File f = new File(fileStore.getEMFResource().getURI().toFileString());
     if (f.exists()) {
       IFile implFile = store.getResource().getFile(f.getName());
       implFile.create(new FileInputStream(f), true, Repository.NULL_PROGRESS_MONITOR);
       resourcesToExport.add(implFile);
       cleanAfterExport.add(implFile);
     }
   } else {
     implBackup = EcoreUtil.copy(impl);
     String jarName =
         NamingUtils.toConnectorImplementationFilename(
                 impl.getImplementationId(), impl.getImplementationVersion(), false)
             + ".jar";
     if (!impl.getJarDependencies().getJarDependency().contains(jarName)) {
       impl.getJarDependencies().getJarDependency().add(jarName);
     }
     impl.setHasSources(includeSources);
     IRepositoryFileStore file = store.getChild(fileName);
     file.save(EcoreUtil.copy(impl));
     resourcesToExport.add(file.getResource());
   }
 }
  protected void addConnectorDefinition(
      ConnectorImplementation impl, List<IResource> resourcesToExport)
      throws FileNotFoundException, CoreException {
    final IRepositoryStore store = getDefinitionStore();
    ConnectorDefinition def =
        ((IDefinitionRepositoryStore) store)
            .getDefinition(impl.getDefinitionId(), impl.getDefinitionVersion());
    EMFFileStore file =
        (EMFFileStore) store.getChild(URI.decode(def.eResource().getURI().lastSegment()));

    if (file != null && !file.canBeShared()) {
      File f = new File(file.getEMFResource().getURI().toFileString());
      if (f.exists()) {
        IFile defFile = store.getResource().getFile(f.getName());
        defFile.create(new FileInputStream(f), true, Repository.NULL_PROGRESS_MONITOR);
        resourcesToExport.add(defFile);
        cleanAfterExport.add(defFile);
      }
    } else if (file != null) {
      resourcesToExport.add(file.getResource());
    }

    addDefinitionIcons(resourcesToExport, store, def);
    addDefinitionPropertiesFile(resourcesToExport, store, def);
  }
  public IStatus run(IProgressMonitor progressMonitor) {
    progressMonitor.beginTask(Messages.exporting, IProgressMonitor.UNKNOWN);
    IStatus status = Status.OK_STATUS;
    try {
      ignoredLibs.add(
          NamingUtils.toConnectorImplementationFilename(
                  impl.getImplementationId(), impl.getImplementationVersion(), false)
              + ".jar");
      cleanAfterExport = new ArrayList<IResource>();
      final SourceRepositoryStore sourceStore = getSourceStore();
      final IRepositoryStore implStore = getImplementationStore();

      List<IResource> resourcesToExport = new ArrayList<IResource>();
      IFolder classpathFolder = implStore.getResource().getFolder(CLASSPATH_DIR);
      if (classpathFolder.exists()) {
        classpathFolder.delete(true, Repository.NULL_PROGRESS_MONITOR);
      }

      classpathFolder.create(true, true, Repository.NULL_PROGRESS_MONITOR);
      resourcesToExport.add(classpathFolder);
      cleanAfterExport.add(classpathFolder);

      status =
          addImplementationJar(impl, classpathFolder, sourceStore, implStore, resourcesToExport);
      if (status.getSeverity() != IStatus.OK) {
        return status;
      }
      addArchiveDescriptor(sourceStore, resourcesToExport);

      if (addDependencies) {
        status = addDependencies(impl, classpathFolder);
        if (status.getSeverity() != IStatus.OK) {
          return status;
        }
      }

      addConnectorImplementation(impl, resourcesToExport, includeSources);
      addConnectorDefinition(impl, resourcesToExport);

      final ArchiveFileExportOperation operation =
          new ArchiveFileExportOperation(null, resourcesToExport, destPath);
      operation.setUseCompression(true);
      operation.setUseTarFormat(false);
      operation.setCreateLeadupStructure(false);
      operation.run(progressMonitor);
      if (!operation.getStatus().isOK()) {
        return operation.getStatus();
      }
    } catch (CoreException e) {
      BonitaStudioLog.error(e);
      return ValidationStatus.error(e.getMessage(), e);
    } catch (InvocationTargetException e) {
      BonitaStudioLog.error(e);
      return ValidationStatus.error(e.getMessage(), e);
    } catch (InterruptedException e) {
      BonitaStudioLog.error(e);
      return ValidationStatus.error(e.getMessage(), e);
    } catch (FileNotFoundException e) {
      BonitaStudioLog.error(e);
      return ValidationStatus.error(e.getMessage(), e);
    } finally {
      if (implBackup != null) {
        final IRepositoryStore store = getImplementationStore();
        String fileName = NamingUtils.getEResourceFileName(implBackup, true);
        if (fileName == null) {
          fileName =
              NamingUtils.toConnectorImplementationFilename(
                  implBackup.getImplementationId(), implBackup.getImplementationVersion(), true);
        }
        IRepositoryFileStore implFile = store.getChild(fileName);
        if (implFile != null) {
          implFile.save(implBackup);
        } else {
          return ValidationStatus.error(fileName + " not found in repository");
        }
      }

      for (IResource r : cleanAfterExport) {
        if (r.exists()) {
          try {
            r.delete(true, Repository.NULL_PROGRESS_MONITOR);
          } catch (CoreException e) {
            BonitaStudioLog.error(e);
          }
        }
      }
    }

    return status;
  }