コード例 #1
0
 public void testSmokeWithCompilerOutput() throws IOException {
   File tempDir = FileUtil.createTempDirectory("compilerTest", "compilerTest");
   try {
     File out = new File(tempDir, "out");
     File stdlib = ForTestCompileRuntime.runtimeJarForTests();
     File jdkAnnotations = ForTestPackJdkAnnotations.jdkAnnotationsForTests();
     ExitCode exitCode =
         new K2JVMCompiler()
             .exec(
                 System.out,
                 "-src",
                 JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kt",
                 "-output",
                 out.getAbsolutePath(),
                 "-noStdlib",
                 "-classpath",
                 stdlib.getAbsolutePath(),
                 "-noJdkAnnotations",
                 "-annotations",
                 jdkAnnotations.getAbsolutePath());
     Assert.assertEquals(ExitCode.OK, exitCode);
     assertEquals(1, out.listFiles().length);
     assertEquals(1, out.listFiles()[0].listFiles().length);
   } finally {
     FileUtil.delete(tempDir);
   }
 }
コード例 #2
0
  public void testHardLinks() throws Exception {
    if (!SystemInfo.isWindows && !SystemInfo.isUnix) {
      System.err.println(getName() + " skipped: " + SystemInfo.OS_NAME);
      return;
    }

    final boolean safeWrite = GeneralSettings.getInstance().isUseSafeWrite();
    final File dir = FileUtil.createTempDirectory("hardlinks.", ".dir", false);
    final SafeWriteRequestor requestor = new SafeWriteRequestor() {};
    try {
      GeneralSettings.getInstance().setUseSafeWrite(false);

      final File targetFile = new File(dir, "targetFile");
      assertTrue(targetFile.createNewFile());
      final File hardLinkFile =
          IoTestUtil.createHardLink(targetFile.getAbsolutePath(), "hardLinkFile");

      final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetFile);
      assertNotNull(file);
      file.setBinaryContent("hello".getBytes("UTF-8"), 0, 0, requestor);
      assertTrue(file.getLength() > 0);

      final VirtualFile check =
          LocalFileSystem.getInstance().refreshAndFindFileByIoFile(hardLinkFile);
      assertNotNull(check);
      assertEquals(file.getLength(), check.getLength());
      assertEquals("hello", VfsUtilCore.loadText(check));
    } finally {
      GeneralSettings.getInstance().setUseSafeWrite(safeWrite);
      FileUtil.delete(dir);
    }
  }
コード例 #3
0
  @Override
  protected void setUp() throws Exception {
    if (ourOutputRoot == null) {
      ourOutputRoot = FileUtil.createTempDirectory("ExecutionTestCase", null, true);
    }
    myModuleOutputDir = new File(ourOutputRoot, PathUtil.getFileName(getTestAppPath()));
    myChecker = initOutputChecker();
    EdtTestUtil.runInEdtAndWait(
        new ThrowableRunnable<Throwable>() {
          @Override
          public void run() throws Throwable {
            ExecutionTestCase.super.setUp();
          }
        });
    if (!myModuleOutputDir.exists()) {
      VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ourOutputRoot);
      assertNotNull(ourOutputRoot.getAbsolutePath(), vDir);
      vDir
          .getChildren(); // we need this to load children to VFS to fire VFileCreatedEvent for the
                          // output directory

      myCompilerTester =
          new CompilerTester(
              myProject, Arrays.asList(ModuleManager.getInstance(myProject).getModules()));
      List<CompilerMessage> messages = myCompilerTester.rebuild();
      for (CompilerMessage message : messages) {
        if (message.getCategory() == CompilerMessageCategory.ERROR) {
          FileUtil.delete(myModuleOutputDir);
          fail("Compilation failed: " + message);
        }
      }
    }
  }
コード例 #4
0
ファイル: KotlinTestUtils.java プロジェクト: yilab/kotlin
 @NotNull
 public static File tmpDir(String name) throws IOException {
   // we should use this form. otherwise directory will be deleted on each test
   File answer =
       FileUtil.createTempDirectory(new File(System.getProperty("java.io.tmpdir")), name, "");
   deleteOnShutdown(answer);
   return answer;
 }
