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

scala_maven.ScalaSourceMojoSupport Maven / Gradle / Ivy

Go to download

The scala-maven-plugin (previously maven-scala-plugin) is used for compiling/testing/running/documenting scala code of any maven project.

There is a newer version: 4.9.2
Show newest version
package scala_maven;

import scala_maven_executions.MainHelper;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author david.bernard
 */
abstract public class ScalaSourceMojoSupport extends ScalaMojoSupport {

    /**
     * Enables/Disables sending java source to the scala compiler.
     *
     * @parameter default-value="true"
     */
    protected boolean sendJavaToScalac = true;

    /**
     * A list of inclusion filters for the compiler.
     * ex :
     * 
     *    <includes>
     *      <include>SomeFile.scala</include>
     *    </includes>
     * 
* * @parameter */ protected Set includes = new HashSet(); /** * A list of exclusion filters for the compiler. * ex : *
     *    <excludes>
     *      <exclude>SomeBadFile.scala</exclude>
     *    </excludes>
     * 
* * @parameter */ protected Set excludes = new HashSet(); /** * Retrieves the list of *all* root source directories. We need to pass all .java and .scala files into the scala compiler */ abstract protected List getSourceDirectories() throws Exception; private boolean _filterPrinted = false; /** * Finds all source files in a set of directories with a given extension. */ protected List findSourceWithFilters() throws Exception { return findSourceWithFilters(getSourceDirectories()); } protected void initFilters() throws Exception { if (includes.isEmpty()) { includes.add("**/*.scala"); if (sendJavaToScalac && isJavaSupportedByCompiler()) { includes.add("**/*.java"); } } if (!_filterPrinted && getLog().isDebugEnabled()) { StringBuilder builder = new StringBuilder("includes = ["); for (String include : includes) { builder.append(include).append(","); } builder.append("]"); getLog().debug(builder.toString()); builder = new StringBuilder("excludes = ["); for (String exclude : excludes) { builder.append(exclude).append(","); } builder.append("]"); getLog().debug(builder.toString()); _filterPrinted = true; } } /** * Finds all source files in a set of directories with a given extension. */ protected List findSourceWithFilters(List sourceRootDirs) throws Exception { List sourceFiles = new ArrayList(); initFilters(); // TODO - Since we're making files anyway, perhaps we should just test // for existence here... for (File dir : sourceRootDirs) { String[] tmpFiles = MainHelper.findFiles(dir, includes.toArray(new String[includes.size()]), excludes.toArray(new String[excludes.size()])); for (String tmpLocalFile : tmpFiles) { File tmpAbsFile = FileUtils.fileOf(new File(dir, tmpLocalFile), useCanonicalPath); sourceFiles.add(tmpAbsFile); } } // scalac is sensitive to scala file order, file system can't guarantee file order => unreproducible build error across platforms // sort files by path (OS dependent) to guarantee reproducible command line. Collections.sort(sourceFiles); return sourceFiles; } /** * This limits the source directories to only those that exist for real. */ protected List normalize(List compileSourceRootsList) throws Exception { List newCompileSourceRootsList = new ArrayList(); if (compileSourceRootsList != null) { // copy as I may be modifying it for (String srcDir : compileSourceRootsList) { File srcDirFile = FileUtils.fileOf(new File(srcDir), useCanonicalPath); if (!newCompileSourceRootsList.contains(srcDirFile) && srcDirFile.exists()) { newCompileSourceRootsList.add(srcDirFile); } } } return newCompileSourceRootsList; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy