4 Replies Latest reply on Aug 14, 2015 7:31 AM by Matous Jobanek

    Arquillian Shrinkwrap provide custom settings.xml file

    Craig Jones Newbie

      Hi,

       

      I have set up a arquillian project and it all works fine locally but when running the maven build on our continuous integration box it fails. I managed to get to the bottom of the problem and it is because the maven user settings.xml file on the CI box actually has some server definitions (for another project) whereas locally to my machine it is the default file (with no servers defined). The tests throw a RuntimeException because the MavenResolver goes looking for settings-security.xml file which doesn't exist on the CI box.

       

      I would prefer not to go adding the settings-security.xml and instead would like to provide the resolver with a 'empty' settings.xml file, or even better, tell it not to use one. Is this possible?

       

      I tried the answer from this thread https://developer.jboss.org/thread/174873 which pretty much says to add the following option to the failsafe plugin:

       

      <plugin>

                      <groupId>org.apache.maven.plugins</groupId>

                      <artifactId>maven-surefire-plugin</artifactId>

                       <version>2.9</version><!-- or upper -->

                              <configuration>

                                  <systemPropertyVariables>

                                         <org.apache.maven.user-settings>nonExistentSetting.xml</org.apache.maven.user-settings>

                                   </systemPropertyVariables>

                              </configuration>

      </plugin>

       

      If i do this and provide an xml file that doesnt exist all work fine from the command line running 'mvn clean install' but when i debug within my IDE it still fails.

       

      Is there a way i can either:

      • Tell the maven resolver not to use a settings.xml / use a 'default' file
      • Create an empty settings.xml in my project and tell the maven resolver to use that

       

      I did try the following line in my code to build my archive but it didnt seem to have an effect:

       

      .addAsLibraries(Maven.configureResolver().fromFile("test-settings.xml").loadPomFromFile("pom.xml").importRuntimeDependencies().resolve().withTransitivity().asFile())

       

       

      Thanks for any help,

      Craig

        • 1. Re: Arquillian Shrinkwrap provide custom settings.xml file
          Karel Piwko Master

          Hello Craig,

           

          unfortunately, IDEs are not picking up system properties defined in surefire plugin by default. If you want to use it that way, you need additionally define this property in test execution configuration.

           

          As for the later case, this should work.  Can you provide stacktrace?

           

          Thanks,

           

          Karel

          • 2. Re: Arquillian Shrinkwrap provide custom settings.xml file
            Craig Jones Newbie

            Hi Karel,

             

            Thanks for helping with this. It may be my understanding of how to set up the Archive that is the problem, so i have given the code below.

             

            return ShrinkWrap.create(WebArchive.class, "repoTest.war")
              .addPackage(MessageRepository.class.getPackage())
              .addAsLibraries(Maven.configureResolver().fromFile("test-settings.xml").loadPomFromFile("pom.xml").importRuntimeDependencies().resolve().withTransitivity().asFile())
              .addAsResource(new File("src/main/resources/META-INF/persistence.xml"), "META-INF/persistence.xml")
              .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
            
            
            

             

            The stack trace is as follows:

             

            org.jboss.shrinkwrap.resolver.api.Invokable$InvocationException: Unable to invoke onlyOne([Ljava.lang.Class;@5066d65f) on object org.jboss.shrinkwrap.resolver.spi.loader.ServiceRegistry with parameters [Ljava.lang.Object;@4233e892
              at org.jboss.shrinkwrap.resolver.api.Invokable.invokeMethod(Invokable.java:108)
              at org.jboss.shrinkwrap.resolver.api.ResolverSystemFactory.createFromUserView(ResolverSystemFactory.java:91)
              at org.jboss.shrinkwrap.resolver.api.ResolverSystemFactory.createFromUserView(ResolverSystemFactory.java:53)
              at org.jboss.shrinkwrap.resolver.api.Resolvers.configure(Resolvers.java:40)
              at org.jboss.shrinkwrap.resolver.api.maven.Maven.configureResolver(Maven.java:46)
              at com.markit.sheen.integration.RepositoryIT.createDeployment(RepositoryIT.java:53)
              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:497)
              at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:177)
              at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generateDeployment(AnnotationDeploymentScenarioGenerator.java:103)
              at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generate(AnnotationDeploymentScenarioGenerator.java:64)
              at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:79)
              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:497)
              at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
              at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
              at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
              at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)
              at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)
              at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
              at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:100)
              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:497)
              at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
              at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
              at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
              at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92)
              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:497)
              at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
              at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
              at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73)
              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:497)
              at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
              at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
              at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)
              at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)
              at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:87)
              at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:201)
              at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:422)
              at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:54)
              at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:218)
              at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
              at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:166)
              at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
              at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
            Caused by: java.lang.reflect.InvocationTargetException
              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:497)
              at org.jboss.shrinkwrap.resolver.api.Invokable.invokeMethod(Invokable.java:100)
              ... 60 more
            Caused by: java.lang.RuntimeException: Could not create new service instance
              at org.jboss.shrinkwrap.resolver.spi.loader.SpiServiceLoader.createInstance(SpiServiceLoader.java:248)
              at org.jboss.shrinkwrap.resolver.spi.loader.SpiServiceLoader.createInstances(SpiServiceLoader.java:208)
              at org.jboss.shrinkwrap.resolver.spi.loader.SpiServiceLoader.all(SpiServiceLoader.java:79)
              at org.jboss.shrinkwrap.resolver.spi.loader.SpiServiceLoader.onlyOne(SpiServiceLoader.java:85)
              at org.jboss.shrinkwrap.resolver.spi.loader.ServiceRegistry.onlyOne(ServiceRegistry.java:117)
              ... 65 more
            Caused by: java.lang.reflect.InvocationTargetException
              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:422)
              at org.jboss.shrinkwrap.resolver.spi.loader.SpiServiceLoader.createInstance(SpiServiceLoader.java:244)
              ... 69 more
            Caused by: org.jboss.shrinkwrap.resolver.api.InvalidConfigurationFileException: Found 2 problems while trying to decrypt settings configuration.1/ [ERROR] Failed to decrypt password for server central: Unable to decrypt encrypted string @ server: central
            2/ [ERROR] Failed to decrypt password for server radgate: Unable to decrypt encrypted string @ server: radgate
            
            
              at org.jboss.shrinkwrap.resolver.impl.maven.bootstrap.MavenSettingsBuilder.decryptPasswords(MavenSettingsBuilder.java:234)
              at org.jboss.shrinkwrap.resolver.impl.maven.bootstrap.MavenSettingsBuilder.buildSettings(MavenSettingsBuilder.java:186)
              at org.jboss.shrinkwrap.resolver.impl.maven.bootstrap.MavenSettingsBuilder.buildDefaultSettings(MavenSettingsBuilder.java:113)
              at org.jboss.shrinkwrap.resolver.impl.maven.MavenWorkingSessionImpl.<init>(MavenWorkingSessionImpl.java:136)
              at org.jboss.shrinkwrap.resolver.impl.maven.ConfigurableMavenResolverSystemImpl.<init>(ConfigurableMavenResolverSystemImpl.java:47)
              ... 74 more
            
            
            

             

            The test-settings file i added is under src/test/resources/test-settings.xml, i have tried this full path in the fromFile() method also. That file looks like:

             

            <?xml version="1.0" encoding="UTF-8"?>
            <settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
                xmlns:xsi="http://www.w4.org/2001/XMLSchema-instance">
            </settings>
            

             

             

            Thanks,

            Craig

            • 3. Re: Arquillian Shrinkwrap provide custom settings.xml file
              Karel Piwko Master

              Craig,

               

              thanks for your stracktrace. The problem lies in fact that MavenWorkingSessionImpl is created first with default values and later on regenerated with settings.xml when you configure resolver.

               

              Hence default settings.xml is always read. If you add system property, it actually changes location of default settings, hence the problem is not present.

               

              Can you please file an issue within https://issues.jboss.org/browse/SHRINKRES project and add affected version? Prior it is fixed, you can use system property workaround. Implementation would either need to create session later in the process or find a different way how to handle this.

               

              Many thanks!

               

              Karel