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

org_scala_tools_maven.AddSourceMojo Maven / Gradle / Ivy

Go to download

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

There is a newer version: 2.15.2
Show newest version
package org_scala_tools_maven;

import java.io.File;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;

/**
 * Add more source directories to the POM.
 *
 * @executionStrategy always
 * @goal add-source
 * @phase generate-sources
 * @requiresDirectInvocation false
 */
public class AddSourceMojo extends AbstractMojo {

	/**
	 * @parameter expression="${project}"
	 * @required
	 * @readonly
	 */
	private MavenProject project;

    /**
     * The directory in which scala source is found
     * 
     * @parameter expression="${project.build.sourceDirectory}/../scala"
     */
    protected File sourceDir;

    /**
     * The directory in which testing scala source is found
     * 
     * @parameter expression="${project.build.testSourceDirectory}/../scala"
     */
    protected File testSourceDir;

    public void execute() throws MojoExecutionException {
    	try {
	    	if (sourceDir != null) {
	        	String path = sourceDir.getCanonicalPath();
	        	if (!project.getCompileSourceRoots().contains(path)) {
	        		getLog().info("Add Source directory: " + path);
	        		project.addCompileSourceRoot(path);
	        	}
			}
	    	if (testSourceDir != null) {
	        	String path = testSourceDir.getCanonicalPath();
	        	if (!project.getTestCompileSourceRoots().contains(path)) {
	        		getLog().info("Add Test Source directory: " + path);
	        		project.addTestCompileSourceRoot(path);
	        	}
			}
    	} catch(Exception exc) {
    		getLog().warn(exc);
    	}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy