1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Allow test proejcts which aren't compressed in zip files. zip files aren't repository friendly, nor can they be easily examined in the IDE.

This commit is contained in:
James Blackburn 2011-01-28 12:47:25 +00:00
parent 7dd91beaf6
commit 3f7e96cb4b

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2010 Intel Corporation and others. * Copyright (c) 2004, 2011 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Intel Corporation - Initial API and implementation * Intel Corporation - Initial API and implementation
* James Blackburn (Broadcom Corp.)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.managedbuilder.testplugin; package org.eclipse.cdt.managedbuilder.testplugin;
@ -65,6 +66,8 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ui.dialogs.IOverwriteQuery; import org.eclipse.ui.dialogs.IOverwriteQuery;
import org.eclipse.ui.internal.ide.filesystem.FileSystemStructureProvider;
import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
import org.eclipse.ui.wizards.datatransfer.ImportOperation; import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider; import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
@ -229,6 +232,19 @@ public class ManagedBuildTestHelper {
} }
} }
/**
* Import a test project into the test workspace.
* Project template must be located under:
* <ul>
* <li>resources/{path}/{name}/{name}.zip</li>
* <li>resources/{path}/{name}.zip</li>
* <li>resources/{path}/{name}</li>
* </ul>
* Where name is either an expanded or zip compressed project.
* @param name - name of the project to import
* @param path - path relative to /resources
* @return IProject or throws AssertionFailedError on failure
*/
public static IProject loadProject(String name, String path) { public static IProject loadProject(String name, String path) {
IPath zipPath = new Path("resources").append(path).append(name).append(name).addFileExtension("zip"); IPath zipPath = new Path("resources").append(path).append(name).append(name).addFileExtension("zip");
File zipFile = CTestPlugin.getFileInPlugin(zipPath); File zipFile = CTestPlugin.getFileInPlugin(zipPath);
@ -236,23 +252,28 @@ public class ManagedBuildTestHelper {
zipPath = new Path("resources").append(path).append(name).addFileExtension("zip"); zipPath = new Path("resources").append(path).append(name).addFileExtension("zip");
zipFile = CTestPlugin.getFileInPlugin(zipPath); zipFile = CTestPlugin.getFileInPlugin(zipPath);
} }
// Try loading as a project directory
if (zipFile == null) { if (zipFile == null) {
Assert.fail("zip file " + zipPath.toString() + " is missing."); zipPath = new Path("resources").append(path).append(name);
return null; zipFile = CTestPlugin.getFileInPlugin(zipPath);
} }
if (zipFile == null) {
Assert.fail("zip file " + zipPath.toString() + " is missing.");
/* never get here */
return null;
}
try { try {
return createProject(name, zipFile, null, null); return createProject(name, zipFile, null, null);
} } catch(Exception e){
catch(Exception e){
Assert.fail("fail to create the project: " + e.getLocalizedMessage()); Assert.fail("fail to create the project: " + e.getLocalizedMessage());
} }
/* never get here */
return null; return null;
} }
static public IProject createProject(String projectName, File zip, IPath location, String projectTypeId) throws CoreException, InvocationTargetException, IOException { static public IProject createProject(String projectName, File importFrom, IPath location, String projectTypeId) throws CoreException, InvocationTargetException, IOException {
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
IProject project= root.getProject(projectName); IProject project= root.getProject(projectName);
if (project.exists()) if (project.exists())
@ -261,28 +282,35 @@ public class ManagedBuildTestHelper {
IPath destPath = (location != null) ? IPath destPath = (location != null) ?
location : location :
project.getFullPath(); project.getFullPath();
if (zip != null) {
importFilesFromZip(new ZipFile(zip), destPath, null); if (importFrom != null) {
IImportStructureProvider importStructure;
Object importRoot;
if (importFrom.isFile()) {
importStructure = new ZipFileStructureProvider(new ZipFile(importFrom));
importRoot = ((ZipFileStructureProvider)importStructure).getRoot();
} else {
importStructure = new FileSystemStructureProvider();
importRoot = importFrom;
} }
return createProject(projectName, location, ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID, projectTypeId);
}
static public void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException {
ZipFileStructureProvider structureProvider= new ZipFileStructureProvider(srcZipFile);
try { try {
ImportOperation op= new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, new IOverwriteQuery() { ImportOperation op= new ImportOperation(destPath, importRoot, importStructure, new IOverwriteQuery() {
public String queryOverwrite(String file) { public String queryOverwrite(String file) {
return ALL; return ALL;
} }
}); });
op.run(monitor); op.setCreateContainerStructure(false);
op.run(null);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// should not happen // should not happen
Assert.assertTrue(false); Assert.assertTrue(false);
} }
} }
return createProject(projectName, location, ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID, projectTypeId);
}
static public IProject createNewManagedProject(IProject newProjectHandle, static public IProject createNewManagedProject(IProject newProjectHandle,
final String name, final String name,
final IPath location, final IPath location,