/** * If minification enabled. */ public boolean isMinificationEnabled() { return !(Boolean.getBoolean(DISABLE_MINIFICATION) || PluginUtils.isAtlassianDevMode()); }
/** * Get a string containing the significant runtime environment details that may require a rebuild of the OSGi cache. * * @return a string containing significant runtime details. */ @VisibleForTesting String getRuntimeEnvironment() { //Two things currently: // - JDK version // - Startup timeout which may be cached in the transformed plugins. return String.format("java.version=%s,plugin.enable.timeout=%d", System.getProperty("java.version"), PluginUtils.getDefaultEnablingWaitPeriod()); }
public Iterable<Element> getModules(final InstallationMode installationMode) { return elements(getPluginElement()).stream() .filter(element -> { String name = element.getName(); return !(PLUGIN_INFO.equalsIgnoreCase(name) || RESOURCE.equalsIgnoreCase(name)); }) .filter(module -> { if (!PluginUtils.doesModuleElementApplyToApplication(module, applications, installationMode)) { log.debug("Ignoring module descriptor for this application: {}", module.attributeValue("key")); return false; } return true; }) .collect(Collectors.toList()); }
if (PluginUtils.doesPluginRequireRestart(plugin)) { if (oldPlugin == null) { markPluginInstallThatRequiresRestart(plugin); + "to the following modules: " + PluginUtils.getPluginModulesThatRequireRestart(plugin)); plugin = unloadablePlugin; } else { else if (oldPlugin != null && PluginUtils.doesPluginRequireRestart(oldPlugin)) {
private boolean requiresRestart() { return frameworkStarted && PluginUtils.doesPluginRequireRestart(this); }
private void markPluginUninstallThatRequiresRestart(final Plugin plugin) { log.info("Uninstalled plugin '{}' requires a restart due to the following modules: {}", plugin, PluginUtils.getPluginModulesThatRequireRestart(plugin)); updateRequiresRestartState(plugin.getKey(), PluginRestartState.REMOVE); }
/** * Determines if a module element applies to the current application by matching the 'application' attribute * to the set of applications. If the application is specified, but isn't in the set, we return false * * @param element The module element * @param applications The set of application applications * @return True if it should apply, false otherwise * @since 2.2.0 */ public static boolean doesModuleElementApplyToApplication(final Element element, final Set<Application> applications, final InstallationMode installationMode) { checkNotNull(element); checkNotNull(applications); final ModuleRestricts restricts = ModuleRestricts.parse(element); final boolean valid = restricts.isValidFor(applications, installationMode); if (!valid && logger.isDebugEnabled()) { logger.debug("Module '{}' with key '{}' is restricted to the following " + "applications {} and therefore does not apply to applications {}", element.getName(), element.attributeValue("key"), restricts, asString(applications)); } return valid; }
private void markPluginInstallThatRequiresRestart(final Plugin plugin) { log.info("Installed plugin '{}' requires a restart due to the following modules: {}", plugin, PluginUtils.getPluginModulesThatRequireRestart(plugin)); updateRequiresRestartState(plugin.getKey(), PluginRestartState.INSTALL); }
/** * Determines if a plugin requires a restart after being installed at runtime. Looks for the annotation * {@link RequiresRestart} on the plugin's module descriptors. * * @param plugin The plugin that was just installed at runtime, but not yet enabled * @return True if a restart is required * @since 2.1 */ public static boolean doesPluginRequireRestart(final Plugin plugin) { //PLUG-451: When in dev mode, plugins should not require a restart. if (isAtlassianDevMode()) { return false; } for (final ModuleDescriptor<?> descriptor : plugin.getModuleDescriptors()) { if (descriptor.getClass().getAnnotation(RequiresRestart.class) != null) { return true; } } return false; }
private byte[] generateManifest(JsonManifest descriptor) { Manifest mf = new Manifest(); mf.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); mf.getMainAttributes().putValue(Constants.BUNDLE_MANIFESTVERSION, "2"); mf.getMainAttributes().putValue(OsgiPlugin.ATLASSIAN_PLUGIN_KEY, descriptor.getKey()); mf.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, descriptor.getKey()); mf.getMainAttributes().putValue(Constants.BUNDLE_VERSION, cleanManifestValue(descriptor.getVersion())); mf.getMainAttributes().putValue(Constants.BUNDLE_NAME, cleanManifestValue(descriptor.getName())); mf.getMainAttributes().putValue(Constants.BUNDLE_DESCRIPTION, cleanManifestValue(descriptor.getDescription())); mf.getMainAttributes().putValue(Constants.IMPORT_PACKAGE, ConventionDescriptorGenerator.class.getPackage().getName()); mf.getMainAttributes().putValue("Spring-Context", "*;timeout:=" + PluginUtils.getDefaultEnablingWaitPeriod()); if (descriptor.getVendor() != null) { mf.getMainAttributes().putValue(Constants.BUNDLE_VENDOR, descriptor.getVendor().getName()); } ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { mf.write(bout); } catch (IOException e) { throw new RuntimeException("Should never happen", e); } return bout.toByteArray(); }
if (!PluginUtils.doesModuleElementApplyToApplication(component, context.getApplications(), context.getInstallationMode())) { continue;
private void markPluginUpgradeThatRequiresRestart(final Plugin plugin) { log.info("Upgraded plugin '{}' requires a restart due to the following modules: {}", plugin, PluginUtils.getPluginModulesThatRequireRestart(plugin)); updateRequiresRestartState(plugin.getKey(), PluginRestartState.UPGRADE); }
if (Boolean.getBoolean(ATLASSIAN_WEBRESOURCE_DISABLE_MINIFICATION) || PluginUtils.isAtlassianDevMode()) { return false;
}, PluginUtils.getDefaultEnablingWaitPeriod(), TimeUnit.SECONDS, 1);
public void execute(TransformContext context) throws PluginTransformationException { if (SpringHelper.shouldGenerateFile(context, SPRING_XML)) { Document springDoc = SpringHelper.createSpringDocument(); Element root = springDoc.getRootElement(); ServiceReference[] serviceReferences = context.getOsgiContainerManager().getRegisteredServices(); for (ComponentImport comp : context.getComponentImports().values()) { if (!PluginUtils.doesModuleElementApplyToApplication(comp.getSource(), context.getApplications(), context.getInstallationMode())) { continue; } Element osgiReference = root.addElement("osgi:reference"); // make sure the new bean id is not already in use. context.trackBean(comp.getKey(), BEAN_SOURCE); osgiReference.addAttribute("id", comp.getKey()); if (comp.getFilter() != null) { osgiReference.addAttribute("filter", comp.getFilter()); } Element interfaces = osgiReference.addElement("osgi:interfaces"); for (String infName : comp.getInterfaces()) { validateInterface(infName, context.getPluginFile().getName(), serviceReferences); context.getExtraImports().add(infName.substring(0, infName.lastIndexOf('.'))); Element e = interfaces.addElement("beans:value"); e.setText(infName); } } if (root.elements().size() > 0) { context.setShouldRequireSpring(true); context.getFileOverrides().put(SPRING_XML, SpringHelper.documentToBytes(springDoc)); } } }
if (isAtlassianDevMode() && pluginsInEnablingState.size() == 1) { final long currentTime = System.currentTimeMillis(); if (singlePluginTimeout == 0) {
if (PluginUtils.doesModuleElementApplyToApplication(compImport.getSource(), context.getApplications(), context.getInstallationMode()) && regInterfaces.containsAll(compImport.getInterfaces())) { found = false; break;
private void assertSpringAvailableIfRequired(final TransformContext context) { if (isAtlassianDevMode() && context.shouldRequireSpring()) { final String header = context.getManifest().getMainAttributes().getValue(SPRING_CONTEXT); if (header == null) { log.debug("Manifest has no 'Spring-Context:' header. Prefer the header 'Spring-Context: *' in the jar '{}'.", context.getPluginArtifact()); } else if (header.contains(";timeout:=")) { log.warn("Manifest contains a 'Spring-Context:' header with a timeout, namely '{}'. This can cause problems as the " + "timeout is server specific. Use the header 'Spring-Context: *' in the jar '{}'.", header, context.getPluginArtifact()); } // else there's a Spring-Context with no timeout:=, which is fine. } }
if (!PluginUtils.doesModuleElementApplyToApplication(e, context.getApplications(), context.getInstallationMode())) { continue;
public Config(ResourceBatchingConfiguration batchingConfiguration, WebResourceIntegration integration, WebResourceUrlProvider urlProvider, ServletContextFactory servletContextFactory, TransformerCache transformerCache, ResourceCompiler resourceCompiler) { this.batchingConfiguration = batchingConfiguration; this.integration = integration; this.urlProvider = urlProvider; this.servletContextFactory = servletContextFactory; this.transformerCache = transformerCache; this.isContentCacheEnabled = !(Boolean.getBoolean(PluginUtils.WEBRESOURCE_DISABLE_FILE_CACHE) || PluginUtils.isAtlassianDevMode()); this.isUrlCachingEnabled = !Boolean.getBoolean(DISABLE_URL_CACHING); this.contentCacheSize = Integer.getInteger(PluginUtils.WEBRESOURCE_FILE_CACHE_SIZE, 1000); this.incrementalCacheSize = Integer.getInteger(INCREMENTAL_CACHE_SIZE, 1000); this.urlCacheSize = Integer.getInteger(PluginUtils.WEBRESOURCE_FILE_CACHE_SIZE, 200); cdnResourceUrlTransformer = new CdnResourceUrlTransformerImpl(this); this.resourceCompiler = resourceCompiler == null ? new NoOpResourceCompiler() : resourceCompiler; this.usePluginInstallTimeInsteadOfTheVersionForSnapshotPlugins = integration.usePluginInstallTimeInsteadOfTheVersionForSnapshotPlugins(); this.syncContextCreated = false; }