@Override
 protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception {
   String pathForClass = PathUtil.getJarPathForClass(LocalInspectionEP.class);
   moduleBuilder.addLibrary("lang-api", pathForClass);
   String platformApiJar = PathUtil.getJarPathForClass(JBList.class);
   moduleBuilder.addLibrary("platform-api", platformApiJar);
 }
  private static String getArtifactResolverJar(boolean isMaven3) throws IOException {
    Class marker =
        isMaven3 ? MavenArtifactResolvedM3RtMarker.class : MavenArtifactResolvedM2RtMarker.class;

    File classDirOrJar = new File(PathUtil.getJarPathForClass(marker));

    if (!classDirOrJar.isDirectory()) {
      return classDirOrJar.getAbsolutePath(); // it's a jar in IDEA installation.
    }

    // it's a classes directory, we are in development mode.
    File tempFile = FileUtil.createTempFile("idea-", "-artifactResolver.jar");
    tempFile.deleteOnExit();

    ZipOutputStream zipOutput = new ZipOutputStream(new FileOutputStream(tempFile));
    try {
      ZipUtil.addDirToZipRecursively(zipOutput, null, classDirOrJar, "", null, null);

      if (isMaven3) {
        File m2Module = new File(PathUtil.getJarPathForClass(MavenModuleMap.class));

        String commonClassesPath = MavenModuleMap.class.getPackage().getName().replace('.', '/');
        ZipUtil.addDirToZipRecursively(
            zipOutput, null, new File(m2Module, commonClassesPath), commonClassesPath, null, null);
      }
    } finally {
      zipOutput.close();
    }

    return tempFile.getAbsolutePath();
  }
  protected void appendForkInfo(Executor executor) throws ExecutionException {
    final String forkMode = getForkMode();
    if (Comparing.strEqual(forkMode, "none")) {
      if (forkPerModule()) {
        if (isExecutorDisabledInForkedMode()) {
          final String actionName = UIUtil.removeMnemonic(executor.getStartActionText());
          throw new CantRunException(
              "'"
                  + actionName
                  + "' is disabled when per-module working directory is configured.<br/>"
                  + "Please specify single working directory, or change test scope to single module.");
        }
      } else {
        return;
      }
    } else if (isExecutorDisabledInForkedMode()) {
      final String actionName = executor.getActionName();
      throw new CantRunException(
          actionName
              + " is disabled in fork mode.<br/>Please change fork mode to &lt;none&gt; to "
              + actionName.toLowerCase(Locale.ENGLISH)
              + ".");
    }

    final JavaParameters javaParameters = getJavaParameters();
    final Sdk jdk = javaParameters.getJdk();
    if (jdk == null) {
      throw new ExecutionException(
          ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
    }

    try {
      final File tempFile = FileUtil.createTempFile("command.line", "", true);
      final PrintWriter writer = new PrintWriter(tempFile, CharsetToolkit.UTF8);
      try {
        if (JdkUtil.useDynamicClasspath(getConfiguration().getProject())) {
          String classpath = PathUtil.getJarPathForClass(CommandLineWrapper.class);
          final String utilRtPath = PathUtil.getJarPathForClass(StringUtilRt.class);
          if (!classpath.equals(utilRtPath)) {
            classpath += File.pathSeparator + utilRtPath;
          }
          writer.println(classpath);
        } else {
          writer.println("");
        }

        writer.println(((JavaSdkType) jdk.getSdkType()).getVMExecutablePath(jdk));
        for (String vmParameter : javaParameters.getVMParametersList().getList()) {
          writer.println(vmParameter);
        }
      } finally {
        writer.close();
      }

      passForkMode(forkMode, tempFile);
    } catch (Exception e) {
      LOG.error(e);
    }
  }
  protected void initialize() throws ExecutionException {
    JavaParametersUtil.configureConfiguration(myJavaParameters, myConfiguration);
    myJavaParameters.setMainClass(JUnitConfiguration.JUNIT_START_CLASS);
    final Module module = myConfiguration.getConfigurationModule().getModule();
    if (myJavaParameters.getJdk() == null) {
      myJavaParameters.setJdk(
          module != null
              ? ModuleRootManager.getInstance(module).getSdk()
              : ProjectRootManager.getInstance(myProject).getProjectSdk());
    }

    myJavaParameters.getClassPath().add(JavaSdkUtil.getIdeaRtJarPath());
    myJavaParameters.getClassPath().add(PathUtil.getJarPathForClass(JUnitStarter.class));
    myJavaParameters
        .getProgramParametersList()
        .add(JUnitStarter.IDE_VERSION + JUnitStarter.VERSION);
    for (RunConfigurationExtension ext :
        Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
      ext.updateJavaParameters(myConfiguration, myJavaParameters, getRunnerSettings());
    }

    final Object[] listeners = Extensions.getExtensions(IDEAJUnitListener.EP_NAME);
    final StringBuilder buf = new StringBuilder();
    for (final Object listener : listeners) {
      boolean enabled = true;
      for (RunConfigurationExtension ext :
          Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
        if (ext.isListenerDisabled(myConfiguration, listener, getRunnerSettings())) {
          enabled = false;
          break;
        }
      }
      if (enabled) {
        final Class classListener = listener.getClass();
        buf.append(classListener.getName()).append("\n");
        myJavaParameters.getClassPath().add(PathUtil.getJarPathForClass(classListener));
      }
    }
    if (buf.length() > 0) {
      try {
        myListenersFile = FileUtil.createTempFile("junit_listeners_", "");
        myListenersFile.deleteOnExit();
        myJavaParameters.getProgramParametersList().add("@@" + myListenersFile.getPath());
        FileUtil.writeToFile(myListenersFile, buf.toString().getBytes());
      } catch (IOException e) {
        LOG.error(e);
      }
    }
  }
  public static String getPathInConf(String fileName) {
    try {
      final String jarPath = PathUtil.getJarPathForClass(GroovyScriptRunner.class);
      if (new File(jarPath).isFile()) { // jar; distribution mode
        return new File(jarPath, "../" + fileName).getCanonicalPath();
      }

      // else, it's directory in out, development mode
      return new File(jarPath, "conf/" + fileName).getCanonicalPath();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
 protected Module createModule(final String name) {
   final Module module = super.createModule(name);
   final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
   final LibraryTable.ModifiableModel modifiableModel =
       model.getModuleLibraryTable().getModifiableModel();
   final Library library = modifiableModel.createLibrary("junit");
   final Library.ModifiableModel libModel = library.getModifiableModel();
   libModel.addRoot(
       VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Before.class))),
       OrderRootType.CLASSES);
   libModel.commit();
   model.commit();
   return module;
 }
 public void updateJavaParameters(
     RunConfigurationBase configuration, JavaParameters params, RunnerSettings runnerSettings) {
   if (runnerSettings != null || !isApplicableFor(configuration)) {
     return;
   }
   StringBuilder argument = new StringBuilder("-javaagent:");
   final String agentPath = PathUtil.getJarPathForClass(ProjectData.class); // todo spaces
   argument.append(agentPath);
   params.getVMParametersList().add(argument.toString());
   params.getClassPath().add(agentPath);
   params
       .getVMParametersList()
       .addProperty(ProjectData.TRACE_DIR, getTracesDirectory(configuration));
 }
