com.intellij.execution.configurations.JavaParameters Java Examples

The following examples show how to use com.intellij.execution.configurations.JavaParameters. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PantsClasspathRunConfigurationExtension.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Filter out all jars imported to the project with the exception of
 * jars on the JDK path, IntelliJ installation paths, and plugin installation path,
 * because Pants is already exporting all the runtime classpath in manifest.jar.
 *
 * Exception applies during unit test of this plugin because "JUnit" and "com.intellij"
 * plugin lives under somewhere under ivy, whereas during normal usage, they are covered
 * by `homePath`.
 *
 *
 * @param params JavaParameters
 * @return a set of paths that should be allowed to passed to the test runner.
 */
@NotNull
private Set<String> calculatePathsAllowed(JavaParameters params) {

  String homePath = PathManager.getHomePath();
  String pluginPath = PathManager.getPluginsPath();

  Set<String> pathsAllowed = Sets.newHashSet(homePath, pluginPath);

  if (ApplicationManager.getApplication().isUnitTestMode()) {
    // /Users/yic/.ivy2/pants/com.intellij.sdk.community/idea_rt/jars/idea_rt-latest.jar ->
    // /Users/yic/.ivy2/pants/com.intellij.sdk.community/
    Optional.ofNullable(PluginManagerCore.getPlugin(PluginId.getId("com.intellij")))
      .map(s -> s.getPath().getParentFile().getParentFile().getParentFile().getAbsolutePath())
      .ifPresent(pathsAllowed::add);

    // At this point we know junit plugin is already enabled.
    // //Users/yic/.ivy2/pants/com.intellij.junit-plugin/junit-rt/jars/junit-rt-latest.jar ->
    // /Users/yic/.ivy2/pants/com.intellij.junit-plugin/
    Optional.ofNullable(PluginManagerCore.getPlugin(PluginId.getId("JUnit")))
      .map(s -> s.getPath().getParentFile().getParentFile().getParentFile().getAbsolutePath())
      .ifPresent(pathsAllowed::add);
  }
  return pathsAllowed;
}
 
Example #2
Source File: AppCommandLineState.java    From SmartTomcat with Apache License 2.0 5 votes vote down vote up
private void addBinFolder(Path tomcatInstallation, JavaParameters javaParams) throws ExecutionException {
    // Dynamically adds the tomcat jars to the classpath
    Path binFolder = tomcatInstallation.resolve("bin");
    if (!Files.exists(binFolder)) {
        throw new ExecutionException("The Tomcat installation configured doesn't contains a bin folder");
    }
    String[] jars = binFolder.toFile().list((dir, name) -> name.endsWith(".jar"));

    assert jars != null;
    for (String jarFile : jars) {
        javaParams.getClassPath().add(binFolder.resolve(jarFile).toFile().getAbsolutePath());
    }
}
 
Example #3
Source File: AppCommandLineState.java    From SmartTomcat with Apache License 2.0 5 votes vote down vote up
private void addLibFolder(Path tomcatInstallation, JavaParameters javaParams) throws ExecutionException {
    // add libs folder
    Path libFolder = tomcatInstallation.resolve("lib");
    if (!Files.exists(libFolder)) {
        throw new ExecutionException("The Tomcat installation configured doesn't contains a lib folder");
    }
    String[] jars = libFolder.toFile().list((dir, name) -> name.endsWith(".jar"));

    assert jars != null;
    for (String jarFile : jars) {
        javaParams.getClassPath().add(libFolder.resolve(jarFile).toFile().getAbsolutePath());
    }
}
 
Example #4
Source File: IntellijWithPluginClasspathHelper.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static void addIntellijLibraries(JavaParameters params, Sdk ideaJdk) {
  String libPath = ideaJdk.getHomePath() + File.separator + "lib";
  PathsList list = params.getClassPath();
  for (String lib : IJ_LIBRARIES) {
    list.addFirst(libPath + File.separator + lib);
  }
  list.addFirst(((JavaSdkType) ideaJdk.getSdkType()).getToolsPath(ideaJdk));
}
 
