View Javadoc

1   /*
2    * Copyright (c) 2007, Ounce Labs, Inc.
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *     * Redistributions of source code must retain the above copyright
8    *       notice, this list of conditions and the following disclaimer.
9    *     * Redistributions in binary form must reproduce the above copyright
10   *       notice, this list of conditions and the following disclaimer in the
11   *       documentation and/or other materials provided with the distribution.
12   *     * Neither the name of the <organization> nor the
13   *       names of its contributors may be used to endorse or promote products
14   *       derived from this software without specific prior written permission.
15   *
16   * THIS SOFTWARE IS PROVIDED BY OUNCE LABS, INC. ``AS IS'' AND ANY
17   * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19   * DISCLAIMED. IN NO EVENT SHALL OUNCE LABS, INC. BE LIABLE FOR ANY
20   * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26   */
27  package org.codehaus.mojo.ounce.utils;
28  
29  import java.io.File;
30  import java.io.IOException;
31  import java.io.InputStream;
32  
33  import org.codehaus.plexus.components.io.fileselectors.FileInfo;
34  
35  /**
36   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
37   */
38  public class ProjectFileInfo
39      implements FileInfo
40  {
41  
42      private File theFile;
43  
44      public ProjectFileInfo( File theFile )
45      {
46          super();
47          this.theFile = theFile;
48      }
49  
50      /*
51       * (non-Javadoc)
52       * 
53       * @see org.codehaus.plexus.components.io.fileselectors.FileInfo#getContents()
54       */
55      public InputStream getContents()
56          throws IOException
57      {
58          return null;
59      }
60  
61      /*
62       * (non-Javadoc)
63       * 
64       * @see org.codehaus.plexus.components.io.fileselectors.FileInfo#getName()
65       */
66      public String getName()
67      {
68          // the selector utils has odd behavior. I must strip
69          // off the leading separator char to match
70          // the default includes etc. This causes problems on
71          // unix os's.
72          String name = theFile.getAbsolutePath().replace( '/', File.separatorChar ).replace( '\\', File.separatorChar );
73          if ( name.startsWith( File.separator ) )
74          {
75              name = name.substring( 1 );
76          }
77          return name;
78      }
79  
80      /*
81       * (non-Javadoc)
82       * 
83       * @see org.codehaus.plexus.components.io.fileselectors.FileInfo#isDirectory()
84       */
85      public boolean isDirectory()
86      {
87          return theFile.isDirectory();
88      }
89  
90      /*
91       * (non-Javadoc)
92       * 
93       * @see org.codehaus.plexus.components.io.fileselectors.FileInfo#isFile()
94       */
95      public boolean isFile()
96      {
97          return !isDirectory();
98      }
99  
100 }