[MAGNOLIA-1018] JavascriptIncludePage doesn't respect classpath when loading javascript class definitions. Created: 28/Aug/06  Updated: 04/Nov/15  Resolved: 04/Nov/15

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Chris Miner Assignee: Philipp Bärfuss
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: 0.25h
Time Spent: Not Specified
Original Estimate: 0.25h
Environment:

irrelevant


Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

If you include two defnintions of a javascript class in your classpath then the JavascriptIncludePage will prefer the last definition in the path. This is not expected since it isn't the way it works with java classes. The first definition found should be preferred. Here's a patch to the renderHtml method:

Index: /home/chris/Documents/magnolia-all/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/pages/JavascriptIncludePage.java
===================================================================
— /home/chris/Documents/magnolia-all/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/pages/JavascriptIncludePage.java (revision 6053)
+++ /home/chris/Documents/magnolia-all/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/pages/JavascriptIncludePage.java (working copy)
@@ -125,21 +125,28 @@
// request.getRequestDispatcher("/.resources/js-libs/*.js").include(request, response);

for (int j = 0; j < files.length; j++) {

  • String name = files[j];
  • Definition def = new Definition();
  • def.name = StringUtils.replace(name, "
    ", "/");
  • def.name = StringUtils.substringAfterLast(def.name, "/js-classes/");
  • def.name = StringUtils.removeEnd(def.name, ".js");
  • def.name = StringUtils.replace(def.name, "/", ".");
  • InputStream stream = ClasspathResourcesUtil.getStream(name);
  • def.content = IOUtils.toString(stream);
  • stream.close();
  • Matcher matcher = importPattern.matcher(def.content);
  • while (matcher.find()) {
  • String importName = matcher.group(1);
  • def.imports.add(importName);
    + String streamName = files[j];
    +
    + // extract a class name based on file path
    + String className = StringUtils.replace(streamName, "
    ", "/");
    + className = StringUtils.substringAfterLast(className, "/js-classes/");
    + className = StringUtils.removeEnd(className, ".js");
    + className = StringUtils.replace(className, "/", ".");
    +
    + // only load up the first definition of a class
    + if (classDefinitions.get(className) == null)
    Unknown macro: {+ Definition def = new Definition();+ def.name = className;+ InputStream stream = ClasspathResourcesUtil.getStream(streamName);+ def.content = IOUtils.toString(stream);+ stream.close(); + Matcher matcher = importPattern.matcher(def.content);+ while (matcher.find()) { + String importName = matcher.group(1); + def.imports.add(importName); + }+ classDefinitions.put(def.name, def); }
  • classDefinitions.put(def.name, def);
    }

// write first the runtime



 Comments   
Comment by Chris Miner [ 29/Aug/06 ]

It could be said that the current solution matches expectations wrt javascript that being that functions defined later replace those defined earlier. Although, as a practical issue it is nice to be able to override class definitions for java as well as the javascript in the same way. Which is to say move the jar up in the class path.

Comment by Michael Mühlebach [ 04/Nov/15 ]

Given the thousands of other issues we have open that are more highly requested, we won't be able to address this issue in the foreseeable future. Instead we will focus on issues with a higher impact, and more votes.
Thanks for taking the time to raise this issue. As you are no doubt aware this issue has been on our backlog for some time now with very little movement.
I'm going to close this to set expectations so the issue doesn't stay open for years with few updates. If the issue is still relevant please feel free to reopen it or create a new issue.

Generated at Mon Feb 12 03:22:52 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.