Moved Locator class to gameserver util package.
This commit is contained in:
@@ -32,6 +32,7 @@ import javax.swing.border.LineBorder;
|
|||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.gameserver.GameServer;
|
import com.l2jmobius.gameserver.GameServer;
|
||||||
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
||||||
|
import com.l2jmobius.gameserver.util.Locator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.l2jmobius.gameserver.ui;
|
package com.l2jmobius.gameserver.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
@@ -24,41 +24,45 @@ import java.text.CharacterIterator;
|
|||||||
import java.text.StringCharacterIterator;
|
import java.text.StringCharacterIterator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
final class Locator
|
/**
|
||||||
|
* The Locator is a utility class which is used to find certain items in the environment.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public final class Locator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor for Locator.
|
* Not instantiable
|
||||||
*/
|
*/
|
||||||
private Locator()
|
private Locator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getClassSource.
|
* Find the directory or jar file the class has been loaded from.
|
||||||
* @param c Class<?>
|
* @param c the class whose location is required.
|
||||||
* @return File
|
* @return the file or jar with the class or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
*/
|
*/
|
||||||
static File getClassSource(Class<?> c)
|
public static File getClassSource(Class<?> c)
|
||||||
{
|
{
|
||||||
String classResource = c.getName().replace('.', '/') + ".class";
|
String classResource = c.getName().replace('.', '/') + ".class";
|
||||||
return getResourceSource(c.getClassLoader(), classResource);
|
return getResourceSource(c.getClassLoader(), classResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getResourceSource.
|
* Find the directory or jar a given resource has been loaded from.
|
||||||
* @param c ClassLoader
|
* @param c the classloader to be consulted for the source.
|
||||||
* @param resource String
|
* @param resource the resource whose location is required.
|
||||||
* @return File
|
* @return the file with the resource source or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
*/
|
*/
|
||||||
private static File getResourceSource(ClassLoader c, String resource)
|
public static File getResourceSource(ClassLoader c, String resource)
|
||||||
{
|
{
|
||||||
if (c == null)
|
if (c == null)
|
||||||
{
|
{
|
||||||
c = Locator.class.getClassLoader();
|
c = Locator.class.getClassLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
URL url = null;
|
URL url = null;
|
||||||
|
|
||||||
if (c == null)
|
if (c == null)
|
||||||
{
|
{
|
||||||
url = ClassLoader.getSystemResource(resource);
|
url = ClassLoader.getSystemResource(resource);
|
||||||
@@ -67,11 +71,9 @@ final class Locator
|
|||||||
{
|
{
|
||||||
url = c.getResource(resource);
|
url = c.getResource(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url != null)
|
if (url != null)
|
||||||
{
|
{
|
||||||
String u = url.toString();
|
String u = url.toString();
|
||||||
|
|
||||||
if (u.startsWith("jar:file:"))
|
if (u.startsWith("jar:file:"))
|
||||||
{
|
{
|
||||||
int pling = u.indexOf("!");
|
int pling = u.indexOf("!");
|
||||||
@@ -85,58 +87,59 @@ final class Locator
|
|||||||
return new File(fromURI(dirName));
|
return new File(fromURI(dirName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method fromURI.
|
* Constructs a file path from a <code>file:</code> URI.
|
||||||
* @param uri String
|
* <p>
|
||||||
* @return String
|
* Will be an absolute path if the given URI is absolute.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Swallows '%' that are not followed by two characters, doesn't deal with non-ASCII characters.
|
||||||
|
* </p>
|
||||||
|
* @param uri the URI designating a file in the local filesystem.
|
||||||
|
* @return the local file system path for the file.
|
||||||
|
* @since Ant 1.6
|
||||||
*/
|
*/
|
||||||
private static String fromURI(String uri)
|
public static String fromURI(String uri)
|
||||||
{
|
{
|
||||||
URL url = null;
|
URL url = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
url = new URL(uri);
|
url = new URL(uri);
|
||||||
}
|
}
|
||||||
catch (MalformedURLException emYouEarlEx)
|
catch (MalformedURLException emYouEarlEx)
|
||||||
{
|
{
|
||||||
// empty catch clause
|
// Ignore malformed exception
|
||||||
}
|
}
|
||||||
|
if ((url == null) || !("file".equals(url.getProtocol())))
|
||||||
if ((url == null) || !"file".equals(url.getProtocol()))
|
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
||||||
}
|
}
|
||||||
|
StringBuffer buf = new StringBuffer(url.getHost());
|
||||||
StringBuilder buf = new StringBuilder(url.getHost());
|
|
||||||
|
|
||||||
if (buf.length() > 0)
|
if (buf.length() > 0)
|
||||||
{
|
{
|
||||||
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
String file = url.getFile();
|
String file = url.getFile();
|
||||||
int queryPos = file.indexOf('?');
|
int queryPos = file.indexOf('?');
|
||||||
buf.append(queryPos < 0 ? file : file.substring(0, queryPos));
|
buf.append((queryPos < 0) ? file : file.substring(0, queryPos));
|
||||||
|
|
||||||
uri = buf.toString().replace('/', File.separatorChar);
|
uri = buf.toString().replace('/', File.separatorChar);
|
||||||
|
|
||||||
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
||||||
{
|
{
|
||||||
uri = uri.substring(1);
|
uri = uri.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = decodeUri(uri);
|
String path = decodeUri(uri);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method decodeUri.
|
* Decodes an Uri with % characters.
|
||||||
* @param uri String
|
* @param uri String with the uri possibly containing % characters.
|
||||||
* @return String
|
* @return The decoded Uri
|
||||||
*/
|
*/
|
||||||
private static String decodeUri(String uri)
|
private static String decodeUri(String uri)
|
||||||
{
|
{
|
||||||
@@ -144,21 +147,17 @@ final class Locator
|
|||||||
{
|
{
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
CharacterIterator iter = new StringCharacterIterator(uri);
|
CharacterIterator iter = new StringCharacterIterator(uri);
|
||||||
|
|
||||||
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
||||||
{
|
{
|
||||||
if (c == '%')
|
if (c == '%')
|
||||||
{
|
{
|
||||||
char c1 = iter.next();
|
char c1 = iter.next();
|
||||||
|
|
||||||
if (c1 != CharacterIterator.DONE)
|
if (c1 != CharacterIterator.DONE)
|
||||||
{
|
{
|
||||||
int i1 = Character.digit(c1, 16);
|
int i1 = Character.digit(c1, 16);
|
||||||
char c2 = iter.next();
|
char c2 = iter.next();
|
||||||
|
|
||||||
if (c2 != CharacterIterator.DONE)
|
if (c2 != CharacterIterator.DONE)
|
||||||
{
|
{
|
||||||
int i2 = Character.digit(c2, 16);
|
int i2 = Character.digit(c2, 16);
|
||||||
@@ -171,21 +170,21 @@ final class Locator
|
|||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = sb.toString();
|
String path = sb.toString();
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getToolsJar.
|
* Get the File necessary to load the Sun compiler tools. If the classes are available to this class, then no additional URL is required and null is returned. This may be because the classes are explicitly in the class path or provided by the JVM directly.
|
||||||
* @return File
|
* @return the tools jar as a File if required, null otherwise.
|
||||||
*/
|
*/
|
||||||
static File getToolsJar()
|
public static File getToolsJar()
|
||||||
{
|
{
|
||||||
|
// firstly check if the tools jar is already in the classpath
|
||||||
boolean toolsJarAvailable = false;
|
boolean toolsJarAvailable = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// just check whether this throws an exception
|
||||||
Class.forName("com.sun.tools.javac.Main");
|
Class.forName("com.sun.tools.javac.Main");
|
||||||
toolsJarAvailable = true;
|
toolsJarAvailable = true;
|
||||||
}
|
}
|
||||||
@@ -198,40 +197,36 @@ final class Locator
|
|||||||
}
|
}
|
||||||
catch (Exception e2)
|
catch (Exception e2)
|
||||||
{
|
{
|
||||||
// empty catch clause
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toolsJarAvailable)
|
if (toolsJarAvailable)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// couldn't find compiler - try to find tools.jar
|
||||||
|
// based on java.home setting
|
||||||
String javaHome = System.getProperty("java.home");
|
String javaHome = System.getProperty("java.home");
|
||||||
|
|
||||||
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
||||||
{
|
{
|
||||||
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
||||||
|
|
||||||
if (!toolsJar.exists())
|
if (!toolsJar.exists())
|
||||||
{
|
{
|
||||||
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return toolsJar;
|
return toolsJar;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getLocationURLs.
|
* Get an array of URLs representing all of the jar files in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for jar files.
|
||||||
* @param location File
|
* @param location the location to scan for Jars.
|
||||||
* @return URL[] * @throws MalformedURLException
|
* @return an array of URLs for all jars in the given location.
|
||||||
* @throws MalformedURLException
|
* @exception MalformedURLException if the URLs for the jars cannot be formed.
|
||||||
*/
|
*/
|
||||||
static URL[] getLocationURLs(File location) throws MalformedURLException
|
public static URL[] getLocationURLs(File location) throws MalformedURLException
|
||||||
{
|
{
|
||||||
return getLocationURLs(location, new String[]
|
return getLocationURLs(location, new String[]
|
||||||
{
|
{
|
||||||
@@ -240,26 +235,25 @@ final class Locator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getLocationURLs.
|
* Get an array of URLs representing all of the files of a given set of extensions in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for matching files.
|
||||||
* @param location File
|
* @param location the location to scan for files.
|
||||||
* @param extensions String[]
|
* @param extensions an array of extension that are to match in the directory search.
|
||||||
* @return URL[] * @throws MalformedURLException
|
* @return an array of URLs of matching files.
|
||||||
* @throws MalformedURLException
|
* @exception MalformedURLException if the URLs for the files cannot be formed.
|
||||||
*/
|
*/
|
||||||
private static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
public static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
||||||
{
|
{
|
||||||
|
|
||||||
URL[] urls = new URL[0];
|
URL[] urls = new URL[0];
|
||||||
|
|
||||||
if (!location.exists())
|
if (!location.exists())
|
||||||
{
|
{
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!location.isDirectory())
|
if (!location.isDirectory())
|
||||||
{
|
{
|
||||||
urls = new URL[1];
|
urls = new URL[1];
|
||||||
String path = location.getPath();
|
String path = location.getPath();
|
||||||
|
|
||||||
for (String extension : extensions)
|
for (String extension : extensions)
|
||||||
{
|
{
|
||||||
if (path.toLowerCase().endsWith(extension))
|
if (path.toLowerCase().endsWith(extension))
|
||||||
@@ -268,10 +262,8 @@ final class Locator
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
||||||
{
|
{
|
||||||
for (String extension : extensions)
|
for (String extension : extensions)
|
||||||
@@ -284,12 +276,10 @@ final class Locator
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
urls = new URL[matches.length];
|
urls = new URL[matches.length];
|
||||||
|
|
||||||
for (int i = 0; i < matches.length; ++i)
|
for (int i = 0; i < matches.length; ++i)
|
||||||
{
|
{
|
||||||
urls[i] = matches[i].toURI().toURL();
|
urls[i] = matches[i].toURI().toURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -32,6 +32,7 @@ import javax.swing.border.LineBorder;
|
|||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.gameserver.GameServer;
|
import com.l2jmobius.gameserver.GameServer;
|
||||||
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
||||||
|
import com.l2jmobius.gameserver.util.Locator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.l2jmobius.gameserver.ui;
|
package com.l2jmobius.gameserver.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
@@ -24,41 +24,45 @@ import java.text.CharacterIterator;
|
|||||||
import java.text.StringCharacterIterator;
|
import java.text.StringCharacterIterator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
final class Locator
|
/**
|
||||||
|
* The Locator is a utility class which is used to find certain items in the environment.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public final class Locator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor for Locator.
|
* Not instantiable
|
||||||
*/
|
*/
|
||||||
private Locator()
|
private Locator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getClassSource.
|
* Find the directory or jar file the class has been loaded from.
|
||||||
* @param c Class<?>
|
* @param c the class whose location is required.
|
||||||
* @return File
|
* @return the file or jar with the class or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
*/
|
*/
|
||||||
static File getClassSource(Class<?> c)
|
public static File getClassSource(Class<?> c)
|
||||||
{
|
{
|
||||||
String classResource = c.getName().replace('.', '/') + ".class";
|
String classResource = c.getName().replace('.', '/') + ".class";
|
||||||
return getResourceSource(c.getClassLoader(), classResource);
|
return getResourceSource(c.getClassLoader(), classResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getResourceSource.
|
* Find the directory or jar a given resource has been loaded from.
|
||||||
* @param c ClassLoader
|
* @param c the classloader to be consulted for the source.
|
||||||
* @param resource String
|
* @param resource the resource whose location is required.
|
||||||
* @return File
|
* @return the file with the resource source or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
*/
|
*/
|
||||||
private static File getResourceSource(ClassLoader c, String resource)
|
public static File getResourceSource(ClassLoader c, String resource)
|
||||||
{
|
{
|
||||||
if (c == null)
|
if (c == null)
|
||||||
{
|
{
|
||||||
c = Locator.class.getClassLoader();
|
c = Locator.class.getClassLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
URL url = null;
|
URL url = null;
|
||||||
|
|
||||||
if (c == null)
|
if (c == null)
|
||||||
{
|
{
|
||||||
url = ClassLoader.getSystemResource(resource);
|
url = ClassLoader.getSystemResource(resource);
|
||||||
@@ -67,11 +71,9 @@ final class Locator
|
|||||||
{
|
{
|
||||||
url = c.getResource(resource);
|
url = c.getResource(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url != null)
|
if (url != null)
|
||||||
{
|
{
|
||||||
String u = url.toString();
|
String u = url.toString();
|
||||||
|
|
||||||
if (u.startsWith("jar:file:"))
|
if (u.startsWith("jar:file:"))
|
||||||
{
|
{
|
||||||
int pling = u.indexOf("!");
|
int pling = u.indexOf("!");
|
||||||
@@ -85,58 +87,59 @@ final class Locator
|
|||||||
return new File(fromURI(dirName));
|
return new File(fromURI(dirName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method fromURI.
|
* Constructs a file path from a <code>file:</code> URI.
|
||||||
* @param uri String
|
* <p>
|
||||||
* @return String
|
* Will be an absolute path if the given URI is absolute.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Swallows '%' that are not followed by two characters, doesn't deal with non-ASCII characters.
|
||||||
|
* </p>
|
||||||
|
* @param uri the URI designating a file in the local filesystem.
|
||||||
|
* @return the local file system path for the file.
|
||||||
|
* @since Ant 1.6
|
||||||
*/
|
*/
|
||||||
private static String fromURI(String uri)
|
public static String fromURI(String uri)
|
||||||
{
|
{
|
||||||
URL url = null;
|
URL url = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
url = new URL(uri);
|
url = new URL(uri);
|
||||||
}
|
}
|
||||||
catch (MalformedURLException emYouEarlEx)
|
catch (MalformedURLException emYouEarlEx)
|
||||||
{
|
{
|
||||||
// empty catch clause
|
// Ignore malformed exception
|
||||||
}
|
}
|
||||||
|
if ((url == null) || !("file".equals(url.getProtocol())))
|
||||||
if ((url == null) || !"file".equals(url.getProtocol()))
|
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
||||||
}
|
}
|
||||||
|
StringBuffer buf = new StringBuffer(url.getHost());
|
||||||
StringBuilder buf = new StringBuilder(url.getHost());
|
|
||||||
|
|
||||||
if (buf.length() > 0)
|
if (buf.length() > 0)
|
||||||
{
|
{
|
||||||
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
String file = url.getFile();
|
String file = url.getFile();
|
||||||
int queryPos = file.indexOf('?');
|
int queryPos = file.indexOf('?');
|
||||||
buf.append(queryPos < 0 ? file : file.substring(0, queryPos));
|
buf.append((queryPos < 0) ? file : file.substring(0, queryPos));
|
||||||
|
|
||||||
uri = buf.toString().replace('/', File.separatorChar);
|
uri = buf.toString().replace('/', File.separatorChar);
|
||||||
|
|
||||||
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
||||||
{
|
{
|
||||||
uri = uri.substring(1);
|
uri = uri.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = decodeUri(uri);
|
String path = decodeUri(uri);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method decodeUri.
|
* Decodes an Uri with % characters.
|
||||||
* @param uri String
|
* @param uri String with the uri possibly containing % characters.
|
||||||
* @return String
|
* @return The decoded Uri
|
||||||
*/
|
*/
|
||||||
private static String decodeUri(String uri)
|
private static String decodeUri(String uri)
|
||||||
{
|
{
|
||||||
@@ -144,21 +147,17 @@ final class Locator
|
|||||||
{
|
{
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
CharacterIterator iter = new StringCharacterIterator(uri);
|
CharacterIterator iter = new StringCharacterIterator(uri);
|
||||||
|
|
||||||
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
||||||
{
|
{
|
||||||
if (c == '%')
|
if (c == '%')
|
||||||
{
|
{
|
||||||
char c1 = iter.next();
|
char c1 = iter.next();
|
||||||
|
|
||||||
if (c1 != CharacterIterator.DONE)
|
if (c1 != CharacterIterator.DONE)
|
||||||
{
|
{
|
||||||
int i1 = Character.digit(c1, 16);
|
int i1 = Character.digit(c1, 16);
|
||||||
char c2 = iter.next();
|
char c2 = iter.next();
|
||||||
|
|
||||||
if (c2 != CharacterIterator.DONE)
|
if (c2 != CharacterIterator.DONE)
|
||||||
{
|
{
|
||||||
int i2 = Character.digit(c2, 16);
|
int i2 = Character.digit(c2, 16);
|
||||||
@@ -171,21 +170,21 @@ final class Locator
|
|||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = sb.toString();
|
String path = sb.toString();
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getToolsJar.
|
* Get the File necessary to load the Sun compiler tools. If the classes are available to this class, then no additional URL is required and null is returned. This may be because the classes are explicitly in the class path or provided by the JVM directly.
|
||||||
* @return File
|
* @return the tools jar as a File if required, null otherwise.
|
||||||
*/
|
*/
|
||||||
static File getToolsJar()
|
public static File getToolsJar()
|
||||||
{
|
{
|
||||||
|
// firstly check if the tools jar is already in the classpath
|
||||||
boolean toolsJarAvailable = false;
|
boolean toolsJarAvailable = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// just check whether this throws an exception
|
||||||
Class.forName("com.sun.tools.javac.Main");
|
Class.forName("com.sun.tools.javac.Main");
|
||||||
toolsJarAvailable = true;
|
toolsJarAvailable = true;
|
||||||
}
|
}
|
||||||
@@ -198,40 +197,36 @@ final class Locator
|
|||||||
}
|
}
|
||||||
catch (Exception e2)
|
catch (Exception e2)
|
||||||
{
|
{
|
||||||
// empty catch clause
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toolsJarAvailable)
|
if (toolsJarAvailable)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// couldn't find compiler - try to find tools.jar
|
||||||
|
// based on java.home setting
|
||||||
String javaHome = System.getProperty("java.home");
|
String javaHome = System.getProperty("java.home");
|
||||||
|
|
||||||
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
||||||
{
|
{
|
||||||
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
||||||
|
|
||||||
if (!toolsJar.exists())
|
if (!toolsJar.exists())
|
||||||
{
|
{
|
||||||
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return toolsJar;
|
return toolsJar;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getLocationURLs.
|
* Get an array of URLs representing all of the jar files in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for jar files.
|
||||||
* @param location File
|
* @param location the location to scan for Jars.
|
||||||
* @return URL[] * @throws MalformedURLException
|
* @return an array of URLs for all jars in the given location.
|
||||||
* @throws MalformedURLException
|
* @exception MalformedURLException if the URLs for the jars cannot be formed.
|
||||||
*/
|
*/
|
||||||
static URL[] getLocationURLs(File location) throws MalformedURLException
|
public static URL[] getLocationURLs(File location) throws MalformedURLException
|
||||||
{
|
{
|
||||||
return getLocationURLs(location, new String[]
|
return getLocationURLs(location, new String[]
|
||||||
{
|
{
|
||||||
@@ -240,26 +235,25 @@ final class Locator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getLocationURLs.
|
* Get an array of URLs representing all of the files of a given set of extensions in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for matching files.
|
||||||
* @param location File
|
* @param location the location to scan for files.
|
||||||
* @param extensions String[]
|
* @param extensions an array of extension that are to match in the directory search.
|
||||||
* @return URL[] * @throws MalformedURLException
|
* @return an array of URLs of matching files.
|
||||||
* @throws MalformedURLException
|
* @exception MalformedURLException if the URLs for the files cannot be formed.
|
||||||
*/
|
*/
|
||||||
private static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
public static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
||||||
{
|
{
|
||||||
|
|
||||||
URL[] urls = new URL[0];
|
URL[] urls = new URL[0];
|
||||||
|
|
||||||
if (!location.exists())
|
if (!location.exists())
|
||||||
{
|
{
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!location.isDirectory())
|
if (!location.isDirectory())
|
||||||
{
|
{
|
||||||
urls = new URL[1];
|
urls = new URL[1];
|
||||||
String path = location.getPath();
|
String path = location.getPath();
|
||||||
|
|
||||||
for (String extension : extensions)
|
for (String extension : extensions)
|
||||||
{
|
{
|
||||||
if (path.toLowerCase().endsWith(extension))
|
if (path.toLowerCase().endsWith(extension))
|
||||||
@@ -268,10 +262,8 @@ final class Locator
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
||||||
{
|
{
|
||||||
for (String extension : extensions)
|
for (String extension : extensions)
|
||||||
@@ -284,12 +276,10 @@ final class Locator
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
urls = new URL[matches.length];
|
urls = new URL[matches.length];
|
||||||
|
|
||||||
for (int i = 0; i < matches.length; ++i)
|
for (int i = 0; i < matches.length; ++i)
|
||||||
{
|
{
|
||||||
urls[i] = matches[i].toURI().toURL();
|
urls[i] = matches[i].toURI().toURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -32,6 +32,7 @@ import javax.swing.border.LineBorder;
|
|||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.gameserver.GameServer;
|
import com.l2jmobius.gameserver.GameServer;
|
||||||
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
||||||
|
import com.l2jmobius.gameserver.util.Locator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.l2jmobius.gameserver.ui;
|
package com.l2jmobius.gameserver.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
@@ -24,41 +24,45 @@ import java.text.CharacterIterator;
|
|||||||
import java.text.StringCharacterIterator;
|
import java.text.StringCharacterIterator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
final class Locator
|
/**
|
||||||
|
* The Locator is a utility class which is used to find certain items in the environment.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public final class Locator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor for Locator.
|
* Not instantiable
|
||||||
*/
|
*/
|
||||||
private Locator()
|
private Locator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getClassSource.
|
* Find the directory or jar file the class has been loaded from.
|
||||||
* @param c Class<?>
|
* @param c the class whose location is required.
|
||||||
* @return File
|
* @return the file or jar with the class or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
*/
|
*/
|
||||||
static File getClassSource(Class<?> c)
|
public static File getClassSource(Class<?> c)
|
||||||
{
|
{
|
||||||
String classResource = c.getName().replace('.', '/') + ".class";
|
String classResource = c.getName().replace('.', '/') + ".class";
|
||||||
return getResourceSource(c.getClassLoader(), classResource);
|
return getResourceSource(c.getClassLoader(), classResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getResourceSource.
|
* Find the directory or jar a given resource has been loaded from.
|
||||||
* @param c ClassLoader
|
* @param c the classloader to be consulted for the source.
|
||||||
* @param resource String
|
* @param resource the resource whose location is required.
|
||||||
* @return File
|
* @return the file with the resource source or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
*/
|
*/
|
||||||
private static File getResourceSource(ClassLoader c, String resource)
|
public static File getResourceSource(ClassLoader c, String resource)
|
||||||
{
|
{
|
||||||
if (c == null)
|
if (c == null)
|
||||||
{
|
{
|
||||||
c = Locator.class.getClassLoader();
|
c = Locator.class.getClassLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
URL url = null;
|
URL url = null;
|
||||||
|
|
||||||
if (c == null)
|
if (c == null)
|
||||||
{
|
{
|
||||||
url = ClassLoader.getSystemResource(resource);
|
url = ClassLoader.getSystemResource(resource);
|
||||||
@@ -67,11 +71,9 @@ final class Locator
|
|||||||
{
|
{
|
||||||
url = c.getResource(resource);
|
url = c.getResource(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url != null)
|
if (url != null)
|
||||||
{
|
{
|
||||||
String u = url.toString();
|
String u = url.toString();
|
||||||
|
|
||||||
if (u.startsWith("jar:file:"))
|
if (u.startsWith("jar:file:"))
|
||||||
{
|
{
|
||||||
int pling = u.indexOf("!");
|
int pling = u.indexOf("!");
|
||||||
@@ -85,58 +87,59 @@ final class Locator
|
|||||||
return new File(fromURI(dirName));
|
return new File(fromURI(dirName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method fromURI.
|
* Constructs a file path from a <code>file:</code> URI.
|
||||||
* @param uri String
|
* <p>
|
||||||
* @return String
|
* Will be an absolute path if the given URI is absolute.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Swallows '%' that are not followed by two characters, doesn't deal with non-ASCII characters.
|
||||||
|
* </p>
|
||||||
|
* @param uri the URI designating a file in the local filesystem.
|
||||||
|
* @return the local file system path for the file.
|
||||||
|
* @since Ant 1.6
|
||||||
*/
|
*/
|
||||||
private static String fromURI(String uri)
|
public static String fromURI(String uri)
|
||||||
{
|
{
|
||||||
URL url = null;
|
URL url = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
url = new URL(uri);
|
url = new URL(uri);
|
||||||
}
|
}
|
||||||
catch (MalformedURLException emYouEarlEx)
|
catch (MalformedURLException emYouEarlEx)
|
||||||
{
|
{
|
||||||
// empty catch clause
|
// Ignore malformed exception
|
||||||
}
|
}
|
||||||
|
if ((url == null) || !("file".equals(url.getProtocol())))
|
||||||
if ((url == null) || !"file".equals(url.getProtocol()))
|
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
||||||
}
|
}
|
||||||
|
StringBuffer buf = new StringBuffer(url.getHost());
|
||||||
StringBuilder buf = new StringBuilder(url.getHost());
|
|
||||||
|
|
||||||
if (buf.length() > 0)
|
if (buf.length() > 0)
|
||||||
{
|
{
|
||||||
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
String file = url.getFile();
|
String file = url.getFile();
|
||||||
int queryPos = file.indexOf('?');
|
int queryPos = file.indexOf('?');
|
||||||
buf.append(queryPos < 0 ? file : file.substring(0, queryPos));
|
buf.append((queryPos < 0) ? file : file.substring(0, queryPos));
|
||||||
|
|
||||||
uri = buf.toString().replace('/', File.separatorChar);
|
uri = buf.toString().replace('/', File.separatorChar);
|
||||||
|
|
||||||
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
||||||
{
|
{
|
||||||
uri = uri.substring(1);
|
uri = uri.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = decodeUri(uri);
|
String path = decodeUri(uri);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method decodeUri.
|
* Decodes an Uri with % characters.
|
||||||
* @param uri String
|
* @param uri String with the uri possibly containing % characters.
|
||||||
* @return String
|
* @return The decoded Uri
|
||||||
*/
|
*/
|
||||||
private static String decodeUri(String uri)
|
private static String decodeUri(String uri)
|
||||||
{
|
{
|
||||||
@@ -144,21 +147,17 @@ final class Locator
|
|||||||
{
|
{
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
CharacterIterator iter = new StringCharacterIterator(uri);
|
CharacterIterator iter = new StringCharacterIterator(uri);
|
||||||
|
|
||||||
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
||||||
{
|
{
|
||||||
if (c == '%')
|
if (c == '%')
|
||||||
{
|
{
|
||||||
char c1 = iter.next();
|
char c1 = iter.next();
|
||||||
|
|
||||||
if (c1 != CharacterIterator.DONE)
|
if (c1 != CharacterIterator.DONE)
|
||||||
{
|
{
|
||||||
int i1 = Character.digit(c1, 16);
|
int i1 = Character.digit(c1, 16);
|
||||||
char c2 = iter.next();
|
char c2 = iter.next();
|
||||||
|
|
||||||
if (c2 != CharacterIterator.DONE)
|
if (c2 != CharacterIterator.DONE)
|
||||||
{
|
{
|
||||||
int i2 = Character.digit(c2, 16);
|
int i2 = Character.digit(c2, 16);
|
||||||
@@ -171,21 +170,21 @@ final class Locator
|
|||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = sb.toString();
|
String path = sb.toString();
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getToolsJar.
|
* Get the File necessary to load the Sun compiler tools. If the classes are available to this class, then no additional URL is required and null is returned. This may be because the classes are explicitly in the class path or provided by the JVM directly.
|
||||||
* @return File
|
* @return the tools jar as a File if required, null otherwise.
|
||||||
*/
|
*/
|
||||||
static File getToolsJar()
|
public static File getToolsJar()
|
||||||
{
|
{
|
||||||
|
// firstly check if the tools jar is already in the classpath
|
||||||
boolean toolsJarAvailable = false;
|
boolean toolsJarAvailable = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// just check whether this throws an exception
|
||||||
Class.forName("com.sun.tools.javac.Main");
|
Class.forName("com.sun.tools.javac.Main");
|
||||||
toolsJarAvailable = true;
|
toolsJarAvailable = true;
|
||||||
}
|
}
|
||||||
@@ -198,40 +197,36 @@ final class Locator
|
|||||||
}
|
}
|
||||||
catch (Exception e2)
|
catch (Exception e2)
|
||||||
{
|
{
|
||||||
// empty catch clause
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toolsJarAvailable)
|
if (toolsJarAvailable)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// couldn't find compiler - try to find tools.jar
|
||||||
|
// based on java.home setting
|
||||||
String javaHome = System.getProperty("java.home");
|
String javaHome = System.getProperty("java.home");
|
||||||
|
|
||||||
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
||||||
{
|
{
|
||||||
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
||||||
|
|
||||||
if (!toolsJar.exists())
|
if (!toolsJar.exists())
|
||||||
{
|
{
|
||||||
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return toolsJar;
|
return toolsJar;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getLocationURLs.
|
* Get an array of URLs representing all of the jar files in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for jar files.
|
||||||
* @param location File
|
* @param location the location to scan for Jars.
|
||||||
* @return URL[] * @throws MalformedURLException
|
* @return an array of URLs for all jars in the given location.
|
||||||
* @throws MalformedURLException
|
* @exception MalformedURLException if the URLs for the jars cannot be formed.
|
||||||
*/
|
*/
|
||||||
static URL[] getLocationURLs(File location) throws MalformedURLException
|
public static URL[] getLocationURLs(File location) throws MalformedURLException
|
||||||
{
|
{
|
||||||
return getLocationURLs(location, new String[]
|
return getLocationURLs(location, new String[]
|
||||||
{
|
{
|
||||||
@@ -240,26 +235,25 @@ final class Locator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getLocationURLs.
|
* Get an array of URLs representing all of the files of a given set of extensions in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for matching files.
|
||||||
* @param location File
|
* @param location the location to scan for files.
|
||||||
* @param extensions String[]
|
* @param extensions an array of extension that are to match in the directory search.
|
||||||
* @return URL[] * @throws MalformedURLException
|
* @return an array of URLs of matching files.
|
||||||
* @throws MalformedURLException
|
* @exception MalformedURLException if the URLs for the files cannot be formed.
|
||||||
*/
|
*/
|
||||||
private static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
public static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
||||||
{
|
{
|
||||||
|
|
||||||
URL[] urls = new URL[0];
|
URL[] urls = new URL[0];
|
||||||
|
|
||||||
if (!location.exists())
|
if (!location.exists())
|
||||||
{
|
{
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!location.isDirectory())
|
if (!location.isDirectory())
|
||||||
{
|
{
|
||||||
urls = new URL[1];
|
urls = new URL[1];
|
||||||
String path = location.getPath();
|
String path = location.getPath();
|
||||||
|
|
||||||
for (String extension : extensions)
|
for (String extension : extensions)
|
||||||
{
|
{
|
||||||
if (path.toLowerCase().endsWith(extension))
|
if (path.toLowerCase().endsWith(extension))
|
||||||
@@ -268,10 +262,8 @@ final class Locator
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
||||||
{
|
{
|
||||||
for (String extension : extensions)
|
for (String extension : extensions)
|
||||||
@@ -284,12 +276,10 @@ final class Locator
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
urls = new URL[matches.length];
|
urls = new URL[matches.length];
|
||||||
|
|
||||||
for (int i = 0; i < matches.length; ++i)
|
for (int i = 0; i < matches.length; ++i)
|
||||||
{
|
{
|
||||||
urls[i] = matches[i].toURI().toURL();
|
urls[i] = matches[i].toURI().toURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -32,6 +32,7 @@ import javax.swing.border.LineBorder;
|
|||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.gameserver.GameServer;
|
import com.l2jmobius.gameserver.GameServer;
|
||||||
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
||||||
|
import com.l2jmobius.gameserver.util.Locator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.l2jmobius.gameserver.ui;
|
package com.l2jmobius.gameserver.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
@@ -24,41 +24,45 @@ import java.text.CharacterIterator;
|
|||||||
import java.text.StringCharacterIterator;
|
import java.text.StringCharacterIterator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
final class Locator
|
/**
|
||||||
|
* The Locator is a utility class which is used to find certain items in the environment.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public final class Locator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor for Locator.
|
* Not instantiable
|
||||||
*/
|
*/
|
||||||
private Locator()
|
private Locator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getClassSource.
|
* Find the directory or jar file the class has been loaded from.
|
||||||
* @param c Class<?>
|
* @param c the class whose location is required.
|
||||||
* @return File
|
* @return the file or jar with the class or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
*/
|
*/
|
||||||
static File getClassSource(Class<?> c)
|
public static File getClassSource(Class<?> c)
|
||||||
{
|
{
|
||||||
String classResource = c.getName().replace('.', '/') + ".class";
|
String classResource = c.getName().replace('.', '/') + ".class";
|
||||||
return getResourceSource(c.getClassLoader(), classResource);
|
return getResourceSource(c.getClassLoader(), classResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getResourceSource.
|
* Find the directory or jar a given resource has been loaded from.
|
||||||
* @param c ClassLoader
|
* @param c the classloader to be consulted for the source.
|
||||||
* @param resource String
|
* @param resource the resource whose location is required.
|
||||||
* @return File
|
* @return the file with the resource source or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
*/
|
*/
|
||||||
private static File getResourceSource(ClassLoader c, String resource)
|
public static File getResourceSource(ClassLoader c, String resource)
|
||||||
{
|
{
|
||||||
if (c == null)
|
if (c == null)
|
||||||
{
|
{
|
||||||
c = Locator.class.getClassLoader();
|
c = Locator.class.getClassLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
URL url = null;
|
URL url = null;
|
||||||
|
|
||||||
if (c == null)
|
if (c == null)
|
||||||
{
|
{
|
||||||
url = ClassLoader.getSystemResource(resource);
|
url = ClassLoader.getSystemResource(resource);
|
||||||
@@ -67,11 +71,9 @@ final class Locator
|
|||||||
{
|
{
|
||||||
url = c.getResource(resource);
|
url = c.getResource(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url != null)
|
if (url != null)
|
||||||
{
|
{
|
||||||
String u = url.toString();
|
String u = url.toString();
|
||||||
|
|
||||||
if (u.startsWith("jar:file:"))
|
if (u.startsWith("jar:file:"))
|
||||||
{
|
{
|
||||||
int pling = u.indexOf("!");
|
int pling = u.indexOf("!");
|
||||||
@@ -85,58 +87,59 @@ final class Locator
|
|||||||
return new File(fromURI(dirName));
|
return new File(fromURI(dirName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method fromURI.
|
* Constructs a file path from a <code>file:</code> URI.
|
||||||
* @param uri String
|
* <p>
|
||||||
* @return String
|
* Will be an absolute path if the given URI is absolute.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Swallows '%' that are not followed by two characters, doesn't deal with non-ASCII characters.
|
||||||
|
* </p>
|
||||||
|
* @param uri the URI designating a file in the local filesystem.
|
||||||
|
* @return the local file system path for the file.
|
||||||
|
* @since Ant 1.6
|
||||||
*/
|
*/
|
||||||
private static String fromURI(String uri)
|
public static String fromURI(String uri)
|
||||||
{
|
{
|
||||||
URL url = null;
|
URL url = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
url = new URL(uri);
|
url = new URL(uri);
|
||||||
}
|
}
|
||||||
catch (MalformedURLException emYouEarlEx)
|
catch (MalformedURLException emYouEarlEx)
|
||||||
{
|
{
|
||||||
// empty catch clause
|
// Ignore malformed exception
|
||||||
}
|
}
|
||||||
|
if ((url == null) || !("file".equals(url.getProtocol())))
|
||||||
if ((url == null) || !"file".equals(url.getProtocol()))
|
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
||||||
}
|
}
|
||||||
|
StringBuffer buf = new StringBuffer(url.getHost());
|
||||||
StringBuilder buf = new StringBuilder(url.getHost());
|
|
||||||
|
|
||||||
if (buf.length() > 0)
|
if (buf.length() > 0)
|
||||||
{
|
{
|
||||||
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
String file = url.getFile();
|
String file = url.getFile();
|
||||||
int queryPos = file.indexOf('?');
|
int queryPos = file.indexOf('?');
|
||||||
buf.append(queryPos < 0 ? file : file.substring(0, queryPos));
|
buf.append((queryPos < 0) ? file : file.substring(0, queryPos));
|
||||||
|
|
||||||
uri = buf.toString().replace('/', File.separatorChar);
|
uri = buf.toString().replace('/', File.separatorChar);
|
||||||
|
|
||||||
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
||||||
{
|
{
|
||||||
uri = uri.substring(1);
|
uri = uri.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = decodeUri(uri);
|
String path = decodeUri(uri);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method decodeUri.
|
* Decodes an Uri with % characters.
|
||||||
* @param uri String
|
* @param uri String with the uri possibly containing % characters.
|
||||||
* @return String
|
* @return The decoded Uri
|
||||||
*/
|
*/
|
||||||
private static String decodeUri(String uri)
|
private static String decodeUri(String uri)
|
||||||
{
|
{
|
||||||
@@ -144,21 +147,17 @@ final class Locator
|
|||||||
{
|
{
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
CharacterIterator iter = new StringCharacterIterator(uri);
|
CharacterIterator iter = new StringCharacterIterator(uri);
|
||||||
|
|
||||||
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
||||||
{
|
{
|
||||||
if (c == '%')
|
if (c == '%')
|
||||||
{
|
{
|
||||||
char c1 = iter.next();
|
char c1 = iter.next();
|
||||||
|
|
||||||
if (c1 != CharacterIterator.DONE)
|
if (c1 != CharacterIterator.DONE)
|
||||||
{
|
{
|
||||||
int i1 = Character.digit(c1, 16);
|
int i1 = Character.digit(c1, 16);
|
||||||
char c2 = iter.next();
|
char c2 = iter.next();
|
||||||
|
|
||||||
if (c2 != CharacterIterator.DONE)
|
if (c2 != CharacterIterator.DONE)
|
||||||
{
|
{
|
||||||
int i2 = Character.digit(c2, 16);
|
int i2 = Character.digit(c2, 16);
|
||||||
@@ -171,21 +170,21 @@ final class Locator
|
|||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = sb.toString();
|
String path = sb.toString();
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getToolsJar.
|
* Get the File necessary to load the Sun compiler tools. If the classes are available to this class, then no additional URL is required and null is returned. This may be because the classes are explicitly in the class path or provided by the JVM directly.
|
||||||
* @return File
|
* @return the tools jar as a File if required, null otherwise.
|
||||||
*/
|
*/
|
||||||
static File getToolsJar()
|
public static File getToolsJar()
|
||||||
{
|
{
|
||||||
|
// firstly check if the tools jar is already in the classpath
|
||||||
boolean toolsJarAvailable = false;
|
boolean toolsJarAvailable = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// just check whether this throws an exception
|
||||||
Class.forName("com.sun.tools.javac.Main");
|
Class.forName("com.sun.tools.javac.Main");
|
||||||
toolsJarAvailable = true;
|
toolsJarAvailable = true;
|
||||||
}
|
}
|
||||||
@@ -198,40 +197,36 @@ final class Locator
|
|||||||
}
|
}
|
||||||
catch (Exception e2)
|
catch (Exception e2)
|
||||||
{
|
{
|
||||||
// empty catch clause
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toolsJarAvailable)
|
if (toolsJarAvailable)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// couldn't find compiler - try to find tools.jar
|
||||||
|
// based on java.home setting
|
||||||
String javaHome = System.getProperty("java.home");
|
String javaHome = System.getProperty("java.home");
|
||||||
|
|
||||||
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
||||||
{
|
{
|
||||||
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
||||||
|
|
||||||
if (!toolsJar.exists())
|
if (!toolsJar.exists())
|
||||||
{
|
{
|
||||||
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return toolsJar;
|
return toolsJar;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getLocationURLs.
|
* Get an array of URLs representing all of the jar files in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for jar files.
|
||||||
* @param location File
|
* @param location the location to scan for Jars.
|
||||||
* @return URL[] * @throws MalformedURLException
|
* @return an array of URLs for all jars in the given location.
|
||||||
* @throws MalformedURLException
|
* @exception MalformedURLException if the URLs for the jars cannot be formed.
|
||||||
*/
|
*/
|
||||||
static URL[] getLocationURLs(File location) throws MalformedURLException
|
public static URL[] getLocationURLs(File location) throws MalformedURLException
|
||||||
{
|
{
|
||||||
return getLocationURLs(location, new String[]
|
return getLocationURLs(location, new String[]
|
||||||
{
|
{
|
||||||
@@ -240,26 +235,25 @@ final class Locator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method getLocationURLs.
|
* Get an array of URLs representing all of the files of a given set of extensions in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for matching files.
|
||||||
* @param location File
|
* @param location the location to scan for files.
|
||||||
* @param extensions String[]
|
* @param extensions an array of extension that are to match in the directory search.
|
||||||
* @return URL[] * @throws MalformedURLException
|
* @return an array of URLs of matching files.
|
||||||
* @throws MalformedURLException
|
* @exception MalformedURLException if the URLs for the files cannot be formed.
|
||||||
*/
|
*/
|
||||||
private static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
public static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
||||||
{
|
{
|
||||||
|
|
||||||
URL[] urls = new URL[0];
|
URL[] urls = new URL[0];
|
||||||
|
|
||||||
if (!location.exists())
|
if (!location.exists())
|
||||||
{
|
{
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!location.isDirectory())
|
if (!location.isDirectory())
|
||||||
{
|
{
|
||||||
urls = new URL[1];
|
urls = new URL[1];
|
||||||
String path = location.getPath();
|
String path = location.getPath();
|
||||||
|
|
||||||
for (String extension : extensions)
|
for (String extension : extensions)
|
||||||
{
|
{
|
||||||
if (path.toLowerCase().endsWith(extension))
|
if (path.toLowerCase().endsWith(extension))
|
||||||
@@ -268,10 +262,8 @@ final class Locator
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
||||||
{
|
{
|
||||||
for (String extension : extensions)
|
for (String extension : extensions)
|
||||||
@@ -284,12 +276,10 @@ final class Locator
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
urls = new URL[matches.length];
|
urls = new URL[matches.length];
|
||||||
|
|
||||||
for (int i = 0; i < matches.length; ++i)
|
for (int i = 0; i < matches.length; ++i)
|
||||||
{
|
{
|
||||||
urls[i] = matches[i].toURI().toURL();
|
urls[i] = matches[i].toURI().toURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,295 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the L2J Mobius project.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package com.l2jmobius.gameserver.ui;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FilenameFilter;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.text.CharacterIterator;
|
|
||||||
import java.text.StringCharacterIterator;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
final class Locator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Constructor for Locator.
|
|
||||||
*/
|
|
||||||
private Locator()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getClassSource.
|
|
||||||
* @param c Class<?>
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
static File getClassSource(Class<?> c)
|
|
||||||
{
|
|
||||||
String classResource = c.getName().replace('.', '/') + ".class";
|
|
||||||
return getResourceSource(c.getClassLoader(), classResource);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getResourceSource.
|
|
||||||
* @param c ClassLoader
|
|
||||||
* @param resource String
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
private static File getResourceSource(ClassLoader c, String resource)
|
|
||||||
{
|
|
||||||
if (c == null)
|
|
||||||
{
|
|
||||||
c = Locator.class.getClassLoader();
|
|
||||||
}
|
|
||||||
|
|
||||||
URL url = null;
|
|
||||||
|
|
||||||
if (c == null)
|
|
||||||
{
|
|
||||||
url = ClassLoader.getSystemResource(resource);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
url = c.getResource(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url != null)
|
|
||||||
{
|
|
||||||
String u = url.toString();
|
|
||||||
|
|
||||||
if (u.startsWith("jar:file:"))
|
|
||||||
{
|
|
||||||
int pling = u.indexOf("!");
|
|
||||||
String jarName = u.substring(4, pling);
|
|
||||||
return new File(fromURI(jarName));
|
|
||||||
}
|
|
||||||
else if (u.startsWith("file:"))
|
|
||||||
{
|
|
||||||
int tail = u.indexOf(resource);
|
|
||||||
String dirName = u.substring(0, tail);
|
|
||||||
return new File(fromURI(dirName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method fromURI.
|
|
||||||
* @param uri String
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
private static String fromURI(String uri)
|
|
||||||
{
|
|
||||||
URL url = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
url = new URL(uri);
|
|
||||||
}
|
|
||||||
catch (MalformedURLException emYouEarlEx)
|
|
||||||
{
|
|
||||||
// empty catch clause
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((url == null) || !"file".equals(url.getProtocol()))
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder(url.getHost());
|
|
||||||
|
|
||||||
if (buf.length() > 0)
|
|
||||||
{
|
|
||||||
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
String file = url.getFile();
|
|
||||||
int queryPos = file.indexOf('?');
|
|
||||||
buf.append(queryPos < 0 ? file : file.substring(0, queryPos));
|
|
||||||
uri = buf.toString().replace('/', File.separatorChar);
|
|
||||||
|
|
||||||
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
|
||||||
{
|
|
||||||
uri = uri.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = decodeUri(uri);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method decodeUri.
|
|
||||||
* @param uri String
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
private static String decodeUri(String uri)
|
|
||||||
{
|
|
||||||
if (uri.indexOf('%') == -1)
|
|
||||||
{
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
CharacterIterator iter = new StringCharacterIterator(uri);
|
|
||||||
|
|
||||||
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
|
||||||
{
|
|
||||||
if (c == '%')
|
|
||||||
{
|
|
||||||
char c1 = iter.next();
|
|
||||||
|
|
||||||
if (c1 != CharacterIterator.DONE)
|
|
||||||
{
|
|
||||||
int i1 = Character.digit(c1, 16);
|
|
||||||
char c2 = iter.next();
|
|
||||||
|
|
||||||
if (c2 != CharacterIterator.DONE)
|
|
||||||
{
|
|
||||||
int i2 = Character.digit(c2, 16);
|
|
||||||
sb.append((char) ((i1 << 4) + i2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = sb.toString();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getToolsJar.
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
static File getToolsJar()
|
|
||||||
{
|
|
||||||
boolean toolsJarAvailable = false;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("com.sun.tools.javac.Main");
|
|
||||||
toolsJarAvailable = true;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("sun.tools.javac.Main");
|
|
||||||
toolsJarAvailable = true;
|
|
||||||
}
|
|
||||||
catch (Exception e2)
|
|
||||||
{
|
|
||||||
// empty catch clause
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toolsJarAvailable)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String javaHome = System.getProperty("java.home");
|
|
||||||
|
|
||||||
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
|
||||||
{
|
|
||||||
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
|
||||||
|
|
||||||
if (!toolsJar.exists())
|
|
||||||
{
|
|
||||||
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return toolsJar;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getLocationURLs.
|
|
||||||
* @param location File
|
|
||||||
* @return URL[] * @throws MalformedURLException
|
|
||||||
* @throws MalformedURLException
|
|
||||||
*/
|
|
||||||
static URL[] getLocationURLs(File location) throws MalformedURLException
|
|
||||||
{
|
|
||||||
return getLocationURLs(location, new String[]
|
|
||||||
{
|
|
||||||
".jar"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getLocationURLs.
|
|
||||||
* @param location File
|
|
||||||
* @param extensions String[]
|
|
||||||
* @return URL[] * @throws MalformedURLException
|
|
||||||
* @throws MalformedURLException
|
|
||||||
*/
|
|
||||||
private static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
|
||||||
{
|
|
||||||
URL[] urls = new URL[0];
|
|
||||||
|
|
||||||
if (!location.exists())
|
|
||||||
{
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!location.isDirectory())
|
|
||||||
{
|
|
||||||
urls = new URL[1];
|
|
||||||
String path = location.getPath();
|
|
||||||
|
|
||||||
for (String extension : extensions)
|
|
||||||
{
|
|
||||||
if (path.toLowerCase().endsWith(extension))
|
|
||||||
{
|
|
||||||
urls[0] = location.toURI().toURL();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
|
||||||
{
|
|
||||||
for (String extension : extensions)
|
|
||||||
{
|
|
||||||
if (name.toLowerCase().endsWith(extension))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
urls = new URL[matches.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < matches.length; ++i)
|
|
||||||
{
|
|
||||||
urls[i] = matches[i].toURI().toURL();
|
|
||||||
}
|
|
||||||
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -32,6 +32,7 @@ import javax.swing.border.LineBorder;
|
|||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.gameserver.GameServer;
|
import com.l2jmobius.gameserver.GameServer;
|
||||||
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
||||||
|
import com.l2jmobius.gameserver.util.Locator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
|
@@ -0,0 +1,285 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the L2J Mobius project.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jmobius.gameserver.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.text.CharacterIterator;
|
||||||
|
import java.text.StringCharacterIterator;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Locator is a utility class which is used to find certain items in the environment.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public final class Locator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Not instantiable
|
||||||
|
*/
|
||||||
|
private Locator()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the directory or jar file the class has been loaded from.
|
||||||
|
* @param c the class whose location is required.
|
||||||
|
* @return the file or jar with the class or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public static File getClassSource(Class<?> c)
|
||||||
|
{
|
||||||
|
String classResource = c.getName().replace('.', '/') + ".class";
|
||||||
|
return getResourceSource(c.getClassLoader(), classResource);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the directory or jar a given resource has been loaded from.
|
||||||
|
* @param c the classloader to be consulted for the source.
|
||||||
|
* @param resource the resource whose location is required.
|
||||||
|
* @return the file with the resource source or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public static File getResourceSource(ClassLoader c, String resource)
|
||||||
|
{
|
||||||
|
if (c == null)
|
||||||
|
{
|
||||||
|
c = Locator.class.getClassLoader();
|
||||||
|
}
|
||||||
|
URL url = null;
|
||||||
|
if (c == null)
|
||||||
|
{
|
||||||
|
url = ClassLoader.getSystemResource(resource);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
url = c.getResource(resource);
|
||||||
|
}
|
||||||
|
if (url != null)
|
||||||
|
{
|
||||||
|
String u = url.toString();
|
||||||
|
if (u.startsWith("jar:file:"))
|
||||||
|
{
|
||||||
|
int pling = u.indexOf("!");
|
||||||
|
String jarName = u.substring(4, pling);
|
||||||
|
return new File(fromURI(jarName));
|
||||||
|
}
|
||||||
|
else if (u.startsWith("file:"))
|
||||||
|
{
|
||||||
|
int tail = u.indexOf(resource);
|
||||||
|
String dirName = u.substring(0, tail);
|
||||||
|
return new File(fromURI(dirName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a file path from a <code>file:</code> URI.
|
||||||
|
* <p>
|
||||||
|
* Will be an absolute path if the given URI is absolute.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Swallows '%' that are not followed by two characters, doesn't deal with non-ASCII characters.
|
||||||
|
* </p>
|
||||||
|
* @param uri the URI designating a file in the local filesystem.
|
||||||
|
* @return the local file system path for the file.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public static String fromURI(String uri)
|
||||||
|
{
|
||||||
|
URL url = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
url = new URL(uri);
|
||||||
|
}
|
||||||
|
catch (MalformedURLException emYouEarlEx)
|
||||||
|
{
|
||||||
|
// Ignore malformed exception
|
||||||
|
}
|
||||||
|
if ((url == null) || !("file".equals(url.getProtocol())))
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
||||||
|
}
|
||||||
|
StringBuffer buf = new StringBuffer(url.getHost());
|
||||||
|
if (buf.length() > 0)
|
||||||
|
{
|
||||||
|
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
||||||
|
}
|
||||||
|
String file = url.getFile();
|
||||||
|
int queryPos = file.indexOf('?');
|
||||||
|
buf.append((queryPos < 0) ? file : file.substring(0, queryPos));
|
||||||
|
|
||||||
|
uri = buf.toString().replace('/', File.separatorChar);
|
||||||
|
|
||||||
|
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
||||||
|
{
|
||||||
|
uri = uri.substring(1);
|
||||||
|
}
|
||||||
|
String path = decodeUri(uri);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes an Uri with % characters.
|
||||||
|
* @param uri String with the uri possibly containing % characters.
|
||||||
|
* @return The decoded Uri
|
||||||
|
*/
|
||||||
|
private static String decodeUri(String uri)
|
||||||
|
{
|
||||||
|
if (uri.indexOf('%') == -1)
|
||||||
|
{
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
CharacterIterator iter = new StringCharacterIterator(uri);
|
||||||
|
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
||||||
|
{
|
||||||
|
if (c == '%')
|
||||||
|
{
|
||||||
|
char c1 = iter.next();
|
||||||
|
if (c1 != CharacterIterator.DONE)
|
||||||
|
{
|
||||||
|
int i1 = Character.digit(c1, 16);
|
||||||
|
char c2 = iter.next();
|
||||||
|
if (c2 != CharacterIterator.DONE)
|
||||||
|
{
|
||||||
|
int i2 = Character.digit(c2, 16);
|
||||||
|
sb.append((char) ((i1 << 4) + i2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String path = sb.toString();
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the File necessary to load the Sun compiler tools. If the classes are available to this class, then no additional URL is required and null is returned. This may be because the classes are explicitly in the class path or provided by the JVM directly.
|
||||||
|
* @return the tools jar as a File if required, null otherwise.
|
||||||
|
*/
|
||||||
|
public static File getToolsJar()
|
||||||
|
{
|
||||||
|
// firstly check if the tools jar is already in the classpath
|
||||||
|
boolean toolsJarAvailable = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// just check whether this throws an exception
|
||||||
|
Class.forName("com.sun.tools.javac.Main");
|
||||||
|
toolsJarAvailable = true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class.forName("sun.tools.javac.Main");
|
||||||
|
toolsJarAvailable = true;
|
||||||
|
}
|
||||||
|
catch (Exception e2)
|
||||||
|
{
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (toolsJarAvailable)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// couldn't find compiler - try to find tools.jar
|
||||||
|
// based on java.home setting
|
||||||
|
String javaHome = System.getProperty("java.home");
|
||||||
|
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
||||||
|
{
|
||||||
|
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
||||||
|
}
|
||||||
|
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
||||||
|
if (!toolsJar.exists())
|
||||||
|
{
|
||||||
|
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return toolsJar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an array of URLs representing all of the jar files in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for jar files.
|
||||||
|
* @param location the location to scan for Jars.
|
||||||
|
* @return an array of URLs for all jars in the given location.
|
||||||
|
* @exception MalformedURLException if the URLs for the jars cannot be formed.
|
||||||
|
*/
|
||||||
|
public static URL[] getLocationURLs(File location) throws MalformedURLException
|
||||||
|
{
|
||||||
|
return getLocationURLs(location, new String[]
|
||||||
|
{
|
||||||
|
".jar"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an array of URLs representing all of the files of a given set of extensions in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for matching files.
|
||||||
|
* @param location the location to scan for files.
|
||||||
|
* @param extensions an array of extension that are to match in the directory search.
|
||||||
|
* @return an array of URLs of matching files.
|
||||||
|
* @exception MalformedURLException if the URLs for the files cannot be formed.
|
||||||
|
*/
|
||||||
|
public static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
||||||
|
{
|
||||||
|
|
||||||
|
URL[] urls = new URL[0];
|
||||||
|
|
||||||
|
if (!location.exists())
|
||||||
|
{
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
if (!location.isDirectory())
|
||||||
|
{
|
||||||
|
urls = new URL[1];
|
||||||
|
String path = location.getPath();
|
||||||
|
for (String extension : extensions)
|
||||||
|
{
|
||||||
|
if (path.toLowerCase().endsWith(extension))
|
||||||
|
{
|
||||||
|
urls[0] = location.toURI().toURL();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
||||||
|
{
|
||||||
|
for (String extension : extensions)
|
||||||
|
{
|
||||||
|
if (name.toLowerCase().endsWith(extension))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
urls = new URL[matches.length];
|
||||||
|
for (int i = 0; i < matches.length; ++i)
|
||||||
|
{
|
||||||
|
urls[i] = matches[i].toURI().toURL();
|
||||||
|
}
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,295 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the L2J Mobius project.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package com.l2jmobius.gameserver.ui;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FilenameFilter;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.text.CharacterIterator;
|
|
||||||
import java.text.StringCharacterIterator;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
final class Locator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Constructor for Locator.
|
|
||||||
*/
|
|
||||||
private Locator()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getClassSource.
|
|
||||||
* @param c Class<?>
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
static File getClassSource(Class<?> c)
|
|
||||||
{
|
|
||||||
String classResource = c.getName().replace('.', '/') + ".class";
|
|
||||||
return getResourceSource(c.getClassLoader(), classResource);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getResourceSource.
|
|
||||||
* @param c ClassLoader
|
|
||||||
* @param resource String
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
private static File getResourceSource(ClassLoader c, String resource)
|
|
||||||
{
|
|
||||||
if (c == null)
|
|
||||||
{
|
|
||||||
c = Locator.class.getClassLoader();
|
|
||||||
}
|
|
||||||
|
|
||||||
URL url = null;
|
|
||||||
|
|
||||||
if (c == null)
|
|
||||||
{
|
|
||||||
url = ClassLoader.getSystemResource(resource);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
url = c.getResource(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url != null)
|
|
||||||
{
|
|
||||||
String u = url.toString();
|
|
||||||
|
|
||||||
if (u.startsWith("jar:file:"))
|
|
||||||
{
|
|
||||||
int pling = u.indexOf("!");
|
|
||||||
String jarName = u.substring(4, pling);
|
|
||||||
return new File(fromURI(jarName));
|
|
||||||
}
|
|
||||||
else if (u.startsWith("file:"))
|
|
||||||
{
|
|
||||||
int tail = u.indexOf(resource);
|
|
||||||
String dirName = u.substring(0, tail);
|
|
||||||
return new File(fromURI(dirName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method fromURI.
|
|
||||||
* @param uri String
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
private static String fromURI(String uri)
|
|
||||||
{
|
|
||||||
URL url = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
url = new URL(uri);
|
|
||||||
}
|
|
||||||
catch (MalformedURLException emYouEarlEx)
|
|
||||||
{
|
|
||||||
// empty catch clause
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((url == null) || !"file".equals(url.getProtocol()))
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder(url.getHost());
|
|
||||||
|
|
||||||
if (buf.length() > 0)
|
|
||||||
{
|
|
||||||
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
String file = url.getFile();
|
|
||||||
int queryPos = file.indexOf('?');
|
|
||||||
buf.append(queryPos < 0 ? file : file.substring(0, queryPos));
|
|
||||||
uri = buf.toString().replace('/', File.separatorChar);
|
|
||||||
|
|
||||||
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
|
||||||
{
|
|
||||||
uri = uri.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = decodeUri(uri);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method decodeUri.
|
|
||||||
* @param uri String
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
private static String decodeUri(String uri)
|
|
||||||
{
|
|
||||||
if (uri.indexOf('%') == -1)
|
|
||||||
{
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
CharacterIterator iter = new StringCharacterIterator(uri);
|
|
||||||
|
|
||||||
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
|
||||||
{
|
|
||||||
if (c == '%')
|
|
||||||
{
|
|
||||||
char c1 = iter.next();
|
|
||||||
|
|
||||||
if (c1 != CharacterIterator.DONE)
|
|
||||||
{
|
|
||||||
int i1 = Character.digit(c1, 16);
|
|
||||||
char c2 = iter.next();
|
|
||||||
|
|
||||||
if (c2 != CharacterIterator.DONE)
|
|
||||||
{
|
|
||||||
int i2 = Character.digit(c2, 16);
|
|
||||||
sb.append((char) ((i1 << 4) + i2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = sb.toString();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getToolsJar.
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
static File getToolsJar()
|
|
||||||
{
|
|
||||||
boolean toolsJarAvailable = false;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("com.sun.tools.javac.Main");
|
|
||||||
toolsJarAvailable = true;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("sun.tools.javac.Main");
|
|
||||||
toolsJarAvailable = true;
|
|
||||||
}
|
|
||||||
catch (Exception e2)
|
|
||||||
{
|
|
||||||
// empty catch clause
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toolsJarAvailable)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String javaHome = System.getProperty("java.home");
|
|
||||||
|
|
||||||
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
|
||||||
{
|
|
||||||
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
|
||||||
|
|
||||||
if (!toolsJar.exists())
|
|
||||||
{
|
|
||||||
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return toolsJar;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getLocationURLs.
|
|
||||||
* @param location File
|
|
||||||
* @return URL[] * @throws MalformedURLException
|
|
||||||
* @throws MalformedURLException
|
|
||||||
*/
|
|
||||||
static URL[] getLocationURLs(File location) throws MalformedURLException
|
|
||||||
{
|
|
||||||
return getLocationURLs(location, new String[]
|
|
||||||
{
|
|
||||||
".jar"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getLocationURLs.
|
|
||||||
* @param location File
|
|
||||||
* @param extensions String[]
|
|
||||||
* @return URL[] * @throws MalformedURLException
|
|
||||||
* @throws MalformedURLException
|
|
||||||
*/
|
|
||||||
private static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
|
||||||
{
|
|
||||||
URL[] urls = new URL[0];
|
|
||||||
|
|
||||||
if (!location.exists())
|
|
||||||
{
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!location.isDirectory())
|
|
||||||
{
|
|
||||||
urls = new URL[1];
|
|
||||||
String path = location.getPath();
|
|
||||||
|
|
||||||
for (String extension : extensions)
|
|
||||||
{
|
|
||||||
if (path.toLowerCase().endsWith(extension))
|
|
||||||
{
|
|
||||||
urls[0] = location.toURI().toURL();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
|
||||||
{
|
|
||||||
for (String extension : extensions)
|
|
||||||
{
|
|
||||||
if (name.toLowerCase().endsWith(extension))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
urls = new URL[matches.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < matches.length; ++i)
|
|
||||||
{
|
|
||||||
urls[i] = matches[i].toURI().toURL();
|
|
||||||
}
|
|
||||||
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -32,6 +32,7 @@ import javax.swing.border.LineBorder;
|
|||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.gameserver.GameServer;
|
import com.l2jmobius.gameserver.GameServer;
|
||||||
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
||||||
|
import com.l2jmobius.gameserver.util.Locator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
|
@@ -0,0 +1,285 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the L2J Mobius project.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jmobius.gameserver.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.text.CharacterIterator;
|
||||||
|
import java.text.StringCharacterIterator;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Locator is a utility class which is used to find certain items in the environment.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public final class Locator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Not instantiable
|
||||||
|
*/
|
||||||
|
private Locator()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the directory or jar file the class has been loaded from.
|
||||||
|
* @param c the class whose location is required.
|
||||||
|
* @return the file or jar with the class or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public static File getClassSource(Class<?> c)
|
||||||
|
{
|
||||||
|
String classResource = c.getName().replace('.', '/') + ".class";
|
||||||
|
return getResourceSource(c.getClassLoader(), classResource);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the directory or jar a given resource has been loaded from.
|
||||||
|
* @param c the classloader to be consulted for the source.
|
||||||
|
* @param resource the resource whose location is required.
|
||||||
|
* @return the file with the resource source or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public static File getResourceSource(ClassLoader c, String resource)
|
||||||
|
{
|
||||||
|
if (c == null)
|
||||||
|
{
|
||||||
|
c = Locator.class.getClassLoader();
|
||||||
|
}
|
||||||
|
URL url = null;
|
||||||
|
if (c == null)
|
||||||
|
{
|
||||||
|
url = ClassLoader.getSystemResource(resource);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
url = c.getResource(resource);
|
||||||
|
}
|
||||||
|
if (url != null)
|
||||||
|
{
|
||||||
|
String u = url.toString();
|
||||||
|
if (u.startsWith("jar:file:"))
|
||||||
|
{
|
||||||
|
int pling = u.indexOf("!");
|
||||||
|
String jarName = u.substring(4, pling);
|
||||||
|
return new File(fromURI(jarName));
|
||||||
|
}
|
||||||
|
else if (u.startsWith("file:"))
|
||||||
|
{
|
||||||
|
int tail = u.indexOf(resource);
|
||||||
|
String dirName = u.substring(0, tail);
|
||||||
|
return new File(fromURI(dirName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a file path from a <code>file:</code> URI.
|
||||||
|
* <p>
|
||||||
|
* Will be an absolute path if the given URI is absolute.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Swallows '%' that are not followed by two characters, doesn't deal with non-ASCII characters.
|
||||||
|
* </p>
|
||||||
|
* @param uri the URI designating a file in the local filesystem.
|
||||||
|
* @return the local file system path for the file.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public static String fromURI(String uri)
|
||||||
|
{
|
||||||
|
URL url = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
url = new URL(uri);
|
||||||
|
}
|
||||||
|
catch (MalformedURLException emYouEarlEx)
|
||||||
|
{
|
||||||
|
// Ignore malformed exception
|
||||||
|
}
|
||||||
|
if ((url == null) || !("file".equals(url.getProtocol())))
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
||||||
|
}
|
||||||
|
StringBuffer buf = new StringBuffer(url.getHost());
|
||||||
|
if (buf.length() > 0)
|
||||||
|
{
|
||||||
|
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
||||||
|
}
|
||||||
|
String file = url.getFile();
|
||||||
|
int queryPos = file.indexOf('?');
|
||||||
|
buf.append((queryPos < 0) ? file : file.substring(0, queryPos));
|
||||||
|
|
||||||
|
uri = buf.toString().replace('/', File.separatorChar);
|
||||||
|
|
||||||
|
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
||||||
|
{
|
||||||
|
uri = uri.substring(1);
|
||||||
|
}
|
||||||
|
String path = decodeUri(uri);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes an Uri with % characters.
|
||||||
|
* @param uri String with the uri possibly containing % characters.
|
||||||
|
* @return The decoded Uri
|
||||||
|
*/
|
||||||
|
private static String decodeUri(String uri)
|
||||||
|
{
|
||||||
|
if (uri.indexOf('%') == -1)
|
||||||
|
{
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
CharacterIterator iter = new StringCharacterIterator(uri);
|
||||||
|
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
||||||
|
{
|
||||||
|
if (c == '%')
|
||||||
|
{
|
||||||
|
char c1 = iter.next();
|
||||||
|
if (c1 != CharacterIterator.DONE)
|
||||||
|
{
|
||||||
|
int i1 = Character.digit(c1, 16);
|
||||||
|
char c2 = iter.next();
|
||||||
|
if (c2 != CharacterIterator.DONE)
|
||||||
|
{
|
||||||
|
int i2 = Character.digit(c2, 16);
|
||||||
|
sb.append((char) ((i1 << 4) + i2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String path = sb.toString();
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the File necessary to load the Sun compiler tools. If the classes are available to this class, then no additional URL is required and null is returned. This may be because the classes are explicitly in the class path or provided by the JVM directly.
|
||||||
|
* @return the tools jar as a File if required, null otherwise.
|
||||||
|
*/
|
||||||
|
public static File getToolsJar()
|
||||||
|
{
|
||||||
|
// firstly check if the tools jar is already in the classpath
|
||||||
|
boolean toolsJarAvailable = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// just check whether this throws an exception
|
||||||
|
Class.forName("com.sun.tools.javac.Main");
|
||||||
|
toolsJarAvailable = true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class.forName("sun.tools.javac.Main");
|
||||||
|
toolsJarAvailable = true;
|
||||||
|
}
|
||||||
|
catch (Exception e2)
|
||||||
|
{
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (toolsJarAvailable)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// couldn't find compiler - try to find tools.jar
|
||||||
|
// based on java.home setting
|
||||||
|
String javaHome = System.getProperty("java.home");
|
||||||
|
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
||||||
|
{
|
||||||
|
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
||||||
|
}
|
||||||
|
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
||||||
|
if (!toolsJar.exists())
|
||||||
|
{
|
||||||
|
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return toolsJar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an array of URLs representing all of the jar files in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for jar files.
|
||||||
|
* @param location the location to scan for Jars.
|
||||||
|
* @return an array of URLs for all jars in the given location.
|
||||||
|
* @exception MalformedURLException if the URLs for the jars cannot be formed.
|
||||||
|
*/
|
||||||
|
public static URL[] getLocationURLs(File location) throws MalformedURLException
|
||||||
|
{
|
||||||
|
return getLocationURLs(location, new String[]
|
||||||
|
{
|
||||||
|
".jar"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an array of URLs representing all of the files of a given set of extensions in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for matching files.
|
||||||
|
* @param location the location to scan for files.
|
||||||
|
* @param extensions an array of extension that are to match in the directory search.
|
||||||
|
* @return an array of URLs of matching files.
|
||||||
|
* @exception MalformedURLException if the URLs for the files cannot be formed.
|
||||||
|
*/
|
||||||
|
public static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
||||||
|
{
|
||||||
|
|
||||||
|
URL[] urls = new URL[0];
|
||||||
|
|
||||||
|
if (!location.exists())
|
||||||
|
{
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
if (!location.isDirectory())
|
||||||
|
{
|
||||||
|
urls = new URL[1];
|
||||||
|
String path = location.getPath();
|
||||||
|
for (String extension : extensions)
|
||||||
|
{
|
||||||
|
if (path.toLowerCase().endsWith(extension))
|
||||||
|
{
|
||||||
|
urls[0] = location.toURI().toURL();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
||||||
|
{
|
||||||
|
for (String extension : extensions)
|
||||||
|
{
|
||||||
|
if (name.toLowerCase().endsWith(extension))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
urls = new URL[matches.length];
|
||||||
|
for (int i = 0; i < matches.length; ++i)
|
||||||
|
{
|
||||||
|
urls[i] = matches[i].toURI().toURL();
|
||||||
|
}
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,295 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the L2J Mobius project.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package com.l2jmobius.gameserver.ui;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FilenameFilter;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.text.CharacterIterator;
|
|
||||||
import java.text.StringCharacterIterator;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
final class Locator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Constructor for Locator.
|
|
||||||
*/
|
|
||||||
private Locator()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getClassSource.
|
|
||||||
* @param c Class<?>
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
static File getClassSource(Class<?> c)
|
|
||||||
{
|
|
||||||
String classResource = c.getName().replace('.', '/') + ".class";
|
|
||||||
return getResourceSource(c.getClassLoader(), classResource);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getResourceSource.
|
|
||||||
* @param c ClassLoader
|
|
||||||
* @param resource String
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
private static File getResourceSource(ClassLoader c, String resource)
|
|
||||||
{
|
|
||||||
if (c == null)
|
|
||||||
{
|
|
||||||
c = Locator.class.getClassLoader();
|
|
||||||
}
|
|
||||||
|
|
||||||
URL url = null;
|
|
||||||
|
|
||||||
if (c == null)
|
|
||||||
{
|
|
||||||
url = ClassLoader.getSystemResource(resource);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
url = c.getResource(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url != null)
|
|
||||||
{
|
|
||||||
String u = url.toString();
|
|
||||||
|
|
||||||
if (u.startsWith("jar:file:"))
|
|
||||||
{
|
|
||||||
int pling = u.indexOf("!");
|
|
||||||
String jarName = u.substring(4, pling);
|
|
||||||
return new File(fromURI(jarName));
|
|
||||||
}
|
|
||||||
else if (u.startsWith("file:"))
|
|
||||||
{
|
|
||||||
int tail = u.indexOf(resource);
|
|
||||||
String dirName = u.substring(0, tail);
|
|
||||||
return new File(fromURI(dirName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method fromURI.
|
|
||||||
* @param uri String
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
private static String fromURI(String uri)
|
|
||||||
{
|
|
||||||
URL url = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
url = new URL(uri);
|
|
||||||
}
|
|
||||||
catch (MalformedURLException emYouEarlEx)
|
|
||||||
{
|
|
||||||
// empty catch clause
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((url == null) || !"file".equals(url.getProtocol()))
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder(url.getHost());
|
|
||||||
|
|
||||||
if (buf.length() > 0)
|
|
||||||
{
|
|
||||||
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
String file = url.getFile();
|
|
||||||
int queryPos = file.indexOf('?');
|
|
||||||
buf.append(queryPos < 0 ? file : file.substring(0, queryPos));
|
|
||||||
uri = buf.toString().replace('/', File.separatorChar);
|
|
||||||
|
|
||||||
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
|
||||||
{
|
|
||||||
uri = uri.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = decodeUri(uri);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method decodeUri.
|
|
||||||
* @param uri String
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
private static String decodeUri(String uri)
|
|
||||||
{
|
|
||||||
if (uri.indexOf('%') == -1)
|
|
||||||
{
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
CharacterIterator iter = new StringCharacterIterator(uri);
|
|
||||||
|
|
||||||
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
|
||||||
{
|
|
||||||
if (c == '%')
|
|
||||||
{
|
|
||||||
char c1 = iter.next();
|
|
||||||
|
|
||||||
if (c1 != CharacterIterator.DONE)
|
|
||||||
{
|
|
||||||
int i1 = Character.digit(c1, 16);
|
|
||||||
char c2 = iter.next();
|
|
||||||
|
|
||||||
if (c2 != CharacterIterator.DONE)
|
|
||||||
{
|
|
||||||
int i2 = Character.digit(c2, 16);
|
|
||||||
sb.append((char) ((i1 << 4) + i2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = sb.toString();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getToolsJar.
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
static File getToolsJar()
|
|
||||||
{
|
|
||||||
boolean toolsJarAvailable = false;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("com.sun.tools.javac.Main");
|
|
||||||
toolsJarAvailable = true;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("sun.tools.javac.Main");
|
|
||||||
toolsJarAvailable = true;
|
|
||||||
}
|
|
||||||
catch (Exception e2)
|
|
||||||
{
|
|
||||||
// empty catch clause
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toolsJarAvailable)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String javaHome = System.getProperty("java.home");
|
|
||||||
|
|
||||||
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
|
||||||
{
|
|
||||||
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
|
||||||
|
|
||||||
if (!toolsJar.exists())
|
|
||||||
{
|
|
||||||
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return toolsJar;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getLocationURLs.
|
|
||||||
* @param location File
|
|
||||||
* @return URL[] * @throws MalformedURLException
|
|
||||||
* @throws MalformedURLException
|
|
||||||
*/
|
|
||||||
static URL[] getLocationURLs(File location) throws MalformedURLException
|
|
||||||
{
|
|
||||||
return getLocationURLs(location, new String[]
|
|
||||||
{
|
|
||||||
".jar"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getLocationURLs.
|
|
||||||
* @param location File
|
|
||||||
* @param extensions String[]
|
|
||||||
* @return URL[] * @throws MalformedURLException
|
|
||||||
* @throws MalformedURLException
|
|
||||||
*/
|
|
||||||
private static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
|
||||||
{
|
|
||||||
URL[] urls = new URL[0];
|
|
||||||
|
|
||||||
if (!location.exists())
|
|
||||||
{
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!location.isDirectory())
|
|
||||||
{
|
|
||||||
urls = new URL[1];
|
|
||||||
String path = location.getPath();
|
|
||||||
|
|
||||||
for (String extension : extensions)
|
|
||||||
{
|
|
||||||
if (path.toLowerCase().endsWith(extension))
|
|
||||||
{
|
|
||||||
urls[0] = location.toURI().toURL();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
|
||||||
{
|
|
||||||
for (String extension : extensions)
|
|
||||||
{
|
|
||||||
if (name.toLowerCase().endsWith(extension))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
urls = new URL[matches.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < matches.length; ++i)
|
|
||||||
{
|
|
||||||
urls[i] = matches[i].toURI().toURL();
|
|
||||||
}
|
|
||||||
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -32,6 +32,7 @@ import javax.swing.border.LineBorder;
|
|||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.gameserver.GameServer;
|
import com.l2jmobius.gameserver.GameServer;
|
||||||
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
||||||
|
import com.l2jmobius.gameserver.util.Locator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
|
@@ -0,0 +1,285 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the L2J Mobius project.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jmobius.gameserver.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.text.CharacterIterator;
|
||||||
|
import java.text.StringCharacterIterator;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Locator is a utility class which is used to find certain items in the environment.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public final class Locator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Not instantiable
|
||||||
|
*/
|
||||||
|
private Locator()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the directory or jar file the class has been loaded from.
|
||||||
|
* @param c the class whose location is required.
|
||||||
|
* @return the file or jar with the class or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public static File getClassSource(Class<?> c)
|
||||||
|
{
|
||||||
|
String classResource = c.getName().replace('.', '/') + ".class";
|
||||||
|
return getResourceSource(c.getClassLoader(), classResource);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the directory or jar a given resource has been loaded from.
|
||||||
|
* @param c the classloader to be consulted for the source.
|
||||||
|
* @param resource the resource whose location is required.
|
||||||
|
* @return the file with the resource source or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public static File getResourceSource(ClassLoader c, String resource)
|
||||||
|
{
|
||||||
|
if (c == null)
|
||||||
|
{
|
||||||
|
c = Locator.class.getClassLoader();
|
||||||
|
}
|
||||||
|
URL url = null;
|
||||||
|
if (c == null)
|
||||||
|
{
|
||||||
|
url = ClassLoader.getSystemResource(resource);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
url = c.getResource(resource);
|
||||||
|
}
|
||||||
|
if (url != null)
|
||||||
|
{
|
||||||
|
String u = url.toString();
|
||||||
|
if (u.startsWith("jar:file:"))
|
||||||
|
{
|
||||||
|
int pling = u.indexOf("!");
|
||||||
|
String jarName = u.substring(4, pling);
|
||||||
|
return new File(fromURI(jarName));
|
||||||
|
}
|
||||||
|
else if (u.startsWith("file:"))
|
||||||
|
{
|
||||||
|
int tail = u.indexOf(resource);
|
||||||
|
String dirName = u.substring(0, tail);
|
||||||
|
return new File(fromURI(dirName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a file path from a <code>file:</code> URI.
|
||||||
|
* <p>
|
||||||
|
* Will be an absolute path if the given URI is absolute.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Swallows '%' that are not followed by two characters, doesn't deal with non-ASCII characters.
|
||||||
|
* </p>
|
||||||
|
* @param uri the URI designating a file in the local filesystem.
|
||||||
|
* @return the local file system path for the file.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public static String fromURI(String uri)
|
||||||
|
{
|
||||||
|
URL url = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
url = new URL(uri);
|
||||||
|
}
|
||||||
|
catch (MalformedURLException emYouEarlEx)
|
||||||
|
{
|
||||||
|
// Ignore malformed exception
|
||||||
|
}
|
||||||
|
if ((url == null) || !("file".equals(url.getProtocol())))
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
||||||
|
}
|
||||||
|
StringBuffer buf = new StringBuffer(url.getHost());
|
||||||
|
if (buf.length() > 0)
|
||||||
|
{
|
||||||
|
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
||||||
|
}
|
||||||
|
String file = url.getFile();
|
||||||
|
int queryPos = file.indexOf('?');
|
||||||
|
buf.append((queryPos < 0) ? file : file.substring(0, queryPos));
|
||||||
|
|
||||||
|
uri = buf.toString().replace('/', File.separatorChar);
|
||||||
|
|
||||||
|
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
||||||
|
{
|
||||||
|
uri = uri.substring(1);
|
||||||
|
}
|
||||||
|
String path = decodeUri(uri);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes an Uri with % characters.
|
||||||
|
* @param uri String with the uri possibly containing % characters.
|
||||||
|
* @return The decoded Uri
|
||||||
|
*/
|
||||||
|
private static String decodeUri(String uri)
|
||||||
|
{
|
||||||
|
if (uri.indexOf('%') == -1)
|
||||||
|
{
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
CharacterIterator iter = new StringCharacterIterator(uri);
|
||||||
|
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
||||||
|
{
|
||||||
|
if (c == '%')
|
||||||
|
{
|
||||||
|
char c1 = iter.next();
|
||||||
|
if (c1 != CharacterIterator.DONE)
|
||||||
|
{
|
||||||
|
int i1 = Character.digit(c1, 16);
|
||||||
|
char c2 = iter.next();
|
||||||
|
if (c2 != CharacterIterator.DONE)
|
||||||
|
{
|
||||||
|
int i2 = Character.digit(c2, 16);
|
||||||
|
sb.append((char) ((i1 << 4) + i2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String path = sb.toString();
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the File necessary to load the Sun compiler tools. If the classes are available to this class, then no additional URL is required and null is returned. This may be because the classes are explicitly in the class path or provided by the JVM directly.
|
||||||
|
* @return the tools jar as a File if required, null otherwise.
|
||||||
|
*/
|
||||||
|
public static File getToolsJar()
|
||||||
|
{
|
||||||
|
// firstly check if the tools jar is already in the classpath
|
||||||
|
boolean toolsJarAvailable = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// just check whether this throws an exception
|
||||||
|
Class.forName("com.sun.tools.javac.Main");
|
||||||
|
toolsJarAvailable = true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class.forName("sun.tools.javac.Main");
|
||||||
|
toolsJarAvailable = true;
|
||||||
|
}
|
||||||
|
catch (Exception e2)
|
||||||
|
{
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (toolsJarAvailable)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// couldn't find compiler - try to find tools.jar
|
||||||
|
// based on java.home setting
|
||||||
|
String javaHome = System.getProperty("java.home");
|
||||||
|
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
||||||
|
{
|
||||||
|
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
||||||
|
}
|
||||||
|
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
||||||
|
if (!toolsJar.exists())
|
||||||
|
{
|
||||||
|
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return toolsJar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an array of URLs representing all of the jar files in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for jar files.
|
||||||
|
* @param location the location to scan for Jars.
|
||||||
|
* @return an array of URLs for all jars in the given location.
|
||||||
|
* @exception MalformedURLException if the URLs for the jars cannot be formed.
|
||||||
|
*/
|
||||||
|
public static URL[] getLocationURLs(File location) throws MalformedURLException
|
||||||
|
{
|
||||||
|
return getLocationURLs(location, new String[]
|
||||||
|
{
|
||||||
|
".jar"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an array of URLs representing all of the files of a given set of extensions in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for matching files.
|
||||||
|
* @param location the location to scan for files.
|
||||||
|
* @param extensions an array of extension that are to match in the directory search.
|
||||||
|
* @return an array of URLs of matching files.
|
||||||
|
* @exception MalformedURLException if the URLs for the files cannot be formed.
|
||||||
|
*/
|
||||||
|
public static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
||||||
|
{
|
||||||
|
|
||||||
|
URL[] urls = new URL[0];
|
||||||
|
|
||||||
|
if (!location.exists())
|
||||||
|
{
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
if (!location.isDirectory())
|
||||||
|
{
|
||||||
|
urls = new URL[1];
|
||||||
|
String path = location.getPath();
|
||||||
|
for (String extension : extensions)
|
||||||
|
{
|
||||||
|
if (path.toLowerCase().endsWith(extension))
|
||||||
|
{
|
||||||
|
urls[0] = location.toURI().toURL();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
||||||
|
{
|
||||||
|
for (String extension : extensions)
|
||||||
|
{
|
||||||
|
if (name.toLowerCase().endsWith(extension))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
urls = new URL[matches.length];
|
||||||
|
for (int i = 0; i < matches.length; ++i)
|
||||||
|
{
|
||||||
|
urls[i] = matches[i].toURI().toURL();
|
||||||
|
}
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,295 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the L2J Mobius project.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package com.l2jmobius.gameserver.ui;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FilenameFilter;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.text.CharacterIterator;
|
|
||||||
import java.text.StringCharacterIterator;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
final class Locator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Constructor for Locator.
|
|
||||||
*/
|
|
||||||
private Locator()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getClassSource.
|
|
||||||
* @param c Class<?>
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
static File getClassSource(Class<?> c)
|
|
||||||
{
|
|
||||||
String classResource = c.getName().replace('.', '/') + ".class";
|
|
||||||
return getResourceSource(c.getClassLoader(), classResource);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getResourceSource.
|
|
||||||
* @param c ClassLoader
|
|
||||||
* @param resource String
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
private static File getResourceSource(ClassLoader c, String resource)
|
|
||||||
{
|
|
||||||
if (c == null)
|
|
||||||
{
|
|
||||||
c = Locator.class.getClassLoader();
|
|
||||||
}
|
|
||||||
|
|
||||||
URL url = null;
|
|
||||||
|
|
||||||
if (c == null)
|
|
||||||
{
|
|
||||||
url = ClassLoader.getSystemResource(resource);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
url = c.getResource(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url != null)
|
|
||||||
{
|
|
||||||
String u = url.toString();
|
|
||||||
|
|
||||||
if (u.startsWith("jar:file:"))
|
|
||||||
{
|
|
||||||
int pling = u.indexOf("!");
|
|
||||||
String jarName = u.substring(4, pling);
|
|
||||||
return new File(fromURI(jarName));
|
|
||||||
}
|
|
||||||
else if (u.startsWith("file:"))
|
|
||||||
{
|
|
||||||
int tail = u.indexOf(resource);
|
|
||||||
String dirName = u.substring(0, tail);
|
|
||||||
return new File(fromURI(dirName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method fromURI.
|
|
||||||
* @param uri String
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
private static String fromURI(String uri)
|
|
||||||
{
|
|
||||||
URL url = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
url = new URL(uri);
|
|
||||||
}
|
|
||||||
catch (MalformedURLException emYouEarlEx)
|
|
||||||
{
|
|
||||||
// empty catch clause
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((url == null) || !"file".equals(url.getProtocol()))
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder(url.getHost());
|
|
||||||
|
|
||||||
if (buf.length() > 0)
|
|
||||||
{
|
|
||||||
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
String file = url.getFile();
|
|
||||||
int queryPos = file.indexOf('?');
|
|
||||||
buf.append(queryPos < 0 ? file : file.substring(0, queryPos));
|
|
||||||
uri = buf.toString().replace('/', File.separatorChar);
|
|
||||||
|
|
||||||
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
|
||||||
{
|
|
||||||
uri = uri.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = decodeUri(uri);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method decodeUri.
|
|
||||||
* @param uri String
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
private static String decodeUri(String uri)
|
|
||||||
{
|
|
||||||
if (uri.indexOf('%') == -1)
|
|
||||||
{
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
CharacterIterator iter = new StringCharacterIterator(uri);
|
|
||||||
|
|
||||||
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
|
||||||
{
|
|
||||||
if (c == '%')
|
|
||||||
{
|
|
||||||
char c1 = iter.next();
|
|
||||||
|
|
||||||
if (c1 != CharacterIterator.DONE)
|
|
||||||
{
|
|
||||||
int i1 = Character.digit(c1, 16);
|
|
||||||
char c2 = iter.next();
|
|
||||||
|
|
||||||
if (c2 != CharacterIterator.DONE)
|
|
||||||
{
|
|
||||||
int i2 = Character.digit(c2, 16);
|
|
||||||
sb.append((char) ((i1 << 4) + i2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.append(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = sb.toString();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getToolsJar.
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
static File getToolsJar()
|
|
||||||
{
|
|
||||||
boolean toolsJarAvailable = false;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("com.sun.tools.javac.Main");
|
|
||||||
toolsJarAvailable = true;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("sun.tools.javac.Main");
|
|
||||||
toolsJarAvailable = true;
|
|
||||||
}
|
|
||||||
catch (Exception e2)
|
|
||||||
{
|
|
||||||
// empty catch clause
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toolsJarAvailable)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String javaHome = System.getProperty("java.home");
|
|
||||||
|
|
||||||
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
|
||||||
{
|
|
||||||
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
|
||||||
|
|
||||||
if (!toolsJar.exists())
|
|
||||||
{
|
|
||||||
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return toolsJar;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getLocationURLs.
|
|
||||||
* @param location File
|
|
||||||
* @return URL[] * @throws MalformedURLException
|
|
||||||
* @throws MalformedURLException
|
|
||||||
*/
|
|
||||||
static URL[] getLocationURLs(File location) throws MalformedURLException
|
|
||||||
{
|
|
||||||
return getLocationURLs(location, new String[]
|
|
||||||
{
|
|
||||||
".jar"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getLocationURLs.
|
|
||||||
* @param location File
|
|
||||||
* @param extensions String[]
|
|
||||||
* @return URL[] * @throws MalformedURLException
|
|
||||||
* @throws MalformedURLException
|
|
||||||
*/
|
|
||||||
private static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
|
||||||
{
|
|
||||||
URL[] urls = new URL[0];
|
|
||||||
|
|
||||||
if (!location.exists())
|
|
||||||
{
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!location.isDirectory())
|
|
||||||
{
|
|
||||||
urls = new URL[1];
|
|
||||||
String path = location.getPath();
|
|
||||||
|
|
||||||
for (String extension : extensions)
|
|
||||||
{
|
|
||||||
if (path.toLowerCase().endsWith(extension))
|
|
||||||
{
|
|
||||||
urls[0] = location.toURI().toURL();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
|
||||||
{
|
|
||||||
for (String extension : extensions)
|
|
||||||
{
|
|
||||||
if (name.toLowerCase().endsWith(extension))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
urls = new URL[matches.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < matches.length; ++i)
|
|
||||||
{
|
|
||||||
urls[i] = matches[i].toURI().toURL();
|
|
||||||
}
|
|
||||||
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -32,6 +32,7 @@ import javax.swing.border.LineBorder;
|
|||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.gameserver.GameServer;
|
import com.l2jmobius.gameserver.GameServer;
|
||||||
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
import com.l2jmobius.gameserver.instancemanager.PlayerCountManager;
|
||||||
|
import com.l2jmobius.gameserver.util.Locator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
|
@@ -0,0 +1,285 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the L2J Mobius project.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jmobius.gameserver.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.text.CharacterIterator;
|
||||||
|
import java.text.StringCharacterIterator;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Locator is a utility class which is used to find certain items in the environment.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public final class Locator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Not instantiable
|
||||||
|
*/
|
||||||
|
private Locator()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the directory or jar file the class has been loaded from.
|
||||||
|
* @param c the class whose location is required.
|
||||||
|
* @return the file or jar with the class or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public static File getClassSource(Class<?> c)
|
||||||
|
{
|
||||||
|
String classResource = c.getName().replace('.', '/') + ".class";
|
||||||
|
return getResourceSource(c.getClassLoader(), classResource);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the directory or jar a given resource has been loaded from.
|
||||||
|
* @param c the classloader to be consulted for the source.
|
||||||
|
* @param resource the resource whose location is required.
|
||||||
|
* @return the file with the resource source or null if we cannot determine the location.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public static File getResourceSource(ClassLoader c, String resource)
|
||||||
|
{
|
||||||
|
if (c == null)
|
||||||
|
{
|
||||||
|
c = Locator.class.getClassLoader();
|
||||||
|
}
|
||||||
|
URL url = null;
|
||||||
|
if (c == null)
|
||||||
|
{
|
||||||
|
url = ClassLoader.getSystemResource(resource);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
url = c.getResource(resource);
|
||||||
|
}
|
||||||
|
if (url != null)
|
||||||
|
{
|
||||||
|
String u = url.toString();
|
||||||
|
if (u.startsWith("jar:file:"))
|
||||||
|
{
|
||||||
|
int pling = u.indexOf("!");
|
||||||
|
String jarName = u.substring(4, pling);
|
||||||
|
return new File(fromURI(jarName));
|
||||||
|
}
|
||||||
|
else if (u.startsWith("file:"))
|
||||||
|
{
|
||||||
|
int tail = u.indexOf(resource);
|
||||||
|
String dirName = u.substring(0, tail);
|
||||||
|
return new File(fromURI(dirName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a file path from a <code>file:</code> URI.
|
||||||
|
* <p>
|
||||||
|
* Will be an absolute path if the given URI is absolute.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Swallows '%' that are not followed by two characters, doesn't deal with non-ASCII characters.
|
||||||
|
* </p>
|
||||||
|
* @param uri the URI designating a file in the local filesystem.
|
||||||
|
* @return the local file system path for the file.
|
||||||
|
* @since Ant 1.6
|
||||||
|
*/
|
||||||
|
public static String fromURI(String uri)
|
||||||
|
{
|
||||||
|
URL url = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
url = new URL(uri);
|
||||||
|
}
|
||||||
|
catch (MalformedURLException emYouEarlEx)
|
||||||
|
{
|
||||||
|
// Ignore malformed exception
|
||||||
|
}
|
||||||
|
if ((url == null) || !("file".equals(url.getProtocol())))
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Can only handle valid file: URIs");
|
||||||
|
}
|
||||||
|
StringBuffer buf = new StringBuffer(url.getHost());
|
||||||
|
if (buf.length() > 0)
|
||||||
|
{
|
||||||
|
buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
|
||||||
|
}
|
||||||
|
String file = url.getFile();
|
||||||
|
int queryPos = file.indexOf('?');
|
||||||
|
buf.append((queryPos < 0) ? file : file.substring(0, queryPos));
|
||||||
|
|
||||||
|
uri = buf.toString().replace('/', File.separatorChar);
|
||||||
|
|
||||||
|
if ((File.pathSeparatorChar == ';') && uri.startsWith("\\") && (uri.length() > 2) && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1))
|
||||||
|
{
|
||||||
|
uri = uri.substring(1);
|
||||||
|
}
|
||||||
|
String path = decodeUri(uri);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes an Uri with % characters.
|
||||||
|
* @param uri String with the uri possibly containing % characters.
|
||||||
|
* @return The decoded Uri
|
||||||
|
*/
|
||||||
|
private static String decodeUri(String uri)
|
||||||
|
{
|
||||||
|
if (uri.indexOf('%') == -1)
|
||||||
|
{
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
CharacterIterator iter = new StringCharacterIterator(uri);
|
||||||
|
for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
||||||
|
{
|
||||||
|
if (c == '%')
|
||||||
|
{
|
||||||
|
char c1 = iter.next();
|
||||||
|
if (c1 != CharacterIterator.DONE)
|
||||||
|
{
|
||||||
|
int i1 = Character.digit(c1, 16);
|
||||||
|
char c2 = iter.next();
|
||||||
|
if (c2 != CharacterIterator.DONE)
|
||||||
|
{
|
||||||
|
int i2 = Character.digit(c2, 16);
|
||||||
|
sb.append((char) ((i1 << 4) + i2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String path = sb.toString();
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the File necessary to load the Sun compiler tools. If the classes are available to this class, then no additional URL is required and null is returned. This may be because the classes are explicitly in the class path or provided by the JVM directly.
|
||||||
|
* @return the tools jar as a File if required, null otherwise.
|
||||||
|
*/
|
||||||
|
public static File getToolsJar()
|
||||||
|
{
|
||||||
|
// firstly check if the tools jar is already in the classpath
|
||||||
|
boolean toolsJarAvailable = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// just check whether this throws an exception
|
||||||
|
Class.forName("com.sun.tools.javac.Main");
|
||||||
|
toolsJarAvailable = true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class.forName("sun.tools.javac.Main");
|
||||||
|
toolsJarAvailable = true;
|
||||||
|
}
|
||||||
|
catch (Exception e2)
|
||||||
|
{
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (toolsJarAvailable)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// couldn't find compiler - try to find tools.jar
|
||||||
|
// based on java.home setting
|
||||||
|
String javaHome = System.getProperty("java.home");
|
||||||
|
if (javaHome.toLowerCase(Locale.US).endsWith("jre"))
|
||||||
|
{
|
||||||
|
javaHome = javaHome.substring(0, javaHome.length() - 4);
|
||||||
|
}
|
||||||
|
File toolsJar = new File(javaHome + "/lib/tools.jar");
|
||||||
|
if (!toolsJar.exists())
|
||||||
|
{
|
||||||
|
System.out.println("Unable to locate tools.jar. " + "Expected to find it in " + toolsJar.getPath());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return toolsJar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an array of URLs representing all of the jar files in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for jar files.
|
||||||
|
* @param location the location to scan for Jars.
|
||||||
|
* @return an array of URLs for all jars in the given location.
|
||||||
|
* @exception MalformedURLException if the URLs for the jars cannot be formed.
|
||||||
|
*/
|
||||||
|
public static URL[] getLocationURLs(File location) throws MalformedURLException
|
||||||
|
{
|
||||||
|
return getLocationURLs(location, new String[]
|
||||||
|
{
|
||||||
|
".jar"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an array of URLs representing all of the files of a given set of extensions in the given location. If the location is a file, it is returned as the only element of the array. If the location is a directory, it is scanned for matching files.
|
||||||
|
* @param location the location to scan for files.
|
||||||
|
* @param extensions an array of extension that are to match in the directory search.
|
||||||
|
* @return an array of URLs of matching files.
|
||||||
|
* @exception MalformedURLException if the URLs for the files cannot be formed.
|
||||||
|
*/
|
||||||
|
public static URL[] getLocationURLs(File location, final String[] extensions) throws MalformedURLException
|
||||||
|
{
|
||||||
|
|
||||||
|
URL[] urls = new URL[0];
|
||||||
|
|
||||||
|
if (!location.exists())
|
||||||
|
{
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
if (!location.isDirectory())
|
||||||
|
{
|
||||||
|
urls = new URL[1];
|
||||||
|
String path = location.getPath();
|
||||||
|
for (String extension : extensions)
|
||||||
|
{
|
||||||
|
if (path.toLowerCase().endsWith(extension))
|
||||||
|
{
|
||||||
|
urls[0] = location.toURI().toURL();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
File[] matches = location.listFiles((FilenameFilter) (dir, name) ->
|
||||||
|
{
|
||||||
|
for (String extension : extensions)
|
||||||
|
{
|
||||||
|
if (name.toLowerCase().endsWith(extension))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
urls = new URL[matches.length];
|
||||||
|
for (int i = 0; i < matches.length; ++i)
|
||||||
|
{
|
||||||
|
urls[i] = matches[i].toURI().toURL();
|
||||||
|
}
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user