Commit Graph

38 Commits

Author SHA1 Message Date
Eugene Yokota d2def1ac74 Use Array to talk to proper build 2020-03-18 16:28:51 -04:00
Ethan Atkins ae4d3aecb8 Explicitly set scripted and server test classpath
This commit makes it so that the scalaVersion, sbtVersion and classpath
are always passed in as parameters to any method that creates an sbt
server -- either for scripted or for the sbt server tests. By making
that change, I was able to change the implementation of scripted in the
sbt project to use publishLocalBin instead of publishLocal. This makes
the scripted tests start much faster (doc alone can easily take 30
second) with messing with the build to exclude slow tasks from
publishLocal.

As part of this change, I removed the test dependency on scriptedSbtRedux for
sbtProj and instead had scriptedSbtRedux depend on sbtProj. This allowed
me to remove some messy LocalProject logic in the resourceGenerators for
scriptedSbtReduxProj. I also had to remove a number of imports in the
scriptedSbtReduxProj because the definitions available in the sbt
package object became available.

I also removed the dependency on sbt-buildinfo and instead pass the
values from the build into test classes using scalatest properties. I
ran into a number of minor issues with the build info plugin, namely
that I couldn't get fullClasspathAsJars to reliably run as a BuildInfo
key. It also is somewhat more clear to me to just rely on the built in
scalatest functionality. The big drawback is that the scalatest
properties can only be strings, but that restriction isn't really a
problem here (strangely the TestData structure has a field configMap
which is effectively Map[String, Any] but Any is actually always String
given how the TestData is created as part of framework initialization.

Since scripted no longer publishes, scriptedUnpublished is now
effectively an alias for scripted.

To get publishLocalBin working, I had to copy private code from
IvyXml.scala into PublishBinPlugin. Once we publish a new version of
sbt, we can remove the copied code and invoke IvyXml.makeIvyXmlBefore
directly.
2020-01-19 09:04:26 -08:00
Ethan Atkins 2f99797bac Fix RunFromSourceMain sbt.Package$ bug
The main reason for having both the RunFromSourceMain and LauncherBased
scripted tests was that RunFromSourceMain would fail for any test that
ended up accessing the sbt.Package$ object. This commit fixes this bug
by reworking the classloader generated by RunFromSourceMain to invoke
sbt, switching from the classpath to jar classpath (by setting exportJars =
true) and entering sbt by calling `new xMain().run` rather than
`xMain.run`.

The reason for switching to the jar classpath is that the jvm seems to
have issues when there are two classes provided in different directories
that have the same case insensitive name, e.g. `sbt.package$` and
`sbt.Package$`. If those classes are instead provided in different
jars, the jvm seems to be able to handle it.

Exporting the jars is not enough though, I had to rework the
ClassLoader created in the launch method to have a layout that was
recognized by xMainConfiguration. I reimplemented the AppConfiguration
in java so that it could bootstrap itself in a single jar classloader
(the only needed jar is the Scripted.

If we export the jars in the build, then the NoClassDefErrors for
`sbt.Package$` go away during scripted tests using RunSourceFromMain.
This might make running tests in subprojects slightly slower but I think
its a worthy tradeoff.
2020-01-19 09:04:26 -08:00
Ethan Atkins ee56140f5c Use logger in scripted instead of println 2019-12-10 10:52:18 -08:00
Dale Wijnand 02e26465f7 Cleanup project/Transform.scala 2019-11-28 21:25:49 +00:00
Ethan Atkins ae84e162ad Limit scripted page numbers
The completions were generating page numbers that didn't make sense if
there were a small number of scripted tests. For example, suppose that
there were only two tests defined, it would generate *1of3 *2of3 and
*3of3 completions even though there weren't even three tests.
2019-10-06 14:07:30 -07:00
Ethan Atkins 9dff18d736 Fix scripted parser crash
In a local progress, I was able to induce a crash in tab completions
because the group key did not exist in pairMap.
2019-10-06 14:07:30 -07:00
Ethan Atkins 49bcef029d Display only valid pages in scripted completions
The tab completions for scripted have long been broken. They display a
number of non-sensical pages like '*0of9' or '*1of0'. Some of the
multiparser changes seem to have caused these invalid
2019-08-31 17:32:34 -07:00
Ethan Atkins 9a1d874c37 Fix divide by zero 2019-08-08 16:06:13 -07:00
Ethan Atkins 7b8ed4d13f Allow sbt scripted tests to run in parallel
I'm not sure if this is a huge benefit or not, but it's nice to have the
option to run the scripted tests in parallel. The default behavior
should be the same as before.
2019-01-31 17:43:14 -08:00
Ethan Atkins b2c9d3e2cf Use custom classloader for scripted tests
We had previously used reflection to load the bridge class, but
continued using sbt's default classloader. This was problematic because
the metabuild could have a different classpath from that required by the
scripted tests.

Bonus: scalafmt

Fixes: #4514
2019-01-31 17:43:14 -08:00
Eugene Yokota 305a8de319 1.2.1-SNAPSHOT 2018-07-30 20:28:42 -04:00
Eugene Yokota d7dc4b3e29 create scripted-sbt-redux
Fixes #4241
Fixes #4242

This introduces a new subproject named scripted-sbt-redux. The purpose of this new subproject is to workaround the 'sbt.test` package vs `Keys.test` key confusion (#4242) while maintaining the forward compatibility of 0.13.17's sbt cross testing ^^ (#4241).

The new subproject uses `sbt.scriptedtest` package name, and that's the one that will be used by the mothership.

Meanwhile "scripted-sbt" subproject will also be published for compatibility purpose.
2018-07-10 03:13:47 -04:00
Dale Wijnand 8187a51d31
Cleanup local Scripted plugin 2018-03-06 11:54:11 +00:00
Dale Wijnand 41249f707a
Define local Scripted plugin keys with macros 2018-03-06 11:54:11 +00:00
Dale Wijnand b9e3d6aa2d
Define local Scripted plugin keys in Global scope 2018-03-06 11:54:11 +00:00
Dale Wijnand e3f33ddf7d
Merge pull request #3897 from dwijnand/misc
Misc tweaks and cleanups
2018-01-30 13:02:55 +00:00
Dale Wijnand bee69ebb92
Get rid of old MavenResolverPluginTest 2018-01-30 07:29:17 +00:00
Eugene Yokota c20029ce16 Work around package name confusion
This works around the name conflict between sbt.test package and sbt.Keys.test.

1. sbt.test package is renamed to sbt.scriptedtest. This allows 1.0 plugins and builds to use `test` to mean `Keys.test`.
2. To keep binary compatibility for sbt 0.13 scripted, I am adding `sbt.test.ScriptedRunner` and `sbt.test.ScriptedTests` in `scripted-plugin` artifact.
3. Another affected user is Giter8 plugin that uses ScriptedPlugin. Since the intereactions are limited to `sbt.ScriptedPlugin.*`, we should be fine here. - https://github.com/foundweekends/giter8/blob/v0.11.0-M2/plugin/src/main/scala-sbt-1.0/giter8/SBTCompat.scala
2018-01-22 14:03:02 -05:00
Eugene Yokota 13e1862c2f set jna.nosys to true programmatically
Previously I was seeing the error upon the first scripted test. I thought it was because Main was somehow not early enough. It might just be because scripted technically runs as part of the build.

Ref sbt/io#110
2017-12-21 00:08:56 -05:00
Antonio Cunei 43a976d42c Port of sbt/zinc#441 to sbt/sbt 1.0.x 2017-11-16 15:15:21 +01:00
Dale Wijnand 0b33c195ef
Upgrade the build to sbt 1.0.0-M5
Some plugins remain commented out, for now.

sbt-doge is no longer needed because a variant of it has been folded
into sbt 1.

For some reason scripted requires src/doc jars of sbt, so switch back to
using `publishAll` rather than `publishLocalBinAll`. :(

Also, the sys.prop change in scripted is to force log4j2 to not use a
thread context classloader, and avoid the following:

    ERROR StatusLogger Unable to create custom ContextSelector. Falling back to default.
     java.lang.ClassCastException: Cannot cast org.apache.logging.log4j.core.async.AsyncLoggerContextSelector to org.apache.logging.log4j.core.selector.ContextSelector
    	at java.lang.Class.cast(Class.java:3369)
    	at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:201)
    	at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOfProperty(LoaderUtil.java:226)
    	at org.apache.logging.log4j.core.impl.Log4jContextFactory.createContextSelector(Log4jContextFactory.java:97)
    	at org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:58)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    	at java.lang.Class.newInstance(Class.java:442)
    	at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:94)
    	at org.apache.logging.log4j.spi.ThreadContextMapFactory.createThreadContextMap(ThreadContextMapFactory.java:73)
    	at org.apache.logging.log4j.ThreadContext.init(ThreadContext.java:223)
    	at org.apache.logging.log4j.ThreadContext.<clinit>(ThreadContext.java:202)
    	at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createDefaultInjector(ContextDataInjectorFactory.java:83)
    	at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createInjector(ContextDataInjectorFactory.java:67)
    	at org.apache.logging.log4j.core.lookup.ContextMapLookup.<init>(ContextMapLookup.java:34)
    	at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:117)
    	at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:125)
    	at org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:46)
    	at org.apache.logging.log4j.core.layout.PatternLayout$Builder.build(PatternLayout.java:650)
    	at org.apache.logging.log4j.core.layout.PatternLayout.createDefaultLayout(PatternLayout.java:487)
    	at sbt.internal.util.ConsoleAppender.<init>(ConsoleAppender.scala:245)
    	at sbt.internal.util.ConsoleAppender$.apply(ConsoleAppender.scala:196)
    	at sbt.internal.util.ConsoleLogger.<init>(ConsoleAppender.scala:42)
    	at sbt.internal.util.ConsoleLogger$.apply(ConsoleAppender.scala:34)
    	at sbt.test.ScriptedRunner.run(ScriptedTests.scala:221)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at Scripted$.doScripted(Scripted.scala:125)
    	at $0483e89d182e9d240274$.$anonfun$scriptedTask$5(build.sbt:301)
