clean i18n directory when first time loading
This commit is contained in:
		| @ -71,7 +71,7 @@ public class Plugin { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void loadFiles(List<Path> files) { | ||||
|     public void loadFiles(List<Path> files, boolean reload) { | ||||
|         for (Path file : files) { | ||||
|             if (fileEndsWith(file, ".html") && hasParentDirectoryWithName(file, NAME_LESSON_SOLUTION_DIRECTORY)) { | ||||
|                 solutionLanguageFiles.put(file.getParent().getFileName().toString(), file.toFile()); | ||||
| @ -83,19 +83,26 @@ public class Plugin { | ||||
|                 lessonSourceFile = file.toFile(); | ||||
|             } | ||||
|             if (fileEndsWith(file, ".properties") && hasParentDirectoryWithName(file, NAME_LESSON_I18N_DIRECTORY)) { | ||||
|                 copyProperties(reload, file); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void copyProperties(boolean reload, Path file) { | ||||
|         try { | ||||
|             ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||||
|             Files.copy(file, bos); | ||||
|             Path propertiesPath = createPropertiesDirectory(); | ||||
|             ResourceBundleClassLoader.setPropertiesPath(propertiesPath); | ||||
|                     Files.write(propertiesPath.resolve(file.getFileName()), bos.toByteArray(), | ||||
|                         StandardOpenOption.CREATE, StandardOpenOption.APPEND); | ||||
|             if ( reload ) { | ||||
|                 Files.write(propertiesPath.resolve(file.getFileName()), bos.toByteArray(), StandardOpenOption.CREATE, StandardOpenOption.APPEND); | ||||
|             } else { | ||||
|                 Files.write(propertiesPath.resolve(file.getFileName()), bos.toByteArray(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); | ||||
|             } | ||||
|         } catch (IOException io) { | ||||
|             throw new PluginLoadingFailure("Property file detected, but unable to copy the properties", io); | ||||
|         } | ||||
|     } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private Path createPropertiesDirectory() throws IOException { | ||||
|         if (Files.exists(pluginDirectory.resolve(NAME_LESSON_I18N_DIRECTORY))) { | ||||
|  | ||||
| @ -21,7 +21,7 @@ public class PluginsLoader implements Runnable { | ||||
|         this.path = path; | ||||
|     } | ||||
|  | ||||
|     public List<Plugin> loadPlugins() { | ||||
|     public List<Plugin> loadPlugins(final boolean reload) { | ||||
|         final List<Plugin> plugins = new ArrayList<Plugin>(); | ||||
|         try { | ||||
|             Files.walkFileTree(path, new SimpleFileVisitor<Path>() { | ||||
| @ -33,7 +33,7 @@ public class PluginsLoader implements Runnable { | ||||
|                         extractor.extract(); | ||||
|                         Plugin plugin = new Plugin(extractor.getBaseDirectory()); | ||||
|                         plugin.loadClasses(extractor.getClasses()); | ||||
|                         plugin.loadFiles(extractor.getFiles()); | ||||
|                         plugin.loadFiles(extractor.getFiles(), reload); | ||||
|                         plugins.add(plugin); | ||||
|                     } catch (Plugin.PluginLoadingFailure e) { | ||||
|                        logger.error("Unable to load plugin, continue reading others..."); | ||||
| @ -51,6 +51,6 @@ public class PluginsLoader implements Runnable { | ||||
|  | ||||
|     @Override | ||||
|     public void run() { | ||||
|         loadPlugins(); | ||||
|         loadPlugins(true); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -316,7 +316,7 @@ public class Course { | ||||
|         } | ||||
|         Path pluginDirectory = Paths.get(path); | ||||
|         webgoatContext.setPluginDirectory(pluginDirectory); | ||||
|         List<Plugin> plugins = new PluginsLoader(pluginDirectory).loadPlugins(); | ||||
|         List<Plugin> plugins = new PluginsLoader(pluginDirectory).loadPlugins(false); | ||||
|         for (Plugin plugin : plugins) { | ||||
|             try { | ||||
|                 Class<AbstractLesson> c = plugin.getLesson(); | ||||
|  | ||||
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user