Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSuchFileException with read.resource.lines #348

Closed
mduerig opened this Issue Feb 17, 2016 · 8 comments

Comments

Projects
None yet
3 participants
@mduerig
Copy link

mduerig commented Feb 17, 2016

I get a NSFE for a resource that I can otherwise load through getClass.getResource:

@ load.ivy("michid" % "script-oak" % "1.1-SNAPSHOT")

@ val name = "TarAnalysis.scala"
name: String = "TarAnalysis.scala"

@ val url = getClass.getResource("/scripts/" + name)
url: java.net.URL = jar:file:/Users/mduerig/.ivy2/cache/michid/script-oak/jars/script-oak-1.1-SNAPSHOT.jar!/scripts/TarAnalysis.scala

@ read.resource.lines(root/'scripts/name)
java.nio.file.NoSuchFileException: /scripts/TarAnalysis.scala
  ammonite.ops.read$resource$.readIn(FileOps.scala:331)
  ammonite.ops.Internals$Reader$lines$iter$.apply(FileOps.scala:76)
  ammonite.ops.Internals$Reader$lines$iter$.apply(FileOps.scala:74)
  ammonite.ops.StreamableOp1$class.apply(FileOps.scala:117)
  ammonite.ops.Internals$Reader$lines$.apply(FileOps.scala:72)
  cmd3$.<init>(Main.scala:239)
  cmd3$.<clinit>(Main.scala:239)

See https://github.com/mduerig/script-oak for "michid" % "script-oak" % "1.1-SNAPSHOT"

@lihaoyi

This comment has been minimized.

Copy link
Owner

lihaoyi commented Feb 19, 2016

The basic problem seems to be that read.resource! (or read! resource in master) doesn't take advantage of the current classloader that's set up by load.ivy. Not sure if that'll be easy to fix

@lihaoyi lihaoyi added the enhancement label Feb 23, 2016

@lihaoyi

This comment has been minimized.

Copy link
Owner

lihaoyi commented Mar 6, 2016

@mduerig I cannot reproduce this locally; can you publish your script-oak thing somewhere i can reach it?

@lihaoyi

This comment has been minimized.

Copy link
Owner

lihaoyi commented Mar 6, 2016

@ load.ivy("michid" % "script-oak" % "1.1-SNAPSHOT")
:: loading settings :: url = jar:file:/Users/haoyi/amm!/org/apache/ivy/core/settings/ivysettings.xml
:: resolving dependencies :: michid#script-oak-caller;working
    confs: [default]

:: problems summary ::
:::: WARNINGS
        module not found: michid#script-oak;1.1-SNAPSHOT

    ==== ivy-cache: tried

      /Users/haoyi/.ivy2/cache/michid/script-oak/jars/ivy-1.1-SNAPSHOT.xml

      -- artifact michid#script-oak;1.1-SNAPSHOT!script-oak.jar:

      /Users/haoyi/.ivy2/cache/michid/script-oak/jars/script-oak-1.1-SNAPSHOT.jar

    ==== cache: tried

      /Users/haoyi/.ivy2/cache/michid/script-oak/jars/ivy-1.1-SNAPSHOT.xml

      -- artifact michid#script-oak;1.1-SNAPSHOT!script-oak.jar:

      /Users/haoyi/.ivy2/cache/michid/script-oak/jars/script-oak-1.1-SNAPSHOT.jar

    ==== local: tried

      /Users/haoyi/.ivy2/local/michid/script-oak/1.1-SNAPSHOT/jars/ivy.xml

      -- artifact michid#script-oak;1.1-SNAPSHOT!script-oak.jar:

      /Users/haoyi/.ivy2/local/michid/script-oak/1.1-SNAPSHOT/jars/script-oak.jar

    ==== m2: tried

      /Users/haoyi/.m2/repository/michid/script-oak/1.1-SNAPSHOT/ivy-1.1-SNAPSHOT.xml

      -- artifact michid#script-oak;1.1-SNAPSHOT!script-oak.jar:

      /Users/haoyi/.m2/repository/michid/script-oak/1.1-SNAPSHOT/script-oak-1.1-SNAPSHOT.jar

    ==== central: tried

      http://repo1.maven.org/maven2/michid/script-oak/1.1-SNAPSHOT/script-oak-1.1-SNAPSHOT.pom

      -- artifact michid#script-oak;1.1-SNAPSHOT!script-oak.jar:

      http://repo1.maven.org/maven2/michid/script-oak/1.1-SNAPSHOT/script-oak-1.1-SNAPSHOT.jar


:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
ammonite.repl.IvyThing$IvyResolutionException: failed to resolve ivy dependencies unresolved dependency: michid#script-oak;1.1-SNAPSHOT: not found
  ammonite.repl.IvyThing.resolveArtifact(IvyThing.scala:100)
  ammonite.repl.interp.Interpreter$DefaultLoadJar.ivy(Interpreter.scala:216)
  cmd3$.<init>(Main.scala:52)
  cmd3$.<clinit>(Main.scala:-1)

@ load.ivy("michid" % "script-oak" % "1.1")
:: resolving dependencies :: michid#script-oak-caller;working
    confs: [default]

:: problems summary ::
:::: WARNINGS
        module not found: michid#script-oak;1.1

    ==== ivy-cache: tried

      /Users/haoyi/.ivy2/cache/michid/script-oak/jars/ivy-1.1.xml

      -- artifact michid#script-oak;1.1!script-oak.jar:

      /Users/haoyi/.ivy2/cache/michid/script-oak/jars/script-oak-1.1.jar

    ==== cache: tried

      /Users/haoyi/.ivy2/cache/michid/script-oak/jars/ivy-1.1.xml

      -- artifact michid#script-oak;1.1!script-oak.jar:

      /Users/haoyi/.ivy2/cache/michid/script-oak/jars/script-oak-1.1.jar

    ==== local: tried

      /Users/haoyi/.ivy2/local/michid/script-oak/1.1/jars/ivy.xml

      -- artifact michid#script-oak;1.1!script-oak.jar:

      /Users/haoyi/.ivy2/local/michid/script-oak/1.1/jars/script-oak.jar

    ==== m2: tried

      /Users/haoyi/.m2/repository/michid/script-oak/1.1/ivy-1.1.xml

      -- artifact michid#script-oak;1.1!script-oak.jar:

      /Users/haoyi/.m2/repository/michid/script-oak/1.1/script-oak-1.1.jar

    ==== central: tried

      http://repo1.maven.org/maven2/michid/script-oak/1.1/script-oak-1.1.pom

      -- artifact michid#script-oak;1.1!script-oak.jar:

      http://repo1.maven.org/maven2/michid/script-oak/1.1/script-oak-1.1.jar


:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
ammonite.repl.IvyThing$IvyResolutionException: failed to resolve ivy dependencies unresolved dependency: michid#script-oak;1.1: not found
  ammonite.repl.IvyThing.resolveArtifact(IvyThing.scala:100)
  ammonite.repl.interp.Interpreter$DefaultLoadJar.ivy(Interpreter.scala:216)
  cmd4$.<init>(Main.scala:52)
  cmd4$.<clinit>(Main.scala:-1)
@mduerig

This comment has been minimized.

Copy link
Author

mduerig commented Mar 6, 2016

This reproduces with any resource from an artefact loaded through ivy. Try with the following, which is available through Maven central:

@ load.ivy("org.apache.jackrabbit" % "oak-core" % "1.3.16")

@ val path = Path("/org/apache/jackrabbit/oak/plugins/blob/blobstore.properties")
path: Path = root/'org/'apache/'jackrabbit/'oak/'plugins/'blob/"blobstore.properties"

// This works
@ getClass.getResource(path.toString)
res16: java.net.URL = jar:file:/Users/mduerig/.ivy2/cache/org.apache.jackrabbit/oak-core/jars/oak-core-1.3.16.jar!/org/apache/jackrabbit/oak/plugins/blob/blobstore.properties

// This doesn't
@ read.resource.lines(path)
java.nio.file.NoSuchFileException: /org/apache/jackrabbit/oak/plugins/blob/blobstore.properties
  ammonite.ops.read$resource$.readIn(FileOps.scala:331)
  ammonite.ops.Internals$Reader$lines$iter$.apply(FileOps.scala:76)
  ammonite.ops.Internals$Reader$lines$iter$.apply(FileOps.scala:74)
  ammonite.ops.StreamableOp1$class.apply(FileOps.scala:117)
  ammonite.ops.Internals$Reader$lines$.apply(FileOps.scala:72)
  cmd17$.<init>(Main.scala:272)
  cmd17$.<clinit>(Main.scala:-1)
@lihaoyi

This comment has been minimized.

Copy link
Owner

lihaoyi commented Mar 7, 2016

This reproduces with any resource from an artefact loaded through ivy.

Hehehe I know but I was lazy and wanted you to find an example so I wouldn't have to 😛

I'll take a look, thanks!

@lihaoyi lihaoyi closed this Mar 7, 2016

@lihaoyi lihaoyi reopened this Mar 7, 2016

lihaoyi pushed a commit that referenced this issue Mar 23, 2016

Li Haoyi
- Make `read! resource` read from the `Thread.currentThread.getContex…
…tClassLoader` by default, fixing #348

- Re-organize `read! resource` to allow proper handling of absolute and relative resources by passing in `Class`s or `ClassLoader`s
- Make `read!` work on `InputStream`s
@lihaoyi

This comment has been minimized.

Copy link
Owner

lihaoyi commented Mar 24, 2016

Should be fixed by 71d1a7f...

@lihaoyi lihaoyi closed this Mar 24, 2016

@mduerig

This comment has been minimized.

Copy link
Author

mduerig commented Mar 27, 2016

Thanks for fixing, works great!

@cvogt

This comment has been minimized.

Copy link
Contributor

cvogt commented Mar 28, 2016

@lihaoyi for my use case, this doesn't happen anymore, but now this happens: #368

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.