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

org_scala_tools_maven_cs.ScalaCSInitMojo 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_cs;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
import org.yaml.snakeyaml.Yaml;

/**
 * Register the current project into running ScalaCS. If there is no running ScalaCS then install (if needed) and start it.
 *
 * @goal cs-init
 * @requiresDependencyResolution test
 */
public class ScalaCSInitMojo extends ScalaCSMojoSupport {

    /**
     * The directory in which to place compilation output
     *
     * @parameter expression="${project.build.outputDirectory}"
     */
    protected File outputDir;

    /**
     * A list of inclusion filters for the compiler.
     * ex :
     * 
     *    <includes>
     *      <include>SomeFile.scala</include>
     *    </includes>
     * 
* * @parameter */ private Set includes = new HashSet(); /** * A list of exclusion filters for the compiler. * ex : *
     *    <excludes>
     *      <exclude>SomeBadFile.scala</exclude>
     *    </excludes>
     * 
* * @parameter */ private Set excludes = new HashSet(); /** * The directory which contains scala/java source files * * @parameter expression="${project.build.sourceDirectory}/../scala" */ protected File sourceDir; /** * The directory in which to place test compilation output * * @parameter expression="${project.build.testOutputDirectory} */ protected File testOutputDir; /** * The directory in which to find test scala source code * * @parameter expression="${project.build.testSourceDirectory}/../scala" */ protected File testSourceDir; /** * The directory in which to find test scala source code * * @parameter expression="${maven.scalacs.dumpYaml}" default-value="true" */ protected boolean dumpYaml; /** * Should send a compilation request after initialization. * * @parameter expression="${maven.scalacs.compileAfterInit}" default-value="false" */ protected boolean compileAfterInit; @Override protected CharSequence doRequest() throws Exception { String yaml = toYaml(project).toString(); if (dumpYaml) { new File(project.getBuild().getDirectory()).mkdirs(); FileUtils.fileWrite(project.getBuild().getDirectory() + "/project.yaml", "UTF-8", yaml); } StringBuilder back = new StringBuilder(); back.append(scs.sendRequestCreateOrUpdate(yaml)); if (compileAfterInit) { back.append(scs.sendRequestCompile(project.getArtifactId()+"-"+project.getVersion(), true, true)); } return back; } private CharSequence toYaml(MavenProject project) throws Exception { HashMap dataCompile = new HashMap(); /* name : sample sourceDirs : - "/home/dwayne/work/oss/scala-tools/scala-tools-server/src/main/scala" includes : - "*.scala" excludes : targetDir : "/home/dwayne/work/oss/scala-tools/scala-tools-server/target/classes" classpath : - "/home/dwayne/.m2/repository/org/scala-lang/scala-library/2.7.5/scala-library-2.7.5.jar" - "/home/dwayne/.m2/repository/org/scala-lang/scala-compiler/2.7.5/scala-compiler-2.7.5.jar" - "/home/dwayne/.m2/repository/org/jboss/netty/netty/3.1.0.GA/netty-3.1.0.GA.jar" - "/home/dwayne/.m2/repository/SnakeYAML/SnakeYAML/1.3/SnakeYAML-1.3.jar" args : - "-deprecation" */ dataCompile.put("name", project.getArtifactId()+"-"+project.getVersion()+"/main"); dataCompile.put("sourceDirs", getSourceDirectories()); if (includes != null) { dataCompile.put("includes", new ArrayList(includes)); } if (excludes != null) { dataCompile.put("excludes", new ArrayList(excludes)); } dataCompile.put("targetDir", outputDir.getCanonicalPath()); dataCompile.put("classpath", project.getCompileClasspathElements()); if (args != null) { dataCompile.put("args", args); } dataCompile.put("exported", new File(localRepo.getBasedir() , localRepo.pathOf(project.getArtifact())).getCanonicalPath()); HashMap dataTest = new HashMap(); dataTest.put("name", project.getArtifactId()+"-"+project.getVersion() +"/test"); dataTest.put("sourceDirs", project.getTestCompileSourceRoots()); if (includes != null) { dataTest.put("includes", new ArrayList(includes)); } if (excludes != null) { dataTest.put("excludes", new ArrayList(excludes)); } dataTest.put("targetDir", testOutputDir.getCanonicalPath()); dataTest.put("classpath", project.getTestClasspathElements()); if (args != null) { dataTest.put("args", args); } Yaml yaml = new Yaml(); List> prjs = new LinkedList>(); prjs.add(dataCompile); prjs.add(dataTest); return yaml.dumpAll(prjs.iterator()); } @SuppressWarnings("unchecked") protected List getSourceDirectories() throws Exception { List sources = project.getCompileSourceRoots(); //Quick fix in case the user has not added the "add-source" goal. String scalaSourceDir = sourceDir.getCanonicalPath(); if(!sources.contains(scalaSourceDir)) { sources.add(scalaSourceDir); } return sources; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy