Search in sources :

Example 66 with IContainer

use of org.eclipse.core.resources.IContainer in project linuxtools by eclipse.

the class SourcesFileHyperlink method open.

/**
 * Tries to open the given file name looking for it in the current directory
 * and in ../SOURCES.
 *
 * @see org.eclipse.jface.text.hyperlink.IHyperlink#open()
 */
@Override
public void open() {
    IContainer container = original.getParent();
    IResource resourceToOpen = container.findMember(fileName);
    if (resourceToOpen == null) {
        IResource sourcesFolder = container.getParent().findMember(// $NON-NLS-1$
        "SOURCES");
        resourceToOpen = ((IFolder) sourcesFolder).getFile(fileName);
    }
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    try {
        if (resourceToOpen.getType() == IResource.FILE) {
            IDE.openEditor(page, (IFile) resourceToOpen);
        }
    } catch (PartInitException e) {
        SpecfileLog.logError(e);
    }
}
Also used : IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 67 with IContainer

use of org.eclipse.core.resources.IContainer in project linuxtools by eclipse.

the class OpenGCAction method getDefaultBinary.

private String getDefaultBinary(IPath file) {
    IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(file);
    if (c != null) {
        IProject project = c.getProject();
        if (project != null && project.exists()) {
            IContainer folder = c.getParent();
            // $NON-NLS-1$
            IFile infoFile = folder.getFile(new Path("AnalysisInfo.txt"));
            try {
                String defaultBinaryFromUserPref = getDefaultBinaryFromUserPref(project, infoFile);
                if (defaultBinaryFromUserPref != null) {
                    return defaultBinaryFromUserPref;
                }
            } catch (IOException | CoreException ex) {
            // do nothing here.
            }
            ICProject cproject = CoreModel.getDefault().create(project);
            if (cproject != null) {
                try {
                    IBinary[] b = cproject.getBinaryContainer().getBinaries();
                    if (b != null && b.length > 0 && b[0] != null) {
                        IResource r = b[0].getResource();
                        return r.getLocation().toOSString();
                    }
                } catch (CModelException e) {
                }
            }
        }
    }
    // $NON-NLS-1$
    return "";
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) CModelException(org.eclipse.cdt.core.model.CModelException) IOException(java.io.IOException) IBinary(org.eclipse.cdt.core.model.IBinary) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 68 with IContainer

use of org.eclipse.core.resources.IContainer in project linuxtools by eclipse.

the class DownloadPrepareSourcesTest method checkPreparedSources.

/**
 * Check if the source was prepared correctly based on project layout
 *
 * @param project The RPM project
 * @param layout The layout of the RPM project (RPMBuild or FLAT)
 * @throws CoreException
 */
public void checkPreparedSources(RPMProject project, RPMProjectLayout layout) throws CoreException {
    IContainer buildFolder = project.getConfiguration().getBuildFolder();
    IFolder helloBuildFolder = null;
    assertNotNull(buildFolder);
    switch(layout) {
        case RPMBUILD:
            assertNotNull(buildFolder.getParent().findMember("BUILD"));
            assertEquals(buildFolder.members().length, 1);
            // check if the file exists under BUILD folder
            helloBuildFolder = buildFolder.getFolder(new Path("hello-2.8"));
            assertTrue(helloBuildFolder.exists());
            // there should be some stuff within hello-2.8/ folder
            assertTrue(helloBuildFolder.members().length >= 1);
            break;
        case FLAT:
            // 4 = "hello-2.8.tar.gz" + ".project" + "hello-2.8-1.fc19.src.rpm" + "hello.spec" + "hello-2.8/"
            assertEquals(buildFolder.members().length, 5);
            helloBuildFolder = buildFolder.getFolder(new Path("hello-2.8"));
            assertTrue(helloBuildFolder.exists());
            // there should be some stuff within hello-2.8/ folder
            assertTrue(helloBuildFolder.members().length >= 1);
            break;
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 69 with IContainer

use of org.eclipse.core.resources.IContainer in project linuxtools by eclipse.

the class RPMProjectTest method testBuildPrepHelloWorld.

@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);
}
Also used : Path(org.eclipse.core.runtime.Path) RPMProject(org.eclipse.linuxtools.rpm.core.RPMProject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IContainer(org.eclipse.core.resources.IContainer) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 70 with IContainer

use of org.eclipse.core.resources.IContainer in project linuxtools by eclipse.

the class RPMProject method getSpecFile.

/**
 * 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;
    SpecfileVisitor specVisitor = new SpecfileVisitor();
    try {
        specsFolder.accept(specVisitor);
        List<IResource> installedSpecs = specVisitor.getSpecFiles();
        if (installedSpecs.size() > 0) {
            file = installedSpecs.get(0);
        }
    } catch (CoreException e) {
    // ignore, failed to find .spec file.
    }
    return file;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) SpecfileVisitor(org.eclipse.linuxtools.internal.rpm.core.SpecfileVisitor) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Aggregations

IContainer (org.eclipse.core.resources.IContainer)199 IResource (org.eclipse.core.resources.IResource)89 IFile (org.eclipse.core.resources.IFile)71 IPath (org.eclipse.core.runtime.IPath)47 CoreException (org.eclipse.core.runtime.CoreException)46 IFolder (org.eclipse.core.resources.IFolder)45 Path (org.eclipse.core.runtime.Path)43 IProject (org.eclipse.core.resources.IProject)28 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)26 ArrayList (java.util.ArrayList)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 IOException (java.io.IOException)13 IStatus (org.eclipse.core.runtime.IStatus)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)12 Status (org.eclipse.core.runtime.Status)10 PartInitException (org.eclipse.ui.PartInitException)10 InputStream (java.io.InputStream)9