001    /**
002     * Copyright (c) 2000-2013 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.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 doFormat() throws Exception {
029                    _formatSH("ext/create.sh");
030                    _formatSH("hooks/create.sh");
031                    _formatSH("layouttpl/create.sh");
032                    _formatSH("portlets/create.sh");
033                    _formatSH("themes/create.sh");
034            }
035    
036            private void _formatSH(String fileName) throws IOException {
037                    File file = new File(fileName);
038    
039                    if (!file.exists()) {
040                            return;
041                    }
042    
043                    String content = fileUtil.read(new File(fileName), true);
044    
045                    if (content.contains("\r")) {
046                            processErrorMessage(fileName, "Invalid new line character");
047    
048                            content = StringUtil.replace(content, "\r", "");
049    
050                            fileUtil.write(fileName, content);
051                    }
052            }
053    
054    }