2017-05-11 09:44:42 +01:00
jvican 70cf417525
Fix #3161: Don't fail if group is not present
This covers the case described in #1361 plus an esoteric case too.
Parsers are initialized when sbt starts and text completions use the
knowledge at that time. If we happen to move a new file that should
influence the behaviour of the tab completion, that file will not be
picked up. Before, since we were throwing an error, the previous case
that would no produce any tab completion would also fail, though the
files are legitimately in the correct place.
2017-05-10 21:40:02 +02:00
jvican f497e15cd8
Run scripted tests in parallel
Add binary-compatible methods to run scripted tests in parallel using
parallel collections. Parallel collections are not tuned and a default
of 4 cores is used for the `ForkJoinPool`. This can be a matter of
experimentation in the future but for now I prefer to stay with it.

The non-parallel methods are not affected by this change.

The changes to the scripted plugin have not been used, only the sbt
scripted plugin is using `runInParallel`. In the future, this change can
also happen so that plugin authors can benefit from parallel sbt
testing. This is not a priority for me now :)
2017-05-10 21:32:36 +02:00
Eugene Yokota da046791e0 Apply Scalafmt formatting 2017-04-21 04:48:31 -04:00
Guillaume Martres 334517aba8 Fix #3013: ScriptedPlugin: Add support for paginated tests
This was already supported in the internal Scripted used by sbt but not
in the ScriptedPlugin. This is fixed by just copy-pasting the modified
parser. We will have to wait for sbt itself to be built using an sbt
with the upgraded ScriptedPlugin to be able to avoid the code duplication.
2017-04-04 17:05:17 -04:00
xuwei-k 5b00e7326b s/newInstance/getDeclaredConstructor().newInstance()
java.lang.Class#newInstance deprecated since Java 9

