<commit_before>package org.jetbrains.jps.incremental.artifacts;

import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.jps.Project;
import org.jetbrains.jps.artifacts.Artifact;
import org.jetbrains.jps.incremental.ModuleRootsIndex;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author nik
 */
public class ArtifactsBuildData {
  private Map<Artifact, ArtifactSourceFilesState> myArtifactState;
  private final ArtifactSourceTimestampStorage myTimestampStorage;
  private ArtifactCompilerPersistentData myPersistentData;
  private final File myArtifactsDataDir;
  private final File myMappingsDir;

  public ArtifactsBuildData(File artifactsDataDir) throws IOException {
    myArtifactsDataDir = artifactsDataDir;
    myTimestampStorage = new ArtifactSourceTimestampStorage(new File(artifactsDataDir, "timestamps"));
    myArtifactState = new HashMap<Artifact, ArtifactSourceFilesState>();
    myPersistentData = new ArtifactCompilerPersistentData(artifactsDataDir);
    myMappingsDir = new File(myArtifactsDataDir, "mappings");
  }

  public ArtifactSourceFilesState getOrCreateState(Artifact artifact, Project project, ModuleRootsIndex index) {
    ArtifactSourceFilesState state = myArtifactState.get(artifact);
    if (state == null) {
      final int artifactId = myPersistentData.getId(artifact.getName());
      state = new ArtifactSourceFilesState(artifact, artifactId, project, index, myTimestampStorage, myMappingsDir);
      myArtifactState.put(artifact, state);
    }
    return state;
  }

  public void clean() {
    myTimestampStorage.wipe();
    myPersistentData.clean();
    for (ArtifactSourceFilesState state : myArtifactState.values()) {
      state.clean();
    }
    myArtifactState.clear();
    FileUtil.delete(myMappingsDir);
  }

  public void close() throws IOException {
    myTimestampStorage.close();
    for (ArtifactSourceFilesState state : myArtifactState.values()) {
      state.close();
    }
  }

  public void flush(boolean memoryCachesOnly) {
    myTimestampStorage.flush(memoryCachesOnly);
    for (ArtifactSourceFilesState state : myArtifactState.values()) {
      state.flush(memoryCachesOnly);
    }
  }
}<commit_msg>compile server: fixed cleaning artifacts caches<commit_after>package org.jetbrains.jps.incremental.artifacts;

import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.jps.Project;
import org.jetbrains.jps.artifacts.Artifact;
import org.jetbrains.jps.incremental.ModuleRootsIndex;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author nik
 */
public class ArtifactsBuildData {
  private Map<Artifact, ArtifactSourceFilesState> myArtifactState;
  private final ArtifactSourceTimestampStorage myTimestampStorage;
  private ArtifactCompilerPersistentData myPersistentData;
  private final File myArtifactsDataDir;
  private final File myMappingsDir;

  public ArtifactsBuildData(File artifactsDataDir) throws IOException {
    myArtifactsDataDir = artifactsDataDir;
    myTimestampStorage = new ArtifactSourceTimestampStorage(new File(artifactsDataDir, "timestamps"));
    myArtifactState = new HashMap<Artifact, ArtifactSourceFilesState>();
    myPersistentData = new ArtifactCompilerPersistentData(artifactsDataDir);
    myMappingsDir = new File(myArtifactsDataDir, "mappings");
  }

  public ArtifactSourceFilesState getOrCreateState(Artifact artifact, Project project, ModuleRootsIndex index) {
    ArtifactSourceFilesState state = myArtifactState.get(artifact);
    if (state == null) {
      final int artifactId = myPersistentData.getId(artifact.getName());
      state = new ArtifactSourceFilesState(artifact, artifactId, project, index, myTimestampStorage, myMappingsDir);
      myArtifactState.put(artifact, state);
    }
    return state;
  }

  public void clean() throws IOException {
    myTimestampStorage.wipe();
    myPersistentData.clean();
    IOException exc = null;
    for (ArtifactSourceFilesState state : myArtifactState.values()) {
      try {
        state.close();
      }
      catch (IOException e) {
        if (exc == null) {
          exc = e;
        }
      }
    }
    myArtifactState.clear();
    FileUtil.delete(myMappingsDir);
    if (exc != null) {
      throw exc;
    }
  }

  public void close() throws IOException {
    myTimestampStorage.close();
    for (ArtifactSourceFilesState state : myArtifactState.values()) {
      state.close();
    }
  }

  public void flush(boolean memoryCachesOnly) {
    myTimestampStorage.flush(memoryCachesOnly);
    for (ArtifactSourceFilesState state : myArtifactState.values()) {
      state.flush(memoryCachesOnly);
    }
  }
}
{'fraction_non_alphanumeric': 0.09096705632306057, 'fraction_numerical': 0.0, 'mean_word_length': 4.58244365361803, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7491475', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1346, 'n_words': 280}