use of org.xwiki.extension.DefaultExtensionDependency in project xwiki-platform by xwiki.
the class RepositoryManager method updateExtensionVersionDependencies.
private boolean updateExtensionVersionDependencies(XWikiDocument document, Extension extension) throws XWikiException {
boolean needSave = false;
List<ExtensionDependency> dependencies = new ArrayList<>(extension.getDependencies());
int dependencyIndex = 0;
// Clean misplaced or bad existing dependencies associated to this extension version
List<BaseObject> xobjects = document.getXObjects(XWikiRepositoryModel.EXTENSIONDEPENDENCY_CLASSREFERENCE);
if (xobjects != null) {
boolean deleteExistingObjects = false;
// Clone since we are going to modify and parse it at the same time
xobjects = new ArrayList<>(document.getXObjects(XWikiRepositoryModel.EXTENSIONDEPENDENCY_CLASSREFERENCE));
for (int i = 0; i < xobjects.size(); ++i) {
BaseObject dependencyObject = xobjects.get(i);
if (dependencyObject != null) {
String extensionVersion = getValue(dependencyObject, XWikiRepositoryModel.PROP_DEPENDENCY_EXTENSIONVERSION, (String) null);
if (StringUtils.isNotEmpty(extensionVersion) && extension.getId().getVersion().equals(new DefaultVersion(extensionVersion))) {
if (deleteExistingObjects) {
document.removeXObject(dependencyObject);
needSave = true;
} else {
String xobjectId = getValue(dependencyObject, XWikiRepositoryModel.PROP_DEPENDENCY_ID);
String xobjectConstraint = getValue(dependencyObject, XWikiRepositoryModel.PROP_DEPENDENCY_CONSTRAINT);
List<String> xobjectRepositories = (List<String>) getValue(dependencyObject, XWikiRepositoryModel.PROP_DEPENDENCY_REPOSITORIES);
boolean xobjectOptional = getValue(dependencyObject, XWikiRepositoryModel.PROP_DEPENDENCY_OPTIONAL, 0) == 1;
if (dependencies.size() > dependencyIndex) {
ExtensionDependency dependency = dependencies.get(dependencyIndex);
DefaultExtensionDependency xobjectDependency = new DefaultExtensionDependency(xobjectId, new DefaultVersionConstraint(xobjectConstraint), xobjectOptional, dependency.getProperties());
xobjectDependency.setRepositories(XWikiRepositoryModel.toRepositoryDescriptors(xobjectRepositories, this.extensionFactory));
if (dependency.equals(xobjectDependency)) {
++dependencyIndex;
continue;
}
}
deleteExistingObjects = true;
document.removeXObject(dependencyObject);
needSave = true;
}
}
}
}
}
// Add missing dependencies
if (dependencyIndex < dependencies.size()) {
XWikiContext xcontext = this.xcontextProvider.get();
for (; dependencyIndex < dependencies.size(); ++dependencyIndex) {
ExtensionDependency dependency = dependencies.get(dependencyIndex);
BaseObject dependencyObject = document.newXObject(XWikiRepositoryModel.EXTENSIONDEPENDENCY_CLASSREFERENCE, xcontext);
dependencyObject.set(XWikiRepositoryModel.PROP_DEPENDENCY_EXTENSIONVERSION, extension.getId().getVersion().getValue(), xcontext);
dependencyObject.set(XWikiRepositoryModel.PROP_DEPENDENCY_ID, dependency.getId(), xcontext);
dependencyObject.set(XWikiRepositoryModel.PROP_DEPENDENCY_CONSTRAINT, dependency.getVersionConstraint().getValue(), xcontext);
dependencyObject.set(XWikiRepositoryModel.PROP_DEPENDENCY_OPTIONAL, dependency.isOptional() ? 1 : 0, xcontext);
dependencyObject.set(XWikiRepositoryModel.PROP_DEPENDENCY_REPOSITORIES, XWikiRepositoryModel.toStringList(dependency.getRepositories()), xcontext);
needSave = true;
}
}
return needSave;
}
use of org.xwiki.extension.DefaultExtensionDependency in project xwiki-platform by xwiki.
the class WikiCopiedEventListenerTest method setUp.
@Before
public void setUp() throws Exception {
this.localExtensionRepository = this.repositoryUtil.getComponentManager().getInstance(LocalExtensionRepository.class);
this.installedExtensionRepository = this.repositoryUtil.getComponentManager().getInstance(InstalledExtensionRepository.class);
this.observation = this.repositoryUtil.getComponentManager().getInstance(ObservationManager.class);
// Extensions
EmptyExtension extension = new EmptyExtension(new ExtensionId("id", "version"), "xar");
EmptyExtension extensionDependency = new EmptyExtension(new ExtensionId("dependency", "version"), "xar");
extension.addDependency(new DefaultExtensionDependency(extensionDependency.getId().getId(), new DefaultVersionConstraint(null, extensionDependency.getId().getVersion())));
this.localExtensionDependency1 = this.localExtensionRepository.storeExtension(extensionDependency);
this.localExtension1 = this.localExtensionRepository.storeExtension(extension);
}
use of org.xwiki.extension.DefaultExtensionDependency in project xwiki-platform by xwiki.
the class ExtensionIT method testDependencies.
/**
* Tests how extension dependencies are displayed (both direct and backward dependencies).
*/
@Test
public void testDependencies() throws Exception {
// Setup the extension and its dependencies.
ExtensionId dependencyId = new ExtensionId("bob-xar-extension", "2.5-milestone-2");
TestExtension dependency = getRepositoryTestUtils().getTestExtension(dependencyId, "xar");
dependency.setName("Bob Wiki Macro");
dependency.setSummary("Required by Alice");
getRepositoryTestUtils().addExtension(dependency);
ExtensionId extensionId = new ExtensionId("alice-xar-extension", "1.3");
TestExtension extension = getRepositoryTestUtils().getTestExtension(extensionId, "xar");
extension.addDependency(new DefaultExtensionDependency(dependencyId.getId(), new DefaultVersionConstraint(dependencyId.getVersion().getValue())));
extension.addDependency(new DefaultExtensionDependency("missing-dependency", new DefaultVersionConstraint("135")));
extension.addDependency(new DefaultExtensionDependency("org.xwiki.platform:xwiki-platform-sheet-api", new DefaultVersionConstraint("[3.2,)")));
extension.addDependency(new DefaultExtensionDependency("org.xwiki.commons:xwiki-commons-diff-api", new DefaultVersionConstraint("2.7")));
extension.addDependency(new DefaultExtensionDependency("org.xwiki.platform:xwiki-platform-display-api", new DefaultVersionConstraint("100.1")));
getRepositoryTestUtils().addExtension(extension);
// Search the extension and assert the list of dependencies.
ExtensionAdministrationPage adminPage = ExtensionAdministrationPage.gotoPage();
ExtensionPane extensionPane = adminPage.getSearchBar().clickAdvancedSearch().search(extensionId).getExtension(0);
ExtensionDependenciesPane dependenciesPane = extensionPane.openDependenciesSection();
List<DependencyPane> directDependencies = dependenciesPane.getDirectDependencies();
assertEquals(5, directDependencies.size());
assertEquals(dependency.getName(), directDependencies.get(0).getName());
assertEquals(dependencyId.getVersion().getValue(), directDependencies.get(0).getVersion());
assertEquals("remote", directDependencies.get(0).getStatus());
assertNull(directDependencies.get(0).getStatusMessage());
assertNull(directDependencies.get(1).getLink());
assertEquals("missing-dependency", directDependencies.get(1).getName());
assertEquals("135", directDependencies.get(1).getVersion());
assertEquals("unknown", directDependencies.get(1).getStatus());
assertNull(directDependencies.get(1).getStatusMessage());
assertNotNull(directDependencies.get(2).getLink());
assertEquals("XWiki Platform - Sheet - API", directDependencies.get(2).getName());
assertEquals("[3.2,)", directDependencies.get(2).getVersion());
assertEquals("core", directDependencies.get(2).getStatus());
assertEquals("Provided", directDependencies.get(2).getStatusMessage());
assertNotNull(directDependencies.get(3).getLink());
assertEquals("XWiki Commons - Diff API", directDependencies.get(3).getName());
assertEquals("2.7", directDependencies.get(3).getVersion());
assertEquals("remote-core", directDependencies.get(3).getStatus());
assertTrue(directDependencies.get(3).getStatusMessage().matches("Version [^\\s]+ is provided"));
assertEquals("XWiki Platform - Display API", directDependencies.get(4).getName());
assertEquals("100.1", directDependencies.get(4).getVersion());
assertEquals("remote-core-incompatible", directDependencies.get(4).getStatus());
assertTrue(directDependencies.get(4).getStatusMessage().matches("Incompatible with provided version [^\\s]+"));
assertTrue(dependenciesPane.getBackwardDependencies().isEmpty());
// Follow the link to a dependency.
directDependencies.get(0).getLink().click();
adminPage = new ExtensionAdministrationPage();
extensionPane = adminPage.getSearchResults().getExtension(0);
assertEquals(dependency.getName(), extensionPane.getName());
assertEquals(dependencyId.getVersion().getValue(), extensionPane.getVersion());
assertEquals(dependency.getSummary(), extensionPane.getSummary());
// Check that we are still in the administration.
assertTrue(new AdministrationPage().hasSection("XWiki.Extensions"));
}
use of org.xwiki.extension.DefaultExtensionDependency in project xwiki-platform by xwiki.
the class ExtensionIT method testInstall.
/**
* Tests how an extension is installed.
*/
@Test
public void testInstall() throws Exception {
// Setup the extension and its dependencies.
ExtensionId extensionId = new ExtensionId("alice-xar-extension", "1.3");
TestExtension extension = getRepositoryTestUtils().getTestExtension(extensionId, "xar");
ExtensionId dependencyId = new ExtensionId("bob-xar-extension", "2.5-milestone-2");
getRepositoryTestUtils().addExtension(getRepositoryTestUtils().getTestExtension(dependencyId, "xar"));
extension.addDependency(new DefaultExtensionDependency(dependencyId.getId(), new DefaultVersionConstraint(dependencyId.getVersion().getValue())));
extension.addDependency(new DefaultExtensionDependency("org.xwiki.platform:xwiki-platform-sheet-api", new DefaultVersionConstraint("[3.2,)")));
getRepositoryTestUtils().addExtension(extension);
// Search the extension and install it.
ExtensionAdministrationPage adminPage = ExtensionAdministrationPage.gotoPage();
ExtensionPane extensionPane = adminPage.getSearchBar().clickAdvancedSearch().search(extensionId).getExtension(0);
extensionPane = extensionPane.install();
// Assert the install plan.
List<DependencyPane> installPlan = extensionPane.openProgressSection().getJobPlan();
assertEquals(2, installPlan.size());
assertEquals(dependencyId, installPlan.get(0).getId());
assertEquals(extensionId, installPlan.get(1).getId());
// Finish the install and assert the install log.
List<LogItemPane> log = extensionPane.confirm().openProgressSection().getJobLog();
int logSize = log.size();
assertTrue(logSize > 1);
assertEquals("info", log.get(0).getLevel());
assertEquals("Starting job of type [install] with identifier " + "[extension/action/alice-xar-extension/wiki:xwiki]", log.get(0).getMessage());
assertEquals("info", log.get(logSize - 1).getLevel());
assertEquals("Finished job of type [install] with identifier " + "[extension/action/alice-xar-extension/wiki:xwiki]", log.get(logSize - 1).getMessage());
// Test that both extensions are usable.
ViewPage viewPage = getUtil().createPage(getTestClassName(), getTestMethodName(), "{{alice/}}\n\n{{bob/}}", "");
String content = viewPage.getContent();
assertTrue(content.contains("Alice says hello!"));
assertTrue(content.contains("Bob says hi!"));
// Check the list of installed extensions.
adminPage = ExtensionAdministrationPage.gotoInstalledExtensions();
SearchResultsPane searchResults = adminPage.getSearchBar().search("bob");
assertEquals(1, searchResults.getDisplayedResultsCount());
extensionPane = searchResults.getExtension(0);
assertEquals("installed-dependency", extensionPane.getStatus());
assertEquals("Installed as dependency", extensionPane.getStatusMessage());
assertEquals(dependencyId, extensionPane.getId());
assertNotNull(extensionPane.getUninstallButton());
searchResults = new SimpleSearchPane().search("alice");
assertEquals(1, searchResults.getDisplayedResultsCount());
extensionPane = searchResults.getExtension(0);
assertEquals("installed", extensionPane.getStatus());
assertEquals("Installed", extensionPane.getStatusMessage());
assertEquals(extensionId, extensionPane.getId());
assertNotNull(extensionPane.getUninstallButton());
// Check if the progress log is persisted.
extensionPane = extensionPane.showDetails();
log = extensionPane.openProgressSection().getJobLog();
assertEquals(logSize, log.size());
assertEquals("info", log.get(0).getLevel());
assertEquals("Starting job of type [install] with identifier " + "[extension/action/alice-xar-extension/wiki:xwiki]", log.get(0).getMessage());
assertEquals("info", log.get(logSize - 1).getLevel());
assertEquals("Finished job of type [install] with identifier " + "[extension/action/alice-xar-extension/wiki:xwiki]", log.get(logSize - 1).getMessage());
// Check if the dependency is properly listed as installed.
List<DependencyPane> dependencies = extensionPane.openDependenciesSection().getDirectDependencies();
assertEquals(2, dependencies.size());
assertEquals(dependencyId, dependencies.get(0).getId());
assertEquals("installed-dependency", dependencies.get(0).getStatus());
assertEquals("Installed as dependency", dependencies.get(0).getStatusMessage());
// Check the backward dependency.
dependencies.get(0).getLink().click();
extensionPane = new ExtensionAdministrationPage().getSearchResults().getExtension(0);
dependencies = extensionPane.openDependenciesSection().getBackwardDependencies();
assertEquals(1, dependencies.size());
assertEquals(extensionId, dependencies.get(0).getId());
assertEquals("installed", dependencies.get(0).getStatus());
assertEquals("Installed", dependencies.get(0).getStatusMessage());
}
use of org.xwiki.extension.DefaultExtensionDependency in project xwiki-platform by xwiki.
the class ExtensionIT method testUninstall.
/**
* Tests how an extension is uninstalled.
*/
@Test
public void testUninstall() throws Exception {
// Setup the extension and its dependencies.
ExtensionId dependencyId = new ExtensionId("bob-xar-extension", "2.5-milestone-2");
getRepositoryTestUtils().addExtension(getRepositoryTestUtils().getTestExtension(dependencyId, "xar"));
ExtensionId extensionId = new ExtensionId("alice-xar-extension", "1.3");
TestExtension extension = getRepositoryTestUtils().getTestExtension(extensionId, "xar");
extension.addDependency(new DefaultExtensionDependency(dependencyId.getId(), new DefaultVersionConstraint(dependencyId.getVersion().getValue())));
getRepositoryTestUtils().addExtension(extension);
// Install the extensions.
getExtensionTestUtils().install(extensionId);
// Check if the installed pages are present.
assertTrue(getUtil().pageExists("ExtensionTest", "Alice"));
assertTrue(getUtil().pageExists("ExtensionTest", "Bob"));
// Uninstall the dependency.
ExtensionAdministrationPage adminPage = ExtensionAdministrationPage.gotoInstalledExtensions();
ExtensionPane extensionPane = adminPage.getSearchBar().clickAdvancedSearch().search(dependencyId).getExtension(0);
extensionPane = extensionPane.uninstall();
// Check the uninstall plan. Both extensions should be included.
List<DependencyPane> uninstallPlan = extensionPane.openProgressSection().getJobPlan();
assertEquals(2, uninstallPlan.size());
assertEquals(extensionId, uninstallPlan.get(0).getId());
assertEquals("installed", uninstallPlan.get(0).getStatus());
assertEquals("Installed", uninstallPlan.get(0).getStatusMessage());
assertEquals(dependencyId, uninstallPlan.get(1).getId());
assertEquals("installed-dependency", uninstallPlan.get(1).getStatus());
assertEquals("Installed as dependency", uninstallPlan.get(1).getStatusMessage());
// Check the confirmation to delete the unused wiki pages.
extensionPane = extensionPane.confirm();
UnusedPagesPane unusedPages = extensionPane.openProgressSection().getUnusedPages();
assertTrue(unusedPages.contains("ExtensionTest", "Alice"));
assertTrue(unusedPages.contains("ExtensionTest", "Bob"));
// Finish the uninstall and check the log.
extensionPane = extensionPane.confirm();
List<LogItemPane> log = extensionPane.openProgressSection().getJobLog();
assertTrue(log.size() > 2);
assertEquals("info", log.get(2).getLevel());
assertEquals("Resolving extension [bob-xar-extension 2.5-milestone-2] from namespace [Home]", log.get(2).getMessage());
assertEquals("info", log.get(log.size() - 1).getLevel());
assertEquals("Finished job of type [uninstall] with identifier " + "[extension/action/bob-xar-extension/wiki:xwiki]", log.get(log.size() - 1).getMessage());
// Check if the uninstalled pages have been deleted.
assertFalse(getUtil().pageExists("ExtensionTest", "Alice"));
assertFalse(getUtil().pageExists("ExtensionTest", "Bob"));
// Install both extension again and uninstall only the one with the dependency.
getExtensionTestUtils().install(extensionId);
adminPage = ExtensionAdministrationPage.gotoInstalledExtensions();
extensionPane = adminPage.getSearchBar().clickAdvancedSearch().search(extensionId).getExtension(0);
extensionPane = extensionPane.uninstall();
// Check the uninstall plan. Only one extension should be included.
uninstallPlan = extensionPane.openProgressSection().getJobPlan();
assertEquals(1, uninstallPlan.size());
assertEquals(extensionId, uninstallPlan.get(0).getId());
// Check the confirmation to delete the unused wiki pages.
extensionPane = extensionPane.confirm();
unusedPages = extensionPane.openProgressSection().getUnusedPages();
assertTrue(unusedPages.contains("ExtensionTest", "Alice"));
assertFalse(unusedPages.contains("ExtensionTest", "Bob"));
// Finish the uninstall and check the log.
log = extensionPane.confirm().openProgressSection().getJobLog();
assertTrue(log.size() > 2);
assertEquals("info", log.get(2).getLevel());
assertEquals("Resolving extension [alice-xar-extension 1.3] from namespace [Home]", log.get(2).getMessage());
assertEquals("info", log.get(log.size() - 1).getLevel());
assertEquals("Finished job of type [uninstall] with identifier " + "[extension/action/alice-xar-extension/wiki:xwiki]", log.get(log.size() - 1).getMessage());
// Check if the uninstalled pages have been deleted.
assertFalse(getUtil().pageExists("ExtensionTest", "Alice"));
assertTrue(getUtil().pageExists("ExtensionTest", "Bob"));
// Check the list of installed extensions. It should contain only the second extension.
adminPage = ExtensionAdministrationPage.gotoInstalledExtensions();
SearchResultsPane searchResults = adminPage.getSearchBar().search("alice");
assertEquals(0, searchResults.getDisplayedResultsCount());
assertNotNull(searchResults.getNoResultsMessage());
searchResults = new SimpleSearchPane().search("bob");
assertEquals(1, searchResults.getDisplayedResultsCount());
extensionPane = searchResults.getExtension(0);
assertEquals("installed-dependency", extensionPane.getStatus());
assertEquals(dependencyId, extensionPane.getId());
}
Aggregations