From 6c5b754229b2490d2f162a7ebb953dfc6b6943e2 Mon Sep 17 00:00:00 2001 From: LadyCailin Date: Wed, 30 Jan 2019 18:15:25 +0100 Subject: [PATCH] Delete obsolete DocGen UI, update UI tool Update Help file in PNViewer to link to the new website. --- .../PureUtilities/Common/OSUtils.java | 62 ++- src/main/java/com/laytonsmith/core/Main.java | 18 +- .../com/laytonsmith/tools/UILauncher.java | 54 +- .../laytonsmith/tools/docgen/DocGenUI.form | 231 --------- .../laytonsmith/tools/docgen/DocGenUI.java | 371 ------------- .../tools/docgen/DocGenUIHandler.java | 488 ------------------ .../tools/docgen/SingleFunctionDialog.form | 84 --- .../tools/docgen/SingleFunctionDialog.java | 116 ----- .../laytonsmith/tools/pnviewer/PNViewer.java | 2 +- .../tools/pnviewer/HelpDialog.html | 2 +- 10 files changed, 89 insertions(+), 1339 deletions(-) delete mode 100644 src/main/java/com/laytonsmith/tools/docgen/DocGenUI.form delete mode 100644 src/main/java/com/laytonsmith/tools/docgen/DocGenUI.java delete mode 100644 src/main/java/com/laytonsmith/tools/docgen/DocGenUIHandler.java delete mode 100644 src/main/java/com/laytonsmith/tools/docgen/SingleFunctionDialog.form delete mode 100644 src/main/java/com/laytonsmith/tools/docgen/SingleFunctionDialog.java diff --git a/src/main/java/com/laytonsmith/PureUtilities/Common/OSUtils.java b/src/main/java/com/laytonsmith/PureUtilities/Common/OSUtils.java index 4995191a7..4efb39144 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/Common/OSUtils.java +++ b/src/main/java/com/laytonsmith/PureUtilities/Common/OSUtils.java @@ -11,7 +11,67 @@ public static enum OS { MAC, LINUX, SOLARIS, - UNKNOWN + UNKNOWN; + + /** + * Returns true if this is {@link #WINDOWS} + * @return + */ + public boolean isWindows() { + return this == WINDOWS; + } + + /** + * Returns true if this is {@link #MAC} + * @return + */ + public boolean isMac() { + return this == MAC; + } + + /** + * Returns true if this is {@link #LINUX} + * @return + */ + public boolean isLinux() { + return this == LINUX; + } + + /** + * Returns true if this is {@link #SOLARIS} + * @return + */ + public boolean isSolaris() { + return this == SOLARIS; + } + + /** + * Returns true if this is {@link #UNKNOWN} + * @return + */ + public boolean isUnknown() { + return this == UNKNOWN; + } + + /** + * Returns true if this is a strict UNIX implementation, that is, {@link #MAC} or {@link #SOLARIS} + * + * @return + */ + public boolean isUnix() { + return this == MAC || this == SOLARIS; + } + + /** + * Returns true if this {@link #isUnix()} returns true, or if this is {@link #LINUX}. This is a less strict + * category than {@link #isUnix()}, because for most purposes, Linux is UNIX compatible, but this is not + * strictly the case. Depending on what you're doing, you may need to differentiate between strict UNIX OSes + * or not, so if this matters, you'll need to do a more granular check. + * @return + */ + public boolean isUnixLike() { + return isUnix() || this == LINUX; + } } /** diff --git a/src/main/java/com/laytonsmith/core/Main.java b/src/main/java/com/laytonsmith/core/Main.java index b92237b60..d08e27fef 100644 --- a/src/main/java/com/laytonsmith/core/Main.java +++ b/src/main/java/com/laytonsmith/core/Main.java @@ -40,7 +40,6 @@ import com.laytonsmith.tools.UILauncher; import com.laytonsmith.tools.docgen.DocGen; import com.laytonsmith.tools.docgen.DocGenExportTool; -import com.laytonsmith.tools.docgen.DocGenUI; import com.laytonsmith.tools.docgen.ExtensionDocGen; import com.laytonsmith.tools.docgen.sitedeploy.SiteDeploy; import com.laytonsmith.tools.pnviewer.PNViewer; @@ -526,9 +525,6 @@ public static void main(String[] args) throws Exception { } else if(mode == UNINSTALL_CMDLINE_MODE) { Interpreter.uninstall(); System.exit(0); - } else if(mode == DOCGEN_MODE) { - DocGenUI.main(args); - System.exit(0); } else if(mode == MSLP_MODE) { String mslp = parsedArgs.getStringArgument(); if(mslp.isEmpty()) { @@ -824,9 +820,17 @@ public static void main(String[] args) throws Exception { } else { // Relaunch the jar in a new process with the --run flag set, // so that the process will be in its own subshell - CommandExecutor ce = new CommandExecutor("java -jar " - + ClassDiscovery.GetClassContainer(Main.class).getPath() + " " - + StringUtils.Join(args, " ") + " --in-shell"); + List largs = new ArrayList<>(); + largs.add("java"); + largs.add("-jar"); + String jarPath = ClassDiscovery.GetClassContainer(Main.class).getPath(); + if(OSUtils.GetOS().isWindows() && jarPath.startsWith("/")) { + jarPath = jarPath.substring(1); + } + largs.add(jarPath); + largs.addAll(Arrays.asList(args)); + largs.add("--in-shell"); + CommandExecutor ce = new CommandExecutor(largs.toArray(new String[largs.size()])); ce.start(); System.exit(0); } diff --git a/src/main/java/com/laytonsmith/tools/UILauncher.java b/src/main/java/com/laytonsmith/tools/UILauncher.java index bc9c5a649..1852aed92 100644 --- a/src/main/java/com/laytonsmith/tools/UILauncher.java +++ b/src/main/java/com/laytonsmith/tools/UILauncher.java @@ -1,7 +1,6 @@ package com.laytonsmith.tools; import com.laytonsmith.PureUtilities.Common.UIUtils; -import com.laytonsmith.tools.docgen.DocGenUI; import com.laytonsmith.tools.pnviewer.PNViewer; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -26,22 +25,11 @@ public class UILauncher extends javax.swing.JFrame { /** * Creates new form UILauncher */ + @SuppressWarnings("OverridableMethodCallInConstructor") public UILauncher() { final String[] args = {}; - uis.add(new UI("Persistence Network Viewer", "Allows easier visualization of the Persistence Network", new Runnable() { - - @Override - public void run() { - PNViewer.main(args); - } - })); - - uis.add(new UI("DocGen", "Allows uploading of the built-in documentation to MediaWiki software.", new Runnable() { - - @Override - public void run() { - DocGenUI.main(args); - } + uis.add(new UI("Persistence Network Viewer", "Allows easier visualization of the Persistence Network", () -> { + PNViewer.main(args); })); initComponents(); @@ -49,25 +37,17 @@ public void run() { setTitle("MethodScript UI Tool Launcher"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - launchButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - if(selectedUI == null) { - JOptionPane.showMessageDialog(UILauncher.this, "Please select a tool from the list on the left.", "Error", JOptionPane.ERROR_MESSAGE); - return; - } - selectedUI.getLauncher().run(); - UILauncher.this.setVisible(false); + launchButton.addActionListener((ActionEvent e) -> { + if(selectedUI == null) { + JOptionPane.showMessageDialog(UILauncher.this, "Please select a tool from the list on the left.", "Error", JOptionPane.ERROR_MESSAGE); + return; } + selectedUI.getLauncher().run(); + UILauncher.this.setVisible(false); }); - exitButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - System.exit(0); - } + exitButton.addActionListener((ActionEvent e) -> { + System.exit(0); }); launcherList.setModel(new AbstractListModel() { @@ -84,14 +64,10 @@ public Object getElementAt(int index) { }); - launcherList.addListSelectionListener(new ListSelectionListener() { - - @Override - public void valueChanged(ListSelectionEvent e) { - UI ui = uis.get(e.getFirstIndex()); - descriptionTextArea.setText(ui.getTooltip()); - selectedUI = ui; - } + launcherList.addListSelectionListener((ListSelectionEvent e) -> { + UI ui = uis.get(e.getFirstIndex()); + descriptionTextArea.setText(ui.getTooltip()); + selectedUI = ui; }); launcherList.addMouseListener(new MouseAdapter() { diff --git a/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.form b/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.form deleted file mode 100644 index 8b77ee846..000000000 --- a/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.form +++ /dev/null @@ -1,231 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.java b/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.java deleted file mode 100644 index 55cd91090..000000000 --- a/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.java +++ /dev/null @@ -1,371 +0,0 @@ -package com.laytonsmith.tools.docgen; - -import com.laytonsmith.PureUtilities.ClassLoading.ClassDiscovery; -import com.laytonsmith.PureUtilities.Common.UIUtils; -import com.laytonsmith.abstraction.Implementation; -import com.laytonsmith.annotations.api; -import com.laytonsmith.commandhelper.CommandHelperFileLocations; -import com.laytonsmith.core.CHLog; -import com.laytonsmith.core.Installer; -import com.laytonsmith.core.Prefs; -import com.laytonsmith.core.extensions.ExtensionManager; -import com.laytonsmith.core.functions.FunctionList; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.UnknownHostException; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JFrame; -import javax.swing.SwingUtilities; -//import org.pushingpixels.substance.api.skin.SubstanceGraphiteGlassLookAndFeel; - -/** - * - * - */ -public class DocGenUI extends javax.swing.JFrame { - - DocGenUIHandler handler; - DocGenUIHandler.ProgressManager manager = new DocGenUIHandler.ProgressManager() { - - @Override - public void setProgress(final Integer i) { - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - if(i == null) { - progress.setIndeterminate(true); - progress.setValue(0); - } else { - progress.setIndeterminate(false); - progress.setValue(i); - } - } - }); - } - - @Override - public void setStatus(final String status) { - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - infoLabel.setText(status); - } - }); - } - }; - - /** - * Creates new form DocGenUI - */ - public DocGenUI() { - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - initComponents(); - UIUtils.centerWindow(this); - this.setTitle("Documentation Generator"); - } - - private void doUpload() { - infoLabel.setText("Info:"); - manager.setProgress(null); - try { - try { - handler = new DocGenUIHandler(manager, new URL("http://" + wikiURL.getText()), username.getText(), - new String(password.getPassword()), "CommandHelper/" + (staged.isSelected() ? "Staged/" : ""), - "CommandHelper/", staged.isSelected(), - functions.isSelected(), examples.isSelected(), events.isSelected(), templates.isSelected()); - handler.go(); - manager.setStatus("Done."); - } catch (DocGenUIHandler.APIException e) { - e.printStackTrace(); - manager.setStatus("Error: " + e.getMessage()); - } catch (DocGenUIHandler.QuickStop e) { - manager.setStatus("Info: Stopped"); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } catch (MalformedURLException ex) { - manager.setStatus("Info: Malformed URL"); - } catch (UnknownHostException e) { - manager.setStatus("Error: Unknown host: " + e.getMessage()); - } catch (Exception ex) { - manager.setStatus(ex.getClass().getSimpleName() + ": " + ex.getMessage()); - } finally { - handler = null; - manager.setProgress(0); - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - uploadButton.setText("Upload"); - } - }); - } - } - - /** - * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The - * content of this method is always regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jLabel1 = new javax.swing.JLabel(); - wikiURL = new javax.swing.JTextField(); - jLabel2 = new javax.swing.JLabel(); - username = new javax.swing.JTextField(); - jLabel3 = new javax.swing.JLabel(); - password = new javax.swing.JPasswordField(); - staged = new javax.swing.JCheckBox(); - jPanel1 = new javax.swing.JPanel(); - functions = new javax.swing.JCheckBox(); - examples = new javax.swing.JCheckBox(); - events = new javax.swing.JCheckBox(); - templates = new javax.swing.JCheckBox(); - jLabel4 = new javax.swing.JLabel(); - singleFunctionUploadButton = new javax.swing.JButton(); - uploadButton = new javax.swing.JButton(); - progress = new javax.swing.JProgressBar(); - infoLabel = new javax.swing.JLabel(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel1.setText("Wiki hostname:"); - - wikiURL.setText("wiki.sk89q.com"); - - jLabel2.setText("Username:"); - - jLabel3.setText("Password:"); - - staged.setSelected(true); - staged.setText("Staged?"); - - jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); - - functions.setSelected(true); - functions.setText("Functions"); - - examples.setSelected(true); - examples.setText("Examples"); - - events.setSelected(true); - events.setText("Events"); - - templates.setSelected(true); - templates.setText("Templates"); - - jLabel4.setText("Upload what?"); - - singleFunctionUploadButton.setText("Single Function..."); - singleFunctionUploadButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - singleFunctionUploadButtonActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(functions) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(examples) - .addGap(18, 18, 18) - .addComponent(singleFunctionUploadButton)) - .addComponent(events) - .addComponent(templates) - .addComponent(jLabel4)) - .addContainerGap(171, Short.MAX_VALUE)) - ); - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel4) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(functions) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(examples) - .addComponent(singleFunctionUploadButton)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(events) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(templates) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - uploadButton.setText("Upload"); - uploadButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - uploadButtonActionPerformed(evt); - } - }); - - infoLabel.setText("Info: Waiting"); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1) - .addComponent(jLabel2) - .addComponent(jLabel3)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(password) - .addComponent(wikiURL) - .addComponent(username))) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addComponent(staged) - .addGap(0, 0, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addComponent(uploadButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 222, Short.MAX_VALUE) - .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(infoLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(wikiURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel2) - .addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createSequentialGroup() - .addComponent(staged) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(uploadButton)) - .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(infoLabel) - .addContainerGap(14, Short.MAX_VALUE)) - ); - - pack(); - } // //GEN-END:initComponents - - private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) { // GEN-FIRST:event_uploadButtonActionPerformed - uploadButton.setText("Stop"); - if(handler != null) { - handler.stop(); - } else { - new Thread(new Runnable() { - - @Override - public void run() { - try { - Prefs.init(CommandHelperFileLocations.getDefault().getPreferencesFile()); - CHLog.initialize(CommandHelperFileLocations.getDefault().getConfigDirectory()); - } catch (IOException ex) { - Logger.getLogger(DocGenUI.class.getName()).log(Level.SEVERE, null, ex); - } - doUpload(); - } - }, "UploadThread").start(); - } - } // GEN-LAST:event_uploadButtonActionPerformed - - private void singleFunctionUploadButtonActionPerformed(java.awt.event.ActionEvent evt) { // GEN-FIRST:event_singleFunctionUploadButtonActionPerformed - // TODO add your handling code here: - } // GEN-LAST:event_singleFunctionUploadButtonActionPerformed - - /** - * @param args the command line arguments - */ - public static void main(String args[]) { - Implementation.forceServerType(Implementation.Type.BUKKIT); - try { - Prefs.init(CommandHelperFileLocations.getDefault().getPreferencesFile()); - } catch (IOException ex) { - Logger.getLogger(DocGenUI.class.getName()).log(Level.SEVERE, null, ex); - } - -// try { -// SwingUtilities.invokeAndWait(new Runnable() { -// -// @Override -// public void run() { -// try { -// UIManager.setLookAndFeel(new SubstanceGraphiteGlassLookAndFeel()); -// JFrame.setDefaultLookAndFeelDecorated(true); -// JDialog.setDefaultLookAndFeelDecorated(true); -// } catch (UnsupportedLookAndFeelException ex) { -// Logger.getLogger(DocGenUI.class.getName()).log(Level.SEVERE, null, ex); -// } -// } -// }); -// } catch (Exception ex) { -// Logger.getLogger(DocGenUI.class.getName()).log(Level.SEVERE, null, ex); -// } catch (NoClassDefFoundError e){ -// //This shouldn't be an error, they just won't have the awesome -// //theme -// System.err.println("NoClassDefFoundError occured while trying to install LaF. Do you have Substance installed?"); -// if(Prefs.DebugMode()){ -// e.printStackTrace(System.err); -// } -// } - ClassDiscovery.getDefaultInstance().addDiscoveryLocation(ClassDiscovery.GetClassContainer(DocGenUI.class)); - Installer.Install(CommandHelperFileLocations.getDefault().getConfigDirectory()); - - /* Create and display the form */ - java.awt.EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - new DocGenUI().setVisible(true); - } - }); - - ExtensionManager.Initialize(ClassDiscovery.getDefaultInstance()); - - //This goes ahead and initializes the platform. - FunctionList.getFunctionList(api.Platforms.INTERPRETER_JAVA); - } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JCheckBox events; - private javax.swing.JCheckBox examples; - private javax.swing.JCheckBox functions; - private javax.swing.JLabel infoLabel; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JPanel jPanel1; - private javax.swing.JPasswordField password; - private javax.swing.JProgressBar progress; - private javax.swing.JButton singleFunctionUploadButton; - private javax.swing.JCheckBox staged; - private javax.swing.JCheckBox templates; - private javax.swing.JButton uploadButton; - private javax.swing.JTextField username; - private javax.swing.JTextField wikiURL; - // End of variables declaration//GEN-END:variables -} diff --git a/src/main/java/com/laytonsmith/tools/docgen/DocGenUIHandler.java b/src/main/java/com/laytonsmith/tools/docgen/DocGenUIHandler.java deleted file mode 100644 index e247203dc..000000000 --- a/src/main/java/com/laytonsmith/tools/docgen/DocGenUIHandler.java +++ /dev/null @@ -1,488 +0,0 @@ -package com.laytonsmith.tools.docgen; - -import com.laytonsmith.PureUtilities.Common.StringUtils; -import com.laytonsmith.PureUtilities.Web.CookieJar; -import com.laytonsmith.PureUtilities.Web.HTTPMethod; -import com.laytonsmith.PureUtilities.Web.HTTPResponse; -import com.laytonsmith.PureUtilities.Web.RequestSettings; -import com.laytonsmith.PureUtilities.Web.WebUtility; -import com.laytonsmith.PureUtilities.XMLDocument; -import com.laytonsmith.PureUtilities.ZipReader; -import com.laytonsmith.annotations.api; -import com.laytonsmith.core.exceptions.ConfigCompileException; -import com.laytonsmith.core.functions.Function; -import com.laytonsmith.core.functions.FunctionBase; -import com.laytonsmith.core.functions.FunctionList; -import com.laytonsmith.persistence.DataSourceException; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.net.URL; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Queue; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.xml.xpath.XPathExpressionException; -import org.xml.sax.SAXException; - -/** - * - * - */ -public class DocGenUIHandler { - - private final String pagePrefix = "\n\n"; - - public static class QuickStop extends RuntimeException { - // - } - - public static interface ProgressManager { - - void setProgress(Integer i); - - void setStatus(String status); - } - - public static void main(String[] args) { - DocGenUI.main(args); - } - - private static final Map> BASE_HEADERS = new HashMap>(); - - static { - BASE_HEADERS.put("User-Agent", Arrays.asList(new String[]{"CommandHelper-DocUploader"})); - } - - URL url; - String username; - String password; - String prefix; - String rootPath; - boolean isStaged; - boolean doFunctions; - boolean doExamples; - boolean doEvents; - boolean doTemplates; - int totalPages = 0; - int atPage = 0; - - private ProgressManager progress; - - boolean stop = false; - URL endpoint; - - public DocGenUIHandler(ProgressManager progress, URL url, String username, String password, String prefix, - String rootPath, - boolean isStaged, boolean doFunctions, - boolean doExamples, boolean doEvents, boolean doTemplates) { - - this.progress = progress; - - this.url = url; - this.username = username; - this.password = password; - this.prefix = prefix; - this.rootPath = rootPath; - this.isStaged = isStaged; - this.doFunctions = doFunctions; - this.doExamples = doExamples; - this.doEvents = doEvents; - this.doTemplates = doTemplates; - if(!this.prefix.endsWith("/")) { - this.prefix += "/"; - } - if(this.prefix.startsWith("/")) { - this.prefix = this.prefix.substring(1); - } - } - - public void stop() { - stop = true; - } - - public void checkStop() { - if(stop) { - throw new QuickStop(); - } - } - - public void go() throws Exception { - try { - endpoint = new URL(url.toString() + "/w/api.php"); - if(getPage(endpoint).getResponseCode() != 200) { - throw new Exception("Unable to reach wiki API."); - } - if(doExamples) { - testCompileExamples(); - } - doLogin(); - //Now, gather up the page count, so we can set our progress bar correctly - if(doFunctions) { - totalPages += getFunctionCount(); - } - if(doExamples) { - totalPages += getExampleCount(); - } - if(doEvents) { - totalPages += getEventCount(); - } - if(doTemplates) { - totalPages += getTemplateCount(); - } - totalPages += getMiscCount(); - progress.setProgress(0); - if(doFunctions) { - doFunctions(); - } - if(doExamples) { - doExamples(); - } - if(doEvents) { - doEvents(); - } - if(doTemplates) { - doTemplates(); - } - } finally { - progress.setProgress(0); - } - } - - private void doFunctions() throws XPathExpressionException, ConfigCompileException { - doUpload(DocGen.functions(DocGen.MarkupType.WIKI, api.Platforms.INTERPRETER_JAVA, isStaged), "/API", true); - } - - private void doExamples() throws ConfigCompileException, XPathExpressionException, IOException, DataSourceException, Exception { - //So they are alphabetical, so we always have a consistent upload order, to - //facilitate tracing problems. - SortedSet names = new TreeSet<>(); - for(FunctionBase base : FunctionList.getFunctionList(api.Platforms.INTERPRETER_JAVA)) { - String name = base.getName(); - if(base.appearInDocumentation()) { - names.add(name); - } - } - for(String name : names) { - String docs = DocGen.examples(name, isStaged); - doUpload(docs, "/API/" + name, true); - } - } - - private void doEvents() throws XPathExpressionException { - doUpload(DocGen.events(DocGen.MarkupType.WIKI), "/Event_API", true); - } - - private void doTemplates() throws IOException, XPathExpressionException { - try { - File root = new File(DocGenUIHandler.class.getResource("/docs").toURI()); - ZipReader reader = new ZipReader(root); - Queue q = new LinkedList<>(); - q.addAll(Arrays.asList(reader.listFiles())); - while(q.peek() != null) { - ZipReader r = new ZipReader(q.poll()); - if(r.isDirectory()) { - q.addAll(Arrays.asList(r.listFiles())); - } else { - String articleName = "/" + r.getFile().getName(); - doUpload(DocGen.Template(r.getFile().getName(), isStaged), articleName, true); - } - } - } catch (URISyntaxException ex) { - Logger.getLogger(DocGenUIHandler.class.getName()).log(Level.SEVERE, null, ex); - } - } - - /** - * Uploads a file to a page. If protect is null, the protections are left as is. If protect is false, protections - * are removed if they are present. If protect is true, protections are added if they are not present. - * - * @param wikiMarkup - * @param page - * @param protect - * @throws XPathExpressionException - */ - void doUpload(String wikiMarkup, String page, Boolean protect) throws XPathExpressionException { - checkStop(); - if(page.startsWith("/")) { - //The prefix already has this - page = page.substring(1); - } - wikiMarkup = pagePrefix + wikiMarkup; - //The full path - String fullPath = prefix + page; - progress.setStatus("Uploading " + fullPath); - //First we need to get the edit token - XMLDocument content = getXML(endpoint, mapCreator( - "action", "query", - "titles", fullPath, - "prop", "revisions", - "rvprop", "sha1", - "format", "xml" - )); - checkStop(); - String sha1 = content.getNode("/api/query/pages/page/revisions/rev/@sha1"); - String sha1local = getSha1(wikiMarkup); - if(!sha1.equals(sha1local)) { - XMLDocument query = getXML(endpoint, mapCreator( - "action", "query", - "titles", fullPath, - "prop", "info", - "intoken", "edit", - "format", "xml" - )); - checkStop(); - String edittoken = query.getNode("/api/query/pages/page/@edittoken"); - XMLDocument edit = getXML(endpoint, mapCreator( - "action", "edit", - "title", fullPath, - "text", wikiMarkup, - "summary", "Automatic documentation update. (This is a bot edit)", - "bot", "true", - "format", "xml", - //This must always come last - "token", edittoken - ), false); - } - if(protect != null) { - XMLDocument query = getXML(endpoint, mapCreator( - "action", "query", - "titles", fullPath, - "prop", "info", - "inprop", "protection", - "intoken", "protect", - "format", "xml" - )); - checkStop(); - String protectToken = query.getNode("/api/query/pages/page/@protecttoken"); - boolean isProtectedEdit = false; - boolean isProtectedMove = false; - if(query.nodeExists("/api/query/pages/page/protection/pr")) { - for(int i = 1; i <= query.countChildren("/api/query/pages/page/protection"); i++) { - //If only sysops can edit and move - if(query.getNode("/api/query/pages/page/protection/pr[" + i + "]/@level").equals("sysop") - && query.getNode("/api/query/pages/page/protection/pr[" + i + "]/@type").equals("edit")) { - isProtectedEdit = true; - } - if(query.getNode("/api/query/pages/page/protection/pr[" + i + "]/@level").equals("sysop") - && query.getNode("/api/query/pages/page/protection/pr[" + i + "]/@type").equals("move")) { - isProtectedMove = true; - } - } - } - boolean isProtected = false; - if(isProtectedEdit && isProtectedMove) { - isProtected = true; - } - if(protect && !isProtected) { - //Protect it - getXML(endpoint, mapCreator( - "action", "protect", - "title", fullPath, - "token", protectToken, - "protections", "edit=sysop|move=sysop", - "expiry", "infinite", - "reason", "Autoprotecting page (This is a bot edit)" - )); - } else if(!protect && isProtected) { - //Unprotect it - getXML(endpoint, mapCreator( - "action", "protect", - "title", fullPath, - "token", protectToken, - "protections", "edit=autoconfirmed|move=autoconfirmed", - "expiry", "infinite", - "reason", "Autoprotecting page (This is a bot edit)" - )); - } - - } - incProgress(); - } - - private void incProgress() { - atPage++; - if(totalPages == 0) { - progress.setProgress(null); - } else { - progress.setProgress((int) ((float) atPage / (float) totalPages * 100.0)); - } - } - - private int getFunctionCount() { - return 1; - } - - private int getExampleCount() { - return FunctionList.getFunctionList(api.Platforms.INTERPRETER_JAVA).size(); - } - - private int getEventCount() { - return 1; - } - - private int getTemplateCount() throws IOException { - try { - int count = 0; - ZipReader reader = new ZipReader(new File(DocGenUIHandler.class.getResource("/docs").toURI())); - Queue q = new LinkedList<>(); - q.addAll(Arrays.asList(reader.listFiles())); - while(q.peek() != null) { - ZipReader r = new ZipReader(q.poll()); - if(r.isDirectory()) { - q.addAll(Arrays.asList(r.listFiles())); - } else { - count++; - } - } - return count; - } catch (URISyntaxException ex) { - throw new APIException(ex); - } - } - - private int getMiscCount() { - int total = 0; - - return total; - } - - private void doLogin() throws MalformedURLException, XPathExpressionException { - checkStop(); - XMLDocument login = getXML(endpoint, mapCreator( - "format", "xml", - "action", "login", - "lgname", username, - "lgpassword", password - )); - if("NeedToken".equals(login.getNode("/api/login/@result"))) { - XMLDocument login2 = getXML(endpoint, mapCreator( - "format", "xml", - "action", "login", - "lgname", username, - "lgpassword", password, - "lgtoken", login.getNode("/api/login/@token") - )); - if(!"Success".equals(login2.getNode("/api/login/@result"))) { - if("WrongPass".equals(login2.getNode("/api/login/@result"))) { - throw new APIException("Wrong password."); - } - throw new APIException("Could not log in successfully."); - } - } - progress.setStatus("Logged in"); - password = null; - } - - public static class APIException extends RuntimeException { - - public APIException(String message) { - super(message); - } - - public APIException(Throwable cause) { - super("API responded incorrectly.", cause); - } - - } - - private static String getSha1(String content) { - try { - MessageDigest digest = java.security.MessageDigest.getInstance("SHA1"); - digest.update(content.getBytes()); - String hash = StringUtils.toHex(digest.digest()).toLowerCase(); - return hash; - } catch (NoSuchAlgorithmException ex) { - throw new RuntimeException("An error occured while trying to hash your data", ex); - } - } - - private static Map mapCreator(String... strings) { - if(strings.length % 2 != 0) { - throw new Error("Only an even number of parameters may be passed to mapCreator"); - } - Map map = new HashMap<>(); - for(int i = 0; i < strings.length; i += 2) { - map.put(strings[i], strings[i + 1]); - } - return map; - } - private static CookieJar cookieStash = new CookieJar(); - - private static XMLDocument getXML(URL url, Map params) throws APIException { - return getXML(url, params, true); - } - - private static XMLDocument getXML(URL url, Map params, boolean useURL) throws APIException { - try { - XMLDocument doc = new XMLDocument(getPage(url, params, useURL).getContentAsString()); - if(doc.nodeExists("/api/error")) { - //Doh. - throw new APIException(doc.getNode("/api/error/@info")); - } - return doc; - } catch (XPathExpressionException | SAXException | IOException e) { - throw new APIException(e); - } - } - - private static HTTPResponse getPage(URL url) throws IOException { - return getPage(url, null); - } - - private static HTTPResponse getPage(URL url, Map params) throws IOException { - return getPage(url, params, false); - } - - /** - * The wiki apparently wants the parameters in the URL, but the method set to post. If useURL is true, it will merge - * the params into the url. - * - * @param url - * @param params - * @param useURL - * @return - * @throws IOException - */ - private static HTTPResponse getPage(URL url, Map params, boolean useURL) throws IOException { - Map> headers = new HashMap<>(BASE_HEADERS); - if(params != null && !params.isEmpty() && useURL) { - StringBuilder b = new StringBuilder(url.getQuery() == null ? "" : url.getQuery()); - if(b.length() != 0) { - b.append("&"); - } - RequestSettings temp = new RequestSettings().setParameters(params); - b.append(WebUtility.encodeParameters(temp.getParameters())); - String query = b.toString(); - url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath() + "?" + query); - } - headers.put("Host", Arrays.asList(new String[]{url.getHost()})); - RequestSettings settings = new RequestSettings().setMethod(HTTPMethod.POST).setHeaders(headers) - .setParameters(params).setCookieJar(cookieStash).setFollowRedirects(true); - return WebUtility.GetPage(url, settings); - } - - public static void testCompileExamples() { - for(FunctionBase fb : FunctionList.getFunctionList(api.Platforms.INTERPRETER_JAVA)) { - if(fb instanceof Function) { - Function f = (Function) fb; - try { - f.examples(); - } catch (ConfigCompileException e) { - throw new RuntimeException("Compilation error while compiling examples for " + f.getName(), e); - } - } - } - } - -} diff --git a/src/main/java/com/laytonsmith/tools/docgen/SingleFunctionDialog.form b/src/main/java/com/laytonsmith/tools/docgen/SingleFunctionDialog.form deleted file mode 100644 index 183026de9..000000000 --- a/src/main/java/com/laytonsmith/tools/docgen/SingleFunctionDialog.form +++ /dev/null @@ -1,84 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/main/java/com/laytonsmith/tools/docgen/SingleFunctionDialog.java b/src/main/java/com/laytonsmith/tools/docgen/SingleFunctionDialog.java deleted file mode 100644 index 400babc36..000000000 --- a/src/main/java/com/laytonsmith/tools/docgen/SingleFunctionDialog.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.laytonsmith.tools.docgen; - -import com.laytonsmith.PureUtilities.Common.StreamUtils; -import com.laytonsmith.PureUtilities.Common.UIUtils; -import com.laytonsmith.core.constructs.Target; -import com.laytonsmith.core.exceptions.ConfigCompileException; -import com.laytonsmith.core.functions.Function; -import com.laytonsmith.core.functions.FunctionList; - -/** - * - * - */ -public class SingleFunctionDialog extends javax.swing.JDialog { - - DocGenUI parent; - - /** - * Creates new form SingleFunctionDialog - */ - public SingleFunctionDialog(DocGenUI parent) { - super(parent, true); - this.parent = parent; - initComponents(); - UIUtils.centerWindowOnWindow(this, parent); - } - - /** - * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The - * content of this method is always regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jLabel1 = new javax.swing.JLabel(); - functionNameField = new javax.swing.JTextField(); - uploadButton = new javax.swing.JButton(); - statusLabel = new javax.swing.JLabel(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - - jLabel1.setText("Function:"); - - uploadButton.setText("Upload"); - uploadButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - uploadButtonActionPerformed(evt); - } - }); - - statusLabel.setText("Waiting..."); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(functionNameField)) - .addGroup(layout.createSequentialGroup() - .addComponent(uploadButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 222, Short.MAX_VALUE) - .addComponent(statusLabel))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(functionNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(uploadButton) - .addComponent(statusLabel)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - pack(); - } // //GEN-END:initComponents - - private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) { // GEN-FIRST:event_uploadButtonActionPerformed - Function f; - try { - f = (Function) FunctionList.getFunction(functionNameField.getText(), Target.UNKNOWN); - if(!f.appearInDocumentation()) { - statusLabel.setText("That function is not configured to have documentation."); - return; - } - try { - String docs = DocGen.examples(f.getName(), parent.handler.isStaged); - parent.handler.doUpload(docs, "/API/" + f.getName(), true); - } catch (Exception ex) { - statusLabel.setText(ex.getMessage()); - ex.printStackTrace(StreamUtils.GetSystemErr()); - } - } catch (ConfigCompileException ex) { - statusLabel.setText("That function doesn't exist."); - return; - } - - } // GEN-LAST:event_uploadButtonActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JTextField functionNameField; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel statusLabel; - private javax.swing.JButton uploadButton; - // End of variables declaration//GEN-END:variables -} diff --git a/src/main/java/com/laytonsmith/tools/pnviewer/PNViewer.java b/src/main/java/com/laytonsmith/tools/pnviewer/PNViewer.java index b2412c82f..28b230f16 100644 --- a/src/main/java/com/laytonsmith/tools/pnviewer/PNViewer.java +++ b/src/main/java/com/laytonsmith/tools/pnviewer/PNViewer.java @@ -265,7 +265,7 @@ public void actionPerformed(ActionEvent e) { @Override public String generate(String... args) { - return "http://wiki.sk89q.com/wiki/CommandHelper/Staged/" + args[0]; + return "https://methodscript.com/docs/" + MSVersion.LATEST + "/" + args[0] + ".html"; } }); builder.addTemplate("jarName", new TemplateBuilder.Generator() { diff --git a/src/main/resources/com/laytonsmith/tools/pnviewer/HelpDialog.html b/src/main/resources/com/laytonsmith/tools/pnviewer/HelpDialog.html index 1231e240a..c404b0908 100644 --- a/src/main/resources/com/laytonsmith/tools/pnviewer/HelpDialog.html +++ b/src/main/resources/com/laytonsmith/tools/pnviewer/HelpDialog.html @@ -17,7 +17,7 @@

General

data format of each one is. The system as a whole deals with key-value pairs, where the keys themselves form a hierarchy, and can be visualized as a tree. Any data may be stored in the values themselves, including arrays. This help section does not cover setting up the PN, for more information on that, please - see the documentation on the wiki. + see the documentation on the website. The first step to using the tool is to connect to a data source. This differs depending on whether or not you are connecting to a local network (on the same computer) or a remote network (on another computer). A