[hg] main-silver: bugfix #223302 'Attach IDE snapshot to bug' ac...

  • From: Tomas Hurka < >
  • To: ,
  • Subject: [hg] main-silver: bugfix #223302 'Attach IDE snapshot to bug' ac...
  • Date: Thu, 06 Dec 2012 12:56:41 -0800

changeset 966e4b1810c3 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/966e4b1810c3
description:
        bugfix #223302 'Attach IDE snapshot to bug' action added

diffstat:

 bugzilla/manifest.mf                                                         
                |    2 +-
 bugzilla/src/org/netbeans/modules/bugzilla/api/NBBugzillaUtils.java          
                |   33 +
 bugzilla/src/org/netbeans/modules/bugzilla/issue/BugzillaIssue.java          
                |    2 +-
 
profiler.snaptracer/src/org/netbeans/modules/profiler/snaptracer/impl/AttachToBugAction.java
 |  286 ++++++++++
 
profiler.snaptracer/src/org/netbeans/modules/profiler/snaptracer/impl/TimelineView.java
      |    8 +-
 
profiler.snaptracer/src/org/netbeans/modules/profiler/snaptracer/impl/icons/bugtracking.png
  |    0 
 6 files changed, 327 insertions(+), 4 deletions(-)

diffs (415 lines):

diff --git a/bugzilla/manifest.mf b/bugzilla/manifest.mf
--- a/bugzilla/manifest.mf
+++ b/bugzilla/manifest.mf
@@ -3,5 +3,5 @@
 OpenIDE-Module: org.netbeans.modules.bugzilla
 OpenIDE-Module-Localizing-Bundle: 
org/netbeans/modules/bugzilla/Bundle.properties
 OpenIDE-Module-Layer: org/netbeans/modules/bugzilla/layer.xml
-OpenIDE-Module-Specification-Version: 1.32
+OpenIDE-Module-Specification-Version: 1.33
 
diff --git 
a/bugzilla/src/org/netbeans/modules/bugzilla/api/NBBugzillaUtils.java 
b/bugzilla/src/org/netbeans/modules/bugzilla/api/NBBugzillaUtils.java
--- a/bugzilla/src/org/netbeans/modules/bugzilla/api/NBBugzillaUtils.java
+++ b/bugzilla/src/org/netbeans/modules/bugzilla/api/NBBugzillaUtils.java
@@ -42,14 +42,20 @@
 
 package org.netbeans.modules.bugzilla.api;
 
+import java.io.File;
+import java.io.IOException;
 import java.net.URL;
 import java.util.prefs.Preferences;
 import java.util.regex.Pattern;
+import javax.swing.SwingUtilities;
 import org.netbeans.modules.bugtracking.api.Issue;
 import org.netbeans.modules.bugtracking.api.Repository;
 import org.netbeans.modules.bugtracking.util.BugtrackingUtil;
 import org.netbeans.modules.bugzilla.Bugzilla;
+import org.netbeans.modules.bugzilla.issue.BugzillaIssue;
+import org.netbeans.modules.bugzilla.repository.BugzillaRepository;
 import org.netbeans.modules.bugzilla.repository.NBRepositorySupport;
+import org.netbeans.modules.bugzilla.util.BugzillaUtil;
 
 /**
  *
@@ -132,4 +138,31 @@
         return NBRepositorySupport.getInstance().getNBRepository();
     }
     
+    /**
+     * Attaches files to the issue with the given id.
+     * 
+     * @param id issue id
+     * @param comment comment to be added to the issue
+     * @param desc attachment description per file
+     * @param contentType content type per file
+     * @param files files to be attached
+     */
+    public static void attachFiles(String id, String comment, String[] desc, 
String[] contentType, File[] files) {
+        assert id != null;
+        assert desc != null;
+        assert files != null;
+        assert contentType != null;
+        assert desc.length == files.length;
+        assert contentType.length == files.length;
+        
+        BugzillaRepository nbRepo = 
NBRepositorySupport.getInstance().getNBBugzillaRepository();
+        BugzillaIssue issue = nbRepo.getIssue(id);
+        if(issue == null) {
+            return;
 }
+        for (int i = 0; i < files.length; i++) {
+            issue.addAttachment(files[i], comment, desc[i], contentType[i], 
false);
+        }
+        BugzillaUtil.openIssue(issue);
+    }
+}
diff --git 
a/bugzilla/src/org/netbeans/modules/bugzilla/issue/BugzillaIssue.java 
b/bugzilla/src/org/netbeans/modules/bugzilla/issue/BugzillaIssue.java
--- a/bugzilla/src/org/netbeans/modules/bugzilla/issue/BugzillaIssue.java
+++ b/bugzilla/src/org/netbeans/modules/bugzilla/issue/BugzillaIssue.java
@@ -821,7 +821,7 @@
         return attachments;
     }
 
