import org.sonar.server.v2.api.user.controller.UserController;
import org.sonar.server.v2.api.user.converter.UsersSearchRestResponseGenerator;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import(CommonWebConfig.class)
-@ComponentScan("com.sonar.github.provisioning.permissions.web.config")
public class PlatformLevel4WebConfig {
@Bean
AnnotationConfigWebApplicationContext springMvcContext = new AnnotationConfigWebApplicationContext();
springMvcContext.setParent(platformLevel.getContainer().context());
springMvcContext.register(configClass);
+ if (PlatformLevel4WebConfig.class.equals(configClass)) {
+ platformLevel.getContainer().getWebApiV2ConfigurationClasses().forEach(springMvcContext::register);
+ }
+
DispatcherServlet dispatcher = servletProvider.apply(springMvcContext);
try {
if (config != null) {
addExtensions(asList(otherComponents));
return this;
}
+
+ void addWebApiV2ConfigurationClass(Class<?> clazz);
}
void load(Context context);
return this;
}
+ @Override
+ public void addWebApiV2ConfigurationClass(Class<?> clazz) {
+ container.addWebApiV2ConfigurationClass(clazz);
+ }
+
@Override
public <T> CoreExtension.Context addExtensions(Collection<T> components) {
requireNonNull(components, "components can't be null");
*/
package org.sonar.core.platform;
+import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
ExtensionContainer declareExtension(@Nullable String defaultCategory, Object extension);
+ void addWebApiV2ConfigurationClass(Class<?> clazz);
+
+ Set<Class<?>> getWebApiV2ConfigurationClasses();
+
@CheckForNull
ExtensionContainer getParent();
}
import com.google.common.collect.Iterables;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
import javax.annotation.Nullable;
import static java.util.Collections.unmodifiableList;
*/
public class ListContainer implements ExtensionContainer {
private final List<Object> objects = new ArrayList<>();
+ private final Set<Class<?>> webConfigurationClasses = new HashSet<>();
@Override
public Container add(Object... objects) {
return this;
}
+ @Override
+ public void addWebApiV2ConfigurationClass(Class<?> clazz) {
+ webConfigurationClasses.add(clazz);
+ }
+
+ @Override
+ public Set<Class<?>> getWebApiV2ConfigurationClasses() {
+ return webConfigurationClasses;
+ }
+
@Override
public ExtensionContainer getParent() {
throw new UnsupportedOperationException();
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
import java.util.function.Supplier;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@Nullable
protected final SpringComponentContainer parent;
protected final List<SpringComponentContainer> children = new ArrayList<>();
+ private final Set<Class<?>> webConfigurationClasses = new HashSet<>();
private final PropertyDefinitions propertyDefinitions;
private final ComponentKeys componentKeys = new ComponentKeys();
return this;
}
+ @Override
+ public void addWebApiV2ConfigurationClass(Class<?> clazz) {
+ webConfigurationClasses.add(clazz);
+ }
+
+ @Override
+ public Set<Class<?>> getWebApiV2ConfigurationClasses() {
+ return Set.copyOf(webConfigurationClasses);
+ }
+
private <T> void registerInstance(T instance) {
Supplier<T> supplier = () -> instance;
Class<T> clazz = (Class<T>) instance.getClass();
assertThatThrownBy(container::getParent).isInstanceOf(UnsupportedOperationException.class);
}
+ @Test
+ public void addWebApiV2ConfigurationClass_whenClassIsAdded_isReturnedByGetWebApiV2ConfigurationClasses() {
+ ListContainer container = new ListContainer();
+ container.addWebApiV2ConfigurationClass(org.sonar.core.test.Test.class);
+ assertThat(container.getWebApiV2ConfigurationClasses()).containsOnly(org.sonar.core.test.Test.class);
+ }
+
class A {
}
assertThat(container.getComponentByType(B.class)).isNotNull();
}
+ @Test
+ public void addWebConfigurationClass_addsClass() {
+ SpringComponentContainer container = new SpringComponentContainer();
+ container.addWebApiV2ConfigurationClass(org.sonar.core.test.Test.class);
+ assertThat(container.getWebApiV2ConfigurationClasses()).contains(org.sonar.core.test.Test.class);
+ }
+
@Test
public void add_configures_module_instances() {
SpringComponentContainer container = new SpringComponentContainer();