aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Guzman2013-11-25 11:12:41 (EST)
committerAlexander Kurtakov2013-11-26 04:43:32 (EST)
commit96ac93c89a32bc653c3683a1b651fa37213bdefc (patch)
tree5b31697e8470b5373eab9687a79ee285018a5a51
parent04a9203f9054cbff8bafdd785def556fa523734d (diff)
downloadorg.eclipse.linuxtools-96ac93c89a32bc653c3683a1b651fa37213bdefc.zip
org.eclipse.linuxtools-96ac93c89a32bc653c3683a1b651fa37213bdefc.tar.gz
org.eclipse.linuxtools-96ac93c89a32bc653c3683a1b651fa37213bdefc.tar.bz2
RPM: createrepo import form page functionalityrefs/changes/50/18850/3
Added working import RPM and remove RPM functionality to createrepo plugin. Execution functionality simply puts a message to the console (to be replaced by command). Change-Id: Ibc064a350fa116fb0cacea20f91757a5ba5ec2f1 Signed-off-by: Neil Guzman <nguzman@redhat.com> Reviewed-on: https://git.eclipse.org/r/18850 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>
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Activator.java2
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java20
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java89
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/MetadataPage.java11
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties14
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java51
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoUtils.java50
7 files changed, 222 insertions, 15 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Activator.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Activator.java
index 06147c0..6f59663 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Activator.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Activator.java
@@ -37,6 +37,7 @@ public class Activator extends AbstractUIPlugin {
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
+ @Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
@@ -46,6 +47,7 @@ public class Activator extends AbstractUIPlugin {
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
+ @Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java
index 301395b..96f85c3 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java
@@ -55,6 +55,18 @@ public final class Messages {
/****/
public static String CreaterepoNewWizardPageTwo_errorURL;
+ // CreaterepoProject
+ /****/
+ public static String CreaterepoProject_executeCreaterepo;
+ /****/
+ public static String CreaterepoProject_errorGettingFile;
+ /****/
+ public static String CreaterepoProject_consoleName;
+
+ // Createrepo
+ /****/
+ public static String Createrepo_jobName;
+
// RepoFormEditor
/****/
public static String RepoFormEditor_errorInitializingForm;
@@ -79,6 +91,14 @@ public final class Messages {
/****/
public static String ImportRPMsPage_errorRefreshingTree;
+ // ImportRPMsPage$ImportButtonListener
+ /****/
+ public static String ImportButtonListener_error;
+
+ // ImportRPMsPage$RemoveButtonListener
+ /****/
+ public static String RemoveButtonListener_error;
+
// MetadataPage
/****/
public static String MetadataPage_title;
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java
index 6afad24..f3c20fb 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java
@@ -10,12 +10,22 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.rpm.createrepo.form;
+import java.io.File;
+import java.util.List;
+
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.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoUtils;
+import org.eclipse.linuxtools.rpm.createrepo.ICreaterepoConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -23,9 +33,14 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.console.MessageConsoleStream;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
@@ -219,19 +234,35 @@ public class ImportRPMsPage extends FormPage {
* Handle the import button execution on the Import RPMs page.
*/
public class ImportButtonListener extends SelectionAdapter {
+ private final String[] EXTENSION_FILTERS = {"*." + ICreaterepoConstants.RPM_FILE_EXTENSION}; //$NON-NLS-1$
+
/*
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetSelected(SelectionEvent e) { }
+ public void widgetSelected(SelectionEvent e) {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ Shell shell = workbench.getModalDialogShellProvider().getShell();
+ FileDialog fileDialog = new FileDialog(shell, SWT.SINGLE);
+ fileDialog.setFilterExtensions(EXTENSION_FILTERS);
+ if (fileDialog.open() != null) {
+ File externalFile = new File(fileDialog.getFilterPath(), fileDialog.getFileName());
+ try {
+ project.importRPM(externalFile);
+ refreshTree();
+ } catch (CoreException e1) {
+ Activator.logError(Messages.ImportButtonListener_error, e1);
+ }
+ }
+ }
/*
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetDefaultSelected(SelectionEvent e) { }
+ public void widgetDefaultSelected(SelectionEvent e) {/* not implemented */}
}
/**
@@ -243,14 +274,42 @@ public class ImportRPMsPage extends FormPage {
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetSelected(SelectionEvent e) { }
+ public void widgetSelected(SelectionEvent e) {
+ TreeItem[] selection = tree.getSelection();
+ try {
+ List<IResource> rpms = project.getRPMs();
+ if (selection.length > 0 && !rpms.isEmpty()) {
+ for (IResource resource : rpms) {
+ for (TreeItem treeItem : selection) {
+ deleteIfEquals(resource, treeItem);
+ }
+ }
+ }
+ refreshTree();
+ } catch (CoreException e1) {
+ Activator.logError(Messages.RemoveButtonListener_error, e1);
+ }
+ }
/*
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetDefaultSelected(SelectionEvent e) { }
+ public void widgetDefaultSelected(SelectionEvent e) {/* not implemented */}
+
+ /**
+ * Delete the resource if the tree item has the same name as it.
+ *
+ * @param resource The resource in the project (the RPM).
+ * @param treeItem The RPM in the tree.
+ * @throws CoreException Thrown when deleting fails.
+ */
+ private void deleteIfEquals(IResource resource, TreeItem treeItem) throws CoreException {
+ if (resource.getName().equals(treeItem.getText())) {
+ resource.delete(false, new NullProgressMonitor());
+ }
+ }
}
/**
@@ -262,14 +321,32 @@ public class ImportRPMsPage extends FormPage {
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetSelected(SelectionEvent e) { }
+ public void widgetSelected(SelectionEvent e) {
+ Job executeCreaterepo = new Job(Messages.Createrepo_jobName) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ monitor.beginTask(Messages.CreaterepoProject_executeCreaterepo, IProgressMonitor.UNKNOWN);
+ MessageConsoleStream os = CreaterepoUtils.findConsole(Messages.CreaterepoProject_consoleName)
+ .newMessageStream();
+ String message = "Createrepo functionality to be implemented when clicking this button"; //$NON-NLS-1$
+ os.print(message);
+ return new Status(IStatus.OK, Activator.PLUGIN_ID, message);
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ executeCreaterepo.setUser(true);
+ executeCreaterepo.schedule();
+ }
/*
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetDefaultSelected(SelectionEvent e) { }
+ public void widgetDefaultSelected(SelectionEvent e) {/* not implemented */}
}
}
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 7f20e5d..a9ac166 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
@@ -26,6 +26,7 @@ import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
@@ -81,7 +82,7 @@ public class MetadataPage extends FormPage {
//--------------------------------- REVISION SECTION START ----------
// Section and its client area to manage updating revision info
Section revSection = toolkit.createSection(form.getBody(), Section.DESCRIPTION
- | Section.TITLE_BAR);
+ | ExpandableComposite.TITLE_BAR);
layout = new GridLayout();
data = new GridData();
data.verticalAlignment = GridData.FILL;
@@ -104,7 +105,7 @@ public class MetadataPage extends FormPage {
//--------------------------------- TAGS SECTION START ----------
// Section and its client area to manage tags
Section tagSection = toolkit.createSection(form.getBody(), Section.DESCRIPTION
- | Section.TITLE_BAR);
+ | ExpandableComposite.TITLE_BAR);
layout = new GridLayout();
tagSection.setText(Messages.MetadataPage_sectionTitleTags);
tagSection.setDescription(Messages.MetadataPage_sectionInstructionTags);
@@ -216,7 +217,7 @@ public class MetadataPage extends FormPage {
* @see org.eclipse.swt.events.SelectionAdapter#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetDefaultSelected(SelectionEvent e) { }
+ public void widgetDefaultSelected(SelectionEvent e) {/* not implemented */}
}
/**
@@ -235,7 +236,7 @@ public class MetadataPage extends FormPage {
* @see org.eclipse.swt.events.SelectionAdapter#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetDefaultSelected(SelectionEvent e) { }
+ public void widgetDefaultSelected(SelectionEvent e) {/* not implemented */}
}
/**
@@ -254,7 +255,7 @@ public class MetadataPage extends FormPage {
* @see org.eclipse.swt.events.SelectionAdapter#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetDefaultSelected(SelectionEvent e) { }
+ public void widgetDefaultSelected(SelectionEvent e) {/* not implemented */}
}
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties
index cfca731..96785e2 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties
@@ -33,6 +33,14 @@ CreaterepoNewWizardPageTwo_errorName=The name of the repository is invalid. Make
CreaterepoNewWizardPageTwo_errorURL=The base URL is invalid. Make sure it has a valid protocol (http://, \
ftp://, file://)
+# CreaterepoProject
+CreaterepoProject_executeCreaterepo=Executing createrepo...
+CreaterepoProject_errorGettingFile=Error occured while trying to get the contents of the file.
+CreaterepoProject_consoleName=Createrepo Console
+
+# Createrepo
+Createrepo_jobName=Create repository
+
# RepoFormEditor
RepoFormEditor_errorInitializingForm=Error while trying to initialize the form page.
RepoFormEditor_errorInitializingProject=Error initializing project.
@@ -51,6 +59,12 @@ ImportRPMsPage_buttonCreateRepo=&Create Repo
ImportRPMsPage_errorRefreshingTree=Error while refreshing the RPM tree. Problem due to trying to get the \
RPMs in the content folder.
+# ImportRPMsPage$ImportButtonListener
+ImportButtonListener_error=Error occured while trying to import the RPM.
+
+# ImportRPMsPage$RemoveButtonListener
+RemoveButtonListener_error=Error occured while trying to remove the RPMs.
+
# MetadataPage
MetadataPage_title=Metadata
MetadataPage_formHeaderText=Repository Tags and Revision
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java
index f4a6512..40f922d 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.linuxtools.rpm.createrepo;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
@@ -19,7 +22,12 @@ import org.eclipse.core.resources.IProject;
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.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
+import org.osgi.framework.FrameworkUtil;
/**
* This class will contain the current project and basic operations of the
@@ -66,10 +74,7 @@ public class CreaterepoProject {
* @throws CoreException Thrown when unable to create the folders.
*/
private void intitialize() throws CoreException {
- content = getProject().getFolder(ICreaterepoConstants.CONTENT_FOLDER);
- if (!content.exists()) {
- content.create(false, true, monitor);
- }
+ createContentFolder();
if (repoFile == null) {
for (IResource child : getProject().members()) {
String extension = child.getFileExtension();
@@ -83,6 +88,44 @@ public class CreaterepoProject {
}
/**
+ * Create the content folder if it doesn't exist.
+ *
+ * @throws CoreException
+ */
+ private void createContentFolder() throws CoreException {
+ content = getProject().getFolder(ICreaterepoConstants.CONTENT_FOLDER);
+ if (!content.exists()) {
+ content.create(false, true, monitor);
+ }
+ }
+
+ /**
+ * Import an RPM file outside of the eclipse workspace.
+ *
+ * @param externalFile The external file to import.
+ * @throws CoreException Thrown when failure to create a workspace file.
+ */
+ public void importRPM(File externalFile) throws CoreException {
+ // must put imported RPMs into the content folder; create if missing
+ if (content == null) {
+ createContentFolder();
+ }
+ IFile file = getContentFolder().getFile(new Path(externalFile.getName()));
+ if (!file.exists()) {
+ try {
+ file.create(new FileInputStream(externalFile), false, monitor);
+ } catch (FileNotFoundException e) {
+ IStatus status = new Status(
+ IStatus.ERROR,
+ FrameworkUtil.getBundle(CreaterepoProject.class).getSymbolicName(),
+ Messages.CreaterepoProject_errorGettingFile, null);
+ throw new CoreException(status);
+ }
+ getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
+ }
+ }
+
+ /**
* Get the project.
*
* @return The project.
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoUtils.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoUtils.java
new file mode 100644
index 0000000..18b3cfa
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoUtils.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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:
+ * Neil Guzman - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.rpm.createrepo;
+
+import org.eclipse.ui.console.ConsolePlugin;
+import org.eclipse.ui.console.IConsole;
+import org.eclipse.ui.console.IConsoleManager;
+import org.eclipse.ui.console.MessageConsole;
+
+/**
+ * Utility class for createrepo.
+ */
+public class CreaterepoUtils {
+
+ /**
+ * Find the console to be used, and if none found, create
+ * a new console to use.
+ *
+ * @param name The name of the console.
+ * @return The found console or a new one if none found.
+ */
+ public static MessageConsole findConsole(String name) {
+ ConsolePlugin plugin = ConsolePlugin.getDefault();
+ IConsoleManager manager = plugin.getConsoleManager();
+ MessageConsole console = null;
+ for (IConsole cons : ConsolePlugin.getDefault().getConsoleManager()
+ .getConsoles()) {
+ if (cons.getName().equals(name)) {
+ console = (MessageConsole) cons;
+ }
+ }
+ // no existing console, create new one
+ if (console == null) {
+ console = new MessageConsole(name, null, null, true);
+ }
+ manager.addConsoles(new IConsole[] { console });
+ console.clearConsole();
+ console.activate();
+ return console;
+ }
+
+}