-    void addAttachment(File file, final String comment, final String desc, 
String contentType, final boolean patch) {
+    public void addAttachment(File file, final String comment, final String 
desc, String contentType, final boolean patch) {
         assert !SwingUtilities.isEventDispatchThread() : "Accessing remote 
host. Do not call in awt"; // NOI18N
         final FileTaskAttachmentSource attachmentSource = new 
FileTaskAttachmentSource(file);
         if (contentType == null) {
diff --git 
a/profiler.snaptracer/src/org/netbeans/modules/profiler/snaptracer/impl/AttachToBugAction.java
 
b/profiler.snaptracer/src/org/netbeans/modules/profiler/snaptracer/impl/AttachToBugAction.java
new file mode 100644
--- /dev/null
+++ 
b/profiler.snaptracer/src/org/netbeans/modules/profiler/snaptracer/impl/AttachToBugAction.java
@@ -0,0 +1,286 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2009 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.profiler.snaptracer.impl;
+
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import org.netbeans.api.progress.ProgressHandle;
+import org.netbeans.api.progress.ProgressHandleFactory;
+import org.netbeans.lib.profiler.ProfilerLogger;
+import org.netbeans.lib.profiler.ui.UIConstants;
+import org.netbeans.modules.profiler.api.ProfilerDialogs;
+import org.openide.DialogDescriptor;
+import org.openide.DialogDisplayer;
+import org.openide.awt.Mnemonics;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.ImageUtilities;
+import org.openide.util.NbBundle;
+import org.openide.util.RequestProcessor;
+
+/**
+ *
+ * @author Tomas Hurka
+ */
+@NbBundle.Messages({
+    "AttachToBugAction_ActionName=Attach IDE snapshot to bug...",
+    "AttachToBugAction_ActionDescr=Attach IDE snapshot to bug...",
+    "AttachToBugAction_ProgressMsg=Attaching snapshot...",
+    "AttachToBugAction_AttachFailedMsg=Attaching snapshot failed.\n{0}",
+    "AttachToBugAction_FileDescription=.npss file attached from NetBeans",
+    "AttachToBugAction_Description=.npss file",
+    "AttachToBugAction_IssueLabel=&Issue number:",
+    "AttachToBugAction_DialogTitle=Select Issue Number"
+})
+final class AttachToBugAction extends AbstractAction {
+
+    private static final String BUZILLA_CLASS = 
"org.netbeans.modules.bugzilla.api.NBBugzillaUtils"; // NOI18N
+    private static final String ATTACH_FILE_METHOD = "attachFiles"; // NOI18N
+    private static final String ICON_PATH = 
"org/netbeans/modules/profiler/snaptracer/impl/icons/bugtracking.png"; // 
NOI18N
+    private static final String NPSS_MINE = "application/x-npss"; // NOI18N
+    private static Method ATTACH_FILE;
+    private final FileObject snapshotFileObject;
+
+    static boolean isSupported() {
+        try {
+            Class bugzilla = Class.forName(BUZILLA_CLASS, true, 
Thread.currentThread().getContextClassLoader());
+            ATTACH_FILE = bugzilla.getMethod(ATTACH_FILE_METHOD, 
String.class, String.class, String[].class, String[].class, File[].class);
+        } catch (NoSuchMethodException ex) {
+            Exceptions.printStackTrace(ex);
+        } catch (SecurityException ex) {
+            Exceptions.printStackTrace(ex);
+        } catch (ClassNotFoundException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        return ATTACH_FILE != null;
+    }
+
+    AttachToBugAction(FileObject fo) {
+        snapshotFileObject = fo;
+
+        putValue(Action.NAME, Bundle.AttachToBugAction_ActionName());
+        putValue(Action.SHORT_DESCRIPTION, 
Bundle.AttachToBugAction_ActionDescr());
+        putValue(Action.SMALL_ICON, ImageUtilities.loadImageIcon(ICON_PATH, 
true));
+        putValue("iconBase", ICON_PATH);
+    }
+
+    @Override
+    public void actionPerformed(final ActionEvent e) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                File file = FileUtil.toFile(snapshotFileObject);
+                String filename = file.getName();
+                IssueNumberDialog issue = new IssueNumberDialog();
+                String bugNumber = issue.getIssueString();
+
+                if (bugNumber != null) {
+                    attachtoBug(bugNumber, file);
+                }
+            }
+        });
+    }
+
+    // TODO: export also UI gestures file if available, preferably based on 
user option
+    private static void attachtoBug(final String bugNumber, final File 
targetFile) {
+        final ProgressHandle progress = ProgressHandleFactory.createHandle(
+                Bundle.AttachToBugAction_ProgressMsg());
+        progress.setInitialDelay(500);
+        RequestProcessor.getDefault().post(new Runnable() {
+            public void run() {
+                progress.start();
+                try {
+                    String[] comments = new 
String[]{Bundle.AttachToBugAction_FileDescription()};
+                    String[] contentType = new String[]{NPSS_MINE};
+                    File[] files = new File[]{targetFile};
+                    ATTACH_FILE.invoke(null, bugNumber, 
Bundle.AttachToBugAction_Description(), comments, contentType, files);
+                } catch (IllegalAccessException ex) {
+                    Exceptions.printStackTrace(ex);
+                } catch (IllegalArgumentException ex) {
+                    Exceptions.printStackTrace(ex);
+                } catch (InvocationTargetException ex) {
+                    Throwable oex = ex.getTargetException();
+                    Logger.getLogger(getClass().getName()).log(Level.INFO, 
"attachtoBug", oex);   // NOI18N
+                    
ProfilerDialogs.displayError(Bundle.AttachToBugAction_AttachFailedMsg(oex.getLocalizedMessage()));
+                    ProfilerLogger.log("Failed to attach NPSS snapshot: " + 
oex.getMessage()); // NOI18N
+                } finally {
+                    progress.finish();
+                }
+            }
+        });
+    }
+
+    @NbBundle.Messages({
+        "IssueNumberDialog_DialogCaption=Select Issue Number",
+        "IssueNumberDialog_LabelString=&Issue number:",
+        "IssueNumberDialog_ButtonName=&OK",
+        "IssueNumberDialog_FieldAccessDescr=Select issue number."
+    })
+    private static class IssueNumberDialog extends JPanel {
+
+        //~ Instance fields 
----------------------------------------------------------------------------------------------------------
+        private JButton okButton;
+        private JLabel issueLabel;
+        private JTextField issueField;
+
+        //~ Constructors 
-------------------------------------------------------------------------------------------------------------
+
+        private IssueNumberDialog() {
+            initComponents();
+        }
+
+        //~ Methods 
------------------------------------------------------------------------------------------------------------------
+        public String getIssueString() {
+
+            final DialogDescriptor dd = new DialogDescriptor(this, 
Bundle.IssueNumberDialog_DialogCaption(), true,
+                    new Object[]{okButton, DialogDescriptor.CANCEL_OPTION},
+                    okButton, DialogDescriptor.BOTTOM_ALIGN, null, null);
+            final Dialog d = DialogDisplayer.getDefault().createDialog(dd);
+            d.setVisible(true);
+
+            if (dd.getValue() == okButton) {
+                return 
Integer.toString(Integer.parseInt(issueField.getText().trim()));
+            } else {
+                return null;
+            }
+        }
+
+        private void initComponents() {
+            GridBagConstraints gridBagConstraints;
+
+            issueLabel = new JLabel();
+            issueField = new JTextField();
+            okButton = new JButton();
+
+            setLayout(new GridBagLayout());
+
+            // issueLabel
+            issueLabel.setLabelFor(issueField);
+            Mnemonics.setLocalizedText(issueLabel, 
Bundle.IssueNumberDialog_LabelString());
+
+            gridBagConstraints = new GridBagConstraints();
+            gridBagConstraints.gridx = 0;
+            gridBagConstraints.gridy = 0;
+            gridBagConstraints.insets = new Insets(15, 10, 0, 10);
+            gridBagConstraints.anchor = GridBagConstraints.WEST;
+            add(issueLabel, gridBagConstraints);
+
+            // issueField
+            
issueField.getAccessibleContext().setAccessibleDescription(Bundle.IssueNumberDialog_FieldAccessDescr());
+            
issueField.setSelectionColor(UIConstants.TABLE_SELECTION_BACKGROUND_COLOR);
+            
issueField.setSelectedTextColor(UIConstants.TABLE_SELECTION_FOREGROUND_COLOR);
+            issueField.setPreferredSize(new Dimension(150, 
issueField.getPreferredSize().height));
+            gridBagConstraints = new GridBagConstraints();
+            gridBagConstraints.gridx = 1;
+            gridBagConstraints.gridy = 0;
+            gridBagConstraints.weightx = 1.0;
+            gridBagConstraints.insets = new Insets(15, 0, 0, 10);
+            gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
+            gridBagConstraints.anchor = GridBagConstraints.WEST;
+            add(issueField, gridBagConstraints);
+            issueField.getDocument().addDocumentListener(new 
DocumentListener() {
+                @Override
+                public void insertUpdate(DocumentEvent e) {
+                    updateOkButton();
+                }
+
+                @Override
+                public void removeUpdate(DocumentEvent e) {
+                    updateOkButton();
+                }
+
+                @Override
+                public void changedUpdate(DocumentEvent e) {
+                    updateOkButton();
+                }
+            });
+
+            // okButton
+            Mnemonics.setLocalizedText(okButton, 
Bundle.IssueNumberDialog_ButtonName());
+            updateOkButton();
+
+            // panel filling bottom space
+            gridBagConstraints = new GridBagConstraints();
+            gridBagConstraints.gridx = 0;
+            gridBagConstraints.gridy = 2;
+            gridBagConstraints.weighty = 1.0;
+            gridBagConstraints.fill = GridBagConstraints.BOTH;
+            gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
+            add(new JPanel(), gridBagConstraints);
+        }
+
+        private void updateOkButton() {
+            String number = issueField.getText().trim();
+
+            try {
+                if (!number.isEmpty()) {
+                    int n = Integer.parseInt(number);
+                    if (n > 0 && n < 1000000) {
+                        okButton.setEnabled(true);
+                        return;
+                    }
+                }
+            } catch (NumberFormatException ex) {
+                // ignore
+            }
+            okButton.setEnabled(false);
+        }
+    }
+}
diff --git 
a/profiler.snaptracer/src/org/netbeans/modules/profiler/snaptracer/impl/TimelineView.java
 
