예제 #1
0
  @NotNull
  @Override
  public Collection<TestMethodModel> getTestMethods() {
    if (testMethods == null) {
      final List<TestMethodModel> result = Lists.newArrayList();

      result.add(new TestAllFilesPresentMethodModel());

      FileUtil.processFilesRecursively(
          rootFile,
          new Processor<File>() {
            @Override
            public boolean process(File file) {
              if (!file.isDirectory() && filenamePattern.matcher(file.getName()).matches()) {
                result.addAll(getTestMethodsFromFile(file));
              }

              return true;
            }
          });

      ContainerUtil.sort(
          result,
          new Comparator<TestMethodModel>() {
            @Override
            public int compare(@NotNull TestMethodModel o1, @NotNull TestMethodModel o2) {
              return StringUtil.compare(o1.getName(), o2.getName(), true);
            }
          });

      testMethods = result;
    }

    return testMethods;
  }
 private void copyUnversionedMembersOfDirectory(final File src, final File dst)
     throws SVNException {
   if (src.isDirectory()) {
     final SVNException[] exc = new SVNException[1];
     FileUtil.processFilesRecursively(
         src,
         new Processor<File>() {
           @Override
           public boolean process(File file) {
             String relativePath = FileUtil.getRelativePath(src, file);
             File newFile = new File(dst, relativePath);
             if (!newFile.exists()) {
               try {
                 copyFileOrDir(src, dst);
               } catch (IOException e) {
                 exc[0] = new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e), e);
                 return false;
               }
             }
             return true;
           }
         });
     if (exc[0] != null) {
       throw exc[0];
     }
   }
 }
예제 #3
0
 private static boolean dirHasFilesInside(@NotNull File dir) {
   return !FileUtil.processFilesRecursively(
       dir,
       new Processor<File>() {
         @Override
         public boolean process(File file) {
           return file.isDirectory();
         }
       });
 }
  private Collection<GitTestBranch> readBranches(boolean local) throws IOException {
    final Collection<GitTestBranch> branches = new ArrayList<GitTestBranch>();
    final File refsHeads = new File(new File(myGitDir, "refs"), local ? "heads" : "remotes");
    FileUtil.processFilesRecursively(
        refsHeads,
        new Processor<File>() {
          @Override
          public boolean process(File file) {
            if (file.equals(refsHeads)) { // don't process the root
              return true;
            }
            if (file.isDirectory()) { // don't process dirs
              return true;
            }
            String relativePath = FileUtil.getRelativePath(refsHeads, file);
            if (relativePath == null) {
              return true;
            }
            String name = FileUtil.toSystemIndependentName(relativePath);
            GitTestBranch branch = null;
            try {
              branch = new GitTestBranch(name, FileUtil.loadFile(file));
            } catch (IOException e) {
              fail(e.toString());
              e.printStackTrace();
            }
            if (!branches.contains(branch)) {
              branches.add(branch);
            }
            return true;
          }
        });

    // read from packed-refs, these have less priority, so the won't overwrite hashes from branch
    // files
    String packedRefs = FileUtil.loadFile(new File(myGitDir, "packed-refs"));
    for (String ref : packedRefs.split("\n")) {
      String[] refAndName = ref.split(" ");
      String name = refAndName[1];
      String prefix = local ? "refs/heads/" : "refs/remotes/";
      if (name.startsWith(prefix)) {
        GitTestBranch branch = new GitTestBranch(name.substring(prefix.length()), refAndName[0]);
        if (!branches.contains(branch)) {
          branches.add(branch);
        }
      }
    }
    return branches;
  }
  public void doTestMultiFile(@NotNull String folderName) {
    final List<String> files = new ArrayList<String>(2);
    FileUtil.processFilesRecursively(
        new File(folderName),
        new Processor<File>() {
          @Override
          public boolean process(File file) {
            if (file.getName().endsWith(".kt")) {
              files.add(relativePath(file));
            }
            return true;
          }
        });

    doTestMultiFile(files);
  }
