001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.theme.migration.service; 018 019import org.nuxeo.ecm.web.resources.api.service.WebResourceManager; 020import org.nuxeo.ecm.web.resources.core.ResourceDescriptor; 021import org.nuxeo.runtime.api.Framework; 022import org.nuxeo.runtime.logging.DeprecationLogger; 023import org.nuxeo.runtime.model.ComponentInstance; 024import org.nuxeo.runtime.model.DefaultComponent; 025 026/** 027 * Compat service displaying migration information for old extension points. 028 * 029 * @since 7.4 030 */ 031public class ThemeMigrationService extends DefaultComponent { 032 033 protected static final String XP = "org.nuxeo.theme.services.ThemeService"; 034 035 protected static final String WR_XP = "org.nuxeo.ecm.platform.WebResources"; 036 037 @Override 038 public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 039 if ("resources".equals(extensionPoint)) { 040 if (contribution instanceof ResourceDescriptor) { 041 ResourceDescriptor r = (ResourceDescriptor) contribution; 042 String message = String.format("Resource '%s' on component %s should now be contributed to extension " 043 + "point '%s': a compatibility registration was performed but it may not be " + "accurate.", 044 r.getName(), contributor.getName(), WR_XP); 045 DeprecationLogger.log(message, "7.4"); 046 Framework.getRuntime().getWarnings().add(message); 047 // ensure path is absolute, consider that resource is in the war, and if not, user will have to declare 048 // it directly to the WRM endpoint 049 String path = r.getPath(); 050 if (path != null && !path.startsWith("/")) { 051 r.setUri("/" + path); 052 } 053 WebResourceManager wrm = Framework.getService(WebResourceManager.class); 054 wrm.registerResource(r); 055 } else { 056 String message = String.format("Warning: unknown contribution to target extension point '%s' of '%s'. " 057 + "Check your extension in component %s", extensionPoint, XP, contributor.getName()); 058 DeprecationLogger.log(message, "7.4"); 059 Framework.getRuntime().getWarnings().add(message); 060 } 061 } else { 062 String message = String.format("Warning: target extension point '%s' of '%s'" 063 + " is unknown as it has been removed since 7.4. Check your extension in component %s", 064 extensionPoint, XP, contributor.getName()); 065 DeprecationLogger.log(message, "7.4"); 066 Framework.getRuntime().getWarnings().add(message); 067 } 068 } 069 070 @Override 071 public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 072 if ("resources".equals(extensionPoint) && contribution instanceof ResourceDescriptor) { 073 ResourceDescriptor r = (ResourceDescriptor) contribution; 074 WebResourceManager wrm = Framework.getService(WebResourceManager.class); 075 wrm.unregisterResource(r); 076 } else { 077 // NOOP 078 } 079 } 080 081}