diff options
author | Neil Guzman | 2013-06-14 18:37:09 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2013-07-09 19:51:17 +0000 |
commit | 50a2ab8f883f23adbb146f23ef1061f61e4adc41 (patch) | |
tree | fc804d7154bcd6511ecbe425372783b5f7135875 | |
parent | 263252753f3e1f8e8fb00293e4874b5c637ec14a (diff) | |
download | org.eclipse.linuxtools-50a2ab8f883f23adbb146f23ef1061f61e4adc41.tar.gz org.eclipse.linuxtools-50a2ab8f883f23adbb146f23ef1061f61e4adc41.tar.xz org.eclipse.linuxtools-50a2ab8f883f23adbb146f23ef1061f61e4adc41.zip |
RPM: download and prepare sources
Download and Prepare sources command added to
RPM UI Editor.
Amend1: resolved some issues, still have to fix
exporting internal problem
Amend2: download/prepare will now work when selecting
editor if its a specfile or selecting a specfile. Also
made it work with either rpm layouts.
Amend3: moved DownloadJob to prevent exporting of internal
package
Amend4: removed whitespace
Amend5: added test cases
Amend6: removed whitespace
Amend7: resolved comments on Patch Set 7
Change-Id: I3373e8738c1a98040bb6836808416604b1910a45
Signed-off-by: Neil Guzman <nguzman@redhat.com>
Reviewed-on: https://git.eclipse.org/r/13989
Tested-by: Hudson CI
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
IP-Clean: Alexander Kurtakov <akurtako@redhat.com>
Tested-by: Alexander Kurtakov <akurtako@redhat.com>
19 files changed, 907 insertions, 136 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.core.tests/resources/srpms/hello-2.8-1.fc19.src.rpm b/rpm/org.eclipse.linuxtools.rpm.core.tests/resources/srpms/hello-2.8-1.fc19.src.rpm Binary files differnew file mode 100644 index 0000000000..9b3cea8262 --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.core.tests/resources/srpms/hello-2.8-1.fc19.src.rpm diff --git a/rpm/org.eclipse.linuxtools.rpm.core.tests/src/org/eclipse/linuxtools/rpm/core/tests/DownloadPrepareSourcesTest.java b/rpm/org.eclipse.linuxtools.rpm.core.tests/src/org/eclipse/linuxtools/rpm/core/tests/DownloadPrepareSourcesTest.java new file mode 100644 index 0000000000..6959c63d92 --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.core.tests/src/org/eclipse/linuxtools/rpm/core/tests/DownloadPrepareSourcesTest.java @@ -0,0 +1,296 @@ +/******************************************************************************* + * Copyright (c) 2013 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.rpm.core.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.linuxtools.rpm.core.RPMProject; +import org.eclipse.linuxtools.rpm.core.RPMProjectLayout; +import org.eclipse.linuxtools.rpm.core.utils.DownloadJob; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.osgi.framework.FrameworkUtil; + +/** + * Tests for the Download and Prepare sources command from RPM UI Editor + * + */ +public class DownloadPrepareSourcesTest { + + static IWorkspace workspace; + static IWorkspaceRoot root; + static NullProgressMonitor monitor; + String pluginRoot; + static IProject testProject; + + final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ + + /** + * Prepare the workspace + * + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + workspace = ResourcesPlugin.getWorkspace(); + root = workspace.getRoot(); + monitor = new NullProgressMonitor(); + } + + /** + * Create the test project before starting each test + * + * @throws CoreException + */ + @Before + public void setUpBeforeTests() throws CoreException { + testProject = root.getProject("testHelloWorld"); + testProject.create(monitor); + testProject.open(monitor); + } + + /** + * If the test project exists, delete it and its contents + * (used to start clean and fresh for each test case) + * + * @throws CoreException + */ + @After + public void cleanUpAfterTests() throws CoreException { + if (testProject != null && testProject.exists()) { + testProject.delete(true, true, monitor); + } + } + + /** + * Testing downloading sources using RPMBuild layout + * + * @throws CoreException + * @throws IOException + * @throws InterruptedException + */ + @Test + public void layoutRPMBuildDownloadSourcesTest() throws CoreException, + IOException, InterruptedException { + RPMProject rpmProject = importSrpm(testProject, + RPMProjectLayout.RPMBUILD); + assertNotNull(rpmProject); + + downloadFile(rpmProject); + + checkDownloadedFile(rpmProject, RPMProjectLayout.RPMBUILD); + } + + /** + * Test downloading sources using FLAT layout + * + * @throws CoreException + * @throws IOException + * @throws InterruptedException + */ + @Test + public void layoutFLATDownloadSourcesTest() throws CoreException, + IOException, InterruptedException { + RPMProject rpmProject = importSrpm(testProject, RPMProjectLayout.FLAT); + assertNotNull(rpmProject); + + downloadFile(rpmProject); + + checkDownloadedFile(rpmProject, RPMProjectLayout.FLAT); + } + + /** + * Test preparing sources using RPMBuild layout + * + * @throws CoreException + * @throws IOException + * @throws InterruptedException + */ + @Test + public void layoutRPMBuildPrepareSourcesTest() throws CoreException, + IOException, InterruptedException { + RPMProject rpmProject = importSrpm(testProject, + RPMProjectLayout.RPMBUILD); + assertNotNull(rpmProject); + + downloadFile(rpmProject); + + checkDownloadedFile(rpmProject, RPMProjectLayout.RPMBUILD); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + IStatus is = rpmProject.buildPrep(bos); + assertTrue(is.isOK()); + + checkPreparedSources(rpmProject, RPMProjectLayout.RPMBUILD); + } + + /** + * Test preparing sources using FLAT layout + * + * @throws CoreException + * @throws IOException + * @throws InterruptedException + */ + @Test + public void layoutFLATPrepareSourcesTest() throws CoreException, + IOException, InterruptedException { + RPMProject rpmProject = importSrpm(testProject, + RPMProjectLayout.FLAT); + assertNotNull(rpmProject); + + downloadFile(rpmProject); + + checkDownloadedFile(rpmProject, RPMProjectLayout.FLAT); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + IStatus is = rpmProject.buildPrep(bos); + assertTrue(is.isOK()); + + checkPreparedSources(rpmProject, RPMProjectLayout.FLAT); + } + + /** + * Check if the file was downloaded 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 checkDownloadedFile(RPMProject project, RPMProjectLayout layout) + throws CoreException { + IContainer sourcesFolder = project.getConfiguration() + .getSourcesFolder(); + assertNotNull(sourcesFolder); + switch (layout) { + case RPMBUILD: + assertNotNull(sourcesFolder.getParent().findMember("SOURCES")); + assertTrue(sourcesFolder.members().length == 1); + // check if the file exists under SOURCES folder + assertNotNull(sourcesFolder + .findMember(new Path("hello-2.8.tar.gz"))); + break; + case FLAT: + // 4 = "hello-2.8.tar.gz" + ".project" + "hello-2.8-1.fc19.src.rpm" + "hello.spec" + assertTrue(sourcesFolder.members().length == 4); + assertNotNull(sourcesFolder + .findMember(new Path("hello-2.8.tar.gz"))); + break; + } + } + + /** + * 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")); + assertTrue(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/" + assertTrue(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; + } + } + + /** + * Download and also test if the file was downloaded correctly + * + * @param project The RPM project + * @throws IOException + * @throws InterruptedException + */ + public void downloadFile(RPMProject project) throws IOException, + InterruptedException { + // connect to the URL + URL url = new URL("http://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + assertEquals(connection.getResponseCode(), HttpURLConnection.HTTP_OK); + + // download the file + String filename = "hello-2.8.tar.gz"; + IFile file = project.getConfiguration().getSourcesFolder() + .getFile(new Path(filename)); + Job downloadJob = new DownloadJob(file, connection); + downloadJob.setUser(true); + downloadJob.schedule(); + downloadJob.join(); + assertTrue(downloadJob.getResult().equals(Status.OK_STATUS)); + } + + /** + * Import the SRPM into the project (make .spec accessible) + * + * @param testProject The test project + * @param layout layout The layout of the RPM project (RPMBuild or FLAT) + * @return The RPM project + * @throws CoreException + * @throws IOException + */ + private RPMProject importSrpm(IProject testProject, RPMProjectLayout layout) + throws CoreException, IOException { + // Instantiate an RPMProject + RPMProject rpmProject = new RPMProject(testProject, layout); + + // Find the test SRPM and install it + URL url = FileLocator.find(FrameworkUtil + .getBundle(RPMProjectTest.class), new Path( + "resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ + "hello-2.8-1.fc19.src.rpm"), null); + File foo = new File(FileLocator.toFileURL(url).getPath()); + + // import the SRPM into the RPMProject + rpmProject.importSourceRPM(foo); + return rpmProject; + } +} diff --git a/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/internal/rpm/core/utils/DownloadJob.java b/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/rpm/core/utils/DownloadJob.java index c6f0367f2e..f2c2ecbbf4 100644 --- a/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/internal/rpm/core/utils/DownloadJob.java +++ b/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/rpm/core/utils/DownloadJob.java @@ -8,7 +8,7 @@ * Contributors: * Alexander Kurtakov (Red Hat) - initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.internal.rpm.core.utils; +package org.eclipse.linuxtools.rpm.core.utils; import java.io.BufferedInputStream; import java.io.File; @@ -25,6 +25,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.linuxtools.internal.rpm.core.utils.Messages; import org.eclipse.linuxtools.rpm.core.IRPMConstants; import org.eclipse.osgi.util.NLS; @@ -35,28 +36,16 @@ import org.eclipse.osgi.util.NLS; public class DownloadJob extends Job { private IFile file; private URLConnection content; - private boolean fileOverride; /** * Creates the download job. * @param file The file to store the remote content. * @param content The URLConnection to the remote file. - * @param override Flag to override file if it exists. */ - public DownloadJob(IFile file, URLConnection content, boolean override) { + public DownloadJob(IFile file, URLConnection content) { super(NLS.bind(Messages.DownloadJob_0, file.getName())); this.file = file; this.content = content; - this.fileOverride = override; - } - - /** - * Creates the download job. - * @param file The file to store the remote content. - * @param content URLConnection to the remote file. - */ - public DownloadJob(IFile file, URLConnection content) { - this(file, content, false); } @Override @@ -69,19 +58,21 @@ public class DownloadJob extends Job { FileOutputStream fos = new FileOutputStream(tempFile); InputStream is = new BufferedInputStream(content.getInputStream()); int b; + byte buf[] = new byte[5 * 1024]; boolean canceled = false; - while ((b = is.read()) != -1) { - if (monitor.isCanceled()) { - canceled = true; - break; + while ((b = is.read(buf)) != -1) { + if (monitor.isCanceled()) { + canceled = true; + break; + } + fos.write(buf, 0 ,b); + monitor.worked(1); } - fos.write(b); - monitor.worked(1); - } is.close(); fos.close(); if (!canceled) { - if (fileOverride) { + // override the previous file if there is one + if (file.exists()) { file.setContents(new FileInputStream(tempFile), true, false, monitor); } else { diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/META-INF/MANIFEST.MF b/rpm/org.eclipse.linuxtools.rpm.ui.editor/META-INF/MANIFEST.MF index 85d3dca69d..2d36c8c6c3 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/META-INF/MANIFEST.MF +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/META-INF/MANIFEST.MF @@ -17,7 +17,8 @@ Require-Bundle: org.eclipse.ui, com.ibm.icu, org.eclipse.ui.forms;bundle-version="3.3.101", org.eclipse.compare;bundle-version="3.4.0", - org.eclipse.linuxtools.rpm.core + org.eclipse.linuxtools.rpm.core, + org.eclipse.ui.console Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.linuxtools.rpm.ui.editor, org.eclipse.linuxtools.rpm.ui.editor.markers, diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.properties b/rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.properties index 9368538a32..512d0274a6 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.properties +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.properties @@ -28,9 +28,11 @@ category.name.0 = Editor Commands command.name = Toggle Comment command.name.0 = Organize patches command.name.1 = Show outline +command.name.2 = Download Sources +command.name.3 = Prepare Sources command.label = Toggle Comments command.tooltip = Add or Remove Comments command.label.0 = Organize patches command.tooltip.0 = Organize patches numerically command.label.1 = Show Outline -command.tooltip.1 = Show Outline +command.tooltip.1 = Display project outline of .spec file
\ No newline at end of file diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.xml b/rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.xml index 6dc651e49e..9ccf2beb86 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.xml +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.xml @@ -242,6 +242,16 @@ categoryId="rpmEditor.category" id="rpmEditor.showOutline.command" name="%command.name.1"/> + <command + categoryId="rpmEditor.category" + id="rpmEditor.downloadSources.command" + name="%command.name.2"> + </command> + <command + categoryId="rpmEditor.category" + id="rpmEditor.prepareSources.command" + name="%command.name.3"> + </command> </extension> <extension point="org.eclipse.ui.handlers"> <handler @@ -253,6 +263,14 @@ <handler class="org.eclipse.linuxtools.internal.rpm.ui.editor.actions.SpecfileEditorShowOutlineActionDelegate" commandId="rpmEditor.showOutline.command" /> + <handler + class="org.eclipse.linuxtools.internal.rpm.ui.editor.actions.SpecfileEditorDownloadSourcesActionDelegate" + commandId="rpmEditor.downloadSources.command"> + </handler> + <handler + class="org.eclipse.linuxtools.internal.rpm.ui.editor.actions.SpecfileEditorPrepareSourcesActionDelegate" + commandId="rpmEditor.prepareSources.command"> + </handler> </extension> <!-- Key bindings --> <extension @@ -272,6 +290,18 @@ commandId="rpmEditor.showOutline.command" contextId="org.eclipse.linuxtools.rpm.ui.specEditorScope" schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/> + <key + commandId="rpmEditor.downloadSources.command" + contextId="org.eclipse.linuxtools.rpm.ui.specEditorScope" + schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" + sequence="Ctrl+Shift+R D"> + </key> + <key + commandId="rpmEditor.prepareSources.command" + contextId="org.eclipse.linuxtools.rpm.ui.specEditorScope" + schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" + sequence="Ctrl+Shift+R P"> + </key> </extension> <!-- Editor menu actions --> <extension @@ -329,6 +359,58 @@ </iterate> </visibleWhen> </command> + <command + commandId="rpmEditor.downloadSources.command" + label="%command.name.2" + tooltip="%command.name.2"> + <visibleWhen> + <iterate + ifEmpty="false" + operator="or"> + <or> + <adapt + type="org.eclipse.core.resources.IResource"> + <test + property="org.eclipse.core.resources.name" + value="*.spec"> + </test> + </adapt> + <with + variable="activeEditorId"> + <equals + value="org.eclipse.linuxtools.rpm.ui.editor.SpecfileEditor"> + </equals> + </with> + </or> + </iterate> + </visibleWhen> + </command> + <command + commandId="rpmEditor.prepareSources.command" + label="%command.name.3" + tooltip="%command.name.3"> + <visibleWhen> + <iterate + ifEmpty="false" + operator="or"> + <or> + <adapt + type="org.eclipse.core.resources.IResource"> + <test + property="org.eclipse.core.resources.name" + value="*.spec"> + </test> + </adapt> + <with + variable="activeEditorId"> + <equals + value="org.eclipse.linuxtools.rpm.ui.editor.SpecfileEditor"> + </equals> + </with> + </or> + </iterate> + </visibleWhen> + </command> </menuContribution> </extension> <!-- Compare support--> diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/RPMHandlerUtils.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/RPMHandlerUtils.java new file mode 100644 index 0000000000..aa8e15694f --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/RPMHandlerUtils.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2013 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.rpm.ui.editor; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.linuxtools.internal.rpm.ui.editor.actions.Messages; +import org.eclipse.linuxtools.rpm.core.IRPMConstants; +import org.eclipse.linuxtools.rpm.core.RPMProject; +import org.eclipse.linuxtools.rpm.core.RPMProjectLayout; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.part.EditorPart; + +/** + * Utility class for RPM UI Editor Handler related things. + * + */ +public class RPMHandlerUtils { + + /** + * Extract the IResource that was selected when the event was fired. + * @param event The fired execution event. + * @return The resource that was selected. + */ + public static IResource getResource(ExecutionEvent event) { + IWorkbenchPart part = HandlerUtil.getActivePart(event); + if (part == null) { + return null; + } + if (part instanceof EditorPart) { + IEditorInput input = ((EditorPart) part).getEditorInput(); + if (input instanceof IFileEditorInput) { + return ((IFileEditorInput) input).getFile(); + } + return null; + } + IWorkbenchSite site = part.getSite(); + if (site == null) { + return null; + } + ISelectionProvider provider = site.getSelectionProvider(); + if (provider == null) { + return null; + } + ISelection selection = provider.getSelection(); + if (selection instanceof IStructuredSelection) { + Object element = ((IStructuredSelection) selection) + .getFirstElement(); + if (element instanceof IResource) { + return (IResource) element; + } else if (element instanceof IAdaptable) { + IAdaptable adaptable = (IAdaptable) element; + Object adapted = adaptable.getAdapter(IResource.class); + return (IResource) adapted; + } else { + return null; + } + } + return null; + } + + /** + * Get an RPMProject for the resource creating a new instance to an RPMProject. + * @param resource The resource to check its parent project. + * @return The RPMProject of the resource passed in. + */ + public static RPMProject getRPMProject(IResource resource) { + RPMProject rc = null; + + try { + IProject parentProject = resource.getProject(); + + // determine if project selected is an RPMProject + if (parentProject.hasNature(IRPMConstants.RPM_NATURE_ID)) { + if (parentProject.getPersistentProperty(new QualifiedName(IRPMConstants.RPM_CORE_ID, IRPMConstants.SPECS_FOLDER)) != null){ + rc = new RPMProject(parentProject, RPMProjectLayout.RPMBUILD); + } else { + rc = new RPMProject(parentProject, RPMProjectLayout.FLAT); + } + } else { + rc = new RPMProject(parentProject, RPMProjectLayout.FLAT); + } + } catch (CoreException e) { + SpecfileLog.logError(Messages.RPMHandlerUtils_cannotCreateRPMProject, e); + } + return rc; + } +} diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/UiUtils.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/UiUtils.java index f45e27f187..c22727d72a 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/UiUtils.java +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/UiUtils.java @@ -68,7 +68,7 @@ public class UiUtils { while (variableMatcher.find()) { define = specfile.getDefine(variableMatcher.group(1)); if (define != null) { - stringToResolve = stringToResolve.replaceAll("\\b"+variableMatcher.group(1)+"\\b", define.getStringValue()); + stringToResolve = stringToResolve.replaceAll("\\b"+variableMatcher.group(1)+"\\b", define.getStringValue()); //$NON-NLS-1$//$NON-NLS-2$ } else { return originalString; } diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/Messages.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/Messages.java index 8f7c50f838..e3d82d6831 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/Messages.java +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/Messages.java @@ -16,6 +16,20 @@ public final class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.linuxtools.internal.rpm.ui.editor.actions.messages"; //$NON-NLS-1$ public static String SpecfileChangelogFormatter_0; public static String SpecfileChangelogFormatter_1; + + // SpecfileEditorDownloadSourcesActionDelegate + public static String DownloadSources_malformedURL; + public static String DownloadSources_cannotConnectToURL; + + // SpecfileEditorPrepareSourcesActionDelegate + public static String PrepareSources_downloadSourcesMalformedURL; + public static String PrepareSources_downloadCancelled; + public static String PrepareSources_downloadConnectionFail; + public static String PrepareSources_coreException; + + // RPMHandlerUtils + public static String RPMHandlerUtils_cannotCreateRPMProject; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorDownloadSourcesActionDelegate.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorDownloadSourcesActionDelegate.java new file mode 100644 index 0000000000..d27bfca161 --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorDownloadSourcesActionDelegate.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2008, 2013 Alexander Kurtakov, Neil Guzman. + * 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + * Neil Guzman - RPM download sources implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.rpm.ui.editor.actions; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.linuxtools.internal.rpm.ui.editor.RPMHandlerUtils; +import org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileLog; +import org.eclipse.linuxtools.internal.rpm.ui.editor.UiUtils; +import org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource; +import org.eclipse.linuxtools.rpm.core.RPMProject; +import org.eclipse.linuxtools.rpm.core.utils.DownloadJob; +import org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile; +import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser; +import org.eclipse.linuxtools.rpm.ui.editor.utils.RPMUtils; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +public class SpecfileEditorDownloadSourcesActionDelegate extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + final Shell shell = HandlerUtil.getActiveShellChecked(event); + final SpecfileParser specparser = new SpecfileParser(); + final IResource resource = RPMHandlerUtils.getResource(event); + final RPMProject rpj = RPMHandlerUtils.getRPMProject(resource); + final IFile workFile = (IFile) rpj.getSpecFile(); + final Specfile specfile = specparser.parse(workFile); + + // retrieve source(s) from specfile + final List<SpecfileSource> sourceURLList = specfile != null ? (List<SpecfileSource>) specfile + .getSources() : null; + + // go through each source, resolve the defines, and then download the file + // currently stops immediately once an invalid source URL is encountered + for (final SpecfileSource sourceurls : sourceURLList) { + try { + String rawURL = sourceurls.getFileName().toString(); + String resolvedURL = UiUtils.resolveDefines(specfile, rawURL.toString()); + URL url = null; + try { + url = new URL(resolvedURL); + } catch(MalformedURLException e) { + SpecfileLog.logError(Messages.DownloadSources_malformedURL + resolvedURL, e); + RPMUtils.showErrorDialog(shell, "Error", //$NON-NLS-1$ + Messages.DownloadSources_malformedURL + resolvedURL); + return null; + } + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + + if (connection.getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND) { + // grab the name of the file from the URL + int offset = url.toString().lastIndexOf("/"); //$NON-NLS-1$ + 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); + RPMUtils.showErrorDialog(shell, "Error", //$NON-NLS-1$ + Messages.DownloadSources_cannotConnectToURL); + return null; + } + } + + return null; + } + +} diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorPrepareSourcesActionDelegate.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorPrepareSourcesActionDelegate.java new file mode 100644 index 0000000000..1df4b69fd2 --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorPrepareSourcesActionDelegate.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * Copyright (c) 2013 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.rpm.ui.editor.actions; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.linuxtools.internal.rpm.ui.editor.RPMHandlerUtils; +import org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileLog; +import org.eclipse.linuxtools.internal.rpm.ui.editor.UiUtils; +import org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource; +import org.eclipse.linuxtools.rpm.core.RPMProject; +import org.eclipse.linuxtools.rpm.core.utils.DownloadJob; +import org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile; +import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser; +import org.eclipse.linuxtools.rpm.ui.editor.utils.RPMUtils; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; +import org.eclipse.ui.handlers.HandlerUtil; + +public class SpecfileEditorPrepareSourcesActionDelegate extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + final Shell shell = HandlerUtil.getActiveShellChecked(event); + final SpecfileParser specparser = new SpecfileParser(); + final IResource resource = RPMHandlerUtils.getResource(event); + final RPMProject rpj = RPMHandlerUtils.getRPMProject(resource); + final IFile workFile = (IFile) rpj.getSpecFile(); + final Specfile specfile = specparser.parse(workFile); + // retrieve source(s) from specfile + final List<SpecfileSource> sourceURLList = specfile != null ? (List<SpecfileSource>) specfile + .getSources() : null; + + // need to download sources THEN prepare it + for (final SpecfileSource sourceurls : sourceURLList) { + try { + String rawURL = sourceurls.getFileName().toString(); + String resolvedURL = UiUtils.resolveDefines(specfile, + rawURL.toString()); + URL url = null; + try { + url = new URL(resolvedURL); + } catch (MalformedURLException e) { + SpecfileLog.logError( + Messages.PrepareSources_downloadSourcesMalformedURL + + resolvedURL, e); + RPMUtils.showErrorDialog(shell, "Error", //$NON-NLS-1$ + Messages.PrepareSources_downloadSourcesMalformedURL + + resolvedURL); + return null; + } + + HttpURLConnection connection = (HttpURLConnection) url + .openConnection(); + + if (connection.getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND) { + // grab the name of the file from the URL + int offset = url.toString().lastIndexOf("/"); //$NON-NLS-1$ + 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(); + try { + // wait for download job to finish + downloadJob.join(); + } catch (InterruptedException e1) { + throw new OperationCanceledException(); + } + if (!downloadJob.getResult().isOK()) { + // bail if something failed + return downloadJob.getResult(); + } + } + } catch (OperationCanceledException e) { + SpecfileLog.logError(Messages.PrepareSources_downloadCancelled, + e); + RPMUtils.showErrorDialog(shell, "Error", //$NON-NLS-1$ + Messages.PrepareSources_downloadCancelled); + return null; + } catch (IOException e) { + SpecfileLog.logError( + Messages.PrepareSources_downloadConnectionFail, e); + RPMUtils.showErrorDialog(shell, "Error", //$NON-NLS-1$ + Messages.PrepareSources_downloadConnectionFail); + return null; + } + } + + Job job = new Job("Preparing sources") { //$NON-NLS-1$ + @Override + protected IStatus run(IProgressMonitor monitor) { + monitor.beginTask( + "Preparing sources for " + rpj.getSpecFile().getName(), //$NON-NLS-1$ + IProgressMonitor.UNKNOWN); + int offset = rpj.getSpecFile().getName().toString().lastIndexOf("."); //$NON-NLS-1$ + String projname = rpj.getSpecFile().getName().toString().substring(0,offset); + MessageConsole myConsole = getConsole(projname); + MessageConsoleStream out = myConsole.newMessageStream(); + IStatus is = null; + try { + // just need to get current stream + is = rpj.buildPrep(out); + } catch (CoreException e) { + SpecfileLog.logError(Messages.PrepareSources_coreException, + e); + RPMUtils.showErrorDialog(shell, "Error", //$NON-NLS-1$ + Messages.PrepareSources_coreException); + return is; + } finally { + monitor.done(); + } + return is; + } + }; + job.setUser(true); // suppress UI. That's done in encapsulated + job.schedule(); + return null; + } + + /** + * Get the console. + * + * @param packageName The name of the package(RPM) this console will be for. + * @return A console instance. + */ + public MessageConsole getConsole(String packageName) { + ConsolePlugin plugin = ConsolePlugin.getDefault(); + IConsoleManager conMan = plugin.getConsoleManager(); + String projectConsoleName = "rpmbuild"+'('+packageName+')'; //$NON-NLS-1$ + MessageConsole ret = null; + for (IConsole cons : ConsolePlugin.getDefault().getConsoleManager() + .getConsoles()) { + if (cons.getName().equals(projectConsoleName)) { + ret = (MessageConsole) cons; + } + } + // no existing console, create new one + if (ret == null) { + ret = new MessageConsole(projectConsoleName, null, null, true); + } + conMan.addConsoles(new IConsole[] { ret }); + ret.clearConsole(); + ret.activate(); + return ret; + } + +} diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/messages.properties b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/messages.properties index 77b79d34af..e47ac98356 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/messages.properties +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/messages.properties @@ -16,3 +16,17 @@ SpecfileChangelogAction_4=\ editor SpecfileChangelogAction_5=EEE MMM d yyyy SpecfileChangelogFormatter_0=Got SpecfileChangelogFormatter_1=\ editor + +# SpecfileEditorDownloadSourcesActionDelegate +DownloadSources_malformedURL=Unable to create URL using: +DownloadSources_cannotConnectToURL=Cannot open a connection using the URL. + +# SpecfileEditorPrepareSourcesActionDelegate +PrepareSources_downloadSourcesMalformedURL=During preparing of sources, unable to create URL using: +PrepareSources_downloadCancelled=While preparing the sources, the download process was interrupted. +PrepareSources_downloadConnectionFail=During preparing of sources, cannot open a connection using the URL. +PrepareSources_coreException=There was a core exception thrown while trying to prepare the sources \ + for the build. + +# RPMHandlerUtils +RPMHandlerUtils_cannotCreateRPMProject=Error trying to retrieve the RPM Project.
\ No newline at end of file diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/hyperlink/DownloadJob.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/hyperlink/DownloadJob.java deleted file mode 100644 index 6b71f69cd2..0000000000 --- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/hyperlink/DownloadJob.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov (Red Hat) - initial API and implementation - *******************************************************************************/ -package org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URLConnection; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileLog; -import org.eclipse.osgi.util.NLS; - -public class DownloadJob extends Job { - private IFile file; - private URLConnection content; - private boolean fileOverride; - - public DownloadJob(IFile file, URLConnection content, boolean override) { - super(NLS.bind(Messages.SourcesFileDownloadHyperlink_4, file.getName())); - this.file = file; - this.content = content; - this.fileOverride = override; - } - - public DownloadJob(IFile file, URLConnection content) { - this(file, content, false); - } - - @Override - public IStatus run(IProgressMonitor monitor) { - monitor.beginTask( - NLS.bind(Messages.SourcesFileDownloadHyperlink_4, - file.getName()), content.getContentLength()); - try { - File tempFile = File.createTempFile(file.getName(), ""); //$NON-NLS-1$ - FileOutputStream fos = new FileOutputStream(tempFile); - InputStream is = new BufferedInputStream(content.getInputStream()); - int b; - boolean canceled = false; - while ((b = is.read()) != -1) { - if (monitor.isCanceled()) { - canceled = true; - break; - } - fos.write(b); - monitor.worked(1); - } - is.close(); - fos.close(); - if (!canceled) { - if (fileOverride) { - file.setContents(new FileInputStream(tempFile), true, - false, monitor); - } else { - file.create(new FileInputStream(tempFile), true, monitor); - - } - } - tempFile.delete(); - } catch (CoreException e) { - SpecfileLog.logError(e); - return Status.CANCEL_STATUS; - } catch (IOException e) { - SpecfileLog.logError(e); - return Status.CANCEL_STATUS; - } - monitor.done(); - return Status.OK_STATUS; - } -}
\ No newline at end of file diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/hyperlink/SourcesFileDownloadHyperlink.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/hyperlink/SourcesFileDownloadHyperlink.java index 1506d25cbb..5dbaf22ffc 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/hyperlink/SourcesFileDownloadHyperlink.java +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/hyperlink/SourcesFileDownloadHyperlink.java @@ -20,6 +20,7 @@ import org.eclipse.core.resources.IResource; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.hyperlink.IHyperlink; import org.eclipse.linuxtools.rpm.core.IRPMConstants; +import org.eclipse.linuxtools.rpm.core.utils.DownloadJob; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; @@ -102,7 +103,7 @@ public class SourcesFileDownloadHyperlink implements IHyperlink { savedFileName)); int rc = mb.open(); if (rc == SWT.OK) { - new DownloadJob(savedFile, connection, true).schedule(); + new DownloadJob(savedFile, connection).schedule(); } } else { @@ -117,4 +118,4 @@ public class SourcesFileDownloadHyperlink implements IHyperlink { } } -} +}
\ No newline at end of file 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 73aef733b9..644b1cf40c 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 @@ -27,14 +27,18 @@ import static org.eclipse.linuxtools.internal.rpm.ui.editor.RpmSections.PRETRANS import static org.eclipse.linuxtools.internal.rpm.ui.editor.RpmSections.PREUN_SECTION; import static org.eclipse.linuxtools.internal.rpm.ui.editor.RpmSections.PRE_SECTION; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.io.LineNumberReader; import java.io.StringReader; import java.util.Arrays; import java.util.Iterator; import java.util.List; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; @@ -168,6 +172,31 @@ public class SpecfileParser { 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$ + } + Specfile specfile = parser.parse(sb.toString()); + return specfile; + } + private void generateTaskMarker(int lineNumber, String line) { String[] taskTags = store.getString(PreferenceConstants.P_TASK_TAGS) .split(";"); //$NON-NLS-1$ diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/messages.properties b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/messages.properties index 4881942a54..5eb8bc6564 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/messages.properties +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/parser/messages.properties @@ -25,3 +25,5 @@ SpecfileParser.8=If this is a Source or Patch directive, it must end with a colo SpecfileSource.0=error: can't match SpecfileSource.1=%patch SpecfileSource.2=error: can't match +SpecfileParseFile.1=Unable to read from IFile when trying to parse to Specfile +SpecfileParseFile.2=Problem with trying to get contents of IFile when parsing
\ No newline at end of file diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/utils/RPMUtils.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/utils/RPMUtils.java new file mode 100644 index 0000000000..345e38c2c8 --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/rpm/ui/editor/utils/RPMUtils.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2013 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.rpm.ui.editor.utils; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; + +/** + * Utility class for RPM UI Editor related things. + * + */ +public class RPMUtils { + + /** + * Show an error dialog. + * + * @param shell A valid shell + * @param title The error dialog title + * @param message The message to be displayed. + */ + public static void showErrorDialog(final Shell shell, + final String title, final String message) { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + MessageDialog.openError(shell, title, message); + } + }); + } +} diff --git a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RPMExportOperation.java b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RPMExportOperation.java index 57455c2565..e12d1b1f49 100644 --- a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RPMExportOperation.java +++ b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RPMExportOperation.java @@ -16,9 +16,6 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.linuxtools.rpm.core.RPMProject; -import org.eclipse.ui.console.ConsolePlugin; -import org.eclipse.ui.console.IConsole; -import org.eclipse.ui.console.IConsoleManager; import org.eclipse.ui.console.IOConsole; import org.eclipse.ui.console.IOConsoleOutputStream; import org.osgi.framework.FrameworkUtil; @@ -50,7 +47,7 @@ public class RPMExportOperation extends Job { @Override public IStatus run(IProgressMonitor monitor) { IStatus result = null; - IOConsole myConsole = findConsole(); + IOConsole myConsole = RpmConsole.findConsole(rpmProject.getSpecFile().getProject().getName()); IOConsoleOutputStream out = myConsole.newOutputStream(); myConsole.clearConsole(); myConsole.activate(); @@ -90,21 +87,4 @@ public class RPMExportOperation extends Job { } return result; } - - private IOConsole findConsole() { - ConsolePlugin plugin = ConsolePlugin.getDefault(); - IConsoleManager conMan = plugin.getConsoleManager(); - IConsole[] existingConsoles = conMan.getConsoles(); - for (IConsole console: existingConsoles) { - if ((RpmConsole.ID+'('+rpmProject.getSpecFile().getProject().getName()+')').equals(console.getName())) { - RpmConsole myConsole = (RpmConsole) console; - myConsole.clearConsole(); - return myConsole; - } - } - // no console found, so create a new one - RpmConsole myConsole = new RpmConsole(rpmProject); - conMan.addConsoles(new IConsole[] { myConsole }); - return myConsole; - } } 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 597cee009e..752618aec4 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 @@ -12,8 +12,11 @@ package org.eclipse.linuxtools.internal.rpm.ui; import org.eclipse.core.resources.IResource; import org.eclipse.linuxtools.rpm.core.RPMProject; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleManager; import org.eclipse.ui.console.IOConsole; - +import org.eclipse.ui.console.MessageConsole; /** * RpmConsole is used to output rpm/rpmbuild output. * @@ -43,4 +46,31 @@ public class RpmConsole extends IOConsole { public IResource getSpecfile() { return rpmProject.getSpecFile(); } + + /** + * Get the console. + * + * @param packageName The name of the package(RPM) this console will be for. + * @return A console instance. + */ + public static IOConsole findConsole(String packageName) { + ConsolePlugin plugin = ConsolePlugin.getDefault(); + IConsoleManager conMan = plugin.getConsoleManager(); + String projectConsoleName = ID+'('+packageName+')'; + IOConsole ret = null; + for (IConsole cons : ConsolePlugin.getDefault().getConsoleManager() + .getConsoles()) { + if (cons.getName().equals(projectConsoleName)) { + ret = (MessageConsole) cons; + } + } + // no existing console, create new one + if (ret == null) { + ret = new MessageConsole(ID+'('+packageName+')', null, null, true); + } + conMan.addConsoles(new IConsole[] { ret }); + ret.clearConsole(); + ret.activate(); + return ret; + } } |