Esempio n. 8
0
  public TOSDialog() {
    super(null, false, IdeModalityType.IDE);
    init();
    setTitle("eddy - Logging preferences");
    setCrossClosesWindow(false);
    // get TOS page out of our jar or directory
    final String pathname = PathUtil.getJarPathForClass(TOSDialog.class);
    final File path = new File(pathname);
    try {
      final URL url;
      if (path.isDirectory()) {
        url = new File(path, "intro.html").toURI().toURL();
      } else {
        url = ResourceUtil.getResource(TOSDialog.class, "", "intro.html");
      }
      TOSTextPane.setPage(url);
    } catch (MalformedURLException e) {
      throw new RuntimeException("Cannot load intro text. Please try reinstalling.", e);
    } catch (IOException e) {
      throw new RuntimeException("Cannot load intro text. Please try reinstalling.", e);
    }

    HyperlinkListener l =
        new HyperlinkListener() {
          @Override
          public void hyperlinkUpdate(HyperlinkEvent e) {
            log("got link event: " + e);
            if (HyperlinkEvent.EventType.ACTIVATED == e.getEventType()) {
              try {
                java.awt.Desktop.getDesktop().browse(e.getURL().toURI());
              } catch (IOException e1) {
                // wtf, do nothing
                log("exception: " + e1);
              } catch (URISyntaxException e2) {
                // broken link, do nothing
                log("exception: " + e2);
              }
            }
          }
        };
    TOSTextPane.addHyperlinkListener(l);
  }
 protected void collectListeners(
     JavaParameters javaParameters, StringBuilder buf, String epName, String delimiter) {
   final T configuration = getConfiguration();
   final Object[] listeners = Extensions.getExtensions(epName);
   for (final Object listener : listeners) {
     boolean enabled = true;
     for (RunConfigurationExtension ext :
         Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
       if (ext.isListenerDisabled(configuration, listener, getRunnerSettings())) {
         enabled = false;
         break;
       }
     }
     if (enabled) {
       if (buf.length() > 0) buf.append(delimiter);
       final Class classListener = listener.getClass();
       buf.append(classListener.getName());
       javaParameters.getClassPath().add(PathUtil.getJarPathForClass(classListener));
     }
   }
 }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    myNestedFormLoader = new MyNestedFormLoader();

    final String swingPath = PathUtil.getJarPathForClass(AbstractButton.class);

    java.util.List<URL> cp = new ArrayList<URL>();
    appendPath(cp, JBTabbedPane.class);
    appendPath(cp, TIntObjectHashMap.class);
    appendPath(cp, UIUtil.class);
    appendPath(cp, SystemInfoRt.class);
    appendPath(cp, ApplicationManager.class);
    appendPath(cp, PathManager.getResourceRoot(this.getClass(), "/messages/UIBundle.properties"));
    appendPath(cp, PathManager.getResourceRoot(this.getClass(), "/RuntimeBundle.properties"));
    appendPath(cp, GridLayoutManager.class); // forms_rt
    appendPath(cp, DataProvider.class);
    myClassFinder =
        new MyClassFinder(
            new URL[] {new File(swingPath).toURI().toURL()}, cp.toArray(new URL[cp.size()]));
  }
  public void appendCoverageArgument(
      final String sessionDataFilePath,
      final String[] patterns,
      final SimpleJavaParameters javaParameters,
      final boolean collectLineInfo,
      final boolean isSampling) {
    StringBuilder argument = new StringBuilder("-javaagent:");
    final String agentPath = PathUtil.getJarPathForClass(ProjectData.class);
    final String parentPath = handleSpacesInPath(agentPath);
    argument.append(parentPath).append(File.separator).append(new File(agentPath).getName());
    argument.append("=");
    try {
      final File tempFile = createTempFile();
      tempFile.deleteOnExit();
      write2file(tempFile, sessionDataFilePath);
      write2file(tempFile, String.valueOf(collectLineInfo));
      write2file(tempFile, Boolean.FALSE.toString()); // append unloaded
      write2file(tempFile, Boolean.FALSE.toString()); // merge with existing
      write2file(tempFile, String.valueOf(isSampling));
      if (patterns != null) {
        for (String coveragePattern : patterns) {
          coveragePattern =
              coveragePattern.replace("$", "\\$").replace(".", "\\.").replaceAll("\\*", ".*");
          if (!coveragePattern.endsWith(".*")) { // include inner classes
            coveragePattern += "(\\$.*)*";
          }
          write2file(tempFile, coveragePattern);
        }
      }
      argument.append(tempFile.getCanonicalPath());
    } catch (IOException e) {
      LOG.info("Coverage was not enabled", e);
      return;
    }

    javaParameters.getVMParametersList().add(argument.toString());
  }
