View Javadoc
1   package org.apache.maven.shared.utils.io;
2   
3   
4   import java.io.File;
5   import java.io.IOException;
6   
7   import static org.apache.commons.io.FileUtils.write;
8   
9   /*
10   * Licensed to the Apache Software Foundation (ASF) under one
11   * or more contributor license agreements.  See the NOTICE file
12   * distributed with this work for additional information
13   * regarding copyright ownership.  The ASF licenses this file
14   * to you under the Apache License, Version 2.0 (the
15   * "License"); you may not use this file except in compliance
16   * with the License.  You may obtain a copy of the License at
17   *
18   *  http://www.apache.org/licenses/LICENSE-2.0
19   *
20   * Unless required by applicable law or agreed to in writing,
21   * software distributed under the License is distributed on an
22   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23   * KIND, either express or implied.  See the License for the
24   * specific language governing permissions and limitations
25   * under the License.
26   */
27  public class SymlinkTestSetup
28  {
29      /**
30       * Creates a standard directory layout with symlinks and files.
31       */
32      public static File createStandardSymlinkTestDir( File root )
33          throws IOException
34      {
35          File srcDir = new File( root, "/src" );
36          srcDir.mkdirs();
37          File target = new File( srcDir, "targetDir" );
38          target.mkdirs();
39          write( new File( target, "targetFile.txt" ), "a regular File payload" );
40          File aRegularDir = new File( srcDir, "aRegularDir" );
41          aRegularDir.mkdirs();
42          write( new File( aRegularDir, "aRegularFile.txt" ), "a regular File payload" );
43  
44          File dirOnTheOutside = new File( root, "dirOnTheOutside" );
45          dirOnTheOutside.mkdirs();
46          write( new File( dirOnTheOutside, "FileInDirOnTheOutside.txt" ), "a file in dir on the outside" );
47          write( new File( root, "onTheOutside.txt" ), "A file on the outside" );
48          write( new File( srcDir, "fileR.txt" ), "FileR payload" );
49          write( new File( srcDir, "fileW.txt" ), "FileW payload" );
50          write( new File( srcDir, "fileX.txt" ), "FileX payload" );
51          // todo: set file attributes (not used here)
52  
53          Java7Support.createSymbolicLink( new File( srcDir, "symDir" ), new File( "targetDir" ) );
54          Java7Support.createSymbolicLink( new File( srcDir, "symLinkToDirOnTheOutside" ),
55                                           new File( "../dirOnTheOutside" ) );
56          Java7Support.createSymbolicLink( new File( srcDir, "symLinkToFileOnTheOutside" ),
57                                           new File( "../onTheOutside.txt" ) );
58          Java7Support.createSymbolicLink( new File( srcDir, "symR" ), new File( "fileR.txt" ) );
59          Java7Support.createSymbolicLink( new File( srcDir, "symW" ), new File( "fileW.txt" ) );
60          Java7Support.createSymbolicLink( new File( srcDir, "symX" ), new File( "fileX.txt" ) );
61          return srcDir;
62      }
63  }