1 package org.apache.maven.continuum.core.action;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.continuum.dao.ProjectDao;
23 import org.apache.maven.continuum.ContinuumException;
24 import org.apache.maven.continuum.model.project.Project;
25 import org.apache.maven.continuum.utils.WorkingDirectoryService;
26
27 import java.io.File;
28 import java.util.List;
29 import java.util.Map;
30
31
32
33
34
35
36
37 public class CheckWorkingDirectoryAction
38 extends AbstractContinuumAction
39 {
40
41
42
43 private WorkingDirectoryService workingDirectoryService;
44
45
46
47
48 private ProjectDao projectDao;
49
50 private static final String KEY_WORKING_DIRECTORY_EXISTS = "working-directory-exists";
51
52 public void execute( Map context )
53 throws Exception
54 {
55 Project project = projectDao.getProject( getProjectId( context ) );
56 List<Project> projectsWithCommonScmRoot = getListOfProjectsInGroupWithCommonScmRoot( context );
57 String projectScmRootUrl = getProjectScmRootUrl( context, project.getScmUrl() );
58
59 File workingDirectory = workingDirectoryService.getWorkingDirectory( project, projectScmRootUrl,
60 projectsWithCommonScmRoot );
61
62 if ( !workingDirectory.exists() )
63 {
64 setWorkingDirectoryExists( context, false );
65
66 return;
67 }
68
69 File[] files = workingDirectory.listFiles();
70
71 if ( files == null )
72 {
73
74 String msg = workingDirectory.getAbsolutePath() + " isn't a directory but a file.";
75 getLogger().error( msg );
76 throw new ContinuumException( msg );
77 }
78
79 setWorkingDirectoryExists( context, files.length > 0 );
80 }
81
82 public static boolean isWorkingDirectoryExists( Map<String, Object> context )
83 {
84 return getBoolean( context, KEY_WORKING_DIRECTORY_EXISTS, false );
85 }
86
87 public static void setWorkingDirectoryExists( Map<String, Object> context, boolean isWorkingDirectoryExists )
88 {
89 context.put( KEY_WORKING_DIRECTORY_EXISTS, isWorkingDirectoryExists );
90 }
91
92 }