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

Alternative mechanism for detecting JUnit5 #149

Closed
LorenzoBettini opened this issue Jul 14, 2021 · 2 comments · Fixed by #199
Closed

Alternative mechanism for detecting JUnit5 #149

LorenzoBettini opened this issue Jul 14, 2021 · 2 comments · Fixed by #199
Assignees
Labels
a: refactoring 📦 Rewrite a part of the software an: enhancement 📈 Improve something for: IDE 🌒 Related to the integration of Pitclipse within Eclipse IDE
Milestone

Comments

@LorenzoBettini
Copy link
Collaborator

As noted in org.pitest.pitclipse.launch.AbstractPitLaunchDelegate.isJUnit5InClasspathOf(IJavaProject) we use a naive mechanism for detecting JUnit5 on the classpath.

We could try to load some classes of the JUnit 5 engine by constructing a classloader using the classpath of the Java project.
Something like (untested)

String[] classPathEntries = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
List<URL> urlList = new ArrayList<URL>();
for (int i = 0; i < classPathEntries.length; i++) {
	String entry = classPathEntries[i];
	IPath path = new Path(entry);
	URL url;
	try {
		url = path.toFile().toURI().toURL();
		urlList.add(url);
	} catch (MalformedURLException e) {
		e.printStackTrace();
	}
}
URL[] urls = (URL[]) urlList.toArray(new URL[urlList.size()]);
URLClassLoader classLoader = new URLClassLoader(urls, parentClassLoader);
@LorenzoBettini LorenzoBettini added an: enhancement 📈 Improve something a: refactoring 📦 Rewrite a part of the software for: IDE 🌒 Related to the integration of Pitclipse within Eclipse IDE labels Jul 14, 2021
LorenzoBettini added a commit that referenced this issue Jul 28, 2022
LorenzoBettini added a commit that referenced this issue Jul 28, 2022
@LorenzoBettini
Copy link
Collaborator Author

Actually, it's much easier:

    public static boolean onClassPathOf(IJavaProject project, String fullyQualifiedName) throws CoreException {
        return project.findType(fullyQualifiedName) != null;
    }

@LorenzoBettini
Copy link
Collaborator Author

@echebbi I hope you don't mind I'm merging these PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: refactoring 📦 Rewrite a part of the software an: enhancement 📈 Improve something for: IDE 🌒 Related to the integration of Pitclipse within Eclipse IDE
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant