6 Replies Latest reply on Apr 5, 2007 10:15 AM by Kevin Conner

    Target directory is not correct for tests in new Maven build

    Adrian Brock Master

      The AccessController test is not working properly in eclipse.

      This is indicitive a greater failure in that tests are being given all permissions
      when they should run with restricted rights.

      This stems from a "hack" in our test framework where we look for the phrase
      "tests" in the url to see whether to give the class restricted access:

      org.jboss.test.security.TestsPolicyPlugin

       // Is this a test location?
       File file = new File(url.toString());
       String name = file.getName();
       if (name.indexOf("tests") != -1 || name.indexOf("-test.jar") != -1)
       {
      


      But with the new maven build, the test classes don't live in somewhere with
      tests in the name, they are in the same codebase as the base classes.

      I assume this is an issue with the eclipse:eclipse plugin?

        • 1. Re: Target directory is not correct for tests in new Maven b
          Adrian Brock Master

          If I understand the code to the eclipse plugin correctly, it is not possible
          to have a seperate output directory for tests unless you also build eclipse
          classes into the same place as the normal maven build puts things:

          org.apache.maven.plugin.eclipse.EclipsePlugin.buildDirectoryList(...)

           // If using the standard output location, don't mix the test output into it.
           String testOutput = null;
           boolean useStandardOutputDir = buildOutputDirectory
           .equals( new File( project.getBuild().getOutputDirectory() ) );
           if ( useStandardOutputDir )
           {
           testOutput = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, new File( project.getBuild()
           .getTestOutputDirectory() ), false );
           }
          


          There's only one parameter that controls output so it is all or nothing.

          We have this configured in jboss-parent
           <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-eclipse-plugin</artifactId>
           <configuration>
           <downloadSources>true</downloadSources>
           <buildOutputDirectory>target/eclipse-classes</buildOutputDirectory>
           </configuration>
           </plugin>
          


          What we really want is the non-existant:
           <testOutputDirectory>target/eclipse-classes-tests</testOutputDirectory>
          

          as well.

          • 2. Re: Target directory is not correct for tests in new Maven b
            Adrian Brock Master

            This is the change that makes the AccessControl test work in eclipse.

            - <classpathentry kind="src" path="src/tests"/>
            + <classpathentry kind="src" output="eclipse-classes-tests" path="src/tests"/>
            




            • 3. Re: Target directory is not correct for tests in new Maven b
              Paul Gier Master

              I removed the eclipse plugin configuration from the parent, and uploaded a new parent snapshot to snapshots.jboss.org.

              Without the buildOutputDirectory parameter, the test classes are compiled to the default maven location test-classes.

               <classpathentry kind="src" path="src/tests" output="target/test-classes"/>
              


              Does this work for you?

              • 4. Re: Target directory is not correct for tests in new Maven b
                Adrian Brock Master

                That will work but introduces two other problems.

                1) Whenever you do a maven clean, it will blow away the classes which
                completely confuses eclipse's incremental compiler.

                2) When I do a release, I don't want it to have classes compiled with eclipse's compiler.
                I want to use the JDK compiler.

                Those are the reasons why we use target/eclipse-classes[-tests] instead of the default
                location.

                • 5. Re: Target directory is not correct for tests in new Maven b
                  Kevin Conner Master

                   

                  "adrian@jboss.org" wrote:
                  Those are the reasons why we use target/eclipse-classes[-tests] instead of the default location.

                  This should be solvable using profiles. I'll give it a go once I have finished my current TS work.

                  • 6. Re: Target directory is not correct for tests in new Maven b
                    Kevin Conner Master

                     

                    "Kevin.Conner@jboss.com" wrote:
                    This should be solvable using profiles. I'll give it a go once I have finished my current TS work.

                    I have modified the root pom.xml and build/pom.xml to include an eclipse profile. This should create the eclipse configuration with separate build directories to the normal maven build.

                    Once these poms are updated execute the following
                    mvn -Peclipse

                    This will run eclipse:eclipse with a slightly different configuration to the normal build.

                    The directories used should be target/eclipse-classes and target/eclipse-tests-classes.

                    I had originally set the test directory to be eclipse-classes-tests but the eclipse plugin believed that this was a nested directory and thus ignored it (for resources anyway).

                    I am still seeing the eclipse configuration from jboss-parent so I have also had to override that in the build/pom.xml.