Search in sources :

Example 16 with PathsList

use of com.intellij.util.PathsList in project intellij-community by JetBrains.

the class PathListBuilderTest method testAsString.

@Test
public void testAsString() {
    PathsList builder = new PathsList();
    builder.add("a" + File.pathSeparatorChar + "b" + File.pathSeparatorChar);
    builder.add("c" + File.pathSeparatorChar);
    assertThat(builder.getPathsString()).isEqualTo("a" + File.pathSeparatorChar + "b" + File.pathSeparatorChar + "c");
}
Also used : PathsList(com.intellij.util.PathsList) Test(org.junit.Test)

Example 17 with PathsList

use of com.intellij.util.PathsList in project intellij-community by JetBrains.

the class GroovyScriptRunner method addClasspathFromRootModel.

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);
    final String cp = nonCore.getPathsString();
    if (!StringUtil.isEmptyOrSpaces(cp)) {
        params.getProgramParametersList().add("--classpath");
        params.getProgramParametersList().add(cp);
    }
}
Also used : PathsList(com.intellij.util.PathsList)

Example 18 with PathsList

use of com.intellij.util.PathsList in project intellij-community by JetBrains.

the class TestObject method createJavaParameters.

@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
    JavaParameters javaParameters = super.createJavaParameters();
    javaParameters.setMainClass(JUnitConfiguration.JUNIT_START_CLASS);
    javaParameters.getProgramParametersList().add(JUnitStarter.IDE_VERSION + JUnitStarter.VERSION);
    final StringBuilder buf = new StringBuilder();
    collectListeners(javaParameters, buf, IDEAJUnitListener.EP_NAME, "\n");
    if (buf.length() > 0) {
        try {
            myListenersFile = FileUtil.createTempFile("junit_listeners_", "", true);
            javaParameters.getProgramParametersList().add("@@" + myListenersFile.getPath());
            FileUtil.writeToFile(myListenersFile, buf.toString().getBytes(CharsetToolkit.UTF8_CHARSET));
        } catch (IOException e) {
            LOG.error(e);
        }
    }
    final Project project = getConfiguration().getProject();
    final SourceScope sourceScope = getSourceScope();
    if (isJUnit5(getConfiguration().getConfigurationModule().getModule(), sourceScope, project)) {
        javaParameters.getProgramParametersList().add(JUnitStarter.JUNIT5_PARAMETER);
        javaParameters.getClassPath().add(PathUtil.getJarPathForClass(JUnit5IdeaTestRunner.class));
        final PathsList classPath = javaParameters.getClassPath();
        classPath.add(PathUtil.getJarPathForClass(TestExecutionListener.class));
        classPath.add(PathUtil.getJarPathForClass(JupiterTestEngine.class));
        classPath.add(PathUtil.getJarPathForClass(JUnitException.class));
        classPath.add(PathUtil.getJarPathForClass(TestEngine.class));
        classPath.add(PathUtil.getJarPathForClass(JUnitPlatform.class));
        try {
            JUnitUtil.getTestCaseClass(sourceScope);
            classPath.add(PathUtil.getJarPathForClass(VintageTestEngine.class));
        } catch (JUnitUtil.NoJUnitException ignore) {
        }
    }
    return javaParameters;
}
Also used : JupiterTestEngine(org.junit.jupiter.engine.JupiterTestEngine) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) JUnitException(org.junit.platform.commons.JUnitException) JUnit5IdeaTestRunner(com.intellij.junit5.JUnit5IdeaTestRunner) IOException(java.io.IOException) VintageTestEngine(org.junit.vintage.engine.VintageTestEngine) Project(com.intellij.openapi.project.Project) SourceScope(com.intellij.execution.testframework.SourceScope) PathsList(com.intellij.util.PathsList) JavaParameters(com.intellij.execution.configurations.JavaParameters) TestEngine(org.junit.platform.engine.TestEngine) JupiterTestEngine(org.junit.jupiter.engine.JupiterTestEngine) VintageTestEngine(org.junit.vintage.engine.VintageTestEngine) JUnitPlatform(org.junit.platform.runner.JUnitPlatform)

Example 19 with PathsList

use of com.intellij.util.PathsList in project android by JetBrains.

the class AndroidDxWrapper method execute.