コード例 #5
0
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   myModel = JpsElementFactory.getInstance().createModel();
   myProject = myModel.getProject();
   myDataStorageRoot = FileUtil.createTempDirectory("compile-server-" + getProjectName(), null);
   myLogger = new TestProjectBuilderLogger();
   myBuildParams = new HashMap<String, String>();
 }
コード例 #6
0
 private String getCompilerOutput(CompileContext context, String moduleOutputDir)
     throws IOException {
   final File dir =
       myForStubs ? FileUtil.createTempDirectory("groovyStubs", null) : new File(moduleOutputDir);
   if (myForStubs) {
     JavaBuilder.addTempSourcePathRoot(context, dir);
   }
   return FileUtil.toCanonicalPath(dir.getPath());
 }
コード例 #7
0
 @NotNull
 private static File createChild(@NotNull File base, int depth) throws IOException {
   File dir = base;
   if (depth < 0) {
     return dir;
   }
   for (int i = 0; i < depth; ++i) {
     dir = FileUtil.createTempDirectory(dir, "grdt", null);
   }
   return dir;
 }
コード例 #8
0
 private void moveToUndoStorage(final VirtualFile file) {
   if (myStorageForUndo == null) {
     try {
       myStorageForUndo = FileUtil.createTempDirectory("svnUndoStorage", "");
     } catch (IOException e) {
       LOG.error(e);
       return;
     }
   }
   final File tmpFile = FileUtil.findSequentNonexistentFile(myStorageForUndo, "tmp", "");
   myUndoStorageContents.add(0, new Pair<File, File>(new File(file.getPath()), tmpFile));
   new File(file.getPath()).renameTo(tmpFile);
 }
コード例 #9
0
 private VirtualFile getTempDir(Module module) throws IOException {
   VirtualFile tempDir = myModuleToTempDirMap.get(module);
   if (tempDir == null) {
     final String projectName = myProject.getName();
     final String moduleName = module.getName();
     File tempDirectory = FileUtil.createTempDirectory(projectName, moduleName);
     tempDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory);
     if (tempDir == null) {
       LOG.error("Cannot locate temp directory " + tempDirectory.getPath());
     }
     myModuleToTempDirMap.put(module, tempDir);
   }
   return tempDir;
 }
コード例 #10
0
    public File cloneToTemp(String gitUrl) throws ServerRuntimeException {
      File cloneDir;
      try {
        cloneDir = FileUtil.createTempDirectory("cloud", "clone");
      } catch (IOException e) {
        throw new ServerRuntimeException(e);
      }

      File cloneDirParent = cloneDir.getParentFile();
      String cloneDirName = cloneDir.getName();

      doClone(cloneDirParent, cloneDirName, gitUrl);
      return cloneDir;
    }
コード例 #11
0
  public void testRefreshSeesLatestDirectoryContents() throws Exception {
    File testDir = FileUtil.createTempDirectory("RefreshChildrenTest." + getName(), null);
    String content = "";
    FileUtil.writeToFile(new File(testDir, "Foo.java"), content);

    LocalFileSystem local = LocalFileSystem.getInstance();
    VirtualFile virtualDir = local.findFileByIoFile(testDir);
    assert virtualDir != null : testDir;
    virtualDir.getChildren();
    virtualDir.refresh(false, true);
    checkChildCount(virtualDir, 1);

    FileUtil.writeToFile(new File(testDir, "Bar.java"), content);
    virtualDir.refresh(false, true);
    checkChildCount(virtualDir, 2);
  }
