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

Using coveralls in cross-project #104

Closed
GRBurst opened this issue Jan 4, 2018 · 14 comments
Closed

Using coveralls in cross-project #104

GRBurst opened this issue Jan 4, 2018 · 14 comments

Comments

@GRBurst
Copy link

GRBurst commented Jan 4, 2018

Hey,

I am having troubles to use sbt coveralls with a cross-project. Since the coverage reports are not available for scalajs (as far as I know), I want to test the coverage of the JVM part only.

Currently I am doing the following with sbt 1.0.4:

sbt ";project graphJVM; coverage; test; coverageReport"
sbt ";project graphJVM; coveralls"

This results in the following exception:

java.lang.IllegalArgumentException: requirement failed: Source directories must not be nested: [...]/graph/jvm/src/main/scala-2.12 is contained in [...]/graph/jvm/src/main/scala

This is strange, because the shown path does not exist and graph is a pure cross-project, which means that I only have a shared src folder, e.g. graph/shared/src/ and not graph/jvm/src. Here graph/jvm only contains a target folder.

However, if I call sbt coveralls on a pure scala sbt sub-project, it succeeds.
This indicates that there is an issue with the coverage of the JVM part of cross projects.

How can I get it to work?

Thanks for your help in advance!

Kind regards :-)

@pme123
Copy link

pme123 commented Mar 28, 2018

I have the same problem

pdolega added a commit to pdolega/sbt-coveralls that referenced this issue Mar 28, 2018
@pdolega
Copy link
Contributor

pdolega commented Mar 28, 2018

The reason behind it is most likely that sbt-coverall thinks scala-2.12 is nested within scala directory.

Here is full stack trace that I am getting:

[info] (results may not appear immediately)
[error] java.lang.IllegalArgumentException: requirement failed: Source directories must not be nested: /home/pdolega/projects/ReactSphere-2018/ReactSphere-reactive-beyond-hype/codebase/src/main/scala-2.12 is contained in /home/pdolega/projects/ReactSphere-2018/ReactSphere-reactive-beyond-hype/codebase/src/main/scala
[error]         at scala.Predef$.require(Predef.scala:277)
[error]         at org.scoverage.coveralls.CoberturaMultiSourceReader.<init>(CoberturaMultiSourceReader.scala:17)
[error]         at org.scoverage.coveralls.CoverallsPlugin$.$anonfun$coverallsTask$1(CoverallsPlugin.scala:107)
[error]         at org.scoverage.coveralls.CoverallsPlugin$.$anonfun$coverallsTask$1$adapted(CoverallsPlugin.scala:57)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:39)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:66)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:262)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:271)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:262)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:174)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:36)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]         at java.lang.Thread.run(Thread.java:748)
[error] (coveralls) java.lang.IllegalArgumentException: requirement failed: Source directories must not be nested: /home/pdolega/projects/ReactSphere-2018/ReactSphere-reactive-beyond-hype/codebase/src/main/scala-2.12 is contained in /home/pdolega/projects/ReactSphere-2018/ReactSphere-reactive-beyond-hype/codebase/src/main/scala
[error] Total time: 3 s, completed Mar 28, 2018 6:09:12 PM

And here is the fix: #113

@pdolega
Copy link
Contributor

pdolega commented Mar 28, 2018

@gslowikowski / @GRBurst this would hopefully sort out this issue

@gslowikowski one thing to keep in mind that this solution used Java 7 feature which may be problematic due to this comment in build.sbt: https://github.com/scoverage/sbt-coveralls/blob/master/build.sbt#L26

(though I'd argue that if we are to handle Java 6 we should have a travis cross build for that - which I am happy to add - but I'd rather first be sure that we really need it)

@pdolega
Copy link
Contributor

pdolega commented Mar 29, 2018

Hey @fommil git blame shows you as the author of this line: https://github.com/scoverage/sbt-coveralls/blob/master/build.sbt#L26

Is there any reason we should keep compatibility with Java version that is not even covered with official support anymore? I guess one of the typical reasons in the past - Android - is at the point where Java 7+ versions are already supported out of the box.

@fommil
Copy link
Contributor

fommil commented Mar 29, 2018

I don't use this anymore

@gslowikowski
Copy link
Member

gslowikowski commented Mar 31, 2018

