All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org_scala_tools_maven.ScalaContinuousTestMojo Maven / Gradle / Ivy

Go to download

The maven-scala-plugin is used for compiling/testing/running/documenting scala code in maven.

The newest version!
/**
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org_scala_tools_maven;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import org.apache.maven.BuildFailureException;
import org.apache.maven.shared.invoker.CommandLineConfigurationException;
import org.apache.maven.shared.invoker.DefaultInvocationRequest;
import org.apache.maven.shared.invoker.InvocationRequest;
import org.apache.maven.shared.invoker.Invoker;
import org.apache.maven.shared.invoker.MavenCommandLineBuilder;
import org.apache.maven.shared.invoker.MavenInvocationException;
import org.apache.maven.shared.invoker.SystemOutHandler;

/**
 * Compile the main and test scala source directory then run unit test cases in continuous (infinite loop).
 * This is an util goal for commandline usage only (Do not use or call it in a pom) !!!
 *
 * @version $Revision: 1.1 $
 * @goal cctest
 * @requiresDependencyResolution test
 */

public class ScalaContinuousTestMojo extends ScalaContinuousCompileMojo {

    /**
     * @component
     */
    protected Invoker invoker;


    /**
     * The local repository for caching artifacts. It is strongly recommended to specify a path to an isolated
     * repository like ${project.build.directory}/it-repo. Otherwise, your ordinary local repository will
     * be used, potentially soiling it with broken artifacts.
     *
     * @parameter expression="${invoker.localRepositoryPath}" default-value="${settings.localRepository}"
     */
    protected File localRepositoryPath;

    /**
     * Specify this parameter to run individual tests by file name, overriding the includes/excludes
     * parameters.  Each pattern you specify here will be used to create an
     * include pattern formatted like **/${test}.java, so you can just type "-Dtest=MyTest"
     * to run a single test called "foo/MyTest.java".  This parameter will override the TestNG suiteXmlFiles
     * parameter.
     *
     * @parameter expression="${test}"
     */
    protected String test;

    /**
     * A space-separated list of the goals to execute as part of running the tests. You can use this
     * setting to run different testing tools other than just JUnit. For example, to run the
     * ScalaTest (with the maven-scalatest-plugin):
     *
     * 
     *   mvn -Dcctest.goals=scalatest:test scala:cctest
     * 
* * To run both ScalaTest and JUnit tests: * *
     *   mvn -Dcctest.goals="surefire:test scalatest:test" scala:cctest
     * 
* * If you need to specify the goal every time you run scala:cctest, you can * configure the setting in the pom.xml: * *
     *    <plugin>
     *       <groupId>org.scala-tools</groupId>
     *       <artifactId>maven-scala-plugin</artifactId>
     *       <version>2.15.1-SNAPSHOT</version>
     *       <configuration>
     *          <ccTestGoals>scalatest:test</ccTestGoals>
     *       </configuration>
     *       <!-- normal executions here -->
     *    </plugin>
     * 
* * @parameter expression="${cctest.goals}" default-value="surefire:test" */ protected String ccTestGoals; @Override protected void postCompileActions() throws Exception { if (test == null) { getLog().info("Now running all the unit tests. Use -Dtest=FooTest to run a single test by name"); } else { getLog().info("Now running tests matching: " + test); } final InvocationRequest request = new DefaultInvocationRequest(); request.setLocalRepositoryDirectory(localRepositoryPath); request.setInteractive(false); request.setErrorHandler(new SystemOutHandler(true)); request.setOutputHandler(new SystemOutHandler(true)); request.setBaseDirectory(project.getBasedir()); request.setPomFile(new File(project.getBasedir(), "pom.xml")); request.setGoals(getMavenGoals()); request.setOffline(false); if (test != null) { Properties properties = new Properties(); properties.put("test", test); request.setProperties(properties); } if (getLog().isDebugEnabled()) { try { getLog().debug("Executing: " + new MavenCommandLineBuilder().build(request)); } catch (CommandLineConfigurationException e) { getLog().debug("Failed to display command line: " + e.getMessage()); } } try { invoker.execute(request); } catch (final MavenInvocationException e) { getLog().debug("Error invoking Maven: " + e.getMessage(), e); throw new BuildFailureException("Maven invocation failed. " + e.getMessage(), e); } } protected List getMavenGoals() { getLog().debug("Running tests with goal(s): " + ccTestGoals); return Arrays.asList(ccTestGoals.split(" ")); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy