Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/rpm
diff options
context:
space:
mode:
authorAlexander Kurtakov2016-02-03 09:14:17 +0000
committerAlexander Kurtakov2016-02-03 09:42:12 +0000
commit66a2c61756dda0fa425ba5007230226a0abd8837 (patch)
tree1a514d9ac36776edcce969bf8d2c243930daa301 /rpm
parent9bbcaa9405adfdbc09291958e91f709474e1de6b (diff)
downloadorg.eclipse.linuxtools-66a2c61756dda0fa425ba5007230226a0abd8837.tar.gz
org.eclipse.linuxtools-66a2c61756dda0fa425ba5007230226a0abd8837.tar.xz
org.eclipse.linuxtools-66a2c61756dda0fa425ba5007230226a0abd8837.zip
rpm: Cleanups
* Inline singular fields. * Remove useless modifiers. * Remove useless local vars before return. * Don't uselessly catch Exception. * More efficient string concatenation. Change-Id: Ieac557430449cc48f4346af0878e3e8f87ba7667 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com> Reviewed-on: https://git.eclipse.org/r/65760 Tested-by: Hudson CI
Diffstat (limited to 'rpm')
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/MetadataPage.java8
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/Activator.java8
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileDocumentProvider.java4
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/forms/MainPackagePage.java251
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/forms/SpecfileFormEditor.java86
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/parser/SpecfileSource.java254
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/preferences/RpmProposalsPreferencePage.java3
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/preferences/TaskTagsPreferencePage.java88
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/SpecfileParser.java1145
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RpmConsole.java4
10 files changed, 876 insertions, 975 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/MetadataPage.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/MetadataPage.java
index 84ef704b1e..f1b97ab458 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/MetadataPage.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/MetadataPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 Red Hat Inc. and others.
+ * Copyright (c) 2013, 2016 Red Hat Inc. and others.
* 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
@@ -55,13 +55,11 @@ public class MetadataPage extends FormPage {
private IEclipsePreferences eclipsePreferences;
private FormToolkit toolkit;
- private ScrolledForm form;
private Text revisionTxt;
private Text tagTxt;
private Tree tagsTree;
private TreeViewer tagsTreeViewer;
- private Composite buttonList;
private static final String MENU_URI = "toolbar:formsToolbar"; //$NON-NLS-1$
private static final String HEADER_ICON = "/icons/library_obj.gif"; //$NON-NLS-1$
@@ -79,7 +77,7 @@ public class MetadataPage extends FormPage {
super.createFormContent(managedForm);
GridLayout layout = new GridLayout();
toolkit = managedForm.getToolkit();
- form = managedForm.getForm();
+ ScrolledForm form = managedForm.getForm();
form.setText(Messages.MetadataPage_formHeaderText);
form.setImage(Activator.getImageDescriptor(HEADER_ICON).createImage());
ToolBarManager toolbarManager = (ToolBarManager) form.getToolBarManager();
@@ -176,7 +174,7 @@ public class MetadataPage extends FormPage {
tagsTree.setLayoutData(expandComposite());
// everything to do with the buttons
- buttonList = toolkit.createComposite(sectionClientTags);
+ Composite buttonList = toolkit.createComposite(sectionClientTags);
layout = new GridLayout();
data = new GridData(SWT.BEGINNING, SWT.FILL, false, true);
layout.marginWidth = 0; layout.marginHeight = 0;
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/Activator.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/Activator.java
index e2e5791deb..5cc1153b84 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/Activator.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/Activator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Red Hat, Inc.
+ * Copyright (c) 2007, 2016 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
@@ -44,9 +44,6 @@ public class Activator extends AbstractUIPlugin {
private ContributionTemplateStore fTemplateStore;
private ContributionContextTypeRegistry fContextTypeRegistry;
- // RPM macros list
- private RpmMacroProposalsList macrosList;
-
// RPM Groups
private List<String> rpmGroups = new ArrayList<>();
@@ -100,8 +97,7 @@ public class Activator extends AbstractUIPlugin {
}
public RpmMacroProposalsList getRpmMacroList() {
- macrosList = new RpmMacroProposalsList();
- return macrosList;
+ return new RpmMacroProposalsList();
}
public RpmPackageProposalsList getRpmPackageList() {
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileDocumentProvider.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileDocumentProvider.java
index 01a1df1aed..8034d838e4 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileDocumentProvider.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileDocumentProvider.java
@@ -14,6 +14,7 @@ package org.eclipse.linuxtools.internal.rpm.ui.editor;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
@@ -21,6 +22,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.linuxtools.internal.rpm.ui.editor.scanners.SpecfilePartitionScanner;
@@ -91,7 +93,7 @@ public class SpecfileDocumentProvider extends TextFileDocumentProvider {
}
resetDocument(element);
return false;
- } catch (Exception e) {
+ } catch (IOException | CoreException | BadLocationException e) {
return true;
}
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/forms/MainPackagePage.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/forms/MainPackagePage.java
index 4225f99a9f..553f44346e 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/forms/MainPackagePage.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/forms/MainPackagePage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Red Hat, Inc.
+ * Copyright (c) 2009, 2016 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
@@ -27,144 +27,135 @@ import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
public class MainPackagePage extends FormPage {
- private FormToolkit toolkit;
- private ScrolledForm form;
- private Specfile specfile;
+ private Specfile specfile;
- public MainPackagePage(SpecfileFormEditor editor, Specfile specfile) {
- super(editor, Messages.MainPackagePage_0, Messages.MainPackagePage_1);
- this.specfile = specfile;
- }
+ public MainPackagePage(SpecfileFormEditor editor, Specfile specfile) {
+ super(editor, Messages.MainPackagePage_0, Messages.MainPackagePage_1);
+ this.specfile = specfile;
+ }
- @Override
- protected void createFormContent(IManagedForm managedForm) {
- super.createFormContent(managedForm);
- toolkit = managedForm.getToolkit();
- form = managedForm.getForm();
- form.setText(Messages.MainPackagePage_2);
- GridLayout layout = new GridLayout();
- layout.marginWidth = layout.marginHeight = 5;
- layout.numColumns = 2;
- RowLayout rowLayout = new RowLayout();
- rowLayout.type = SWT.VERTICAL;
- rowLayout.justify = true;
- rowLayout.fill = true;
+ @Override
+ protected void createFormContent(IManagedForm managedForm) {
+ super.createFormContent(managedForm);
+ FormToolkit toolkit = managedForm.getToolkit();
+ ScrolledForm form = managedForm.getForm();
+ form.setText(Messages.MainPackagePage_2);
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = layout.marginHeight = 5;
+ layout.numColumns = 2;
+ RowLayout rowLayout = new RowLayout();
+ rowLayout.type = SWT.VERTICAL;
+ rowLayout.justify = true;
+ rowLayout.fill = true;
- form.getBody().setLayout(rowLayout);
- form.getBody().setLayoutData(rowLayout);
- layout.numColumns = 2;
- GridData gd = new GridData();
- gd.horizontalSpan = 2;
- gd.horizontalAlignment = SWT.FILL;
- final Section mainPackageSection = toolkit.createSection(form.getBody(),
- ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE
- | ExpandableComposite.EXPANDED);
- mainPackageSection.setText(Messages.MainPackagePage_3);
- mainPackageSection.setLayout(new GridLayout());
- Composite mainPackageClient = toolkit.createComposite(mainPackageSection);
- GridLayout gridLayout = new GridLayout();
- gridLayout.marginWidth = gridLayout.marginHeight = 5;
- gridLayout.numColumns = 2;
+ form.getBody().setLayout(rowLayout);
+ form.getBody().setLayoutData(rowLayout);
+ layout.numColumns = 2;
+ GridData gd = new GridData();
+ gd.horizontalSpan = 2;
+ gd.horizontalAlignment = SWT.FILL;
+ final Section mainPackageSection = toolkit.createSection(form.getBody(),
+ ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
+ mainPackageSection.setText(Messages.MainPackagePage_3);
+ mainPackageSection.setLayout(new GridLayout());
+ Composite mainPackageClient = toolkit.createComposite(mainPackageSection);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.marginWidth = gridLayout.marginHeight = 5;
+ gridLayout.numColumns = 2;
- mainPackageClient.setLayout(gridLayout);
- new RpmTagText(mainPackageClient, RpmTags.NAME, specfile);
- new RpmTagText(mainPackageClient, RpmTags.VERSION, specfile);
- new RpmTagText(mainPackageClient, RpmTags.RELEASE, specfile);
- new RpmTagText(mainPackageClient, RpmTags.URL, specfile);
- new RpmTagText(mainPackageClient, RpmTags.LICENSE, specfile);
- new RpmTagText(mainPackageClient, RpmTags.GROUP, specfile);
- new RpmTagText(mainPackageClient, RpmTags.EPOCH, specfile);
- new RpmTagText(mainPackageClient, RpmTags.BUILD_ROOT, specfile);
- new RpmTagText(mainPackageClient, RpmTags.BUILD_ARCH, specfile);
- new RpmTagText(mainPackageClient, RpmTags.SUMMARY, specfile, SWT.MULTI);
+ mainPackageClient.setLayout(gridLayout);
+ new RpmTagText(mainPackageClient, RpmTags.NAME, specfile);
+ new RpmTagText(mainPackageClient, RpmTags.VERSION, specfile);
+ new RpmTagText(mainPackageClient, RpmTags.RELEASE, specfile);
+ new RpmTagText(mainPackageClient, RpmTags.URL, specfile);
+ new RpmTagText(mainPackageClient, RpmTags.LICENSE, specfile);
+ new RpmTagText(mainPackageClient, RpmTags.GROUP, specfile);
+ new RpmTagText(mainPackageClient, RpmTags.EPOCH, specfile);
+ new RpmTagText(mainPackageClient, RpmTags.BUILD_ROOT, specfile);
+ new RpmTagText(mainPackageClient, RpmTags.BUILD_ARCH, specfile);
+ new RpmTagText(mainPackageClient, RpmTags.SUMMARY, specfile, SWT.MULTI);
- // BuildRequires
- final Section buildRequiresSection = toolkit.createSection(mainPackageClient,
- ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE
- | ExpandableComposite.EXPANDED);
- buildRequiresSection.setText(Messages.MainPackagePage_4);
- buildRequiresSection.setLayout(rowLayout);
- buildRequiresSection.setExpanded(false);
- Composite buildRequiresClient = toolkit.createComposite(buildRequiresSection);
- buildRequiresClient.setLayout(gridLayout);
- for (SpecfileTag buildRequire: specfile.getBuildRequires()) {
- new RpmTagText(buildRequiresClient, buildRequire, specfile);
- }
- buildRequiresSection.setClient(buildRequiresClient);
- toolkit.paintBordersFor(buildRequiresClient);
- toolkit.paintBordersFor(buildRequiresSection);
+ // BuildRequires
+ final Section buildRequiresSection = toolkit.createSection(mainPackageClient,
+ ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
+ buildRequiresSection.setText(Messages.MainPackagePage_4);
+ buildRequiresSection.setLayout(rowLayout);
+ buildRequiresSection.setExpanded(false);
+ Composite buildRequiresClient = toolkit.createComposite(buildRequiresSection);
+ buildRequiresClient.setLayout(gridLayout);
+ for (SpecfileTag buildRequire : specfile.getBuildRequires()) {
+ new RpmTagText(buildRequiresClient, buildRequire, specfile);
+ }
+ buildRequiresSection.setClient(buildRequiresClient);
+ toolkit.paintBordersFor(buildRequiresClient);
+ toolkit.paintBordersFor(buildRequiresSection);
- // Requires
- final Section requiresSection = toolkit.createSection(mainPackageClient,
- ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE
- | ExpandableComposite.EXPANDED);
- requiresSection.setText(Messages.MainPackagePage_5);
- requiresSection.setLayout(rowLayout);
- requiresSection.setExpanded(false);
- Composite requiresClient = toolkit.createComposite(requiresSection);
- requiresClient.setLayout(gridLayout);
- requiresClient.setLayoutData(gd);
- for (SpecfileTag require: specfile.getRequires()) {
- new RpmTagText(requiresClient, require, specfile);
- }
- requiresSection.setClient(requiresClient);
- toolkit.paintBordersFor(requiresClient);
- toolkit.paintBordersFor(requiresSection);
+ // Requires
+ final Section requiresSection = toolkit.createSection(mainPackageClient,
+ ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
+ requiresSection.setText(Messages.MainPackagePage_5);
+ requiresSection.setLayout(rowLayout);
+ requiresSection.setExpanded(false);
+ Composite requiresClient = toolkit.createComposite(requiresSection);
+ requiresClient.setLayout(gridLayout);
+ requiresClient.setLayoutData(gd);
+ for (SpecfileTag require : specfile.getRequires()) {
+ new RpmTagText(requiresClient, require, specfile);
+ }
+ requiresSection.setClient(requiresClient);
+ toolkit.paintBordersFor(requiresClient);
+ toolkit.paintBordersFor(requiresSection);
- mainPackageSection.setClient(mainPackageClient);
- toolkit.paintBordersFor(mainPackageClient);
- toolkit.paintBordersFor(mainPackageSection);
+ mainPackageSection.setClient(mainPackageClient);
+ toolkit.paintBordersFor(mainPackageClient);
+ toolkit.paintBordersFor(mainPackageSection);
- // subpackages
- final Section packagesSection = toolkit.createSection(form.getBody(),
- ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE
- | ExpandableComposite.EXPANDED);
- packagesSection.setText(Messages.MainPackagePage_6);
- packagesSection.setLayout(gridLayout);
- Composite packagesClient = toolkit.createComposite(packagesSection);
- packagesClient.setLayout(gridLayout);
- packagesClient.setLayoutData(gd);
- for (SpecfilePackage specfilePackage : specfile.getPackages()
- .getPackages()) {
- if (specfilePackage.isMainPackage()){
- continue;
- }
- final Section packageSection = toolkit.createSection(packagesClient,
- ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE
- | ExpandableComposite.EXPANDED);
- packageSection.setText(specfilePackage.getFullPackageName());
- packageSection.setExpanded(false);
- packageSection.setLayout(rowLayout);
- Composite packageClient = toolkit.createComposite(packageSection);
- packageClient.setLayout(gridLayout);
- packageClient.setLayoutData(gd);
- new RpmTagText(packageClient, RpmTags.SUMMARY, specfile, specfilePackage, SWT.MULTI);
- new RpmTagText(packageClient, RpmTags.GROUP, specfile, specfilePackage, SWT.MULTI);
+ // subpackages
+ final Section packagesSection = toolkit.createSection(form.getBody(),
+ ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
+ packagesSection.setText(Messages.MainPackagePage_6);
+ packagesSection.setLayout(gridLayout);
+ Composite packagesClient = toolkit.createComposite(packagesSection);
+ packagesClient.setLayout(gridLayout);
+ packagesClient.setLayoutData(gd);
+ for (SpecfilePackage specfilePackage : specfile.getPackages().getPackages()) {
+ if (specfilePackage.isMainPackage()) {
+ continue;
+ }
+ final Section packageSection = toolkit.createSection(packagesClient,
+ ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
+ packageSection.setText(specfilePackage.getFullPackageName());
+ packageSection.setExpanded(false);
+ packageSection.setLayout(rowLayout);
+ Composite packageClient = toolkit.createComposite(packageSection);
+ packageClient.setLayout(gridLayout);
+ packageClient.setLayoutData(gd);
+ new RpmTagText(packageClient, RpmTags.SUMMARY, specfile, specfilePackage, SWT.MULTI);
+ new RpmTagText(packageClient, RpmTags.GROUP, specfile, specfilePackage, SWT.MULTI);
- final Section packageRequiresSection = toolkit.createSection(packageClient,
- ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE
- | ExpandableComposite.EXPANDED);
- packageRequiresSection.setText(Messages.MainPackagePage_7);
- packageRequiresSection.setLayout(rowLayout);
- packageRequiresSection.setLayoutData(gd);
- Composite packageRequiresClient = toolkit.createComposite(packageRequiresSection);
- packageRequiresClient.setLayout(gridLayout);
- packageRequiresClient.setLayoutData(gd);
- for (SpecfileTag require: specfilePackage.getRequires()) {
- new RpmTagText(packageRequiresClient, require, specfile);
- }
- packageRequiresSection.setClient(packageRequiresClient);
+ final Section packageRequiresSection = toolkit.createSection(packageClient,
+ ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
+ packageRequiresSection.setText(Messages.MainPackagePage_7);
+ packageRequiresSection.setLayout(rowLayout);
+ packageRequiresSection.setLayoutData(gd);
+ Composite packageRequiresClient = toolkit.createComposite(packageRequiresSection);
+ packageRequiresClient.setLayout(gridLayout);
+ packageRequiresClient.setLayoutData(gd);
+ for (SpecfileTag require : specfilePackage.getRequires()) {
+ new RpmTagText(packageRequiresClient, require, specfile);
+ }
+ packageRequiresSection.setClient(packageRequiresClient);
- toolkit.paintBordersFor(packageRequiresClient);
- toolkit.paintBordersFor(packageRequiresSection);
+ toolkit.paintBordersFor(packageRequiresClient);
+ toolkit.paintBordersFor(packageRequiresSection);
- packageSection.setClient(packageClient);
- toolkit.paintBordersFor(packageClient);
- toolkit.paintBordersFor(packageSection);
- }
- packagesSection.setClient(packagesClient);
- toolkit.paintBordersFor(packagesClient);
- toolkit.paintBordersFor(packagesSection);
- managedForm.refresh();
- }
+ packageSection.setClient(packageClient);
+ toolkit.paintBordersFor(packageClient);
+ toolkit.paintBordersFor(packageSection);
+ }
+ packagesSection.setClient(packagesClient);
+ toolkit.paintBordersFor(packagesClient);
+ toolkit.paintBordersFor(packagesSection);
+ managedForm.refresh();
+ }
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/forms/SpecfileFormEditor.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/forms/SpecfileFormEditor.java
index b5b13f34f3..a49b5f8d73 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/forms/SpecfileFormEditor.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/forms/SpecfileFormEditor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Red Hat, Inc.
+ * Copyright (c) 2009, 2016 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
@@ -22,54 +22,52 @@ import org.eclipse.ui.forms.widgets.FormToolkit;
public class SpecfileFormEditor extends FormEditor {
- FormPage mainPackage;
- SpecfileEditor editor;
- private Specfile specfile;
+ SpecfileEditor editor;
- public SpecfileFormEditor() {
- super();
- editor = new SpecfileEditor();
- }
+ public SpecfileFormEditor() {
+ super();
+ editor = new SpecfileEditor();
+ }
- @Override
- protected FormToolkit createToolkit(Display display) {
- // Create a toolkit that shares colors between editors.
- return new FormToolkit(Display.getCurrent());
- }
+ @Override
+ protected FormToolkit createToolkit(Display display) {
+ // Create a toolkit that shares colors between editors.
+ return new FormToolkit(Display.getCurrent());
+ }
- @Override
- protected void addPages() {
- try {
- int index = addPage(editor, getEditorInput());
- setPageText(index, Messages.SpecfileFormEditor_0);
- specfile = editor.getSpecfile();
- mainPackage = new MainPackagePage(this, specfile);
- addPage(0, mainPackage);
- addPage(1, new RpmSectionPage(this, specfile, RpmSections.PREP_SECTION));
- addPage(2, new RpmSectionPage(this, specfile, RpmSections.BUILD_SECTION));
- addPage(3, new RpmSectionPage(this, specfile, RpmSections.INSTALL_SECTION));
- } catch (PartInitException e) {
- //
- }
- }
+ @Override
+ protected void addPages() {
+ try {
+ int index = addPage(editor, getEditorInput());
+ setPageText(index, Messages.SpecfileFormEditor_0);
+ Specfile specfile = editor.getSpecfile();
+ FormPage mainPackage = new MainPackagePage(this, specfile);
+ addPage(0, mainPackage);
+ addPage(1, new RpmSectionPage(this, specfile, RpmSections.PREP_SECTION));
+ addPage(2, new RpmSectionPage(this, specfile, RpmSections.BUILD_SECTION));
+ addPage(3, new RpmSectionPage(this, specfile, RpmSections.INSTALL_SECTION));
+ } catch (PartInitException e) {
+ //
+ }
+ }
- @Override
- public void doSave(IProgressMonitor monitor) {
- editor.doSave(monitor);
- }
+ @Override
+ public void doSave(IProgressMonitor monitor) {
+ editor.doSave(monitor);
+ }
- @Override
- public void doSaveAs() {
- //noop
- }
+ @Override
+ public void doSaveAs() {
+ // noop
+ }
- @Override
- public boolean isSaveAsAllowed() {
- return false;
- }
+ @Override
+ public boolean isSaveAsAllowed() {
+ return false;
+ }
- @Override
- public boolean isDirty() {
- return editor.isDirty();
- }
+ @Override
+ public boolean isDirty() {
+ return editor.isDirty();
+ }
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/parser/SpecfileSource.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/parser/SpecfileSource.java
index 7c9d2ace9e..8091f9c25f 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/parser/SpecfileSource.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/parser/SpecfileSource.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Red Hat, Inc.
+ * Copyright (c) 2007, 2016 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
@@ -23,134 +23,126 @@ import org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile;
import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement;
public class SpecfileSource extends SpecfileElement {
- private int number;
- private int lineNumber = -1;
- private String fileName;
-
- public enum SourceType {
- SOURCE, PATCH
- }
-
- private SourceType sourceType;
- private List<Integer> linesUsed;
-
- public SourceType getSourceType() {
- return sourceType;
- }
-
- public void setSourceType(SourceType sourceType) {
- this.sourceType = sourceType;
- }
-
- public SpecfileSource(int number, String fileName) {
- super("source"); //$NON-NLS-1$
- this.number = number;
- this.fileName = fileName;
- this.linesUsed = new ArrayList<>();
- }
-
- public String getFileName() {
- return resolve(fileName);
- }
-
- public void setFileName(String fileName) {
- this.fileName = fileName;
- }
-
- public int getNumber() {
- return number;
- }
-
- public void setNumber(int number) {
- this.number = number;
- }
-
- public void addLineUsed(int lineNumber) {
- linesUsed.add(Integer.valueOf(lineNumber));
- }
-
- public void removeLineUsed(int lineNumber) {
- linesUsed.remove(Integer.valueOf(lineNumber));
- }
-
- public List<Integer> getLinesUsed() {
- return linesUsed;
- }
-
- @Override
- public String toString() {
- if (sourceType == SourceType.SOURCE) {
- return MessageFormat.format(
- "Source #{0} (line #{1}, used on lines {2}) -> {3}", //$NON-NLS-1$
- number, lineNumber, getLinesUsed(), fileName);
- }
- return MessageFormat.format(
- "Patch #{0} (line #{1}, used on lines {2}) -> {3}", number, //$NON-NLS-1$
- lineNumber, getLinesUsed(), fileName);
- }
-
- // Note that changeReferences assumes that the number of the source/patch
- // has *already been set*. If this is not true, it will simply do nothing
- public void changeReferences(int oldPatchNumber) {
- Specfile specfile = this.getSpecfile();
- Pattern patchPattern;
- if (oldPatchNumber == 0) {
- patchPattern = Pattern
- .compile("%patch" + oldPatchNumber + "|%patch"); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- patchPattern = Pattern.compile("%patch" + oldPatchNumber); //$NON-NLS-1$
- }
- for (int lineNumber : getLinesUsed()) {
- String line;
- try {
- line = specfile.getLine(lineNumber);
- Matcher patchMatcher = patchPattern.matcher(line);
- if (!patchMatcher.find()) {
- System.out
- .println(Messages.getString("SpecfileSource.0") + patchPattern.pattern()); //$NON-NLS-1$
- // throw new BadLocationException("can't match " +
- // patchPattern);
- }
- specfile.changeLine(lineNumber, line.replaceAll(
- patchPattern.pattern(),
- Messages.getString("SpecfileSource.1") + number)); //$NON-NLS-1$
- } catch (BadLocationException e) {
- SpecfileLog.logError(e);
- }
- }
- }
-
- public void changeDeclaration(int oldPatchNumber) {
- Specfile specfile = this.getSpecfile();
- Pattern patchPattern;
- if (oldPatchNumber == 0) {
- patchPattern = Pattern.compile("Patch" + oldPatchNumber + "|Patch"); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- patchPattern = Pattern.compile("Patch" + oldPatchNumber); //$NON-NLS-1$
- }
- String line;
- try {
- line = specfile.getLine(lineNumber);
- Matcher patchMatcher = patchPattern.matcher(line);
- if (!patchMatcher.find()) {
- // TODO: Maybe we can throw a exception here.
- System.out
- .println(Messages.getString("SpecfileSource.2") + patchPattern.pattern()); //$NON-NLS-1$
- }
- specfile.changeLine(lineNumber,
- line.replaceAll(patchPattern.pattern(), "Patch" + number)); //$NON-NLS-1$
- } catch (BadLocationException e) {
- SpecfileLog.logError(e);
- }
- }
-
- @Override
- public int getLineNumber() {
- return lineNumber;
- }
-
- @Override
- public void setLineNumber(int lineNumber) {
- this.lineNumber = lineNumber;
- }
+ private int number;
+ private int lineNumber = -1;
+ private String fileName;
+
+ public enum SourceType {
+ SOURCE, PATCH
+ }
+
+ private SourceType sourceType;
+ private List<Integer> linesUsed;
+
+ public SourceType getSourceType() {
+ return sourceType;
+ }
+
+ public void setSourceType(SourceType sourceType) {
+ this.sourceType = sourceType;
+ }
+
+ public SpecfileSource(int number, String fileName) {
+ super("source"); //$NON-NLS-1$
+ this.number = number;
+ this.fileName = fileName;
+ this.linesUsed = new ArrayList<>();
+ }
+
+ public String getFileName() {
+ return resolve(fileName);
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+ public void addLineUsed(int lineNumber) {
+ linesUsed.add(Integer.valueOf(lineNumber));
+ }
+
+ public void removeLineUsed(int lineNumber) {
+ linesUsed.remove(Integer.valueOf(lineNumber));
+ }
+
+ public List<Integer> getLinesUsed() {
+ return linesUsed;
+ }
+
+ @Override
+ public String toString() {
+ if (sourceType == SourceType.SOURCE) {
+ return MessageFormat.format("Source #{0} (line #{1}, used on lines {2}) -> {3}", //$NON-NLS-1$
+ number, lineNumber, getLinesUsed(), fileName);
+ }
+ return MessageFormat.format("Patch #{0} (line #{1}, used on lines {2}) -> {3}", number, //$NON-NLS-1$
+ lineNumber, getLinesUsed(), fileName);
+ }
+
+ // Note that changeReferences assumes that the number of the source/patch
+ // has *already been set*. If this is not true, it will simply do nothing
+ public void changeReferences(int oldPatchNumber) {
+ Specfile specfile = this.getSpecfile();
+ Pattern patchPattern;
+ if (oldPatchNumber == 0) {
+ patchPattern = Pattern.compile("%patch" + oldPatchNumber + "|%patch"); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ patchPattern = Pattern.compile("%patch" + oldPatchNumber); //$NON-NLS-1$
+ }
+ for (int lineNumber : getLinesUsed()) {
+ String line;
+ try {
+ line = specfile.getLine(lineNumber);
+ Matcher patchMatcher = patchPattern.matcher(line);
+ if (!patchMatcher.find()) {
+ // throw new BadLocationException("can't match " +
+ // patchPattern);
+ }
+ specfile.changeLine(lineNumber,
+ line.replaceAll(patchPattern.pattern(), Messages.getString("SpecfileSource.1") + number)); //$NON-NLS-1$
+ } catch (BadLocationException e) {
+ SpecfileLog.logError(e);
+ }
+ }
+ }
+
+ public void changeDeclaration(int oldPatchNumber) {
+ Specfile specfile = this.getSpecfile();
+ Pattern patchPattern;
+ if (oldPatchNumber == 0) {
+ patchPattern = Pattern.compile("Patch" + oldPatchNumber + "|Patch"); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ patchPattern = Pattern.compile("Patch" + oldPatchNumber); //$NON-NLS-1$
+ }
+ String line;
+ try {
+ line = specfile.getLine(lineNumber);
+ Matcher patchMatcher = patchPattern.matcher(line);
+ if (!patchMatcher.find()) {
+ // TODO: Maybe we can throw a exception here.
+ System.out.println(Messages.getString("SpecfileSource.2") + patchPattern.pattern()); //$NON-NLS-1$
+ }
+ specfile.changeLine(lineNumber, line.replaceAll(patchPattern.pattern(), "Patch" + number)); //$NON-NLS-1$
+ } catch (BadLocationException e) {
+ SpecfileLog.logError(e);
+ }
+ }
+
+ @Override
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ @Override
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/preferences/RpmProposalsPreferencePage.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/preferences/RpmProposalsPreferencePage.java
index 1bbc2e75bb..c1b7bde2d2 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/preferences/RpmProposalsPreferencePage.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/preferences/RpmProposalsPreferencePage.java
@@ -74,8 +74,7 @@ public class RpmProposalsPreferencePage extends FieldEditorPreferencePage implem
PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null);
}
});
- Composite fieldEditorComposite = (Composite) super.createContents(parent);
- return fieldEditorComposite;
+ return super.createContents(parent);
}
private FieldEditor rpmtoolsRadioGroupFieldEditor() {
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/preferences/TaskTagsPreferencePage.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/preferences/TaskTagsPreferencePage.java
index 3f44cb1aec..bb90d5bd8f 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/preferences/TaskTagsPreferencePage.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/preferences/TaskTagsPreferencePage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Red Hat, Inc.
+ * Copyright (c) 2008, 2016 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
@@ -19,61 +19,59 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
-public class TaskTagsPreferencePage extends FieldEditorPreferencePage implements
- IWorkbenchPreferencePage {
+public class TaskTagsPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
- public TaskTagsPreferencePage() {
- super(GRID);
- setPreferenceStore(Activator.getDefault().getPreferenceStore());
- }
+ public TaskTagsPreferencePage() {
+ super(GRID);
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ }
- @Override
- public void init(IWorkbench workbench) {
- }
+ @Override
+ public void init(IWorkbench workbench) {
+ }
- @Override
- protected void createFieldEditors() {
- addField(new TasksListEditor(PreferenceConstants.P_TASK_TAGS,
- Messages.TaskTagsPreferencePage_0,
- getFieldEditorParent()));
- }
+ @Override
+ protected void createFieldEditors() {
+ addField(new TasksListEditor(PreferenceConstants.P_TASK_TAGS, Messages.TaskTagsPreferencePage_0,
+ getFieldEditorParent()));
+ }
- static class TasksListEditor extends ListEditor {
+ static class TasksListEditor extends ListEditor {
- public TasksListEditor(String name, String labelText, Composite parent) {
- super(name, labelText, parent);
- }
+ public TasksListEditor(String name, String labelText, Composite parent) {
+ super(name, labelText, parent);
+ }
- @Override
- protected String createList(String[] items) {
- StringBuilder itemsString = new StringBuilder();
- for (String item : items) {
- itemsString.append(item + ';');
- }
- return itemsString.toString();
- }
+ @Override
+ protected String createList(String[] items) {
+ StringBuilder itemsString = new StringBuilder();
+ for (String item : items) {
+ itemsString.append(item).append(';');
+ }
+ return itemsString.toString();
+ }
- @Override
- protected String getNewInputObject() {
- String result = null;
- // open an input dialog so that the user can enter a new task tag
- InputDialog inputDialog = new InputDialog(getShell(),
- Messages.TaskTagsPreferencePage_1, Messages.TaskTagsPreferencePage_2, "", null); //$NON-NLS-1$
- int returnCode = inputDialog.open();
+ @Override
+ protected String getNewInputObject() {
+ String result = null;
+ // open an input dialog so that the user can enter a new task tag
+ InputDialog inputDialog = new InputDialog(getShell(), Messages.TaskTagsPreferencePage_1,
+ Messages.TaskTagsPreferencePage_2, "", null); //$NON-NLS-1$
+ int returnCode = inputDialog.open();
- if (returnCode == Window.OK) {
- result = inputDialog.getValue();
- }
+ if (returnCode == Window.OK) {
+ result = inputDialog.getValue();
+ }
- return result;
+ return result;
- }
+ }
- @Override
- protected String[] parseString(String stringList) {
- return stringList.split(";"); //$NON-NLS-1$
- }
+ @Override
+ protected String[] parseString(String stringList) {
+ return stringList.split(";"); //$NON-NLS-1$
+ }
- }
+ }
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/SpecfileParser.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/SpecfileParser.java
index 8a20c3a32e..5a836bcaca 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/SpecfileParser.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/SpecfileParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Red Hat, Inc.
+ * Copyright (c) 2007, 2016 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
@@ -58,612 +58,539 @@ import org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileTaskHandler;
public class SpecfileParser {
- private static final String DEFINE_SEPARATOR = ":"; //$NON-NLS-1$
-
- private static final String SPACE_REGEX = "\\s+"; //$NON-NLS-1$
-
- /**
- * These are SRPM-wide sections, and they also cannot have any flags like -n
- * or -f. Hence they are called simple. This is probably a misleading name
- * and it should be renamed to reflect that they are SRPM-wide sections.
- */
- public static final String[] simpleSections = { PREP_SECTION, BUILD_SECTION,
- INSTALL_SECTION, CLEAN_SECTION, CHANGELOG_SECTION };
-
- /**
- * These are sections that apply to a particular sub-package (i.e. binary
- * RPM), including the main package. These can also have flags like -f or -n
- * appended to them, hence they are called complex. This should probably be
- * renamed to reflect that they are in fact per-RPM sections.
- */
- private static String[] complexSections = { PRETRANS_SECTION, PRE_SECTION,
- PREUN_SECTION, POST_SECTION, POSTUN_SECTION, POSTTRANS_SECTION,
- FILES_SECTION, PACKAGE_SECTION, DESCRIPTION_SECTION };
-
- private static String[] simpleDefinitions = { RpmTags.EPOCH, RpmTags.NAME,
- RpmTags.VERSION, RpmTags.RELEASE, RpmTags.URL, RpmTags.BUILD_ARCH };
-
- private static String[] directValuesDefinitions = { RpmTags.LICENSE,
- RpmTags.BUILD_ROOT };
- // Note that the ordering here should match that in
- // SpecfileSource#SOURCETYPE
- private static String[] complexDefinitions = { "Source", "Patch" }; //$NON-NLS-1$ //$NON-NLS-2$
-
- private static String[] packageLevelDefinitions = { RpmTags.SUMMARY,
- RpmTags.GROUP, RpmTags.OBSOLETES, RpmTags.PROVIDES,
- RpmTags.REQUIRES, RpmTags.REQUIRES_PRE, RpmTags.REQUIRES_POST,
- RpmTags.REQUIRES_POSTUN };
-
- private SpecfileErrorHandler errorHandler;
- private SpecfileTaskHandler taskHandler;
- private IPreferenceStore store;
- private SpecfileSection lastSection;
- private SpecfilePackage activePackage;
-
- public SpecfileParser() {
- store = Activator.getDefault().getPreferenceStore();
- }
-
- public Specfile parse(IDocument specfileDocument) {
-
- // remove all existing markers, if a SpecfileErrorHandler is
- // instantiated.
- if (errorHandler != null) {
- errorHandler.removeExistingMarkers();
- }
- if (taskHandler != null) {
- taskHandler.removeExistingMarkers();
- }
- LineNumberReader reader = new LineNumberReader(new StringReader(
- specfileDocument.get()));
- String line = ""; //$NON-NLS-1$
- int lineStartPosition = 0;
- Specfile specfile = new Specfile();
- specfile.setDocument(specfileDocument);
- try {
- while ((line = reader.readLine()) != null) {
- if (taskHandler != null) {
- generateTaskMarker(reader.getLineNumber() - 1, line);
- }
- // IDocument.getLine(#) is 0-indexed whereas
- // reader.getLineNumber appears to be 1-indexed
- SpecfileElement element = parseLine(line, specfile, reader
- .getLineNumber() - 1);
- if (element != null) {
- element.setLineNumber(reader.getLineNumber() - 1);
- element.setLineStartPosition(lineStartPosition);
- element.setLineEndPosition(lineStartPosition
- + line.length());
- if (element.getClass() == SpecfileTag.class) {
- SpecfileTag tag = (SpecfileTag) element;
- specfile.addDefine(tag);
- } else if ((element.getClass() == SpecfilePatchMacro.class)) {
- SpecfilePatchMacro thisPatchMacro = (SpecfilePatchMacro) element;
- if (thisPatchMacro != null) {
- thisPatchMacro.setSpecfile(specfile);
- }
- SpecfileSource thisPatch = specfile
- .getPatch(thisPatchMacro.getPatchNumber());
- if (thisPatch != null) {
- thisPatch.addLineUsed(reader.getLineNumber() - 1);
- thisPatch.setSpecfile(specfile);
- }
- } else if ((element.getClass() == SpecfileDefine.class)) {
- specfile.addDefine((SpecfileDefine) element);
- } else if ((element.getClass() == SpecfileSource.class)) {
- SpecfileSource source = (SpecfileSource) element;
-
- source.setLineNumber(reader.getLineNumber() - 1);
- if (source.getSourceType() == SpecfileSource.SourceType.SOURCE) {
- specfile.addSource(source);
- } else {
- specfile.addPatch(source);
- }
- }
- }
-
- // sets the last SpecfileSection's end line to that of the end of
- // the end of the specfileDocument.
- // SpecfileParser#parseMacro will handle correcting the end line
- // if the last SpecfileSection was not truly the last 1
- // This is for the purpose of making DocumentRangeNode work
- if (lastSection != null) {
- lastSection.setSectionEndLine(specfileDocument
- .getNumberOfLines() - 1);
- }
-
- // The +1 is for the line delimiter. FIXME: will we end up off
- // by one on the last line?
- lineStartPosition += line.length() + 1;
- }
- } catch (IOException e) {
- // FIXME
- SpecfileLog.logError(e);
- }
- return specfile;
- }
-
- /**
- * Parse a File into a specfile
- *
- * @param file The File to be parsed
- * @return A Specfile object
- */
- public Specfile parse(IFile file) {
- SpecfileParser parser = new SpecfileParser();
- StringBuilder sb = new StringBuilder();
- String line = null;
- try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(
- file.getContents()));
- while ((line = reader.readLine()) != null) {
- sb.append(line + "\n"); //$NON-NLS-1$
- }
- } catch (IOException e) {
- SpecfileLog.logError(Messages.getString("SpecfileParseFile.1"), e); //$NON-NLS-1$
- } catch (CoreException e) {
- SpecfileLog.logError(Messages.getString("SpecfileParseFile.2"), e); //$NON-NLS-1$
- }
- return parser.parse(sb.toString());
- }
-
- private void generateTaskMarker(int lineNumber, String line) {
- String[] taskTags = store.getString(PreferenceConstants.P_TASK_TAGS)
- .split(";"); //$NON-NLS-1$
- int commentCharIndex = line
- .indexOf(ISpecfileSpecialSymbols.COMMENT_START);
- if (commentCharIndex > -1) {
- for (String item : taskTags) {
- int taskIndex = line.indexOf(item);
- if (taskIndex > commentCharIndex) {
- taskHandler.handleTask(lineNumber, line, item);
- }
- }
- }
- }
-
- public Specfile parse(String specfileContent) {
- return parse(new Document(specfileContent));
- }
-
- public SpecfileElement parseLine(String lineText, Specfile specfile,
- int lineNumber) {
-
- if (lineText.startsWith("%")) {//$NON-NLS-1$
- return parseMacro(lineText, specfile, lineNumber);
- }
-
- for (String simpleDefinition : simpleDefinitions) {
- if (lineText.startsWith(simpleDefinition + DEFINE_SEPARATOR)) {
- return parseSimpleDefinition(lineText, specfile, lineNumber,
- false);
- }
- }
- for (String directValuesDefinition : directValuesDefinitions) {
- if (lineText.startsWith(directValuesDefinition + DEFINE_SEPARATOR)) {
- return parseDirectDefinition(lineText, specfile, lineNumber);
- }
- }
- for (String directValuesDefinition : packageLevelDefinitions) {
- if (lineText.startsWith(directValuesDefinition + DEFINE_SEPARATOR)) {
- SpecfileElement definition = parseDirectDefinition(lineText,
- specfile, lineNumber);
- if (directValuesDefinition.equals(RpmTags.REQUIRES)) {
- if (activePackage != null) {
- activePackage.addRequire((SpecfileTag) definition);
- } else {
- specfile.addRequire((SpecfileTag) definition);
- }
- }
- return definition;
- }
- }
-
- if (lineText.startsWith(complexDefinitions[0])
- && lineText.contains(DEFINE_SEPARATOR)) {
- return parseComplexDefinition(lineText, lineNumber,
- SourceType.SOURCE);
- } else if (lineText.startsWith(complexDefinitions[1])
- && lineText.contains(DEFINE_SEPARATOR)) {
- return parseComplexDefinition(lineText, lineNumber,
- SourceType.PATCH);
- } else if (lineText.startsWith("BuildRequires")) { //$NON-NLS-1$
- return parseBuildRequire(lineText, lineNumber, specfile);
- }
-
- return null;
- }
-
- private SpecfileElement parseBuildRequire(String lineText, int lineNumber,
- Specfile specfile) {
- String value = lineText.substring(lineText.indexOf(':') + 1,
- lineText.length()).trim();
- SpecfileDefine buildRequire = new SpecfileDefine(
- "BuildRequires", value, specfile, null); //$NON-NLS-1$
- buildRequire.setLineNumber(lineNumber);
- specfile.addBuildRequire(buildRequire);
- return buildRequire;
- }
-
- private SpecfileSection parseSection(String lineText, Specfile specfile,
- int lineNumber) {
- List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
- SpecfileSection toReturn = null;
- boolean isSimpleSection = false;
- for (Iterator<String> iter = tokens.iterator(); iter.hasNext();) {
- String token = iter.next();
-
- // Sections
- // Simple Section Headers
- for (String simpleSection : simpleSections) {
- if (token.equals(simpleSection)) {
- toReturn = new SpecfileSection(token.substring(1), specfile);
- specfile.addSection(toReturn);
- isSimpleSection = true;
- }
-
- }
-
- // Complex Section Headers
- for (String complexSection : complexSections) {
- if (token.equals(complexSection)) {
- String name = token.substring(1);
- if (!name.equals("package")) { //$NON-NLS-1$
- toReturn = new SpecfileSection(name, specfile);
- specfile.addComplexSection(toReturn);
- }
- while (iter.hasNext()) {
- String nextToken = iter.next();
- if (nextToken.equals("-n")) { //$NON-NLS-1$
- if (!iter.hasNext()) {
- errorHandler
- .handleError(new SpecfileParseException(
- Messages
- .getString("SpecfileParser.1") //$NON-NLS-1$
- + name
- + Messages
- .getString("SpecfileParser.2"), //$NON-NLS-1$
- lineNumber, 0, lineText
- .length(),
- IMarker.SEVERITY_ERROR));
- continue;
- }
-
- nextToken = iter.next();
- if (nextToken.startsWith("-")) { //$NON-NLS-1$
- errorHandler
- .handleError(new SpecfileParseException(
- Messages
- .getString("SpecfileParser.3") //$NON-NLS-1$
- + nextToken
- + Messages
- .getString("SpecfileParser.4"), //$NON-NLS-1$
- lineNumber, 0, lineText
- .length(),
- IMarker.SEVERITY_ERROR));
- }
-
- } else if (nextToken.equals("-p")) { //$NON-NLS-1$
- // FIXME: rest of line is the actual section
- break;
- } else if (nextToken.equals("-f")) { //$NON-NLS-1$
- break;
- }
-
- // this is a package
- if (toReturn == null) {
- SpecfilePackage tmpPackage = specfile
- .getPackage(nextToken);
-
- if (tmpPackage == null) {
- tmpPackage = new SpecfilePackage(nextToken,
- specfile);
- specfile.addPackage(tmpPackage);
- }
- activePackage = tmpPackage;
- return tmpPackage;
- }
-
- // this is another section
- SpecfilePackage enclosingPackage = specfile
- .getPackage(nextToken);
- if (enclosingPackage == null) {
- enclosingPackage = new SpecfilePackage(nextToken,
- specfile);
- specfile.addPackage(enclosingPackage);
- }
- toReturn.setPackage(enclosingPackage);
- enclosingPackage.addSection(toReturn);
- }
- }
- }
- }
-
- // if this package is part of the top level package, add it to
- // it
- if (toReturn != null && toReturn.getPackage() == null) {
- SpecfilePackage topPackage = specfile
- .getPackage(specfile.getName());
- if (topPackage == null) {
- topPackage = new SpecfilePackage(specfile.getName(), specfile);
- specfile.addPackage(topPackage);
- }
- if (!isSimpleSection) {
- topPackage.addSection(toReturn);
- }
- }
- if (lastSection != null) {
- lastSection.setSectionEndLine(lineNumber);
- }
- return toReturn;
- }
-
- private SpecfileElement parseMacro(String lineText, Specfile specfile,
- int lineNumber) {
- // FIXME: handle other macros
-
- if (lineText.startsWith("%define") || lineText.startsWith("%global")) { //$NON-NLS-1$ //$NON-NLS-2$
- return parseDefine(lineText, specfile, lineNumber);
- } else if (lineText.startsWith("%patch")) { //$NON-NLS-1$
- return parsePatch(lineText, lineNumber);
- }
-
- String[] sections = new String[simpleSections.length
- + complexSections.length];
- System.arraycopy(simpleSections, 0, sections, 0, simpleSections.length);
- System.arraycopy(complexSections, 0, sections, simpleSections.length,
- complexSections.length);
- for (String section : sections) {
- if (lineText.startsWith(section)) {
- lastSection = parseSection(lineText, specfile, lineNumber);
- if (lastSection != null) {
- lastSection.setSectionEndLine(lineNumber + 1);
- }
- return lastSection;
- }
- }
- // FIXME: add handling of lines containing %{SOURCENNN}
- return null;
- }
-
- private SpecfileElement parsePatch(String lineText, int lineNumber) {
-
- SpecfilePatchMacro toReturn = null;
-
- List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
-
- for (String token : tokens) {
- // %patchN+
- try {
- if (token.startsWith("%patch")) { //$NON-NLS-1$
- int patchNumber = 0;
- if (token.length() > 6) {
- patchNumber = Integer.parseInt(token.substring(6));
- }
- toReturn = new SpecfilePatchMacro(patchNumber);
- }
- } catch (NumberFormatException e) {
- errorHandler.handleError(new SpecfileParseException(
- Messages.getString("SpecfileParser.5"), //$NON-NLS-1$
- lineNumber, 0, lineText.length(),
- IMarker.SEVERITY_ERROR));
- return null;
- }
- }
-
- return toReturn;
- }
-
- private SpecfileDefine parseDefine(String lineText, Specfile specfile,
- int lineNumber) {
- List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
- SpecfileDefine toReturn = null;
- for (Iterator<String> iter = tokens.iterator(); iter.hasNext();) {
- // Eat the actual "%define" or "%global" token
- iter.next();
- while (iter.hasNext()) {
- String defineName = iter.next();
- // FIXME: is this true? investigate in rpmbuild source
- // Definitions must being with a letter
- if (!Character.isLetter(defineName.charAt(0))
- && (defineName.charAt(0) != '_')) {
- errorHandler.handleError(new SpecfileParseException(
- Messages.getString("SpecfileParser.6"), //$NON-NLS-1$
- lineNumber, 0, lineText.length(),
- IMarker.SEVERITY_ERROR));
- return null;
- } else {
- if (iter.hasNext()) {
- String defineStringValue = iter.next();
- // Defines that are more than one token
- if (iter.hasNext()) {
- defineStringValue = lineText.substring(lineText
- .indexOf(defineStringValue));
- // Eat up the rest of the tokens
- while (iter.hasNext()) {
- iter.next();
- }
- }
- int defineIntValue = -1;
- try {
- defineIntValue = Integer
- .parseInt(defineStringValue);
- } catch (NumberFormatException e) {
- toReturn = new SpecfileDefine(defineName,
- defineStringValue, specfile, null);
- }
- if (toReturn == null) {
- toReturn = new SpecfileDefine(defineName,
- defineIntValue, specfile, null);
- }
- } else {
- errorHandler.handleError(new SpecfileParseException(defineName+
- Messages.getString("SpecfileParser.14"), //$NON-NLS-1$
- lineNumber, 0, lineText.length(),
- IMarker.SEVERITY_ERROR));
- }
- }
- }
- }
- return toReturn;
- }
-
- private SpecfileElement parseComplexDefinition(String lineText,
- int lineNumber, SourceType sourceType) {
- SpecfileSource toReturn = null;
- List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
- int number = -1;
- boolean firstToken = true;
-
- for (Iterator<String> iter = tokens.iterator(); iter.hasNext();) {
- String token = iter.next();
- if (token != null && token.length() > 0) {
- if (firstToken) {
- if (token.endsWith(DEFINE_SEPARATOR)) {
- token = token.substring(0, token.length() - 1);
- } else {
- // FIXME: come up with a better error message here
- // FIXME: what about descriptions that begin a line with
- // the word "Source" or "Patch"?
- errorHandler.handleError(new SpecfileParseException(
- Messages.getString("SpecfileParser.8"), //$NON-NLS-1$
- lineNumber, 0, lineText.length(),
- IMarker.SEVERITY_WARNING));
- return null;
- }
- if (sourceType == SourceType.PATCH) {
- if (token.length() > 5) {
- number = Integer.parseInt(token.substring(5));
- if (!("patch" + number).equalsIgnoreCase(token)) { //$NON-NLS-1$
- errorHandler
- .handleError(new SpecfileParseException(
- Messages
- .getString("SpecfileParser.10"), //$NON-NLS-1$
- lineNumber, 0, lineText
- .length(),
- IMarker.SEVERITY_ERROR));
- return null;
- }
- } else {
- number = 0;
- }
- } else {
- if (token.length() > 6) {
- number = Integer.parseInt(token.substring(6));
- if (!("source" + number).equalsIgnoreCase(token)) { //$NON-NLS-1$
- errorHandler
- .handleError(new SpecfileParseException(
- Messages
- .getString("SpecfileParser.11"), //$NON-NLS-1$
- lineNumber, 0, lineText
- .length(),
- IMarker.SEVERITY_ERROR));
- return null;
- }
- } else {
- number = 0;
- }
- }
- toReturn = new SpecfileSource(number, ""); //$NON-NLS-1$
- toReturn.setSourceType(sourceType);
- firstToken = false;
- } else {
- // toReturn should never be null but check just in case
- if (toReturn != null) {
- toReturn.setFileName(token);
- }
- if (iter.hasNext()) {
- errorHandler.handleError(new SpecfileParseException(
- Messages.getString("SpecfileParser.12"), //$NON-NLS-1$
- lineNumber, 0, lineText.length(),
- IMarker.SEVERITY_ERROR));
- }
- }
- }
- }
-
- return toReturn;
- }
-
- private SpecfileElement parseSimpleDefinition(String lineText,
- Specfile specfile, int lineNumber, boolean warnMultipleValues) {
- List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
- SpecfileTag toReturn = null;
-
- for (Iterator<String> iter = tokens.iterator(); iter.hasNext();) {
- String token = iter.next();
-
- if (token.length() <= 0) {
- break;
- }
-
- if (iter.hasNext()) {
- String possValue = iter.next();
- if (possValue.startsWith("%") && iter.hasNext()) { //$NON-NLS-1$
- possValue += ' ' + iter.next();
- }
- toReturn = new SpecfileTag(token.substring(0,
- token.length() - 1).toLowerCase(), possValue, specfile,
- null);
- if (iter.hasNext() && !warnMultipleValues) {
- errorHandler.handleError(new SpecfileParseException(
- token.substring(0, token.length() - 1)
- + Messages.getString("SpecfileParser.13"), //$NON-NLS-1$
- lineNumber, 0, lineText.length(),
- IMarker.SEVERITY_ERROR));
- return null;
- }
- } else {
- errorHandler.handleError(new SpecfileParseException(token
- .substring(0, token.length() - 1)
- + Messages.getString("SpecfileParser.14"), lineNumber, //$NON-NLS-1$
- 0, lineText.length(), IMarker.SEVERITY_ERROR));
- toReturn = null;
- }
- }
- if ((toReturn != null)) {
- String returnStringValue = toReturn.getStringValue();
- if (returnStringValue != null) {
- try {
- int intValue = Integer.parseInt(returnStringValue);
- toReturn.setValue(intValue);
- } catch (NumberFormatException e) {
- if (toReturn.getName().equalsIgnoreCase(RpmTags.EPOCH)) {
- errorHandler
- .handleError(new SpecfileParseException(
- Messages.getString("SpecfileParser.16"), lineNumber, //$NON-NLS-1$
- 0, lineText.length(),
- IMarker.SEVERITY_ERROR));
- toReturn = null;
- }
- }
- }
- }
- return toReturn;
- }
-
- private SpecfileElement parseDirectDefinition(String lineText,
- Specfile specfile, int lineNumber) {
- String[] parts = lineText.split(DEFINE_SEPARATOR, 2);
- SpecfileTag directDefinition;
- if (parts.length == 2) {
- directDefinition = new SpecfileTag(parts[0], parts[1].trim(),
- specfile, activePackage);
- directDefinition.setLineNumber(lineNumber);
- } else {
- errorHandler.handleError(new SpecfileParseException(parts[0]
- + Messages.getString("SpecfileParser.14"), lineNumber, //$NON-NLS-1$
- 0, lineText.length(), IMarker.SEVERITY_ERROR));
- directDefinition = null;
- }
- return directDefinition;
- }
-
- public void setErrorHandler(SpecfileErrorHandler specfileErrorHandler) {
- errorHandler = specfileErrorHandler;
- }
-
- public void setTaskHandler(SpecfileTaskHandler specfileTaskHandler) {
- taskHandler = specfileTaskHandler;
- }
+ private static final String DEFINE_SEPARATOR = ":"; //$NON-NLS-1$
+
+ private static final String SPACE_REGEX = "\\s+"; //$NON-NLS-1$
+
+ /**
+ * These are SRPM-wide sections, and they also cannot have any flags like -n
+ * or -f. Hence they are called simple. This is probably a misleading name
+ * and it should be renamed to reflect that they are SRPM-wide sections.
+ */
+ public static final String[] simpleSections = { PREP_SECTION, BUILD_SECTION, INSTALL_SECTION, CLEAN_SECTION,
+ CHANGELOG_SECTION };
+
+ /**
+ * These are sections that apply to a particular sub-package (i.e. binary
+ * RPM), including the main package. These can also have flags like -f or -n
+ * appended to them, hence they are called complex. This should probably be
+ * renamed to reflect that they are in fact per-RPM sections.
+ */
+ private static String[] complexSections = { PRETRANS_SECTION, PRE_SECTION, PREUN_SECTION, POST_SECTION,
+ POSTUN_SECTION, POSTTRANS_SECTION, FILES_SECTION, PACKAGE_SECTION, DESCRIPTION_SECTION };
+
+ private static String[] simpleDefinitions = { RpmTags.EPOCH, RpmTags.NAME, RpmTags.VERSION, RpmTags.RELEASE,
+ RpmTags.URL, RpmTags.BUILD_ARCH };
+
+ private static String[] directValuesDefinitions = { RpmTags.LICENSE, RpmTags.BUILD_ROOT };
+ // Note that the ordering here should match that in
+ // SpecfileSource#SOURCETYPE
+ private static String[] complexDefinitions = { "Source", "Patch" }; //$NON-NLS-1$ //$NON-NLS-2$
+
+ private static String[] packageLevelDefinitions = { RpmTags.SUMMARY, RpmTags.GROUP, RpmTags.OBSOLETES,
+ RpmTags.PROVIDES, RpmTags.REQUIRES, RpmTags.REQUIRES_PRE, RpmTags.REQUIRES_POST, RpmTags.REQUIRES_POSTUN };
+
+ private SpecfileErrorHandler errorHandler;
+ private SpecfileTaskHandler taskHandler;
+ private IPreferenceStore store;
+ private SpecfileSection lastSection;
+ private SpecfilePackage activePackage;
+
+ public SpecfileParser() {
+ store = Activator.getDefault().getPreferenceStore();
+ }
+
+ public Specfile parse(IDocument specfileDocument) {
+
+ // remove all existing markers, if a SpecfileErrorHandler is
+ // instantiated.
+ if (errorHandler != null) {
+ errorHandler.removeExistingMarkers();
+ }
+ if (taskHandler != null) {
+ taskHandler.removeExistingMarkers();
+ }
+ LineNumberReader reader = new LineNumberReader(new StringReader(specfileDocument.get()));
+ String line = ""; //$NON-NLS-1$
+ int lineStartPosition = 0;
+ Specfile specfile = new Specfile();
+ specfile.setDocument(specfileDocument);
+ try {
+ while ((line = reader.readLine()) != null) {
+ if (taskHandler != null) {
+ generateTaskMarker(reader.getLineNumber() - 1, line);
+ }
+ // IDocument.getLine(#) is 0-indexed whereas
+ // reader.getLineNumber appears to be 1-indexed
+ SpecfileElement element = parseLine(line, specfile, reader.getLineNumber() - 1);
+ if (element != null) {
+ element.setLineNumber(reader.getLineNumber() - 1);
+ element.setLineStartPosition(lineStartPosition);
+ element.setLineEndPosition(lineStartPosition + line.length());
+ if (element.getClass() == SpecfileTag.class) {
+ SpecfileTag tag = (SpecfileTag) element;
+ specfile.addDefine(tag);
+ } else if ((element.getClass() == SpecfilePatchMacro.class)) {
+ SpecfilePatchMacro thisPatchMacro = (SpecfilePatchMacro) element;
+ if (thisPatchMacro != null) {
+ thisPatchMacro.setSpecfile(specfile);
+ }
+ SpecfileSource thisPatch = specfile.getPatch(thisPatchMacro.getPatchNumber());
+ if (thisPatch != null) {
+ thisPatch.addLineUsed(reader.getLineNumber() - 1);
+ thisPatch.setSpecfile(specfile);
+ }
+ } else if ((element.getClass() == SpecfileDefine.class)) {
+ specfile.addDefine((SpecfileDefine) element);
+ } else if ((element.getClass() == SpecfileSource.class)) {
+ SpecfileSource source = (SpecfileSource) element;
+
+ source.setLineNumber(reader.getLineNumber() - 1);
+ if (source.getSourceType() == SpecfileSource.SourceType.SOURCE) {
+ specfile.addSource(source);
+ } else {
+ specfile.addPatch(source);
+ }
+ }
+ }
+
+ // sets the last SpecfileSection's end line to that of the end
+ // of
+ // the end of the specfileDocument.
+ // SpecfileParser#parseMacro will handle correcting the end line
+ // if the last SpecfileSection was not truly the last 1
+ // This is for the purpose of making DocumentRangeNode work
+ if (lastSection != null) {
+ lastSection.setSectionEndLine(specfileDocument.getNumberOfLines() - 1);
+ }
+
+ // The +1 is for the line delimiter. FIXME: will we end up off
+ // by one on the last line?
+ lineStartPosition += line.length() + 1;
+ }
+ } catch (IOException e) {
+ // FIXME
+ SpecfileLog.logError(e);
+ }
+ return specfile;
+ }
+
+ /**
+ * Parse a File into a specfile
+ *
+ * @param file
+ * The File to be parsed
+ * @return A Specfile object
+ */
+ public Specfile parse(IFile file) {
+ SpecfileParser parser = new SpecfileParser();
+ StringBuilder sb = new StringBuilder();
+ String line = null;
+ try {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents()));
+ while ((line = reader.readLine()) != null) {
+ sb.append(line).append('\n');
+ }
+ } catch (IOException e) {
+ SpecfileLog.logError(Messages.getString("SpecfileParseFile.1"), e); //$NON-NLS-1$
+ } catch (CoreException e) {
+ SpecfileLog.logError(Messages.getString("SpecfileParseFile.2"), e); //$NON-NLS-1$
+ }
+ return parser.parse(sb.toString());
+ }
+
+ private void generateTaskMarker(int lineNumber, String line) {
+ String[] taskTags = store.getString(PreferenceConstants.P_TASK_TAGS).split(";"); //$NON-NLS-1$
+ int commentCharIndex = line.indexOf(ISpecfileSpecialSymbols.COMMENT_START);
+ if (commentCharIndex > -1) {
+ for (String item : taskTags) {
+ int taskIndex = line.indexOf(item);
+ if (taskIndex > commentCharIndex) {
+ taskHandler.handleTask(lineNumber, line, item);
+ }
+ }
+ }
+ }
+
+ public Specfile parse(String specfileContent) {
+ return parse(new Document(specfileContent));
+ }
+
+ public SpecfileElement parseLine(String lineText, Specfile specfile, int lineNumber) {
+
+ if (lineText.startsWith("%")) {//$NON-NLS-1$
+ return parseMacro(lineText, specfile, lineNumber);
+ }
+
+ for (String simpleDefinition : simpleDefinitions) {
+ if (lineText.startsWith(simpleDefinition + DEFINE_SEPARATOR)) {
+ return parseSimpleDefinition(lineText, specfile, lineNumber, false);
+ }
+ }
+ for (String directValuesDefinition : directValuesDefinitions) {
+ if (lineText.startsWith(directValuesDefinition + DEFINE_SEPARATOR)) {
+ return parseDirectDefinition(lineText, specfile, lineNumber);
+ }
+ }
+ for (String directValuesDefinition : packageLevelDefinitions) {
+ if (lineText.startsWith(directValuesDefinition + DEFINE_SEPARATOR)) {
+ SpecfileElement definition = parseDirectDefinition(lineText, specfile, lineNumber);
+ if (directValuesDefinition.equals(RpmTags.REQUIRES)) {
+ if (activePackage != null) {
+ activePackage.addRequire((SpecfileTag) definition);
+ } else {
+ specfile.addRequire((SpecfileTag) definition);
+ }
+ }
+ return definition;
+ }
+ }
+
+ if (lineText.startsWith(complexDefinitions[0]) && lineText.contains(DEFINE_SEPARATOR)) {
+ return parseComplexDefinition(lineText, lineNumber, SourceType.SOURCE);
+ } else if (lineText.startsWith(complexDefinitions[1]) && lineText.contains(DEFINE_SEPARATOR)) {
+ return parseComplexDefinition(lineText, lineNumber, SourceType.PATCH);
+ } else if (lineText.startsWith("BuildRequires")) { //$NON-NLS-1$
+ return parseBuildRequire(lineText, lineNumber, specfile);
+ }
+
+ return null;
+ }
+
+ private SpecfileElement parseBuildRequire(String lineText, int lineNumber, Specfile specfile) {
+ String value = lineText.substring(lineText.indexOf(':') + 1, lineText.length()).trim();
+ SpecfileDefine buildRequire = new SpecfileDefine("BuildRequires", value, specfile, null); //$NON-NLS-1$
+ buildRequire.setLineNumber(lineNumber);
+ specfile.addBuildRequire(buildRequire);
+ return buildRequire;
+ }
+
+ private SpecfileSection parseSection(String lineText, Specfile specfile, int lineNumber) {
+ List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
+ SpecfileSection toReturn = null;
+ boolean isSimpleSection = false;
+ for (Iterator<String> iter = tokens.iterator(); iter.hasNext();) {
+ String token = iter.next();
+
+ // Sections
+ // Simple Section Headers
+ for (String simpleSection : simpleSections) {
+ if (token.equals(simpleSection)) {
+ toReturn = new SpecfileSection(token.substring(1), specfile);
+ specfile.addSection(toReturn);
+ isSimpleSection = true;
+ }
+
+ }
+
+ // Complex Section Headers
+ for (String complexSection : complexSections) {
+ if (token.equals(complexSection)) {
+ String name = token.substring(1);
+ if (!name.equals("package")) { //$NON-NLS-1$
+ toReturn = new SpecfileSection(name, specfile);
+ specfile.addComplexSection(toReturn);
+ }
+ while (iter.hasNext()) {
+ String nextToken = iter.next();
+ if (nextToken.equals("-n")) { //$NON-NLS-1$
+ if (!iter.hasNext()) {
+ errorHandler.handleError(new SpecfileParseException(
+ Messages.getString("SpecfileParser.1") //$NON-NLS-1$
+ + name + Messages.getString("SpecfileParser.2"), //$NON-NLS-1$
+ lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
+ continue;
+ }
+
+ nextToken = iter.next();
+ if (nextToken.startsWith("-")) { //$NON-NLS-1$
+ errorHandler.handleError(new SpecfileParseException(
+ Messages.getString("SpecfileParser.3") //$NON-NLS-1$
+ + nextToken + Messages.getString("SpecfileParser.4"), //$NON-NLS-1$
+ lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
+ }
+
+ } else if (nextToken.equals("-p")) { //$NON-NLS-1$
+ // FIXME: rest of line is the actual section
+ break;
+ } else if (nextToken.equals("-f")) { //$NON-NLS-1$
+ break;
+ }
+
+ // this is a package
+ if (toReturn == null) {
+ SpecfilePackage tmpPackage = specfile.getPackage(nextToken);
+
+ if (tmpPackage == null) {
+ tmpPackage = new SpecfilePackage(nextToken, specfile);
+ specfile.addPackage(tmpPackage);
+ }
+ activePackage = tmpPackage;
+ return tmpPackage;
+ }
+
+ // this is another section
+ SpecfilePackage enclosingPackage = specfile.getPackage(nextToken);
+ if (enclosingPackage == null) {
+ enclosingPackage = new SpecfilePackage(nextToken, specfile);
+ specfile.addPackage(enclosingPackage);
+ }
+ toReturn.setPackage(enclosingPackage);
+ enclosingPackage.addSection(toReturn);
+ }
+ }
+ }
+ }
+
+ // if this package is part of the top level package, add it to
+ // it
+ if (toReturn != null && toReturn.getPackage() == null) {
+ SpecfilePackage topPackage = specfile.getPackage(specfile.getName());
+ if (topPackage == null) {
+ topPackage = new SpecfilePackage(specfile.getName(), specfile);
+ specfile.addPackage(topPackage);
+ }
+ if (!isSimpleSection) {
+ topPackage.addSection(toReturn);
+ }
+ }
+ if (lastSection != null) {
+ lastSection.setSectionEndLine(lineNumber);
+ }
+ return toReturn;
+ }
+
+ private SpecfileElement parseMacro(String lineText, Specfile specfile, int lineNumber) {
+ // FIXME: handle other macros
+
+ if (lineText.startsWith("%define") || lineText.startsWith("%global")) { //$NON-NLS-1$ //$NON-NLS-2$
+ return parseDefine(lineText, specfile, lineNumber);
+ } else if (lineText.startsWith("%patch")) { //$NON-NLS-1$
+ return parsePatch(lineText, lineNumber);
+ }
+
+ String[] sections = new String[simpleSections.length + complexSections.length];
+ System.arraycopy(simpleSections, 0, sections, 0, simpleSections.length);
+ System.arraycopy(complexSections, 0, sections, simpleSections.length, complexSections.length);
+ for (String section : sections) {
+ if (lineText.startsWith(section)) {
+ lastSection = parseSection(lineText, specfile, lineNumber);
+ if (lastSection != null) {
+ lastSection.setSectionEndLine(lineNumber + 1);
+ }
+ return lastSection;
+ }
+ }
+ // FIXME: add handling of lines containing %{SOURCENNN}
+ return null;
+ }
+
+ private SpecfileElement parsePatch(String lineText, int lineNumber) {
+
+ SpecfilePatchMacro toReturn = null;
+
+ List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
+
+ for (String token : tokens) {
+ // %patchN+
+ try {
+ if (token.startsWith("%patch")) { //$NON-NLS-1$
+ int patchNumber = 0;
+ if (token.length() > 6) {
+ patchNumber = Integer.parseInt(token.substring(6));
+ }
+ toReturn = new SpecfilePatchMacro(patchNumber);
+ }
+ } catch (NumberFormatException e) {
+ errorHandler.handleError(new SpecfileParseException(Messages.getString("SpecfileParser.5"), //$NON-NLS-1$
+ lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
+ return null;
+ }
+ }
+
+ return toReturn;
+ }
+
+ private SpecfileDefine parseDefine(String lineText, Specfile specfile, int lineNumber) {
+ List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
+ SpecfileDefine toReturn = null;
+ for (Iterator<String> iter = tokens.iterator(); iter.hasNext();) {
+ // Eat the actual "%define" or "%global" token
+ iter.next();
+ while (iter.hasNext()) {
+ String defineName = iter.next();
+ // FIXME: is this true? investigate in rpmbuild source
+ // Definitions must being with a letter
+ if (!Character.isLetter(defineName.charAt(0)) && (defineName.charAt(0) != '_')) {
+ errorHandler.handleError(new SpecfileParseException(Messages.getString("SpecfileParser.6"), //$NON-NLS-1$
+ lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
+ return null;
+ } else {
+ if (iter.hasNext()) {
+ String defineStringValue = iter.next();
+ // Defines that are more than one token
+ if (iter.hasNext()) {
+ defineStringValue = lineText.substring(lineText.indexOf(defineStringValue));
+ // Eat up the rest of the tokens
+ while (iter.hasNext()) {
+ iter.next();
+ }
+ }
+ int defineIntValue = -1;
+ try {
+ defineIntValue = Integer.parseInt(defineStringValue);
+ } catch (NumberFormatException e) {
+ toReturn = new SpecfileDefine(defineName, defineStringValue, specfile, null);
+ }
+ if (toReturn == null) {
+ toReturn = new SpecfileDefine(defineName, defineIntValue, specfile, null);
+ }
+ } else {
+ errorHandler.handleError(
+ new SpecfileParseException(defineName + Messages.getString("SpecfileParser.14"), //$NON-NLS-1$
+ lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
+ }
+ }
+ }
+ }
+ return toReturn;
+ }
+
+ private SpecfileElement parseComplexDefinition(String lineText, int lineNumber, SourceType sourceType) {
+ SpecfileSource toReturn = null;
+ List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
+ int number = -1;
+ boolean firstToken = true;
+
+ for (Iterator<String> iter = tokens.iterator(); iter.hasNext();) {
+ String token = iter.next();
+ if (token != null && token.length() > 0) {
+ if (firstToken) {
+ if (token.endsWith(DEFINE_SEPARATOR)) {
+ token = token.substring(0, token.length() - 1);
+ } else {
+ // FIXME: come up with a better error message here
+ // FIXME: what about descriptions that begin a line with
+ // the word "Source" or "Patch"?
+ errorHandler.handleError(new SpecfileParseException(Messages.getString("SpecfileParser.8"), //$NON-NLS-1$
+ lineNumber, 0, lineText.length(), IMarker.SEVERITY_WARNING));
+ return null;
+ }
+ if (sourceType == SourceType.PATCH) {
+ if (token.length() > 5) {
+ number = Integer.parseInt(token.substring(5));
+ if (!("patch" + number).equalsIgnoreCase(token)) { //$NON-NLS-1$
+ errorHandler
+ .handleError(new SpecfileParseException(Messages.getString("SpecfileParser.10"), //$NON-NLS-1$
+ lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
+ return null;
+ }
+ } else {
+ number = 0;
+ }
+ } else {
+ if (token.length() > 6) {
+ number = Integer.parseInt(token.substring(6));
+ if (!("source" + number).equalsIgnoreCase(token)) { //$NON-NLS-1$
+ errorHandler
+ .handleError(new SpecfileParseException(Messages.getString("SpecfileParser.11"), //$NON-NLS-1$
+ lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
+ return null;
+ }
+ } else {
+ number = 0;
+ }
+ }
+ toReturn = new SpecfileSource(number, ""); //$NON-NLS-1$
+ toReturn.setSourceType(sourceType);
+ firstToken = false;
+ } else {
+ // toReturn should never be null but check just in case
+ if (toReturn != null) {
+ toReturn.setFileName(token);
+ }
+ if (iter.hasNext()) {
+ errorHandler.handleError(new SpecfileParseException(Messages.getString("SpecfileParser.12"), //$NON-NLS-1$
+ lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
+ }
+ }
+ }
+ }
+
+ return toReturn;
+ }
+
+ private SpecfileElement parseSimpleDefinition(String lineText, Specfile specfile, int lineNumber,
+ boolean warnMultipleValues) {
+ List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
+ SpecfileTag toReturn = null;
+
+ for (Iterator<String> iter = tokens.iterator(); iter.hasNext();) {
+ String token = iter.next();
+
+ if (token.length() <= 0) {
+ break;
+ }
+
+ if (iter.hasNext()) {
+ String possValue = iter.next();
+ if (possValue.startsWith("%") && iter.hasNext()) { //$NON-NLS-1$
+ possValue += ' ' + iter.next();
+ }
+ toReturn = new SpecfileTag(token.substring(0, token.length() - 1).toLowerCase(), possValue, specfile,
+ null);
+ if (iter.hasNext() && !warnMultipleValues) {
+ errorHandler.handleError(new SpecfileParseException(
+ token.substring(0, token.length() - 1) + Messages.getString("SpecfileParser.13"), //$NON-NLS-1$
+ lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
+ return null;
+ }
+ } else {
+ errorHandler.handleError(new SpecfileParseException(
+ token.substring(0, token.length() - 1) + Messages.getString("SpecfileParser.14"), lineNumber, //$NON-NLS-1$
+ 0, lineText.length(), IMarker.SEVERITY_ERROR));
+ toReturn = null;
+ }
+ }
+ if ((toReturn != null)) {
+ String returnStringValue = toReturn.getStringValue();
+ if (returnStringValue != null) {
+ try {
+ int intValue = Integer.parseInt(returnStringValue);
+ toReturn.setValue(intValue);
+ } catch (NumberFormatException e) {
+ if (toReturn.getName().equalsIgnoreCase(RpmTags.EPOCH)) {
+ errorHandler.handleError(
+ new SpecfileParseException(Messages.getString("SpecfileParser.16"), lineNumber, //$NON-NLS-1$
+ 0, lineText.length(), IMarker.SEVERITY_ERROR));
+ toReturn = null;
+ }
+ }
+ }
+ }
+ return toReturn;
+ }
+
+ private SpecfileElement parseDirectDefinition(String lineText, Specfile specfile, int lineNumber) {
+ String[] parts = lineText.split(DEFINE_SEPARATOR, 2);
+ SpecfileTag directDefinition;
+ if (parts.length == 2) {
+ directDefinition = new SpecfileTag(parts[0], parts[1].trim(), specfile, activePackage);
+ directDefinition.setLineNumber(lineNumber);
+ } else {
+ errorHandler.handleError(
+ new SpecfileParseException(parts[0] + Messages.getString("SpecfileParser.14"), lineNumber, //$NON-NLS-1$
+ 0, lineText.length(), IMarker.SEVERITY_ERROR));
+ directDefinition = null;
+ }
+ return directDefinition;
+ }
+
+ public void setErrorHandler(SpecfileErrorHandler specfileErrorHandler) {
+ errorHandler = specfileErrorHandler;
+ }
+
+ public void setTaskHandler(SpecfileTaskHandler specfileTaskHandler) {
+ taskHandler = specfileTaskHandler;
+ }
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RpmConsole.java b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RpmConsole.java
index 31215ecb4e..0bbcb45cba 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RpmConsole.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RpmConsole.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2013 Red Hat Inc. and others.
+ * Copyright (c) 2010, 2016 Red Hat Inc. and others.
* 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
@@ -58,7 +58,7 @@ public class RpmConsole extends IOConsole {
/**
* A listener for responding to the run state of a build operation.
*/
- public static interface RpmConsoleObserver {
+ public interface RpmConsoleObserver {
/**
* This method is called whenever the run state of the build operation changes.
* @param running Whether or not the build is currently running.

Back to the top