Index: build.properties =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.core.tests/build.properties,v retrieving revision 1.1 diff -u -r1.1 build.properties --- build.properties 10 Dec 2004 17:38:27 -0000 1.1 +++ build.properties 18 May 2005 20:43:46 -0000 @@ -3,3 +3,10 @@ bin.includes = plugin.xml,\ tests.jar,\ resources/ +src.includes = .classpath,\ + .project,\ + ChangeLog,\ + build.properties,\ + plugin.xml,\ + resources/,\ + src/ Index: plugin.xml =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.core.tests/plugin.xml,v retrieving revision 1.1 diff -u -r1.1 plugin.xml --- plugin.xml 10 Dec 2004 17:38:27 -0000 1.1 +++ plugin.xml 18 May 2005 20:43:46 -0000 @@ -16,7 +16,6 @@ - Index: src/org/eclipse/cdt/rpm/core/tests/AllTests.java =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.core.tests/src/org/eclipse/cdt/rpm/core/tests/AllTests.java,v retrieving revision 1.1 diff -u -r1.1 AllTests.java --- src/org/eclipse/cdt/rpm/core/tests/AllTests.java 10 Dec 2004 17:38:27 -0000 1.1 +++ src/org/eclipse/cdt/rpm/core/tests/AllTests.java 18 May 2005 20:43:46 -0000 @@ -1,5 +1,5 @@ /* - * (c) 2004 Red Hat, Inc. + * (c) 2004, 2005 Red Hat, Inc. * * This program is open source software licensed under the * Eclipse Public License ver. 1 @@ -7,6 +7,8 @@ package org.eclipse.cdt.rpm.core.tests; +import org.eclipse.cdt.rpm.core.internal.tests.RPMCoreInternalTestSuite; + import junit.framework.Test; import junit.framework.TestSuite; @@ -15,6 +17,7 @@ public static Test suite() { TestSuite suite = new TestSuite("Test for org.eclipse.cdt.rpm.core.tests"); //$JUnit-BEGIN$ + suite.addTest(RPMCoreInternalTestSuite.suite()); suite.addTest(RPMCoreTestSuite.suite()); //$JUnit-END$ return suite; Index: src/org/eclipse/cdt/rpm/core/tests/CProjectHelper.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/core/tests/CProjectHelper.java diff -N src/org/eclipse/cdt/rpm/core/tests/CProjectHelper.java --- src/org/eclipse/cdt/rpm/core/tests/CProjectHelper.java 10 Dec 2004 17:38:27 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,260 +0,0 @@ -package org.eclipse.cdt.rpm.core.tests; - -import junit.framework.Assert; - -import org.eclipse.cdt.core.CCProjectNature; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.CProjectNature; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.IArchive; -import org.eclipse.cdt.core.model.IArchiveContainer; -import org.eclipse.cdt.core.model.IBinary; -import org.eclipse.cdt.core.model.IBinaryContainer; -import org.eclipse.cdt.core.model.ICContainer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ISourceRoot; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.ui.dialogs.IOverwriteQuery; - -/** - * Helper methods to set up a ICProject. - */ -public class CProjectHelper { - - /** - * Creates a ICProject. - */ - public static ICProject createCProject(final String projectName, String binFolderName) throws CoreException { - final IWorkspace ws = ResourcesPlugin.getWorkspace(); - final IProject newProject[] = new IProject[1]; - ws.run(new IWorkspaceRunnable() { - - public void run(IProgressMonitor monitor) throws CoreException { - IWorkspaceRoot root = ws.getRoot(); - IProject project = root.getProject(projectName); - if (!project.exists()) { - project.create(null); - } else { - project.refreshLocal(IResource.DEPTH_INFINITE, null); - } - if (!project.isOpen()) { - project.open(null); - } - if (!project.hasNature(CProjectNature.C_NATURE_ID)) { - String projectId = "TestProject"; - addNatureToProject(project, CProjectNature.C_NATURE_ID, null); - CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false); - } - newProject[0] = project; - } - }, null); - - return CCorePlugin.getDefault().getCoreModel().create(newProject[0]); - } - - private static String getMessage(IStatus status) { - StringBuffer message = new StringBuffer("["); - message.append(status.getMessage()); - if (status.isMultiStatus()) { - IStatus children[] = status.getChildren(); - for( int i = 0; i < children.length; i++) { - message.append(getMessage(children[i])); - } - } - message.append("]"); - return message.toString(); - } - - public static ICProject createCCProject(final String projectName, final String binFolderName) throws CoreException { - final IWorkspace ws = ResourcesPlugin.getWorkspace(); - final ICProject newProject[] = new ICProject[1]; - ws.run(new IWorkspaceRunnable() { - - public void run(IProgressMonitor monitor) throws CoreException { - ICProject cproject = createCProject(projectName, binFolderName); - if (!cproject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) { - addNatureToProject(cproject.getProject(), CCProjectNature.CC_NATURE_ID, null); - } - newProject[0] = cproject; - } - }, null); - return newProject[0]; - } - - /** - * Removes a ICProject. - */ - public static void delete(ICProject cproject) { - try { - cproject.getProject().delete(true, true, null); - } catch (CoreException e) { - try { - Thread.sleep(1000); - } catch (InterruptedException e1) { - } finally { - try { - System.gc(); - System.runFinalization(); - cproject.getProject().delete(true, true, null); - } catch (CoreException e2) { - Assert.fail(getMessage(e2.getStatus())); - } - } - } - } - - /** - * Adds a folder container to a ICProject. - */ - public static ICContainer addCContainer(ICProject cproject, String containerName) throws CoreException { - IProject project = cproject.getProject(); - ICContainer container = null; - if (containerName == null || containerName.length() == 0) { - ICContainer[] conts = cproject.getSourceRoots(); - if (conts.length > 0) { - container = conts[0]; - } - } else { - IFolder folder = project.getFolder(containerName); - if (!folder.exists()) { - folder.create(false, true, null); - } - container = CoreModel.getDefault().create(folder); - } - return container; - } - - - /** - * Removes a folder from a ICProject. - */ - public static void removeCContainer(ICProject cproject, String containerName) throws CoreException { - IFolder folder = cproject.getProject().getFolder(containerName); - folder.delete(true, null); - } - - /** - * Attempts to find an archive with the given name in the workspace - */ - public static IArchive findArchive(ICProject testProject, String name) throws CModelException { - int x; - IArchive[] myArchives; - IArchiveContainer archCont; - /*************************************************************************************************************************** - * Since ArchiveContainer.getArchives does not wait until all the archives in the project have been parsed before returning - * the list, we have to do a sync ArchiveContainer.getChildren first to make sure we find all the archives. - */ - archCont = testProject.getArchiveContainer(); - myArchives = archCont.getArchives(); - if (myArchives.length < 1) - return (null); - for (x = 0; x < myArchives.length; x++) { - if (myArchives[x].getElementName().equals(name)) - return (myArchives[x]); - } - return (null); - } - - /** - * Attempts to find a binary with the given name in the workspace - */ - public static IBinary findBinary(ICProject testProject, String name) throws CModelException { - IBinaryContainer binCont; - int x; - IBinary[] myBinaries; - binCont = testProject.getBinaryContainer(); - myBinaries = binCont.getBinaries(); - if (myBinaries.length < 1) - return (null); - for (x = 0; x < myBinaries.length; x++) { - if (myBinaries[x].getElementName().equals(name)) - return (myBinaries[x]); - } - return (null); - } - - /** - * Attempts to find an object with the given name in the workspace - */ - public static IBinary findObject(ICProject testProject, String name) throws CModelException { - ICElement[] sourceRoots = testProject.getChildren(); - for (int i = 0; i < sourceRoots.length; i++) { - ISourceRoot root = (ISourceRoot) sourceRoots[i]; - ICElement[] myElements = root.getChildren(); - for (int x = 0; x < myElements.length; x++) { - if (myElements[x].getElementName().equals(name)) { - if (myElements[x] instanceof IBinary) { - return ((IBinary) myElements[x]); - } - } - } - } - return null; - } - - /** - * Attempts to find a TranslationUnit with the given name in the workspace - */ - public static ITranslationUnit findTranslationUnit(ICProject testProject, String name) throws CModelException { - ICElement[] sourceRoots = testProject.getChildren(); - for (int i = 0; i < sourceRoots.length; i++) { - ISourceRoot root = (ISourceRoot) sourceRoots[i]; - ICElement[] myElements = root.getChildren(); - for (int x = 0; x < myElements.length; x++) { - if (myElements[x].getElementName().equals(name)) { - if (myElements[x] instanceof ITranslationUnit) { - return ((ITranslationUnit) myElements[x]); - } - } - } - } - return null; - } - - /** - * Attempts to find an element with the given name in the workspace - */ - public static ICElement findElement(ICProject testProject, String name) throws CModelException { - ICElement[] sourceRoots = testProject.getChildren(); - for (int i = 0; i < sourceRoots.length; i++) { - ISourceRoot root = (ISourceRoot) sourceRoots[i]; - ICElement[] myElements = root.getChildren(); - for (int x = 0; x < myElements.length; x++) { - if (myElements[x].getElementName().equals(name)) { - return myElements[x]; - } - } - } - return null; - } - - private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException { - IProjectDescription description = proj.getDescription(); - String[] prevNatures = description.getNatureIds(); - String[] newNatures = new String[prevNatures.length + 1]; - System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); - newNatures[prevNatures.length] = natureId; - description.setNatureIds(newNatures); - proj.setDescription(description, monitor); - } - - private static class ImportOverwriteQuery implements IOverwriteQuery { - - public String queryOverwrite(String file) { - return ALL; - } - } -} \ No newline at end of file Index: src/org/eclipse/cdt/rpm/core/tests/RPMCoreTestSuite.java =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.core.tests/src/org/eclipse/cdt/rpm/core/tests/RPMCoreTestSuite.java,v retrieving revision 1.1 diff -u -r1.1 RPMCoreTestSuite.java --- src/org/eclipse/cdt/rpm/core/tests/RPMCoreTestSuite.java 10 Dec 2004 17:38:27 -0000 1.1 +++ src/org/eclipse/cdt/rpm/core/tests/RPMCoreTestSuite.java 18 May 2005 20:43:46 -0000 @@ -1,5 +1,5 @@ /* - * (c) 2004 Red Hat, Inc. + * (c) 2004, 2005 Red Hat, Inc. * * This program is open source software licensed under the * Eclipse Public License ver. 1 @@ -15,9 +15,8 @@ TestSuite suite = new TestSuite( "Test for org.eclipse.cdt.rpm.core.tests"); //$JUnit-BEGIN$ - suite.addTest(RPMExportTests.suite()); - suite.addTest(SRPMImportTests.suite()); - suite.addTest(SRPMExportTests.suite()); + suite.addTestSuite(RPMProjectNatureTest.class); + suite.addTestSuite(RPMProjectFactoryTest.class); //$JUnit-END$ return suite; } Index: src/org/eclipse/cdt/rpm/core/tests/RPMCoreTestsPlugin.java =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.core.tests/src/org/eclipse/cdt/rpm/core/tests/RPMCoreTestsPlugin.java,v retrieving revision 1.1 diff -u -r1.1 RPMCoreTestsPlugin.java --- src/org/eclipse/cdt/rpm/core/tests/RPMCoreTestsPlugin.java 10 Dec 2004 17:38:27 -0000 1.1 +++ src/org/eclipse/cdt/rpm/core/tests/RPMCoreTestsPlugin.java 18 May 2005 20:43:46 -0000 @@ -1,5 +1,5 @@ /* - * (c) 2004 Red Hat, Inc. + * (c) 2004, 2005 Red Hat, Inc. * * This program is open source software licensed under the * Eclipse Public License ver. 1 Index: src/org/eclipse/cdt/rpm/core/tests/RPMExportTests.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/core/tests/RPMExportTests.java diff -N src/org/eclipse/cdt/rpm/core/tests/RPMExportTests.java --- src/org/eclipse/cdt/rpm/core/tests/RPMExportTests.java 10 Dec 2004 17:38:27 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,131 +0,0 @@ -/* - * (c) 2004 Red Hat, Inc. - * - * This program is open source software licensed under the - * Eclipse Public License ver. 1 - */ -package org.eclipse.cdt.rpm.core.tests; - -import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.net.URL; - -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.rpm.core.RPMExport; -import org.eclipse.cdt.rpm.core.SRPMImport; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceDescription; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; - -import junit.framework.TestCase; -import junit.framework.TestSuite; - - -/** - * @author Jeremy Handcock - * - * This class tests the RPM plug-in's core SRPM import operation - */ -public class RPMExportTests extends TestCase { - IWorkspace workspace; - IWorkspaceRoot root; - NullProgressMonitor monitor; - String pluginRoot; - static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ - - /** - * Constructor for RPMExportTests. - * @param name - */ - public RPMExportTests(String name) { - super(name); - } - - /* - * @see TestCase#setUp() - */ - protected void setUp() throws Exception { - IWorkspaceDescription desc; - workspace = ResourcesPlugin.getWorkspace(); - root = workspace.getRoot(); - monitor = new NullProgressMonitor(); - if(workspace == null) { - fail("Workspace was not setup"); - } - if(root == null) { - fail("Workspace root was not setup"); - } - desc = workspace.getDescription(); - desc.setAutoBuilding(false); - workspace.setDescription(desc); - } - - public static TestSuite suite() { - return new TestSuite(RPMExportTests.class); - } - - public void testHelloWorldRPMExport() throws CoreException, IOException { - /* Create C project to use during the test */ - RPMExportTester("helloworld", "2", "2"); - } - - private void RPMExportTester(String name, String version, String release) - throws CoreException, IOException { - - /* Create C project to use during the test */ - ICProject testProject = CProjectHelper.createCProject(name, "none"); //$NON-NLS-1$ //$NON-NLS-2$ - if(testProject == null) { - fail("Unable to create project"); - } - - URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + - file_sep + name+"-"+version+"-"+release+".src.rpm")); - if (url == null) - fail("Unable to find resources" + file_sep + "srpms" + file_sep + - name+"-"+version+"-"+release+".src.rpm"); - - SRPMImport SRPMImport = new SRPMImport(testProject.getProject().getLocation(). - toOSString(), Platform.asLocalURL(url).getPath()); - SRPMImport.setDoAutoconf(true); - SRPMImport.setDoPatches(true); - SRPMImport.run(); - - /* Export the SRPM */ - RPMExport rpmExport = new RPMExport(testProject.getProject().getLocation().toOSString()); - // set the various properties for an RPM export - - rpmExport.setUi_ver_no(version); - rpmExport.setUi_rel_no(release); - rpmExport.setUi_spec_file(""); - - rpmExport.run(); - - File f = new File(testProject.getProject().getLocation().toOSString()); - FilenameFilter rpms = new FilenameFilter() { - public boolean accept(File dir, String name) { - return (name.endsWith(".rpm") && !name.endsWith("src.rpm")); - } - }; - - String[] files = f.list(rpms); - assertTrue("source rpms were not generated", files != null); //$NON-NLS-1$ - - - /* Clean up */ - testProject.getProject().delete(true, true, monitor); - } - - /* - * @see TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - } - -} Index: src/org/eclipse/cdt/rpm/core/tests/SRPMExportTests.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/core/tests/SRPMExportTests.java diff -N src/org/eclipse/cdt/rpm/core/tests/SRPMExportTests.java --- src/org/eclipse/cdt/rpm/core/tests/SRPMExportTests.java 10 Dec 2004 17:38:27 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,145 +0,0 @@ -/* - * (c) 2004 Red Hat, Inc. - * - * This program is open source software licensed under the - * Eclipse Public License ver. 1 - */ -package org.eclipse.cdt.rpm.core.tests; - -import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.net.URL; - -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.rpm.core.SRPMExport; -import org.eclipse.cdt.rpm.core.SRPMImport; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceDescription; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; - -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * @author Jeremy Handcock - * - * This class tests the RPM plug-in's core SRPM import operation - */ -public class SRPMExportTests extends TestCase { - IWorkspace workspace; - IWorkspaceRoot root; - NullProgressMonitor monitor; - String pluginRoot; - static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ - - /** - * Constructor for SRPMExportTests. - * @param name - */ - public SRPMExportTests(String name) { - super(name); - } - - /* - * @see TestCase#setUp() - */ - protected void setUp() throws Exception { - IWorkspaceDescription desc; - workspace = ResourcesPlugin.getWorkspace(); - root = workspace.getRoot(); - monitor = new NullProgressMonitor(); - if(workspace == null) { - fail("Workspace was not setup"); - } - if(root == null) { - fail("Workspace root was not setup"); - } - desc = workspace.getDescription(); - desc.setAutoBuilding(false); - workspace.setDescription(desc); - } - - public static TestSuite suite() { - return new TestSuite(SRPMExportTests.class); - } - - public void testHelloWorldSRPMExport() throws CoreException, IOException { - /* Create C project to use during the test */ - SRPMExportTester("helloworld", "2", "2"); - } - - private void SRPMExportTester(String name, String version, String release) - throws CoreException, IOException { - - /* Create C project to use during the test */ - ICProject testProject = CProjectHelper.createCProject(name, "none"); //$NON-NLS-1$ //$NON-NLS-2$ - if(testProject == null) { - fail("Unable to create project"); - } - - URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ - name+"-"+version+"-"+release+".src.rpm")); - if (url == null) - fail("Unable to find resources" + file_sep + "srpms" + file_sep + - name+"-"+version+"-"+release+".src.rpm"); - - SRPMImport SRPMImport; - SRPMImport = new SRPMImport(testProject.getProject().getLocation(). - toOSString(), Platform.asLocalURL(url).getPath()); - SRPMImport.setDoAutoconf(true); - SRPMImport.setDoPatches(true); - SRPMImport.run(); - /* Make sure the import was successful */ - File f = new File(testProject.getProject().getLocation().toOSString() + - file_sep + ".srpminfo"); //$NON-NLS-1$ - f.delete(); - f = new File(testProject.getProject().getLocation().toOSString() + - file_sep + "eclipse_"+name+".spec"); //$NON-NLS-1$ - f.delete(); - f = new File(testProject.getProject().getLocation().toOSString() + - file_sep + name+"-"+version+"-"+release+".src.rpm"); //$NON-NLS-1$ - f.delete(); - - /* Export the SRPM */ - SRPMExport srpmExport = new SRPMExport(testProject.getProject().getLocation().toOSString()); - // set the various properties of an RPM export - - srpmExport.setChangelog_entry(""/** Tue Sep 14 2004 -- aluchko "*/); - srpmExport.setPatch_tag(""); - - - - srpmExport.setUi_ver_no(version); - srpmExport.setUi_rel_no(release); - srpmExport.setUi_spec_file(""); - - - srpmExport.run(); - - f = new File(testProject.getProject().getLocation().toOSString()); - FilenameFilter rpms = new FilenameFilter() { - public boolean accept(File dir, String name) { - return (name.endsWith("src.rpm")); - } - }; - String[] files = f.list(rpms); - assertTrue("source rpms were not generated", files != null); //$NON-NLS-1$ - - /* Clean up */ - testProject.getProject().delete(true, true, monitor); - } - - /* - * @see TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - } - -} \ No newline at end of file Index: src/org/eclipse/cdt/rpm/core/tests/SRPMImportTests.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/core/tests/SRPMImportTests.java diff -N src/org/eclipse/cdt/rpm/core/tests/SRPMImportTests.java --- src/org/eclipse/cdt/rpm/core/tests/SRPMImportTests.java 10 Dec 2004 17:38:27 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,121 +0,0 @@ -/* - * (c) 2004 Red Hat, Inc. - * - * This program is open source software licensed under the - * Eclipse Public License ver. 1 - */ -package org.eclipse.cdt.rpm.core.tests; - -import java.io.File; -import java.io.IOException; -import java.net.URL; - -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.rpm.core.SRPMImport; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceDescription; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; - -/** - * @author Jeremy Handcock - * - * This class tests the RPM plug-in's core SRPM import operation - */ -public class SRPMImportTests extends TestCase { - IWorkspace workspace; - IWorkspaceRoot root; - NullProgressMonitor monitor; - String pluginRoot; - static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ - - /** - * Constructor for SRPMImportTests. - * @param name - */ - public SRPMImportTests(String name) { - super(name); - } - - /* - * @see TestCase#setUp() - */ - protected void setUp() throws Exception { - IWorkspaceDescription desc; - workspace = ResourcesPlugin.getWorkspace(); - root = workspace.getRoot(); - monitor = new NullProgressMonitor(); - if(workspace == null) { - fail("Workspace was not setup"); - } - if(root == null) { - fail("Workspace root was not setup"); - } - desc = workspace.getDescription(); - desc.setAutoBuilding(false); - workspace.setDescription(desc); - } - - public static TestSuite suite() { - return new TestSuite(SRPMImportTests.class); - } - - public void testHelloWorldSRPMImport() throws CoreException, IOException { - /* Create C project to use during the test */ - SRPMImportTester("helloworld", "2-2"); - } - - private void SRPMImportTester(String name, String version) - throws CoreException, IOException { - - /* Create C project to use during the test */ - ICProject testProject = CProjectHelper.createCProject(name, "none"); //$NON-NLS-1$ //$NON-NLS-2$ - if(testProject == null) { - fail("Unable to create project"); - } - - URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ - name+"-"+version+".src.rpm")); - if (url == null) - fail("Unable to find resources" + file_sep + "srpms" + file_sep + - name+"-"+version+".src.rpm"); - - /* Import the SRPM */ - SRPMImport SRPMImport; - SRPMImport = new SRPMImport( - testProject.getProject().getLocation().toOSString(), - Platform.asLocalURL(url).getPath()); - SRPMImport.setDoAutoconf(true); - SRPMImport.setDoPatches(true); - SRPMImport.run(); - - /* Make sure the import was successful */ - File f = new File(testProject.getProject().getLocation().toOSString() + - file_sep + ".srpminfo"); //$NON-NLS-1$ - assertTrue(".srpminfo not found", f != null && f.exists()); //$NON-NLS-1$ - f = new File(testProject.getProject().getLocation().toOSString() + - file_sep + "eclipse_"+name+".spec"); //$NON-NLS-1$ - assertTrue("spec not found", f != null && f.exists()); //$NON-NLS-1$ - f = new File(testProject.getProject().getLocation().toOSString() + - file_sep + name+"-"+version+".src.rpm"); //$NON-NLS-1$ - assertTrue("srpm not found", f != null && f.exists()); //$NON-NLS-1$ - - /* Clean up */ - testProject.getProject().delete(true, true, monitor); - } - - /* - * @see TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - } - -} \ No newline at end of file Index: resources/specs/helloworld.spec =================================================================== RCS file: resources/specs/helloworld.spec diff -N resources/specs/helloworld.spec --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ resources/specs/helloworld.spec 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,30 @@ +%define _unpackaged_files_terminate_build 0 +Summary: None - Eclipse-generated spec file +Name: helloworld +Version: 2 +Release: 2 +License: GPL +Group: Applications/Internet +Source: helloworld-%{version}.tar.bz2 +Requires: tar +BuildRoot: %{_tmppath}/%{name}-root +%description + +Basic spec file for rpm build in Eclipse for helloworld + +%prep +%setup -q +%build + +make + +%install rm -rf $RPM_BUILD_ROOT +%makeinstall RPM_BUILD_ROOT=$RPM_BUILD_ROOT +%clean +rm -rf $RPM_BUILD_ROOT +%files +%defattr(-,root,root) +/usr/local/bin/helloworld +%changelog +* Tue Sep 07 2004 Rick Moseley +- Original Index: src/org/eclipse/cdt/rpm/core/internal/tests/RPMCoreInternalTestSuite.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/core/internal/tests/RPMCoreInternalTestSuite.java diff -N src/org/eclipse/cdt/rpm/core/internal/tests/RPMCoreInternalTestSuite.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/rpm/core/internal/tests/RPMCoreInternalTestSuite.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,23 @@ +/* + * (c) 2005 Red Hat, Inc. + * + * This program is open source software licensed under the + * Eclipse Public License ver. 1 + */ +package org.eclipse.cdt.rpm.core.internal.tests; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class RPMCoreInternalTestSuite extends TestSuite { + + public static Test suite() { + TestSuite suite = new TestSuite( + "Test for org.eclipse.cdt.rpm.core.internal.tests"); + //$JUnit-BEGIN$ + suite.addTest(RPMProjectTest.suite()); + suite.addTest(SpecFileParserTest.suite()); + //$JUnit-END$ + return suite; + } +} Index: src/org/eclipse/cdt/rpm/core/internal/tests/RPMProjectTest.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/core/internal/tests/RPMProjectTest.java diff -N src/org/eclipse/cdt/rpm/core/internal/tests/RPMProjectTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/rpm/core/internal/tests/RPMProjectTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,301 @@ +/* + * (c) 2005 Red Hat, Inc. + * + * This program is open source software licensed under the + * Eclipse Public License ver. 1 + */ +package org.eclipse.cdt.rpm.core.internal.tests; + +import java.io.File; +import java.io.StringBufferInputStream; +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Date; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.rpm.core.IRPMConstants; +import org.eclipse.cdt.rpm.core.IRPMProject; +import org.eclipse.cdt.rpm.core.ISpecFile; +import org.eclipse.cdt.rpm.core.RPMCorePlugin; +import org.eclipse.cdt.rpm.core.RPMExportDelta; +import org.eclipse.cdt.rpm.core.RPMProjectFactory; +import org.eclipse.cdt.rpm.core.RPMProjectNature; +import org.eclipse.cdt.rpm.core.tests.RPMCoreTestsPlugin; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.QualifiedName; + +public class RPMProjectTest extends TestCase { + + IWorkspace workspace; + IWorkspaceRoot root; + NullProgressMonitor monitor; + String pluginRoot; + + final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ + private final String line_sep = System.getProperty("line.separator"); //$NON-NLS-1$ + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + IWorkspaceDescription desc; + workspace = ResourcesPlugin.getWorkspace(); + root = workspace.getRoot(); + monitor = new NullProgressMonitor(); + if(workspace == null) { + fail("Workspace was not setup"); + } + if(root == null) { + fail("Workspace root was not setup"); + } + desc = workspace.getDescription(); + desc.setAutoBuilding(false); + workspace.setDescription(desc); + } + + public static TestSuite suite() { + return new TestSuite(RPMProjectTest.class); + } + + public void testImportHelloWorld() throws Exception { + // Create a project for the test + IProject testProject = root.getProject("testHelloWorld"); + testProject.create(monitor); + testProject.open(monitor); + if(testProject == null) { + fail("Unable to create test project"); + } + + // Instantiate an RPMProject + IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); + + // Find the test SRPM and install it + URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ + "helloworld-2-2.src.rpm")); + if (url == null) { + fail("Unable to find resource" + file_sep + "srpms" + file_sep + + "helloworld-2-2.src.rpm"); + } + File foo = new File(Platform.asLocalURL(url).getPath()); + rpmProject.importSourceRPM(foo); + + // Make sure the original SRPM got copied into the workspace + IFile srpm = rpmProject.getConfiguration().getSrpmsFolder().getFile("helloworld-2-2.src.rpm"); + assertTrue(srpm.exists()); + assertNotNull(rpmProject.getProject().getPersistentProperty(new QualifiedName(RPMCorePlugin.ID, + IRPMConstants.SRPM_PROPERTY))); + + // Make sure everything got installed properly + IFile spec = rpmProject.getConfiguration().getSpecsFolder().getFile("helloworld.spec"); + assertTrue(spec.exists()); + IFile sourceBall = rpmProject.getConfiguration().getSourcesFolder().getFile("helloworld-2.tar.bz2"); + assertTrue(sourceBall.exists()); + + // Make sure we got the spec file + ISpecFile specFile = rpmProject.getSpecFile(); + assertTrue(specFile != null); + assertNotNull(rpmProject.getProject().getPersistentProperty(new QualifiedName(RPMCorePlugin.ID, + IRPMConstants.SPEC_FILE_PROPERTY))); + + // Make sure the sources got copied from BUILD to the project root + IResource[] sources = rpmProject.getConfiguration().getBuildFolder().members(); + // If there is one folder, assume it contains all the sources + if(sources.length == 1 && sources[0].getType() == IResource.FOLDER) { + IFolder foo1 = rpmProject.getProject().getFolder(sources[0].getProjectRelativePath()); + sources = foo1.members(); + } + for(int i=0; i < sources.length; i++) { + if(sources[i].getType() == IResource.FILE) { + assertTrue(testProject.getFile(sources[i].getName()).exists()); + } + else if(sources[i].getType() == IResource.FOLDER) { + assertTrue(testProject.getFolder(sources[i].getName()).exists()); + } + } + + // Make sure the checksum was stored + assertNotNull(rpmProject.getProject().getPersistentProperty(new QualifiedName(RPMCorePlugin.ID, + IRPMConstants.CHECKSUM_PROPERTY))); + + // Make sure the RPM nature was added + assertTrue(rpmProject.getProject().hasNature(RPMProjectNature.RPM_NATURE_ID)); + + // Clean up + testProject.delete(true, false, monitor); + } + + public void testBuildPrepHelloWorld() throws Exception { + // Create a project for the test + IProject testProject = root.getProject("testBuildPrepHelloWorld"); + testProject.create(monitor); + testProject.open(monitor); + if(testProject == null) { + fail("Unable to create test project"); + } + + // Instantiate an RPMProject + IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); + + // Find the test SRPM, install, and build-prep it + URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ + "helloworld-2-2.src.rpm")); + if (url == null) { + fail("Unable to find resource" + file_sep + "srpms" + file_sep + + "helloworld-2-2.src.rpm"); + } + File foo = new File(Platform.asLocalURL(url).getPath()); + rpmProject.importSourceRPM(foo); + rpmProject.buildPrep(); + + // Make sure we got everything in the build directory + IFolder builddir = rpmProject.getConfiguration().getBuildFolder(); + IFolder helloworldFolder = builddir.getFolder("helloworld-2"); + assertTrue(helloworldFolder.exists()); + + // Clean up + testProject.delete(true, false, monitor); + } + + public void testIsChangedHelloWorld() throws Exception { + // Create a project for the test + IProject testProject = root.getProject("testIsChangedHelloWorld"); + testProject.create(monitor); + testProject.open(monitor); + if(testProject == null) { + fail("Unable to create test project"); + } + + // Instantiate an RPMProject + IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); + + // Find the test SRPM and install it + URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ + "helloworld-2-2.src.rpm")); + if (url == null) { + fail("Unable to find resource" + file_sep + "srpms" + file_sep + + "helloworld-2-2.src.rpm"); + } + File foo = new File(Platform.asLocalURL(url).getPath()); + rpmProject.importSourceRPM(foo); + assertFalse(rpmProject.isChanged()); + + testProject.delete(true, false, null); + } + + public void testIsChangedHelloWorld1() throws Exception { + // Create a project for the test + IProject testProject = root.getProject("testIsChangedHelloWorld1"); + testProject.create(monitor); + testProject.open(monitor); + if(testProject == null) { + fail("Unable to create test project"); + } + + // Instantiate an RPMProject + IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); + + // Find the test SRPM and install it + URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ + "helloworld-2-2.src.rpm")); + if (url == null) { + fail("Unable to find resource" + file_sep + "srpms" + file_sep + + "helloworld-2-2.src.rpm"); + } + File foo = new File(Platform.asLocalURL(url).getPath()); + rpmProject.importSourceRPM(foo); + IFile sourceFile = rpmProject.getProject().getFile("helloworld.cpp"); + StringBufferInputStream foo1 = new StringBufferInputStream("/* */"); + sourceFile.appendContents(foo1, false, false, null); + assertTrue(rpmProject.isChanged()); + + testProject.delete(true, false, null); + } + + public void testBuildSourceRPMHelloWorld() throws Exception { + // Create a project for the test + IProject testProject = root.getProject("testBuildSourceRPMHelloWorld1"); + testProject.create(monitor); + testProject.open(monitor); + if(testProject == null) { + fail("Unable to create test project"); + } + + // Instantiate an RPMProject + IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); + + // Find the test SRPM and install it + URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ + "helloworld-2-2.src.rpm")); + if (url == null) { + fail("Unable to find resource" + file_sep + "srpms" + file_sep + + "helloworld-2-2.src.rpm"); + } + File foo = new File(Platform.asLocalURL(url).getPath()); + rpmProject.importSourceRPM(foo); + RPMExportDelta export = new RPMExportDelta(); + export.setSpecFile(rpmProject.getSpecFile().getFile()); + export.setVersion("2"); + export.setRelease("3"); + rpmProject.buildSourceRPM(export); + + IFile foo2 = rpmProject.getConfiguration().getSrpmsFolder().getFile("helloworld-2-3.src.rpm"); + assertTrue(foo2.exists()); + + testProject.delete(true, false, null); + } + + public void testBuildSourceRPMHelloWorld1() throws Exception { + // Create a project for the test + IProject testProject = root.getProject("testBuildSourceRPMHelloWorld"); + testProject.create(monitor); + testProject.open(monitor); + if(testProject == null) { + fail("Unable to create test project"); + } + + // Instantiate an RPMProject + IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); + + // Find the test SRPM and install it + URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ + "helloworld-2-2.src.rpm")); + if (url == null) { + fail("Unable to find resource" + file_sep + "srpms" + file_sep + + "helloworld-2-2.src.rpm"); + } + File foo = new File(Platform.asLocalURL(url).getPath()); + rpmProject.importSourceRPM(foo); + IFile sourceFile = rpmProject.getProject().getFile("helloworld.cpp"); + StringBufferInputStream foo1 = new StringBufferInputStream("/* */"); + sourceFile.appendContents(foo1, false, false, null); + RPMExportDelta export = new RPMExportDelta(); + export.setSpecFile(rpmProject.getSpecFile().getFile()); + export.setVersion("2"); + export.setRelease("4"); + export.setPatchName("myPatchFFFFF.patch"); + Date today = new Date(); + SimpleDateFormat df = new SimpleDateFormat("E MMM dd yyyy"); //$NON-NLS-1$ + export.setChangelogEntry("* " + df.format(today) + " Foo Bot 2-4" + line_sep + + "- Made test change" + line_sep); + rpmProject.buildSourceRPM(export); + + // Make sure patch was created + assertTrue(rpmProject.getConfiguration().getSourcesFolder().getFile(export.getPatchName()).exists()); + + IFile foo2 = rpmProject.getConfiguration().getSrpmsFolder().getFile("helloworld-2-4.src.rpm"); + assertTrue(foo2.exists()); + } +} Index: src/org/eclipse/cdt/rpm/core/internal/tests/SpecFileParserTest.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/core/internal/tests/SpecFileParserTest.java diff -N src/org/eclipse/cdt/rpm/core/internal/tests/SpecFileParserTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/rpm/core/internal/tests/SpecFileParserTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,100 @@ +/* + * (c) 2005 Red Hat, Inc. + * + * This program is open source software licensed under the + * Eclipse Public License ver. 1 + */ +package org.eclipse.cdt.rpm.core.internal.tests; + +import java.io.File; +import java.io.FileInputStream; +import java.net.URL; + +import org.eclipse.cdt.rpm.core.internal.SpecFileParser; +import org.eclipse.cdt.rpm.core.tests.RPMCoreTestsPlugin; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class SpecFileParserTest extends TestCase { + + IWorkspace workspace; + IWorkspaceRoot root; + NullProgressMonitor monitor; + String pluginRoot; + final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ + + public static TestSuite suite() { + return new TestSuite(SpecFileParserTest.class); + } + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + IWorkspaceDescription desc; + workspace = ResourcesPlugin.getWorkspace(); + root = workspace.getRoot(); + monitor = new NullProgressMonitor(); + if(workspace == null) { + fail("Workspace was not setup"); + } + if(root == null) { + fail("Workspace root was not setup"); + } + desc = workspace.getDescription(); + desc.setAutoBuilding(false); + workspace.setDescription(desc); + } + + public void testParseHelloWorld() throws Exception { + // Create a project for the test + IProject testProject = root.getProject("testHelloWorldSpec"); + testProject.create(monitor); + testProject.open(monitor); + if(testProject == null) { + fail("Unable to create test project"); + } + + // Find the spec + URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "specs" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ + "helloworld.spec")); + if (url == null) { + fail("Unable to find resource" + file_sep + "srpms" + file_sep + + "helloworld.spec"); + } + File foo = new File(Platform.asLocalURL(url).getPath()); + + // Copy the spec into workspace + IFile specFile = testProject.getFile("helloworld.spec"); + specFile.create(new FileInputStream(foo), false, null); + assertTrue(specFile.exists()); + + // Try parsing it + SpecFileParser parser = new SpecFileParser(specFile); + parser.parse(); + + // Make sure we parsed the spec correctly + String name = parser.getName(); + assertTrue(name.equals("helloworld")); + String version = parser.getVersion(); + assertTrue(version.equals("2")); + String release = parser.getRelease(); + assertTrue(release.equals("2")); + assertTrue(parser.getConfigureArgs() == null); + + // Clean up + testProject.delete(true, false, monitor); + } + +} Index: src/org/eclipse/cdt/rpm/core/tests/RPMProjectFactoryTest.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/core/tests/RPMProjectFactoryTest.java diff -N src/org/eclipse/cdt/rpm/core/tests/RPMProjectFactoryTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/rpm/core/tests/RPMProjectFactoryTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,62 @@ +/* + * (c) 2005 Red Hat, Inc. + * + * This program is open source software licensed under the + * Eclipse Public License ver. 1 + */ + +package org.eclipse.cdt.rpm.core.tests; + +import org.eclipse.cdt.rpm.core.IRPMProject; +import org.eclipse.cdt.rpm.core.RPMProjectFactory; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.NullProgressMonitor; + +import junit.framework.TestCase; + +public class RPMProjectFactoryTest extends TestCase { + + IWorkspace workspace; + IWorkspaceRoot root; + NullProgressMonitor monitor; + String pluginRoot; + final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + IWorkspaceDescription desc; + workspace = ResourcesPlugin.getWorkspace(); + root = workspace.getRoot(); + monitor = new NullProgressMonitor(); + if(workspace == null) { + fail("Workspace was not setup"); + } + if(root == null) { + fail("Workspace root was not setup"); + } + desc = workspace.getDescription(); + desc.setAutoBuilding(false); + workspace.setDescription(desc); + } + + public void testGetNewProject() throws Exception { + // Create a project for the test + IProject testProject = root.getProject("testHelloWorld"); + testProject.create(monitor); + testProject.open(monitor); + if(testProject == null) { + fail("Unable to create test project"); + } + + IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); + assertNotNull(rpmProject); + testProject.delete(true, false, monitor); + } +} Index: src/org/eclipse/cdt/rpm/core/tests/RPMProjectNatureTest.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/core/tests/RPMProjectNatureTest.java diff -N src/org/eclipse/cdt/rpm/core/tests/RPMProjectNatureTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/rpm/core/tests/RPMProjectNatureTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,59 @@ +/* + * (c) 2005 Red Hat, Inc. + * + * This program is open source software licensed under the + * Eclipse Public License ver. 1 + */ + +package org.eclipse.cdt.rpm.core.tests; + +import org.eclipse.cdt.rpm.core.RPMProjectNature; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.NullProgressMonitor; + +import junit.framework.TestCase; + +public class RPMProjectNatureTest extends TestCase { + + IWorkspace workspace; + IWorkspaceRoot root; + NullProgressMonitor monitor; + String pluginRoot; + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + IWorkspaceDescription desc; + workspace = ResourcesPlugin.getWorkspace(); + root = workspace.getRoot(); + monitor = new NullProgressMonitor(); + if(workspace == null) { + fail("Workspace was not setup"); + } + if(root == null) { + fail("Workspace root was not setup"); + } + desc = workspace.getDescription(); + desc.setAutoBuilding(false); + workspace.setDescription(desc); + } + + public void testAddRPMProjectNature() throws Exception { + IProject testProject = root.getProject("testProject"); + testProject.create(monitor); + testProject.open(monitor); + if(testProject == null) { + fail("Unable to create test project"); + } + RPMProjectNature.addRPMNature(testProject, monitor); + assertTrue(testProject.hasNature(RPMProjectNature.RPM_NATURE_ID)); + testProject.delete(true, false, monitor); + } + +}