Guys, can you confirm that the problem exists when src/main/scala directory does not exist and src/main-scala-2.12 exists?

I see, that the conversion to paths (toURI.getPath) adds training slash to a directory. If the path does not exist, it's not added (see File.toURI() method).

If both: src/main/scala and src/main/scala-2.12 exist, the paths are: ...../src/main/scala/ and ...../src/main/scala-2.12/ and everything works.

But if only src/main/scala-2.12 exist, the paths are: ...../src/main/scala (without trailing slash) and ...../src/main/scala-2.12/ and plugin fails.

The solution would be to filter non-existent source roots.

Can you check your failing builds?

@pdolega
Copy link
Contributor

pdolega commented Mar 31, 2018

Hey @gslowikowski you are right - removing this directory obviously helps. But I don't think that filtering out non-existent paths is the right solution.

IMHO the problem is in incorrectly recognizing nested directories and I have submitted fix for that here: #113

It sorts out this problem altogether.

@gslowikowski
Copy link
Member

@pdolega I remember about your PR, but it's always better to fix the real source of the problem.

The algorithm of recognizing nested directories works properly for existing directories.

After changing allSources declaration in CoverallsPlugin.scala file to:

    val allSources = (sources ++ multiSources).filter(_.isDirectory()).distinct

problem is solved.
If you agree with me, that this solution works, you can use it in your PR, I will merge it and we will still be compatible with Java6 :)

Additionally, I think we need scripted test here. It should be added now or later. When I was executing your unit tests, I had to check on a real project, what paths are passed by SBT - relative, absolute, or maybe canonical? BTW, I didn't verify plugin behavior on projects with non-canonical paths (e.g. something like src/main/scala/../scala-2).

@pdolega
Copy link
Contributor

pdolega commented Mar 31, 2018

Ah! I misread you comment. Apologies. I read this part incorrectly:

Guys, can you confirm that the problem exists when src/main/scala directory does not exist and src/main-scala-2.12 exists?

Let me check it out - it might be that you are absolutely right with diagnosis of the problem (and you are definitely right as for the scripted test)

@pdolega
Copy link
Contributor

pdolega commented Mar 31, 2018

@gslowikowski you were right indeed. Change in CoverallsPlugin.scala sorts out the problem. I have completely missed the fact that it also fails on non-existent paths. So I guess this is one of the things that would ususally happen with nested projects like in my case:

[error] java.lang.IllegalArgumentException: requirement failed: Source directories must not be nested: /home/pdolega/projects/ReactSphere-2018/ReactSphere-reactive-beyond-hype/codebase/src/main/scala-2.12 is contained in /home/pdolega/projects/ReactSphere-2018/ReactSphere-reactive-beyond-hype/codebase/src/main/scala
[error]         at scala.Predef$.require(Predef.scala:277)
[error]         at org.scoverage.coveralls.CoberturaMultiSourceReader.<init>(CoberturaMultiSourceReader.scala:17)
[error]         at org.scoverage.coveralls.CoverallsPlugin$.$anonfun$coverallsTask$1(CoverallsPlugin.scala:108)
[error]         at org.scoverage.coveralls.CoverallsPlugin$.$anonfun$coverallsTask$1$adapted(CoverallsPlugin.scala:57)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)

Above /home/pdolega/projects/ReactSphere-2018/ReactSphere-reactive-beyond-hype/codebase/ is src root but all projects are actually one level below. So codebase dir neither have src/main/scala nor src/main/scala-2.12

Good point!

PS. I have update PR with your suggested change, now I need to add scripted test for this scenario.

pdolega added a commit to pdolega/sbt-coveralls that referenced this issue Mar 31, 2018
gslowikowski added a commit that referenced this issue Apr 8, 2018
@gslowikowski
Copy link
Member

Fixed by #113

@gslowikowski
Copy link
Member

Version 1.2.4-SNAPSHOT deployed to Sonatype snapshots repository.

Add

resolvers += Resolver.sonatypeRepo("snapshots")

to project's settings to test it.

@gslowikowski
Copy link
Member

Version 1.2.4 published

@viktor-podzigun
Copy link
Contributor

Latest version works perfectly for our Cross-Project builds.

Thanks a lot to everyone involved for fixing it!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants