1 package org.codehaus.mojo.natives;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import org.codehaus.mojo.natives.parser.Parser;
7
8 /*
9 * The MIT License
10 *
11 * Copyright (c) 2004, The Codehaus
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a copy of
14 * this software and associated documentation files (the "Software"), to deal in
15 * the Software without restriction, including without limitation the rights to
16 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17 * of the Software, and to permit persons to whom the Software is furnished to do
18 * so, subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be included in all
21 * copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 * SOFTWARE.
30 */
31
32 /**
33 * @author <a href="mailto:dantran@gmail.com">Dan Tran</a>
34 * @version $Id$
35 */
36
37 public class SourceDependencyAnalyzer
38 {
39 public static boolean isStaled( File source, File dest, Parser parser, File[] includePaths )
40 throws NativeBuildException
41 {
42 if ( !source.exists() )
43 {
44 throw new NativeBuildException( source.getPath() + " not found." );
45 }
46
47 // quick compare with the source where the user likely to change first
48 if ( ( !dest.exists() ) || ( dest.lastModified() < source.lastModified() ) )
49 {
50 return true;
51 }
52
53 // analyze the depenencies of the source file to detect any new changes
54 Dependency dependency = new Dependency( null, source, parser, includePaths );
55
56 try
57 {
58 dependency.analyze();
59 }
60 catch ( IOException ioe )
61 {
62 throw new NativeBuildException( "Error analysing " + source.getPath() + ". Reason: " + ioe.getMessage() );
63 }
64
65 return dest.lastModified() < dependency.getCompositeLastModified();
66
67 }
68
69 }