Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 089d7a7aeef344196cdc74c340d4f80d08d9a597 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*******************************************************************************
 * Copyright (c) 2007, 2009 Red Hat, Inc.
 * 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 - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.rpm.core.tests;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.eclipse.core.resources.IContainer;
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.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;
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.Ignore;
import org.junit.Test;
import org.osgi.framework.FrameworkUtil;

public class RPMProjectTest {

    static IWorkspace workspace;
    static IWorkspaceRoot root;
    static NullProgressMonitor monitor;
    String pluginRoot;

    final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$

    @BeforeClass
    public static void setUp() {
        workspace = ResourcesPlugin.getWorkspace();
        root = workspace.getRoot();
        monitor = new NullProgressMonitor();
    }

    @Test
    public void testImportHelloWorld() throws Exception {
        // Create a project for the test
        IProject testProject = root.getProject("testHelloWorld");
        RPMProject rpmProject = importSrpm(testProject);

        // Make sure the original SRPM got copied into the workspace
        IFile srpm = rpmProject.getConfiguration().getSrpmsFolder()
                .getFile(new Path("helloworld-2-2.src.rpm"));
        assertTrue(srpm.exists());

        // Make sure everything got installed properly
        IFile spec = rpmProject.getConfiguration().getSpecsFolder()
                .getFile(new Path("helloworld.spec"));
        assertTrue(spec.exists());
        IFile sourceBall = rpmProject.getConfiguration().getSourcesFolder()
                .getFile(new Path("helloworld-2.tar.bz2"));
        assertTrue(sourceBall.exists());

        // Make sure we got the spec file
        IResource specFile = rpmProject.getSpecFile();
        assertNotNull(specFile);

        // Make sure the RPM nature was added
        assertTrue(testProject.hasNature(IRPMConstants.RPM_NATURE_ID));

        // Clean up
        testProject.delete(true, true, monitor);
    }

    @Test
    public void testImportHelloWorldFlat() 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.FLAT);

        // 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);
        File foo = new File(FileLocator.toFileURL(url).getPath());
        rpmProject.importSourceRPM(foo);

        // Make sure the original SRPM got copied into the workspace
        IFile srpm = rpmProject.getConfiguration().getSrpmsFolder()
                .getFile(new Path("helloworld-2-2.src.rpm"));
        assertTrue(srpm.exists());

        // Make sure everything got installed properly
        IFile spec = rpmProject.getConfiguration().getSpecsFolder()
                .getFile(new Path("helloworld.spec"));
        assertTrue(spec.exists());
        IFile sourceBall = rpmProject.getConfiguration().getSourcesFolder()
                .getFile(new Path("helloworld-2.tar.bz2"));
        assertTrue(sourceBall.exists());

        // Make sure we got the spec file
        IResource specFile = rpmProject.getSpecFile();
        assertNotNull(specFile);

        // Make sure the RPM nature was added
        assertTrue(testProject.hasNature(IRPMConstants.RPM_NATURE_ID));

        // Clean up
        testProject.delete(true, true, monitor);
    }

    @Test @Ignore
    public void testBuildPrepHelloWorld() throws Exception {
        // Create a project for the test
        IProject testProject = root.getProject("testBuildPrepHelloWorld");
        RPMProject rpmProject = importSrpm(testProject);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        rpmProject.buildPrep(bos);


        // Make sure we got everything in the build directory
        IContainer builddir = rpmProject.getConfiguration().getBuildFolder();
        IFolder helloworldFolder = builddir.getFolder(new Path("helloworld-2"));
        assertTrue(helloworldFolder.exists());

        // Clean up
        testProject.delete(true, true, monitor);
    }

    @Test @Ignore
    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 @Ignore
    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 @Ignore
    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);

        // 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);
        File foo = new File(FileLocator.toFileURL(url).getPath());
        rpmProject.importSourceRPM(foo);
        return rpmProject;
    }

    @Test @Ignore
    public void testGetSourcesFolder() throws Exception {

        // Create a project for the test
        IProject testProject = root.getProject("testBuildSourceRPMHelloWorld1");
        testProject.create(monitor);
        testProject.open(monitor);
        // Instantiate an RPMProject
        RPMProject rpmProject = new RPMProject(testProject,
                        RPMProjectLayout.RPMBUILD);
        IProjectConfiguration config = rpmProject.getConfiguration();
        String folder = config.getSourcesFolder().getLocation().toOSString();

        int sourceFolder = folder.indexOf("SOURCES");
        assertTrue(sourceFolder != -1);
        testProject.delete(true, true, null);
    }
}

Back to the top