Search in sources :

Example 1 with CreaterepoProject

use of org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject in project linuxtools by eclipse.

the class CreaterepoProjectTest method testInitialize.

/**
 * Test if initializing createrepo project is successful. This means that
 * content folder is initialized but not created (done by wizard, import, or
 * execute commands) and that .repo file exists.
 *
 * @throws CoreException
 */
@Test
public void testInitialize() throws CoreException {
    CreaterepoProject createrepoProject = new CreaterepoProject(project, (IFile) project.findMember(ICreaterepoTestConstants.REPO_NAME));
    // content folder is defined, but not created (wizard does that)
    assertNotNull(createrepoProject.getContentFolder());
    assertFalse(createrepoProject.getContentFolder().exists());
    // repo file is found and exists
    assertNotNull(createrepoProject.getRepoFile());
    assertTrue(createrepoProject.getRepoFile().exists());
    assertEquals(ICreaterepoTestConstants.REPO_NAME, createrepoProject.getRepoFile().getName());
}
Also used : CreaterepoProject(org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject) Test(org.junit.Test)

Example 2 with CreaterepoProject

use of org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject in project linuxtools by eclipse.

the class CreaterepoProjectTest method testImportRPM.

/**
 * Test if importing RPMs from external source successfully saves into
 * the "content" folder.
 *
 * @throws CoreException
 * @throws IOException
 */
@Test
public void testImportRPM() throws CoreException, IOException {
    CreaterepoProject createrepoProject = new CreaterepoProject(project);
    // test for file
    URL rpmURL = FileLocator.find(FrameworkUtil.getBundle(CreaterepoProjectTest.class), new Path(TEST_RPM_LOC1), null);
    File rpmFile = new File(FileLocator.toFileURL(rpmURL).getPath());
    createrepoProject.importRPM(rpmFile);
    assertNotNull(createrepoProject.getContentFolder());
    assertTrue(createrepoProject.getContentFolder().exists());
    assertEquals(1, createrepoProject.getContentFolder().members().length);
    assertTrue(createrepoProject.getContentFolder().findMember(ICreaterepoTestConstants.RPM1).exists());
    // test for duplicate file
    createrepoProject.importRPM(rpmFile);
    assertEquals(1, createrepoProject.getContentFolder().members().length);
    assertTrue(createrepoProject.getContentFolder().findMember(ICreaterepoTestConstants.RPM1).exists());
    // test for new file
    rpmURL = FileLocator.find(FrameworkUtil.getBundle(CreaterepoProjectTest.class), new Path(TEST_RPM_LOC2), null);
    rpmFile = new File(FileLocator.toFileURL(rpmURL).getPath());
    createrepoProject.importRPM(rpmFile);
    assertEquals(2, createrepoProject.getContentFolder().members().length);
    assertTrue(createrepoProject.getContentFolder().findMember(ICreaterepoTestConstants.RPM2).exists());
}
Also used : Path(org.eclipse.core.runtime.Path) CreaterepoProject(org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 3 with CreaterepoProject

use of org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject in project linuxtools by eclipse.

the class CreaterepoCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    // $NON-NLS-1$
    final String executionType = event.getParameter("executionType");
    try {
        IWorkbench wb = PlatformUI.getWorkbench();
        IWorkbenchPage wbPage = wb.getActiveWorkbenchWindow().getActivePage();
        IEditorInput editorInput = wbPage.getActiveEditor().getEditorInput();
        IResource resource = ResourceUtil.getResource(editorInput);
        final CreaterepoProject project = new CreaterepoProject(resource.getProject());
        Job executeCreaterepo = new Job(Messages.Createrepo_jobName) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    monitor.beginTask(Messages.CreaterepoProject_executeCreaterepo, IProgressMonitor.UNKNOWN);
                    MessageConsoleStream os = CreaterepoUtils.findConsole(Messages.CreaterepoProject_consoleName).newMessageStream();
                    if (executionType.equals("refresh")) {
                        // $NON-NLS-1$
                        return project.update(os);
                    } else {
                        return project.createrepo(os);
                    }
                } catch (CoreException e) {
                    Activator.logError(Messages.Createrepo_errorExecuting, e);
                } finally {
                    monitor.done();
                }
                return null;
            }
        };
        executeCreaterepo.setUser(true);
        executeCreaterepo.schedule();
    } catch (CoreException e) {
        Activator.logError(Messages.CreaterepoProject_executeCreaterepo, e);
    }
    return null;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) Job(org.eclipse.core.runtime.jobs.Job) CreaterepoProject(org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Example 4 with CreaterepoProject

use of org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject in project linuxtools by eclipse.

the class RepoFormEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    IFile file = ResourceUtil.getFile(input);
    setPartName(file.getName());
    try {
        project = new CreaterepoProject(file.getProject(), file);
    } catch (CoreException e) {
        Activator.logError(Messages.RepoFormEditor_errorInitializingProject, e);
    }
    resourceChangeListener = new CreaterepoResourceChangeListener(project);
    ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener);
}
Also used : IFile(org.eclipse.core.resources.IFile) CreaterepoResourceChangeListener(org.eclipse.linuxtools.internal.rpm.createrepo.listener.CreaterepoResourceChangeListener) CoreException(org.eclipse.core.runtime.CoreException) CreaterepoProject(org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject)

