View Javadoc

1   package org.apache.maven.continuum.utils;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.continuum.configuration.ConfigurationService;
23  import org.apache.maven.continuum.model.project.Project;
24  import org.apache.maven.continuum.model.project.ProjectGroup;
25  import org.springframework.stereotype.Service;
26  
27  import java.io.File;
28  import java.util.List;
29  import javax.annotation.Resource;
30  
31  /**
32   * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
33   * @version $Id: ChrootJailWorkingDirectoryService.java 1372260 2012-08-13 04:29:09Z brett $
34   */
35  @Service( "workingDirectoryService#chrootJail" )
36  public class ChrootJailWorkingDirectoryService
37      implements WorkingDirectoryService
38  {
39      @Resource
40      private ConfigurationService configurationService;
41  
42      /**
43       * @plexus.configuration
44       */
45      private File chrootJailDirectory;
46  
47      public void setConfigurationService( ConfigurationService configurationService )
48      {
49          this.configurationService = configurationService;
50      }
51  
52      public ConfigurationService getConfigurationService()
53      {
54          return configurationService;
55      }
56  
57      public void setChrootJailDirectory( File chrootJailDirectory )
58      {
59          this.chrootJailDirectory = chrootJailDirectory;
60      }
61  
62      public File getChrootJailDirectory()
63      {
64          return chrootJailDirectory;
65      }
66  
67      public File getWorkingDirectory( Project project )
68      {
69          return getWorkingDirectory( project, true );
70      }
71  
72      public File getWorkingDirectory( Project project, boolean shouldSet )
73      {
74          ProjectGroup projectGroup = project.getProjectGroup();
75  
76          File f = new File( getChrootJailDirectory(), projectGroup.getGroupId() );
77          f = new File( f, getConfigurationService().getWorkingDirectory().getPath() );
78          return new File( f, Integer.toString( project.getId() ) );
79      }
80  
81      public File getWorkingDirectory( Project project, String projectScmRoot, List<Project> projects )
82      {
83          return getWorkingDirectory( project, true );
84      }
85  
86      public File getWorkingDirectory( Project project, String projectScmRoot, List<Project> projects, boolean shouldSet )
87      {
88          return getWorkingDirectory( project, shouldSet );
89      }
90  }