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