Search in sources :

Example 6 with SpecfileParser

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser in project linuxtools by eclipse.

the class SpecfileContentProvider method inputChanged.

@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    if (oldInput != null) {
        IDocument document = documentProvider.getDocument(oldInput);
        if (document != null) {
            try {
                document.removePositionCategory(SECTION_POSITIONS);
            } catch (BadPositionCategoryException x) {
            }
            document.removePositionUpdater(positionUpdater);
        }
    }
    if (newInput != null) {
        IDocument document = documentProvider.getDocument(newInput);
        if (document != null) {
            document.addPositionCategory(SECTION_POSITIONS);
            document.addPositionUpdater(positionUpdater);
            specfile = new SpecfileParser().parse(document);
        }
    }
}
Also used : BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) IDocument(org.eclipse.jface.text.IDocument)

Example 7 with SpecfileParser

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser in project linuxtools by eclipse.

the class AReplaceTextResolution method run.

@Override
public void run(IMarker marker) {
    IEditorPart editor = getEditor(marker);
    if (editor == null) {
        return;
    }
    IDocument doc = editor.getAdapter(IDocument.class);
    try {
        int lineNumber = marker.getAttribute(IMarker.LINE_NUMBER, 0);
        int index = doc.getLineOffset(lineNumber);
        String line = new SpecfileParser().parse(doc).getLine(lineNumber);
        int rowIndex = line.indexOf(getOriginalString());
        if (rowIndex > -1) {
            doc.replace(index + rowIndex, getOriginalString().length(), getReplaceString());
        }
    } catch (BadLocationException e) {
        RpmlintLog.logError(e);
    }
}
Also used : IEditorPart(org.eclipse.ui.IEditorPart) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 8 with SpecfileParser

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser in project linuxtools by eclipse.

the class FileTestCase method setUp.

@Before
public void setUp() throws CoreException {
    testProject = new SpecfileTestProject();
    String fileName = "test" + this.getClass().getSimpleName() + ".spec";
    testFile = testProject.createFile(fileName);
    editor = new SpecfileEditor();
    parser = new SpecfileParser();
    specfile = new Specfile();
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) SpecfileEditor(org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) Before(org.junit.Before)

Example 9 with SpecfileParser

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser in project linuxtools by eclipse.

the class AInsertLineResolution method run.

/**
 * Inserts an entire line at a given position as a resolution for a problem.
 *
 * @see org.eclipse.ui.IMarkerResolution#run(org.eclipse.core.resources.IMarker)
 */
@Override
public void run(IMarker marker) {
    IEditorPart editor = getEditor(marker);
    if (editor == null) {
        return;
    }
    // Get the document
    IDocument doc = editor.getAdapter(IDocument.class);
    try {
        int index = doc.getLineOffset(getLineNumberForInsert(new SpecfileParser().parse(doc)));
        doc.replace(index, 0, getLineToInsert());
    } catch (BadLocationException e) {
        RpmlintLog.logError(e);
    }
}
Also used : IEditorPart(org.eclipse.ui.IEditorPart) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 10 with SpecfileParser

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser in project linuxtools by eclipse.

the class SpecfileEditorDownloadSourcesActionDelegate 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 = workFile != null ? specparser.parse(workFile) : null;
    // retrieve source(s) from specfile
    final List<SpecfileSource> sourceURLList = specfile != null ? (List<SpecfileSource>) specfile.getSources() : null;
    // currently stops immediately once an invalid source URL is encountered
    for (final SpecfileSource sourceurls : sourceURLList) {
        try {
            String rawURL = sourceurls.getFileName();
            String resolvedURL = UiUtils.resolveDefines(specfile, rawURL);
            URL url = null;
            try {
                url = new URL(resolvedURL);
            } catch (MalformedURLException e) {
                SpecfileLog.logError(NLS.bind(Messages.DownloadSources_malformedURL, resolvedURL), e);
                // $NON-NLS-1$
                RPMUtils.showErrorDialog(// $NON-NLS-1$
                shell, // $NON-NLS-1$
                "Error", NLS.bind(Messages.DownloadSources_malformedURL, resolvedURL));
                return null;
            }
            URLConnection connection = url.openConnection();
            if (!(connection instanceof HttpURLConnection) || ((HttpURLConnection) connection).getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND) {
                connection.connect();
                // grab the name of the file from the URL
                // $NON-NLS-1$
                int offset = url.toString().lastIndexOf("/");
                String filename = url.toString().substring(offset + 1);
                // create the path to the "to be downloaded" file
                IFile file = rpj.getConfiguration().getSourcesFolder().getFile(new Path(filename));
                Job downloadJob = new DownloadJob(file, connection);
                downloadJob.setUser(true);
                downloadJob.schedule();
            }
        } catch (IOException e) {
            SpecfileLog.logError(Messages.DownloadSources_cannotConnectToURL, e);
            // $NON-NLS-1$
            RPMUtils.showErrorDialog(// $NON-NLS-1$
            shell, // $NON-NLS-1$
            "Error", Messages.DownloadSources_cannotConnectToURL);
            return null;
        }
    }
    return null;
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) Path(org.eclipse.core.runtime.Path) MalformedURLException(java.net.MalformedURLException) IFile(org.eclipse.core.resources.IFile) RPMProject(org.eclipse.linuxtools.rpm.core.RPMProject) IOException(java.io.IOException) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) DownloadJob(org.eclipse.linuxtools.rpm.core.utils.DownloadJob) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) Shell(org.eclipse.swt.widgets.Shell) SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) HttpURLConnection(java.net.HttpURLConnection) DownloadJob(org.eclipse.linuxtools.rpm.core.utils.DownloadJob) Job(org.eclipse.core.runtime.jobs.Job) IResource(org.eclipse.core.resources.IResource)

Aggregations

SpecfileParser (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser)10 BadLocationException (org.eclipse.jface.text.BadLocationException)6 Specfile (org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile)6 IDocument (org.eclipse.jface.text.IDocument)5 IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 Job (org.eclipse.core.runtime.jobs.Job)2 IRegion (org.eclipse.jface.text.IRegion)2 SpecfileEditor (org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor)2 SpecfileSource (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource)2 RPMProject (org.eclipse.linuxtools.rpm.core.RPMProject)2 DownloadJob (org.eclipse.linuxtools.rpm.core.utils.DownloadJob)2 SpecfileDefine (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine)2 Shell (org.eclipse.swt.widgets.Shell)2 IEditorPart (org.eclipse.ui.IEditorPart)2 StringTokenizer (com.ibm.icu.util.StringTokenizer)1 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1