コード例 #12
0
  protected void setUp() throws Exception {
    super.setUp();
    myTempDir = FileUtil.createTempDirectory("GitRepositoryReaderTest", null);

    File pluginRoot = new File(PluginPathManager.getPluginHomePath("git4idea"));
    File dataDir = new File(new File(pluginRoot, "testData"), "repo");

    FileUtil.copyDir(dataDir, myTempDir);
    myGitDir = new File(myTempDir, ".git");
    FileUtil.rename(new File(myTempDir, "dot_git"), myGitDir);
    assertTrue(myGitDir.exists());
    myRepositoryReader = new GitRepositoryReader(myGitDir);

    myLocalBranches = readBranches(true);
    myRemoteBranches = readBranches(false);
  }
コード例 #13
0
  public static VirtualFile createTestProjectStructure(
      String tempName,
      final Module module,
      final String rootPath,
      final Collection<File> filesToDelete,
      final boolean addProjectRoots)
      throws Exception {
    File dir = FileUtil.createTempDirectory(tempName, null);
    filesToDelete.add(dir);

    final VirtualFile vDir =
        LocalFileSystem.getInstance()
            .refreshAndFindFileByPath(dir.getCanonicalPath().replace(File.separatorChar, '/'));

    final Exception[] exception = {null};
    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              public void run() {
                if (rootPath != null) {
                  VirtualFile vDir1 =
                      LocalFileSystem.getInstance()
                          .findFileByPath(rootPath.replace(File.separatorChar, '/'));
                  if (vDir1 == null) {
                    exception[0] = new Exception(rootPath + " not found");
                    return;
                  }
                  try {
                    VfsUtil.copyDirectory(null, vDir1, vDir, null);
                  } catch (IOException e) {
                    exception[0] = e;
                    return;
                  }
                }

                if (addProjectRoots) {
                  addSourceContentToRoots(module, vDir);
                }
              }
            });
    if (exception[0] != null) throw exception[0];

    return vDir;
  }
コード例 #14
0
  public void testSmokeWithCompilerJar() throws IOException {
    File tempDir = FileUtil.createTempDirectory("compilerTest", "compilerTest");

    try {
      File stdlib = ForTestCompileRuntime.runtimeJarForTests();
      File jdkAnnotations = ForTestPackJdkAnnotations.jdkAnnotationsForTests();
      File resultJar = new File(tempDir, "result.jar");
      ExitCode rv =
          new K2JVMCompiler()
              .exec(
                  System.out,
                  "-module",
                  JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kts",
                  "-jar",
                  resultJar.getAbsolutePath(),
                  "-noStdlib",
                  "-classpath",
                  stdlib.getAbsolutePath(),
                  "-noJdkAnnotations",
                  "-annotations",
                  jdkAnnotations.getAbsolutePath());
      Assert.assertEquals("compilation completed with non-zero code", ExitCode.OK, rv);
      FileInputStream fileInputStream = new FileInputStream(resultJar);
      try {
        JarInputStream is = new JarInputStream(fileInputStream);
        try {
          final List<String> entries = listEntries(is);
          assertTrue(
              entries.contains(
                  "Smoke/"
                      + PackageClassUtils.getPackageClassName(new FqName("Smoke"))
                      + ".class"));
          assertEquals(1, entries.size());
        } finally {
          is.close();
        }
      } finally {
        fileInputStream.close();
      }
    } finally {
      FileUtil.delete(tempDir);
    }
  }
コード例 #15
0
  public void testBadFileName() throws Exception {
    if (!SystemInfo.isUnix) {
      System.err.println(getName() + " skipped: " + SystemInfo.OS_NAME);
      return;
    }

    final File dir = FileUtil.createTempDirectory("test.", ".dir");
    final File file = FileUtil.createTempFile(dir, "test\\", "\\txt", true);

    final VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir);
    assertNotNull(vDir);
    assertEquals(0, vDir.getChildren().length);

    ((VirtualFileSystemEntry) vDir).markDirtyRecursively();
    vDir.refresh(false, true);

    final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
    assertNull(vFile);
  }