@SuppressWarnings({ "IOResourceOpenedButNotSafelyClosed" })
public static Map<AndroidCompilerMessageKind, List<String>> execute(@NotNull Module module, @NotNull IAndroidTarget target, @NotNull String outputDir, @NotNull String[] compileTargets, @NotNull String additionalVmParams, int maxHeapSize, boolean optimize) {
    BuildToolInfo buildToolInfo = target.getBuildToolInfo();
    if (buildToolInfo == null) {
        return Collections.singletonMap(AndroidCompilerMessageKind.ERROR, Collections.singletonList("No Build Tools in the Android SDK."));
    }
    String outFile = outputDir + File.separatorChar + AndroidCommonUtils.CLASSES_FILE_NAME;
    final Map<AndroidCompilerMessageKind, List<String>> messages = new HashMap<AndroidCompilerMessageKind, List<String>>(2);
    messages.put(AndroidCompilerMessageKind.ERROR, new ArrayList<String>());
    messages.put(AndroidCompilerMessageKind.INFORMATION, new ArrayList<String>());
    messages.put(AndroidCompilerMessageKind.WARNING, new ArrayList<String>());
    String dxJarPath = buildToolInfo.getPath(BuildToolInfo.PathId.DX_JAR);
    File dxJar = new File(dxJarPath);
    if (!dxJar.isFile()) {
        messages.get(AndroidCompilerMessageKind.ERROR).add(AndroidBundle.message("android.file.not.exist.error", dxJarPath));
        return messages;
    }
    JavaParameters parameters = new JavaParameters();
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    // dex runs after simple java compilation, so JDK must be specified
    assert sdk != null;
    parameters.setJdk(sdk);
    parameters.setMainClass(AndroidDxRunner.class.getName());
    ParametersList programParamList = parameters.getProgramParametersList();
    programParamList.add(dxJarPath);
    programParamList.add(outFile);
    programParamList.add("--optimize", Boolean.toString(optimize));
    programParamList.addAll(compileTargets);
    programParamList.add("--exclude");
    ParametersList vmParamList = parameters.getVMParametersList();
    if (additionalVmParams.length() > 0) {
        vmParamList.addParametersString(additionalVmParams);
    }
    if (!AndroidCommonUtils.hasXmxParam(vmParamList.getParameters())) {
        vmParamList.add("-Xmx" + maxHeapSize + "M");
    }
    final PathsList classPath = parameters.getClassPath();
    classPath.add(PathUtil.getJarPathForClass(AndroidDxRunner.class));
    classPath.add(PathUtil.getJarPathForClass(FileUtilRt.class));
    // delete file to check if it will exist after dex compilation
    if (!new File(outFile).delete()) {
        LOG.info("Cannot delete file " + outFile);
    }
    Process process;
    try {
        parameters.setUseDynamicClasspath(true);
        GeneralCommandLine commandLine = parameters.toCommandLine();
        LOG.info(commandLine.getCommandLineString());
        process = commandLine.createProcess();
        AndroidCommonUtils.handleDexCompilationResult(process, commandLine.getCommandLineString(), outFile, messages, false);
    } catch (ExecutionException e) {
        messages.get(AndroidCompilerMessageKind.ERROR).add("ExecutionException: " + e.getMessage());
        LOG.info(e);
        return messages;
    }
    return messages;
}
Also used : BuildToolInfo(com.android.sdklib.BuildToolInfo) HashMap(com.intellij.util.containers.HashMap) AndroidCompilerMessageKind(org.jetbrains.android.util.AndroidCompilerMessageKind) PathsList(com.intellij.util.PathsList) PathsList(com.intellij.util.PathsList) ArrayList(java.util.ArrayList) List(java.util.List) FileUtilRt(com.intellij.openapi.util.io.FileUtilRt) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File)

Example 20 with PathsList

use of com.intellij.util.PathsList in project android by JetBrains.

the class AndroidJunitPatcherTest method testMultipleMockableJars_oldModel.

public void testMultipleMockableJars_oldModel() throws Exception {
    String jar22 = myRoot + "lib1/build/intermediates/mockable-android-22.jar";
    String jar15 = myRoot + "lib2/build/intermediates/mockable-android-15.jar";
    PathsList classPath = myJavaParameters.getClassPath();
    classPath.addFirst(jar22);
    classPath.addFirst(jar15);
    myPatcher.patchJavaParameters(myModule, myJavaParameters);
    List<String> pathList = classPath.getPathList();
    assertEquals(myMockableAndroidJar, Iterables.getLast(pathList));
    assertThat(pathList).containsNoneOf(jar15, jar22);
}
Also used : PathsList(com.intellij.util.PathsList)

Aggregations

PathsList (com.intellij.util.PathsList)20 Test (org.junit.Test)6 File (java.io.File)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 ExecutionException (com.intellij.execution.ExecutionException)2 JavaParameters (com.intellij.execution.configurations.JavaParameters)2 Module (com.intellij.openapi.module.Module)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 IOException (java.io.IOException)2 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)2 AndroidProject (com.android.builder.model.AndroidProject)1 JavaArtifact (com.android.builder.model.JavaArtifact)1 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)1 Revision (com.android.repository.Revision)1 BuildToolInfo (com.android.sdklib.BuildToolInfo)1 AndroidGradleSettings (com.android.tools.idea.gradle.util.AndroidGradleSettings)1 PsiClassWriter (com.intellij.compiler.PsiClassWriter)1 FileSetCompileScope (com.intellij.compiler.impl.FileSetCompileScope)1 InstrumentationClassFinder (com.intellij.compiler.instrumentation.InstrumentationClassFinder)1