Skip to content
Permalink
Browse files
Merge pull request #1725 from liorhson/JENKINS-27289-update
Contine the JENKINS-27289 ticket: update the getResources as well
  • Loading branch information
jglick committed Jun 16, 2015
2 parents a013c03 + dc23c11 commit f3f8abd36bdd60d2d85c9cd5a9f2555640dd53a1
Showing with 19 additions and 4 deletions.
  1. +19 −4 core/src/main/java/hudson/util/MaskingClassLoader.java
@@ -23,11 +23,14 @@
*/
package hudson.util;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Enumeration;
import java.util.Collections;

/**
* {@link ClassLoader} that masks a specified set of classes
@@ -74,18 +77,30 @@ public MaskingClassLoader(ClassLoader parent, Collection<String> masks) {

@Override
public synchronized URL getResource(String name) {
for (String mask : masksResources) {
if(name.startsWith(mask))
return null;
}
if (isMasked(name)) return null;

return super.getResource(name);
}

@Override
public Enumeration<URL> getResources(String name) throws IOException {
if (isMasked(name)) return Collections.emptyEnumeration();

return super.getResources(name);
}

public synchronized void add(String prefix) {
masksClasses.add(prefix);
if(prefix !=null){
masksResources.add(prefix.replace(".","/"));
}
}

private boolean isMasked(String name) {
for (String mask : masksResources) {
if(name.startsWith(mask))
return true;
}
return false;
}
}

0 comments on commit f3f8abd

Please sign in to comment.