public PluginResourceLocatorImpl(WebResourceIntegration webResourceIntegration) { pluginAccessor = webResourceIntegration.getPluginAccessor(); }
private WebResourceModuleDescriptor getWebResourceModuleDescriptor(String key) { ModuleDescriptor<?> moduleDescriptor; try { moduleDescriptor = integration.getPluginAccessor().getEnabledPluginModule(key); } catch (RuntimeException e) { moduleDescriptor = null; } if (moduleDescriptor == null) { return null; } if (!(moduleDescriptor instanceof WebResourceModuleDescriptor)) { return null; } return (WebResourceModuleDescriptor) moduleDescriptor; }
private Plugin getPlugin(String key) { // Detecting if it's a web resource key or plugin key. if (key.contains(":")) { ModuleDescriptor<?> moduleDescriptor = integration.getPluginAccessor().getEnabledPluginModule(key); return checkNotNull(moduleDescriptor.getPlugin()); } else { return checkNotNull(integration.getPluginAccessor().getEnabledPlugin(key)); } }
@Override public String getStaticPluginResourceUrl(final String moduleCompleteKey, final String resourceName, final UrlMode urlMode) { final ModuleDescriptor<?> moduleDescriptor = webResourceIntegration.getPluginAccessor().getEnabledPluginModule(moduleCompleteKey); if (moduleDescriptor == null) { return null; } return getStaticPluginResourceUrl(moduleDescriptor, resourceName, urlMode); }
public Iterable<ModuleDescriptorStub> getDependenciesInContext(RequestCache requestCache, UrlBuildingStrategy urlBuildingStrategy, final String context, boolean excludeSuperBatchedResources, final Set<String> skippedResources, boolean includeDependenciesForFailedUrlReadingConditions) { final Set<ModuleDescriptorStub> contextResources = new LinkedHashSet<>(); final Class<WebResourceModuleDescriptor> clazz = WebResourceModuleDescriptor.class; List<String> contextDependencies = new ArrayList<>(); for (final WebResourceModuleDescriptor descriptor : webResourceIntegration.getPluginAccessor().getEnabledModuleDescriptorsByClass(clazz)) { if (descriptor != null && descriptor.getContexts().contains(context)) { contextDependencies.add(descriptor.getCompleteKey()); } } // Adding modules. Bundle bundle = requestCache.getSnapshot().get(Config.CONTEXT_PREFIX + ":" + context); if (bundle != null) { contextDependencies.addAll(bundle.getDependencies()); } for (String key : contextDependencies) { final LinkedHashMap<String, ModuleDescriptorStub> dependencies = new LinkedHashMap<>(); final Iterable<String> superBatchResources = excludeSuperBatchedResources ? getSuperBatchDependencyKeys() : Collections.<String> emptyList(); resolveDependencies(requestCache, urlBuildingStrategy, key, dependencies, superBatchResources, new Stack<String>(), skippedResources, includeDependenciesForFailedUrlReadingConditions); for (final ModuleDescriptorStub dependency : dependencies.values()) { contextResources.add(dependency); } } return unmodifiableCollection(contextResources); }
/** * Represents product state considering everything that contributes to content of resources. * * @since v3.5.0 */ public String computeGlobalStateHash() { // This needs to represent all the things that contribute // to the content of files or contribute to what // requireContext() or requireResource() would result in List<String> state = new LinkedList<>(); state.add("productver"); state.add(integration.getHostApplicationVersion()); // annotators impact content of files state.add("annotators"); state.add(String.valueOf(getContentAnnotator(JS_TYPE).hashCode())); state.add(String.valueOf(getContentAnnotator(CSS_TYPE).hashCode())); state.add("plugins"); List<Plugin> plugins = new ArrayList<>(integration.getPluginAccessor().getEnabledPlugins()); sort(plugins, consistentPluginOrder()); for (Plugin plugin : plugins) { state.add(plugin.getKey()); state.add(getPluginVersionOrInstallTime(plugin, usePluginInstallTimeInsteadOfTheVersionForSnapshotPlugins)); } String globalProductStateHash = HashBuilder.buildHash(state); log.info("Calculated global state hash {} based on {}", globalProductStateHash, state); return globalProductStateHash; }
public PluginResourceLocatorImpl(final WebResourceIntegration webResourceIntegration, final ServletContextFactory servletContextFactory, final WebResourceUrlProvider webResourceUrlProvider, final ResourceBatchingConfiguration batchingConfiguration, final PluginEventManager pluginEventManager, final StaticTransformers staticTransformers, final ResourceCompiler resourceCompiler) { Config config = new Config( batchingConfiguration, webResourceIntegration, webResourceUrlProvider, servletContextFactory, new TransformerCache(pluginEventManager, webResourceIntegration.getPluginAccessor()), resourceCompiler ); config.setStaticTransformers(staticTransformers); initialize(pluginEventManager, config); }
moduleDescriptor = webResourceIntegration.getPluginAccessor().getEnabledPluginModule(moduleKey); } catch (IllegalArgumentException e) { boolean found = tryResolveAsModule(requestCache, urlBuildingStrategy, moduleKey, orderedResourceKeys, superBatchResources, if (webResourceIntegration.getPluginAccessor().getPluginModule(moduleKey) != null)
Map<WebResource, CachedTransformers> webResourcesTransformations, Map<String, IntermediaryContextData> intermediaryContexts) { List<ModulesDescriptor> modulesDescriptors = integration.getPluginAccessor() .getEnabledModuleDescriptorsByClass(ModulesDescriptor.class);
final List<WebResourceModuleDescriptor> webResourceDescriptors = integration.getPluginAccessor() .getEnabledModuleDescriptorsByClass(WebResourceModuleDescriptor.class);
/** * Get Resource for Plugin. */ public Resource getPluginResource(String pluginKey, String name) { Plugin plugin = integration.getPluginAccessor().getPlugin(pluginKey); if (plugin == null) { return null; } ResourceLocation resourceLocation = plugin.getResourceLocation(DOWNLOAD_PARAM_VALUE, name); if (resourceLocation == null) { return null; } PluginResourceContainer resourceContainer = new PluginResourceContainer(new Snapshot(this), pluginKey, plugin.getDateLoaded(), getPluginVersionOrInstallTime(plugin, usePluginInstallTimeInsteadOfTheVersionForSnapshotPlugins)); Resource resource = buildResource(resourceContainer, resourceLocation); return resource; }
/** * Get not declared Resource. */ public Resource getModuleResource(String completeKey, String name) { // Confluence throws error if trying to query module with not complete key (with the plugin key for example). if (!isWebResourceKey(completeKey)) { return null; } ModuleDescriptor<?> moduleDescriptor = integration.getPluginAccessor().getEnabledPluginModule(completeKey); // In case of virtual context or super batch resource there would be null returned. if (moduleDescriptor == null) { return null; } ResourceLocation resourceLocation = moduleDescriptor.getResourceLocation(DOWNLOAD_PARAM_VALUE, name); if (resourceLocation == null) { return null; } Plugin plugin = moduleDescriptor.getPlugin(); Date updatedAt = (plugin.getDateLoaded() == null) ? new Date() : plugin.getDateLoaded(); PluginResourceContainer resourceContainer = new PluginResourceContainer(new Snapshot(this), completeKey, updatedAt, getPluginVersionOrInstallTime(plugin, usePluginInstallTimeInsteadOfTheVersionForSnapshotPlugins)); return buildResource(resourceContainer, resourceLocation); }
public PluginResourceLocatorImpl(final WebResourceIntegration webResourceIntegration, final ServletContextFactory servletContextFactory, final WebResourceUrlProvider webResourceUrlProvider, final ResourceBatchingConfiguration batchingConfiguration, final PluginEventManager pluginEventManager, final ResourceCompiler resourceCompiler) { Config config = new Config( batchingConfiguration, webResourceIntegration, webResourceUrlProvider, servletContextFactory, new TransformerCache(pluginEventManager, webResourceIntegration.getPluginAccessor()), resourceCompiler ); StaticTransformers staticTransformers = new DefaultStaticTransformers(new DefaultStaticTransformersSupplier( webResourceIntegration, webResourceUrlProvider, config.getCdnResourceUrlTransformer())); config.setStaticTransformers(staticTransformers); initialize(pluginEventManager, config); }
@Override protected String create() { // This transform's only "variable" is the context path, and hence is not even variable since the // context path is already in the url path. Therefore we don't need to contribute anything additional // to the hash - this transform is a "constant" and other transformers / conditions don't apply to data // uri's or images. final String version = Config.getPluginVersionOrInstallTime(webResourceIntegration.getPluginAccessor().getPlugin(parameters.getPluginKey()), usePluginInstallTimeInsteadOfTheVersionForSnapshotPlugins); String resourcePrefix = PATH_SEPARATOR + AbstractFileServerServlet.SERVLET_PATH + PATH_SEPARATOR + AbstractFileServerServlet.RESOURCE_URL_PREFIX; String localRelativeUrl = webResourceUrlProvider.getStaticResourcePrefix(version, UrlMode.RELATIVE) + resourcePrefix + PATH_SEPARATOR + parameters.getPluginKey() + ":" + parameters.getModuleKey() + PATH_SEPARATOR; if (requestCdnUrl) { final CDNStrategy cdnStrategy = webResourceIntegration.getCDNStrategy(); if (cdnStrategy == null || !cdnStrategy.supportsCdn()) { // This will throw an exception if we have the CDN parameter in the URL, but // webResourceIntegration.getCdnStrategy() returns null. This situation will occur // if the cdn strategy is changed (eg via dark feature) between url-generation time and // resource-fetch time. In this situation, it is correct to throw an exception - the alternative // is to poison the CDN-side cache with a resource that has not been transformed to CDN. throw new CdnStrategyChangedException("CDN strategy has changed between url generation time and resource fetch time"); } return cdnResourceUrlTransformer.getResourceCdnPrefix(localRelativeUrl); } else { return localRelativeUrl; } } };