Fixed rewriting paths in the jsp/js and css resources
This commit is contained in:
		| @ -32,7 +32,7 @@ public class Plugin { | |||||||
|     private Class<AbstractLesson> lesson; |     private Class<AbstractLesson> lesson; | ||||||
|     private Map<String, File> solutionLanguageFiles = new HashMap<>(); |     private Map<String, File> solutionLanguageFiles = new HashMap<>(); | ||||||
|     private Map<String, File> lessonPlansLanguageFiles = new HashMap<>(); |     private Map<String, File> lessonPlansLanguageFiles = new HashMap<>(); | ||||||
|     private List<File> cssFiles = Lists.newArrayList(); |     private List<File> pluginFiles = Lists.newArrayList(); | ||||||
|     private File lessonSourceFile; |     private File lessonSourceFile; | ||||||
|  |  | ||||||
|     public Plugin(Path pluginDirectory) { |     public Plugin(Path pluginDirectory) { | ||||||
| @ -79,8 +79,8 @@ public class Plugin { | |||||||
|             if (fileEndsWith(file, ".properties") && hasParentDirectoryWithName(file, NAME_LESSON_I18N_DIRECTORY)) { |             if (fileEndsWith(file, ".properties") && hasParentDirectoryWithName(file, NAME_LESSON_I18N_DIRECTORY)) { | ||||||
|                 copyProperties(reload, file); |                 copyProperties(reload, file); | ||||||
|             } |             } | ||||||
|             if (fileEndsWith(file, ".css")) { |             if (fileEndsWith(file, ".css", ".jsp", ".js")) { | ||||||
|                 cssFiles.add(file.toFile()); |                 pluginFiles.add(file.toFile()); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -120,10 +120,23 @@ public class Plugin { | |||||||
|                     pluginTarget.getFileName().toString() + "/plugin/" + this.lesson |                     pluginTarget.getFileName().toString() + "/plugin/" + this.lesson | ||||||
|                             .getSimpleName() + "/lessonPlans/en/" + this.lesson.getSimpleName() + "_files", |                             .getSimpleName() + "/lessonPlans/en/" + this.lesson.getSimpleName() + "_files", | ||||||
|                     lessonPlansLanguageFiles.values()); |                     lessonPlansLanguageFiles.values()); | ||||||
|             replaceInFiles("setSrc\\(\"js\\/", "setSrc\\(\"" + pluginTarget.getFileName().toString() + "/plugin/" + this.lesson |  | ||||||
|                     .getSimpleName() + "/js/", Arrays.asList(lessonSourceFile)); |             String[] replacements = {"jsp", "js"}; | ||||||
|             replaceInFiles("url\\(images", "url\\(" + pluginTarget.getFileName().toString() + "/plugin/" + this.lesson |             for ( String replacement : replacements ) { | ||||||
|                     .getSimpleName() + "/jsp/images", cssFiles); |                 String s = String.format("plugin/%s/%s/", this.lesson.getSimpleName(), replacement); | ||||||
|  |                 String r = String.format("%s/plugin/%s/%s/", pluginTarget.getFileName().toString(), | ||||||
|  |                         this.lesson.getSimpleName(), replacement); | ||||||
|  |                 replaceInFiles(s,r, pluginFiles); | ||||||
|  |                 replaceInFiles(s,r, Arrays.asList(lessonSourceFile)); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             //CSS with url('/plugin/images') should not begin with / otherwise image cannot be found | ||||||
|  |             String s = String.format("/plugin/%s/images/", this.lesson.getSimpleName()); | ||||||
|  |             String r = String.format("%s/plugin/%s/images/", pluginTarget.getFileName().toString(), this.lesson.getSimpleName()); | ||||||
|  |             replaceInFiles(s,r, pluginFiles); | ||||||
|  |             replaceInFiles(s,r, Arrays.asList(lessonSourceFile)); | ||||||
|  |  | ||||||
|  |  | ||||||
|         } catch (IOException e) { |         } catch (IOException e) { | ||||||
|             throw new PluginLoadingFailure("Unable to rewrite the paths in the solutions", e); |             throw new PluginLoadingFailure("Unable to rewrite the paths in the solutions", e); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -21,6 +21,15 @@ public class PluginFileUtils { | |||||||
|         return p.getFileName().toString().endsWith(s); |         return p.getFileName().toString().endsWith(s); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static boolean fileEndsWith(Path p, String... suffixes) { | ||||||
|  |         for (String suffix : suffixes) { | ||||||
|  |             if (fileEndsWith(p, suffix)) { | ||||||
|  |                 return true; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public static boolean hasParentDirectoryWithName(Path p, String s) { |     public static boolean hasParentDirectoryWithName(Path p, String s) { | ||||||
|         if (p == null || p.getParent() == null || p.getParent().equals(p.getRoot())) { |         if (p == null || p.getParent() == null || p.getParent().equals(p.getRoot())) { | ||||||
|             return false; |             return false; | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user