类org.eclipse.ui.wizards.datatransfer.ProjectConfigurator源码实例Demo

下面列出了怎么用org.eclipse.ui.wizards.datatransfer.ProjectConfigurator的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: thym   文件: ImportTest.java
@Test
public void test() throws Exception {
	ReadableByteChannel channel = null;
	try {
		channel = Channels.newChannel(new URL("https://github.com/apache/cordova-app-hello-world/archive/master.zip").openStream()); //$NON-NLS-1$
	} catch (IOException ex) {
		Assume.assumeNoException("This test require ability to connect to Internet", ex); //$NON-NLS-1$
	}
	File outputFile = File.createTempFile("cordova-app-hello-world", ".zip"); //$NON-NLS-1$ //$NON-NLS-2$
	FileOutputStream fos = new FileOutputStream(outputFile);
	fos.getChannel().transferFrom(channel, 0, Long.MAX_VALUE);
	channel.close();
	fos.close();
	Expand expand = new Expand();
	expand.setSrc(outputFile);
	File outputDirectory = Files.createTempDirectory("cordova-app-hello-world").toFile(); //$NON-NLS-1$
	expand.setDest(outputDirectory);
	expand.execute();
	outputFile.delete();

	Set<IProject> newProjects = null;
	SmartImportJob job = new SmartImportJob(outputDirectory, Collections.EMPTY_SET, true, true);
	try {
		Map<File, List<ProjectConfigurator>> proposals = job.getImportProposals(new NullProgressMonitor());
		Assert.assertEquals("Expected only 1 project to import", 1, proposals.size()); //$NON-NLS-1$
		boolean thymConfiguratorFound = false;
		for (ProjectConfigurator configurator : proposals.values().iterator().next()) {
			if (configurator instanceof CordovaProjectConfigurator) {
				thymConfiguratorFound = true;
			}
		}
		Assert.assertTrue("Cordova configurator not found while checking directory", thymConfiguratorFound); //$NON-NLS-1$
		
		// accept proposals
		job.setDirectoriesToImport(proposals.keySet());

		IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
		Set<IProject> beforeImport = new HashSet<>(Arrays.asList(wsRoot.getProjects()));
		job.run(new NullProgressMonitor());
		job.join();
		newProjects = new HashSet<>(Arrays.asList(wsRoot.getProjects()));
		newProjects.removeAll(beforeImport);
		Assert.assertEquals("Expected only 1 new project", 1, newProjects.size()); //$NON-NLS-1$
		IProject newProject = newProjects.iterator().next();
		boolean startsWith = newProject.getLocation().toFile().getAbsolutePath().startsWith(outputDirectory.toPath().toRealPath().toAbsolutePath().toString());
		Assert.assertTrue(startsWith);
		HybridProject hybridProject = HybridProject.getHybridProject(newProject);
		Assert.assertNotNull("Project not configured as hybrid", hybridProject); //$NON-NLS-1$
	} finally {
		if (newProjects != null) {
			for (IProject project : newProjects) {
				project.delete(true, true, new NullProgressMonitor());
			}
		}
	}
}
 
 类所在包
 同包方法