### Eclipse Workspace Patch 1.0 #P Ametys - Plugin SkinCommons Index: main/plugin-skincommons/sitemap.xmap =================================================================== --- main/plugin-skincommons/sitemap.xmap (revision 37228) +++ main/plugin-skincommons/sitemap.xmap (working copy) @@ -37,7 +37,7 @@ <map:parameter name="prefix" value="/plugins/skincommons/preview"/> </map:act> <map:act type="set-skin-location"> - <map:parameter name="skin-location" value="WEB-INF/data/skins/temp"/> + <map:parameter name="skin-location" value="skins/temp"/> </map:act> <map:act type="set-header"> <map:parameter name="Cache-Control" value="no-store"/> Index: main/plugin-skincommons/src/org/ametys/plugins/skincommons/SkinEditionHelper.java =================================================================== --- main/plugin-skincommons/src/org/ametys/plugins/skincommons/SkinEditionHelper.java (revision 37228) +++ main/plugin-skincommons/src/org/ametys/plugins/skincommons/SkinEditionHelper.java (working copy) @@ -47,6 +47,7 @@ import org.ametys.core.cocoon.XMLResourceBundleFactory; import org.ametys.plugins.repository.metadata.UnknownMetadataException; import org.ametys.runtime.plugin.component.AbstractLogEnabled; +import org.ametys.runtime.servlet.RuntimeConfig; import org.ametys.web.cache.CacheHelper; import org.ametys.web.cache.pageelement.PageElementCache; import org.ametys.web.cocoon.I18nTransformer; @@ -297,7 +298,7 @@ } } - _i18nFactory.invalidateCatalogue("context://WEB-INF/data/skins/temp/" + skinName + "/i18n", "messages", localName); + _i18nFactory.invalidateCatalogue("ametys-home://skins/temp/" + skinName + "/i18n", "messages", localName); } catch (ComponentException e) { @@ -312,7 +313,7 @@ */ public File getTempDirectory (String skinName) { - return new File (_cocoonContext.getRealPath("/WEB-INF/data/skins/temp/" + skinName)); + return FileUtils.getFile(RuntimeConfig.getInstance().getAmetysHome(), "skins", "temp", skinName); } /** @@ -322,7 +323,7 @@ */ public File getWorkDirectory (String skinName) { - return new File (_cocoonContext.getRealPath("/WEB-INF/data/skins/work/" + skinName)); + return FileUtils.getFile(RuntimeConfig.getInstance().getAmetysHome(), "skins", "work", skinName); } /** @@ -333,7 +334,8 @@ */ public File getBackupDirectory (String skinName, Date date) { - return new File(_cocoonContext.getRealPath("/WEB-INF/data/skins/backup/" + skinName + "/" + _DATE_FORMAT.format(date))); + String dateStr = _DATE_FORMAT.format(date); + return FileUtils.getFile(RuntimeConfig.getInstance().getAmetysHome(), "skins", "backup", skinName, dateStr); } /** @@ -343,7 +345,7 @@ */ public File getRootBackupDirectory (String skinName) { - return new File(_cocoonContext.getRealPath("/WEB-INF/data/skins/backup/" + skinName)); + return FileUtils.getFile(RuntimeConfig.getInstance().getAmetysHome(), "skins", "backup", skinName); } /** @@ -353,7 +355,7 @@ */ public String getTempDirectoryURI (String skinName) { - return "context://WEB-INF/data/skins/temp/" + skinName; + return "ametys-home://skins/temp/" + skinName; } /** @@ -363,7 +365,7 @@ */ public String getWorkDirectoryURI (String skinName) { - return "context://WEB-INF/data/skins/work/" + skinName; + return "ametys-home://skins/work/" + skinName; } /** @@ -374,7 +376,7 @@ */ public String getBackupDirectoryURI (String skinName, Date date) { - return "context://WEB-INF/data/skins/backup/" + skinName + "/" + _DATE_FORMAT.format(date); + return "ametys-home://skins/backup/" + skinName + "/" + _DATE_FORMAT.format(date); } /** @@ -384,7 +386,7 @@ */ public String getRootBackupDirectoryURI (String skinName) { - return "context://WEB-INF/data/skins/backup/" + skinName; + return "ametys-home://skins/backup/" + skinName; } /** #P Ametys - Plugin ContentIO Index: main/plugin-contentio/src/org/ametys/plugins/contentio/ContentImportManager.java =================================================================== --- main/plugin-contentio/src/org/ametys/plugins/contentio/ContentImportManager.java (revision 37228) +++ main/plugin-contentio/src/org/ametys/plugins/contentio/ContentImportManager.java (working copy) @@ -43,6 +43,7 @@ import org.xml.sax.InputSource; import org.ametys.plugins.contentio.in.xml.XmlContentImporter; +import org.ametys.runtime.servlet.RuntimeConfig; /** * Component handling the import of contents, based on the {@link ContentImporter} multiple extension point. @@ -123,11 +124,11 @@ { String baseName = FilenameUtils.getBaseName(name); String ext = FilenameUtils.getExtension(name); - tempFile = File.createTempFile(baseName, ext); + tempFile = File.createTempFile(baseName, ext, RuntimeConfig.getInstance().getTmpDir()); } else { - tempFile = File.createTempFile("content-import-", null); + tempFile = File.createTempFile("content-import-", null, RuntimeConfig.getInstance().getTmpDir()); } // Copy the stream to the temporary file. #P Ametys - 01 Runtime Index: main/kernel/src/org/ametys/runtime/cocoon/cocoon.xconf =================================================================== --- main/kernel/src/org/ametys/runtime/cocoon/cocoon.xconf (revision 37352) +++ main/kernel/src/org/ametys/runtime/cocoon/cocoon.xconf (working copy) @@ -126,6 +126,7 @@ <component-instance class="org.ametys.runtime.cocoon.source.ZipSourceFactory" name="zip"/> <component-instance class="org.ametys.runtime.plugin.PluginSourceFactory" name="plugin"/> <component-instance class="org.ametys.runtime.workspace.WorkspaceSourceFactory" name="workspace"/> + <component-instance class="org.ametys.runtime.data.AmetysHomeSourceFactory" name="ametys-home"/> <component-instance class="org.apache.cocoon.components.source.impl.ContextSourceFactory" name="context"/> <component-instance class="org.apache.cocoon.components.source.impl.SitemapSourceFactory" name="cocoon"/> Index: main/kernel/src/org/ametys/runtime/servlet/RuntimeConfig.java =================================================================== --- main/kernel/src/org/ametys/runtime/servlet/RuntimeConfig.java (revision 37352) +++ main/kernel/src/org/ametys/runtime/servlet/RuntimeConfig.java (working copy) @@ -63,6 +63,9 @@ /* Locations of external workspaces */ private Map<String, File> _externalWorkspaces = new HashMap<>(); + private File _ametysHome; + private File _tmpDir; + private RuntimeConfig() { // empty constructor @@ -83,7 +86,7 @@ } /** - * Returns true if the Runtime has been configured (ie. if the {@link #configure(Configuration, Configuration, String)} method has been called. + * Returns true if the Runtime has been configured (ie. if the {@link #configure(Configuration, Configuration, File, String)} method has been called. * @return true if the Runtime has been configured. */ public static boolean isConfigured() @@ -98,13 +101,17 @@ * Be aware that this can cause the application to become unstable.</b> * @param runtimeConf the Configuration of the Runtime kernel (ie the contents of the WEB-INF/param/runtime.xml file) * @param externalConf the Configuration of external locations (ie the contents of the WEB-INF/param/external-locations.xml file) + * @param ametysHome The ametys home directory * @param contextPath the application context path */ - public static synchronized void configure(Configuration runtimeConf, Configuration externalConf, String contextPath) + public static synchronized void configure(Configuration runtimeConf, Configuration externalConf, File ametysHome, String contextPath) { __config = new RuntimeConfig(); __config._contextPath = contextPath; + __config._ametysHome = ametysHome; + __config._tmpDir = new File(ametysHome, "tmp"); + __config._tmpDir.mkdirs(); // runtimeConfig is null if the runtime.xml could not be read for any reason if (runtimeConf != null) @@ -377,4 +384,22 @@ { return _buildDate; } + + /** + * Returns the Ametys home directory. Cannot be null. + * @return The Ametys home directory. + */ + public File getAmetysHome() + { + return _ametysHome; + } + + /** + * Returns the Ametys temporary directory. Cannot be null + * @return The Ametys temporary directory. + */ + public File getTmpDir() + { + return _tmpDir; + } } Index: main/kernel/src/org/ametys/runtime/servlet/RuntimeServlet.java =================================================================== --- main/kernel/src/org/ametys/runtime/servlet/RuntimeServlet.java (revision 37352) +++ main/kernel/src/org/ametys/runtime/servlet/RuntimeServlet.java (working copy) @@ -60,10 +60,12 @@ import org.apache.cocoon.util.log.SLF4JLoggerAdapter; import org.apache.cocoon.util.log.SLF4JLoggerManager; import org.apache.cocoon.xml.XMLUtils; +import org.apache.commons.collections.EnumerationUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.commons.lang.time.StopWatch; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.xml.DOMConfigurator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -72,6 +74,8 @@ import org.ametys.runtime.config.Config; import org.ametys.runtime.config.ConfigManager; +import org.ametys.runtime.data.AmetysHomeLock; +import org.ametys.runtime.data.AmetysHomeLockException; import org.ametys.runtime.plugin.Init; import org.ametys.runtime.plugin.InitExtensionPoint; import org.ametys.runtime.plugin.PluginsManager; @@ -100,6 +104,12 @@ /** The config file relative path */ public static final String CONFIG_RELATIVE_PATH = "/WEB-INF/config/config.xml"; + + /** Name of the servlet initialization parameter for the ametys home property */ + public static final String AMETYS_HOME_PROPERTY = "ametys.home.property"; + + /** The default ametys home path (relative to the servlet context) */ + public static final String AMETYS_HOME_DEFAULT = "/WEB-INF/data"; /** The run modes */ public enum RunMode @@ -126,6 +136,9 @@ private File _uploadDir; private File _cacheDir; + private File _ametysHome; + private AmetysHomeLock _ametysHomeLock; + private Logger _logger; private LoggerManager _loggerManager; @@ -177,6 +190,10 @@ // Configuration file Config.setFilename(_servletContext.getRealPath(CONFIG_RELATIVE_PATH)); + // Init the Ametys home directory and lock before setting the logger. + // The log folder is located in the Ametys home directory. + _initAmetysHome(); + // Init logger _initLogger(); @@ -207,6 +224,51 @@ } } + private void _initAmetysHome() throws AmetysHomeLockException + { + String ametysHomePath = null; + + boolean hasAmetysHomeProp = EnumerationUtils.toList(getInitParameterNames()).contains(AMETYS_HOME_PROPERTY); + if (!hasAmetysHomeProp) + { + System.out.println(String.format("[INFO] The '%s' servlet initialization parameter was not found. The Ametys home directory default value will be used '%s'", + AMETYS_HOME_PROPERTY, AMETYS_HOME_DEFAULT)); + } + else + { + String ametysHomeEnv = getInitParameter(AMETYS_HOME_PROPERTY); + if (StringUtils.isEmpty(ametysHomeEnv)) + { + System.out.println(String.format("[WARN] The '%s' servlet initialization parameter appears to be empty. Ametys home directory default value will be used '%s'", + AMETYS_HOME_PROPERTY, AMETYS_HOME_DEFAULT)); + } + else + { + ametysHomePath = System.getenv(ametysHomeEnv); + if (StringUtils.isEmpty(ametysHomePath)) + { + System.out.println(String.format( + "[WARN] The '%s' environment variable was not found or was empty. servlet initialization parameter appears to be empty. Ametys home directory default value will be used '%s'", + ametysHomeEnv, AMETYS_HOME_DEFAULT)); + } + } + } + + if (StringUtils.isEmpty(ametysHomePath)) + { + ametysHomePath = _servletContext.getRealPath(AMETYS_HOME_DEFAULT); + } + + System.out.println("Acquiring lock on " + ametysHomePath); + + // Acquire the lock on Ametys home + _ametysHome = new File(ametysHomePath); + _ametysHome.mkdirs(); + + _ametysHomeLock = new AmetysHomeLock(_ametysHome); + _ametysHomeLock.acquire(); + } + private void _initAmetys() throws Exception { // WEB-INF/param/runtime.xml loading @@ -216,7 +278,7 @@ // Upload initialization _maxUploadSize = DEFAULT_MAX_UPLOAD_SIZE; - _uploadDir = new File(_servletContext.getRealPath("/WEB-INF/data/uploads")); + _uploadDir = new File(RuntimeConfig.getInstance().getAmetysHome(), "uploads"); if (ConfigManager.getInstance().isComplete()) { @@ -226,23 +288,6 @@ // if the feature core/runtime.upload is deactivated, use the default value (10 Mb) _maxUploadSize = maxUploadSizeParam.intValue(); } - - String uploadDirParam = Config.getInstance().getValueAsString("runtime.upload.dir"); - if (uploadDirParam != null) - { - File uploadDir = new File(uploadDirParam); - - if (uploadDir.isAbsolute()) - { - // Yes : keep it as is - _uploadDir = uploadDir; - } - else - { - // No : consider it relative to context path - _uploadDir = new File(_servletContextPath, uploadDirParam); - } - } } _uploadDir.mkdirs(); @@ -262,9 +307,9 @@ // Hack to have context-relative log files, because of lack in configuration capabilities in log4j. // If there are more than one Ametys in the same JVM, the property will be successively set for each instance, // so we heavily rely on DOMConfigurator beeing synchronous. - System.setProperty("ametys.log4j.contextPath", _servletContextPath); + System.setProperty("ametys.home.dir", _ametysHome.getAbsolutePath()); DOMConfigurator.configure(logj4fFile); - System.clearProperty("ametys.log4j.contextPath"); + System.clearProperty("ametys.home.dir"); _loggerManager = new SLF4JLoggerManager(); _logger = LoggerFactory.getLogger(getClass()); @@ -361,7 +406,7 @@ throw new ServletException("Unable to load external locations values at WEB-INF/param/external-locations.xml", e); } - RuntimeConfig.configure(runtimeConf, externalConf, _servletContextPath); + RuntimeConfig.configure(runtimeConf, externalConf, _ametysHome, _servletContextPath); } @Override @@ -372,7 +417,13 @@ _logger.debug("Servlet destroyed - disposing Cocoon"); _disposeCocoon(); } - + + if (_ametysHomeLock != null) + { + _ametysHomeLock.release(); + _ametysHomeLock = null; + } + _avalonContext = null; _logger = null; _loggerManager = null; Index: main/plugin-admin/i18n/messages_en.xml =================================================================== --- main/plugin-admin/i18n/messages_en.xml (revision 37352) +++ main/plugin-admin/i18n/messages_en.xml (working copy) @@ -47,6 +47,8 @@ <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_JVM_VENDOR">Vendor</message> <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_JVM_NAME">JVM</message> <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_JVM_TIME">Startup</message> + <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_AMETYS">Ametys</message> + <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_AMETYS_AMETYS_HOME">Data directory</message> <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_MEM">Memory usage</message> <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_MEM_HEAP">Main</message> <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_MEM_NHEAP">Internal</message> Index: main/plugin-admin/i18n/messages_fr.xml =================================================================== --- main/plugin-admin/i18n/messages_fr.xml (revision 37352) +++ main/plugin-admin/i18n/messages_fr.xml (working copy) @@ -47,6 +47,8 @@ <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_JVM_VENDOR">Editeur</message> <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_JVM_NAME">JVM</message> <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_JVM_TIME">Démarrage</message> + <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_AMETYS">Ametys</message> + <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_AMETYS_AMETYS_HOME">Répertoire des données</message> <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_MEM">Utilisation de la mémoire</message> <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_MEM_HEAP">Principale</message> <message key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_MEM_NHEAP">Interne</message> Index: main/plugin-admin/pages/jvmstatus/jvmstatus.xsl =================================================================== --- main/plugin-admin/pages/jvmstatus/jvmstatus.xsl (revision 37352) +++ main/plugin-admin/pages/jvmstatus/jvmstatus.xsl (working copy) @@ -73,6 +73,11 @@ <span id="startTime"><i18n:date pattern="long" src-pattern="yyyy-MM-dd'T'HH:mm" value="{startTime}"/> <i18n:time pattern="short" src-pattern="yyyy-MM-dd'T'HH:mm" value="{startTime}"/></span> </div> </div> + + <div id="ametys"> + <div class="label"><i18n:text i18n:key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_AMETYS_AMETYS_HOME"/></div> + <xsl:value-of select="ametysHome"/> + </div> <div id="memory"> <div class="label"><i18n:text i18n:key="PLUGINS_ADMIN_STATUS_TAB_GENERAL_MEM_HEAP"/></div> Index: main/plugin-admin/resources/js/Ametys/plugins/admin/jvmstatus/JVMStatusTool.js =================================================================== --- main/plugin-admin/resources/js/Ametys/plugins/admin/jvmstatus/JVMStatusTool.js (revision 37352) +++ main/plugin-admin/resources/js/Ametys/plugins/admin/jvmstatus/JVMStatusTool.js (working copy) @@ -131,6 +131,11 @@ title : "<i18n:text i18n:key='PLUGINS_ADMIN_STATUS_TAB_GENERAL_JVM'/>", html: '' },{ + xtype: 'panel', + itemId: 'ametys', + title : "<i18n:text i18n:key='PLUGINS_ADMIN_STATUS_TAB_GENERAL_AMETYS'/>", + html: '' + },{ xtype: 'panel', itemId: 'memory', title : "<i18n:text i18n:key='PLUGINS_ADMIN_STATUS_TAB_GENERAL_MEM'/>", @@ -185,13 +190,16 @@ */ _refreshCb: function (response, args) { - // Html for the 4 panels of the tool + // Html for the 5 panels of the tool var html = Ext.dom.Query.jsSelect("div[id='system']", response)[0].innerHTML; this._jvmStatusPanel.down('#system').update(html); html = Ext.dom.Query.jsSelect("div[id='java']", response)[0].innerHTML; this._jvmStatusPanel.down('#jvm').update(html); + html = Ext.dom.Query.jsSelect("div[id='ametys']", response)[0].innerHTML; + this._jvmStatusPanel.down('#ametys').update(html); + html = Ext.dom.Query.jsSelect("div[id='memory']", response)[0].innerHTML; this._jvmStatusPanel.down('#memory').update(html); Index: main/plugin-admin/sitemap.xmap =================================================================== --- main/plugin-admin/sitemap.xmap (revision 37352) +++ main/plugin-admin/sitemap.xmap (working copy) @@ -147,7 +147,7 @@ <map:act type="set-header"> <map:parameter name="Content-Disposition" value="attachment"/> </map:act> - <map:read src="context://WEB-INF/logs/{1}.log"/> + <map:read src="ametys-home://logs/{1}.log"/> </map:match> <map:match pattern="logs/download.zip"> <map:act type="set-header"> Index: main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/GeneralStatusGenerator.java =================================================================== --- main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/GeneralStatusGenerator.java (revision 37352) +++ main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/GeneralStatusGenerator.java (working copy) @@ -28,6 +28,7 @@ import org.xml.sax.SAXException; import org.ametys.runtime.parameter.ParameterHelper; +import org.ametys.runtime.servlet.RuntimeConfig; /** @@ -62,6 +63,8 @@ XMLUtils.createElement(contentHandler, "jvmName", rBean.getVmName()); XMLUtils.createElement(contentHandler, "startTime", ParameterHelper.valueToString(new Date(rBean.getStartTime()))); + XMLUtils.createElement(contentHandler, "ametysHome", RuntimeConfig.getInstance().getAmetysHome().getPath()); + XMLUtils.endElement(contentHandler, "characteristics"); contentHandler.endDocument(); } Index: main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/MonitoringConstants.java =================================================================== --- main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/MonitoringConstants.java (revision 37352) +++ main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/MonitoringConstants.java (working copy) @@ -20,8 +20,11 @@ */ public interface MonitoringConstants { - /** Webapp path for storing RRD files. */ - public static final String RRD_STORAGE_PATH = "/WEB-INF/data/monitoring"; + /** + * The name of the monitoring directory, located in the Ametys home + * directory + */ + public static final String RRD_STORAGE_DIRECTORY = "monitoring"; /** Extension of RRD files. */ public static final String RRD_EXT = ".rrd"; @@ -109,6 +112,5 @@ return 60 * 60 * hours * days; } - } } Index: main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/MonitoringExtensionPoint.java =================================================================== --- main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/MonitoringExtensionPoint.java (revision 37352) +++ main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/MonitoringExtensionPoint.java (working copy) @@ -18,12 +18,13 @@ import java.io.File; import java.io.IOException; -import org.apache.cocoon.Constants; +import org.apache.commons.io.FileUtils; import org.rrd4j.core.RrdDb; import org.rrd4j.core.RrdDef; import org.ametys.runtime.plugin.ExtensionPoint; import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint; +import org.ametys.runtime.servlet.RuntimeConfig; /** * {@link ExtensionPoint} for collecting sample of data in order to be @@ -39,10 +40,8 @@ { super.initializeExtensions(); - org.apache.cocoon.environment.Context cocoonContext = (org.apache.cocoon.environment.Context) _context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); - String rrdStoragePath = cocoonContext.getRealPath(RRD_STORAGE_PATH); - File rrdStorageDir = new File(rrdStoragePath); - + File rrdStorageDir = FileUtils.getFile(RuntimeConfig.getInstance().getAmetysHome(), RRD_STORAGE_DIRECTORY); + if (!rrdStorageDir.exists()) { if (!rrdStorageDir.mkdirs()) Index: main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/RRDGraphReader.java =================================================================== --- main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/RRDGraphReader.java (revision 37352) +++ main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/RRDGraphReader.java (working copy) @@ -22,39 +22,38 @@ import javax.imageio.ImageIO; -import org.apache.avalon.framework.context.Context; -import org.apache.avalon.framework.context.ContextException; -import org.apache.avalon.framework.context.Contextualizable; +import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; -import org.apache.cocoon.Constants; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.reading.Reader; import org.apache.cocoon.reading.ServiceableReader; +import org.apache.commons.io.FileUtils; import org.rrd4j.graph.RrdGraph; import org.rrd4j.graph.RrdGraphDef; import org.xml.sax.SAXException; +import org.ametys.runtime.servlet.RuntimeConfig; + /** * {@link Reader} for exposing a monitoring graph. */ -public class RRDGraphReader extends ServiceableReader implements Contextualizable, MonitoringConstants +public class RRDGraphReader extends ServiceableReader implements Initializable, MonitoringConstants { private String _rrdStoragePath; private MonitoringExtensionPoint _monitoringExtensionPoint; - public void contextualize(Context context) throws ContextException - { - org.apache.cocoon.environment.Context cocoonContext = (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); - _rrdStoragePath = cocoonContext.getRealPath(RRD_STORAGE_PATH); - } - @Override public void service(ServiceManager smanager) throws ServiceException { super.service(smanager); _monitoringExtensionPoint = (MonitoringExtensionPoint) smanager.lookup(MonitoringExtensionPoint.ROLE); } + + public void initialize() throws Exception + { + _rrdStoragePath = FileUtils.getFile(RuntimeConfig.getInstance().getAmetysHome(), RRD_STORAGE_DIRECTORY).getPath(); + } @Override public String getMimeType() Index: main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/RRDXmlExportReader.java =================================================================== --- main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/RRDXmlExportReader.java (revision 37352) +++ main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/RRDXmlExportReader.java (working copy) @@ -18,29 +18,28 @@ import java.io.File; import java.io.IOException; -import org.apache.avalon.framework.context.Context; -import org.apache.avalon.framework.context.ContextException; -import org.apache.avalon.framework.context.Contextualizable; -import org.apache.cocoon.Constants; +import org.apache.avalon.framework.activity.Initializable; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.reading.AbstractReader; import org.apache.cocoon.reading.Reader; +import org.apache.commons.io.FileUtils; import org.rrd4j.core.RrdDb; import org.xml.sax.SAXException; +import org.ametys.runtime.servlet.RuntimeConfig; + /** * {@link Reader} for exporting sample datas. */ -public class RRDXmlExportReader extends AbstractReader implements Contextualizable, MonitoringConstants +public class RRDXmlExportReader extends AbstractReader implements Initializable, MonitoringConstants { private String _rrdStoragePath; - public void contextualize(Context context) throws ContextException + public void initialize() throws Exception { - org.apache.cocoon.environment.Context cocoonContext = (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); - _rrdStoragePath = cocoonContext.getRealPath(RRD_STORAGE_PATH); + _rrdStoragePath = FileUtils.getFile(RuntimeConfig.getInstance().getAmetysHome(), RRD_STORAGE_DIRECTORY).getPath(); } - + @Override public String getMimeType() { Index: main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/RRDsFeederTimerTask.java =================================================================== --- main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/RRDsFeederTimerTask.java (revision 37352) +++ main/plugin-admin/src/org/ametys/runtime/plugins/admin/jvmstatus/monitoring/RRDsFeederTimerTask.java (working copy) @@ -23,17 +23,16 @@ import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.component.Component; -import org.apache.avalon.framework.context.Context; -import org.apache.avalon.framework.context.ContextException; -import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.LogEnabled; import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; -import org.apache.cocoon.Constants; +import org.apache.commons.io.FileUtils; import org.rrd4j.core.RrdDb; +import org.ametys.runtime.servlet.RuntimeConfig; + /** * {@link TimerTask} for creating and feeding RRDs files in order to * produce graphs for monitoring: @@ -45,7 +44,7 @@ * <li>Servlet Engine session count * </ul> */ -public class RRDsFeederTimerTask extends TimerTask implements Component, LogEnabled, Contextualizable, Serviceable, Initializable, Disposable, MonitoringConstants +public class RRDsFeederTimerTask extends TimerTask implements Component, LogEnabled, Serviceable, Initializable, Disposable, MonitoringConstants { private Logger _logger; private MonitoringExtensionPoint _monitoringExtensionPoint; @@ -56,12 +55,6 @@ { _logger = logger; } - - public void contextualize(Context context) throws ContextException - { - org.apache.cocoon.environment.Context cocoonContext = (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); - _rrdStoragePath = cocoonContext.getRealPath(RRD_STORAGE_PATH); - } public void service(ServiceManager manager) throws ServiceException { @@ -70,6 +63,8 @@ public void initialize() throws Exception { + _rrdStoragePath = FileUtils.getFile(RuntimeConfig.getInstance().getAmetysHome(), RRD_STORAGE_DIRECTORY).getPath(); + _logger.debug("Starting timer"); // Daemon thread _timer = new Timer("RRDFeeder", true); Index: main/plugin-admin/src/org/ametys/runtime/plugins/admin/logs/LogsClientSideElement.java =================================================================== --- main/plugin-admin/src/org/ametys/runtime/plugins/admin/logs/LogsClientSideElement.java (revision 37352) +++ main/plugin-admin/src/org/ametys/runtime/plugins/admin/logs/LogsClientSideElement.java (working copy) @@ -47,7 +47,7 @@ public class LogsClientSideElement extends StaticClientSideElement { /** The path to the application's logs folder */ - private static final String __LOGS_BASE = "context://WEB-INF/logs/"; + private static final String __LOGS_BASE = "ametys-home://logs/"; /** The Excalibur source resolver */ private SourceResolver _sourceResolver; Index: main/plugin-admin/src/org/ametys/runtime/plugins/admin/logs/LogsDownloadGenerator.java =================================================================== --- main/plugin-admin/src/org/ametys/runtime/plugins/admin/logs/LogsDownloadGenerator.java (revision 37352) +++ main/plugin-admin/src/org/ametys/runtime/plugins/admin/logs/LogsDownloadGenerator.java (working copy) @@ -44,7 +44,7 @@ { AttributesImpl zipAttrs = new AttributesImpl(); zipAttrs.addAttribute("", "name", "name", "CDATA", file); - zipAttrs.addAttribute("", "src", "src", "CDATA", "context://WEB-INF/logs/" + file); + zipAttrs.addAttribute("", "src", "src", "CDATA", "ametys-home://logs/" + file); XMLUtils.startElement(contentHandler, ZipArchiveSerializer.ZIP_NAMESPACE, "entry", zipAttrs); XMLUtils.endElement(contentHandler, ZipArchiveSerializer.ZIP_NAMESPACE, "entry"); } Index: main/plugin-admin/src/org/ametys/runtime/plugins/admin/logs/LogsGenerator.java =================================================================== --- main/plugin-admin/src/org/ametys/runtime/plugins/admin/logs/LogsGenerator.java (revision 37352) +++ main/plugin-admin/src/org/ametys/runtime/plugins/admin/logs/LogsGenerator.java (working copy) @@ -52,7 +52,7 @@ private void _logs() throws IOException, SAXException { - TraversableSource logsDirectorySource = (TraversableSource) resolver.resolveURI("context://WEB-INF/logs"); + TraversableSource logsDirectorySource = (TraversableSource) resolver.resolveURI("ametys-home://logs"); try { Index: main/plugin-admin/src/org/ametys/runtime/plugins/admin/system/GetSystemAnnouncements.java =================================================================== --- main/plugin-admin/src/org/ametys/runtime/plugins/admin/system/GetSystemAnnouncements.java (revision 37352) +++ main/plugin-admin/src/org/ametys/runtime/plugins/admin/system/GetSystemAnnouncements.java (working copy) @@ -20,9 +20,6 @@ import java.util.List; import java.util.Map; -import org.apache.avalon.framework.context.Context; -import org.apache.avalon.framework.context.ContextException; -import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; @@ -38,18 +35,10 @@ /** * Get the system announces from the system.xml file */ -public class GetSystemAnnouncements extends ServiceableAction implements Contextualizable +public class GetSystemAnnouncements extends ServiceableAction { private SystemHelper _systemHelper; - private org.apache.cocoon.environment.Context _environmentContext; - - @Override - public void contextualize(Context context) throws ContextException - { - _environmentContext = (org.apache.cocoon.environment.Context) context.get(org.apache.cocoon.Constants.CONTEXT_ENVIRONMENT_CONTEXT); - } - @Override public void service(ServiceManager serviceManager) throws ServiceException { @@ -68,8 +57,7 @@ List<Map<String, String>> announcements = new ArrayList<> (); - String contextPath = _environmentContext.getRealPath("/"); - SystemAnnouncement systemAnnouncement = _systemHelper.readValues(contextPath); + SystemAnnouncement systemAnnouncement = _systemHelper.readValues(); Map<String, String> messages = systemAnnouncement.getMessages(); Index: main/plugin-admin/src/org/ametys/runtime/plugins/admin/system/SystemAnnouncementClientSideElement.java =================================================================== --- main/plugin-admin/src/org/ametys/runtime/plugins/admin/system/SystemAnnouncementClientSideElement.java (revision 37352) +++ main/plugin-admin/src/org/ametys/runtime/plugins/admin/system/SystemAnnouncementClientSideElement.java (working copy) @@ -17,9 +17,6 @@ import java.util.Map; -import org.apache.avalon.framework.context.Context; -import org.apache.avalon.framework.context.ContextException; -import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; @@ -27,20 +24,12 @@ /** * This client side element toggles controller according system announcement's state - * */ -public class SystemAnnouncementClientSideElement extends StaticClientSideElement implements Contextualizable +public class SystemAnnouncementClientSideElement extends StaticClientSideElement { - private org.apache.cocoon.environment.Context _environmentContext; private SystemHelper _systemHelper; @Override - public void contextualize(Context context) throws ContextException - { - _environmentContext = (org.apache.cocoon.environment.Context) context.get(org.apache.cocoon.Constants.CONTEXT_ENVIRONMENT_CONTEXT); - } - - @Override public void service(ServiceManager smanager) throws ServiceException { super.service(smanager); @@ -52,8 +41,7 @@ { Map<String, Object> parameters = super.getParameters(contextualParameters); - String contextPath = _environmentContext.getRealPath("/"); - boolean isAvailable = _systemHelper.isSystemAnnouncementAvailable(contextPath); + boolean isAvailable = _systemHelper.isSystemAnnouncementAvailable(); if ("true".equals(parameters.get("toggle-enabled"))) { Index: main/plugin-admin/src/org/ametys/runtime/plugins/admin/system/SystemHelper.java =================================================================== --- main/plugin-admin/src/org/ametys/runtime/plugins/admin/system/SystemHelper.java (revision 37352) +++ main/plugin-admin/src/org/ametys/runtime/plugins/admin/system/SystemHelper.java (working copy) @@ -50,18 +50,22 @@ import org.ametys.core.ui.Callable; import org.ametys.core.util.I18nUtils; import org.ametys.core.util.I18nizableText; +import org.ametys.runtime.servlet.RuntimeConfig; /** * Helper for manipulating system announcement */ public class SystemHelper extends AbstractLogEnabled implements Component, Serviceable, Contextualizable { - /** The relative path to the file where system information are saved (announcement, maintenance...) */ - public static final String ADMINISTRATOR_SYSTEM_FILE = "WEB-INF/data/administrator/system.xml"; + /** + * The path to the file where system information are saved (announcement, + * maintenance...), relative to ametys home + */ + public static final String ADMINISTRATOR_SYSTEM_DIRECTORY = "administrator/system.xml"; + /** Avalon role */ public static final String ROLE = SystemHelper.class.getName(); - private org.apache.cocoon.environment.Context _environmentContext; private I18nUtils _i18nUtils; private Context _context; @@ -75,7 +79,6 @@ public void contextualize(Context context) throws ContextException { _context = context; - _environmentContext = (org.apache.cocoon.environment.Context) context.get(org.apache.cocoon.Constants.CONTEXT_ENVIRONMENT_CONTEXT); } /** @@ -86,10 +89,9 @@ @Callable public void setAnnouncementAvailable (boolean available) throws ProcessingException { - SystemAnnouncement systemAnnouncement = readValues(_environmentContext.getRealPath("/")); + SystemAnnouncement systemAnnouncement = readValues(); - String contextPath = _environmentContext.getRealPath("/"); - _save(contextPath, available, systemAnnouncement.getMessages()); + _save(available, systemAnnouncement.getMessages()); } /** @@ -105,7 +107,7 @@ { Map<String, Object> result = new HashMap<> (); - SystemAnnouncement sytemAnnouncement = readValues(_environmentContext.getRealPath("/")); + SystemAnnouncement sytemAnnouncement = readValues(); Map<String, String> messages = sytemAnnouncement.getMessages(); if (messages.containsKey(language) && !override) @@ -117,8 +119,7 @@ // Add or edit message messages.put(language, message); - String contextPath = _environmentContext.getRealPath("/"); - _save(contextPath, sytemAnnouncement.isAvailable(), messages); + _save(sytemAnnouncement.isAvailable(), messages); return result; } @@ -134,15 +135,14 @@ { Map<String, Object> result = new HashMap<> (); - SystemAnnouncement sytemAnnouncement = readValues(_environmentContext.getRealPath("/")); + SystemAnnouncement sytemAnnouncement = readValues(); Map<String, String> messages = sytemAnnouncement.getMessages(); if (messages.containsKey(language)) { messages.remove(language); - String contextPath = _environmentContext.getRealPath("/"); - _save(contextPath, sytemAnnouncement.isAvailable(), messages); + _save(sytemAnnouncement.isAvailable(), messages); } return result; @@ -150,14 +150,13 @@ /** * Saves the system announcement's values - * @param contextPath The context path * @param state true to enable system announcement * @param messages the messages - * @throws ProcessingException if an error ocurred + * @throws ProcessingException if an error occurred */ - private void _save (String contextPath, boolean state, Map<String, String> messages) throws ProcessingException + private void _save (boolean state, Map<String, String> messages) throws ProcessingException { - File systemFile = new File(contextPath, ADMINISTRATOR_SYSTEM_FILE); + File systemFile = new File(RuntimeConfig.getInstance().getAmetysHome(), ADMINISTRATOR_SYSTEM_DIRECTORY); try { @@ -215,25 +214,23 @@ /** * Tests if system announcements are active. - * @param contextPath the webapp context path * @return true if system announcements are active. */ - public boolean isSystemAnnouncementAvailable(String contextPath) + public boolean isSystemAnnouncementAvailable() { - SystemAnnouncement systemAnnouncement = readValues(contextPath); + SystemAnnouncement systemAnnouncement = readValues(); return systemAnnouncement.isAvailable(); } /** * Return the date of the last modification of the annonce - * @param contextPath the webapp context path * @return The date of the last modification or 0 if there is no announce file */ - public long getSystemAnnoucementLastModificationDate(String contextPath) + public long getSystemAnnoucementLastModificationDate() { try { - File systemFile = new File(contextPath, ADMINISTRATOR_SYSTEM_FILE); + File systemFile = new File(RuntimeConfig.getInstance().getAmetysHome(), ADMINISTRATOR_SYSTEM_DIRECTORY); if (!systemFile.exists() || !systemFile.isFile()) { return 0; @@ -251,12 +248,11 @@ * Returns the system announcement for the given language code, or for the default language code if there is no specified announcement for the given language code.<br> * Returns null if the system announcements are not activated. * @param languageCode the desired language code of the system announcement - * @param contextPath the webapp context path * @return the system announcement in the specified language code, or in the default language code, or null if announcements are not active. */ - public String getSystemAnnouncement(String languageCode, String contextPath) + public String getSystemAnnouncement(String languageCode) { - SystemAnnouncement systemAnnouncement = readValues(contextPath); + SystemAnnouncement systemAnnouncement = readValues(); if (!systemAnnouncement.isAvailable()) { @@ -287,19 +283,18 @@ /** * Read the system announcement's values - * @param contextPath The application context path * @return The system announcement values; */ - public SystemAnnouncement readValues (String contextPath) + public SystemAnnouncement readValues() { SystemAnnouncement announcement = new SystemAnnouncement(); try { - File systemFile = new File(contextPath, ADMINISTRATOR_SYSTEM_FILE); + File systemFile = new File(RuntimeConfig.getInstance().getAmetysHome(), ADMINISTRATOR_SYSTEM_DIRECTORY); if (!systemFile.exists() || !systemFile.isFile()) { - _setDefaultValues(contextPath); + _setDefaultValues(); } Configuration configuration; @@ -330,7 +325,7 @@ } } - private void _setDefaultValues (String contextPath) throws ProcessingException + private void _setDefaultValues () throws ProcessingException { Map objectModel = ContextHelper.getObjectModel(_context); Locale locale = org.apache.cocoon.i18n.I18nUtils.findLocale(objectModel, "locale", null, Locale.getDefault(), true); @@ -339,7 +334,7 @@ Map<String, String> messages = new HashMap<> (); messages.put("*", defaultMessage); - _save(contextPath, false, messages); + _save(false, messages); } /** Index: main/plugin-core-impl/plugin.xml =================================================================== --- main/plugin-core-impl/plugin.xml (revision 37352) +++ main/plugin-core-impl/plugin.xml (working copy) @@ -1434,7 +1434,7 @@ <component role="org.ametys.core.upload.UploadManager" id="org.ametys.plugins.core.upload.FSUploadManager" class="org.ametys.plugins.core.impl.upload.FSUploadManager"> - <!-- UploadManager for storing uploaded files into /WEB-INF/data/uploads-user --> + <!-- UploadManager for storing uploaded files into Ametys home 'uploads-user' directory --> </component> </components> </feature> Index: main/plugin-core-impl/src/org/ametys/plugins/core/impl/upload/FSUploadManager.java =================================================================== --- main/plugin-core-impl/src/org/ametys/plugins/core/impl/upload/FSUploadManager.java (revision 37352) +++ main/plugin-core-impl/src/org/ametys/plugins/core/impl/upload/FSUploadManager.java (working copy) @@ -53,16 +53,20 @@ import org.ametys.core.upload.Upload; import org.ametys.core.upload.UploadManager; +import org.ametys.runtime.servlet.RuntimeConfig; /** - * {@link UploadManager} which stores uploaded files into - * <code>/WEB-INF/data/uploads-user</code>.<p> + * {@link UploadManager} which stores uploaded files into the + * <code>uploads-user</code> directory located in Ametys home + * <p> * Note that this implementation is not cluster safe. */ public class FSUploadManager extends TimerTask implements UploadManager, ThreadSafe, Initializable, Contextualizable, LogEnabled, Disposable { - /** Global uploads directory. */ - public static final String UPLOADS_DIR = "/WEB-INF/data/uploads-user"; + /** + * The path to the global uploads directory relative to ametys home + */ + public static final String UPLOADS_DIRECTORY = "uploads-user"; /** Context. */ protected org.apache.cocoon.environment.Context _context; @@ -84,7 +88,6 @@ { // Retrieve context-root from context _context = (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); - _globalUploadsDir = new File(_context.getRealPath(UPLOADS_DIR)); } @Override @@ -95,6 +98,8 @@ _logger.debug("Starting timer"); } + _globalUploadsDir = new File(RuntimeConfig.getInstance().getAmetysHome(), UPLOADS_DIRECTORY); + // Daemon thread _timer = new Timer("FSUploadManager", true); Index: main/plugin-core-ui/src/org/ametys/plugins/core/ui/system/SystemAnnouncementGenerator.java =================================================================== --- main/plugin-core-ui/src/org/ametys/plugins/core/ui/system/SystemAnnouncementGenerator.java (revision 37352) +++ main/plugin-core-ui/src/org/ametys/plugins/core/ui/system/SystemAnnouncementGenerator.java (working copy) @@ -18,9 +18,6 @@ import java.io.IOException; import java.util.Locale; -import org.apache.avalon.framework.context.Context; -import org.apache.avalon.framework.context.ContextException; -import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.cocoon.ProcessingException; @@ -34,18 +31,11 @@ /** * Generates the system announcement */ -public class SystemAnnouncementGenerator extends ServiceableGenerator implements Contextualizable +public class SystemAnnouncementGenerator extends ServiceableGenerator { - private org.apache.cocoon.environment.Context _environmentContext; private SystemHelper _systemHelper; @Override - public void contextualize(Context context) throws ContextException - { - _environmentContext = (org.apache.cocoon.environment.Context) context.get(org.apache.cocoon.Constants.CONTEXT_ENVIRONMENT_CONTEXT); - } - - @Override public void service(ServiceManager smanager) throws ServiceException { super.service(smanager); @@ -58,16 +48,15 @@ contentHandler.startDocument(); XMLUtils.startElement(contentHandler, "SystemAnnounce"); - String contextPath = _environmentContext.getRealPath("/"); - boolean isAvailable = _systemHelper.isSystemAnnouncementAvailable(contextPath); + boolean isAvailable = _systemHelper.isSystemAnnouncementAvailable(); XMLUtils.createElement(contentHandler, "IsAvailable", String.valueOf(isAvailable)); if (isAvailable) { Locale locale = I18nUtils.findLocale(objectModel, "locale", null, Locale.getDefault(), true); - XMLUtils.createElement(contentHandler, "LastModification", String.valueOf(_systemHelper.getSystemAnnoucementLastModificationDate(contextPath))); - XMLUtils.createElement(contentHandler, "Message", _systemHelper.getSystemAnnouncement(locale.getLanguage(), contextPath)); + XMLUtils.createElement(contentHandler, "LastModification", String.valueOf(_systemHelper.getSystemAnnoucementLastModificationDate())); + XMLUtils.createElement(contentHandler, "Message", _systemHelper.getSystemAnnouncement(locale.getLanguage())); } XMLUtils.endElement(contentHandler, "SystemAnnounce"); Index: main/plugin-core/i18n/messages_en.xml =================================================================== --- main/plugin-core/i18n/messages_en.xml (revision 37352) +++ main/plugin-core/i18n/messages_en.xml (working copy) @@ -54,8 +54,6 @@ <message key="PLUGINS_CORE_UPLOAD_CONFIG_GROUP">Uploads management</message> <message key="PLUGINS_CORE_UPLOAD_CONFIG_MAXSIZE_LABEL">Maximum size</message> <message key="PLUGINS_CORE_UPLOAD_CONFIG_MAXSIZE_DESCRIPTION">The maximum size (in bytes) of uploaded files</message> - <message key="PLUGINS_CORE_UPLOAD_CONFIG_DIR_LABEL">Destination directory</message> - <message key="PLUGINS_CORE_UPLOAD_CONFIG_DIR_DESCRIPTION">Destination directory for uploaded files. You can use a path relative to your web application directory. The directory path must not end with the '/' character.<br/>Samples: '/home/cms/data/uploads' or 'WEB-INF/data/uploads'.</message> <!-- USER AND RIGHTS --> @@ -246,8 +244,6 @@ <!-- PARAMETER CHECKERS --> <message key="PLUGINS_CORE_MAIL_CONNECTION_CHECKER_LABEL">Connection to the mail server</message> <message key="PLUGINS_CORE_MAIL_CONNECTION_CHECKER_DESC">This test checks if the given information allows the connection to the mail server.</message> - <message key="PLUGINS_CORE_UPLOAD_DIRECTORY_CHECKER_LABEL">Upload directory</message> - <message key="PLUGINS_CORE_UPLOAD_DIRECTORY_CHECKER_DESC">This test checks the existence of the specified folder or the possibility to create it otherwise, and then if Ametys can write in it. The created folder is temporary and is deleted at the end of the test.</message> <message key="PLUGINS_CORE_CAS_SERVER_CHECKER_LABEL">CAS server's url</message> <message key="PLUGINS_CORE_CAS_SERVER_CHECKER_DESC">This test checks that the specified url is valid by trying to establish a connection.</message> <message key="PLUGINS_CORE_LDAP_DN_CONNECTION_CHECKER_LABEL">Connection to the LDAP</message> Index: main/plugin-core/i18n/messages_fr.xml =================================================================== --- main/plugin-core/i18n/messages_fr.xml (revision 37352) +++ main/plugin-core/i18n/messages_fr.xml (working copy) @@ -54,8 +54,6 @@ <message key="PLUGINS_CORE_UPLOAD_CONFIG_GROUP">Gestion des uploads</message> <message key="PLUGINS_CORE_UPLOAD_CONFIG_MAXSIZE_LABEL">Taille maximale</message> <message key="PLUGINS_CORE_UPLOAD_CONFIG_MAXSIZE_DESCRIPTION">La taille maximale (en octets) des fichiers uploadés</message> - <message key="PLUGINS_CORE_UPLOAD_CONFIG_DIR_LABEL">Répertoire de destination</message> - <message key="PLUGINS_CORE_UPLOAD_CONFIG_DIR_DESCRIPTION">Répertoire de destination des fichiers uploadés. Vous pouvez utiliser un chemin relatif à l'application web. Le chemin ne doit pas finir par '/'.<br/>Exemple : '/home/cms/data/uploads' ou 'WEB-INF/data/uploads'.</message> <!-- USER AND RIGHTS --> <message key="PLUGINS_CORE_USERANDRIGHTS_CATEGORY">Utilisateurs et droits</message> @@ -244,8 +242,6 @@ <!-- PARAMETER CHECKERS --> <message key="PLUGINS_CORE_MAIL_CONNECTION_CHECKER_LABEL">Connexion au serveur mail</message> <message key="PLUGINS_CORE_MAIL_CONNECTION_CHECKER_DESC">Ce test vérifie que les informations rentrées permettent bien d'établir une connexion avec le serveur d'envoi d'emails</message> - <message key="PLUGINS_CORE_UPLOAD_DIRECTORY_CHECKER_LABEL">Répertoire destination d'upload</message> - <message key="PLUGINS_CORE_UPLOAD_DIRECTORY_CHECKER_DESC">Ce test vérifie l'existence du dossier spécifié ou la possibilité de créer ce nouveau dossier sinon, puis qu'Ametys a bien les droits d'écriture. Le dossier créée est temporaire et est supprimé à la fin du test.</message> <message key="PLUGINS_CORE_CAS_SERVER_CHECKER_LABEL">Url du serveur CAS</message> <message key="PLUGINS_CORE_CAS_SERVER_CHECKER_DESC">Ce test vérifie que le l'url spécifiée est valide en essayant d'établir une connexion.</message> <message key="PLUGINS_CORE_LDAP_DN_CONNECTION_CHECKER_LABEL">Connexion au LDAP</message> Index: main/plugin-core/plugin.xml =================================================================== --- main/plugin-core/plugin.xml (revision 37352) +++ main/plugin-core/plugin.xml (working copy) @@ -80,22 +80,6 @@ <group i18n="true">PLUGINS_CORE_UPLOAD_CONFIG_GROUP</group> <order>10</order> </param> - <param id="runtime.upload.dir" type="string"> - <!-- - The destination directory for uploaded files. - --> - <label i18n="true">PLUGINS_CORE_UPLOAD_CONFIG_DIR_LABEL</label> - <description i18n="true">PLUGINS_CORE_UPLOAD_CONFIG_DIR_DESCRIPTION</description> - <validation> - <mandatory/> - <regexp>^.*[^\/]$</regexp> - <invalidText i18n="true">PLUGINS_CORE_REGEXP_INVALID_PATH</invalidText> - </validation> - <default-value>WEB-INF/data/uploads</default-value> - <category i18n="true">PLUGINS_CORE_SYSTEM_CONFIG_CATEGORY</category> - <group i18n="true">PLUGINS_CORE_UPLOAD_CONFIG_GROUP</group> - <order>20</order> - </param> <!-- + | MAIL - ADDRESSES @@ -233,28 +217,6 @@ <param-ref id="smtp.mail.sysadminto"/> </linked-params> </param-checker--> - - <param-checker id="upload-directory-checker" class="org.ametys.plugins.core.impl.checker.DirectoryChecker"> - <label i18n="true">PLUGINS_CORE_UPLOAD_DIRECTORY_CHECKER_LABEL</label> - <description i18n="true">PLUGINS_CORE_UPLOAD_DIRECTORY_CHECKER_DESC</description> - <icon-large>img/config/check/test_directorywrite_48.png</icon-large> - <icon-medium>img/config/check/test_directorywrite_32.png</icon-medium> - <icon-small>img/config/check/test_directorywrite_16.png</icon-small> - - <configuration> - <check-write/> - <creates-if-required/> - </configuration> - - <ui-ref> - <order>1</order> - <param-ref id="runtime.upload.dir"/> - </ui-ref> - - <linked-params> - <param-ref id="runtime.upload.dir"/> - </linked-params> - </param-checker> </config> <extension-points> @@ -474,7 +436,6 @@ <!-- Mark thoses configuration parameters as necessary. If you do not want to configure this beacause your application does not upload any file => unactive this feature. --> <config> <param-ref id="runtime.upload.max-size"/> - <param-ref id="runtime.upload.dir"/> </config> </feature> Index: main/workspace-admin/src/org/ametys/runtime/workspaces/admin/authentication/AdminAuthenticateAction.java =================================================================== --- main/workspace-admin/src/org/ametys/runtime/workspaces/admin/authentication/AdminAuthenticateAction.java (revision 37352) +++ main/workspace-admin/src/org/ametys/runtime/workspaces/admin/authentication/AdminAuthenticateAction.java (working copy) @@ -15,6 +15,7 @@ */ package org.ametys.runtime.workspaces.admin.authentication; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; @@ -30,7 +31,6 @@ import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.acting.AbstractAction; -import org.apache.cocoon.environment.Context; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.Request; @@ -43,6 +43,7 @@ import org.ametys.core.authentication.CredentialsProvider; import org.ametys.core.user.User; import org.ametys.plugins.core.impl.authentication.BasicCredentialsProvider; +import org.ametys.runtime.servlet.RuntimeConfig; /** * Cocoon action for authenticating users in the administration workspace. @@ -54,23 +55,19 @@ { /** The request attribute name for telling that super user is logged in. */ public static final String REQUEST_ATTRIBUTE_SUPER_USER = "Runtime:SuperUser"; - /** Location (from webapplication context) of the administrator password */ - public static final String ADMINISTRATOR_PASSWORD_FILENAME = "/WEB-INF/data/administrator/admin.xml"; + /** Location of the administrator password relative to ametys home */ + public static final String ADMINISTRATOR_PASSWORD_FILENAME = "administrator/admin.xml"; private static final String __SESSION_ADMINISTRATOR = "Runtime:Administrator"; /** The cocoon context, initialized during the contextualize method */ protected org.apache.avalon.framework.context.Context _context; - /** The environment context */ - protected Context _envContext; - private CredentialsProvider _credentialsProvider; public void contextualize(org.apache.avalon.framework.context.Context context) throws ContextException { _context = context; - _envContext = (Context) _context.get(org.apache.cocoon.Constants.CONTEXT_ENVIRONMENT_CONTEXT); } public void initialize() throws Exception @@ -154,7 +151,7 @@ return false; } - try (InputStream is = new FileInputStream(_envContext.getRealPath(ADMINISTRATOR_PASSWORD_FILENAME))) + try (InputStream is = new FileInputStream(new File(RuntimeConfig.getInstance().getAmetysHome(), ADMINISTRATOR_PASSWORD_FILENAME))) { XPath xpath = XPathFactory.newInstance().newXPath(); String pass = xpath.evaluate("admin/password", new InputSource(is)); @@ -185,7 +182,10 @@ { if (getLogger().isWarnEnabled()) { - getLogger().warn("The file '" + ADMINISTRATOR_PASSWORD_FILENAME + "' is missing. Default administrator password 'admin' is used.", e); + String ametysHomePath = RuntimeConfig.getInstance().getAmetysHome().getPath(); + getLogger().warn( + "The file '" + ADMINISTRATOR_PASSWORD_FILENAME + "' is missing in Ametys home '" + ametysHomePath + + "'.\nDefault administrator password 'admin' is used.", e); } return "admin".equals(passwd); Index: templates/application/WEB-INF/log4j.deliver.xml =================================================================== --- templates/application/WEB-INF/log4j.deliver.xml (revision 37352) +++ templates/application/WEB-INF/log4j.deliver.xml (working copy) @@ -18,7 +18,7 @@ <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="servlet" class="biz.minaret.log4j.DatedFileAppender"> - <param name="Directory" value="${context-root}/WEB-INF/logs"/> + <param name="Directory" value="${ametys.home.dir}/logs"/> <param name="Prefix" value="cms-"/> <param name="Suffix" value=".log"/> <param name="Append" value="true"/> Index: templates/application/WEB-INF/log4j.xml =================================================================== --- templates/application/WEB-INF/log4j.xml (revision 37352) +++ templates/application/WEB-INF/log4j.xml (working copy) @@ -21,7 +21,7 @@ <appender name="servlet" class="org.apache.log4j.rolling.RollingFileAppender"> <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy"> - <param name="FileNamePattern" value="${context-root}/WEB-INF/logs/servlet-engine-%d.log"/> + <param name="FileNamePattern" value="${ametys.home.dir}/logs/servlet-engine-%d.log"/> </rollingPolicy> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5p [%c] (%t;%X{requestURI}) %m%n"/> Index: templates/application/WEB-INF/web.xml =================================================================== --- templates/application/WEB-INF/web.xml (revision 37352) +++ templates/application/WEB-INF/web.xml (working copy) @@ -237,7 +237,16 @@ <param-name>form-encoding</param-name> <param-value>utf-8</param-value> </init-param> - + + <!-- + Ametys home property allow to use an environment variable that will indicates the Ametys home directory location. + By default the Ametys home directory location will be WEB-INF/data . + --> + <init-param> + <param-name>ametys.home.property</param-name> + <param-value>AMETYS_RUNTIME_HOME</param-value> + </init-param> + <!-- This parameter allows you to startup Cocoon2 immediately after startup of your servlet engine. Index: test-env/src/org/ametys/runtime/test/AbstractRuntimeTestCase.java =================================================================== --- test-env/src/org/ametys/runtime/test/AbstractRuntimeTestCase.java (revision 37352) +++ test-env/src/org/ametys/runtime/test/AbstractRuntimeTestCase.java (working copy) @@ -25,6 +25,8 @@ import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; +import junit.framework.TestCase; + import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; import org.slf4j.Logger; @@ -32,18 +34,24 @@ import org.xml.sax.XMLReader; import org.ametys.runtime.config.Config; +import org.ametys.runtime.data.AmetysHomeLock; +import org.ametys.runtime.data.AmetysHomeLockException; import org.ametys.runtime.servlet.RuntimeConfig; -import junit.framework.TestCase; - /** * Abstract test case for all Runtime test cases. */ public abstract class AbstractRuntimeTestCase extends TestCase { + /** Ametys home directory path relative to the context path of the test environment. **/ + public static final String AMETYS_HOME_DIR = "/WEB-INF/data"; + /** The cocoon wrapper. */ protected CocoonWrapper _cocoon; + /** The lock on Ametys home */ + protected AmetysHomeLock _ametysHomeLock; + /** Logger for traces */ protected Logger _logger = LoggerFactory.getLogger(getClass()); @@ -64,6 +72,48 @@ super(name); } + @Override + protected void tearDown() throws Exception + { + if (_ametysHomeLock != null) + { + if (_logger.isInfoEnabled()) + { + _logger.info("Releasing lock on Ametys home"); + } + + _ametysHomeLock.release(); + _ametysHomeLock = null; + } + + super.tearDown(); + } + + /** + * Initialize the Ametys home directory and acquire a lock on it. + * @param contextPath the test application path + * @return The Ametys home directory + * @throws AmetysHomeLockException If an error occurs while acquiring the lock on Ametys home + */ + protected File _initAmetysHome(String contextPath) throws AmetysHomeLockException + { + String ametysHomePath = contextPath + AMETYS_HOME_DIR; + + if (_logger.isInfoEnabled()) + { + _logger.info("Acquiring lock on " + ametysHomePath); + } + + // Acquire the lock on Ametys home + File ametysHome = new File(ametysHomePath); + ametysHome.mkdirs(); + + _ametysHomeLock = new AmetysHomeLock(ametysHome); + _ametysHomeLock.acquire(); + + return ametysHome; + } + /** * Configures the RuntimeConfig with the given file * @param fileName the name of the config file @@ -72,6 +122,8 @@ */ protected void _configureRuntime(String fileName, String contextPath) throws Exception { + File ametysHome = _initAmetysHome(contextPath); + File runtimeConfigFile = new File(fileName); Configuration runtimeConf = null; @@ -110,7 +162,7 @@ } } - RuntimeConfig.configure(runtimeConf, externalConf, contextPath); + RuntimeConfig.configure(runtimeConf, externalConf, ametysHome, contextPath); } /** Index: test/environments/configs/config1.xml =================================================================== --- test/environments/configs/config1.xml (revision 37352) +++ test/environments/configs/config1.xml (working copy) @@ -26,7 +26,6 @@ <runtime.datasource.core.jdbc.url>jdbc:mysql://mysql-dev.anyware.corp/Ametys_Runtime_Test</runtime.datasource.core.jdbc.url> <runtime.authentication.basic.realm>realm</runtime.authentication.basic.realm> <runtime.upload.max-size>10000000</runtime.upload.max-size> -<runtime.upload.dir>WEB-INF/data/uploads</runtime.upload.dir> <runtime.debug.ui>0</runtime.debug.ui> <runtime.cache.xslt>false</runtime.cache.xslt> <runtime.log.abnormal.time>false</runtime.log.abnormal.time> Index: test/environments/configs/config3.xml =================================================================== --- test/environments/configs/config3.xml (revision 37352) +++ test/environments/configs/config3.xml (working copy) @@ -28,7 +28,6 @@ <runtime.datasource.core.jdbc.url>jdbc:mysql://mysql-dev.anyware.corp/Ametys_Runtime_Test</runtime.datasource.core.jdbc.url> <runtime.authentication.basic.realm>realm</runtime.authentication.basic.realm> <runtime.upload.max-size>10000000</runtime.upload.max-size> -<runtime.upload.dir>WEB-INF/data/uploads</runtime.upload.dir> <runtime.debug.ui>0</runtime.debug.ui> <runtime.cache.xslt>false</runtime.cache.xslt> <runtime.log.abnormal.time>false</runtime.log.abnormal.time> Index: test/environments/configs/config4.xml =================================================================== --- test/environments/configs/config4.xml (revision 37352) +++ test/environments/configs/config4.xml (working copy) @@ -27,7 +27,6 @@ <runtime.datasource.core.jdbc.url>jdbc:mysql://mysql-dev.anyware.corp/Ametys_Runtime_Test</runtime.datasource.core.jdbc.url> <runtime.authentication.basic.realm>realm</runtime.authentication.basic.realm> <runtime.upload.max-size>10000000</runtime.upload.max-size> -<runtime.upload.dir>WEB-INF/data/uploads</runtime.upload.dir> <runtime.debug.ui>0</runtime.debug.ui> <runtime.cache.xslt>false</runtime.cache.xslt> <runtime.log.abnormal.time>false</runtime.log.abnormal.time> Index: test/environments/configs/config_derby.xml =================================================================== --- test/environments/configs/config_derby.xml (revision 37352) +++ test/environments/configs/config_derby.xml (working copy) @@ -22,7 +22,6 @@ <runtime.datasource.core.jdbc.passwd/> <runtime.authentication.basic.realm>realm</runtime.authentication.basic.realm> <runtime.upload.max-size>10000000</runtime.upload.max-size> - <runtime.upload.dir>WEB-INF/data/uploads</runtime.upload.dir> <runtime.debug.ui>0</runtime.debug.ui> <runtime.cache.xslt>false</runtime.cache.xslt> <runtime.log.abnormal.time>false</runtime.log.abnormal.time> Index: test/environments/configs/config_hsqldb.xml =================================================================== --- test/environments/configs/config_hsqldb.xml (revision 37352) +++ test/environments/configs/config_hsqldb.xml (working copy) @@ -22,7 +22,6 @@ <runtime.datasource.core.jdbc.passwd/> <runtime.authentication.basic.realm>realm</runtime.authentication.basic.realm> <runtime.upload.max-size>10000000</runtime.upload.max-size> - <runtime.upload.dir>WEB-INF/data/uploads</runtime.upload.dir> <runtime.debug.ui>0</runtime.debug.ui> <runtime.cache.xslt>false</runtime.cache.xslt> <runtime.log.abnormal.time>false</runtime.log.abnormal.time> Index: test/environments/configs/config_oracle.xml =================================================================== --- test/environments/configs/config_oracle.xml (revision 37352) +++ test/environments/configs/config_oracle.xml (working copy) @@ -22,7 +22,6 @@ <runtime.datasource.core.jdbc.passwd>Ametys_Runtime</runtime.datasource.core.jdbc.passwd> <runtime.authentication.basic.realm>realm</runtime.authentication.basic.realm> <runtime.upload.max-size>10000000</runtime.upload.max-size> - <runtime.upload.dir>WEB-INF/data/uploads</runtime.upload.dir> <runtime.debug.ui>0</runtime.debug.ui> <runtime.cache.xslt>false</runtime.cache.xslt> <runtime.log.abnormal.time>false</runtime.log.abnormal.time> Index: test/environments/configs/config_postgres.xml =================================================================== --- test/environments/configs/config_postgres.xml (revision 37352) +++ test/environments/configs/config_postgres.xml (working copy) @@ -22,7 +22,6 @@ <runtime.datasource.core.jdbc.url>jdbc:postgresql://goldorak/ametys_runtime_test</runtime.datasource.core.jdbc.url> <runtime.authentication.basic.realm>realm</runtime.authentication.basic.realm> <runtime.upload.max-size>10000000</runtime.upload.max-size> -<runtime.upload.dir>WEB-INF/data/uploads</runtime.upload.dir> <runtime.debug.ui>0</runtime.debug.ui> <runtime.cache.xslt>false</runtime.cache.xslt> <runtime.log.abnormal.time>false</runtime.log.abnormal.time> Index: test/src/org/ametys/runtime/test/AllTests.java =================================================================== --- test/src/org/ametys/runtime/test/AllTests.java (revision 37352) +++ test/src/org/ametys/runtime/test/AllTests.java (working copy) @@ -62,6 +62,7 @@ TestSuite suite = new TestSuite("Test for org.ametys.runtime.test"); //$JUnit-BEGIN$ + suite.addTestSuite(AmetysHomeTestCase.class); suite.addTestSuite(RuntimeConfigTestCase.class); suite.addTestSuite(WorkspacesTestCase.class); suite.addTestSuite(ConfigManagerTestCase.class); Index: test/src/org/ametys/runtime/test/AmetysHomeTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/AmetysHomeTestCase.java (revision 0) +++ test/src/org/ametys/runtime/test/AmetysHomeTestCase.java (revision 0) @@ -0,0 +1,244 @@ +/* + * Copyright 2009 Anyware Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ametys.runtime.test; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.FileStore; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.AclEntry; +import java.nio.file.attribute.AclEntryFlag; +import java.nio.file.attribute.AclEntryPermission; +import java.nio.file.attribute.AclEntryType; +import java.nio.file.attribute.AclFileAttributeView; +import java.nio.file.attribute.PosixFileAttributeView; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.UserPrincipal; +import java.util.EnumSet; +import java.util.List; + +import org.apache.commons.io.FileUtils; + +import org.ametys.runtime.data.AmetysHomeLock; +import org.ametys.runtime.data.AmetysHomeLockException; + +/** + * Tests the RuntimeConfig + */ +public class AmetysHomeTestCase extends AbstractRuntimeTestCase +{ + @Override + protected void setUp() throws Exception + { + _startApplication("test/environments/runtimes/runtime01.xml", "test/environments/configs/config1.xml", "test/environments/webapp1"); + super.setUp(); + } + + @Override + protected void tearDown() throws Exception + { + _cocoon.dispose(); + super.tearDown(); + } + + /** + * Test the lock on the Ametys home directory. + */ + public void testAmetysHomeLocked() + { + Exception e = null; + + try + { + _ametysHomeLock.acquire(); + fail("Should not be able to acquire twice."); + } + catch (AmetysHomeLockException ae) + { + e = ae; + } + + assertNotNull("An ametys home lock exception must have been thrown during the lock acquire.", e); + } + + + /** + * Various tests on the lock feature provided by Ametys Home lock. + * @throws Exception if an error occurs + */ + public void testFolderLock() throws Exception + { + String path = "test/environments/webapp1/WEB-INF/data"; + String lockFolderName = "lockFolder"; + + // 0 - Remove lockFolder if existing + File lockFolder = new File(path, lockFolderName); + FileUtils.deleteDirectory(lockFolder); + + // 1 - Creating a lock on an nonexistent folder will fails + AmetysHomeLock ametysHomeLock = new AmetysHomeLock(lockFolder); + try + { + ametysHomeLock.acquire(); + fail("Should not be able to acquire a lock on a unexisting folder"); + } + catch (AmetysHomeLockException e) + { + // ok + } + finally + { + ametysHomeLock.release(); + } + + // 2 - Creating the folder, the lock can be acquired now + lockFolder.mkdirs(); + ametysHomeLock = new AmetysHomeLock(lockFolder); + try + { + ametysHomeLock.acquire(); + } + catch (AmetysHomeLockException e) + { + _logger.error("The lock must be acquired without error", e); + fail("The lock must be acquired without error"); + } + + // 3 - Cannot remove the '.lock' file + File lockFile = new File(lockFolder, ".lock"); + + assertTrue("The lock must be acquired", lockFile.exists()); + assertFalse("Must not be able to create a lock file", lockFile.createNewFile()); + assertFalse("Must not be able to delete the lock file", lockFile.delete()); + + // Create a folder and a file in the locked folder + String filePath = "a/b/c.txt"; + File file = new File(lockFolder, filePath); + assertTrue("Must be able to create folder", file.getParentFile().mkdirs()); + assertTrue("Must be able to a file", file.createNewFile()); + + try (PrintWriter pw = new PrintWriter(file)) + { + pw.write("Writing in file..."); + } + catch (Exception e) + { + _logger.error("Error while writing to file", e); + fail("Must be able to write to a file"); + } + + assertTrue("Must be able to delete the file", file.delete()); + + // 5 - Release the lock + ametysHomeLock.release(); + assertFalse("The lock has been released", lockFile.exists()); + + // 6 - Create a fake lock file in the lock folder + assertTrue("Must be able to create a fake lock file", lockFile.createNewFile()); + + // 7 - Must still be able to acquire the lock + ametysHomeLock = new AmetysHomeLock(lockFolder); + try + { + ametysHomeLock.acquire(); + } + catch (AmetysHomeLockException e) + { + fail("The lock must be acquired without error"); + } + finally + { + ametysHomeLock.release(); + } + } + + /** + * Test the acquisition of the lock on a read only folder + * @throws Exception if an error occurs + */ + public void testFolderLockReadOnly() throws Exception + { + String path = "test/environments/webapp1/WEB-INF/data"; + String lockFolderName = "lockFolder"; + + // Remove lockFolder if existing + File lockFolder = new File(path, lockFolderName); + FileUtils.deleteDirectory(lockFolder); + + lockFolder.mkdirs(); + assertTrue("The directory must be marked as read only", _makeDirectoryReadOnly(lockFolder)); + assertFalse("The folder must be read only", Files.isWritable(lockFolder.toPath())); + + AmetysHomeLock ametysHomeLock = new AmetysHomeLock(lockFolder); + try + { + ametysHomeLock.acquire(); + fail("Should not be able to acquire a lock on a read only folder"); + } + catch (AmetysHomeLockException e) + { + // ok + } + finally + { + ametysHomeLock.release(); + } + } + + private boolean _makeDirectoryReadOnly(File dir) throws IOException + { + Path path = dir.toPath(); + + FileStore store = Files.getFileStore(path); + boolean supportAcl = store.supportsFileAttributeView("acl"); // For Windows mainly. + boolean supportPosix = store.supportsFileAttributeView("posix"); // For Unix mainly. + + if (supportAcl) + { + UserPrincipal current = path.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByName(System.getProperty("user.name")); + + // get view + AclFileAttributeView view = Files.getFileAttributeView(path, AclFileAttributeView.class); + + // create specific read only entry (+ delete) for current user + AclEntry entry = AclEntry.newBuilder() + .setType(AclEntryType.DENY) + .setFlags(EnumSet.of(AclEntryFlag.FILE_INHERIT, AclEntryFlag.DIRECTORY_INHERIT)) + .setPrincipal(current) + .setPermissions(AclEntryPermission.WRITE_DATA, AclEntryPermission.WRITE_ATTRIBUTES) + .build(); + + List<AclEntry> acl = view.getAcl(); + acl.add(0, entry); + view.setAcl(acl); + + return true; + } + else if (supportPosix) + { + // get view + PosixFileAttributeView view = Files.getFileAttributeView(path, PosixFileAttributeView.class); + view.setPermissions(EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ)); + + return true; + } + + return false; + } +} + Index: test/src/org/ametys/runtime/test/ConfigManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/ConfigManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/ConfigManagerTestCase.java (working copy) @@ -38,6 +38,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + CommandLineContext ctx = new CommandLineContext("test/environments/webapp1"); ctx.enableLogging(new SLF4JLoggerAdapter(LoggerFactory.getLogger("ctx"))); _context = new DefaultContext(); Index: test/src/org/ametys/runtime/test/groups/jdbc/AbstractJdbcGroupsTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/groups/jdbc/AbstractJdbcGroupsTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/groups/jdbc/AbstractJdbcGroupsTestCase.java (working copy) @@ -68,8 +68,6 @@ */ protected void _resetDB(String runtimeFilename, String configFileName) throws Exception { - super.setUp(); - _startApplication("test/environments/runtimes/" + runtimeFilename, "test/environments/configs/" + configFileName, "test/environments/webapp1"); _setDatabase(Arrays.asList(getScripts())); Index: test/src/org/ametys/runtime/test/groups/ldap/GroupDrivenLdapGroupsTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/groups/ldap/GroupDrivenLdapGroupsTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/groups/ldap/GroupDrivenLdapGroupsTestCase.java (working copy) @@ -28,8 +28,9 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _startApplication("test/environments/runtimes/runtime8.xml", "test/environments/configs/config3.xml", "test/environments/webapp1"); - _groupsManager = (GroupsManager) Init.getPluginServiceManager().lookup(GroupsManager.ROLE); } Index: test/src/org/ametys/runtime/test/groups/ldap/UserDrivenLdapGroupsTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/groups/ldap/UserDrivenLdapGroupsTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/groups/ldap/UserDrivenLdapGroupsTestCase.java (working copy) @@ -28,8 +28,9 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _startApplication("test/environments/runtimes/runtime9.xml", "test/environments/configs/config4.xml", "test/environments/webapp1"); - _groupsManager = (GroupsManager) Init.getPluginServiceManager().lookup(GroupsManager.ROLE); } Index: test/src/org/ametys/runtime/test/rights/basic/BasicRightsManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/rights/basic/BasicRightsManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/rights/basic/BasicRightsManagerTestCase.java (working copy) @@ -33,6 +33,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _startApplication("test/environments/runtimes/runtime12.xml", "test/environments/configs/config1.xml", "test/environments/webapp1"); } Index: test/src/org/ametys/runtime/test/rights/profile/DerbyProfileBasedRightsManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/rights/profile/DerbyProfileBasedRightsManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/rights/profile/DerbyProfileBasedRightsManagerTestCase.java (working copy) @@ -26,6 +26,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _resetDB("runtime4.xml", "config_derby.xml"); } Index: test/src/org/ametys/runtime/test/rights/profile/HsqlProfileBasedRightsManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/rights/profile/HsqlProfileBasedRightsManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/rights/profile/HsqlProfileBasedRightsManagerTestCase.java (working copy) @@ -26,6 +26,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _resetDB("runtime4.xml", "config_hsqldb.xml"); } Index: test/src/org/ametys/runtime/test/rights/profile/MysqlProfileBasedRightsManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/rights/profile/MysqlProfileBasedRightsManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/rights/profile/MysqlProfileBasedRightsManagerTestCase.java (working copy) @@ -26,6 +26,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _resetDB("runtime4.xml", "config1.xml"); } Index: test/src/org/ametys/runtime/test/rights/profile/OracleProfileBasedRightsManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/rights/profile/OracleProfileBasedRightsManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/rights/profile/OracleProfileBasedRightsManagerTestCase.java (working copy) @@ -26,6 +26,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _resetDB("runtime4.xml", "config_oracle.xml"); } Index: test/src/org/ametys/runtime/test/rights/profile/PostgresProfileBasedRightsManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/rights/profile/PostgresProfileBasedRightsManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/rights/profile/PostgresProfileBasedRightsManagerTestCase.java (working copy) @@ -26,6 +26,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _resetDB("runtime4.xml", "config_postgres.xml"); } Index: test/src/org/ametys/runtime/test/rights/profile/hierarchical/DerbyHierarchicalProfileBasedRightsManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/rights/profile/hierarchical/DerbyHierarchicalProfileBasedRightsManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/rights/profile/hierarchical/DerbyHierarchicalProfileBasedRightsManagerTestCase.java (working copy) @@ -26,6 +26,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _resetDB("runtime5.xml", "config_derby.xml"); } Index: test/src/org/ametys/runtime/test/rights/profile/hierarchical/HsqlHierarchicalProfileBasedRightsManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/rights/profile/hierarchical/HsqlHierarchicalProfileBasedRightsManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/rights/profile/hierarchical/HsqlHierarchicalProfileBasedRightsManagerTestCase.java (working copy) @@ -26,6 +26,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _resetDB("runtime5.xml", "config_hsqldb.xml"); } Index: test/src/org/ametys/runtime/test/rights/profile/hierarchical/MysqlHierarchicalProfileBasedRightsManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/rights/profile/hierarchical/MysqlHierarchicalProfileBasedRightsManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/rights/profile/hierarchical/MysqlHierarchicalProfileBasedRightsManagerTestCase.java (working copy) @@ -26,6 +26,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _resetDB("runtime5.xml", "config1.xml"); } Index: test/src/org/ametys/runtime/test/rights/profile/hierarchical/OracleHierarchicalProfileBasedRightsManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/rights/profile/hierarchical/OracleHierarchicalProfileBasedRightsManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/rights/profile/hierarchical/OracleHierarchicalProfileBasedRightsManagerTestCase.java (working copy) @@ -26,6 +26,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _resetDB("runtime5.xml", "config_oracle.xml"); } Index: test/src/org/ametys/runtime/test/rights/profile/hierarchical/PostgresHierarchicalProfileBasedRightsManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/rights/profile/hierarchical/PostgresHierarchicalProfileBasedRightsManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/rights/profile/hierarchical/PostgresHierarchicalProfileBasedRightsManagerTestCase.java (working copy) @@ -26,6 +26,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _resetDB("runtime5.xml", "config_postgres.xml"); } Index: test/src/org/ametys/runtime/test/ui/DesktopManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/ui/DesktopManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/ui/DesktopManagerTestCase.java (working copy) @@ -40,6 +40,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _startApplication("test/environments/runtimes/runtime01.xml", "test/environments/configs/config1.xml", "test/environments/webapp2"); _desktopManager = (DesktopManager) Init.getPluginServiceManager().lookup("DesktopManagerTest"); Index: test/src/org/ametys/runtime/test/ui/StaticUIItemFactoryTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/ui/StaticUIItemFactoryTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/ui/StaticUIItemFactoryTestCase.java (working copy) @@ -33,6 +33,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _startApplication("test/environments/runtimes/runtime01.xml", "test/environments/configs/config1.xml", "test/environments/webapp2"); _desktopManager = (DesktopManager) Init.getPluginServiceManager().lookup("DesktopManagerTest"); Index: test/src/org/ametys/runtime/test/userpref/AbstractUserPreferencesTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/userpref/AbstractUserPreferencesTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/userpref/AbstractUserPreferencesTestCase.java (working copy) @@ -59,8 +59,6 @@ */ protected void _resetDB(String runtimeFilename, String configFileName) throws Exception { - super.setUp(); - _startApplication("test/environments/runtimes/" + runtimeFilename, "test/environments/configs/" + configFileName, "test/environments/webapp1"); _setDatabase(Arrays.asList(getScripts())); Index: test/src/org/ametys/runtime/test/users/jdbc/AbstractJDBCUsersManagerTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/AbstractJDBCUsersManagerTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/AbstractJDBCUsersManagerTestCase.java (working copy) @@ -38,8 +38,6 @@ */ protected void _resetDB(String runtimeFilename, String configFileName) throws Exception { - super.setUp(); - _startApplication("test/environments/runtimes/" + runtimeFilename, "test/environments/configs/" + configFileName, "test/environments/webapp1"); _setDatabase(Arrays.asList(getScripts())); Index: test/src/org/ametys/runtime/test/users/jdbc/DerbyJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/DerbyJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/DerbyJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime4.xml", "config_derby.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/HsqlJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/HsqlJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/HsqlJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime4.xml", "config_hsqldb.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/MysqlJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/MysqlJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/MysqlJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime4.xml", "config1.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/OracleJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/OracleJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/OracleJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime4.xml", "config_oracle.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/PostgresJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/PostgresJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/PostgresJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime4.xml", "config_postgres.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/DerbyCredentialsAwareJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/DerbyCredentialsAwareJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/DerbyCredentialsAwareJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime7.xml", "config_derby.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/HsqlCredentialsAwareJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/HsqlCredentialsAwareJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/HsqlCredentialsAwareJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime7.xml", "config_hsqldb.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/MysqlCredentialsAwareJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/MysqlCredentialsAwareJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/MysqlCredentialsAwareJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime7.xml", "config1.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/OracleCredentialsAwareJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/OracleCredentialsAwareJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/OracleCredentialsAwareJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime7.xml", "config_oracle.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/PostgresCredentialsAwareJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/PostgresCredentialsAwareJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/credentialsaware/PostgresCredentialsAwareJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime7.xml", "config_postgres.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/modifiable/DerbyModifiableJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/modifiable/DerbyModifiableJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/modifiable/DerbyModifiableJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime5.xml", "config_derby.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/modifiable/HsqlModifiableJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/modifiable/HsqlModifiableJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/modifiable/HsqlModifiableJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime5.xml", "config_hsqldb.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/modifiable/MysqlModifiableJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/modifiable/MysqlModifiableJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/modifiable/MysqlModifiableJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime5.xml", "config1.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/modifiable/OracleModifiableJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/modifiable/OracleModifiableJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/modifiable/OracleModifiableJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime5.xml", "config_oracle.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/modifiable/PostgresModifiableJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/modifiable/PostgresModifiableJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/modifiable/PostgresModifiableJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime5.xml", "config_postgres.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/DerbyModifiableCredentialsAwareJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/DerbyModifiableCredentialsAwareJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/DerbyModifiableCredentialsAwareJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime6.xml", "config_derby.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/HsqlModifiableCredentialsAwareJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/HsqlModifiableCredentialsAwareJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/HsqlModifiableCredentialsAwareJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime6.xml", "config_hsqldb.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/MysqlModifiableCredentialsAwareJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/MysqlModifiableCredentialsAwareJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/MysqlModifiableCredentialsAwareJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime6.xml", "config1.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/OracleModifiableCredentialsAwareJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/OracleModifiableCredentialsAwareJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/OracleModifiableCredentialsAwareJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime6.xml", "config_oracle.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/PostgresModifiableCredentialsAwareJdbcUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/PostgresModifiableCredentialsAwareJdbcUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/jdbc/modifiablecredentialsaware/PostgresModifiableCredentialsAwareJdbcUsersTestCase.java (working copy) @@ -26,6 +26,7 @@ @Override protected void setUp() throws Exception { + super.setUp(); _resetDB("runtime6.xml", "config_postgres.xml"); } @@ -33,6 +34,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } @Override Index: test/src/org/ametys/runtime/test/users/ldap/CredentialAwareLdapUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/ldap/CredentialAwareLdapUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/ldap/CredentialAwareLdapUsersTestCase.java (working copy) @@ -27,23 +27,15 @@ */ public class CredentialAwareLdapUsersTestCase extends LdapUsersTestCase { - @Override - protected void setUp() throws Exception + protected void _startApp() throws Exception { _startApplication("test/environments/runtimes/runtime9.xml", "test/environments/configs/config4.xml", "test/environments/webapp1"); - + _usersManager = (UsersManager) Init.getPluginServiceManager().lookup(UsersManager.ROLE); } @Override - protected void tearDown() throws Exception - { - _cocoon.dispose(); - super.tearDown(); - } - - @Override public void testType() throws Exception { // JDBC IMPL Index: test/src/org/ametys/runtime/test/users/ldap/LdapUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/ldap/LdapUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/ldap/LdapUsersTestCase.java (working copy) @@ -46,8 +46,19 @@ @Override protected void setUp() throws Exception { + super.setUp(); + + _startApp(); + } + + /** + * start the application + * @throws Exception if an error occurs + */ + protected void _startApp() throws Exception + { _startApplication("test/environments/runtimes/runtime8.xml", "test/environments/configs/config3.xml", "test/environments/webapp1"); - + _usersManager = (UsersManager) Init.getPluginServiceManager().lookup(UsersManager.ROLE); } Index: test/src/org/ametys/runtime/test/users/others/StaticUsersTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/users/others/StaticUsersTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/users/others/StaticUsersTestCase.java (working copy) @@ -40,7 +40,7 @@ protected void setUp() throws Exception { super.setUp(); - + _startApplication("test/environments/runtimes/runtime01.xml", "test/environments/configs/config1.xml", "test/environments/webapp1"); } Index: test/src/org/ametys/runtime/test/util/I18nTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/util/I18nTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/util/I18nTestCase.java (working copy) @@ -38,6 +38,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _startApplication("test/environments/runtimes/runtime01.xml", "test/environments/configs/config1.xml", "test/environments/webapp2"); ServiceManager manager = Init.getPluginServiceManager(); @@ -48,6 +50,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } /** Index: test/src/org/ametys/runtime/test/util/JSONTestCase.java =================================================================== --- test/src/org/ametys/runtime/test/util/JSONTestCase.java (revision 37352) +++ test/src/org/ametys/runtime/test/util/JSONTestCase.java (working copy) @@ -40,6 +40,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + _startApplication("test/environments/runtimes/runtime01.xml", "test/environments/configs/config1.xml", "test/environments/webapp2"); ServiceManager manager = Init.getPluginServiceManager(); #P Ametys - 02 Repository Index: main/plugin-repositoryapp/src/org/ametys/plugins/repositoryapp/authentication/AdminRepositoryAuthentication.java =================================================================== --- main/plugin-repositoryapp/src/org/ametys/plugins/repositoryapp/authentication/AdminRepositoryAuthentication.java (revision 37284) +++ main/plugin-repositoryapp/src/org/ametys/plugins/repositoryapp/authentication/AdminRepositoryAuthentication.java (working copy) @@ -16,6 +16,7 @@ package org.ametys.plugins.repositoryapp.authentication; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; @@ -27,32 +28,28 @@ import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLogEnabled; -import org.apache.cocoon.environment.Context; import org.apache.commons.codec.binary.Base64; import org.xml.sax.InputSource; import org.ametys.core.authentication.Credentials; import org.ametys.core.authentication.CredentialsProvider; import org.ametys.plugins.core.impl.authentication.BasicCredentialsProvider; +import org.ametys.runtime.servlet.RuntimeConfig; /** * Authentication for the repository application looking for the administrator login and password. */ public class AdminRepositoryAuthentication extends AbstractLogEnabled implements RepositoryAuthentication, Contextualizable { - /** Location (from webapplication context) of the administrator password */ - public static final String ADMINISTRATOR_PASSWORD_FILENAME = "/WEB-INF/data/administrator/admin.xml"; + /** Location of the administrator password relative to ametys home */ + public static final String ADMINISTRATOR_PASSWORD_FILENAME = "administrator/admin.xml"; /** The cocoon context, initialized during the contextualize method */ private org.apache.avalon.framework.context.Context _context; - /** The environment context */ - private Context _envContext; - public void contextualize(org.apache.avalon.framework.context.Context context) throws ContextException { _context = context; - _envContext = (Context) _context.get(org.apache.cocoon.Constants.CONTEXT_ENVIRONMENT_CONTEXT); } @Override @@ -87,7 +84,7 @@ return false; } - try (InputStream is = new FileInputStream(_envContext.getRealPath(ADMINISTRATOR_PASSWORD_FILENAME))) + try (InputStream is = new FileInputStream(new File(RuntimeConfig.getInstance().getAmetysHome(), ADMINISTRATOR_PASSWORD_FILENAME))) { XPath xpath = XPathFactory.newInstance().newXPath(); String pass = xpath.evaluate("admin/password", new InputSource(is)); @@ -118,7 +115,10 @@ { if (getLogger().isWarnEnabled()) { - getLogger().warn("The file '" + ADMINISTRATOR_PASSWORD_FILENAME + "' is missing. Default administrator password 'admin' is used.", e); + String ametysHomePath = RuntimeConfig.getInstance().getAmetysHome().getPath(); + getLogger().warn( + "The file '" + ADMINISTRATOR_PASSWORD_FILENAME + "' is missing in Ametys home '" + ametysHomePath + + "'.\nDefault administrator password 'admin' is used.", e); } return "admin".equals(passwd); } Index: webapp/WEB-INF/config/config.deliver.xml =================================================================== --- webapp/WEB-INF/config/config.deliver.xml (revision 37284) +++ webapp/WEB-INF/config/config.deliver.xml (working copy) @@ -25,5 +25,4 @@ <runtime.debug.ui>false</runtime.debug.ui> <!-- plugin.core:PLUGINS_CORE_UPLOAD_CONFIG_GROUP_UPLOAD --> <runtime.upload.max-size>10485760</runtime.upload.max-size> - <runtime.upload.dir>WEB-INF/data/uploads</runtime.upload.dir> </config> Index: webapp/WEB-INF/log4j.deliver.xml =================================================================== --- webapp/WEB-INF/log4j.deliver.xml (revision 37284) +++ webapp/WEB-INF/log4j.deliver.xml (working copy) @@ -21,7 +21,7 @@ <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="servlet" class="biz.minaret.log4j.DatedFileAppender"> - <param name="Directory" value="${context-root}/WEB-INF/logs"/> + <param name="Directory" value="${ametys.home.dir}/WEB-INF/logs"/> <param name="Prefix" value="ametys-repository-"/> <param name="Suffix" value=".log"/> <param name="Append" value="true"/> Index: webapp/WEB-INF/log4j.xml =================================================================== --- webapp/WEB-INF/log4j.xml (revision 37284) +++ webapp/WEB-INF/log4j.xml (working copy) @@ -22,7 +22,7 @@ <appender name="lf5-servlet" class="org.apache.log4j.lf5.LF5Appender"/> <appender name="servlet" class="biz.minaret.log4j.DatedFileAppender"> - <param name="Directory" value="${context-root}/WEB-INF/logs"/> + <param name="Directory" value="${ametys.home.dir}/WEB-INF/logs"/> <param name="Prefix" value="ametys-repository-"/> <param name="Suffix" value=".log"/> <param name="Append" value="true"/> Index: webapp/WEB-INF/web.xml =================================================================== --- webapp/WEB-INF/web.xml (revision 37284) +++ webapp/WEB-INF/web.xml (working copy) @@ -79,7 +79,16 @@ <param-name>log4j-config</param-name> <param-value>/WEB-INF/log4j.xml</param-value> </init-param> - + + <!-- + Ametys home property allow to use an environment variable that will indicates the Ametys home directory location. + By default the Ametys home directory location will be WEB-INF/data . + --> + <init-param> + <param-name>ametys.home.property</param-name> + <param-value>AMETYS_REPOSITORY_HOME</param-value> + </init-param> + <!-- This parameter indicates the category id of the logger from the LogKit configuration used by the CocoonServlet. #P Ametys - Plugin SkinFactory Index: main/plugin-skinfactory/src/org/ametys/skinfactory/model/SkinModelDAO.java =================================================================== --- main/plugin-skinfactory/src/org/ametys/skinfactory/model/SkinModelDAO.java (revision 37228) +++ main/plugin-skinfactory/src/org/ametys/skinfactory/model/SkinModelDAO.java (working copy) @@ -38,6 +38,7 @@ import org.ametys.core.ui.Callable; import org.ametys.plugins.skincommons.SkinEditionHelper; +import org.ametys.runtime.servlet.RuntimeConfig; import org.ametys.skinfactory.SkinFactoryComponent; import org.ametys.skinfactory.filefilter.ModelFileFilter; import org.ametys.web.cocoon.I18nTransformer; @@ -152,7 +153,9 @@ @Callable public String importModel(String modelName, String tmpDirPath) throws IOException { - File tmpDir = new File(System.getProperty("java.io.tmpdir") + File.separator + tmpDirPath.replace('/', File.separatorChar)); + File ametysTmpDir = RuntimeConfig.getInstance().getTmpDir(); + File tmpDir = new File(ametysTmpDir, tmpDirPath.replace('/', File.separatorChar)); + if (tmpDir.isDirectory()) { File rootLocation = new File(_modelsManager.getModelsLocation()); Index: main/plugin-skinfactory/src/org/ametys/skinfactory/skins/SkinDAO.java =================================================================== --- main/plugin-skinfactory/src/org/ametys/skinfactory/skins/SkinDAO.java (revision 37228) +++ main/plugin-skinfactory/src/org/ametys/skinfactory/skins/SkinDAO.java (working copy) @@ -35,14 +35,10 @@ import javax.xml.xpath.XPathFactory; import org.apache.avalon.framework.component.Component; -import org.apache.avalon.framework.context.Context; -import org.apache.avalon.framework.context.ContextException; -import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; -import org.apache.cocoon.Constants; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.xml.sax.InputSource; @@ -59,6 +55,7 @@ import org.ametys.plugins.skincommons.SkinEditionHelper; import org.ametys.plugins.skincommons.SkinLockManager; import org.ametys.runtime.parameter.ParameterHelper; +import org.ametys.runtime.servlet.RuntimeConfig; import org.ametys.skinfactory.SkinFactoryComponent; import org.ametys.skinfactory.filefilter.ModelFileFilter; import org.ametys.skinfactory.filefilter.SkinFileFilter; @@ -84,7 +81,7 @@ /** * Component to interact with a skin */ -public class SkinDAO extends AbstractLogEnabled implements Serviceable, Component, Contextualizable +public class SkinDAO extends AbstractLogEnabled implements Serviceable, Component { /** Constant for skin editor tool id */ public static final String SKIN_FACTORY_TOOL_ID = "uitool-skinfactory"; @@ -106,8 +103,6 @@ private SkinsManager _skinsManager; private UsersManager _usersManager; - private org.apache.cocoon.environment.Context _cocoonContext; - @Override public void service(ServiceManager manager) throws ServiceException { @@ -124,12 +119,6 @@ _usersManager = (UsersManager) manager.lookup(UsersManager.ROLE); } - @Override - public void contextualize(Context context) throws ContextException - { - _cocoonContext = (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); - } - /** * Check the current save state of a skin * @param skinId The skin id @@ -437,7 +426,7 @@ String skinId = site.getSkinId(); String modelName = _skinHelper.getTempModel(skinId); - File tempDir = new File (_cocoonContext.getRealPath("/WEB-INF/data/skins/temp/" + skinId)); + File tempDir = _skinHelper.getTempDirectory(skinId); String colorTheme = _skinFactoryManager.getColorTheme(tempDir); SkinModel model = _modelsManager.getModel(modelName); #P Ametys - 04 Workflow Index: test/environment/config-oracle.xml =================================================================== --- test/environment/config-oracle.xml (revision 37352) +++ test/environment/config-oracle.xml (working copy) @@ -21,10 +21,8 @@ <runtime.datasource.core.jdbc.url>jdbc:oracle:thin:@oracle10.anyware.corp:1521/XE</runtime.datasource.core.jdbc.url> <runtime.authentication.basic.realm>realm</runtime.authentication.basic.realm> <runtime.upload.max-size>10000000</runtime.upload.max-size> -<runtime.upload.dir>WEB-INF/data/uploads</runtime.upload.dir> <content.unlocktimer.activate>false</content.unlocktimer.activate> <content.unlocktimer.period>2</content.unlocktimer.period> -<org.ametys.plugins.repository.home>WEB-INF/data/repository</org.ametys.plugins.repository.home> <org.ametys.plugins.repository.cache>16777216</org.ametys.plugins.repository.cache> <repository.default.sort>document</repository.default.sort> <runtime.debug.ui>0</runtime.debug.ui> Index: test/environment/config-postgres.xml =================================================================== --- test/environment/config-postgres.xml (revision 37352) +++ test/environment/config-postgres.xml (working copy) @@ -21,10 +21,8 @@ <runtime.datasource.core.jdbc.url>jdbc:postgresql://postgresql-dev.anyware.corp/ametest</runtime.datasource.core.jdbc.url> <runtime.authentication.basic.realm>realm</runtime.authentication.basic.realm> <runtime.upload.max-size>10000000</runtime.upload.max-size> -<runtime.upload.dir>WEB-INF/data/uploads</runtime.upload.dir> <content.unlocktimer.activate>false</content.unlocktimer.activate> <content.unlocktimer.period>2</content.unlocktimer.period> -<org.ametys.plugins.repository.home>WEB-INF/data/repository</org.ametys.plugins.repository.home> <org.ametys.plugins.repository.cache>16777216</org.ametys.plugins.repository.cache> <repository.default.sort>document</repository.default.sort> <runtime.debug.ui>0</runtime.debug.ui> Index: test/environment/config.xml =================================================================== --- test/environment/config.xml (revision 37352) +++ test/environment/config.xml (working copy) @@ -21,10 +21,8 @@ <runtime.datasource.core.jdbc.url>jdbc:mysql://mysql-dev.anyware.corp/Ametys_Runtime_Test</runtime.datasource.core.jdbc.url> <runtime.authentication.basic.realm>realm</runtime.authentication.basic.realm> <runtime.upload.max-size>10000000</runtime.upload.max-size> -<runtime.upload.dir>WEB-INF/data/uploads</runtime.upload.dir> <content.unlocktimer.activate>false</content.unlocktimer.activate> <content.unlocktimer.period>2</content.unlocktimer.period> -<org.ametys.plugins.repository.home>WEB-INF/data/repository</org.ametys.plugins.repository.home> <org.ametys.plugins.repository.cache>16777216</org.ametys.plugins.repository.cache> <repository.default.sort>document</repository.default.sort> <runtime.debug.ui>0</runtime.debug.ui> Index: test/src/org/ametys/plugins/workflow/WorkflowTestCase.java =================================================================== --- test/src/org/ametys/plugins/workflow/WorkflowTestCase.java (revision 37352) +++ test/src/org/ametys/plugins/workflow/WorkflowTestCase.java (working copy) @@ -42,6 +42,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + // Remove jackrabbit home directory before each test FileUtils.deleteDirectory(new File("test/environment/webapp/WEB-INF/data/repository")); @@ -54,6 +56,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } /** #P Ametys - Plugin Flipbook Index: main/plugin-flipbook/sitemap.xmap =================================================================== --- main/plugin-flipbook/sitemap.xmap (revision 35506) +++ main/plugin-flipbook/sitemap.xmap (working copy) @@ -205,7 +205,7 @@ <map:act type="set-header"> <map:parameter name="X-Ametys-Cacheable" value="true" /> </map:act> - <map:read src="context://WEB-INF/data/flipbook/{1}/pages/{2}.png" /> + <map:read src="ametys-home://flipbook/{1}/pages/{2}.png" /> </map:match> @@ -214,7 +214,7 @@ <map:act type="set-header"> <map:parameter name="X-Ametys-Cacheable" value="true" /> </map:act> - <map:read src="context://WEB-INF/data/flipbook/{1}/document/{2}.pdf" /> + <map:read src="ametys-home://flipbook/{1}/document/{2}.pdf" /> </map:match> Index: main/plugin-flipbook/src/org/ametys/plugins/flipbook/AbstractConvertDocument2ImagesComponent.java =================================================================== --- main/plugin-flipbook/src/org/ametys/plugins/flipbook/AbstractConvertDocument2ImagesComponent.java (revision 35506) +++ main/plugin-flipbook/src/org/ametys/plugins/flipbook/AbstractConvertDocument2ImagesComponent.java (working copy) @@ -38,11 +38,12 @@ import org.apache.commons.io.IOUtils; import org.ametys.plugins.repository.AmetysObjectResolver; +import org.ametys.runtime.servlet.RuntimeConfig; /** * Document to images action: converts the document into one image per page if it is not already done. */ -public abstract class AbstractConvertDocument2ImagesComponent extends AbstractLogEnabled implements ThreadSafe, Initializable, Contextualizable, Serviceable, Component +public abstract class AbstractConvertDocument2ImagesComponent extends AbstractLogEnabled implements ThreadSafe, Initializable, Serviceable, Component { /** The ametys object resolver. */ protected AmetysObjectResolver _resolver; @@ -50,9 +51,6 @@ /** The document to images convertor. */ protected Document2ImagesConvertor _documentToImages; - /** The cocoon context */ - protected org.apache.cocoon.environment.Context _cocoonContext; - /** Map of locks, indexed by resource ID. */ private ConcurrentMap<String, ReentrantLock> _locks; @@ -63,13 +61,6 @@ } @Override - public void contextualize(Context context) throws ContextException - { - _cocoonContext = (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); - } - - - @Override public void service(ServiceManager serviceManager) throws ServiceException { _resolver = (AmetysObjectResolver) serviceManager.lookup(AmetysObjectResolver.ROLE); @@ -78,7 +69,7 @@ /** * Test if the mimetype is supported for conversion - * @param mimeType + * @param mimeType The mime type * @return true if the mimetype can be transformed */ protected boolean isMimeTypeSupported(String mimeType) @@ -88,15 +79,15 @@ /** * Create the images and put it into the cache - * @param relativeCachePath - * @param md5sum - * @param documentInputStream - * @param documentName - * @param documentId - * @param documentMimeType + * @param relativeCachePath The relative cache path + * @param md5sum The md5 sum + * @param documentInputStream The document input stream + * @param documentName The document name + * @param documentId The document identifire + * @param documentMimeType The document mime type * @return The absolute cache path - * @throws IOException - * @throws FlipbookException + * @throws IOException If an IO error occurs + * @throws FlipbookException A general flipbook exception * @throws UnsupportedOperationException If the mime type is not supported */ protected String cache(String relativeCachePath, String md5sum, InputStream documentInputStream, String documentName, String documentId, String documentMimeType) throws IOException, FlipbookException @@ -106,14 +97,14 @@ throw new UnsupportedOperationException("Cannot convert files of type '" + documentMimeType + "'"); } - String cachePath = _cocoonContext.getRealPath("/WEB-INF/data/flipbook") + "/" + relativeCachePath; - - File baseFolder = new File(cachePath); + File baseFolder = FileUtils.getFile(RuntimeConfig.getInstance().getAmetysHome(), "flipbook", relativeCachePath); if (!baseFolder.exists()) { baseFolder.mkdirs(); } + String cachePath = baseFolder.getPath(); + File md5File = new File(baseFolder, "document.md5"); if (!md5File.isFile()) { @@ -173,11 +164,11 @@ /** * Create images for a resource, in a specified folder. - * @param documentInputStream - * @param documentName + * @param documentInputStream Document inputstream + * @param documentName Document name * @param baseFolder the base folder. - * @throws IOException - * @throws FlipbookException + * @throws IOException If an IO error occurs + * @throws FlipbookException A general flipbook exception */ protected void createImages(InputStream documentInputStream, String documentName, File baseFolder) throws IOException, FlipbookException { Index: main/plugin-flipbook/src/org/ametys/plugins/flipbook/GetFirstPageAction.java =================================================================== --- main/plugin-flipbook/src/org/ametys/plugins/flipbook/GetFirstPageAction.java (revision 35506) +++ main/plugin-flipbook/src/org/ametys/plugins/flipbook/GetFirstPageAction.java (working copy) @@ -32,32 +32,22 @@ import org.apache.cocoon.environment.SourceResolver; import org.apache.commons.io.FileUtils; +import org.ametys.runtime.servlet.RuntimeConfig; + /** * Get the first page image for thumbnail */ -public class GetFirstPageAction extends ServiceableAction implements Contextualizable +public class GetFirstPageAction extends ServiceableAction { /** Request attribute from path to images' directory */ public static final String IMAGES_DIRECTORY_PATH_REQUEST_ATTR = "images-base-directory"; - /** The cocoon context */ - protected org.apache.cocoon.environment.Context _cocoonContext; - - @Override - public void contextualize(Context context) throws ContextException - { - _cocoonContext = (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); - } - public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception { String path = parameters.getParameter("path", null); + File imageFolder = FileUtils.getFile(RuntimeConfig.getInstance().getAmetysHome(), "flipbook", path, "pages"); - String rootPath = _cocoonContext.getRealPath("/WEB-INF/data/flipbook"); - String fullPath = rootPath + "/" + path; - // List the image files. - File imageFolder = new File(fullPath + "/pages"); if (imageFolder.exists()) { List<File> imageFiles = new ArrayList<>(FileUtils.listFiles(imageFolder, new String[] {"png"}, false)); #P Ametys - 07 CMS Index: main/plugin-cms/sitemap.xmap =================================================================== --- main/plugin-cms/sitemap.xmap (revision 37352) +++ main/plugin-cms/sitemap.xmap (working copy) @@ -578,7 +578,7 @@ </map:match> <map:match pattern="consistency/inconsistent-contents.xml"> - <map:generate src="context://WEB-INF/data/consistency/report.xml" type="tolerant-file"/> + <map:generate src="ametys-home://consistency/report.xml" type="tolerant-file"/> <map:transform src="stylesheets/consistency/limit.xsl"> <map:parameter name="start" value="{request-param:start}"/> <map:parameter name="limit" value="{request-param:limit}"/> @@ -596,7 +596,7 @@ </map:match> <map:match pattern="consistency/inconsistent-contents-mail.html"> - <map:generate src="context://WEB-INF/data/consistency/report.xml" type="tolerant-file"/> + <map:generate src="ametys-home://consistency/report.xml" type="tolerant-file"/> <map:transform src="stylesheets/consistency/mail.xsl"> <map:parameter name="url" value="{parent-context-attr:url}"/> </map:transform> Index: main/plugin-cms/src/org/ametys/cms/content/consistency/ContentConsistencyEngine.java =================================================================== --- main/plugin-cms/src/org/ametys/cms/content/consistency/ContentConsistencyEngine.java (revision 37352) +++ main/plugin-cms/src/org/ametys/cms/content/consistency/ContentConsistencyEngine.java (working copy) @@ -65,6 +65,7 @@ import org.ametys.plugins.repository.AmetysObjectResolver; import org.ametys.plugins.repository.AmetysRepositoryException; import org.ametys.runtime.config.Config; +import org.ametys.runtime.servlet.RuntimeConfig; /** * Content consistency engine: generate consistency information for all contents. @@ -144,7 +145,7 @@ _baseUrl = StringUtils.stripEnd(StringUtils.removeEndIgnoreCase(Config.getInstance().getValueAsString("cms.url"), "index.html"), "/"); _mailFrom = Config.getInstance().getValueAsString("smtp.mail.from"); - _reportDirectory = new File(_environmentContext.getRealPath("/WEB-INF/data/consistency")); + _reportDirectory = new File(RuntimeConfig.getInstance().getAmetysHome(), "consistency"); _initialized = true; } Index: test/environment/config.xml =================================================================== --- test/environment/config.xml (revision 37352) +++ test/environment/config.xml (working copy) @@ -17,7 +17,6 @@ <config> <content.unlocktimer.activate>true</content.unlocktimer.activate> <content.unlocktimer.period>2</content.unlocktimer.period> - <org.ametys.plugins.repository.home>WEB-INF/data/repository</org.ametys.plugins.repository.home> <org.ametys.plugins.repository.cache>16777216</org.ametys.plugins.repository.cache> <runtime.debug.ui>0</runtime.debug.ui> <runtime.cache.xslt>false</runtime.cache.xslt> Index: test/src/org/ametys/cms/content/ContentTypeTestCase.java =================================================================== --- test/src/org/ametys/cms/content/ContentTypeTestCase.java (revision 37352) +++ test/src/org/ametys/cms/content/ContentTypeTestCase.java (working copy) @@ -58,12 +58,16 @@ _startApplication("test/environment/runtime.xml", "test/environment/config.xml", "test/environment/webapp"); _contentTypeEP = (ContentTypeExtensionPoint) Init.getPluginServiceManager().lookup(ContentTypeExtensionPoint.ROLE); + + super.setUp(); } @Override protected void tearDown() throws Exception { _cocoon.dispose(); + + super.tearDown(); } /** Index: test/src/org/ametys/cms/content/DefaultContentTestCase.java =================================================================== --- test/src/org/ametys/cms/content/DefaultContentTestCase.java (revision 37352) +++ test/src/org/ametys/cms/content/DefaultContentTestCase.java (working copy) @@ -80,12 +80,16 @@ _ametysObjectResolver = (AmetysObjectResolver) Init.getPluginServiceManager().lookup(AmetysObjectResolver.ROLE); _workflow = (Workflow) Init.getPluginServiceManager().lookup(Workflow.ROLE); + + super.setUp(); } @Override protected void tearDown() throws Exception { _cocoon.dispose(); + + super.tearDown(); } /** Index: test/src/org/ametys/cms/content/MetadataManagerTestCase.java =================================================================== --- test/src/org/ametys/cms/content/MetadataManagerTestCase.java (revision 37352) +++ test/src/org/ametys/cms/content/MetadataManagerTestCase.java (working copy) @@ -64,12 +64,16 @@ _ametysObjectResolver = (AmetysObjectResolver) Init.getPluginServiceManager().lookup(AmetysObjectResolver.ROLE); _metadataManager = (MetadataManager) Init.getPluginServiceManager().lookup(MetadataManager.ROLE); _contentTypeExtensionsPoint = (ContentTypeExtensionPoint) Init.getPluginServiceManager().lookup(ContentTypeExtensionPoint.ROLE); + + super.setUp(); } @Override protected void tearDown() throws Exception { _cocoon.dispose(); + + super.tearDown(); } /** #P Ametys - 08 WEB Index: main/plugin-web/sitemap-back.xmap =================================================================== --- main/plugin-web/sitemap-back.xmap (revision 37352) +++ main/plugin-web/sitemap-back.xmap (working copy) @@ -700,7 +700,7 @@ <!-- + | CONTENT CONSISTENCY + --> <map:match pattern="consistency/*/inconsistent-contents.xml"> - <map:generate src="context://WEB-INF/data/consistency/{1}/report.xml" type="tolerant-file" /> + <map:generate src="ametys-home://consistency/{1}/report.xml" type="tolerant-file" /> <map:transform src="plugin:cms://stylesheets/consistency/limit.xsl"> <map:parameter name="start" value="{request-param:start}" /> <map:parameter name="limit" value="{request-param:limit}" /> @@ -719,7 +719,7 @@ </map:match> <map:match pattern="consistency/*/inconsistent-contents-mail.html"> - <map:generate src="context://WEB-INF/data/consistency/{1}/report.xml" type="tolerant-file" /> + <map:generate src="ametys-home://consistency/{1}/report.xml" type="tolerant-file" /> <map:transform src="plugin:cms://stylesheets/consistency/mail.xsl"> <map:parameter name="url" value="{parent-context-attr:url}" /> </map:transform> Index: main/plugin-web/src/org/ametys/web/cocoon/GenerateSiteAction.java =================================================================== --- main/plugin-web/src/org/ametys/web/cocoon/GenerateSiteAction.java (revision 37352) +++ main/plugin-web/src/org/ametys/web/cocoon/GenerateSiteAction.java (working copy) @@ -30,6 +30,7 @@ import org.apache.cocoon.environment.SourceResolver; import org.ametys.plugins.repository.AmetysObjectResolver; +import org.ametys.runtime.servlet.RuntimeConfig; import org.ametys.web.generation.SiteGenerator; import org.ametys.web.repository.site.Site; @@ -57,7 +58,7 @@ { Site site = _resolver.resolveById(source); Context context = ObjectModelHelper.getContext(objectModel); - siteGenerator.generate(manager, objectModel, site, new File(context.getRealPath("/WEB-INF/data/generation"))); + siteGenerator.generate(manager, objectModel, site, new File(RuntimeConfig.getInstance().getAmetysHome(), "generation")); } catch (Exception e) { Index: main/plugin-web/src/org/ametys/web/cocoon/I18nTransformer.java =================================================================== --- main/plugin-web/src/org/ametys/web/cocoon/I18nTransformer.java (revision 37352) +++ main/plugin-web/src/org/ametys/web/cocoon/I18nTransformer.java (working copy) @@ -137,7 +137,7 @@ if (StringUtils.isNotEmpty(skinName)) { - message = _getExternalMessage ("context://" + skinLocation + "/" + skinName + "/i18n", key); + message = _getExternalMessage ("ametys-home://" + skinLocation + "/" + skinName + "/i18n", key); } if (message == null) Index: main/plugin-web/src/org/ametys/web/skin/SkinDAO.java =================================================================== --- main/plugin-web/src/org/ametys/web/skin/SkinDAO.java (revision 37352) +++ main/plugin-web/src/org/ametys/web/skin/SkinDAO.java (working copy) @@ -54,6 +54,7 @@ import org.ametys.plugins.repository.metadata.UnknownMetadataException; import org.ametys.runtime.parameter.Errors; import org.ametys.runtime.parameter.ParameterHelper; +import org.ametys.runtime.servlet.RuntimeConfig; import org.ametys.web.cocoon.I18nTransformer; import org.ametys.web.cocoon.I18nUtils; import org.ametys.web.repository.site.Site; @@ -265,7 +266,8 @@ { Map<String, Object> result = new HashMap<>(); - File tmpDir = new File(System.getProperty("java.io.tmpdir") + File.separator + tmpDirPath.replace('/', File.separatorChar)); + File tmpDir = new File(RuntimeConfig.getInstance().getTmpDir(), tmpDirPath.replace('/', File.separatorChar)); + if (tmpDir.isDirectory()) { File rootLocation = new File(_skinsManager.getSkinsLocation()); Index: main/plugin-web/src/org/ametys/web/skin/SkinsManager.java =================================================================== --- main/plugin-web/src/org/ametys/web/skin/SkinsManager.java (revision 37352) +++ main/plugin-web/src/org/ametys/web/skin/SkinsManager.java (working copy) @@ -34,9 +34,11 @@ import org.apache.cocoon.Constants; import org.apache.cocoon.components.ContextHelper; import org.apache.cocoon.environment.Request; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.excalibur.source.SourceResolver; +import org.ametys.runtime.servlet.RuntimeConfig; import org.ametys.web.repository.site.SiteManager; /** @@ -149,7 +151,7 @@ String skinLocation = (String) request.getAttribute("skin-location"); if (skinLocation != null) { - return _cocoonContext.getRealPath("/" + skinLocation); + return new File(RuntimeConfig.getInstance().getAmetysHome(), skinLocation).getPath(); } } catch (CascadingRuntimeException e) @@ -211,7 +213,7 @@ String skinLocation = (String) request.getAttribute("skin-location"); if (skinLocation != null) { - return _cocoonContext.getRealPath("/" + skinLocation + "/" + id); + return FileUtils.getFile(RuntimeConfig.getInstance().getAmetysHome(), skinLocation, id).getPath(); } return _cocoonContext.getRealPath("/skins/" + id); Index: main/plugin-web/src/org/ametys/web/skin/actions/SkinConfigurationAction.java =================================================================== --- main/plugin-web/src/org/ametys/web/skin/actions/SkinConfigurationAction.java (revision 37352) +++ main/plugin-web/src/org/ametys/web/skin/actions/SkinConfigurationAction.java (working copy) @@ -43,6 +43,7 @@ import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.SourceResolver; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.excalibur.xml.sax.SAXParser; import org.slf4j.LoggerFactory; @@ -60,9 +61,10 @@ import org.ametys.runtime.parameter.ParameterHelper.ParameterType; import org.ametys.runtime.parameter.Validator; import org.ametys.runtime.plugin.component.ThreadSafeComponentManager; +import org.ametys.runtime.servlet.RuntimeConfig; import org.ametys.web.skin.Skin; -import org.ametys.web.skin.SkinsManager; import org.ametys.web.skin.SkinParameter; +import org.ametys.web.skin.SkinsManager; /** * Get the skin configuration parameters and their values @@ -103,7 +105,8 @@ } else { - skinDir = new File(System.getProperty("java.io.tmpdir") + File.separator + tempDir.replace('/', File.separatorChar) + File.separator + skinDirName); + File ametysTmpDir = RuntimeConfig.getInstance().getTmpDir(); + skinDir = FileUtils.getFile(ametysTmpDir, tempDir.replace('/', File.separatorChar), skinDirName); } Map<String, Object> result = new HashMap<>(); Index: main/plugin-web/src/org/ametys/web/skin/actions/UploadSkinAction.java =================================================================== --- main/plugin-web/src/org/ametys/web/skin/actions/UploadSkinAction.java (revision 37352) +++ main/plugin-web/src/org/ametys/web/skin/actions/UploadSkinAction.java (working copy) @@ -43,6 +43,7 @@ import org.apache.tika.io.IOUtils; import org.ametys.core.cocoon.JSonReader; +import org.ametys.runtime.servlet.RuntimeConfig; /** * This action receive a form with the "importfile" zip file as an exported skin. @@ -130,7 +131,8 @@ */ protected File _unzip(File uploadedFile) throws IOException { - File tmpFile = new File(System.getProperty("java.io.tmpdir") + File.separator + Long.toString(Math.round(Math.random() * 1000000.0))); + File tmpFile = new File(RuntimeConfig.getInstance().getTmpDir(), Long.toString(Math.round(Math.random() * 1000000.0))); + getLogger().debug("Importing skin in tmp dir " + tmpFile.getAbsolutePath()); ZipFile zipFile = new ZipFile(uploadedFile, "cp437"); #P Ametys - 03 Plugin Repository Index: main/plugin-repository/i18n/messages_en.xml =================================================================== --- main/plugin-repository/i18n/messages_en.xml (revision 37352) +++ main/plugin-repository/i18n/messages_en.xml (working copy) @@ -24,8 +24,6 @@ <message key="PLUGINS_REPOSITORY_CONFIG_CONTENT_UNLOCKTIMER_PERIOD_DESCRIPTION">Number of hours before the automatic unlocking will be triggered.</message> <message key="PLUGINS_REPOSITORY_CONFIG_JCR">JCR Repository</message> - <message key="PLUGINS_REPOSITORY_CONFIG_JCR_HOME_LABEL">Path</message> - <message key="PLUGINS_REPOSITORY_CONFIG_JCR_HOME_DESCRIPTION">Path to the repository directory.<br/>The directory can be empty but must already exist.<br/>You can use a path relative to your web application directory. The directory path must not end with the '/' character.<br/>Samples: '/home/cms/data/repository' or 'WEB-INF/data/repository'.</message> <message key="PLUGINS_REPOSITORY_CONFIG_JCR_CACHE_LABEL">Cache size</message> <message key="PLUGINS_REPOSITORY_CONFIG_JCR_CACHE_DESCRIPTION">Size of the JCR cache in bytes (defaults to 16777216, ie. 16 Mb).</message> <message key="PLUGINS_REPOSITORY_CONFIG_JCR_JNDI_LABEL">JNDI Identifier</message> @@ -103,7 +101,4 @@ <message key="PLUGINS_REPOSITORY_ADMINISTRATOR_LABEL">JCR repository</message> <message key="PLUGINS_REPOSITORY_ADMINISTRATOR_DESCRIPTION">Access to JCR repository explorer</message> - <!-- Parameter checkers --> - <message key="PLUGINS_REPOSITORY_REPOSITORY_CHECKER_LABEL">JCR repository location</message> - <message key="PLUGINS_REPOSITORY_REPOSITORY_CHECKER_DESC">This test checks the existence of the specified folder or the possibility to create it otherwise, and then if Ametys can write in it. The created folder is temporary and is deleted at the end of the test.</message> </catalogue> Index: main/plugin-repository/i18n/messages_fr.xml =================================================================== --- main/plugin-repository/i18n/messages_fr.xml (revision 37352) +++ main/plugin-repository/i18n/messages_fr.xml (working copy) @@ -24,8 +24,6 @@ <message key="PLUGINS_REPOSITORY_CONFIG_CONTENT_UNLOCKTIMER_PERIOD_DESCRIPTION">Nombre d'heures devant s'écouler avant le déverrouillage automatique.</message> <message key="PLUGINS_REPOSITORY_CONFIG_JCR">Repository JCR</message> - <message key="PLUGINS_REPOSITORY_CONFIG_JCR_HOME_LABEL">Chemin d'accès</message> - <message key="PLUGINS_REPOSITORY_CONFIG_JCR_HOME_DESCRIPTION">Chemin d'accès jusqu'au répertoire contenant le repository de données.<br/>Le répertoire peut-être vide mais doit exister.<br/>Vous pouvez utiliser un chemin relatif à l'application web. Le chemin ne doit pas finir par '/'.<br/>Exemple : '/home/cms/data/repository' ou 'WEB-INF/data/repository'.</message> <message key="PLUGINS_REPOSITORY_CONFIG_JCR_CACHE_LABEL">Taille du cache</message> <message key="PLUGINS_REPOSITORY_CONFIG_JCR_CACHE_DESCRIPTION">Taille du cache JCR en octets (par défaut 16777216, soit 16 Mo).</message> <message key="PLUGINS_REPOSITORY_CONFIG_JCR_JNDI_LABEL">Identifiant JNDI</message> @@ -103,8 +101,4 @@ <message key="PLUGINS_REPOSITORY_ADMINISTRATOR_LABEL">Repository JCR</message> <message key="PLUGINS_REPOSITORY_ADMINISTRATOR_DESCRIPTION">Accès à l'explorateur JCR</message> - <!-- Parameter checkers --> - <message key="PLUGINS_REPOSITORY_REPOSITORY_CHECKER_LABEL">Chemin d'accès JCR</message> - <message key="PLUGINS_REPOSITORY_REPOSITORY_CHECKER_DESC">Ce test vérifie l'existence du dossier spécifié ou la possibilité de créer ce nouveau dossier sinon, puis qu'Ametys a bien les droits d'écriture. Le dossier créée est temporaire et est supprimé à la fin du test.</message> - </catalogue> Index: main/plugin-repository/plugin.xml =================================================================== --- main/plugin-repository/plugin.xml (revision 37352) +++ main/plugin-repository/plugin.xml (working copy) @@ -125,20 +125,6 @@ <feature name="provider.jackrabbit"> <config> - <param id="org.ametys.plugins.repository.home" type="string"> - <label i18n="true">PLUGINS_REPOSITORY_CONFIG_JCR_HOME_LABEL</label> - <description i18n="true">PLUGINS_REPOSITORY_CONFIG_JCR_HOME_DESCRIPTION</description> - <validation> - <mandatory/> - <regexp>^.*[^\/]$</regexp> - <invalidText i18n="true">plugin.core:PLUGINS_CORE_REGEXP_INVALID_PATH</invalidText> - </validation> - <default-value>WEB-INF/data/repository</default-value> - <category i18n="true">plugin.repositoryapp:PLUGINS_REPOSITORYAPP_CONFIG_CATEGORY</category> - <group i18n="true">PLUGINS_REPOSITORY_CONFIG_JCR</group> - <order>10</order> - </param> - <param id="org.ametys.plugins.repository.cache" type="long"> <label i18n="true">PLUGINS_REPOSITORY_CONFIG_JCR_CACHE_LABEL</label> <description i18n="true">PLUGINS_REPOSITORY_CONFIG_JCR_CACHE_DESCRIPTION</description> @@ -148,30 +134,8 @@ <default-value>16777216</default-value> <category i18n="true">plugin.repositoryapp:PLUGINS_REPOSITORYAPP_CONFIG_CATEGORY</category> <group i18n="true">PLUGINS_REPOSITORY_CONFIG_JCR</group> - <order>20</order> + <order>10</order> </param> - - <param-checker id="repository-checker" class="org.ametys.plugins.core.impl.checker.DirectoryChecker"> - <label i18n="true">PLUGINS_REPOSITORY_REPOSITORY_CHECKER_LABEL</label> - <description i18n="true">PLUGINS_REPOSITORY_REPOSITORY_CHECKER_DESC</description> - <icon-large plugin="core">img/config/check/test_directorywrite_48.png</icon-large> - <icon-medium plugin="core">img/config/check/test_directorywrite_32.png</icon-medium> - <icon-small plugin="core">img/config/check/test_directorywrite_16.png</icon-small> - - <configuration> - <check-write/> - <creates-if-required/> - </configuration> - - <ui-ref> - <order>1</order> - <param-ref id="org.ametys.plugins.repository.home"/> - </ui-ref> - - <linked-params> - <param-ref id="org.ametys.plugins.repository.home"/> - </linked-params> - </param-checker> </config> <components> <component role="javax.jcr.Repository" Index: main/plugin-repository/src/org/ametys/plugins/repository/provider/JackrabbitRepository.java =================================================================== --- main/plugin-repository/src/org/ametys/plugins/repository/provider/JackrabbitRepository.java (revision 37352) +++ main/plugin-repository/src/org/ametys/plugins/repository/provider/JackrabbitRepository.java (working copy) @@ -41,6 +41,7 @@ import org.ametys.plugins.repository.RepositoryConstants; import org.ametys.runtime.config.Config; +import org.ametys.runtime.servlet.RuntimeConfig; /** * JackrabbitRepository is a JCR repository component based on Jackrabbit @@ -59,15 +60,9 @@ public void initialize() throws Exception { - String home = Config.getInstance().getValueAsString("org.ametys.plugins.repository.home"); String config = _context.getRealPath("/WEB-INF/param/repository.xml"); - File homeFile = new File(home); - if (!homeFile.isAbsolute()) - { - // No : consider it relative to context path - homeFile = new File(_context.getRealPath("/" + home)); - } + File homeFile = new File(RuntimeConfig.getInstance().getAmetysHome(), "repository"); if (getLogger().isDebugEnabled()) { Index: test/environment/config.xml =================================================================== --- test/environment/config.xml (revision 37352) +++ test/environment/config.xml (working copy) @@ -17,7 +17,6 @@ <config> <content.unlocktimer.activate>true</content.unlocktimer.activate> <content.unlocktimer.period>2</content.unlocktimer.period> - <org.ametys.plugins.repository.home>WEB-INF/data/repository</org.ametys.plugins.repository.home> <org.ametys.plugins.repository.cache>16777216</org.ametys.plugins.repository.cache> <org.ametys.plugins.repository.jndi>jcr/globalRepository</org.ametys.plugins.repository.jndi> <repository.default.sort>document</repository.default.sort> Index: test/src/org/ametys/plugins/repository/AbstractRepositoryTestCase.java =================================================================== --- test/src/org/ametys/plugins/repository/AbstractRepositoryTestCase.java (revision 37352) +++ test/src/org/ametys/plugins/repository/AbstractRepositoryTestCase.java (working copy) @@ -69,6 +69,8 @@ @Override protected void setUp() throws Exception { + super.setUp(); + // Remove jackrabbit home directory before each test FileUtils.deleteDirectory(new File(JR_HOME_DIR)); @@ -105,6 +107,7 @@ protected void tearDown() throws Exception { _cocoon.dispose(); + super.tearDown(); } /** #P Ametys - Plugin NTLMAuthentication Index: main/plugin-ntlm-authentication/src/org/ametys/plugins/ntlm/authentication/NTLMCredentialsProvider.java =================================================================== --- main/plugin-ntlm-authentication/src/org/ametys/plugins/ntlm/authentication/NTLMCredentialsProvider.java (revision 35507) +++ main/plugin-ntlm-authentication/src/org/ametys/plugins/ntlm/authentication/NTLMCredentialsProvider.java (working copy) @@ -15,6 +15,7 @@ */ package org.ametys.plugins.ntlm.authentication; +import java.io.File; import java.util.HashMap; import java.util.Map; @@ -22,11 +23,9 @@ import javax.servlet.ServletContext; import jcifs.ntlmssp.Type3Message; -import jespa.http.HttpSecurityFilter; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; -import org.apache.cocoon.Constants; import org.apache.cocoon.components.ContextHelper; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.Request; @@ -34,11 +33,12 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang.StringUtils; +import org.ametys.core.authentication.Credentials; +import org.ametys.core.authentication.filter.RuntimeFilter; +import org.ametys.plugins.core.impl.authentication.RemoteUserCredentialsProvider; import org.ametys.runtime.authentication.AuthorizationRequiredException; -import org.ametys.runtime.authentication.Credentials; -import org.ametys.runtime.authentication.filter.RuntimeFilter; import org.ametys.runtime.config.Config; -import org.ametys.runtime.plugins.core.authentication.RemoteUserCredentialsProvider; +import org.ametys.runtime.servlet.RuntimeConfig; /** @@ -71,7 +71,7 @@ // Authentication filter. parameters.put("fallback.location", "/"); - parameters.put("jespa.log.path", ((org.apache.cocoon.environment.Context) _context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT)).getRealPath("/WEB-INF/logs/jespa.log")); + parameters.put("jespa.log.path", new File(RuntimeConfig.getInstance().getAmetysHome(), "logs/jespa.log").getPath()); if (!config.getValueAsString("runtime.authentication.ntlm.localhost.dns").isEmpty()) { parameters.put("localhost.dns.name", config.getValueAsString("runtime.authentication.ntlm.localhost.dns")); #P Ametys - 09 SITE Index: main/plugin-site/i18n/messages_en.xml =================================================================== --- main/plugin-site/i18n/messages_en.xml (revision 37228) +++ main/plugin-site/i18n/messages_en.xml (working copy) @@ -20,8 +20,6 @@ <message key="SITE_CONFIG_BO_CATEGORY">CMS</message> <message key="SITE_CONFIG_BO_GROUP">CMS</message> - <message key="SITE_CONFIG_ROOT_LABEL">Cache directory URL</message> - <message key="SITE_CONFIG_ROOT_DESCRIPTION">Cache directory URL. Use context://... for a relative path or file:// for an absolute path.</message> <message key="SITE_CONFIG_CACHE_MAX_FILENAME_LENGTH_LABEL">Filename length limit</message> <message key="SITE_CONFIG_CACHE_MAX_FILENAME_LENGTH_DESCRIPTION">Specify a maximum length for the cache file names. <br/><b>Be careful!</b> Don't modify this value unless you're sure you understand what it implies. An ill-adapted value can prevent pages with long names for being displayed, or decrease cache performances.</message> <message key="SITE_CONFIG_ROOT_CATEGORY">Cache</message> Index: main/plugin-site/i18n/messages_fr.xml =================================================================== --- main/plugin-site/i18n/messages_fr.xml (revision 37228) +++ main/plugin-site/i18n/messages_fr.xml (working copy) @@ -20,8 +20,6 @@ <message key="SITE_CONFIG_BO_CATEGORY">CMS</message> <message key="SITE_CONFIG_BO_GROUP">CMS</message> - <message key="SITE_CONFIG_ROOT_LABEL">URL de répertoire du cache</message> - <message key="SITE_CONFIG_ROOT_DESCRIPTION">URL de répertoire du cache. Utilisez context://... pour un chemin relatif ou file:// pour un chemin absolu.</message> <message key="SITE_CONFIG_CACHE_MAX_FILENAME_LENGTH_LABEL">Limite de longueur du nom des fichiers</message> <message key="SITE_CONFIG_CACHE_MAX_FILENAME_LENGTH_DESCRIPTION">Indiquez ici le nombre maximum de caractères du nom des fichiers dans le cache.<br/><b>Attention !</b> Ne modifiez cette valeur que si vous êtes certain d'en comprendre les implications. Une mauvaise valeur peut empêcher les pages au nom trop long d'être affichées, ou réduire les performances du cache.</message> <message key="SITE_CONFIG_ROOT_CATEGORY">Cache</message> Index: main/plugin-site/plugin.xml =================================================================== --- main/plugin-site/plugin.xml (revision 37228) +++ main/plugin-site/plugin.xml (working copy) @@ -27,13 +27,6 @@ <category i18n="true">SITE_CONFIG_BO_CATEGORY</category> <group i18n="true">SITE_CONFIG_BO_GROUP</group> </param> - <param type="string" id="org.ametys.site.root"> - <label i18n="true">SITE_CONFIG_ROOT_LABEL</label> - <description i18n="true">SITE_CONFIG_ROOT_DESCRIPTION</description> - <default-value>context://WEB-INF/data/cache</default-value> - <category i18n="true">SITE_CONFIG_ROOT_CATEGORY</category> - <group i18n="true">SITE_CONFIG_ROOT_GROUP</group> - </param> <param type="long" id="org.ametys.site.cache.max.filename.length"> <label i18n="true">SITE_CONFIG_CACHE_MAX_FILENAME_LENGTH_LABEL</label> <description i18n="true">SITE_CONFIG_CACHE_MAX_FILENAME_LENGTH_DESCRIPTION</description> Index: main/workspace-site/sitemap.xmap =================================================================== --- main/workspace-site/sitemap.xmap (revision 37228) +++ main/workspace-site/sitemap.xmap (working copy) @@ -57,7 +57,7 @@ <map:parameter name="page" value="skins/{1}"/> <map:read type="cms-response"/> </map:act> - <map:read type="site-resource" src="{config:org.ametys.site.root}/skins/{1}"/> + <map:read type="site-resource" src="ametys-home://cache/skins/{1}"/> </map:match> <map:match pattern="_generate/plugins/**"> @@ -65,7 +65,7 @@ <map:parameter name="page" value="plugins/{1}"/> <map:read type="cms-response"/> </map:act> - <map:read type="site-resource" src="{config:org.ametys.site.root}/plugins/{1}"/> + <map:read type="site-resource" src="ametys-home://cache/plugins/{1}"/> </map:match> <map:match pattern="_generate/**"> @@ -73,7 +73,7 @@ <map:parameter name="page" value="{1}"/> <map:read type="cms-response"/> </map:act> - <map:read type="site-resource" src="{config:org.ametys.site.root}/{request-param:site}/{1}"/> + <map:read type="site-resource" src="ametys-home://cache/{request-param:site}/{1}"/> </map:match> </map:pipeline> @@ -144,29 +144,29 @@ <map:match pattern="**"> <map:act type="get-site"> <!-- First lookup the site directory --> - <map:act type="resource-exists" src="{config:org.ametys.site.root}/{site}/{path}"> + <map:act type="resource-exists" src="ametys-home://cache/{site}/{path}"> <map:parameter name="site" value="{site}"/> <map:act type="set-content-disposition"/> - <map:read type="site-resource" src="{config:org.ametys.site.root}/{../site}/{../path}"/> + <map:read type="site-resource" src="ametys-home://cache/{../site}/{../path}"/> </map:act> <!-- Then test if the resource is cacheable --> <map:act type="is-cacheable" src="{site}/{path}"> - <map:parameter name="uri" value="{config:org.ametys.site.root}/{site}/{path}"/> + <map:parameter name="uri" value="ametys-home://cache/{site}/{path}"/> <map:parameter name="site" value="{site}"/> <map:act type="set-content-disposition"/> - <map:read type="site-resource" src="{config:org.ametys.site.root}/{../site}/{../path}"/> + <map:read type="site-resource" src="ametys-home://cache/{../site}/{../path}"/> </map:act> <!-- Finally asks the CMS --> <map:redirect-to uri="cocoon:/_generate/{site}/{path}"/> </map:act> <!-- First lookup in common directories (skins, plugins, ...) --> - <map:act type="resource-exists" src="{config:org.ametys.site.root}/{request-attr:path}"> - <map:read src="{config:org.ametys.site.root}/{request-attr:path}"/> + <map:act type="resource-exists" src="ametys-home://cache/{request-attr:path}"> + <map:read src="ametys-home://cache/{request-attr:path}"/> </map:act> <!-- Then test if the resource is cacheable --> <map:act type="is-cacheable" src="{request-attr:path}"> - <map:parameter name="uri" value="{config:org.ametys.site.root}/{request-attr:path}"/> - <map:read src="{config:org.ametys.site.root}/{request-attr:path}"/> + <map:parameter name="uri" value="ametys-home://cache/{request-attr:path}"/> + <map:read src="ametys-home://cache/{request-attr:path}"/> </map:act> <!-- Finally asks the CMS --> <map:redirect-to uri="cocoon:/_generate/{request-attr:path}"/> Index: main/workspace-site/src/org/ametys/site/GeneratePageAction.java =================================================================== --- main/workspace-site/src/org/ametys/site/GeneratePageAction.java (revision 37228) +++ main/workspace-site/src/org/ametys/site/GeneratePageAction.java (working copy) @@ -37,8 +37,6 @@ import org.apache.cocoon.environment.Response; import org.apache.cocoon.environment.Session; import org.apache.commons.lang.StringUtils; -import org.apache.excalibur.source.SourceResolver; -import org.apache.excalibur.source.impl.FileSource; import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpUriRequest; @@ -47,8 +45,8 @@ import org.ametys.core.authentication.AuthenticateAction; import org.ametys.plugins.site.Site; import org.ametys.runtime.authentication.AccessDeniedException; -import org.ametys.runtime.config.Config; import org.ametys.runtime.exception.ServiceUnavailableException; +import org.ametys.runtime.servlet.RuntimeConfig; /** * Call the BO for getting a page content and stores it in the local cache. @@ -58,8 +56,6 @@ private static final Pattern __COOKIE_PATH_PATTERN = Pattern.compile(".*(Path=[^;]+).*"); - private SourceResolver _resolver; - private CacheAccessManager _cacheAccess; private CacheAccessCounter _cacheAccessCounter; @@ -67,7 +63,6 @@ public void service(ServiceManager sManager) throws ServiceException { super.service(sManager); - _resolver = (SourceResolver) sManager.lookup(SourceResolver.ROLE); _cacheAccess = (CacheAccessManager) sManager.lookup(CacheAccessManager.ROLE); _cacheAccessCounter = (CacheAccessCounter) sManager.lookup(CacheAccessCounter.ROLE); } @@ -265,8 +260,7 @@ getLogger().debug("The page is cacheable, writing into the cache: " + decodedPage); } - String rootCache = Config.getInstance().getValueAsString("org.ametys.site.root"); - File root = ((FileSource) _resolver.resolveURI(rootCache)).getFile(); + File root = SiteCacheHelper.getRootCache(); File file = getFile(root, decodedPage); if (!file.exists()) Index: main/workspace-site/src/org/ametys/site/Init.java =================================================================== --- main/workspace-site/src/org/ametys/site/Init.java (revision 37228) +++ main/workspace-site/src/org/ametys/site/Init.java (working copy) @@ -33,10 +33,10 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.excalibur.source.SourceResolver; -import org.apache.excalibur.source.impl.FileSource; import org.ametys.core.util.mail.SendMailHelper; import org.ametys.runtime.config.Config; +import org.ametys.runtime.servlet.RuntimeConfig; /** * Init class for FO application. @@ -68,8 +68,7 @@ @Override public void init() throws Exception { - String rootCache = Config.getInstance().getValueAsString("org.ametys.site.root"); - File root = ((FileSource) _resolver.resolveURI(rootCache)).getFile(); + File root = SiteCacheHelper.getRootCache(); try { Index: main/workspace-site/src/org/ametys/site/InvalidateImagesAction.java =================================================================== --- main/workspace-site/src/org/ametys/site/InvalidateImagesAction.java (revision 37228) +++ main/workspace-site/src/org/ametys/site/InvalidateImagesAction.java (working copy) @@ -27,11 +27,10 @@ import org.apache.cocoon.environment.Redirector; import org.apache.commons.io.FileUtils; import org.apache.excalibur.source.SourceResolver; -import org.apache.excalibur.source.impl.FileSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.ametys.runtime.config.Config; +import org.ametys.runtime.servlet.RuntimeConfig; /** * Invalidates cached data for a given site. @@ -39,14 +38,12 @@ public class InvalidateImagesAction extends ServiceableAction implements ThreadSafe { private Logger _logger = LoggerFactory.getLogger("site.cache.log"); - private SourceResolver _resolver; private CacheAccessManager _cacheAccess; @Override public void service(ServiceManager sManager) throws ServiceException { super.service(sManager); - _resolver = (SourceResolver) sManager.lookup(SourceResolver.ROLE); _cacheAccess = (CacheAccessManager) sManager.lookup(CacheAccessManager.ROLE); } @@ -55,8 +52,7 @@ { String path = parameters.getParameter("path"); - String rootCache = Config.getInstance().getValueAsString("org.ametys.site.root"); - File root = ((FileSource) _resolver.resolveURI(rootCache)).getFile(); + File root = SiteCacheHelper.getRootCache(); // files to delete are like path/to/file_100x200.jpg Index: main/workspace-site/src/org/ametys/site/InvalidatePageAction.java =================================================================== --- main/workspace-site/src/org/ametys/site/InvalidatePageAction.java (revision 37228) +++ main/workspace-site/src/org/ametys/site/InvalidatePageAction.java (working copy) @@ -26,11 +26,10 @@ import org.apache.cocoon.environment.Redirector; import org.apache.commons.io.FileUtils; import org.apache.excalibur.source.SourceResolver; -import org.apache.excalibur.source.impl.FileSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.ametys.runtime.config.Config; +import org.ametys.runtime.servlet.RuntimeConfig; /** * Invalidates cached data for a given site. @@ -55,11 +54,9 @@ public Map act(Redirector redirector, org.apache.cocoon.environment.SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception { String site = parameters.getParameter("site"); - String page = parameters.getParameter("page"); - String rootCache = Config.getInstance().getValueAsString("org.ametys.site.root"); - File root = ((FileSource) _resolver.resolveURI(rootCache)).getFile(); + File root = SiteCacheHelper.getRootCache(); String path = site + "/" + page; Index: main/workspace-site/src/org/ametys/site/InvalidateSharedResourcesAction.java =================================================================== --- main/workspace-site/src/org/ametys/site/InvalidateSharedResourcesAction.java (revision 37228) +++ main/workspace-site/src/org/ametys/site/InvalidateSharedResourcesAction.java (working copy) @@ -57,8 +57,7 @@ { String path = parameters.getParameter("path"); - String rootCache = Config.getInstance().getValueAsString("org.ametys.site.root"); - File root = ((FileSource) _resolver.resolveURI(rootCache)).getFile(); + File root = SiteCacheHelper.getRootCache(); for (File site : root.listFiles(new SiteFilter())) { Index: main/workspace-site/src/org/ametys/site/InvalidateSiteAction.java =================================================================== --- main/workspace-site/src/org/ametys/site/InvalidateSiteAction.java (revision 37228) +++ main/workspace-site/src/org/ametys/site/InvalidateSiteAction.java (working copy) @@ -54,8 +54,7 @@ { String site = parameters.getParameter("site"); - String rootCache = Config.getInstance().getValueAsString("org.ametys.site.root"); - File root = ((FileSource) _resolver.resolveURI(rootCache)).getFile(); + File root = SiteCacheHelper.getRootCache(); File siteRoot = new File(root, site); if (siteRoot.exists()) Index: main/workspace-site/src/org/ametys/site/InvalidateSkinAction.java =================================================================== --- main/workspace-site/src/org/ametys/site/InvalidateSkinAction.java (revision 37228) +++ main/workspace-site/src/org/ametys/site/InvalidateSkinAction.java (working copy) @@ -49,8 +49,7 @@ { String skin = parameters.getParameter("skin"); - String rootCache = Config.getInstance().getValueAsString("org.ametys.site.root"); - File root = ((FileSource) _resolver.resolveURI(rootCache)).getFile(); + File root = SiteCacheHelper.getRootCache(); File skinRoot = new File(root, "skins/" + skin); if (skinRoot.exists()) Index: main/workspace-site/src/org/ametys/site/ResourceExistsAction.java =================================================================== --- main/workspace-site/src/org/ametys/site/ResourceExistsAction.java (revision 37228) +++ main/workspace-site/src/org/ametys/site/ResourceExistsAction.java (working copy) @@ -39,7 +39,6 @@ import org.ametys.plugins.site.cache.monitoring.Constants; import org.ametys.plugins.site.cache.monitoring.process.access.ResourceAccessComponent; import org.ametys.plugins.site.cache.monitoring.process.access.impl.FrontResourceAccess; -import org.ametys.runtime.config.Config; /** * The cocoon resource exists action but that returns false for folders @@ -75,7 +74,7 @@ String uuid = UUID.randomUUID().toString(); request.setAttribute("Monitoring-UUID", uuid); - String path = StringUtils.removeStart(resourceURI, Config.getInstance().getValueAsString("org.ametys.site.root")); + String path = StringUtils.removeStart(resourceURI, SiteCacheHelper.getRootCache().getPath()); FrontResourceAccess fra = new FrontResourceAccess(uniqueId, uuid, parameters.getParameter("site", null), path); try Index: main/workspace-site/src/org/ametys/site/SiteCacheHelper.java =================================================================== --- main/workspace-site/src/org/ametys/site/SiteCacheHelper.java (revision 37228) +++ main/workspace-site/src/org/ametys/site/SiteCacheHelper.java (working copy) @@ -30,6 +30,7 @@ import org.ametys.core.util.URLEncoder; import org.ametys.runtime.config.Config; +import org.ametys.runtime.servlet.RuntimeConfig; /** * Class providing helper methods for cache files. @@ -45,6 +46,15 @@ } /** + * Return the root cache file + * @return The root cache File + */ + public static File getRootCache() + { + return new File(RuntimeConfig.getInstance().getAmetysHome(), "cache"); + } + + /** * Test if a file is valid. * @param file the file to test. * @return true if the file is valid, false otherwise. #P Ametys - Plugin SkinEditor Index: main/plugin-skineditor/src/org/ametys/plugins/skineditor/readers/SkinResourceReader.java =================================================================== --- main/plugin-skineditor/src/org/ametys/plugins/skineditor/readers/SkinResourceReader.java (revision 37228) +++ main/plugin-skineditor/src/org/ametys/plugins/skineditor/readers/SkinResourceReader.java (working copy) @@ -128,7 +128,7 @@ private Source _getSource (String skinName, String path) throws IOException { - return _srcResolver.resolveURI("context://WEB-INF/data/skins/temp/" + skinName + _decodePath(path)); + return _srcResolver.resolveURI("ametys-home://skins/temp/" + skinName + _decodePath(path)); } private String _decodePath (String path) throws UnsupportedEncodingException Index: main/plugin-skineditor/src/org/ametys/plugins/skineditor/skin/GetTempSkinResourcesAction.java =================================================================== --- main/plugin-skineditor/src/org/ametys/plugins/skineditor/skin/GetTempSkinResourcesAction.java (revision 37228) +++ main/plugin-skineditor/src/org/ametys/plugins/skineditor/skin/GetTempSkinResourcesAction.java (working copy) @@ -35,7 +35,7 @@ protected String getRootURI(Request request) { String skinName = request.getParameter("skinName"); - return "context://WEB-INF/data/skins/temp/" + skinName; + return "ametys-home://skins/temp/" + skinName; } @Override #P Ametys - 06 Explorer Index: webapp/WEB-INF/config/config.deliver.xml =================================================================== --- webapp/WEB-INF/config/config.deliver.xml (revision 37352) +++ webapp/WEB-INF/config/config.deliver.xml (working copy) @@ -39,7 +39,6 @@ <runtime.debug.ui>2</runtime.debug.ui> <!-- plugin.core:PLUGINS_CORE_UPLOAD_CONFIG_GROUP_UPLOAD --> <runtime.upload.max-size>10485760</runtime.upload.max-size> - <runtime.upload.dir>WEB-INF/data/uploads</runtime.upload.dir> <!--+ | plugin.core:PLUGINS_CORE_DATASOURCE_CORE_CONFIG_CATEGORY_AUTHENTICATION @@ -53,7 +52,6 @@ +--> <!-- plugin.repository:PLUGINS_REPOSITORY_CONFIG_JCR --> - <org.ametys.plugins.repository.home>WEB-INF/data/repository</org.ametys.plugins.repository.home> <org.ametys.plugins.repository.cache>16777216</org.ametys.plugins.repository.cache> <!-- plugin.repository:PLUGINS_REPOSITORY_CONFIG_UNLOCKTIMER --> <content.unlocktimer.activate>true</content.unlocktimer.activate> Index: webapp/WEB-INF/log4j.deliver.xml =================================================================== --- webapp/WEB-INF/log4j.deliver.xml (revision 37352) +++ webapp/WEB-INF/log4j.deliver.xml (working copy) @@ -18,7 +18,7 @@ <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="servlet" class="biz.minaret.log4j.DatedFileAppender"> - <param name="Directory" value="${context-root}/WEB-INF/logs"/> + <param name="Directory" value="${ametys.home.dir}/WEB-INF/logs"/> <param name="Prefix" value="cms-"/> <param name="Suffix" value=".log"/> <param name="Append" value="true"/> Index: webapp/WEB-INF/log4j.xml =================================================================== --- webapp/WEB-INF/log4j.xml (revision 37352) +++ webapp/WEB-INF/log4j.xml (working copy) @@ -20,7 +20,7 @@ <appender name="lf5-servlet" class="org.apache.log4j.lf5.LF5Appender"/> <appender name="servlet" class="biz.minaret.log4j.DatedFileAppender"> - <param name="Directory" value="${context-root}/WEB-INF/logs"/> + <param name="Directory" value="${ametys.home.dir}/WEB-INF/logs"/> <param name="Prefix" value="cms-"/> <param name="Suffix" value=".log"/> <param name="Append" value="true"/> Index: webapp/WEB-INF/web.xml =================================================================== --- webapp/WEB-INF/web.xml (revision 37352) +++ webapp/WEB-INF/web.xml (working copy) @@ -240,7 +240,17 @@ <param-name>form-encoding</param-name> <param-value>utf-8</param-value> </init-param> - + + <!-- + Ametys home property allow to use an environment variable that will indicates the Ametys home directory location. + By default the Ametys home directory location will be WEB-INF/data . + --> + <init-param> + <param-name>ametys.home.property</param-name> + <param-value>AMETYS_EXPLORER_HOME</param-value> + </init-param> + + <!-- This parameter allows you to startup Cocoon2 immediately after startup of your servlet engine.