001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.tools.jspc.common;
016    
017    import java.io.File;
018    
019    import org.apache.tools.ant.DirectoryScanner;
020    
021    /**
022     * @author Minhchau Dang
023     */
024    public class TimestampUpdater {
025    
026            public static void main(String[] args) {
027                    if (args.length == 1) {
028                            new TimestampUpdater(args[0]);
029                    }
030                    else {
031                            throw new IllegalArgumentException();
032                    }
033            }
034    
035            public TimestampUpdater(String classDir) {
036                    DirectoryScanner directoryScanner = new DirectoryScanner();
037    
038                    directoryScanner.setBasedir(classDir);
039                    directoryScanner.setIncludes(new String[] {"**\\*.java"});
040    
041                    directoryScanner.scan();
042    
043                    String[] fileNames = directoryScanner.getIncludedFiles();
044    
045                    for (String fileName : fileNames) {
046                            File javaFile = new File(classDir, fileName);
047    
048                            String fileNameWithoutExtension = fileName.substring(
049                                    0, fileName.length() - 5);
050    
051                            String classFileName = fileNameWithoutExtension.concat(".class");
052    
053                            File classFile = new File(classDir, classFileName);
054    
055                            classFile.setLastModified(javaFile.lastModified());
056                    }
057            }
058    
059    }