private JavaParameters createJavaParameters() throws ExecutionException {
    JavaParameters parameters = new JavaParameters();
    Sdk sdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
    if (sdk == null) {
      throw new ExecutionException("No Java SDK available.");
    }
    parameters.setJdk(sdk);
    parameters.setMainClass(AbstractPaxBasedFrameworkRunner.PaxRunnerMainClass);
    PathsList classpath = parameters.getClassPath();
    for (VirtualFile libraryFile : AbstractPaxBasedFrameworkRunner.getPaxLibraries()) {
      classpath.add(libraryFile);
    }

    ParametersList parametersList = parameters.getProgramParametersList();
    parametersList.add("--p=" + myFrameworkType);
    if (!StringUtil.isEmpty(myVersion)) {
      parametersList.add("--v=" + myVersion);
    }
    parametersList.add("--nologo=true");
    parametersList.add("--executor=noop");
    parametersList.add("--workingDirectory=" + myTargetFolder);
    if (myClearDownloadFolder) {
      parametersList.add("--clean");
    }
    if (!StringUtil.isEmpty(myProfiles)) {
      parametersList.add("--profiles=" + myProfiles);
    }
    return parameters;
  }
  protected static void addClasspathFromRootModel(
      @Nullable Module module, boolean isTests, JavaParameters params, boolean allowDuplication)
      throws CantRunException {
    PathsList nonCore = new PathsList();
    getClassPathFromRootModel(module, isTests, params, allowDuplication, nonCore);
    nonCore.add(".");

    final String cp = nonCore.getPathsString();
    if (!StringUtil.isEmptyOrSpaces(cp)) {
      params.getProgramParametersList().add("--classpath");
      params.getProgramParametersList().add(cp);
    }
  }
  @Nullable
  public static PathsList getClassPathFromRootModel(
      Module module,
      boolean isTests,
      JavaParameters params,
      boolean allowDuplication,
      PathsList pathList)
      throws CantRunException {
    if (module == null) {
      return null;
    }

    final JavaParameters tmp = new JavaParameters();
    tmp.configureByModule(
        module, isTests ? JavaParameters.CLASSES_AND_TESTS : JavaParameters.CLASSES_ONLY);
    if (tmp.getClassPath().getVirtualFiles().isEmpty()) {
      return null;
    }

    Set<VirtualFile> core = new HashSet<VirtualFile>(params.getClassPath().getVirtualFiles());

    for (VirtualFile virtualFile : tmp.getClassPath().getVirtualFiles()) {
      if (allowDuplication || !core.contains(virtualFile)) {
        pathList.add(virtualFile);
      }
    }
    return pathList;
  }
Exemplo n.º 4
0
  private PathsList removeFrameworkStuff(Module module, List<VirtualFile> rootFiles) {
    final List<File> toExclude = getImplicitClasspathRoots(module);
    if (LOG.isDebugEnabled()) {
      LOG.debug("Before removing framework stuff: " + rootFiles);
      LOG.debug("Implicit roots:" + toExclude);
    }

    PathsList scriptClassPath = new PathsList();
    eachRoot:
    for (VirtualFile file : rootFiles) {
      for (final File excluded : toExclude) {
        if (VfsUtil.isAncestor(excluded, VfsUtil.virtualToIoFile(file), false)) {
          continue eachRoot;
        }
      }
      scriptClassPath.add(file);
    }
    return scriptClassPath;
  }
  private void assertClasspath(String moduleName, Scope scope, Type type, String... expectedPaths)
      throws Exception {
    createOutputDirectories();

    PathsList actualPathsList;
    Module module = getModule(moduleName);

    if (scope == Scope.RUNTIME) {
      JavaParameters params = new JavaParameters();
      params.configureByModule(
          module,
          type == Type.TESTS ? JavaParameters.CLASSES_AND_TESTS : JavaParameters.CLASSES_ONLY);
      actualPathsList = params.getClassPath();
    } else {
      OrderEnumerator en =
          OrderEnumerator.orderEntries(module).recursively().withoutSdk().compileOnly();
      if (type == Type.PRODUCTION) en.productionOnly();
      actualPathsList = en.classes().getPathsList();
    }

    assertPaths(expectedPaths, actualPathsList.getPathList());
  }
 /**
  * Configures given classpath to reference target i18n bundle file(s).
  *
  * @param classPath process classpath
  * @param bundlePath path to the target bundle file
  * @param contextClass class from the same content root as the target bundle file
  */
 public static void addBundle(
     @NotNull PathsList classPath, @NotNull String bundlePath, @NotNull Class<?> contextClass) {
   String pathToUse = bundlePath.replace('.', '/');
   if (!pathToUse.endsWith(".properties")) {
     pathToUse += ".properties";
   }
   if (!pathToUse.startsWith("/")) {
     pathToUse = '/' + pathToUse;
   }
   String root = PathManager.getResourceRoot(contextClass, pathToUse);
   if (root != null) {
     classPath.add(root);
   }
 }