package aQute.launcher.plugin;

import java.io.*;

import junit.framework.*;
import aQute.bnd.build.*;
import aQute.lib.io.*;

public class ProjectLaunchImplTest extends TestCase {

	private static void reallyClean(Workspace ws) throws Exception {
		for (Project project : ws.getAllProjects()) {
			project.clean();

			File target = project.getTargetDir();
			if (target.isDirectory() && target.getParentFile() != null) {
				IO.delete(target);
			}
			File output = project.getSrcOutput().getAbsoluteFile();
			if (output.isDirectory() && output.getParentFile() != null) {
				IO.delete(output);
			}
		}
		IO.delete(ws.getFile("cnf/cache"));
	}

	public void tearDown() throws Exception {
		reallyClean(new Workspace(IO.getFile("test/ws")));
	}

	public static void testParseSystemCapabilities() throws Exception {
		Workspace ws = Workspace.getWorkspace(IO.getFile("test/ws"));
		Project project = ws.getProject("p1");
		project.getTarget().mkdirs();
		String systemCaps = null;

		try {
			ProjectLauncherImpl launcher = new ProjectLauncherImpl(project);
			launcher.prepare();

			systemCaps = launcher.getSystemCapabilities();
		}
		finally {
			project.close();
			ws.close();
		}
		assertEquals(
				"osgi.native;osgi.native.osname:List<String>=\"Win7,Windows7,Windows 7\";osgi.native.osversion:Version=6.1",
				systemCaps);
	}

	public void testCwdIsProjectBase() throws Exception {
		Workspace ws = Workspace.getWorkspace(IO.getFile("test/ws"));
		Project project = ws.getProject("p1");
		assertEquals(project.getBase(), new ProjectLauncherImpl(project).getCwd());
	}
}

@@ -930,26 +930,15 @@
 ect.
-getTarget().mkdirs
+prepare
 ();%0A
@@ -1481,16 +1481,37 @@
 (%22p1%22);%0A
+%09%09project.prepare();%0A
 %09%09assert

Use project.prepare() to ensure unit tests are in good state