Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-66247] Call Index.listClassNames #52

Merged
merged 6 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.kohsuke.accmod.impl;

import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;
import org.apache.maven.plugin.logging.Log;
Expand All @@ -40,20 +39,17 @@
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.jvnet.hudson.annotation_indexer.Index;

import static org.objectweb.asm.ClassReader.SKIP_FRAMES;

Expand Down Expand Up @@ -133,13 +129,7 @@ public void check(File f) throws IOException {
* Loads all the access restrictions defined in our dependencies.
*/
private void loadAccessRestrictions() throws IOException {
for (String prefix : new String[] {"META-INF/services/annotations/", "META-INF/annotations/"}) {
final Enumeration<URL> res = dependencies.getResources(prefix + Restricted.class.getName());
while (res.hasMoreElements()) {
URL url = res.nextElement();
loadRestrictions(url.openStream(), false);
}
}
loadRestrictions(dependencies, false);
}

/**
Expand All @@ -148,12 +138,8 @@ private void loadAccessRestrictions() throws IOException {
* @param isInTheInspectedModule
* This value shows up in {@link RestrictedElement#isInTheInspectedModule()}.
*/
public void loadRestrictions(InputStream stream, final boolean isInTheInspectedModule) throws IOException {
if (stream==null) return;

BufferedReader r = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
String className;
while ((className=r.readLine())!=null) {
public void loadRestrictions(ClassLoader cl, final boolean isInTheInspectedModule) throws IOException {
for (String className : Index.listClassNames(Restricted.class, cl)) {
InputStream is = dependencies.getResourceAsStream(className.replace('.','/') + ".class");
if (is==null) {
errorListener.onWarning(null,null,"Failed to find class file for "+ className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
Expand Down Expand Up @@ -95,17 +94,11 @@ public void onWarning(Throwable t, Location loc, String msg) {
}, properties != null ? properties : new Properties(), getLog());

// If there is a restriction list in the inspected module itself, load it as well:
for (String prefix : new String[] {"META-INF/services/annotations/", "META-INF/annotations/"}) {
URL local = new URL(outputURL, prefix + Restricted.class.getName());
InputStream self = null;
try {
self = local.openStream();
getLog().debug("loaded local index " + local);
} catch (IOException e) {
getLog().debug("could not load local index " + local, e);
}
if (self!=null)
checker.loadRestrictions(self, true);
try {
checker.loadRestrictions(new URLClassLoader(new URL[] {outputURL}, ClassLoader.getSystemClassLoader().getParent()), true);
getLog().debug("loaded local index " + outputURL);
} catch (IOException e) {
getLog().debug("could not load local index " + outputURL, e);
}

// perform checks
Expand Down