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.
}
}
}
}
}
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();
}
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());
}
}
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);
}
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());
}
}
Aggregations