예제 #6
0
 private static void writeRuntimeToJar(final JarOutputStream stream) throws IOException {
   final File unpackedRuntimePath = getUnpackedRuntimePath();
   if (unpackedRuntimePath != null) {
     FileUtil.processFilesRecursively(
         unpackedRuntimePath,
         new Processor<File>() {
           @Override
           public boolean process(File file) {
             if (file.isDirectory()) return true;
             final String relativePath = FileUtil.getRelativePath(unpackedRuntimePath, file);
             try {
               stream.putNextEntry(new JarEntry(FileUtil.toSystemIndependentName(relativePath)));
               FileInputStream fis = new FileInputStream(file);
               try {
                 FileUtil.copy(fis, stream);
               } finally {
                 fis.close();
               }
             } catch (IOException e) {
               throw new RuntimeException(e);
             }
             return true;
           }
         });
   } else {
     File runtimeJarPath = getRuntimeJarPath();
     if (runtimeJarPath != null) {
       JarInputStream jis = new JarInputStream(new FileInputStream(runtimeJarPath));
       try {
         while (true) {
           JarEntry e = jis.getNextJarEntry();
           if (e == null) {
             break;
           }
           if (FileUtil.getExtension(e.getName()).equals("class")) {
             stream.putNextEntry(e);
             FileUtil.copy(jis, stream);
           }
         }
       } finally {
         jis.close();
       }
     } else {
       throw new CompileEnvironmentException("Couldn't find runtime library");
     }
   }
 }
  private void blackBoxFileWithJavaByFullPath(@NotNull String directory) throws Exception {
    File dirFile = new File(directory);

    final List<String> javaFilePaths = new ArrayList<String>();
    final List<String> ktFilePaths = new ArrayList<String>();
    FileUtil.processFilesRecursively(
        dirFile,
        new Processor<File>() {
          @Override
          public boolean process(File file) {
            String path = relativePath(file);
            if (path.endsWith(".kt")) {
              ktFilePaths.add(path);
            } else if (path.endsWith(".java")) {
              javaFilePaths.add(path);
            }
            return true;
          }
        });

    CompilerConfiguration configuration =
        JetTestUtils.compilerConfigurationForTests(
            ConfigurationKind.ALL, TestJdkKind.FULL_JDK, JetTestUtils.getAnnotationsJar());
    configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, dirFile);
    myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
    loadFiles(ArrayUtil.toStringArray(ktFilePaths));
    classFileFactory =
        GenerationUtils.compileManyFilesGetGenerationStateForTest(
                myEnvironment.getProject(), myFiles.getPsiFiles())
            .getFactory();
    File kotlinOut = JetTestUtils.tmpDir(toString());
    OutputUtilsPackage.writeAllTo(classFileFactory, kotlinOut);

    // TODO: support several Java sources
    File javaOut = compileJava(KotlinPackage.single(javaFilePaths), kotlinOut.getPath());
    // Add javac output to classpath so that the created class loader can find generated Java
    // classes
    configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, javaOut);

    blackBox();
  }
 /**
  * @return the list of local branches in this Git repository. key is the branch name, value is the
  *     file.
  */
 private Map<String, File> readLocalBranches() {
   final Map<String, File> branches = new HashMap<String, File>();
   if (!myRefsHeadsDir.exists()) {
     return branches;
   }
   FileUtil.processFilesRecursively(
       myRefsHeadsDir,
       new Processor<File>() {
         @Override
         public boolean process(File file) {
           if (!file.isDirectory()) {
             String relativePath = FileUtil.getRelativePath(myRefsHeadsDir, file);
             if (relativePath != null) {
               branches.put(FileUtil.toSystemIndependentName(relativePath), file);
             }
           }
           return true;
         }
       });
   return branches;
 }
 /** @return list of branches from refs/remotes. */
 private Set<GitBranch> readUnpackedRemoteBranches() {
   final Set<GitBranch> branches = new HashSet<GitBranch>();
   if (!myRefsRemotesDir.exists()) {
     return branches;
   }
   FileUtil.processFilesRecursively(
       myRefsRemotesDir,
       new Processor<File>() {
         @Override
         public boolean process(File file) {
           if (!file.isDirectory()) {
             final String relativePath = FileUtil.getRelativePath(myRefsRemotesDir, file);
             if (relativePath != null) {
               String branchName = FileUtil.toSystemIndependentName(relativePath);
               String hash = loadHashFromBranchFile(file);
               branches.add(new GitBranch(branchName, hash == null ? "" : hash, false, true));
             }
           }
           return true;
         }
       });
   return branches;
 }