Example #5
Source File: IntellijWithPluginClasspathHelper.java    From intellij with Apache License 2.0 5 votes vote down vote up
public static void addRequiredVmParams(
    JavaParameters params, Sdk ideaJdk, ImmutableSet<File> javaAgents) {
  String canonicalSandbox = IdeaJdkHelper.getSandboxHome(ideaJdk);
  ParametersList vm = params.getVMParametersList();

  String libPath = ideaJdk.getHomePath() + File.separator + "lib";
  vm.add("-Xbootclasspath/a:" + libPath + File.separator + "boot.jar");
  
  vm.defineProperty("idea.config.path", canonicalSandbox + File.separator + "config");
  vm.defineProperty("idea.system.path", canonicalSandbox + File.separator + "system");
  vm.defineProperty("idea.plugins.path", canonicalSandbox + File.separator + "plugins");
  vm.defineProperty("idea.classpath.index.enabled", "false");

  if (SystemInfo.isMac) {
    vm.defineProperty("idea.smooth.progress", "false");
    vm.defineProperty("apple.laf.useScreenMenuBar", "true");
  }

  if (SystemInfo.isXWindow) {
    if (!vm.hasProperty("sun.awt.disablegrab")) {
      vm.defineProperty(
          "sun.awt.disablegrab", "true"); // See http://devnet.jetbrains.net/docs/DOC-1142
    }
  }
  for (File javaAgent : javaAgents) {
    vm.add("-javaagent:" + javaAgent.getAbsolutePath());
  }

  params.setWorkingDirectory(ideaJdk.getHomePath() + File.separator + "bin" + File.separator);
  params.setJdk(ideaJdk);

  addIntellijLibraries(params, ideaJdk);

  params.setMainClass("com.intellij.idea.Main");
}
 
Example #6
Source File: BlazeJavaDebuggerRunner.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void patch(
    JavaParameters javaParameters,
    RunnerSettings runnerSettings,
    RunProfile runProfile,
    final boolean beforeExecution) {
  // We don't want to support Java run configuration patching.
}
 
