Search in sources :

Example 6 with UnsupportedMethodException

use of org.gradle.tooling.model.UnsupportedMethodException in project android by JetBrains.

the class AndroidJunitPatcher method handleJavaResources.

/**
   * Puts folders with merged java resources for the selected variant of every module on the classpath.
   *
   * <p>The problem we're solving here is that CompilerModuleExtension supports only one directory for "compiler output". When IJ compiles
   * Java projects, it copies resources to the output classes dir. This is something our Gradle plugin doesn't do, so we need to add the
   * resource directories to the classpath here.
   *
   * <p>We need to do this for every project dependency as well, since we're using classes and resources directories of these directly.
   *
   * @see <a href="http://b.android.com/172409">Bug 172409</a>
   */
private static void handleJavaResources(@NotNull Module module, @NotNull AndroidModuleModel androidModel, @NotNull PathsList classPath) {
    CompilerManager compilerManager = CompilerManager.getInstance(module.getProject());
    CompileScope scope = compilerManager.createModulesCompileScope(new Module[] { module }, true, true);
    // The only test resources we want to use, are the ones from the module where the test is. They should go first, before main resources.
    JavaArtifact testArtifact = androidModel.getUnitTestArtifactInSelectedVariant();
    if (testArtifact != null) {
        try {
            classPath.add(testArtifact.getJavaResourcesFolder());
        } catch (UnsupportedMethodException ignored) {
        // Java resources were not present in older versions of the gradle plugin.
        }
    }
    FileRootSearchScope excludeScope = null;
    TestArtifactSearchScopes testScopes = TestArtifactSearchScopes.get(module);
    if (testScopes != null) {
        excludeScope = testScopes.getUnitTestExcludeScope();
    }
    for (Module affectedModule : scope.getAffectedModules()) {
        AndroidFacet facet = AndroidFacet.getInstance(affectedModule);
        if (facet != null) {
            AndroidModuleModel affectedAndroidModel = AndroidModuleModel.get(facet);
            if (affectedAndroidModel != null) {
                try {
                    File resourceFolder = affectedAndroidModel.getMainArtifact().getJavaResourcesFolder();
                    if (excludeScope != null && excludeScope.accept(resourceFolder)) {
                        continue;
                    }
                    classPath.add(resourceFolder);
                } catch (UnsupportedMethodException ignored) {
                // Java resources were not present in older versions of the gradle plugin.
                }
            }
        }
    }
}
Also used : CompileScope(com.intellij.openapi.compiler.CompileScope) JavaArtifact(com.android.builder.model.JavaArtifact) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) CompilerManager(com.intellij.openapi.compiler.CompilerManager) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) File(java.io.File) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 7 with UnsupportedMethodException

use of org.gradle.tooling.model.UnsupportedMethodException in project android by JetBrains.

the class GradleUtilTest method getGeneratedSourcesWithOldModel.

@Test
public void getGeneratedSourcesWithOldModel() {
    BaseArtifact baseArtifact = mock(BaseArtifact.class);
    when(baseArtifact.getGeneratedSourceFolders()).thenThrow(new UnsupportedMethodException(""));
    Collection<File> actual = GradleUtil.getGeneratedSourceFolders(baseArtifact);
    assertThat(actual).isEmpty();
}
Also used : UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) BaseArtifact(com.android.builder.model.BaseArtifact) File(java.io.File) Test(org.junit.Test)

Example 8 with UnsupportedMethodException

use of org.gradle.tooling.model.UnsupportedMethodException in project android by JetBrains.

the class ProxyUtilTest method assertProxyEquals.

