mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ACS-3594 Add mechanism to deprecate modules within the Repo (#1445)
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.module;
|
||||||
|
|
||||||
|
import static java.util.Optional.ofNullable;
|
||||||
|
import static java.util.function.Predicate.not;
|
||||||
|
import static java.util.stream.Collectors.joining;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.module.ModuleDetails;
|
||||||
|
import org.alfresco.service.cmr.module.ModuleService;
|
||||||
|
import org.springframework.extensions.surf.util.I18NUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Halts the bootstrap process if a deprecated module is present.
|
||||||
|
*
|
||||||
|
* @author Domenico Sibilio
|
||||||
|
* @since 7.3.0
|
||||||
|
*/
|
||||||
|
public class DeprecatedModulesValidator
|
||||||
|
{
|
||||||
|
private static final String ERROR_MSG = "module.err.deprecated_modules";
|
||||||
|
private final ModuleService moduleService;
|
||||||
|
private final List<String> deprecatedModules;
|
||||||
|
|
||||||
|
public DeprecatedModulesValidator(final ModuleService moduleService, final List<String> deprecatedModules)
|
||||||
|
{
|
||||||
|
this.moduleService = moduleService;
|
||||||
|
this.deprecatedModules = deprecatedModules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onInit()
|
||||||
|
{
|
||||||
|
ofNullable(moduleService.getAllModules())
|
||||||
|
.map(this::getDeprecatedModules)
|
||||||
|
.filter(not(String::isBlank))
|
||||||
|
.ifPresent(DeprecatedModulesValidator::throwException);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDeprecatedModules(List<ModuleDetails> modules)
|
||||||
|
{
|
||||||
|
return modules.stream()
|
||||||
|
.filter(module -> deprecatedModules.contains(module.getId()))
|
||||||
|
.map(module -> module.getTitle() + " " + module.getModuleVersionNumber())
|
||||||
|
.collect(joining(", "));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void throwException(String foundDeprecatedModules)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException(I18NUtil.getMessage(ERROR_MSG, foundDeprecatedModules));
|
||||||
|
}
|
||||||
|
}
|
@@ -18,3 +18,4 @@ module.err.component_already_registered=A component named ''{0}'' has already be
|
|||||||
module.err.unable_to_open_module_properties=The module properties file ''{0}'' could not be read.
|
module.err.unable_to_open_module_properties=The module properties file ''{0}'' could not be read.
|
||||||
module.err.component_in_missing_module=The component ''{0}'' belongs to a non-existent module ''{1}''.
|
module.err.component_in_missing_module=The component ''{0}'' belongs to a non-existent module ''{1}''.
|
||||||
module.err.orphaned_components={0} module components were not considered for execution.
|
module.err.orphaned_components={0} module components were not considered for execution.
|
||||||
|
module.err.deprecated_modules=The following deprecated modules are installed: {0}. Please remove these AMPs in order to continue.
|
@@ -24,8 +24,17 @@
|
|||||||
<property name="tenantAdminService" ref="tenantAdminService" />
|
<property name="tenantAdminService" ref="tenantAdminService" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="deprecatedModulesValidator" class="org.alfresco.repo.module.DeprecatedModulesValidator" init-method="onInit">
|
||||||
|
<constructor-arg name="moduleService" ref="moduleService" />
|
||||||
|
<constructor-arg name="deprecatedModules">
|
||||||
|
<list>
|
||||||
|
<value>alfresco-saml-repo</value>
|
||||||
|
</list>
|
||||||
|
</constructor-arg>
|
||||||
|
</bean>
|
||||||
|
|
||||||
<!-- Import of installed modules -->
|
<!-- Import of installed modules -->
|
||||||
|
|
||||||
<!-- bootstrap context first - for any resources shared between modules like the data list model -->
|
<!-- bootstrap context first - for any resources shared between modules like the data list model -->
|
||||||
<import resource="classpath*:alfresco/module/*/module-bootstrap-context.xml"/>
|
<import resource="classpath*:alfresco/module/*/module-bootstrap-context.xml"/>
|
||||||
<!-- the main context for each module -->
|
<!-- the main context for each module -->
|
||||||
|
@@ -67,6 +67,7 @@ import org.junit.runners.Suite;
|
|||||||
org.alfresco.repo.management.subsystems.CryptodocSwitchableApplicationContextFactoryTest.class,
|
org.alfresco.repo.management.subsystems.CryptodocSwitchableApplicationContextFactoryTest.class,
|
||||||
org.alfresco.repo.module.ModuleDetailsImplTest.class,
|
org.alfresco.repo.module.ModuleDetailsImplTest.class,
|
||||||
org.alfresco.repo.module.ModuleVersionNumberTest.class,
|
org.alfresco.repo.module.ModuleVersionNumberTest.class,
|
||||||
|
org.alfresco.repo.module.DeprecatedModulesValidatorTest.class,
|
||||||
org.alfresco.repo.node.integrity.IntegrityEventTest.class,
|
org.alfresco.repo.node.integrity.IntegrityEventTest.class,
|
||||||
org.alfresco.repo.policy.MTPolicyComponentTest.class,
|
org.alfresco.repo.policy.MTPolicyComponentTest.class,
|
||||||
org.alfresco.repo.policy.PolicyComponentTest.class,
|
org.alfresco.repo.policy.PolicyComponentTest.class,
|
||||||
|
@@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.module;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertThrows;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.module.ModuleDetails;
|
||||||
|
import org.alfresco.service.cmr.module.ModuleService;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test suite for the {@link DeprecatedModulesValidator} class.
|
||||||
|
*
|
||||||
|
* @author Domenico Sibilio
|
||||||
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class DeprecatedModulesValidatorTest
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final String DEPRECATED_MODULE_1 = "deprecated-module-1";
|
||||||
|
private static final String DEPRECATED_MODULE_2 = "deprecated-module-2";
|
||||||
|
private static final String VALID_MODULE = "valid-module";
|
||||||
|
private static final List<String> DEPRECATED_MODULES = List.of(DEPRECATED_MODULE_1, DEPRECATED_MODULE_2);
|
||||||
|
@Mock
|
||||||
|
private ModuleService moduleService;
|
||||||
|
@Mock
|
||||||
|
private ModuleDetails moduleDetails;
|
||||||
|
private DeprecatedModulesValidator deprecatedModulesValidator;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
deprecatedModulesValidator = new DeprecatedModulesValidator(moduleService, DEPRECATED_MODULES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDoNothingWhenNoModulesAreFound()
|
||||||
|
{
|
||||||
|
when(moduleService.getAllModules()).thenReturn(null);
|
||||||
|
|
||||||
|
deprecatedModulesValidator.onInit();
|
||||||
|
|
||||||
|
verify(moduleService).getAllModules();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDoNothingWhenNoDeprecatedModulesAreFound()
|
||||||
|
{
|
||||||
|
when(moduleService.getAllModules()).thenReturn(List.of(moduleDetails));
|
||||||
|
when(moduleDetails.getId()).thenReturn(VALID_MODULE);
|
||||||
|
|
||||||
|
deprecatedModulesValidator.onInit();
|
||||||
|
|
||||||
|
verify(moduleService).getAllModules();
|
||||||
|
verify(moduleDetails).getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalStateException.class)
|
||||||
|
public void shouldThrowExceptionWhenADeprecatedModuleIsFound()
|
||||||
|
{
|
||||||
|
when(moduleService.getAllModules()).thenReturn(List.of(moduleDetails));
|
||||||
|
when(moduleDetails.getId()).thenReturn(DEPRECATED_MODULE_1);
|
||||||
|
|
||||||
|
deprecatedModulesValidator.onInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldThrowExceptionWhenMultipleDeprecatedModulesAreFound()
|
||||||
|
{
|
||||||
|
when(moduleService.getAllModules()).thenReturn(List.of(moduleDetails, moduleDetails));
|
||||||
|
when(moduleDetails.getId()).thenReturn(DEPRECATED_MODULE_1)
|
||||||
|
.thenReturn(DEPRECATED_MODULE_2);
|
||||||
|
|
||||||
|
assertThrows("IllegalStateException should be thrown.",
|
||||||
|
IllegalStateException.class,
|
||||||
|
() -> deprecatedModulesValidator.onInit());
|
||||||
|
|
||||||
|
verify(moduleService).getAllModules();
|
||||||
|
verify(moduleDetails, times(2)).getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldThrowExceptionWhenBothValidAndDeprecatedModulesAreFound()
|
||||||
|
{
|
||||||
|
when(moduleService.getAllModules()).thenReturn(List.of(moduleDetails, moduleDetails));
|
||||||
|
when(moduleDetails.getId()).thenReturn(VALID_MODULE)
|
||||||
|
.thenReturn(DEPRECATED_MODULE_2);
|
||||||
|
|
||||||
|
assertThrows("IllegalStateException should be thrown.",
|
||||||
|
IllegalStateException.class,
|
||||||
|
() -> deprecatedModulesValidator.onInit());
|
||||||
|
|
||||||
|
verify(moduleService).getAllModules();
|
||||||
|
verify(moduleDetails, times(2)).getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user