Texen
  1. Texen
  2. TEXEN-13

Generator.parse fails, if the outputfile points to a directory, that does not exist.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1
    • Labels:
      None

      Description

      The Texentask generates the outputdirectory, if it does not exist, but the Generator-Implementation lacks this feature for control templates like the following:

      1. control.vm
        $generator.parse("myTemplate.vm", "subdirectory/myTemplate.out")

      So either allow subclasses of TexenTask to use another Generator (1), or change the implementation of getWriter to allow the Generator to create absent directories(2).

      (1)
      line 486:
      Generator generator = createGenerator();

      protected Generator createGenerator() {
      return Generator.getInstance();
      }

      (2)
      public Writer getWriter(final String path, final String encoding) throws Exception {
      final File f = new File(path).getParentFile();
      if (!f.exists())

      { f.mkdirs(); }

      ..
      }

        Activity

        Sebastian Zarnekow created issue -
        Sebastian Zarnekow made changes -
        Field Original Value New Value
        Description The Texentask generates the outputdirectory, if it does not exist, but the Generator-Implementation lacks this feature for control templates like the following:

        # control.vm
        $generator.parse("myTemplate.vm", "subdirectory/myTemplate.out")

        So either allow subclasses of TexenTask to use another Generator (1), or change the implementation of getWriter to allow the Generator to create absent (2).

        (1)
        line 486:
        Generator generator = createGenerator();

        protected Generator createGenerator() {
          return Generator.getInstance();
        }

        (2)
        public Writer getWriter(final String path, final String encoding) throws Exception {
          final File f = new File(path).getParentFile();
          if (!f.exists()) {
            f.mkdirs();
          }
          ..
        }
        The Texentask generates the outputdirectory, if it does not exist, but the Generator-Implementation lacks this feature for control templates like the following:

        # control.vm
        $generator.parse("myTemplate.vm", "subdirectory/myTemplate.out")

        So either allow subclasses of TexenTask to use another Generator (1), or change the implementation of getWriter to allow the Generator to create absent directories(2).

        (1)
        line 486:
        Generator generator = createGenerator();

        protected Generator createGenerator() {
          return Generator.getInstance();
        }

        (2)
        public Writer getWriter(final String path, final String encoding) throws Exception {
          final File f = new File(path).getParentFile();
          if (!f.exists()) {
            f.mkdirs();
          }
          ..
        }
        Hide
        Will Glass-Husain added a comment -

        Hi,

        I added your first suggestion – move the creation of the generator into a protected method, allowing it to be overridden.

        I'm not sure about the idea of creating directories. For one thing, this only creates one level – what if multiple parts of the path are invalid.

        I'm going to resolve the issue. If you want to reopen and discuss, that's fine. It'd be useful if you could point to other libraries which do this (create parent directories or trees of directories) when trying to write a file. Most ant tasks I've called don't. (they give an error that the path doesn't exist).

        Show
        Will Glass-Husain added a comment - Hi, I added your first suggestion – move the creation of the generator into a protected method, allowing it to be overridden. I'm not sure about the idea of creating directories. For one thing, this only creates one level – what if multiple parts of the path are invalid. I'm going to resolve the issue. If you want to reopen and discuss, that's fine. It'd be useful if you could point to other libraries which do this (create parent directories or trees of directories) when trying to write a file. Most ant tasks I've called don't. (they give an error that the path doesn't exist).
        Will Glass-Husain made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Will Glass-Husain made changes -
        Fix Version/s 1.1 [ 12312817 ]
        Affects Version/s 1.0 [ 12312816 ]
        Hide
        Sebastian Zarnekow added a comment -

        Thanks for extracting createGenerator.
        However the actual implementation of Generator as a singleton makes it impossible to successfully work with a subclass.
        I attached a patch that allows to inherit from Generator and will not break existing code. Tests included.

        Show
        Sebastian Zarnekow added a comment - Thanks for extracting createGenerator. However the actual implementation of Generator as a singleton makes it impossible to successfully work with a subclass. I attached a patch that allows to inherit from Generator and will not break existing code. Tests included.
        Sebastian Zarnekow made changes -
        Attachment GeneratorNotReallyASingleton.patch [ 12367462 ]
        Will Glass-Husain made changes -
        Status Resolved [ 5 ] Reopened [ 4 ]
        Resolution Fixed [ 1 ]
        Hide
        Will Glass-Husain added a comment -

        Thanks for contributing. Nice idea. Does "ant test" work?

        By the way, please take a look at the code style guidelines on our wiki when you have a chance. It's much easier to update the code if the patch follows them. (4 spaces, not tabs, and the bodies of all if statements need matching braces on their own lines). I'll fix the code this time.

        Show
        Will Glass-Husain added a comment - Thanks for contributing. Nice idea. Does "ant test" work? By the way, please take a look at the code style guidelines on our wiki when you have a chance. It's much easier to update the code if the patch follows them. (4 spaces, not tabs, and the bodies of all if statements need matching braces on their own lines). I'll fix the code this time.
        Hide
        Sebastian Zarnekow added a comment -

        Thanks for the pointer to the code style guidelines.
        The patch contains a new test that uses a custom generator.
        "ant test" works.

        Show
        Sebastian Zarnekow added a comment - Thanks for the pointer to the code style guidelines. The patch contains a new test that uses a custom generator. "ant test" works.
        Hide
        Will Glass-Husain added a comment -

        patch applied, thanks again.

        Show
        Will Glass-Husain added a comment - patch applied, thanks again.
        Will Glass-Husain made changes -
        Resolution Fixed [ 1 ]
        Status Reopened [ 4 ] Resolved [ 5 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Sebastian Zarnekow
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development