001    /**
002     * Copyright (c) 2000-present 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.module.framework;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.kernel.util.StringUtil;
019    import com.liferay.portal.util.PropsValues;
020    
021    import java.io.File;
022    
023    import java.net.URL;
024    
025    /**
026     * @author Raymond Aug??
027     */
028    public class RuntimeClasspathResolver implements ClasspathResolver {
029    
030            @Override
031            public URL[] getClasspathURLs() throws Exception {
032                    File coreDir = new File(PropsValues.MODULE_FRAMEWORK_BASE_DIR, "core");
033    
034                    File[] files = coreDir.listFiles();
035    
036                    if (files == null) {
037                            throw new IllegalStateException(
038                                    "Missing " + coreDir.getCanonicalPath());
039                    }
040    
041                    URL[] urls = new URL[files.length];
042    
043                    for (int i = 0; i < urls.length; i++) {
044    
045                            // Ensure URLs are properly composed for Windows environments.
046                            // Otherwise, we will run into unexpected errors when referencing a
047                            // class from a JSP. See LPS-61210 for more information.
048    
049                            String path = StringUtil.replace(
050                                    files[i].getAbsolutePath(), StringPool.BACK_SLASH,
051                                    StringPool.SLASH);
052    
053                            if (!path.startsWith(StringPool.SLASH)) {
054                                    path = StringPool.SLASH + path;
055                            }
056    
057                            urls[i] = new URL("file", null, path);
058                    }
059    
060                    return urls;
061            }
062    
063    }