Search in sources :

Example 6 with PathsList

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

the class PathListBuilderTest method testAddFirstTwice.

@Test
public void testAddFirstTwice() {
    PathsList builder = new PathsList();
    builder.addFirst("b" + File.pathSeparatorChar + "b");
    builder.addFirst("a");
    assertThat(builder.getPathList()).containsExactly("a", "b");
}
Also used : PathsList(com.intellij.util.PathsList) Test(org.junit.Test)

Example 7 with PathsList

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

the class PathListBuilderTest method testDuplications.

@Test
public void testDuplications() {
    PathsList builder = new PathsList();
    builder.add("b");
    builder.add("b");
    builder.addFirst("a");
    builder.addFirst("a");
    builder.addTail("c");
    builder.addTail("c");
    assertThat(builder.getPathList()).containsExactly("a", "b", "c");
}
Also used : PathsList(com.intellij.util.PathsList) Test(org.junit.Test)

Example 8 with PathsList

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

the class AndroidJunitPatcher method patchJavaParameters.

@Override
public void patchJavaParameters(@Nullable Module module, @NotNull JavaParameters javaParameters) {
    // Only patch if the project is a Gradle project.
    if (module == null || !isBuildWithGradle(module.getProject())) {
        return;
    }
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    if (androidModel == null) {
        return;
    }
    // Modify the class path only if we're dealing with the unit test artifact.
    JavaArtifact testArtifact = androidModel.getUnitTestArtifactInSelectedVariant();
    if (testArtifact == null) {
        return;
    }
    PathsList classPath = javaParameters.getClassPath();
    TestArtifactSearchScopes testScopes = TestArtifactSearchScopes.get(module);
    if (testScopes == null) {
        return;
    }
    // Filter the library / module dependencies that are in android test
    FileRootSearchScope excludeScope = testScopes.getUnitTestExcludeScope();
    // complexity. TODO change the {@code PathList} API.
    for (String path : classPath.getPathList()) {
        if (excludeScope.accept(new File(path))) {
            classPath.remove(path);
        }
    }
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform == null) {
        return;
    }
    String originalClassPath = classPath.getPathsString();
    try {
        handlePlatformJar(classPath, platform, testArtifact);
        handleJavaResources(module, androidModel, classPath);
    } catch (RuntimeException e) {
        throw new RuntimeException(String.format("Error patching the JUnit class path. Original class path:%n%s", originalClassPath), e);
    }
}
Also used : JavaArtifact(com.android.builder.model.JavaArtifact) PathsList(com.intellij.util.PathsList) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) File(java.io.File)

Example 9 with PathsList

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

the class AndroidJunitPatcher method patchJavaParameters.

@Override
public void patchJavaParameters(@Nullable Module module, JavaParameters javaParameters) {
    if (module == null) {
        return;
    }
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    if (androidModel == null) {
        return;
    }
    // Modify the class path only if we're dealing with the unit test artifact.
    PathsList classPath = javaParameters.getClassPath();
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (sdk == null || !(sdk.getSdkType() instanceof AndroidSdkType)) {
        return;
    }
    SdkAdditionalData data = sdk.getSdkAdditionalData();
    if (!(data instanceof AndroidSdkAdditionalData)) {
        return;
    }
    AndroidPlatform platform = ((AndroidSdkAdditionalData) data).getAndroidPlatform();
    if (platform == null) {
        return;
    }
    classPath.remove(platform.getTarget().getPath(IAndroidTarget.ANDROID_JAR));
    // Move the mockable android jar to the end.
    String mockableJarPath = null;
    for (String path : classPath.getPathList()) {
        if (new File(FileUtil.toSystemDependentName(path)).getName().startsWith("mockable-android")) {
            // PathsList stores strings - use the one that's actually stored there.
            mockableJarPath = path;
            break;
        }
    }
    if (mockableJarPath != null) {
        classPath.remove(mockableJarPath);
        classPath.addTail(mockableJarPath);
    }
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) PathsList(com.intellij.util.PathsList) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidSdkType(org.jetbrains.android.sdk.AndroidSdkType) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData)

Example 10 with PathsList

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

the class GradleManager method enhanceRemoteProcessing.

@Override
public void enhanceRemoteProcessing(@NotNull SimpleJavaParameters parameters) throws ExecutionException {
    final Set<String> additionalEntries = ContainerUtilRt.newHashSet();
    for (GradleProjectResolverExtension extension : RESOLVER_EXTENSIONS.getValue()) {
        ContainerUtilRt.addIfNotNull(additionalEntries, PathUtil.getJarPathForClass(extension.getClass()));
        for (Class aClass : extension.getExtraProjectModelClasses()) {
            ContainerUtilRt.addIfNotNull(additionalEntries, PathUtil.getJarPathForClass(aClass));
        }
        extension.enhanceRemoteProcessing(parameters);
    }
    final PathsList classPath = parameters.getClassPath();
    for (String entry : additionalEntries) {
        classPath.add(entry);
    }
    parameters.getVMParametersList().addProperty(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY, GradleConstants.SYSTEM_ID.getId());
}
Also used : GradleProjectResolverExtension(org.jetbrains.plugins.gradle.service.project.GradleProjectResolverExtension) 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