Skip to content

withFileFromClasspath does not work for resources within a jar #213

Closed

Description

As per the title ClasspathTrait.withFileFromClassPath fails with

Can't get size from blah blah blah path/SKYNET-0.7-SNAPSHOT.jar!/com/example/Dockerfile

When it is given a classpath resource within a jar.

For the moment I'm working round this with a transferable that copies the resource to a byte array

  static Transferable fromClasspath(final String resourcePath) {
    URL resource = ClasspathTrait.class.getClassLoader()
        .getResource(resourcePath);

    try (InputStream stream = resource.openStream()) {
      byte[] bytes = IOUtils.toByteArray(stream);

      return new Transferable() {
        @Override
        public long getSize() {
          return bytes.length;
        }

        @Override
        public void transferTo(OutputStream outputStream) {
          try {
            IOUtils.write(bytes, outputStream);
          } catch (IOException e) {
            throw new RuntimeException(
                "Can't transfer resource " + resourcePath, e);
          }
        }
      };
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  };

But it would be preferable for the DSL to support this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions