Search in sources :

Example 1 with TargetTypeProvider

use of org.gradle.tooling.internal.adapter.TargetTypeProvider in project intellij-community by JetBrains.

the class ProjectImportAction method configureAdditionalTypes.

private static void configureAdditionalTypes(BuildController controller) {
    try {
        Field adapterField = controller.getClass().getDeclaredField("adapter");
        adapterField.setAccessible(true);
        ProtocolToModelAdapter adapter = (ProtocolToModelAdapter) adapterField.get(controller);
        Field typeProviderField = adapter.getClass().getDeclaredField("targetTypeProvider");
        typeProviderField.setAccessible(true);
        TargetTypeProvider typeProvider = (TargetTypeProvider) typeProviderField.get(adapter);
        Field targetTypesField = typeProvider.getClass().getDeclaredField("configuredTargetTypes");
        targetTypesField.setAccessible(true);
        //noinspection unchecked
        Map<String, Class<?>> targetTypes = (Map<String, Class<?>>) targetTypesField.get(typeProvider);
        targetTypes.put(ExternalProjectDependency.class.getCanonicalName(), ExternalProjectDependency.class);
        targetTypes.put(ExternalLibraryDependency.class.getCanonicalName(), ExternalLibraryDependency.class);
        targetTypes.put(FileCollectionDependency.class.getCanonicalName(), FileCollectionDependency.class);
        targetTypes.put(UnresolvedExternalDependency.class.getCanonicalName(), UnresolvedExternalDependency.class);
    } catch (Exception ignore) {
    // TODO handle error
    }
}
Also used : Field(java.lang.reflect.Field) ProtocolToModelAdapter(org.gradle.tooling.internal.adapter.ProtocolToModelAdapter) TargetTypeProvider(org.gradle.tooling.internal.adapter.TargetTypeProvider) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException)

Aggregations

ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)1 Field (java.lang.reflect.Field)1 ProtocolToModelAdapter (org.gradle.tooling.internal.adapter.ProtocolToModelAdapter)1 TargetTypeProvider (org.gradle.tooling.internal.adapter.TargetTypeProvider)1