1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.google.code.sbt;
19
20 import java.io.File;
21
22 import org.apache.maven.plugin.AbstractMojo;
23 import org.apache.maven.plugins.annotations.Component;
24 import org.apache.maven.plugins.annotations.LifecyclePhase;
25 import org.apache.maven.plugins.annotations.Mojo;
26 import org.apache.maven.project.MavenProject;
27
28
29
30
31
32
33
34
35
36
37 @Mojo( name = "addScalaSources", defaultPhase = LifecyclePhase.INITIALIZE )
38 public class SBTAddScalaSourcesMojo
39 extends AbstractMojo
40 {
41
42
43
44
45 @Component
46 protected MavenProject project;
47
48
49
50
51 public void execute()
52 {
53 if ( "pom".equals( project.getPackaging() ) )
54 {
55 return;
56 }
57
58 File baseDir = project.getBasedir();
59
60 File mainScalaPath = new File( baseDir, "src/main/scala" );
61 if ( mainScalaPath.isDirectory() )
62 {
63 String mainScalaPathStr = mainScalaPath.getAbsolutePath();
64 if ( !project.getCompileSourceRoots().contains( mainScalaPathStr ) )
65 {
66 project.addCompileSourceRoot( mainScalaPathStr );
67 getLog().debug( "Added source directory: " + mainScalaPathStr );
68 }
69 }
70
71 File testScalaPath = new File( baseDir, "src/test/scala" );
72 if ( testScalaPath.isDirectory() )
73 {
74 String testScalaPathStr = testScalaPath.getAbsolutePath();
75 if ( !project.getCompileSourceRoots().contains( testScalaPathStr ) )
76 {
77 project.addTestCompileSourceRoot( testScalaPathStr );
78 getLog().debug( "Added test source directory: " + testScalaPathStr );
79 }
80 }
81 }
82
83 }