use of org.gradle.tooling.model.UnsupportedMethodException in project android by JetBrains.
the class ProxyUtilTest method testNewMethod.
public void testNewMethod() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
MyInterface reproxy = reproxy(MyInterface.class, myProxy);
assertNotNull(reproxy);
InvocationHandler handler = Proxy.getInvocationHandler(reproxy);
assertTrue(handler instanceof WrapperInvocationHandler);
WrapperInvocationHandler wrapper = (WrapperInvocationHandler) handler;
Method m = MyInterface.class.getMethod("getString");
wrapper.values.remove(m.toGenericString());
try {
reproxy.getString();
fail("Removed method should throw an exception");
} catch (UnsupportedMethodException e) {
// Expected.
}
}
use of org.gradle.tooling.model.UnsupportedMethodException in project android by JetBrains.
the class ProxyUtilTest method testReproxyUnsupportedMethods.
public void testReproxyUnsupportedMethods() throws NoSuchMethodException {
MyInterface reproxyA = reproxy(MyInterface.class, myProxy);
assertNotNull(reproxyA);
MyInterface reproxyB = reproxy(MyInterface.class, myProxy);
assertNotNull(reproxyB);
UnsupportedMethodException expected = null;
try {
reproxyA.doesNotExist();
fail("Reproxy method should throw.");
} catch (UnsupportedMethodException e) {
// Expected.
expected = e;
}
try {
reproxyB.doesNotExist();
fail("Reproxy method should throw.");
} catch (UnsupportedMethodException e) {
// For reproxied objects, the UnsupportedMethodExceptions should be the same.
assertEquals(expected, e);
}
}
use of org.gradle.tooling.model.UnsupportedMethodException in project android by JetBrains.
the class AppResourceRepository method findAarLibrariesFromGradle.
/**
* Looks up the library dependencies from the Gradle tools model and returns the corresponding {@code .aar}
* resource directories.
*/
@NotNull
private static Map<File, String> findAarLibrariesFromGradle(@NotNull GradleVersion modelVersion, List<AndroidFacet> dependentFacets, List<AndroidLibrary> libraries) {
// Pull out the unique directories, in case multiple modules point to the same .aar folder
Map<File, String> files = new HashMap<>(libraries.size());
Set<String> moduleNames = Sets.newHashSet();
for (AndroidFacet f : dependentFacets) {
moduleNames.add(f.getModule().getName());
}
try {
for (AndroidLibrary library : libraries) {
// We should only add .aar dependencies if they aren't already provided as modules.
// For now, the way we associate them with each other is via the library name;
// in the future the model will provide this for us
String libraryName = null;
String projectName = library.getProject();
if (projectName != null && !projectName.isEmpty()) {
libraryName = projectName.substring(projectName.lastIndexOf(':') + 1);
// Since this library has project!=null, it exists in module form; don't
// add it here.
moduleNames.add(libraryName);
continue;
} else {
File folder = library.getFolder();
String name = folder.getName();
if (modelVersion.getMajor() > 2 || modelVersion.getMajor() == 2 && modelVersion.getMinor() >= 2) {
// Library.getName() was added in 2.2
libraryName = library.getName();
} else if (name.endsWith(DOT_AAR)) {
libraryName = name.substring(0, name.length() - DOT_AAR.length());
} else if (folder.getPath().contains(AndroidModuleModel.EXPLODED_AAR)) {
libraryName = folder.getParentFile().getName();
}
}
if (libraryName != null && !moduleNames.contains(libraryName)) {
File resFolder = library.getResFolder();
if (resFolder.exists()) {
files.put(resFolder, libraryName);
// Don't add it again!
moduleNames.add(libraryName);
}
}
}
} catch (UnsupportedMethodException e) {
// This happens when there is an incompatibility between the builder-model interfaces embedded in Android Studio and the
// cached model.
// If we got here is because this code got invoked before project sync happened (e.g. when reopening a project with open editors).
// Project sync now is smart enough to handle this case and will trigger a full sync.
LOG.warn("Incompatibility found between the IDE's builder-model and the cached Gradle model", e);
}
return files;
}
use of org.gradle.tooling.model.UnsupportedMethodException in project intellij-community by JetBrains.
the class BaseGradleProjectResolverExtension method createModule.
@NotNull
@Override
public DataNode<ModuleData> createModule(@NotNull IdeaModule gradleModule, @NotNull DataNode<ProjectData> projectDataNode) {
DataNode<ModuleData> mainModuleNode = createMainModule(resolverCtx, gradleModule, projectDataNode);
final ModuleData mainModuleData = mainModuleNode.getData();
final String mainModuleConfigPath = mainModuleData.getLinkedExternalProjectPath();
final String mainModuleFileDirectoryPath = mainModuleData.getModuleFileDirectoryPath();
ExternalProject externalProject = resolverCtx.getExtraProject(gradleModule, ExternalProject.class);
if (resolverCtx.isResolveModulePerSourceSet() && externalProject != null) {
String[] moduleGroup = null;
if (!ModuleGrouperKt.isQualifiedModuleNamesEnabled()) {
String gradlePath = gradleModule.getGradleProject().getPath();
final boolean isRootModule = StringUtil.isEmpty(gradlePath) || ":".equals(gradlePath);
moduleGroup = isRootModule ? new String[] { mainModuleData.getInternalName() } : ArrayUtil.remove(gradlePath.split(":"), 0);
mainModuleData.setIdeModuleGroup(isRootModule ? null : moduleGroup);
}
for (ExternalSourceSet sourceSet : externalProject.getSourceSets().values()) {
final String moduleId = getModuleId(resolverCtx, gradleModule, sourceSet);
final String moduleExternalName = gradleModule.getName() + ":" + sourceSet.getName();
final String moduleInternalName = getInternalModuleName(gradleModule, externalProject, sourceSet.getName());
GradleSourceSetData sourceSetData = new GradleSourceSetData(moduleId, moduleExternalName, moduleInternalName, mainModuleFileDirectoryPath, mainModuleConfigPath);
sourceSetData.setGroup(externalProject.getGroup());
sourceSetData.setVersion(externalProject.getVersion());
sourceSetData.setIdeModuleGroup(moduleGroup);
sourceSetData.setSourceCompatibility(sourceSet.getSourceCompatibility());
sourceSetData.setTargetCompatibility(sourceSet.getTargetCompatibility());
final Set<File> artifacts = ContainerUtil.newTroveSet(FileUtil.FILE_HASHING_STRATEGY);
if ("main".equals(sourceSet.getName())) {
final Set<File> defaultArtifacts = externalProject.getArtifactsByConfiguration().get("default");
if (defaultArtifacts != null) {
artifacts.addAll(defaultArtifacts);
}
if (externalProject.getArtifactsByConfiguration().get("archives") != null) {
final Set<File> archivesArtifacts = ContainerUtil.newHashSet(externalProject.getArtifactsByConfiguration().get("archives"));
final Set<File> testsArtifacts = externalProject.getArtifactsByConfiguration().get("tests");
if (testsArtifacts != null) {
archivesArtifacts.removeAll(testsArtifacts);
}
artifacts.addAll(archivesArtifacts);
}
} else {
if ("test".equals(sourceSet.getName())) {
sourceSetData.setProductionModuleId(getInternalModuleName(gradleModule, externalProject, "main"));
final Set<File> testsArtifacts = externalProject.getArtifactsByConfiguration().get("tests");
if (testsArtifacts != null) {
artifacts.addAll(testsArtifacts);
}
}
}
artifacts.addAll(sourceSet.getArtifacts());
sourceSetData.setArtifacts(ContainerUtil.newArrayList(artifacts));
DataNode<GradleSourceSetData> sourceSetDataNode = mainModuleNode.createChild(GradleSourceSetData.KEY, sourceSetData);
final Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap = projectDataNode.getUserData(GradleProjectResolver.RESOLVED_SOURCE_SETS);
assert sourceSetMap != null;
sourceSetMap.put(moduleId, Pair.create(sourceSetDataNode, sourceSet));
}
} else {
try {
IdeaJavaLanguageSettings languageSettings = gradleModule.getJavaLanguageSettings();
if (languageSettings != null) {
if (languageSettings.getLanguageLevel() != null) {
mainModuleData.setSourceCompatibility(languageSettings.getLanguageLevel().toString());
}
if (languageSettings.getTargetBytecodeVersion() != null) {
mainModuleData.setTargetCompatibility(languageSettings.getTargetBytecodeVersion().toString());
}
}
} catch (UnsupportedMethodException ignore) {
// org.gradle.tooling.model.idea.IdeaModule.getJavaLanguageSettings method supported since Gradle 2.11
}
}
final ProjectData projectData = projectDataNode.getData();
if (StringUtil.equals(mainModuleData.getLinkedExternalProjectPath(), projectData.getLinkedExternalProjectPath())) {
projectData.setGroup(mainModuleData.getGroup());
projectData.setVersion(mainModuleData.getVersion());
}
return mainModuleNode;
}
use of org.gradle.tooling.model.UnsupportedMethodException in project android by JetBrains.
the class AndroidPluginGeneration method find.
@Nullable
public static AndroidPluginGeneration find(@NotNull Module module) {
AndroidModuleModel gradleModel = AndroidModuleModel.get(module);
if (gradleModel != null) {
try {
// only true for experimental plugin 0.6.0-betaX (or whenever the getPluginGeneration() was added) or later.
return gradleModel.getAndroidProject().getPluginGeneration() == GENERATION_COMPONENT ? COMPONENT : ORIGINAL;
} catch (UnsupportedMethodException t) {
// happens for 2.0.0-alphaX or earlier stable version plugins and 0.6.0-alphax or earlier experimental plugin versions.
}
}
// Now look at the applied plugins in the build.gradle file.
GradleBuildModel buildModel = GradleBuildModel.get(module);
if (buildModel != null) {
List<String> appliedPlugins = getValues(buildModel.appliedPlugins());
for (AndroidPluginGeneration generation : ourValues) {
if (appliedPlugins.contains(generation.getApplicationPluginId()) || appliedPlugins.contains(generation.getLibraryPluginId())) {
return generation;
}
}
}
return null;
}
Aggregations