Java Code Examples for org.gradle.internal.reflect.ObjectInstantiationException

The following examples show how to use org.gradle.internal.reflect.ObjectInstantiationException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private TaskInternal createTaskObject(ProjectInternal project, final Class<? extends TaskInternal> type, String name, boolean generateGetters) {
    if (!Task.class.isAssignableFrom(type)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create task of type '%s' as it does not implement the Task interface.",
                type.getSimpleName()));
    }

    final Class<? extends TaskInternal> generatedType;
    if (generateGetters) {
        generatedType = generator.generate(type);
    } else {
        generatedType = type;
    }

    return AbstractTask.injectIntoNewInstance(project, name, new Callable<TaskInternal>() {
        public TaskInternal call() throws Exception {
            try {
                return instantiator.newInstance(generatedType);
            } catch (ObjectInstantiationException e) {
                throw new TaskInstantiationException(String.format("Could not create task of type '%s'.", type.getSimpleName()),
                        e.getCause());
            }
        }
    });
}
 
Example 2
private TaskInternal createTaskObject(ProjectInternal project, final Class<? extends TaskInternal> type, String name, boolean generateGetters) {
    if (!Task.class.isAssignableFrom(type)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create task of type '%s' as it does not implement the Task interface.",
                type.getSimpleName()));
    }

    final Class<? extends TaskInternal> generatedType;
    if (generateGetters) {
        generatedType = generator.generate(type);
    } else {
        generatedType = type;
    }

    return AbstractTask.injectIntoNewInstance(project, name, new Callable<TaskInternal>() {
        public TaskInternal call() throws Exception {
            try {
                return instantiator.newInstance(generatedType);
            } catch (ObjectInstantiationException e) {
                throw new TaskInstantiationException(String.format("Could not create task of type '%s'.", type.getSimpleName()),
                        e.getCause());
            }
        }
    });
}
 
Example 3
private TaskInternal createTaskObject(ProjectInternal project, final Class<? extends TaskInternal> type, String name, boolean generateGetters) {
    if (!Task.class.isAssignableFrom(type)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create task of type '%s' as it does not implement the Task interface.",
                type.getSimpleName()));
    }

    final Class<? extends TaskInternal> generatedType;
    if (generateGetters) {
        generatedType = generator.generate(type);
    } else {
        generatedType = type;
    }

    return AbstractTask.injectIntoNewInstance(project, name, new Callable<TaskInternal>() {
        public TaskInternal call() throws Exception {
            try {
                return instantiator.newInstance(generatedType);
            } catch (ObjectInstantiationException e) {
                throw new TaskInstantiationException(String.format("Could not create task of type '%s'.", type.getSimpleName()),
                        e.getCause());
            }
        }
    });
}
 
Example 4
private TaskInternal createTaskObject(ProjectInternal project, final Class<? extends TaskInternal> type, String name, boolean generateGetters) {
    if (!Task.class.isAssignableFrom(type)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create task of type '%s' as it does not implement the Task interface.",
                type.getSimpleName()));
    }

    final Class<? extends TaskInternal> generatedType;
    if (generateGetters) {
        generatedType = generator.generate(type);
    } else {
        generatedType = type;
    }

    return AbstractTask.injectIntoNewInstance(project, name, new Callable<TaskInternal>() {
        public TaskInternal call() throws Exception {
            try {
                return instantiator.newInstance(generatedType);
            } catch (ObjectInstantiationException e) {
                throw new TaskInstantiationException(String.format("Could not create task of type '%s'.", type.getSimpleName()),
                        e.getCause());
            }
        }
    });
}
 
Example 5
public static <T extends BaseBinarySpec> T create(Class<T> type, BinaryNamingScheme namingScheme, Instantiator instantiator) {
    if (type.equals(BaseBinarySpec.class)) {
        throw new ModelInstantiationException("Cannot create instance of abstract class BaseBinarySpec.");
    }
    nextBinaryInfo.set(new BinaryInfo(namingScheme, type.getSimpleName()));
    try {
        try {
            return instantiator.newInstance(type);
        } catch (ObjectInstantiationException e) {
            throw new ModelInstantiationException(String.format("Could not create binary of type %s", type.getSimpleName()), e.getCause());
        }
    } finally {
        nextBinaryInfo.set(null);
    }
}
 
Example 6
public static <T extends BaseComponentSpec> T create(Class<T> type, ComponentSpecIdentifier identifier, FunctionalSourceSet mainSourceSet, Instantiator instantiator) {
    if (type.equals(BaseComponentSpec.class)) {
        throw new ModelInstantiationException("Cannot create instance of abstract class BaseComponentSpec.");
    }
    nextComponentInfo.set(new ComponentInfo(identifier, type.getSimpleName(), mainSourceSet));
    try {
        try {
            return instantiator.newInstance(type);
        } catch (ObjectInstantiationException e) {
            throw new ModelInstantiationException(String.format("Could not create component of type %s", type.getSimpleName()), e.getCause());
        }
    } finally {
        nextComponentInfo.set(null);
    }
}
 
Example 7
public T newInstance(Object... params) {
    Instantiator instantiator = new DirectInstantiator();
    try {
        return instantiator.newInstance(implementationClass, params);
    } catch (ObjectInstantiationException t) {
        throw new RuntimeException(String.format("Could not create an implementation of service '%s'.", serviceType.getName()), t);
    }
}
 
