public DockerContainerObjectBuilder < T > withContainerObjectClass ( Class < T > containerObjectClass ) { if ( containerObjectClass == null ) { throw new IllegalArgumentException ( "container object class cannot be null" ) ; } this . containerObjectClass = containerObjectClass ; //First we check if this ContainerObject is defining a @CubeDockerFile in static method final List < Method > methodsWithCubeDockerFile = ReflectionUtil . getMethodsWithAnnotation ( containerObjectClass , CubeDockerFile . class ) ; if ( methodsWithCubeDockerFile . size ( ) > 1 ) { throw new IllegalArgumentException ( String . format ( "More than one %s annotation found and only one was expected. Methods where annotation was found are: %s" , CubeDockerFile . class . getSimpleName ( ) , methodsWithCubeDockerFile ) ) ; } classHasMethodWithCubeDockerFile = ! methodsWithCubeDockerFile . isEmpty ( ) ; classDefinesCubeDockerFile = containerObjectClass . isAnnotationPresent ( CubeDockerFile . class ) ; classDefinesImage = containerObjectClass . isAnnotationPresent ( Image . class ) ; if ( classHasMethodWithCubeDockerFile ) { methodWithCubeDockerFile = methodsWithCubeDockerFile . get ( 0 ) ; boolean isMethodStatic = Modifier . isStatic ( methodWithCubeDockerFile . getModifiers ( ) ) ; boolean methodHasNoArguments = methodWithCubeDockerFile . getParameterCount ( ) == 0 ; boolean methodReturnsAnArchive = Archive . class . isAssignableFrom ( methodWithCubeDockerFile . getReturnType ( ) ) ; if ( ! isMethodStatic || ! methodHasNoArguments || ! methodReturnsAnArchive ) { throw new IllegalArgumentException ( String . format ( "Method %s annotated with %s is expected to be static, no args and return %s." , methodWithCubeDockerFile , CubeDockerFile . class . getSimpleName ( ) , Archive . class . getSimpleName ( ) ) ) ; } } // User has defined @CubeDockerfile on the class and a method if ( classHasMethodWithCubeDockerFile && classDefinesCubeDockerFile ) { throw new IllegalArgumentException ( String . format ( "More than one %s annotation found and only one was expected. Both class and method %s has the annotation." , CubeDockerFile . class . getSimpleName ( ) , methodWithCubeDockerFile ) ) ; } // User has defined @CubeDockerfile and @Image if ( ( classHasMethodWithCubeDockerFile || classDefinesCubeDockerFile ) && classDefinesImage ) { throw new IllegalArgumentException ( String . format ( "Container Object %s has defined %s annotation and %s annotation together." , containerObjectClass . getSimpleName ( ) , Image . class . getSimpleName ( ) , CubeDockerFile . class . getSimpleName ( ) ) ) ; } // User has not defined either @CubeDockerfile or @Image if ( ! classDefinesCubeDockerFile && ! classDefinesImage && ! classHasMethodWithCubeDockerFile ) { throw new IllegalArgumentException ( String . format ( "Container Object %s is not annotated with either %s or %s annotations." , containerObjectClass . getName ( ) , CubeDockerFile . class . getSimpleName ( ) , Image . class . getSimpleName ( ) ) ) ; } return this ; }
Specifies the container object class to be instantiated