1 package com.soebes.maven.extensions.incremental;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.nio.file.Path;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Objects;
27
28 import org.apache.maven.project.MavenProject;
29 import org.apache.maven.scm.ScmFile;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36 public class ModuleCalculator
37 {
38 private final Logger logger = LoggerFactory.getLogger( getClass().getName() );
39
40 private List<MavenProject> projectList;
41
42 private List<ScmFile> changeList;
43
44
45
46
47
48 public ModuleCalculator( List<MavenProject> projectList, List<ScmFile> changeList )
49 {
50 this.projectList = Objects.requireNonNull( projectList, "projectList is not allowed to be null." );
51 this.changeList = Objects.requireNonNull( changeList, "changeList is not allowed to be null." );
52 }
53
54
55
56
57
58
59
60 public List<MavenProject> calculateChangedModules( Path projectRootpath )
61 {
62
63
64 List<MavenProject> result = new ArrayList<>();
65 for ( MavenProject project : projectList )
66 {
67 Path relativize = projectRootpath.relativize( project.getBasedir().toPath() );
68 for ( ScmFile fileItem : changeList )
69 {
70 boolean startsWith = new File( fileItem.getPath() ).toPath().startsWith( relativize );
71 logger.debug( "startswith: " + startsWith + " " + fileItem.getPath() + " " + relativize );
72 if ( startsWith )
73 {
74 if ( !result.contains( project ) )
75 {
76 result.add( project );
77 }
78 }
79 }
80 }
81 return result;
82 }
83
84 }