public ReflectiveProcedureCompiler withoutNamingRestrictions() { return new ReflectiveProcedureCompiler( inputSignatureDeterminer, outputMappers, safeFieldInjections, allFieldInjections, log, typeMappers, config, name -> { // all ok } ); }
private Callables loadProcedures( URL jar, ClassLoader loader, Callables target ) throws IOException, KernelException { RawIterator<Class<?>,IOException> classes = listClassesIn( jar, loader ); while ( classes.hasNext() ) { Class<?> next = classes.next(); target.addAllProcedures( compiler.compileProcedure( next, null, false ) ); target.addAllFunctions( compiler.compileFunction( next ) ); target.addAllAggregationFunctions( compiler.compileAggregationFunction( next ) ); } return target; }
MethodHandle constructor = constructor( fcnDefinition ); QualifiedName funcName = extractName( fcnDefinition, method, valueName, definedName ); if ( config.isWhitelisted( funcName.toString() ) ) out.add( compileFunction( fcnDefinition, constructor, method, funcName ) );
/** * Register a new function defined with annotations on a java class. * @param func the function class */ public void registerBuiltInFunctions( Class<?> func ) throws KernelException { for ( CallableUserFunction function : compiler.withoutNamingRestrictions().compileFunction( func ) ) { register( function, false ); } }
@Test public void shouldNotLoadAnyProcedureIfConfigIsEmpty() throws Throwable { // Given ProcedureConfig config = new ProcedureConfig( Config.defaults( procedure_whitelist, "" ) ); Log log = mock(Log.class); ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, components, log, config ); // When List<CallableProcedure> proc = procedureCompiler.compileProcedure( SingleReadOnlyProcedure.class, null, false ); // Then verify( log ) .warn( "The procedure 'org.neo4j.kernel.impl.proc.listCoolPeople' is not on the whitelist and won't be loaded." ); assertThat( proc.isEmpty(), is(true) ); }
MethodHandle resultMethod = lookup.unreflect( result ); String description = description( method ); UserAggregationFunction function = method.getAnnotation( UserAggregationFunction.class ); String deprecated = deprecated( method, function::deprecatedBy, "Use of @UserAggregationFunction(deprecatedBy) without @Deprecated in " + funcName ); description = describeAndLogLoadFailure( funcName ); UserFunctionSignature signature = new UserFunctionSignature( funcName, inputSignature, valueConverter.type(), deprecated,
/** * Register a new internal procedure defined with annotations on a java class. * @param proc the procedure class * @param overrideCurrentImplementation set to true if procedures within this class should override older procedures with the same name * @param warning the warning the procedure should generate when called */ public void registerProcedure( Class<?> proc, boolean overrideCurrentImplementation, String warning ) throws KernelException { for ( CallableProcedure procedure : compiler.compileProcedure( proc, warning, true ) ) { register( procedure, overrideCurrentImplementation ); } }
MethodHandle constructor = constructor( fcnDefinition ); QualifiedName funcName = extractName( fcnDefinition, method, valueName, definedName ); out.add( compileAggregationFunction( fcnDefinition, constructor, method, funcName ) );
MethodHandle constructor = constructor( procDefinition ); QualifiedName procName = extractName( procDefinition, method, valueName, definedName ); out.add( compileProcedure( procDefinition, constructor, method, warning, fullAccess, procName ) );
ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, new ComponentRegistry(), log, ProcedureConfig.DEFAULT ); List<CallableUserFunction> funcs = procedureCompiler.compileFunction( FunctionWithDeprecation.class );
ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, new ComponentRegistry(), log, ProcedureConfig.DEFAULT ); List<CallableUserAggregationFunction> funcs = procedureCompiler.compileAggregationFunction( FunctionWithDeprecation.class );
/** * Register a new aggregation function defined with annotations on a java class. * @param func the function class */ public void registerAggregationFunction( Class<?> func, boolean overrideCurrentImplementation ) throws KernelException { for ( CallableUserAggregationFunction function : compiler.compileAggregationFunction( func ) ) { register( function, overrideCurrentImplementation ); } }
private List<CallableUserFunction> compile( Class<?> clazz ) throws KernelException { return procedureCompiler.compileFunction( clazz ); } }
@Test public void shouldNotLoadNoneWhiteListedProcedure() throws Throwable { // Given ProcedureConfig config = new ProcedureConfig( Config.defaults( procedure_whitelist, "org.neo4j.kernel.impl.proc.NOTlistCoolPeople" ) ); Log log = mock(Log.class); ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, components, log, config ); // When List<CallableProcedure> proc = procedureCompiler.compileProcedure( SingleReadOnlyProcedure.class, null, false ); // Then verify( log ) .warn( "The procedure 'org.neo4j.kernel.impl.proc.listCoolPeople' is not on the whitelist and won't be loaded." ); assertThat( proc.isEmpty(), is(true) ); }
Class<?> returnType = method.getReturnType(); TypeMappers.TypeChecker typeChecker = typeMappers.checkerFor( returnType ); String description = description( method ); UserFunction function = method.getAnnotation( UserFunction.class ); String deprecated = deprecated( method, function::deprecatedBy, "Use of @UserFunction(deprecatedBy) without @Deprecated in " + procName ); description = describeAndLogLoadFailure( procName ); UserFunctionSignature signature = new UserFunctionSignature( procName, inputSignature, typeChecker.type(), deprecated,
private List<CallableProcedure> compile( Class<?> clazz ) throws KernelException { return procedureCompiler.compileProcedure( clazz, null, true ); }
MethodHandle constructor = constructor( fcnDefinition ); QualifiedName funcName = extractName( fcnDefinition, method, valueName, definedName ); out.add( compileAggregationFunction( fcnDefinition, constructor, method, funcName ) );
MethodHandle constructor = constructor( procDefinition ); QualifiedName procName = extractName( procDefinition, method, valueName, definedName ); out.add( compileProcedure( procDefinition, constructor, method, warning, fullAccess, procName ) );
private List<CallableUserAggregationFunction> compile( Class<?> clazz ) throws KernelException { return procedureCompiler.compileAggregationFunction( clazz ); } }
/** * Register a new function defined with annotations on a java class. * @param func the function class */ public void registerFunction( Class<?> func, boolean overrideCurrentImplementation ) throws KernelException { for ( CallableUserFunction function : compiler.compileFunction( func ) ) { register( function, overrideCurrentImplementation ); } }