b/profiler.snaptracer/src/org/netbeans/modules/profiler/snaptracer/impl/TimelineView.java
--- 
a/profiler.snaptracer/src/org/netbeans/modules/profiler/snaptracer/impl/TimelineView.java
+++ 
b/profiler.snaptracer/src/org/netbeans/modules/profiler/snaptracer/impl/TimelineView.java
@@ -62,6 +62,7 @@
 import org.netbeans.modules.profiler.api.icons.Icons;
 import org.netbeans.modules.profiler.snaptracer.impl.icons.TracerIcons;
 import 
org.netbeans.modules.profiler.snaptracer.impl.timeline.TimelineSupport;
+import org.openide.filesystems.FileObject;
 import org.openide.util.NbBundle;
 
 /**
@@ -161,8 +162,11 @@
         }
         
         ProfilerToolbar toolbar = ProfilerToolbar.create(true);
-
-        toolbar.add(new 
ExportSnapshotAction(model.getSnapshot().getNpssFileObject()));
+        FileObject npssFo = model.getSnapshot().getNpssFileObject();
+        toolbar.add(new ExportSnapshotAction(npssFo));
+        if (AttachToBugAction.isSupported()) {
+            toolbar.add(new AttachToBugAction(npssFo));
+        }
         toolbar.addSeparator();
         
         toolbar.add(panel.zoomInAction());
diff --git 
a/profiler.snaptracer/src/org/netbeans/modules/profiler/snaptracer/impl/icons/bugtracking.png
 
b/profiler.snaptracer/src/org/netbeans/modules/profiler/snaptracer/impl/icons/bugtracking.png
new file mode 100755
index 
0000000000000000000000000000000000000000..9bd8170838a7d8eaf31eec1fc26e42172fd2af62
GIT bin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Project Features

About this Project

ConnectedDeveloper was started in November 2009, is owned by tpavek, and has 66 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close