ComponentDeclaration componentDeclaration; if (chunks.length > 1) { componentDeclaration = new ComponentDeclaration(chunks[1], Integer.parseInt(chunks[0])); } else { componentDeclaration = new ComponentDeclaration(chunks[0]); componentDeclaration.getImplementationClassName(), componentDeclaration.getPriority()); annotatedClassNames.add(componentDeclaration); } catch (Exception e) {
@Override public int hashCode() { return new HashCodeBuilder(5, 45).append(getImplementationClassName()).append(getPriority()).toHashCode(); }
componentDeclarations.add(new ComponentDeclaration(componentOverrideDeclaration .getImplementationClassName(), 0));
/** Used so that AllTests can set the persistent test context. */ public static void initializeSystem(PersistentTestContext context) throws Exception { AbstractTest.setContext(context); BaseElement.setContext(context); TestUtils.setContext(context); AbstractTest.componentManager = new EmbeddableComponentManager(); // Only load the minimal number of components required for the test framework, for both performance reasons // and for avoiding having to declare dependencies such as HttpServletRequest. ComponentAnnotationLoader loader = new ComponentAnnotationLoader(); List<ComponentDeclaration> componentDeclarations = new ArrayList<>(); componentDeclarations.add(new ComponentDeclaration(DefaultStringEntityReferenceResolver.class.getName())); componentDeclarations.add(new ComponentDeclaration(DefaultStringEntityReferenceSerializer.class.getName())); componentDeclarations.add(new ComponentDeclaration(RelativeStringEntityReferenceResolver.class.getName())); componentDeclarations.add(new ComponentDeclaration(DefaultEntityReferenceProvider.class.getName())); componentDeclarations.add(new ComponentDeclaration(DefaultModelConfiguration.class.getName())); componentDeclarations.add(new ComponentDeclaration(DefaultSymbolScheme.class.getName())); loader.initialize(AbstractTest.componentManager, AbstractTest.class.getClassLoader(), componentDeclarations); TestUtils.initializeComponent(AbstractTest.componentManager); }
Class<?> componentClass; try { componentClass = classLoader.loadClass(componentDeclaration.getImplementationClassName()); } catch (Exception e) { throw new RuntimeException( String.format("Failed to load component class [%s] for annotation parsing", componentDeclaration.getImplementationClassName()), e);
componentDeclarations.add(new ComponentDeclaration(componentOverrideDeclaration .getImplementationClassName(), 0));
/** * @param annotations the list of annotations to check * @param alreadyProcessedAnnotations the list of already processed annotation to avoid circular dependencies * @return the list of Component Declarations declared by any passed annotation annotated by {@link ComponentList} */ private List<ComponentDeclaration> getComponentDeclarationsFromAnnotation(Annotation[] annotations, List<Annotation> alreadyProcessedAnnotations) { Set<ComponentDeclaration> componentDeclarations = new LinkedHashSet<>(); for (Annotation annotation : annotations) { // Is the Annotation (or one of the Annotation annotating the Annotation) tagged with @ComponentList? // If so, then call the "value()" method to get the list of Component Declarations if (annotation instanceof ComponentList) { ComponentList componentListAnnotation = (ComponentList) annotation; for (Class<?> componentClass : componentListAnnotation.value()) { componentDeclarations.add(new ComponentDeclaration(componentClass.getName())); } } else { // Protection against Annotations that tag themselves with themselves like @Retention, @Documented, etc if (!alreadyProcessedAnnotations.contains(annotation)) { alreadyProcessedAnnotations.add(annotation); componentDeclarations.addAll(getComponentDeclarationsFromAnnotation( annotation.annotationType().getAnnotations(), alreadyProcessedAnnotations)); } } } return new ArrayList<>(componentDeclarations); }
@Override public boolean equals(Object object) { if (object == null) { return false; } if (object == this) { return true; } if (object.getClass() != getClass()) { return false; } ComponentDeclaration rhs = (ComponentDeclaration) object; return new EqualsBuilder().append(getImplementationClassName(), rhs.getImplementationClassName()) .append(getPriority(), rhs.getPriority()).isEquals(); }
Class<?> componentClass = null; try { componentClass = classLoader.loadClass(componentDeclaration.getImplementationClassName()); } catch (ClassNotFoundException e) { getLogger().warn("Can't find any existing component with class [{}]. Ignoring it.", componentDeclaration.getImplementationClassName()); } catch (Exception e) { getLogger().warn("Fail to load component implementation class [{}]. Ignoring it.", componentDeclaration.getImplementationClassName(), e);
/** * If the user has specified the {@link org.xwiki.test.annotation.AllComponents} annotation then all components * are lodaded; however this is not recommended since it slows down the execution time and makes the test less * controlled; we recommend instead to use the {@link ComponentList} annotation which only registers the component * implementation you pass to it; or even better don't use any annotation which means no component is registered * explicitly which should be the default since you're mocking all component dependencies with the * {@link MockingRequirement} annotation. */ private void registerComponents() { AllComponents allComponentsAnnotation = this.getClass().getAnnotation(AllComponents.class); if (allComponentsAnnotation != null) { this.loader.initialize(this.componentManager, getClass().getClassLoader()); } else { ComponentList componentListAnnotation = this.getClass().getAnnotation(ComponentList.class); if (componentListAnnotation != null) { List<ComponentDeclaration> componentDeclarations = new ArrayList<ComponentDeclaration>(); for (Class<?> componentClass : componentListAnnotation.value()) { componentDeclarations.add(new ComponentDeclaration(componentClass.getName())); } this.loader.initialize(this.componentManager, getClass().getClassLoader(), componentDeclarations); } } }
if (componentDeclaration.getPriority() < currentPriority) { priorityMap.put(roleHint, componentDeclaration.getPriority()); } else if (componentDeclaration.getPriority() == currentPriority) { if (warn) { + "[{}]. However, no action was taken since both components have the same priority " + "level of [{}].", new Object[] { componentDeclaration.getImplementationClassName(), roleHint, descriptorMap.get(roleHint).getImplementation().getName(), currentPriority }); "Ignored component [{}] since its priority level of [{}] is lower " + "than the currently registered component [{}] which has a priority of [{}]", new Object[] { componentDeclaration.getImplementationClassName(), componentDeclaration.getPriority(), currentPriority }); priorityMap.put(roleHint, componentDeclaration.getPriority());