use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class FlavorSearchJob method runInternal.
@Override
protected void runInternal() throws Exception {
// Get known flavors
Collection<ExtensionId> knownFlavors = this.flavorManager.getKnownFlavors();
Collection<String> knownInvalidFlavors = this.flavorManager.getKnownInvalidFlavors();
// Get remote flavors
IterableResult<Extension> flavors = this.flavorManager.searchFlavors(new FlavorQuery());
this.progressManager.pushLevelProgress(knownFlavors.size() + flavors.getSize(), this);
try {
// Remember which flavors already been (in)validated
Set<String> doneFlavors = new HashSet<>();
// Add the know invalid flavors to the list of already done flavors
doneFlavors.addAll(knownInvalidFlavors);
String namespace = getRequest().getNamespaces().iterator().next();
// Add known flavors
for (ExtensionId flavorId : knownFlavors) {
this.progressManager.startStep(this);
// Validate and add the flavor
validateKnownFlavor(flavorId, namespace);
// Remember we took care of this flavor
doneFlavors.add(flavorId.getId());
this.progressManager.endStep(this);
}
// Add remote flavors
for (Extension flavor : flavors) {
this.progressManager.startStep(this);
// Search only unknown flavors
if (!doneFlavors.contains(flavor.getId().getId())) {
Extension validExtension = findValidVersion(flavor.getId().getId(), namespace);
if (validExtension != null) {
this.foundFlavors.add(validExtension);
}
}
this.progressManager.endStep(this);
}
} finally {
this.progressManager.popLevelProgress(this);
}
}
use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class Package method registerExtension.
private void registerExtension(XWikiContext context) {
// Register the package as extension if it's one
if (isInstallExtension() && StringUtils.isNotEmpty(getExtensionId()) && StringUtils.isNotEmpty(getVersion())) {
ExtensionId extensionId = new ExtensionId(getExtensionId(), getVersion());
try {
LocalExtensionRepository localRepository = Utils.getComponent(LocalExtensionRepository.class);
LocalExtension localExtension = localRepository.getLocalExtension(extensionId);
if (localExtension == null) {
Extension extension;
try {
// Try to find and download the extension from a repository
extension = Utils.getComponent(ExtensionRepositoryManager.class).resolve(extensionId);
} catch (ResolveException e) {
LOGGER.debug("Can't find extension [{}]", extensionId, e);
// FIXME: Create a dummy extension. Need support for partial/lazy extension.
return;
}
localExtension = localRepository.storeExtension(extension);
}
InstalledExtensionRepository installedRepository = Utils.getComponent(InstalledExtensionRepository.class);
String namespace = "wiki:" + context.getWikiId();
// Make sure it's not already there
if (installedRepository.getInstalledExtension(localExtension.getId().getId(), namespace) == null) {
for (ExtensionId feature : localExtension.getExtensionFeatures()) {
if (installedRepository.getInstalledExtension(feature.getId(), namespace) != null) {
// Already exist so don't register it or it could create a mess
return;
}
}
} else {
return;
}
// Register the extension as installed
InstalledExtension installedExtension = installedRepository.installExtension(localExtension, namespace, false);
// Tell the world about it
Utils.getComponent(ObservationManager.class).notify(new ExtensionInstalledEvent(installedExtension.getId(), namespace), installedExtension);
} catch (Exception e) {
LOGGER.error("Failed to register extenion [{}] from the XAR", extensionId, e);
}
}
}
use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class RepositoryManager method resolveExtensionVersion.
/**
* This method factually resolves extension from remote source (when it's possible). Call it only when the data that
* is going to be obtained cannot be got from extension document xobject
*
* @since 9.5RC1
*/
public Extension resolveExtensionVersion(XWikiDocument extensionDocument, String extensionVersion) throws ResolveException {
BaseObject extensionObject = extensionDocument.getXObject(XWikiRepositoryModel.EXTENSION_CLASSREFERENCE);
if (extensionObject == null) {
return null;
}
String extensionId = getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_ID, (String) null);
BaseObject extensionProxyObject = extensionDocument.getXObject(XWikiRepositoryModel.EXTENSIONPROXY_CLASSREFERENCE);
if (extensionProxyObject == null) {
return null;
}
String repositoryId = getValue(extensionProxyObject, XWikiRepositoryModel.PROP_PROXY_REPOSITORYID, (String) null);
if (extensionId == null || repositoryId == null) {
return null;
}
ExtensionRepository repository = this.extensionRepositoryManager.getRepository(repositoryId);
if (isGivenVersionOneOfExtensionVersions(repository, extensionId, extensionVersion)) {
return repository.resolve(new ExtensionId(extensionId, extensionVersion));
} else {
return tryToResolveExtensionFromExtensionFeatures(repository, extensionObject, extensionVersion);
}
}
use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class AllITs method initExtensions.
public static void initExtensions(PersistentTestContext context) throws Exception {
// This will not be null if we are in the middle of allTests
if (repositoryUtil == null) {
repositoryUtil = new RepositoryUtils();
}
// Initialize extensions and repositories
RepositoryTestUtils repositoryTestUtil = new RepositoryTestUtils(context.getUtil(), repositoryUtil, new SolrTestUtils(context.getUtil()));
repositoryTestUtil.init();
ExtensionTestUtils extensionTestUtil = new ExtensionTestUtils(context.getUtil());
// Set integration repository and extension utils.
context.getProperties().put(RepositoryTestUtils.PROPERTY_KEY, repositoryTestUtil);
context.getProperties().put(ExtensionTestUtils.PROPERTY_KEY, extensionTestUtil);
// Populate maven repository
File extensionFile = repositoryUtil.getExtensionPackager().getExtensionFile(new ExtensionId("emptyjar", "1.0"));
FileUtils.copyFile(extensionFile, new File(repositoryUtil.getMavenRepository(), "maven/extension/1.0/extension-1.0.jar"));
FileUtils.copyFile(extensionFile, new File(repositoryUtil.getMavenRepository(), "maven/extension/2.0/extension-2.0.jar"));
FileUtils.copyFile(extensionFile, new File(repositoryUtil.getMavenRepository(), "maven/oldextension/0.9/oldextension-0.9.jar"));
FileUtils.copyFile(extensionFile, new File(repositoryUtil.getMavenRepository(), "maven/dependency/version/dependency-version.jar"));
// Used in the Extension Manager functional tests.
FileUtils.copyFile(extensionFile, new File(repositoryUtil.getMavenRepository(), "org/xwiki/commons/xwiki-commons-diff-api/2.7/xwiki-commons-diff-api-2.7.jar"));
FileUtils.copyFile(extensionFile, new File(repositoryUtil.getMavenRepository(), "org/xwiki/platform/xwiki-platform-display-api/100.1/xwiki-platform-display-api-100.1.jar"));
}
use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.
the class ExtensionIT method testRepositorySelector.
/**
* Tests the extension repository selector (all, core, installed, local).
*/
@Test
public void testRepositorySelector() throws Exception {
// Setup the extension.
ExtensionId extensionId = new ExtensionId("alice-xar-extension", "1.3");
TestExtension extension = getRepositoryTestUtils().getTestExtension(extensionId, "xar");
getRepositoryTestUtils().addExtension(extension);
getRepositoryTestUtils().waitUntilReady();
// Check that the Recommended Extensions are displayed by default.
ExtensionAdministrationPage adminPage = ExtensionAdministrationPage.gotoPage();
Select repositorySelect = adminPage.getSearchBar().getRepositorySelect();
assertEquals("Recommended Extensions", repositorySelect.getFirstSelectedOption().getText());
// Check that a remote extension appears only in the list of "All Extensions".
adminPage.getSearchBar().selectRepository("installed");
SearchResultsPane searchResults = adminPage.getSearchBar().search("alice");
assertNull(searchResults.getExtension(extensionId));
adminPage.getSearchBar().getRepositorySelect().selectByVisibleText("All Extensions");
adminPage = new ExtensionAdministrationPage();
adminPage.waitUntilPageIsLoaded();
// The value of the search input must be preserved when we switch the repository.
assertEquals("alice", adminPage.getSearchBar().getSearchInput().getAttribute("value"));
assertNotNull(adminPage.getSearchResults().getExtension(extensionId));
assertNull(new SimpleSearchPane().selectRepository("local").getExtension(extensionId));
// Check that an installed extension appears also in "Installed Extensions" and "Local Extensions".
getExtensionTestUtils().install(extensionId);
adminPage = ExtensionAdministrationPage.gotoPage();
adminPage.getSearchBar().selectRepository("installed");
searchResults = adminPage.getSearchBar().search("alice");
assertNotNull(searchResults.getExtension(extensionId));
assertNotNull(new SimpleSearchPane().selectRepository("local").getExtension(extensionId));
assertNotNull(new SimpleSearchPane().selectRepository("").getExtension(extensionId));
// Check local extension.
getExtensionTestUtils().uninstall(extensionId.getId(), true);
adminPage = ExtensionAdministrationPage.gotoPage();
adminPage.getSearchBar().selectRepository("installed");
searchResults = adminPage.getSearchBar().search("alice");
assertNull(searchResults.getExtension(extensionId));
assertNotNull(new SimpleSearchPane().selectRepository("local").getExtension(extensionId));
assertNotNull(new SimpleSearchPane().selectRepository("").getExtension(extensionId));
}
Aggregations