Skip to content

Commit

Permalink
Merge pull request #1725 from liorhson/JENKINS-27289-update
Browse files Browse the repository at this point in the history
Contine the JENKINS-27289 ticket: update the getResources as well
  • Loading branch information
jglick committed Jun 16, 2015
2 parents a013c03 + dc23c11 commit f3f8abd
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions core/src/main/java/hudson/util/MaskingClassLoader.java
Expand Up @@ -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
Expand Down Expand Up @@ -74,18 +77,30 @@ protected synchronized Class<?> loadClass(String name, boolean resolve) throws C

@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.