Example #7
Source File: CommandLineTargetTest.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 5 votes vote down vote up
@Test
public void testDebugCommand() {
    JavaParameters params = Mockito.mock(JavaParameters.class);
    String debugCommand = CommandLineTarget.builder()
            .isDebugging(true)
            .parameters(javaParameters)
            .embeddedLinuxJVMRunConfiguration(piRunConfiguration)
            .build().toString();
    assertTrue(debugCommand.contains("sudo java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + parameters.getPort()));
}
 
Example #8
Source File: PantsClasspathRunConfigurationExtension.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * The goal of this function is to find classpath for IntelliJ JUnit/Scala runner.
 * <p/>
 * This function will fail if the projects' Pants doesn't support `--export-classpath-manifest-jar-only`.
 * It also assumes that Pants has created a manifest jar that contains all the classpath links for the
 * particular test that's being run.
 */
@Override
public <T extends RunConfigurationBase> void updateJavaParameters(
  T configuration,
  @NotNull JavaParameters params,
  RunnerSettings runnerSettings
) throws ExecutionException {
  List<BeforeRunTask<?>> tasks = ((RunManagerImpl) RunManager.getInstance(configuration.getProject())).getBeforeRunTasks(configuration);
  boolean builtByPants = tasks.stream().anyMatch(s -> s.getProviderId().equals(PantsMakeBeforeRun.ID));
  // Not built by Pants means it was built by IntelliJ, in which case we don't need to change the classpath.
  if (!builtByPants) {
    return;
  }

  final Module module = findPantsModule(configuration);
  if (module == null) {
    return;
  }

  Set<String> pathsAllowed = calculatePathsAllowed(params);

  final PathsList classpath = params.getClassPath();
  List<String> classpathToKeep = classpath.getPathList().stream()
    .filter(cp -> pathsAllowed.stream().anyMatch(cp::contains)).collect(Collectors.toList());
  classpath.clear();
  classpath.addAll(classpathToKeep);

  VirtualFile manifestJar = PantsUtil.findProjectManifestJar(configuration.getProject())
    .orElseThrow(() -> new ExecutionException("manifest.jar is not found. It should be generated by `./pants export-classpath ...`"));
  classpath.add(manifestJar.getPath());

  PantsExternalMetricsListenerManager.getInstance().logTestRunner(configuration);
}
 
Example #9
Source File: MuleRunnerCommandLineState.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
@Override
    public JavaParameters createJavaParameters() throws ExecutionException {
        JavaParameters javaParams = new JavaParameters();
        // Use the same JDK as the project
        Project project = this.model.getProject();
        ProjectRootManager manager = ProjectRootManager.getInstance(project);
        javaParams.setJdk(manager.getProjectSdk());
        // All modules to use the same things
//        Module[] modules = ModuleManager.getInstance(project).getModules();
//        if (modules.length > 0) {
//            for (Module module : modules) {
//                javaParams.configureByModule(module, JavaParameters.JDK_AND_CLASSES);
//            }
//        }

        final String muleHome = model.getMuleHome();
        final MuleClassPath muleClassPath = new MuleClassPath(new File(muleHome));
        final List<File> urLs = muleClassPath.getJars();
        for (File jar : urLs) {
            javaParams.getClassPath().add(jar);
        }
        //EE license location 
        javaParams.getClassPath().add(muleHome + "/conf");
        
        //Mule main class
        javaParams.setMainClass(MAIN_CLASS);

        //Add default vm parameters
        javaParams.getVMParametersList().add("-Dmule.home=" + muleHome);
        javaParams.getVMParametersList().add("-Dmule.base=" + muleHome);
        javaParams.getVMParametersList().add("-Dmule.testingMode=true");
        javaParams.getVMParametersList().add("-Djava.net.preferIPv4Stack=TRUE ");
        javaParams.getVMParametersList().add("-Dmvel2.disable.jit=TRUE");
        javaParams.getVMParametersList().add("-Dorg.glassfish.grizzly.nio.transport.TCPNIOTransport.max-receive-buffer-size=1048576");
        javaParams.getVMParametersList().add("-Dorg.glassfish.grizzly.nio.transport.TCPNIOTransport.max-send-buffer-size=1048576");
        javaParams.getVMParametersList().add("-Djava.endorsed.dirs=" + muleHome + "/lib/endorsed ");
        javaParams.getVMParametersList().add("-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager");
        javaParams.getVMParametersList().add("-Dmule.forceConsoleLog=true");

        if (isDebug) {
            javaParams.getVMParametersList().add("-Dmule.debug.enable=true");
            javaParams.getVMParametersList().add("-Dmule.debug.suspend=true");
        }

        javaParams.getVMParametersList().add("-Xms1024m");
        javaParams.getVMParametersList().add("-Xmx1024m");
        javaParams.getVMParametersList().add("-XX:PermSize=256m");
        javaParams.getVMParametersList().add("-XX:MaxPermSize=256m");
        javaParams.getVMParametersList().add("-XX:+HeapDumpOnOutOfMemoryError");
        javaParams.getVMParametersList().add("-XX:+AlwaysPreTouch");
        javaParams.getVMParametersList().add("-XX:NewSize=512m");
        javaParams.getVMParametersList().add("-XX:MaxNewSize=512m");
        javaParams.getVMParametersList().add("-XX:MaxTenuringThreshold=8");


        // VM Args
        String vmArgs = this.getVmArgs();
        if (vmArgs != null) {
            javaParams.getVMParametersList().addParametersString(vmArgs);
        }

        // All done, run it
        return javaParams;
    }
 
Example #10
Source File: WeaveRunnerCommandLine.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
@Override
protected JavaParameters createJavaParameters() throws ExecutionException
{
    final JavaParameters javaParams = new JavaParameters();
    // Use the same JDK as the project
    final Project project = this.model.getProject();
    final ProjectRootManager manager = ProjectRootManager.getInstance(project);
    javaParams.setJdk(manager.getProjectSdk());
    // All modules to use the same things
    final Module[] modules = ModuleManager.getInstance(project).getModules();
    if (modules.length > 0)
    {
        for (Module module : modules)
        {
            javaParams.configureByModule(module, JavaParameters.JDK_AND_CLASSES);
        }
    }

    final String weaveHome = model.getWeaveHome();
    if (StringUtils.isNotBlank(weaveHome))
    {
        final List<File> urLs = WeaveSdk.getJars(weaveHome);
        for (File jar : urLs)
        {
            javaParams.getClassPath().add(jar);
        }
    }
    //Mule main class
    javaParams.setMainClass(MAIN_CLASS);

    //Add default vm parameters
    javaParams.getVMParametersList().add("-Xms1024m");
    javaParams.getVMParametersList().add("-Xmx1024m");
    javaParams.getVMParametersList().add("-XX:PermSize=256m");
    javaParams.getVMParametersList().add("-XX:MaxPermSize=256m");
    javaParams.getVMParametersList().add("-XX:+HeapDumpOnOutOfMemoryError");
    javaParams.getVMParametersList().add("-XX:+AlwaysPreTouch");
    javaParams.getVMParametersList().add("-XX:NewSize=512m");
    javaParams.getVMParametersList().add("-XX:MaxNewSize=512m");
    javaParams.getVMParametersList().add("-XX:MaxTenuringThreshold=8");

    final List<WeaveInput> weaveInputs = model.getWeaveInputs();
    for (WeaveInput weaveInput : weaveInputs)
    {
        javaParams.getProgramParametersList().add("-input");
        javaParams.getProgramParametersList().add(weaveInput.getName());
        javaParams.getProgramParametersList().add(weaveInput.getPath());
    }

    if (isDebug)
    {
        javaParams.getVMParametersList().add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005");
        javaParams.getProgramParametersList().add("-debug");
    }

    if (!StringUtils.isBlank(model.getWeaveOutput()))
    {
        javaParams.getProgramParametersList().add("-output", model.getWeaveOutput());
    }

    javaParams.getProgramParametersList().add(model.getWeaveFile());

    // All done, run it
    return javaParams;
}
 
Example #11
Source File: BlazeIntellijPluginConfiguration.java    From intellij with Apache License 2.0 4 votes vote down vote up
/**
 * Plugin jar has been previously created via blaze build. This method: - copies jar to sandbox
 * environment - cracks open jar and finds plugin.xml (with ID, etc., needed for JVM args) - sets
 * up the SDK, etc. (use project SDK?) - sets up the JVM, and returns a JavaCommandLineState
 */
@Nullable
@Override
public RunProfileState getState(Executor executor, ExecutionEnvironment env)
    throws ExecutionException {
  final Sdk ideaJdk = pluginSdk;
  if (!IdeaJdkHelper.isIdeaJdk(ideaJdk)) {
    throw new ExecutionException("Choose an IntelliJ Platform Plugin SDK");
  }
  String sandboxHome = IdeaJdkHelper.getSandboxHome(ideaJdk);
  if (sandboxHome == null) {
    throw new ExecutionException("No sandbox specified for IntelliJ Platform Plugin SDK");
  }

  try {
    sandboxHome = new File(sandboxHome).getCanonicalPath();
  } catch (IOException e) {
    throw new ExecutionException("No sandbox specified for IntelliJ Platform Plugin SDK", e);
  }
  String buildNumber = IdeaJdkHelper.getBuildNumber(ideaJdk);
  final BlazeIntellijPluginDeployer deployer =
      new BlazeIntellijPluginDeployer(sandboxHome, buildNumber, target);
  env.putUserData(BlazeIntellijPluginDeployer.USER_DATA_KEY, deployer);

  // copy license from running instance of idea
  IdeaJdkHelper.copyIDEALicense(sandboxHome);

  return new JavaCommandLineState(env) {
    @Override
    protected JavaParameters createJavaParameters() throws ExecutionException {
      DeployedPluginInfo deployedPluginInfo = deployer.deployNonBlocking();

      final JavaParameters params = new JavaParameters();

      ParametersList vm = params.getVMParametersList();

      fillParameterList(vm, vmParameters);
      fillParameterList(params.getProgramParametersList(), programParameters);

      IntellijWithPluginClasspathHelper.addRequiredVmParams(
          params, ideaJdk, deployedPluginInfo.javaAgents);

      vm.defineProperty(
          JetBrainsProtocolHandler.REQUIRED_PLUGINS_KEY,
          Joiner.on(',').join(deployedPluginInfo.pluginIds));

      if (!vm.hasProperty(PlatformUtils.PLATFORM_PREFIX_KEY) && buildNumber != null) {
        String prefix = IdeaJdkHelper.getPlatformPrefix(buildNumber);
        if (prefix != null) {
          vm.defineProperty(PlatformUtils.PLATFORM_PREFIX_KEY, prefix);
        }
      }
      return params;
    }

    /** https://youtrack.jetbrains.com/issue/IDEA-201733 */
    @Override
    protected GeneralCommandLine createCommandLine() throws ExecutionException {
      GeneralCommandLine commandLine = super.createCommandLine();
      for (String jreName : new String[] {"jbr", "jre64", "jre"}) {
        File bundledJre = new File(ideaJdk.getHomePath(), jreName);
        if (bundledJre.isDirectory()) {
          File bundledJava = new File(bundledJre, "bin/java");
          if (bundledJava.canExecute()) {
            commandLine.setExePath(bundledJava.getAbsolutePath());
            break;
          }
        }
      }
      return commandLine;
    }

    @Override
    protected OSProcessHandler startProcess() throws ExecutionException {
      deployer.blockUntilDeployComplete();
      final OSProcessHandler handler = super.startProcess();
      handler.addProcessListener(
          new ProcessAdapter() {
            @Override
            public void processTerminated(ProcessEvent event) {
              deployer.deleteDeployment();
            }
          });
      return handler;
    }
  };
}
 
Example #12
Source File: AppCommandLineState.java    From SmartTomcat with Apache License 2.0 2 votes vote down vote up
@Override
protected JavaParameters createJavaParameters() {
    try {

        Path tomcatInstallationPath = Paths.get(configuration.getTomcatInfo().getPath());
        String moduleRoot = configuration.getModuleName();
        String contextPath = configuration.getContextPath();
        String tomcatVersion = configuration.getTomcatInfo().getVersion();
        String vmOptions = configuration.getVmOptions();
        Map<String, String> envOptions = configuration.getEnvOptions();

        Project project = this.configuration.getProject();

        JavaParameters javaParams = new JavaParameters();


        ProjectRootManager manager = ProjectRootManager.getInstance(project);
        javaParams.setJdk(manager.getProjectSdk());

        javaParams.setDefaultCharset(project);

        javaParams.setMainClass(TOMCAT_MAIN_CLASS);
        javaParams.getProgramParametersList().add("start");
        addBinFolder(tomcatInstallationPath, javaParams);
        addLibFolder(tomcatInstallationPath, javaParams);

        File file = new File(configuration.getDocBase());
        VirtualFile fileByIoFile = LocalFileSystem.getInstance().findFileByIoFile(file);
        Module module = ModuleUtilCore.findModuleForFile(fileByIoFile, configuration.getProject());


        if (module == null) {
            throw new ExecutionException("The Module Root specified is not a module according to Intellij");
        }

        String userHome = System.getProperty("user.home");
        Path workPath = Paths.get(userHome, ".SmartTomcat", project.getName(), module.getName());
        Path confPath = workPath.resolve("conf");
        if (!confPath.toFile().exists()) {
            confPath.toFile().mkdirs();
        }


        FileUtil.copyFileOrDir(tomcatInstallationPath.resolve("conf").toFile(), confPath.toFile());

        javaParams.setWorkingDirectory(workPath.toFile());


        updateServerConf(tomcatVersion, module, confPath, contextPath, configuration);


        javaParams.setPassParentEnvs(configuration.getPassParentEnvironmentVariables());
        if (envOptions != null) {
            javaParams.setEnv(envOptions);
        }
        javaParams.getVMParametersList().addParametersString(vmOptions);
        return javaParams;

    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }


}