Example 8
public <T extends Plugin<?>> T loadPlugin(Class<T> pluginClass) {
    if (!Plugin.class.isAssignableFrom(pluginClass)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create plugin of type '%s' as it does not implement the Plugin interface.",
                pluginClass.getSimpleName()));
    }
    try {
        return instantiator.newInstance(pluginClass);
    } catch (ObjectInstantiationException e) {
        throw new PluginInstantiationException(String.format("Could not create plugin of type '%s'.",
                pluginClass.getSimpleName()), e.getCause());
    }
}
 
Example 9
public T newInstance(Object... params) {
    Instantiator instantiator = new DirectInstantiator();
    try {
        return instantiator.newInstance(implementationClass, params);
    } catch (ObjectInstantiationException t) {
        throw new RuntimeException(String.format("Could not create an implementation of service '%s'.", serviceType.getName()), t);
    }
}
 
Example 10
public <T extends Plugin> T loadPlugin(Class<T> pluginClass) {
    if (!Plugin.class.isAssignableFrom(pluginClass)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create plugin of type '%s' as it does not implement the Plugin interface.",
                pluginClass.getSimpleName()));
    }
    try {
        return instantiator.newInstance(pluginClass);
    } catch (ObjectInstantiationException e) {
        throw new PluginInstantiationException(String.format("Could not create plugin of type '%s'.",
                pluginClass.getSimpleName()), e.getCause());
    }
}
 
Example 11
public static <T extends LanguageSourceSet> T create(Class<? extends LanguageSourceSet> publicType, Class<T> implementationType, ComponentSpecIdentifier componentId, SourceDirectorySetFactory sourceDirectorySetFactory) {
    NEXT_SOURCE_SET_INFO.set(new SourceSetInfo(componentId, publicType, sourceDirectorySetFactory));
    try {
        try {
            return DirectInstantiator.INSTANCE.newInstance(implementationType);
        } catch (ObjectInstantiationException e) {
            throw new ModelInstantiationException(String.format("Could not create LanguageSourceSet of type %s", publicType.getSimpleName()), e.getCause());
        }
    } finally {
        NEXT_SOURCE_SET_INFO.set(null);
    }
}
 
Example 12
public static <T extends BaseBinarySpec> T create(Class<T> type, BinaryNamingScheme namingScheme, Instantiator instantiator) {
    if (type.equals(BaseBinarySpec.class)) {
        throw new ModelInstantiationException("Cannot create instance of abstract class BaseBinarySpec.");
    }
    nextBinaryInfo.set(new BinaryInfo(namingScheme, type.getSimpleName()));
    try {
        try {
            return instantiator.newInstance(type);
        } catch (ObjectInstantiationException e) {
            throw new ModelInstantiationException(String.format("Could not create binary of type %s", type.getSimpleName()), e.getCause());
        }
    } finally {
        nextBinaryInfo.set(null);
    }
}
 
Example 13
public static <T extends BaseComponentSpec> T create(Class<T> type, ComponentSpecIdentifier identifier, FunctionalSourceSet mainSourceSet, Instantiator instantiator) {
    if (type.equals(BaseComponentSpec.class)) {
        throw new ModelInstantiationException("Cannot create instance of abstract class BaseComponentSpec.");
    }
    nextComponentInfo.set(new ComponentInfo(identifier, type.getSimpleName(), mainSourceSet));
    try {
        try {
            return instantiator.newInstance(type);
        } catch (ObjectInstantiationException e) {
            throw new ModelInstantiationException(String.format("Could not create component of type %s", type.getSimpleName()), e.getCause());
        }
    } finally {
        nextComponentInfo.set(null);
    }
}
 
Example 14
public T newInstance(Object... params) {
    Instantiator instantiator = new DirectInstantiator();
    try {
        return instantiator.newInstance(implementationClass, params);
    } catch (ObjectInstantiationException t) {
        throw new RuntimeException(String.format("Could not create an implementation of service '%s'.", serviceType.getName()), t);
    }
}
 
Example 15
public <T extends Plugin<?>> T loadPlugin(Class<T> pluginClass) {
    if (!Plugin.class.isAssignableFrom(pluginClass)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create plugin of type '%s' as it does not implement the Plugin interface.",
                pluginClass.getSimpleName()));
    }
    try {
        return instantiator.newInstance(pluginClass);
    } catch (ObjectInstantiationException e) {
        throw new PluginInstantiationException(String.format("Could not create plugin of type '%s'.",
                pluginClass.getSimpleName()), e.getCause());
    }
}
 
Example 16
public T newInstance(Object... params) {
    Instantiator instantiator = new DirectInstantiator();
    try {
        return instantiator.newInstance(implementationClass, params);
    } catch (ObjectInstantiationException t) {
        throw new RuntimeException(String.format("Could not create an implementation of service '%s'.", serviceType.getName()), t);
    }
}
 
Example 17
public <T extends Plugin> T loadPlugin(Class<T> pluginClass) {
    if (!Plugin.class.isAssignableFrom(pluginClass)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create plugin of type '%s' as it does not implement the Plugin interface.",
                pluginClass.getSimpleName()));
    }
    try {
        return instantiator.newInstance(pluginClass);
    } catch (ObjectInstantiationException e) {
        throw new PluginInstantiationException(String.format("Could not create plugin of type '%s'.",
                pluginClass.getSimpleName()), e.getCause());
    }
}