Esempio n. 12
0
 public static boolean checkTestNGInClasspath(PsiElement psiElement) {
   final Project project = psiElement.getProject();
   final PsiManager manager = PsiManager.getInstance(project);
   if (JavaPsiFacade.getInstance(manager.getProject())
           .findClass(TestNG.class.getName(), psiElement.getResolveScope())
       == null) {
     if (!ApplicationManager.getApplication().isUnitTestMode()) {
       if (Messages.showOkCancelDialog(
               psiElement.getProject(),
               "TestNG will be added to module classpath",
               "Unable to convert.",
               Messages.getWarningIcon())
           != Messages.OK) {
         return false;
       }
     }
     final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement);
     if (module == null) return false;
     String url =
         VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Assert.class)));
     ModuleRootModificationUtil.addModuleLibrary(module, url);
   }
   return true;
 }
 private static void appendPath(Collection<URL> container, Class cls)
     throws MalformedURLException {
   final String path = PathUtil.getJarPathForClass(cls);
   appendPath(container, path);
 }
Esempio n. 14
0
 private static boolean hasDocTagsSupport() {
   String testngJarPath = PathUtil.getJarPathForClass(Test.class);
   String version =
       JarUtil.getJarAttribute(new File(testngJarPath), Attributes.Name.IMPLEMENTATION_VERSION);
   return version != null && StringUtil.compareVersionNumbers(version, "5.12") <= 0;
 }