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.sourceformatter;
016    
017    import com.liferay.portal.kernel.util.StringUtil;
018    
019    import java.io.File;
020    import java.io.IOException;
021    
022    /**
023     * @author Hugo Huijser
024     */
025    public class SHSourceProcessor extends BaseSourceProcessor {
026    
027            @Override
028            protected void format() throws Exception {
029                    format("ext/create.sh");
030                    format("hooks/create.sh");
031                    format("layouttpl/create.sh");
032                    format("portlets/create.sh");
033                    format("themes/create.sh");
034            }
035    
036            @Override
037            protected String format(String fileName) throws IOException {
038                    File file = new File(fileName);
039    
040                    if (!file.exists()) {
041                            return null;
042                    }
043    
044                    String content = fileUtil.read(new File(fileName), true);
045    
046                    if (content.contains("\r")) {
047                            processErrorMessage(fileName, "Invalid new line character");
048    
049                            if (isAutoFix()) {
050                                    content = StringUtil.replace(content, "\r", "");
051    
052                                    fileUtil.write(fileName, content);
053                            }
054                    }
055    
056                    return content;
057            }
058    
059    }