http://download.java.net/java/jdk9/docs/api/java/lang/Class.html#newInstance--

```
Deprecated. This method propagates any exception thrown by the nullary constructor, including a checked exception. Use of this method effectively bypasses the compile-time exception checking that would otherwise be performed by the compiler. The Constructor.newInstance method avoids this problem by wrapping any exception thrown by the constructor in a (checked) InvocationTargetException.
The call

 clazz.newInstance()

can be replaced by

 clazz.getDeclaredConstructor().newInstance()

The latter sequence of calls is inferred to be able to throw the additional exception types InvocationTargetException and NoSuchMethodException. Both of these exception types are subclasses of ReflectiveOperationException.
Creates a new instance of the class represented by this Class object. The class is instantiated as if by a new expression with an empty argument list. The class is initialized if it has not already been initialized.
```
2017-03-15 11:53:49 +09:00
Dale Wijnand 472d28964a Configure scripted to do less
Particularly doesn't compile, package and publish source and doc jars.
2016-09-01 01:14:14 +01:00
Eugene Yokota ab43ec51d8 Adds a scripted test that tests repo override 2016-05-01 03:31:18 -04:00
Eugene Yokota 63ff359aca Implements scriptedBufferLog on sbt build 2016-03-30 23:48:20 -04:00
Eugene Yokota ff7ac294e7 Adds more memory to internal scripted task 2016-02-26 17:58:35 -05:00
Martin Duhem d84573c9d3 Include pending scripted tests in * and *aofb 2015-08-19 09:11:02 +02:00
Pierre DAL-PRA 54d54b9f4f Replace procedure syntax by explicit Unit annotation 2015-08-04 10:07:38 +02:00
Pierre DAL-PRA 3ffa333c14 Fix most build warnings 2015-07-10 11:53:48 +02:00
Eugene Yokota 618ac5236a Bumping up Scala version to 2.10.5/2.11.6. Fixes #1980
To pass File => Unit callback across the classloader boundary
I am encoding it as a java.util.List[File] by overriding
 method.
This was needed since Java didn't allow me to cast
from one classloader to the other.
2015-06-19 16:51:39 -04:00
Josh Suereth 004a557c37 Remove unused proguard configuration. 2015-03-24 18:37:57 -04:00
Eugene Yokota 75e7b47718 Run scripted with sbt-maven-resolver 2015-01-12 22:01:16 -05:00
Eugene Yokota 91de6c6b79 Multi-project build.sbt 2014-12-17 23:38:10 -05:00