private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); delegate = Resources.fromPath(path); }
/** * Used to look up resources based on user provided path using the Data Directory as base * directory. * * <p>Convenience method for Resources.fromPath(resources.get(Paths.BASE), path) * * <p>See {@link Resources#fromPath(String, Resource)} */ public Resource fromPath(String path) { return Resources.fromPath(path, resources.get(Paths.BASE)); }
/** * Helper method that infers the directory that contains or will contain GWC configuration. * First we will check if a specific location was set using properties GEOWEBCACHE_CONFIG_DIR * and GEOWEBCACHE_CACHE_DIR, then we will check if a location was provided and then fallback on * the default location. */ private static Resource inferConfigDirectory( ResourceStore resourceStore, String providedConfigDirectory) { // check if a specific location was provided using a context property otherwise use the // provided directory String configDirectoryPath = findFirstDefined(GEOWEBCACHE_CONFIG_DIR_PROPERTY, GEOWEBCACHE_CACHE_DIR_PROPERTY) .orElse(providedConfigDirectory); // if the configuration directory stills not defined we use the default location if (configDirectoryPath == null) { configDirectoryPath = DEFAULT_CONFIGURATION_DIR_NAME; } // instantiate a resource for the configuration directory File configurationDirectory = new File(configDirectoryPath); if (configurationDirectory.isAbsolute()) { return Resources.fromPath(configurationDirectory.getAbsolutePath()); } // configuration directory path is relative to geoserver data directory return resourceStore.get(configDirectoryPath); }
Resource uploadsRoot = Resources.fromPath(value); return Resources.directory(uploadsRoot, !Resources.exists(uploadsRoot));
/** * @param sourceBackupFolder * @param mosaicIndexBase * @param res * @throws IOException */ private boolean copyFile( final Resource sourceBackupFolder, final Resource mosaicIndexBase, Resource res, boolean overwrite) throws IOException { final String relative = sourceBackupFolder.dir().toURI().relativize(res.file().toURI()).getPath(); Resource targetFtl = Resources.fromPath(relative, mosaicIndexBase.parent()); if (!Resources.exists(targetFtl) || overwrite) { if (!targetFtl.parent().dir().exists()) { targetFtl.parent().dir().mkdirs(); } Resources.copy(res.file(), targetFtl.parent()); return true; } return false; } }
.getPath(); Resource targetFtl = Resources.fromPath(relative, targetBackupFolder);
@Test public void testUploadRootExternalProps() throws Exception { // On a brand new data folder, the directory may not exists until the Importer has been // invoked the first time File dirFromProperties = Resources.directory(Resources.fromPath("props_uploads")); // Read the upload root folder and creates it if does not exists importer.getUploadRoot(); // Read the folder again... dirFromProperties = Resources.directory(Resources.fromPath("props_uploads")); // ... and ensure it is the same as defined on the .properties file assertEquals(dirFromProperties, importer.getUploadRoot()); // Let's now override the external folder through the Environment variable. This takes // precedence on .properties System.setProperty(Importer.UPLOAD_ROOT_KEY, "env_uploads"); // Let's check that the upload root is now different from the previous one... assertNotEquals(dirFromProperties, importer.getUploadRoot()); // ... but it is equal to the one defined through the Environment variable instead // Read the folder again... dirFromProperties = Resources.directory(Resources.fromPath("env_uploads")); // ... and ensure it is the same as defined on the .properties file assertEquals(dirFromProperties, importer.getUploadRoot()); }