<commit_before>package org.jetbrains.jps.builders;

import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.util.Function;
import junit.framework.Assert;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.JpsPathUtil;
import org.jetbrains.jps.Project;
import org.jetbrains.jps.api.CanceledStatus;
import org.jetbrains.jps.cmdline.ClasspathBootstrap;
import org.jetbrains.jps.cmdline.ProjectDescriptor;
import org.jetbrains.jps.idea.IdeaProjectLoader;
import org.jetbrains.jps.incremental.*;
import org.jetbrains.jps.incremental.fs.BuildFSState;
import org.jetbrains.jps.incremental.messages.BuildMessage;
import org.jetbrains.jps.incremental.storage.BuildDataManager;
import org.jetbrains.jps.incremental.storage.ProjectTimestamps;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.JpsModel;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.java.JpsJavaSdkType;
import org.jetbrains.jps.model.library.JpsOrderRootType;
import org.jetbrains.jps.model.library.JpsSdkProperties;
import org.jetbrains.jps.model.library.JpsTypedLibrary;
import org.jetbrains.jps.model.serialization.JpsProjectLoader;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author nik
 */
public abstract class JpsBuildTestCase extends UsefulTestCase {
  protected JpsProject myJpsProject;
  protected JpsModel myModel;
  protected Project myProject;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    myProject = new Project();
    myProject.setProjectName(getProjectName());
    myModel = JpsElementFactory.getInstance().createModel();
    myJpsProject = myModel.getProject();
    Utils.setSystemRoot(FileUtil.createTempDirectory("compile-server", null));
  }

  protected JpsTypedLibrary<JpsSdkProperties> initJdk(final String name) {
    try {
      return initJdk(name, FileUtil.toSystemIndependentName(ClasspathBootstrap.getResourcePath(Object.class).getCanonicalPath()));
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  protected JpsTypedLibrary<JpsSdkProperties> initJdk(final String name, final String path) {
    JpsSdkProperties properties = new JpsSdkProperties(System.getProperty("java.home"), "1.6");
    JpsTypedLibrary<JpsSdkProperties> jdk = myModel.getGlobal().getLibraryCollection().addLibrary(name, JpsJavaSdkType.INSTANCE,
                                                                                                  properties);
    jdk.addRoot(JpsPathUtil.pathToUrl(path), JpsOrderRootType.COMPILED);
    return jdk;
  }

  protected String getProjectName() {
    return StringUtil.decapitalize(StringUtil.trimStart(getName(), "test"));
  }

  protected ProjectDescriptor createProjectDescriptor(final BuildLoggingManager buildLoggingManager) {
    try {
      final File dataStorageRoot = Utils.getDataStorageRoot(myProject);
      ProjectTimestamps timestamps = new ProjectTimestamps(dataStorageRoot);<commit_msg>Fix JPS builder test for JDK 7<commit_after>package org.jetbrains.jps.builders;

import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.util.Function;
import junit.framework.Assert;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.JpsPathUtil;
import org.jetbrains.jps.Project;
import org.jetbrains.jps.api.CanceledStatus;
import org.jetbrains.jps.cmdline.ClasspathBootstrap;
import org.jetbrains.jps.cmdline.ProjectDescriptor;
import org.jetbrains.jps.idea.IdeaProjectLoader;
import org.jetbrains.jps.incremental.*;
import org.jetbrains.jps.incremental.fs.BuildFSState;
import org.jetbrains.jps.incremental.messages.BuildMessage;
import org.jetbrains.jps.incremental.storage.BuildDataManager;
import org.jetbrains.jps.incremental.storage.ProjectTimestamps;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.JpsModel;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.java.JpsJavaSdkType;
import org.jetbrains.jps.model.library.JpsOrderRootType;
import org.jetbrains.jps.model.library.JpsSdkProperties;
import org.jetbrains.jps.model.library.JpsTypedLibrary;
import org.jetbrains.jps.model.serialization.JpsProjectLoader;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author nik
 */
public abstract class JpsBuildTestCase extends UsefulTestCase {
  protected JpsProject myJpsProject;
  protected JpsModel myModel;
  protected Project myProject;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    myProject = new Project();
    myProject.setProjectName(getProjectName());
    myModel = JpsElementFactory.getInstance().createModel();
    myJpsProject = myModel.getProject();
    Utils.setSystemRoot(FileUtil.createTempDirectory("compile-server", null));
  }

  protected JpsTypedLibrary<JpsSdkProperties> initJdk(final String name) {
    try {
      return initJdk(name, FileUtil.toSystemIndependentName(ClasspathBootstrap.getResourcePath(Object.class).getCanonicalPath()));
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  protected JpsTypedLibrary<JpsSdkProperties> initJdk(final String name, final String path) {
    JpsSdkProperties properties = new JpsSdkProperties(System.getProperty("java.home"), System.getProperty("java.version"));
    JpsTypedLibrary<JpsSdkProperties> jdk = myModel.getGlobal().getLibraryCollection().addLibrary(name, JpsJavaSdkType.INSTANCE,
                                                                                                  properties);
    jdk.addRoot(JpsPathUtil.pathToUrl(path), JpsOrderRootType.COMPILED);
    return jdk;
  }

  protected String getProjectName() {
    return StringUtil.decapitalize(StringUtil.trimStart(getName(), "test"));
  }

  protected ProjectDescriptor createProjectDescriptor(final BuildLoggingManager buildLoggingManager) {
    try {
      final File dataStorageRoot = Utils.getDataStorageRoot(myProject);
      ProjectTimestamps timestamps = new ProjectTimestamps(dataStorageRoot);
{'fraction_non_alphanumeric': 0.0987171464330413, 'fraction_numerical': 0.00046933667083854817, 'mean_word_length': 4.8012704174228675, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6348014', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1930, 'n_words': 315}