Skip to content
This repository has been archived by the owner on Aug 29, 2019. It is now read-only.

Commit

Permalink
Allow JUnit libraries to read files from the output directory
Browse files Browse the repository at this point in the history
Without these permissions, files that can be read successfully in a main
method cannot be read in tests.
  • Loading branch information
maxg committed Jul 31, 2012
1 parent 68fcb3c commit c2bf249
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.eclipse.core.runtime.*;
import org.eclipse.debug.core.*;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate;
import org.eclipse.jdt.launching.IVMRunner;
import org.eclipse.jdt.launching.VMRunnerConfiguration;
Expand Down Expand Up @@ -42,8 +43,20 @@ public class JUnitRestrictedLaunchConfigurationDelegate extends JUnitLaunchConfi
InputStream run = new FileInputStream(Application.bundleResourcePath("config/export/security.run.policy"));
IO.copy(new InputStreamReader(run), out);

IJavaProject proj = getJavaProject(configuration);
String bin = proj.getProject().getWorkspace().getRoot().getFile(proj.getOutputLocation()).getRawLocation() + "/-";

out.println("grant codeBase \"file:" + FileLocator.toFileURL(Platform.getBundle("org.junit").getEntry("/junit.jar")).getPath() + "\" {");
out.println(" permission java.io.FilePermission \"" + bin + "\", \"read\";"); // XXX secure?
out.println("};");

out.println("grant codeBase \"file:" + FileLocator.toFileURL(Platform.getBundle("org.eclipse.jdt.junit4.runtime").getEntry("/")).getPath() + "\" {");
out.println(" permission java.io.FilePermission \"" + bin + "\", \"read\";"); // XXX secure?
out.println("};");

String junit = FileLocator.toFileURL(Platform.getBundle("org.eclipse.jdt.junit.runtime").getEntry("/")).getPath();
out.println("grant codeBase \"file:" + junit + "\" {");
out.println(" permission java.io.FilePermission \"" + bin + "\", \"read\";"); // XXX secure?
// discovering test classes
if (programArguments.contains("-testNameFile")) {
String testNameFile = (String)programArguments.get(programArguments.indexOf("-testNameFile")+1);
Expand Down

0 comments on commit c2bf249

Please sign in to comment.