mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
Add Autotools test for bug 434275
- add a way to create a linked folder in utilities class - add new test for virtual folder - fix markExecutable to handle linked resources when they exist Change-Id: I88f800f6f4e4f50e754ea0190f558852825bc498 Reviewed-on: https://git.eclipse.org/r/30769 Tested-by: Hudson CI Reviewed-by: Elena Laskavaia <elaskavaia.cdt@gmail.com>
This commit is contained in:
parent
2a3246fa84
commit
3b458e99b5
3 changed files with 212 additions and 1 deletions
|
@ -27,6 +27,7 @@ public class AllAutotoolsTests {
|
|||
suite.addTestSuite(AutotoolsProjectNatureTest.class);
|
||||
suite.addTestSuite(AutotoolsProjectTest1.class);
|
||||
suite.addTestSuite(AutotoolsProjectTest2.class);
|
||||
suite.addTestSuite(AutotoolsVirtualFolderTest.class);
|
||||
suite.addTestSuite(UpdateConfigureTest.class);
|
||||
suite.addTest(AutoconfTests.suite());
|
||||
suite.addTest(EditorTests.suite());
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008, 2012 Red Hat Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Red Hat Incorporated - initial API and implementation
|
||||
* Marc-Andre Laperle - Fix failing test on Windows
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.autotools.tests;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.autotools.core.AutotoolsNewProjectNature;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.URIUtil;
|
||||
|
||||
// This test verifies using Autotools with a linked folder.
|
||||
public class AutotoolsVirtualFolderTest extends TestCase {
|
||||
|
||||
private IProject testProject;
|
||||
|
||||
/*
|
||||
* @see TestCase#setUp()
|
||||
*/
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
if (!ProjectTools.setup())
|
||||
fail("could not perform basic project workspace setup");
|
||||
testProject = ProjectTools.createProject("testProjectVirtualFolder");
|
||||
if (testProject == null) {
|
||||
fail("Unable to create test project");
|
||||
}
|
||||
testProject.open(new NullProgressMonitor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test sample project with a virtual folder that points to configure scripts.
|
||||
* Tests Bug 434275 - Autotools configuration in subfolder not found
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testAutotoolsVirtualFolder() throws Exception {
|
||||
Path p = new Path("zip/project2.zip");
|
||||
IWorkspaceRoot root = ProjectTools.getWorkspaceRoot();
|
||||
IPath rootPath = root.getLocation();
|
||||
IPath configPath = rootPath.append("config");
|
||||
File configDir = configPath.toFile();
|
||||
configDir.deleteOnExit();
|
||||
assertTrue(configDir.mkdir());
|
||||
ProjectTools.createLinkedFolder(testProject, "src", URIUtil.append(root.getLocationURI(), "config"));
|
||||
ProjectTools.addSourceContainerWithImport(testProject, "src", p, null);
|
||||
assertTrue(testProject.hasNature(AutotoolsNewProjectNature.AUTOTOOLS_NATURE_ID));
|
||||
assertTrue(exists("src/ChangeLog"));
|
||||
ProjectTools.setConfigDir(testProject, "src");
|
||||
ProjectTools.markExecutable(testProject, "src/autogen.sh");
|
||||
assertFalse(exists("src/configure"));
|
||||
assertFalse(exists("src/Makefile.in"));
|
||||
assertFalse(exists("src/sample/Makefile.in"));
|
||||
assertFalse(exists("src/aclocal.m4"));
|
||||
assertTrue(ProjectTools.build());
|
||||
assertTrue(exists("src/configure"));
|
||||
assertTrue(exists("src/Makefile.in"));
|
||||
assertTrue(exists("src/sample/Makefile.in"));
|
||||
assertTrue(exists("src/aclocal.m4"));
|
||||
assertTrue(exists("config.status"));
|
||||
assertTrue(exists("Makefile"));
|
||||
String extension = Platform.getOS().equals(Platform.OS_WIN32) ? ".exe" : "";
|
||||
assertTrue(exists("sample/a.out" + extension));
|
||||
assertTrue(exists("sample/Makefile"));
|
||||
}
|
||||
|
||||
private boolean exists(String path) {
|
||||
return testProject.exists(new Path(path));
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
try {
|
||||
testProject.delete(true, true, null);
|
||||
} catch (Exception e) {
|
||||
//FIXME: Why does a ResourceException occur when deleting the project??
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URI;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
|
@ -36,13 +37,18 @@ import org.eclipse.core.runtime.FileLocator;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.actions.WorkspaceModifyOperation;
|
||||
import org.eclipse.ui.dialogs.IOverwriteQuery;
|
||||
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
|
||||
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
|
||||
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
|
||||
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class ProjectTools {
|
||||
|
||||
static IWorkspace workspace;
|
||||
|
@ -99,6 +105,14 @@ public class ProjectTools {
|
|||
return monitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the workspace.
|
||||
* @return The workspace
|
||||
*/
|
||||
public static IWorkspaceRoot getWorkspaceRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a specified file in a project as executable.
|
||||
* @param project The project that the file is found in
|
||||
|
@ -114,9 +128,18 @@ public class ProjectTools {
|
|||
launcher.showCommand(true);
|
||||
IPath commandPath = new Path("chmod");
|
||||
IPath runPath = project.getLocation().append(filePath).removeLastSegments(1);
|
||||
// if the path points to an actual object, use its resource to get its run path location
|
||||
// which will handle any linked directories
|
||||
if (project.findMember(filePath) != null)
|
||||
runPath = project.findMember(filePath).getLocation().removeLastSegments(1);
|
||||
String[] args = new String[2];
|
||||
args[0] = "+x";
|
||||
args[1] = project.getLocation().append(filePath).toOSString();
|
||||
// if the path points to an actual object, use its resource to get its location
|
||||
// which will handle any linked directories
|
||||
if (project.findMember(filePath) != null)
|
||||
args[1] = project.findMember(filePath).getLocation().toOSString();
|
||||
else // otherwise, just append to project location
|
||||
args[1] = project.getLocation().append(filePath).toOSString();
|
||||
try {
|
||||
Process proc = launcher.execute(commandPath, args, new String[0],
|
||||
runPath, new NullProgressMonitor());
|
||||
|
@ -424,4 +447,95 @@ public class ProjectTools {
|
|||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a virtual folder for a project
|
||||
* @param project The project
|
||||
* @param path Folder path
|
||||
* @return the virtual folder
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static IContainer createVirtualFolder(IProject project, IPath path) throws CoreException {
|
||||
int segmentCount = path.segmentCount();
|
||||
IContainer currentFolder = project;
|
||||
|
||||
for (int i = 0; i < segmentCount; i++) {
|
||||
currentFolder = currentFolder.getFolder(new Path(path.segment(i)));
|
||||
if (!currentFolder.exists()) {
|
||||
((IFolder) currentFolder).create(IResource.VIRTUAL
|
||||
| IResource.DERIVED, true, new NullProgressMonitor());
|
||||
}
|
||||
}
|
||||
return currentFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a linked resource for a project
|
||||
* @param project The project
|
||||
* @param folderName Name of the linked folder in the project
|
||||
* @param path The URI of the real file/folder
|
||||
*
|
||||
* @return
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static IContainer createLinkedFolder(IProject project, IPath projectPath, IPath realPath) throws CoreException {
|
||||
int segmentCount = projectPath.segmentCount() - 1;
|
||||
IContainer currentFolder = project;
|
||||
|
||||
for (int i = 0; i < segmentCount; i++) {
|
||||
currentFolder = currentFolder.getFolder(new Path(projectPath.segment(i)));
|
||||
if (!currentFolder.exists()) {
|
||||
((IFolder) currentFolder).create(IResource.DERIVED | IResource.VIRTUAL, true, new NullProgressMonitor());
|
||||
}
|
||||
}
|
||||
IFolder folder = currentFolder.getFolder(new Path(projectPath.lastSegment()));
|
||||
if (!folder.isLinked()) {
|
||||
((IFolder)folder).createLink(realPath, 0, null);
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a linked folder for a project
|
||||
* @param project The project
|
||||
* @param folderName Name of the linked folder in the project
|
||||
* @param path The URI of the real file/folder
|
||||
*
|
||||
* @return
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static IFolder createLinkedFolder(IProject project, String folderName, final URI linkTarget) throws Exception {
|
||||
final IFolder folderHandle = root.getFolder(project.getFullPath().append(folderName));
|
||||
|
||||
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
|
||||
public void execute(IProgressMonitor monitor) throws CoreException {
|
||||
try {
|
||||
monitor
|
||||
.beginTask(
|
||||
IDEWorkbenchMessages.NewFolderDialog_progress,
|
||||
2000);
|
||||
if (monitor.isCanceled()) {
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
folderHandle.createLink(linkTarget,
|
||||
IResource.ALLOW_MISSING_LOCAL, monitor);
|
||||
if (monitor.isCanceled()) {
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
} finally {
|
||||
monitor.done();
|
||||
}
|
||||
}
|
||||
};
|
||||
try {
|
||||
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(
|
||||
operation);
|
||||
} catch (InterruptedException exception) {
|
||||
return null;
|
||||
} catch (InvocationTargetException exception) {
|
||||
throw exception;
|
||||
}
|
||||
return folderHandle;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue