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