001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.util.ant;
016    
017    import java.io.File;
018    
019    import org.apache.tools.ant.Project;
020    import org.apache.tools.ant.taskdefs.UpToDate;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class UpToDateTask {
026    
027            public static boolean isUpToDate(File source, File target) {
028                    if (!source.exists() || !target.exists()) {
029                            return false;
030                    }
031    
032                    Project project = AntUtil.getProject();
033    
034                    UpToDate upToDate = new UpToDate();
035    
036                    upToDate.setProject(project);
037                    upToDate.setProperty("uptodate");
038                    upToDate.setSrcfile(source);
039                    upToDate.setTargetFile(target);
040    
041                    upToDate.execute();
042    
043                    if (project.getProperty("uptodate") != null) {
044                            return true;
045                    }
046                    else {
047                            return false;
048                    }
049            }
050    
051            public static boolean isUpToDate(String source, String target) {
052                    return isUpToDate(new File(source), new File(target));
053            }
054    
055    }