Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

extra check for getResource when asserts are enabled to make sure

getting the wrong resource doesn't happen
as it would in case of using `class-loader-of`(tested)
  • Loading branch information...
commit 27e7b74205fc07691dfc24888b57032f01fcb9a8 1 parent 05eb0f7
basicsensei authored
View
49 javasrc/cljminecraft/BasePlugin.java
@@ -149,10 +149,11 @@ public BasePlugin() {
//TODO: maybe add a test to make sure this didn't change in the future
}
- public static void showClassPath(String prefix, ClassLoader cl){
+ public static String showClassPath(String prefix, ClassLoader cl){
_info("=="+prefix+"== For classloader "+cl+" ----------");
_info(getClassPath(cl));
_info("=="+prefix+"== ----END---"+cl+" ----------");
+ return "";
}
@@ -186,6 +187,52 @@ public final static String getClassPath(ClassLoader cl) {
return cp;
}
+ protected String showResources(ClassLoader cl, String file1) {
+ try {
+ Enumeration<URL> urls = cl.getResources( file1 );
+ System.out.println("all `"+file1+"` Resources: { ");
+ while (urls.hasMoreElements()) {
+ System.out.println(urls.nextElement());
+ }
+ System.out.println(" }");
+ } catch ( IOException e ) {
+ e.printStackTrace();
+ }
+ return "";
+ }
+
+ protected int count(Enumeration e) {
+ assert null != e:"you passed null, bug somewhere";
+ int count=0;
+ while(e.hasMoreElements()) {
+ count++;
+ e.nextElement();
+ }
+ return count;
+ }
+
+ @Override
+ public InputStream getResource( String fileName ) {
+ //XXX: when a file within the .jar of current plugin is needed then from within clojure or java either call this method or call
+ //clojure.lang.RT.getResource(this.getClassLoader(), fileName); where this == plugin instance
+ //or else it will get the file from cljminecraft not from memorystone, ie. file name like config.yml which exists in both in same location
+ assert isNotMoreThanOneResource(fileName):"more than 1 file with the same name was detected in classpath,"
+ +showClassPath("",getClassLoader())
+ +showResources( getClassLoader(), fileName )
+ +" PLEASE SEE ABOVE ";
+
+ return super.getResource( fileName );
+ }
+
+ protected boolean isNotMoreThanOneResource(String fileName) {
+ try {
+ return count(getClassLoader().getResources( fileName )) <= 1;
+ } catch ( IOException e ) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+
public final void severe(String msg) {
info(ChatColor.RED+"[SEVERE] "+ChatColor.RESET+msg);//because colored won't show [SEVERE] only [INFO] level msgs
}
View
9 javasrc/cljminecraft/ClojurePlugin.java
@@ -59,7 +59,6 @@ public boolean start() {
return success;
}
-
@Override
public void stop() {//called only when onEnable didn't fail (if we did the logic right)
String pluginName = getDescription().getName();
@@ -72,14 +71,6 @@ public void stop() {//called only when onEnable didn't fail (if we did the logic
}
- @Override
- public InputStream getResource( String fileName ) {
- //this is overridden only so the below comment is obvious, maybe someone could suggest another way to let coder know? of the following:
- //XXX: when a file within the .jar of current plugin is needed then from within clojure or java either call this method or call
- //clojure.lang.RT.getResource(this.getClassLoader(), fileName); where this == plugin instance
- //or else it will get the file from cljminecraft not from memorystone, ie. file name like config.yml which exists in both in same location
- return super.getResource( fileName );
- }
/*in plugin.yml of your clojure plugin which depends on cljminecraft, these are required:
*
Please sign in to comment.
Something went wrong with that request. Please try again.