diff options
author | Alexander Kurtakov | 2013-01-11 15:51:34 +0000 |
---|---|---|
committer | Camilo Bernal | 2013-01-11 19:28:27 +0000 |
commit | 5bf898df4587cb5dcb2f2d924c61f68dc071375b (patch) | |
tree | b8c366e7bad0f0041f7ffce3b051999ea0a0b83c /rpm | |
parent | c3896d90b78cf4c44c682ccd7fd14993228531f6 (diff) | |
download | org.eclipse.linuxtools-5bf898df4587cb5dcb2f2d924c61f68dc071375b.tar.gz org.eclipse.linuxtools-5bf898df4587cb5dcb2f2d924c61f68dc071375b.tar.xz org.eclipse.linuxtools-5bf898df4587cb5dcb2f2d924c61f68dc071375b.zip |
Let it test all build options.
* make buildPrep has similar signature to other build*
* add javadocs
* simplify test class to not have checks to explicitly fail if it will
happen internally too.
Change-Id: I53c9df116bd636677d0f510fcb8a1ece3bf05c52
Reviewed-on: https://git.eclipse.org/r/9627
Tested-by: Hudson CI
Reviewed-by: Camilo Bernal <cabernal@redhat.com>
IP-Clean: Camilo Bernal <cabernal@redhat.com>
Tested-by: Camilo Bernal <cabernal@redhat.com>
Diffstat (limited to 'rpm')
3 files changed, 95 insertions, 81 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.core.tests/src/org/eclipse/linuxtools/rpm/core/tests/RPMProjectTest.java b/rpm/org.eclipse.linuxtools.rpm.core.tests/src/org/eclipse/linuxtools/rpm/core/tests/RPMProjectTest.java index 4c38628706..f9e541325f 100644 --- a/rpm/org.eclipse.linuxtools.rpm.core.tests/src/org/eclipse/linuxtools/rpm/core/tests/RPMProjectTest.java +++ b/rpm/org.eclipse.linuxtools.rpm.core.tests/src/org/eclipse/linuxtools/rpm/core/tests/RPMProjectTest.java @@ -12,10 +12,10 @@ package org.eclipse.linuxtools.rpm.core.tests; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; import java.net.URL; import org.eclipse.core.resources.IContainer; @@ -24,9 +24,9 @@ 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.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; @@ -34,6 +34,7 @@ import org.eclipse.linuxtools.rpm.core.IProjectConfiguration; import org.eclipse.linuxtools.rpm.core.IRPMConstants; import org.eclipse.linuxtools.rpm.core.RPMProject; import org.eclipse.linuxtools.rpm.core.RPMProjectLayout; +import org.eclipse.linuxtools.rpm.core.utils.Utils; import org.junit.BeforeClass; import org.junit.Test; import org.osgi.framework.FrameworkUtil; @@ -48,44 +49,17 @@ public class RPMProjectTest { final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ @BeforeClass - public static void setUp() throws Exception { - IWorkspaceDescription desc; + public static void setUp() { workspace = ResourcesPlugin.getWorkspace(); - if (workspace == null) { - fail("Workspace was not setup"); - } root = workspace.getRoot(); monitor = new NullProgressMonitor(); - if (root == null) { - fail("Workspace root was not setup"); - } - desc = workspace.getDescription(); - desc.setAutoBuilding(false); - workspace.setDescription(desc); } @Test public void testImportHelloWorld() throws Exception { // Create a project for the test IProject testProject = root.getProject("testHelloWorld"); - testProject.create(monitor); - testProject.open(monitor); - - // Instantiate an RPMProject - RPMProject rpmProject = new RPMProject(testProject, - RPMProjectLayout.RPMBUILD); - - // Find the test SRPM and install it - URL url = FileLocator.find(FrameworkUtil - .getBundle(RPMProjectTest.class), new Path( - "resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ - "helloworld-2-2.src.rpm"), null); - if (url == null) { - fail("Unable to find resource" + file_sep + "srpms" + file_sep - + "helloworld-2-2.src.rpm"); - } - File foo = new File(FileLocator.toFileURL(url).getPath()); - rpmProject.importSourceRPM(foo); + RPMProject rpmProject = importSrpm(testProject); // Make sure the original SRPM got copied into the workspace IFile srpm = rpmProject.getConfiguration().getSrpmsFolder() @@ -127,10 +101,6 @@ public class RPMProjectTest { .getBundle(RPMProjectTest.class), new Path( "resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ "helloworld-2-2.src.rpm"), null); - if (url == null) { - fail("Unable to find resource" + file_sep + "srpms" + file_sep - + "helloworld-2-2.src.rpm"); - } File foo = new File(FileLocator.toFileURL(url).getPath()); rpmProject.importSourceRPM(foo); @@ -162,24 +132,7 @@ public class RPMProjectTest { public void testBuildPrepHelloWorld() throws Exception { // Create a project for the test IProject testProject = root.getProject("testBuildPrepHelloWorld"); - testProject.create(monitor); - testProject.open(monitor); - - // Instantiate an RPMProject - RPMProject rpmProject = new RPMProject(testProject, - RPMProjectLayout.RPMBUILD); - - // Find the test SRPM, install, and build-prep it - URL url = FileLocator.find(FrameworkUtil - .getBundle(RPMProjectTest.class), new Path( - "resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ - "helloworld-2-2.src.rpm"), null); - if (url == null) { - fail("Unable to find resource" + file_sep + "srpms" + file_sep - + "helloworld-2-2.src.rpm"); - } - File foo = new File(FileLocator.toFileURL(url).getPath()); - rpmProject.importSourceRPM(foo); + RPMProject rpmProject = importSrpm(testProject); ByteArrayOutputStream bos = new ByteArrayOutputStream(); rpmProject.buildPrep(bos); @@ -197,6 +150,57 @@ public class RPMProjectTest { public void testBuildSourceRPMHelloWorld() throws Exception { // Create a project for the test IProject testProject = root.getProject("testBuildSourceRPMHelloWorld1"); + RPMProject rpmProject = importSrpm(testProject); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + rpmProject.buildSourceRPM(bos); + + IFile foo2 = rpmProject.getConfiguration().getSrpmsFolder() + .getFile(new Path("helloworld-2-2.src.rpm")); + assertTrue(foo2.exists()); + + testProject.delete(true, true, null); + } + + @Test + public void testBuildBinaryRPMHelloWorld() throws Exception { + // Create a project for the test + IProject testProject = root.getProject("testBuildBinaryRPMHelloWorld1"); + RPMProject rpmProject = importSrpm(testProject); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + rpmProject.buildBinaryRPM(bos); + + IFile foo2 = rpmProject.getConfiguration().getSrpmsFolder() + .getFile(new Path("helloworld-2-2.src.rpm")); + assertTrue(foo2.exists()); + + String arch = Utils.runCommandToString("rpm", "--eval", "%{_arch}").trim(); + IFile foo3 = rpmProject.getConfiguration().getRpmsFolder().getFolder(new Path(arch)) + .getFile(new Path("helloworld-2-2."+arch+".rpm")); + assertTrue(foo3.exists()); + testProject.delete(true, true, null); + } + + @Test + public void testBuildAllRPMHelloWorld() throws Exception { + // Create a project for the test + IProject testProject = root.getProject("testBuildAllRPMHelloWorld1"); + RPMProject rpmProject = importSrpm(testProject); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + rpmProject.buildAll(bos); + + IFile foo2 = rpmProject.getConfiguration().getSrpmsFolder() + .getFile(new Path("helloworld-2-2.src.rpm")); + assertTrue(foo2.exists()); + + String arch = Utils.runCommandToString("rpm", "--eval", "%{_arch}").trim(); + IFile foo3 = rpmProject.getConfiguration().getRpmsFolder().getFolder(new Path(arch)) + .getFile(new Path("helloworld-2-2."+arch+".rpm")); + assertTrue(foo3.exists()); + testProject.delete(true, true, null); + } + + private RPMProject importSrpm(IProject testProject) throws CoreException, + IOException { testProject.create(monitor); testProject.open(monitor); @@ -209,20 +213,9 @@ public class RPMProjectTest { .getBundle(RPMProjectTest.class), new Path( "resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ "helloworld-2-2.src.rpm"), null); - if (url == null) { - fail("Unable to find resource" + file_sep + "srpms" + file_sep - + "helloworld-2-2.src.rpm"); - } File foo = new File(FileLocator.toFileURL(url).getPath()); rpmProject.importSourceRPM(foo); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - rpmProject.buildSourceRPM(bos); - - IFile foo2 = rpmProject.getConfiguration().getSrpmsFolder() - .getFile(new Path("helloworld-2-2.src.rpm")); - assertTrue(foo2.exists()); - - testProject.delete(true, true, null); + return rpmProject; } @Test @@ -238,16 +231,8 @@ public class RPMProjectTest { IProjectConfiguration config = rpmProject.getConfiguration(); String folder = config.getSourcesFolder().getLocation().toOSString(); - boolean srcFolderPath = true; - int sourceFolder = folder.indexOf("SOURCES"); - - if (sourceFolder==-1) { - srcFolderPath=false; - } - - assertTrue(srcFolderPath); + assertTrue(sourceFolder != -1); testProject.delete(true, true, null); - -} + } } diff --git a/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/internal/rpm/core/utils/RPMBuild.java b/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/internal/rpm/core/utils/RPMBuild.java index a8db118c84..971f460dfe 100644 --- a/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/internal/rpm/core/utils/RPMBuild.java +++ b/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/internal/rpm/core/utils/RPMBuild.java @@ -75,12 +75,13 @@ public class RPMBuild { * the spec file * @param outStream * The stream to write the output to. + * @return The return code of the build job. * @throws CoreException * If the operation fails. */ - public void buildPrep(IResource specFile, OutputStream outStream) + public IStatus buildPrep(IResource specFile, OutputStream outStream) throws CoreException { - build(specFile, outStream, "-bp"); //$NON-NLS-1$ + return build(specFile, outStream, "-bp"); //$NON-NLS-1$ } /** diff --git a/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/rpm/core/RPMProject.java b/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/rpm/core/RPMProject.java index b8a8b95651..e8c429a33b 100644 --- a/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/rpm/core/RPMProject.java +++ b/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/rpm/core/RPMProject.java @@ -66,10 +66,20 @@ public class RPMProject { } } + /** + * Returns the configuration (RPMBuild, FLAT) for this project. + * + * @return The project configuration. + */ public IProjectConfiguration getConfiguration() { return rpmConfig; } + /** + * Returns the .spec file of this project. + * + * @return The .spec file or null if one is not found. + */ public IResource getSpecFile() { IContainer specsFolder = getConfiguration().getSpecsFolder(); IResource file = null; @@ -80,12 +90,17 @@ public class RPMProject { List<IResource> installedSpecs = specVisitor.getSpecFiles(); file = installedSpecs.get(0); } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + // ignore, failed to find .spec file. } return file; } + /** + * Import a SRPM into this RPM project using local file. + * + * @param externalFile The SRPM file. + * @throws CoreException If there is problem with the .src.rpm file. + */ public void importSourceRPM(File externalFile) throws CoreException { // Copy original SRPM to workspace IFile srpmFile = getConfiguration().getSrpmsFolder().getFile( @@ -139,6 +154,12 @@ public class RPMProject { importSourceRPM(tempFile); } + /** + * Build both source and binary rpms. + * @param outStream The stream to right command output to. + * @return The result of the command. + * @throws CoreException If exception occurs during building. + */ public IStatus buildAll(OutputStream outStream) throws CoreException { RPMBuild rpmbuild = new RPMBuild(getConfiguration()); IStatus result = rpmbuild.buildAll(getSpecFile(), outStream); @@ -186,11 +207,18 @@ public class RPMProject { return result; } - public void buildPrep(OutputStream out) throws CoreException { + /** + * Prepares sources for build (rpmbuild -bp). + * @param out The stream to right command output to. + * @return The result of the command. + * @throws CoreException If exception occurs during building. + */ + public IStatus buildPrep(OutputStream out) throws CoreException { RPMBuild rpmbuild = new RPMBuild(getConfiguration()); - rpmbuild.buildPrep(getSpecFile(), out); + IStatus result = rpmbuild.buildPrep(getSpecFile(), out); getConfiguration().getBuildFolder().refreshLocal( IResource.DEPTH_INFINITE, null); + return result; } } |