private static void assertProxyEquals(MyInterface expected, MyInterface actual) {
    assertEquals(expected.getString(), actual.getString());
    assertEquals(expected.getFile(), actual.getFile());
    assertEquals(expected.getNativeBoolean(), actual.getNativeBoolean());
    assertEquals(expected.getStringCollection(), actual.getStringCollection());
    assertEquals(expected.getBooleanList(), actual.getBooleanList());
    assertEquals(expected.getStringSet(), actual.getStringSet());
    assertProxyCollectionEquals(expected.getProxyCollection(), actual.getProxyCollection());
    assertProxyCollectionEquals(expected.getProxyList(), actual.getProxyList());
    assertProxyCollectionEquals(expected.getMapToProxy(), actual.getMapToProxy());
    UnsupportedMethodException exception = null;
    try {
        expected.doesNotExist();
        fail("Original method should throw.");
    } catch (UnsupportedMethodException e) {
        // Expected.
        exception = e;
    }
    try {
        actual.doesNotExist();
        fail("Reproxy should also throw.");
    } catch (UnsupportedMethodException e) {
        assertEquals(e.getClass(), exception.getClass());
        assertEquals(e.getMessage(), exception.getMessage());
    }
}
Also used : UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException)

Example 9 with UnsupportedMethodException

use of org.gradle.tooling.model.UnsupportedMethodException in project intellij-community by JetBrains.

the class BaseGradleProjectResolverExtension method populateModuleCompileOutputSettings.

@Override
public void populateModuleCompileOutputSettings(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule) {
    ExternalProject externalProject = resolverCtx.getExtraProject(gradleModule, ExternalProject.class);
    if (resolverCtx.isResolveModulePerSourceSet() && externalProject != null) {
        DataNode<ProjectData> projectDataNode = ideModule.getDataNode(ProjectKeys.PROJECT);
        assert projectDataNode != null;
        final Map<String, Pair<String, ExternalSystemSourceType>> moduleOutputsMap = projectDataNode.getUserData(MODULES_OUTPUTS);
        assert moduleOutputsMap != null;
        processSourceSets(resolverCtx, gradleModule, externalProject, ideModule, new SourceSetsProcessor() {

            @Override
            public void process(@NotNull DataNode<? extends ModuleData> dataNode, @NotNull ExternalSourceSet sourceSet) {
                for (Map.Entry<IExternalSystemSourceType, ExternalSourceDirectorySet> directorySetEntry : sourceSet.getSources().entrySet()) {
                    ExternalSystemSourceType sourceType = ExternalSystemSourceType.from(directorySetEntry.getKey());
                    ExternalSourceDirectorySet sourceDirectorySet = directorySetEntry.getValue();
                    final ModuleData moduleData = dataNode.getData();
                    File outputDir = sourceDirectorySet.getOutputDir();
                    moduleData.setCompileOutputPath(sourceType, outputDir.getAbsolutePath());
                    moduleData.setInheritProjectCompileOutputPath(sourceDirectorySet.isCompilerOutputPathInherited());
                    File gradleOutputDir = sourceDirectorySet.getGradleOutputDir();
                    String gradleOutputPath = moduleData.getCompileOutputPath(sourceType);
                    if (!gradleOutputDir.getPath().equals(outputDir.getPath())) {
                        gradleOutputPath = ExternalSystemApiUtil.toCanonicalPath(gradleOutputDir.getAbsolutePath());
                        moduleOutputsMap.put(gradleOutputPath, Pair.create(moduleData.getId(), sourceType));
                    }
                    Map<ExternalSystemSourceType, String> map = dataNode.getUserData(GradleProjectResolver.GRADLE_OUTPUTS);
                    if (map == null) {
                        map = ContainerUtil.newHashMap();
                        dataNode.putUserData(GradleProjectResolver.GRADLE_OUTPUTS, map);
                    }
                    map.put(sourceType, gradleOutputPath);
                }
            }
        });
        return;
    }
    IdeaCompilerOutput moduleCompilerOutput = gradleModule.getCompilerOutput();
    File buildDir = null;
    try {
        buildDir = gradleModule.getGradleProject().getBuildDirectory();
    } catch (UnsupportedMethodException ignore) {
    // see org.gradle.tooling.model.GradleProject.getBuildDirectory method supported only since Gradle 2.0
    // will use com.intellij.openapi.externalSystem.model.ExternalProject.getBuildDir() instead
    }
    Map<ExternalSystemSourceType, File> compileOutputPaths = ContainerUtil.newHashMap();
    boolean inheritOutputDirs = moduleCompilerOutput != null && moduleCompilerOutput.getInheritOutputDirs();
    ModuleData moduleData = ideModule.getData();
    if (moduleCompilerOutput != null) {
        File classesOutputDir = selectCompileOutputDir(moduleCompilerOutput.getOutputDir(), externalProject, "classes/main");
        compileOutputPaths.put(ExternalSystemSourceType.SOURCE, classesOutputDir);
        File resourcesOutputDir = selectCompileOutputDir(moduleCompilerOutput.getOutputDir(), externalProject, "resources/main");
        compileOutputPaths.put(ExternalSystemSourceType.RESOURCE, resourcesOutputDir);
        File testClassesOuputDir = selectCompileOutputDir(moduleCompilerOutput.getTestOutputDir(), externalProject, "classes/test");
        compileOutputPaths.put(ExternalSystemSourceType.TEST, testClassesOuputDir);
        File testResourcesOutputDir = selectCompileOutputDir(moduleCompilerOutput.getTestOutputDir(), externalProject, "resources/test");
        compileOutputPaths.put(ExternalSystemSourceType.TEST_RESOURCE, testResourcesOutputDir);
    }
    for (Map.Entry<ExternalSystemSourceType, File> sourceTypeFileEntry : compileOutputPaths.entrySet()) {
        final File outputPath = ObjectUtils.chooseNotNull(sourceTypeFileEntry.getValue(), buildDir);
        if (outputPath != null) {
            moduleData.setCompileOutputPath(sourceTypeFileEntry.getKey(), outputPath.getAbsolutePath());
        }
    }
    moduleData.setInheritProjectCompileOutputPath(inheritOutputDirs);
}
Also used : UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) File(java.io.File) JavaProjectData(com.intellij.externalSystem.JavaProjectData) Pair(com.intellij.openapi.util.Pair)