예제 #10
0
  public static void assertAllTestsPresentInSingleGeneratedClass(
      @NotNull Class<?> testCaseClass,
      @NotNull File testDataDir,
      @NotNull final Pattern filenamePattern) {
    TestMetadata testClassMetadata = testCaseClass.getAnnotation(TestMetadata.class);
    Assert.assertNotNull("No metadata for class: " + testCaseClass, testClassMetadata);
    final File rootFile = new File(testClassMetadata.value());

    final Set<String> filePaths = collectPathsMetadata(testCaseClass);

    FileUtil.processFilesRecursively(
        testDataDir,
        new Processor<File>() {
          @Override
          public boolean process(File file) {
            if (file.isFile() && filenamePattern.matcher(file.getName()).matches()) {
              assertFilePathPresent(file, rootFile, filePaths);
            }

            return true;
          }
        });
  }
예제 #11
0
  @Override
  public void build(
      @NotNull ErlangTarget target,
      @NotNull DirtyFilesHolder<ErlangSourceRootDescriptor, ErlangTarget> holder,
      @NotNull BuildOutputConsumer outputConsumer,
      @NotNull final CompileContext context)
      throws ProjectBuildException, IOException {
    LOG.debug(target.getPresentableName());
    final Ref<Boolean> hasDirtyFiles = Ref.create(false);
    holder.processDirtyFiles(
        new FileProcessor<ErlangSourceRootDescriptor, ErlangTarget>() {
          @Override
          public boolean apply(ErlangTarget target, File file, ErlangSourceRootDescriptor root)
              throws IOException {
            hasDirtyFiles.set(true);
            return true;
          }
        });
    if (!hasDirtyFiles.get() && !holder.hasRemovedFiles()) {
      return;
    }

    JpsModule module = target.getModule();
    JpsJavaExtensionService instance = JpsJavaExtensionService.getInstance();

    File outputDirectory = instance.getOutputDirectory(module, target.isTests());
    if (outputDirectory == null) {
      context.processMessage(
          new CompilerMessage(
              NAME, BuildMessage.Kind.ERROR, "No output dir for module " + module.getName()));
      throw new ProjectBuildException();
    }

    if (!outputDirectory.exists()) FileUtil.createDirectory(outputDirectory);

    JpsSdk<JpsDummyElement> sdk = module.getSdk(JpsErlangSdkType.INSTANCE);
    if (sdk == null) {
      context.processMessage(
          new CompilerMessage(
              NAME, BuildMessage.Kind.ERROR, "No SDK for module " + module.getName()));
      throw new ProjectBuildException();
    }

    File executable = JpsErlangSdkType.getByteCodeCompilerExecutable(sdk.getHomePath());

    List<String> commandList = new ArrayList<String>();
    commandList.add(executable.getAbsolutePath());

    CommonProcessors.CollectProcessor<File> processor =
        new CommonProcessors.CollectProcessor<File>() {
          @Override
          protected boolean accept(File file) {
            return !file.isDirectory() && FileUtilRt.extensionEquals(file.getName(), "erl");
          }
        };
    for (JpsModuleSourceRoot root : module.getSourceRoots()) {
      commandList.add("-I");
      commandList.add(root.getFile().getAbsolutePath());
      FileUtil.processFilesRecursively(root.getFile(), processor);
    }

    for (File f : processor.getResults()) {
      commandList.add(f.getAbsolutePath());
    }

    LOG.debug(StringUtil.join(commandList, " "));
    Process process = new ProcessBuilder(commandList).directory(outputDirectory).start();
    BaseOSProcessHandler handler =
        new BaseOSProcessHandler(process, null, Charset.defaultCharset());
    ProcessAdapter adapter =
        new ProcessAdapter() {
          @Override
          public void onTextAvailable(ProcessEvent event, Key outputType) {
            ErlangCompilerError error = ErlangCompilerError.create("", event.getText());
            if (error != null) {

              boolean isError = error.getCategory() == CompilerMessageCategory.ERROR;
              BuildMessage.Kind kind =
                  isError ? BuildMessage.Kind.ERROR : BuildMessage.Kind.WARNING;
              CompilerMessage msg =
                  new CompilerMessage(
                      NAME,
                      kind,
                      error.getErrorMessage(),
                      VirtualFileManager.extractPath(error.getUrl()),
                      -1,
                      -1,
                      -1,
                      error.getLine(),
                      -1);
              context.processMessage(msg);
            }
          }
        };
    handler.addProcessListener(adapter);
    handler.startNotify();
    handler.waitFor();
  }