Skip to content

Commit

Permalink
149: simply use the JavaProject API
Browse files Browse the repository at this point in the history
Task-Url: #149
  • Loading branch information
LorenzoBettini committed Jul 28, 2022
1 parent 440e0bd commit f5a399e
Showing 1 changed file with 3 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,16 @@

package org.pitest.pitclipse.launch.config;

import com.google.common.collect.ImmutableList;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.JavaRuntime;
import org.pitest.pitclipse.launch.AbstractPitLaunchDelegate;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.ImmutableList;

public class ProjectUtils {

Expand All @@ -58,30 +48,7 @@ public static boolean onClassPathOf(IJavaProject testProject, IJavaProject proje
}

public static boolean onClassPathOf(IJavaProject project, String fullyQualifiedName) throws CoreException {
String[] classPathEntries = JavaRuntime.computeDefaultRuntimeClassPath(project);
List<URL> urlList = new ArrayList<>();
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 = urlList.toArray(new URL[urlList.size()]);
try (URLClassLoader classLoader = new URLClassLoader(urls, AbstractPitLaunchDelegate.class.getClassLoader())) {
try {
classLoader.loadClass(fullyQualifiedName);
return true;
} catch (ClassNotFoundException e) {
return false;
}
} catch (IOException e1) {
throw new CoreException(Status.error("Closing the classloader", e1));
}
return project.findType(fullyQualifiedName) != null;
}

public static boolean sameProject(IJavaProject testProject, IJavaProject project) {
Expand Down

0 comments on commit f5a399e

Please sign in to comment.