Search in sources :

Example 1 with RPMProject

use of org.eclipse.linuxtools.rpm.core.RPMProject in project linuxtools by eclipse.

the class SpecfileEditorPrepareSourcesActionDelegate method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Shell shell = HandlerUtil.getActiveShellChecked(event);
    final SpecfileParser specparser = new SpecfileParser();
    final IResource resource = RPMHandlerUtils.getResource(event);
    final RPMProject rpj = RPMHandlerUtils.getRPMProject(resource);
    final IFile workFile = (IFile) rpj.getSpecFile();
    final Specfile specfile = specparser.parse(workFile);
    if (!downloadFile(shell, rpj, specfile)) {
        return null;
    }
    Job job = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    "Preparing sources") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            monitor.beginTask(NLS.bind(Messages.PrepareSources_prepareSources, rpj.getSpecFile().getName()), IProgressMonitor.UNKNOWN);
            // $NON-NLS-1$
            int offset = rpj.getSpecFile().getName().lastIndexOf(".");
            MessageConsoleStream out = getConsole(rpj.getSpecFile().getName().substring(0, offset)).newMessageStream();
            IStatus is = null;
            try {
                is = rpj.buildPrep(out);
            } catch (CoreException e) {
                SpecfileLog.logError(Messages.PrepareSources_coreException, e);
                RPMUtils.showErrorDialog(shell, Messages.PrepareSources_error, Messages.PrepareSources_coreException);
                return is;
            } finally {
                monitor.done();
            }
            return is;
        }
    };
    // suppress UI. That's done in encapsulated
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) RPMProject(org.eclipse.linuxtools.rpm.core.RPMProject) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) DownloadJob(org.eclipse.linuxtools.rpm.core.utils.DownloadJob) Job(org.eclipse.core.runtime.jobs.Job) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) IResource(org.eclipse.core.resources.IResource)

Example 2 with RPMProject

use of org.eclipse.linuxtools.rpm.core.RPMProject in project linuxtools by eclipse.

the class DownloadPrepareSourcesTest method layoutFLATDownloadSourcesTest.

/**
 * Test downloading sources using FLAT layout
 *
 * @throws CoreException
 * @throws IOException
 * @throws InterruptedException
 */
@Test
public void layoutFLATDownloadSourcesTest() throws CoreException, IOException, InterruptedException {
    RPMProject rpmProject = importSrpm(testProject, RPMProjectLayout.FLAT);
    assertNotNull(rpmProject);
    downloadFile(rpmProject);
    checkDownloadedFile(rpmProject, RPMProjectLayout.FLAT);
}
Also used : RPMProject(org.eclipse.linuxtools.rpm.core.RPMProject) Test(org.junit.Test)

Example 3 with RPMProject

use of org.eclipse.linuxtools.rpm.core.RPMProject in project linuxtools by eclipse.

the class DownloadPrepareSourcesTest method layoutRPMBuildPrepareSourcesTest.

/**
 * Test preparing sources using RPMBuild layout
 *
 * @throws CoreException
 * @throws IOException
 * @throws InterruptedException
 */
@Test
public void layoutRPMBuildPrepareSourcesTest() throws CoreException, IOException, InterruptedException {
    RPMProject rpmProject = importSrpm(testProject, RPMProjectLayout.RPMBUILD);
    assertNotNull(rpmProject);
    downloadFile(rpmProject);
    checkDownloadedFile(rpmProject, RPMProjectLayout.RPMBUILD);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    IStatus is = rpmProject.buildPrep(bos);
    assertTrue(is.isOK());
    checkPreparedSources(rpmProject, RPMProjectLayout.RPMBUILD);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) RPMProject(org.eclipse.linuxtools.rpm.core.RPMProject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 4 with RPMProject

use of org.eclipse.linuxtools.rpm.core.RPMProject in project linuxtools by eclipse.

the class RPMProjectTest method importSrpm.

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(// $NON-NLS-1$ //$NON-NLS-2$
    "resources" + file_sep + "srpms" + file_sep + "helloworld-2-2.src.rpm"), null);
    File foo = new File(FileLocator.toFileURL(url).getPath());
    rpmProject.importSourceRPM(foo);
    return rpmProject;
}
Also used : Path(org.eclipse.core.runtime.Path) RPMProject(org.eclipse.linuxtools.rpm.core.RPMProject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) URL(java.net.URL)

Example 5 with RPMProject

use of org.eclipse.linuxtools.rpm.core.RPMProject in project linuxtools by eclipse.

the class RPMProjectTest method testImportHelloWorldFlat.

@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(// $NON-NLS-1$ //$NON-NLS-2$
    "resources" + file_sep + "srpms" + file_sep + "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);
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) RPMProject(org.eclipse.linuxtools.rpm.core.RPMProject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) IResource(org.eclipse.core.resources.IResource) Test(org.junit.Test)

Aggregations

RPMProject (org.eclipse.linuxtools.rpm.core.RPMProject)16 Test (org.junit.Test)11 IFile (org.eclipse.core.resources.IFile)9 Path (org.eclipse.core.runtime.Path)9 IProject (org.eclipse.core.resources.IProject)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Ignore (org.junit.Ignore)5 URL (java.net.URL)4 IResource (org.eclipse.core.resources.IResource)4 File (java.io.File)3 IStatus (org.eclipse.core.runtime.IStatus)3 CoreException (org.eclipse.core.runtime.CoreException)2 Job (org.eclipse.core.runtime.jobs.Job)2 DownloadJob (org.eclipse.linuxtools.rpm.core.utils.DownloadJob)2 Specfile (org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile)2 SpecfileParser (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser)2 Shell (org.eclipse.swt.widgets.Shell)2 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1