/** * Cast the given type to a subtype of {@link Enum}. * @param enumType the enum type, never {@code null} * @return the given type as subtype of {@link Enum} * @throws IllegalArgumentException if the given type is not a subtype of {@link Enum} */ @SuppressWarnings("rawtypes") private static Class<? extends Enum> asEnumType(Class<?> enumType) { Assert.notNull(enumType, "Enum type must not be null"); if (!Enum.class.isAssignableFrom(enumType)) { throw new IllegalArgumentException("Supplied type is not an enum: " + enumType.getName()); } return enumType.asSubclass(Enum.class); }
public JUnit38ClassRunner(Class<?> klass) { this(new TestSuite(klass.asSubclass(TestCase.class))); }
@Override protected Boolean computeValue(Class<?> type) { checkExceptionClassValidity(type.asSubclass(Exception.class)); return true; } };
/** * Look up a class by name. * @param klass class name * @param base super class of the class for verification * @param <T> the type of the base class * @return the new class */ public static <T> Class<? extends T> loadClass(String klass, Class<T> base) throws ClassNotFoundException { return Class.forName(klass, true, Utils.getContextOrKafkaClassLoader()).asSubclass(base); }
private static AWSCredentialsProvider getCustomAWSCredentialsProvider(Configuration conf, String providerClass) { try { return conf.getClassByName(providerClass) .asSubclass(AWSCredentialsProvider.class) .getConstructor(URI.class, Configuration.class) .newInstance(null, conf); } catch (ReflectiveOperationException e) { throw new RuntimeException(format("Error creating an instance of %s", providerClass), e); } }
@Override protected Boolean computeValue(Class<?> type) { checkExceptionClassValidity(type.asSubclass(Exception.class)); return true; } };
@SuppressWarnings({"unchecked", "RedundantCast"}) private static Class<? extends InputFormat<?, ?>> getInputFormatClass(JobConf conf, String inputFormatName) throws ClassNotFoundException { // CDH uses different names for Parquet if ("parquet.hive.DeprecatedParquetInputFormat".equals(inputFormatName) || "parquet.hive.MapredParquetInputFormat".equals(inputFormatName)) { return MapredParquetInputFormat.class; } Class<?> clazz = conf.getClassByName(inputFormatName); return (Class<? extends InputFormat<?, ?>>) clazz.asSubclass(InputFormat.class); }
private Test testCaseForClass(Class<?> each) { if (TestCase.class.isAssignableFrom(each)) { return new TestSuite(each.asSubclass(TestCase.class)); } else { return warning(each.getCanonicalName() + " does not extend TestCase"); } }
private Test testCaseForClass(Class<?> each) { if (TestCase.class.isAssignableFrom(each)) { return new TestSuite(each.asSubclass(TestCase.class)); } else { return warning(each.getCanonicalName() + " does not extend TestCase"); } }
@Override public List<? extends ToolInstaller> getDefaultInstallers() { try { Class<? extends ToolInstaller> jdkInstallerClass = Jenkins.getInstance().getPluginManager() .uberClassLoader.loadClass("hudson.tools.JDKInstaller").asSubclass(ToolInstaller.class); Constructor<? extends ToolInstaller> constructor = jdkInstallerClass.getConstructor(String.class, boolean.class); return Collections.singletonList(constructor.newInstance(null, false)); } catch (ClassNotFoundException e) { return Collections.emptyList(); } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to get default installer", e); return Collections.emptyList(); } }
private static AWSCredentialsProvider getCustomAWSCredentialsProvider(URI uri, Configuration conf, String providerClass) { try { log.debug("Using AWS credential provider %s for URI %s", providerClass, uri); return conf.getClassByName(providerClass) .asSubclass(AWSCredentialsProvider.class) .getConstructor(URI.class, Configuration.class) .newInstance(uri, conf); } catch (ReflectiveOperationException e) { throw new RuntimeException(format("Error creating an instance of %s for URI %s", providerClass, uri), e); } }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { // read the parent fields and the final fields in.defaultReadObject(); try { Class<? extends Writable> writableSplit = splitType.asSubclass(Writable.class); mapreduceInputSplit = (org.apache.hadoop.mapreduce.InputSplit) WritableFactories.newInstance(writableSplit); } catch (Exception e) { throw new RuntimeException("Unable to instantiate the Hadoop InputSplit", e); } ((Writable) mapreduceInputSplit).readFields(in); } }
/** * @deprecated Use {@link #getAction(Class)} on {@code AbstractTestResultAction}. */ @Deprecated public Action getTestResultAction() { try { return getAction(Jenkins.getInstance().getPluginManager().uberClassLoader.loadClass("hudson.tasks.test.AbstractTestResultAction").asSubclass(Action.class)); } catch (ClassNotFoundException x) { return null; } }
/** * @deprecated Use {@link #getAction(Class)} on {@code AggregatedTestResultAction}. */ @Deprecated public Action getAggregatedTestResultAction() { try { return getAction(Jenkins.getInstance().getPluginManager().uberClassLoader.loadClass("hudson.tasks.test.AggregatedTestResultAction").asSubclass(Action.class)); } catch (ClassNotFoundException x) { return null; } }
private static <T> T newInstance(String className, Class<T> superType) throws ReflectiveOperationException { return HiveStorageFormat.class.getClassLoader().loadClass(className).asSubclass(superType).getConstructor().newInstance(); }
private static Constructor<? extends RecordWriter> getOrcWriterConstructor() { try { Constructor<? extends RecordWriter> constructor = OrcOutputFormat.class.getClassLoader() .loadClass(ORC_RECORD_WRITER) .asSubclass(RecordWriter.class) .getDeclaredConstructor(Path.class, WriterOptions.class); constructor.setAccessible(true); return constructor; } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } }
protected TestResult runSingleMethod(String testCase, String method, boolean wait) throws Exception { Class<? extends TestCase> testClass = loadSuiteClass(testCase).asSubclass(TestCase.class); Test test = TestSuite.createTest(testClass, method); return doRun(test, wait); }
static FilterFactory createFilterFactory(String filterFactoryFqcn) throws FilterNotCreatedException { Class<? extends FilterFactory> filterFactoryClass; try { filterFactoryClass = Classes.getClass(filterFactoryFqcn).asSubclass(FilterFactory.class); } catch (Exception e) { throw new FilterNotCreatedException(e); } return createFilterFactory(filterFactoryClass); }
protected TestResult runSingleMethod(String testCase, String method, boolean wait) throws Exception { Class<? extends TestCase> testClass = loadSuiteClass(testCase).asSubclass(TestCase.class); Test test = TestSuite.createTest(testClass, method); return doRun(test, wait); }
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { try { DescribableList r = (DescribableList) context.getRequiredType().asSubclass(DescribableList.class).newInstance(); CopyOnWriteList core = copyOnWriteListConverter.unmarshal(reader, context); r.data.replaceBy(core); return r; } catch (InstantiationException e) { InstantiationError x = new InstantiationError(); x.initCause(e); throw x; } catch (IllegalAccessException e) { IllegalAccessError x = new IllegalAccessError(); x.initCause(e); throw x; } } }