コード例 #16
0
  protected void setUp() throws Exception {
    super.setUp();
    myTempDirectory = FileUtil.createTempDirectory(getTestName(true), "test");
    myFilesToDelete.add(getTestContentFile());
    final File testRoot = new File(getTestDataPath(), getTestPath());
    assertTrue(testRoot.getAbsolutePath(), testRoot.isDirectory());

    final File currentTestRoot = new File(testRoot, getTestDirectoryName());
    assertTrue(currentTestRoot.getAbsolutePath(), currentTestRoot.isDirectory());

    FileUtil.copyDir(currentTestRoot, new File(myTempDirectory, getTestDirectoryName()));

    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              public void run() {
                setupContentRoot();
              }
            });
  }
コード例 #17
0
  public static VirtualFile createTestProjectStructure(
      String tempName,
      Module module,
      String rootPath,
      Collection<File> filesToDelete,
      boolean addProjectRoots)
      throws IOException {
    File dir = FileUtil.createTempDirectory(tempName, null, false);
    filesToDelete.add(dir);

    VirtualFile vDir =
        LocalFileSystem.getInstance()
            .refreshAndFindFileByPath(dir.getCanonicalPath().replace(File.separatorChar, '/'));
    assert vDir != null && vDir.isDirectory() : dir;
    PlatformTestCase.synchronizeTempDirVfs(vDir);

    EdtTestUtil.runInEdtAndWait(
        () -> {
          AccessToken token = WriteAction.start();
          try {
            if (rootPath != null) {
              VirtualFile vDir1 =
                  LocalFileSystem.getInstance()
                      .findFileByPath(rootPath.replace(File.separatorChar, '/'));
              if (vDir1 == null) {
                throw new Exception(rootPath + " not found");
              }
              VfsUtil.copyDirectory(null, vDir1, vDir, null);
            }

            if (addProjectRoots) {
              addSourceContentToRoots(module, vDir);
            }
          } finally {
            token.finish();
          }
        });
    return vDir;
  }
コード例 #18
0
 @Nullable
 private File getOutputDirsToCompileTo(ModuleChunk chunk, final List<OutputDir> dirs)
     throws IOException {
   File fileToDelete = null;
   if (chunk.getModuleCount() == 1) { // optimization
     final Module module = chunk.getModules()[0];
     ApplicationManager.getApplication()
         .runReadAction(
             new Runnable() {
               public void run() {
                 final String sourcesOutputDir = getOutputDir(module);
                 if (shouldCompileTestsSeparately(module)) {
                   if (sourcesOutputDir != null) {
                     dirs.add(new OutputDir(sourcesOutputDir, ModuleChunk.SOURCES));
                   }
                   final String testsOutputDir = getTestsOutputDir(module);
                   if (testsOutputDir == null) {
                     LOG.error("Tests output dir is null for module \"" + module.getName() + "\"");
                   } else {
                     dirs.add(new OutputDir(testsOutputDir, ModuleChunk.TEST_SOURCES));
                   }
                 } else { // both sources and test sources go into the same output
                   if (sourcesOutputDir == null) {
                     LOG.error(
                         "Sources output dir is null for module \"" + module.getName() + "\"");
                   } else {
                     dirs.add(new OutputDir(sourcesOutputDir, ModuleChunk.ALL_SOURCES));
                   }
                 }
               }
             });
   } else { // chunk has several modules
     final File outputDir = FileUtil.createTempDirectory("compile", "output");
     fileToDelete = outputDir;
     dirs.add(new OutputDir(outputDir.getPath(), ModuleChunk.ALL_SOURCES));
   }
   return fileToDelete;
 }
