Search in sources :

Example 56 with ExtensionId

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);
    }
}
Also used : Extension(org.xwiki.extension.Extension) ExtensionId(org.xwiki.extension.ExtensionId) FlavorQuery(org.xwiki.platform.flavor.FlavorQuery) HashSet(java.util.HashSet)

Example 57 with ExtensionId

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);
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) Extension(org.xwiki.extension.Extension) LocalExtension(org.xwiki.extension.LocalExtension) ResolveException(org.xwiki.extension.ResolveException) InstalledExtension(org.xwiki.extension.InstalledExtension) LocalExtensionRepository(org.xwiki.extension.repository.LocalExtensionRepository) LocalExtension(org.xwiki.extension.LocalExtension) ExtensionId(org.xwiki.extension.ExtensionId) ObservationManager(org.xwiki.observation.ObservationManager) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) XWikiException(com.xpn.xwiki.XWikiException) QueryException(org.xwiki.query.QueryException) DocumentException(org.dom4j.DocumentException) IOException(java.io.IOException) ResolveException(org.xwiki.extension.ResolveException) ExtensionInstalledEvent(org.xwiki.extension.event.ExtensionInstalledEvent)

Example 58 with ExtensionId

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);
    }
}
Also used : ExtensionRepository(org.xwiki.extension.repository.ExtensionRepository) ExtensionId(org.xwiki.extension.ExtensionId) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 59 with ExtensionId

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"));
}
Also used : RepositoryUtils(org.xwiki.extension.test.RepositoryUtils) SolrTestUtils(org.xwiki.repository.test.SolrTestUtils) ExtensionTestUtils(org.xwiki.extension.test.ExtensionTestUtils) RepositoryTestUtils(org.xwiki.repository.test.RepositoryTestUtils) ExtensionId(org.xwiki.extension.ExtensionId) File(java.io.File)

Example 60 with ExtensionId

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));
}
Also used : ExtensionAdministrationPage(org.xwiki.extension.test.po.ExtensionAdministrationPage) Select(org.openqa.selenium.support.ui.Select) ExtensionId(org.xwiki.extension.ExtensionId) TestExtension(org.xwiki.repository.test.TestExtension) SearchResultsPane(org.xwiki.extension.test.po.SearchResultsPane) SimpleSearchPane(org.xwiki.extension.test.po.SimpleSearchPane) Test(org.junit.Test)

Aggregations

ExtensionId (org.xwiki.extension.ExtensionId)67 Test (org.junit.Test)37 InstalledExtension (org.xwiki.extension.InstalledExtension)13 ExtensionAdministrationPage (org.xwiki.extension.test.po.ExtensionAdministrationPage)11 TestExtension (org.xwiki.repository.test.TestExtension)11 ExtensionPane (org.xwiki.extension.test.po.ExtensionPane)9 DocumentReference (org.xwiki.model.reference.DocumentReference)9 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)8 Extension (org.xwiki.extension.Extension)7 InstallRequest (org.xwiki.extension.job.InstallRequest)6 DefaultVersionConstraint (org.xwiki.extension.version.internal.DefaultVersionConstraint)6 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 IOException (java.io.IOException)5 DefaultExtensionDependency (org.xwiki.extension.DefaultExtensionDependency)5 SearchResultsPane (org.xwiki.extension.test.po.SearchResultsPane)5 ViewPage (org.xwiki.test.ui.po.ViewPage)5 XWikiContext (com.xpn.xwiki.XWikiContext)4 ResolveException (org.xwiki.extension.ResolveException)4 DependencyPane (org.xwiki.extension.test.po.DependencyPane)4 LogItemPane (org.xwiki.extension.test.po.LogItemPane)4