Example 5 with CreaterepoProject

use of org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject in project linuxtools by eclipse.

the class CreaterepoProjectTest method testSimpleExecute.

/**
 * Simple test execution of createrepo. This checks to see if the "content" folder
 * was created while executing and that the execution is successful if repomd.xml was created
 * under the repodata folder.
 *
 * @throws CoreException
 */
@Test
@Ignore
public void testSimpleExecute() throws CoreException {
    // assume that there is creatrepo version of >= 0.9.8
    Assume.assumeTrue(Createrepo.isCorrectVersion().isOK());
    CreaterepoProject createrepoProject = new CreaterepoProject(project);
    // make sure that content folder doesn't exist
    assertFalse(createrepoProject.getContentFolder().exists());
    // $NON-NLS-1$
    IStatus status = createrepoProject.createrepo(CreaterepoUtils.findConsole("test").newMessageStream());
    // check if  executing has an OK status and that content folder is created with the repodata contents
    assertEquals(Status.OK_STATUS, status);
    assertTrue(createrepoProject.getContentFolder().exists());
    assertTrue(createrepoProject.getContentFolder().members().length > 0);
    // check if the repodata folder exists and repomd.xml exists within it
    assertTrue(createrepoProject.getContentFolder().findMember(ICreaterepoTestConstants.REPODATA_FOLDER).exists());
    IFolder repodataFolder = (IFolder) createrepoProject.getContentFolder().findMember(ICreaterepoTestConstants.REPODATA_FOLDER);
    // repodata should have at least more than 1 file: repomd.xml + archives
    assertTrue(repodataFolder.members().length > 1);
    assertTrue(repodataFolder.findMember(ICreaterepoTestConstants.REPO_MD_NAME).exists());
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) CreaterepoProject(org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject) IFolder(org.eclipse.core.resources.IFolder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

CreaterepoProject (org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject)7 Test (org.junit.Test)5 IFile (org.eclipse.core.resources.IFile)3 File (java.io.File)2 URL (java.net.URL)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 Path (org.eclipse.core.runtime.Path)2 IFolder (org.eclipse.core.resources.IFolder)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Job (org.eclipse.core.runtime.jobs.Job)1 CreaterepoResourceChangeListener (org.eclipse.linuxtools.internal.rpm.createrepo.listener.CreaterepoResourceChangeListener)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 MessageConsoleStream (org.eclipse.ui.console.MessageConsoleStream)1 Ignore (org.junit.Ignore)1