Do some cleanup when a project is closed.

We can clean up the node tern server we use to calculate hints now, since
we know we will need to re-init it in any new project that is opened.
330572
function resetModule() {
            function resetTernServer() {
                if (_ternNodeDomain.ready()) {
                    _ternNodeDomain.exec('resetTernServer');
                }
            }
            
            if (_ternNodeDomain) {
                if (addFilesPromise) {
                    // If we're in the middle of added files, don't reset 
                    // until we're done
                    addFilesPromise.done(resetTernServer).fail(resetTernServer);
                } else {
                    resetTernServer();
                }
            }
        }
963472
private void cleanupProjectIfEmpty() {

        m_requiresCleanup = false;
        try {
            CmsObject cms = OpenCms.initCmsObject(m_adminCms);
            cms.readProject(getProject().getUuid());
        } catch (CmsException e) {
            return;
        }
        try {
            CmsObject cms = OpenCms.initCmsObject(m_adminCms);
            cms.getRequestContext().setCurrentProject(getProject());
            CmsUUID projectId = getProject().getUuid();
            List<CmsResource> projectResources = cms.readProjectView(projectId, CmsResource.STATE_KEEP);
            if (projectResources.isEmpty()) {
                cms.deleteProject(projectId);
            }
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
573477
def cleanup(self):
        
        now = time.time()
        expired = now - NODE_TIMEOUT
        if self.conn.zremrangebyscore(self.key, 0, expired):
            self._notify()
515381
private void cleanup() { // d623593
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();

        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "cleanup");

        synchronized (ivRemoteAsyncResultReaper) {
            if (ivAddedToReaper) { // d690014
                // d690014.3 - The call to remove will remove the result from the
                // reaper and then call unexportObject itself.
                this.ivRemoteAsyncResultReaper.remove(this);
            } else {
                unexportObject();
            }
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "cleanup");
    }
551004
public void dispose() {
        if (executionPlan != null) {
            executionPlan.dispose();
        }
        if (appClassList != null) {
            appClassList.clear();
        }
        if (classObserverList != null) {
            classObserverList.clear();
        }
        if (referencedClassSet != null) {
            referencedClassSet.clear();
        }
        analysisOptions.analysisFeatureSettingList = null;
        bugReporter = null;
        classFactory = null;
        IO.close(classPath);
        classPath = null;
        classScreener = null;
        detectorFactoryCollection = null;
        executionPlan = null;
        progressReporter = null;
        IO.close(project);
        project = null;
        analysisOptions.userPreferences = null;
    }
1087914
public void cleanupProjectArtifacts(final int projectId) {
    try {
      this.storageCleaner.cleanupProjectArtifacts(projectId);
    } catch (final Exception e) {
      log.error("Error occured during cleanup. Ignoring and continuing...", e);
    }
  }
291657
public void cleanup ()
    {
        // tell any pending object subscribers that they're not getting their bits
        for (PendingRequest<?> req : _penders.values()) {
            for (Subscriber<?> sub : req.targets) {
                sub.requestFailed(req.oid, new ObjectAccessException("Client connection closed"));
            }
        }
        _penders.clear();
        _flusher.cancel();
        _flushes.clear();
        _dead.clear();
        _client.getRunQueue().postRunnable(new Runnable() {
            public void run () {
                _ocache.clear();
            }
        });
    }
372571
public void cleanup() {
        if (lineSource != null) {
            try {
                lineSource.close();
            } catch (Exception e) {
                // Ignore
            }
        }

        lineSource = null;
        line = null;
        number = 0;
    }
1281118
void checkClosed() throws FetchException {
        TransactionScope<Txn> scope = localTransactionScope();

        // Lock out shutdown task.
        scope.getLock().lock();
        try {
            if (mPrimaryDatabase == null) {
                // If shutting down, this will force us to block forever.
                try {
                    scope.getTxn();
                } catch (Exception e) {
                    // Don't care.
                }
                // Okay, not shutting down, so throw exception.
                throw new FetchException("Repository closed");
            }
        } finally {
            scope.getLock().unlock();
        }
    }
695021
function onClearBackend(projectInfo){
    let backendProject = getBackendProjectObject(projectInfo)
    if(backendProject){
        backendProject.name = ''
        setBackendProjectObject(backendProject, projectInfo)
    }
}
449439
def _clean():
    
    LOGGER.info('Cleaning project directory...')
    folders_to_cleanup = [
        '.eggs',
        'build',
        f'{config.PACKAGE_NAME()}.egg-info',
    ]
    for folder in folders_to_cleanup:
        if os.path.exists(folder):
            LOGGER.info('\tremoving: %s', folder)
            shutil.rmtree(folder)
246435
synchronized void cleanUpOverMemoryTask(TaskAttemptID tid, boolean wasFailure,
      String diagnosticMsg) {
    TaskInProgress tip = runningTasks.get(tid);
    if (tip != null) {
      tip.reportDiagnosticInfo(diagnosticMsg);
      try {
        purgeTask(tip, wasFailure); // Marking it as failed/killed.
      } catch (IOException ioe) {
        LOG.warn("Couldn't purge the task of " + tid + ". Error : " + ioe);
      }
    }
  }
1126825
def project_closing(self, project):
        

        yield from super().project_closing(project)
        # delete the Dynamips devices corresponding to the project
        tasks = []
        for device in self._devices.values():
            if device.project.id == project.id:
                tasks.append(asyncio.async(device.delete()))

        if tasks:
            done, _ = yield from asyncio.wait(tasks)
            for future in done:
                try:
                    future.result()
                except (Exception, GeneratorExit) as e:
                    log.error("Could not delete device {}".format(e), exc_info=1)
359678
def project_closed(self, project):
        

        yield from super().project_closed(project)
        hdd_files_to_close = yield from self._find_inaccessible_hdd_files()
        for hdd_file in hdd_files_to_close:
            log.info("Closing VirtualBox VM disk file {}".format(os.path.basename(hdd_file)))
            try:
                yield from self.execute("closemedium", ["disk", hdd_file])
            except VirtualBoxError as e:
                log.warning("Could not close VirtualBox VM disk file {}: {}".format(os.path.basename(hdd_file), e))
                continue
186193
@Override
    public void close() throws Exception {
        try {
            this.servers.stream().filter(Objects::nonNull).forEach(BookieServer::shutdown);
            if (this.zkServer.get() != null) {
                this.zkServer.get().close();
            }
        } finally {
            cleanupDirectories();
        }

        Thread c = this.cleanup.getAndSet(null);
        if (c != null) {
            Runtime.getRuntime().removeShutdownHook(c);
        }
    }
420481
def cleanup(parent = Object, current = @top)
      return unless all_project_objects_lookup[current]
      current.constants.each {|const| cleanup current, current.const_get(const)}
      parent.send(:remove_const, current.to_s.split('::').last.to_sym)
    end
1346452
function (args, callback) {
        if (ternserver) {
          ternserver.request({
              query: {
                type: "definition",  //$NON-NLS-1$
                file: args.meta.location,
                end: args.params.offset,
                guess: args.guess
              },
              files: args.files
            },
            function (error, decl) {
              if (error) {
                callback({request: 'definition', error: error.message, message: Messages['failedToComputeDecl']}); //$NON-NLS-1$
              }
              if (decl && typeof decl.start === 'number' && typeof decl.end === "number") {
                callback({request: 'definition', declaration: decl}); //$NON-NLS-1$
              } else if (decl && decl.origin) {
                //tern guessed at it when there is no line infos
                var idx = decl.origin.lastIndexOf(".");
                if (idx > -1 && decl.origin.slice(idx) === ".js") {
                  decl.guess = true;
                } else {
                  delete decl.guess;  //sometimes Tern will set the guess flag, we only want the index flag
                  decl.index = true;
                }
                callback({request: 'definition', declaration: decl}); //$NON-NLS-1$
              } else {
                callback({request: 'definition', declaration: null}); //$NON-NLS-1$
              }
            });
        } else {
          callback({request: 'definition', message: Messages['failedToComputeDeclNoServer']}); //$NON-NLS-1$
        }
      }