コード例 #19
0
  public static VirtualFile createTestProjectStructure(
      String tempName,
      final Module module,
      final String rootPath,
      final Collection<File> filesToDelete,
      final boolean addProjectRoots)
      throws Exception {
    File dir = FileUtil.createTempDirectory(tempName, null, false);
    filesToDelete.add(dir);

    final VirtualFile vDir =
        LocalFileSystem.getInstance()
            .refreshAndFindFileByPath(dir.getCanonicalPath().replace(File.separatorChar, '/'));
    assert vDir != null && vDir.isDirectory() : dir;

    Project project = module != null ? module.getProject() : null;
    new WriteCommandAction.Simple(project) {
      @Override
      protected void run() throws Throwable {
        if (rootPath != null) {
          VirtualFile vDir1 =
              LocalFileSystem.getInstance()
                  .findFileByPath(rootPath.replace(File.separatorChar, '/'));
          if (vDir1 == null) {
            throw new Exception(rootPath + " not found");
          }
          VfsUtil.copyDirectory(null, vDir1, vDir, null);
        }

        if (addProjectRoots) {
          addSourceContentToRoots(module, vDir);
        }
      }
    }.execute().throwException();

    return vDir;
  }
コード例 #20
0
 private String getCompilerOutput(String moduleOutputDir) throws IOException {
   return FileUtil.toCanonicalPath(
       (myForStubs ? FileUtil.createTempDirectory("groovyStubs", null) : new File(moduleOutputDir))
           .getPath());
 }
コード例 #21
0
ファイル: KotlinTestUtils.java プロジェクト: yilab/kotlin
 @NotNull
 public static File tmpDirForTest(TestCase test) throws IOException {
   File answer = FileUtil.createTempDirectory(test.getClass().getSimpleName(), test.getName());
   deleteOnShutdown(answer);
   return answer;
 }
コード例 #22
0
 protected File doGetProjectDir() throws IOException {
   return FileUtil.createTempDirectory("prj", null);
 }