Example 10 with UnsupportedMethodException

use of org.gradle.tooling.model.UnsupportedMethodException in project meghanada-server by mopemope.

the class GradleProject method setCompileTarget.

private void setCompileTarget(final IdeaProject ideaProject) {
    final IdeaJavaLanguageSettings javaLanguageSettings = ideaProject.getJavaLanguageSettings();
    try {
        final String srcLevel = javaLanguageSettings.getLanguageLevel().toString();
        final String targetLevel = javaLanguageSettings.getTargetBytecodeVersion().toString();
        super.compileSource = srcLevel;
        super.compileTarget = targetLevel;
    } catch (UnsupportedMethodException e) {
        log.warn(e.getMessage());
    }
}
Also used : IdeaJavaLanguageSettings(org.gradle.tooling.model.idea.IdeaJavaLanguageSettings) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException)

Aggregations

UnsupportedMethodException (org.gradle.tooling.model.UnsupportedMethodException)10 File (java.io.File)5 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 JavaProjectData (com.intellij.externalSystem.JavaProjectData)2 Pair (com.intellij.openapi.util.Pair)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (com.android.annotations.Nullable)1 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 BaseArtifact (com.android.builder.model.BaseArtifact)1 JavaArtifact (com.android.builder.model.JavaArtifact)1 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)1 WrapperInvocationHandler (com.android.tools.idea.gradle.util.ProxyUtil.WrapperInvocationHandler)1 CompileScope (com.intellij.openapi.compiler.CompileScope)1 CompilerManager (com.intellij.openapi.compiler.CompilerManager)1 Module (com.intellij.openapi.module.Module)1 TIntObjectHashMap (gnu.trove.TIntObjectHashMap)1 TObjectIntHashMap (gnu.trove.TObjectIntHashMap)1 IdeaJavaLanguageSettings (org.gradle.tooling.model.idea.IdeaJavaLanguageSettings)1 GradleSourceSetData (org.jetbrains.plugins.gradle.model.data.GradleSourceSetData)1