001    /**
002     * Copyright (c) 2000-2013 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.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 classDirName) {
036                    DirectoryScanner directoryScanner = new DirectoryScanner();
037    
038                    directoryScanner.setBasedir(classDirName);
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(classDirName, 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(classDirName, classFileName);
054    
055                            classFile.setLastModified(javaFile.lastModified());
056                    }
057            }
058    
059    }