コード例 #23
0
  public Builder.ExitCode build(final CompileContext context, ModuleChunk chunk)
      throws ProjectBuildException {
    ExitCode exitCode = ExitCode.OK;
    final Map<File, Module> toCompile = new HashMap<File, Module>();
    try {
      context.processFilesToRecompile(
          chunk,
          new FileProcessor() {
            @Override
            public boolean apply(Module module, File file, String sourceRoot) throws Exception {
              final String path = file.getPath();
              if (isGroovyFile(path)) { // todo file type check
                toCompile.put(file, module);
              }
              return true;
            }
          });

      if (toCompile.isEmpty()) {
        return exitCode;
      }

      final Set<String> cp = new LinkedHashSet<String>();
      // groovy_rt.jar
      // IMPORTANT! must be the first in classpath
      cp.add(ClasspathBootstrap.getResourcePath(GroovyCompilerWrapper.class).getPath());

      for (File file :
          context
              .getProjectPaths()
              .getClasspathFiles(chunk, ClasspathKind.compile(context.isCompilingTests()), false)) {
        cp.add(FileUtil.toCanonicalPath(file.getPath()));
      }
      for (File file :
          context
              .getProjectPaths()
              .getClasspathFiles(chunk, ClasspathKind.runtime(context.isCompilingTests()), false)) {
        cp.add(FileUtil.toCanonicalPath(file.getPath()));
      }

      final File tempFile = FileUtil.createTempFile("ideaGroovyToCompile", ".txt", true);
      final Module representativeModule = chunk.getModules().iterator().next();
      File moduleOutputDir =
          context
              .getProjectPaths()
              .getModuleOutputDir(representativeModule, context.isCompilingTests());
      final File dir =
          myForStubs
              ? FileUtil.createTempDirectory(/*new File("/tmp/stubs/"), */ "groovyStubs", null)
              : moduleOutputDir;
      assert dir != null;

      final Set<String> toCompilePaths = new LinkedHashSet<String>();
      for (File file : toCompile.keySet()) {
        toCompilePaths.add(FileUtil.toSystemIndependentName(file.getPath()));
      }

      String moduleOutputPath = FileUtil.toCanonicalPath(moduleOutputDir.getPath());
      if (!moduleOutputPath.endsWith("/")) {
        moduleOutputPath += "/";
      }
      Map<String, String> class2Src =
          buildClassToSourceMap(chunk, context, toCompilePaths, moduleOutputPath);

      String encoding = "UTF-8"; // todo encoding
      List<String> patchers = Collections.emptyList(); // todo patchers
      GroovycOSProcessHandler.fillFileWithGroovycParameters(
          tempFile,
          FileUtil.toCanonicalPath(dir.getPath()),
          toCompilePaths,
          FileUtil.toSystemDependentName(moduleOutputPath),
          class2Src,
          encoding,
          patchers);

      if (myForStubs) {
        JavaBuilder.addTempSourcePathRoot(context, dir);
      }

      // todo CompilerUtil.addLocaleOptions()
      // todo different outputs in a chunk
      // todo module jdk path
      final List<String> cmd =
          ExternalProcessUtil.buildJavaCommandLine(
              SystemProperties.getJavaHome() + "/bin/java",
              "org.jetbrains.groovy.compiler.rt.GroovycRunner",
              Collections.<String>emptyList(),
              new ArrayList<String>(cp),
              Arrays.asList(
                  "-Xmx384m" /*, "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5858"*/),
              Arrays.<String>asList(myForStubs ? "stubs" : "groovyc", tempFile.getPath()));

      deleteCorrespondingOutputFiles(context, toCompile);

      List<GroovycOSProcessHandler.OutputItem> successfullyCompiled = Collections.emptyList();
      try {
        final Process process = Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()]));
        GroovycOSProcessHandler handler =
            new GroovycOSProcessHandler(process, null) {
              @Override
              protected void updateStatus(@Nullable String status) {
                context.processMessage(
                    new ProgressMessage(status == null ? GROOVY_COMPILER_IN_OPERATION : status));
              }
            };
        handler.startNotify();
        handler.waitFor();

        successfullyCompiled = handler.getSuccessfullyCompiled();

        final List<CompilerMessage> messages = handler.getCompilerMessages();
        for (CompilerMessage message : messages) {
          context.processMessage(message);
        }

        boolean hasMessages = !messages.isEmpty();

        final StringBuffer unparsedBuffer = handler.getStdErr();
        if (unparsedBuffer.length() != 0) {
          context.processMessage(
              new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.INFO, unparsedBuffer.toString()));
        }

        final int exitValue = handler.getProcess().exitValue();
        if (!hasMessages && exitValue != 0) {
          context.processMessage(
              new CompilerMessage(
                  BUILDER_NAME,
                  BuildMessage.Kind.ERROR,
                  "Internal groovyc error: code " + exitValue));
        }
      } finally {
        if (!myForStubs) {
          final Mappings delta = context.createDelta();
          final List<File> successfullyCompiledFiles = new ArrayList<File>();
          if (!successfullyCompiled.isEmpty()) {
            final Callbacks.Backend callback = delta.getCallback();

            for (GroovycOSProcessHandler.OutputItem item : successfullyCompiled) {
              final String sourcePath = FileUtil.toSystemIndependentName(item.sourcePath);
              final String outputPath = FileUtil.toSystemIndependentName(item.outputPath);
              final RootDescriptor moduleAndRoot = context.getModuleAndRoot(new File(sourcePath));
              if (moduleAndRoot != null) {
                final String moduleName = moduleAndRoot.module.getName().toLowerCase(Locale.US);
                context
                    .getDataManager()
                    .getSourceToOutputMap(moduleName, moduleAndRoot.isTestRoot)
                    .appendData(sourcePath, outputPath);
              }
              callback.associate(
                  outputPath,
                  Callbacks.getDefaultLookup(sourcePath),
                  new ClassReader(FileUtil.loadFileBytes(new File(outputPath))));
              successfullyCompiledFiles.add(new File(sourcePath));
            }
          }

          final boolean needSecondPass =
              updateMappings(context, delta, chunk, toCompile.keySet(), successfullyCompiledFiles);
          if (needSecondPass) {
            exitCode = ExitCode.ADDITIONAL_PASS_REQUIRED;
          }
        }
      }

      return exitCode;
    } catch (Exception e) {
      throw new ProjectBuildException(e);
    }
  }
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   myArtifactsOutput = FileUtil.createTempDirectory("artifactsOutput", null);
 }