View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors.
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   * 
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23   */
24  package org.modeshape.connector.svn.mgnt;
25  
26  import org.modeshape.connector.scm.ScmAction;
27  import org.tmatesoft.svn.core.SVNException;
28  import org.tmatesoft.svn.core.io.ISVNEditor;
29  
30  /**
31   * root should be the last, previously created, parent folder. Each directory in the path will be created.
32   * @author serge pagop
33   */
34  public class AddDirectory implements ScmAction {
35      private String rootDirPath;
36      private String childDirPath;
37  
38      public AddDirectory( String rootPath,
39                           String childDirPath ) {
40          this.rootDirPath = rootPath;
41          this.childDirPath = childDirPath;
42      }
43  
44      public void applyAction( Object context ) throws SVNException {
45  
46          ISVNEditor editor = (ISVNEditor)context;
47  
48          ISVNEditorUtil.openDirectories(editor, this.rootDirPath);
49          String[] paths = this.childDirPath.split("/");
50          String newPath = this.rootDirPath;
51          for (int i = 0, length = paths.length; i < length; i++) {
52              newPath = (newPath.length() != 0) ? newPath + "/" + paths[i] : paths[i];
53  
54              editor.addDir(newPath, null, -1);
55          }
56  
57          ISVNEditorUtil.closeDirectories(editor, childDirPath);
58          ISVNEditorUtil.closeDirectories(editor, this.rootDirPath);
59      }
60  
61      @Override
62      public String toString() {
63          return "AddDirectory {" + rootDirPath + "/" + childDirPath + "}";
64      }
65  }