Last active
December 9, 2019 19:43
-
-
Save SubOptimal/a57400defc5e69f0de1f7b99b38d7ce2 to your computer and use it in GitHub Desktop.
Netbeans Tomcat HOME check - see: https://twitter.com/speakjava/status/1202692785155035137 --- https://twitter.com/lamitpobus/status/1203312117560070144?s=20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NB_HOME=~/bin/netbeans.11.2 | |
NB_LIB=$NB_HOME/enterprise/modules | |
[ ! -d build ] && mkdir build | |
javac -cp $NB_LIB/ext/jsr88javax.jar:\ | |
$NB_LIB/org-netbeans-modules-tomcat5.jar \ | |
-d build \ | |
Main.java WizardCheck.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sub.optimal; | |
import java.io.File; | |
import org.netbeans.modules.tomcat5.TomcatFactory; | |
public class Main { | |
public static void main(String[] args) { | |
File catalinaHome = new File(args[0]); | |
String version = TomcatFactory.getTomcatVersionString(catalinaHome); | |
System.out.println("version = " + version); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NB_HOME=~/bin/netbeans.11.2 | |
NB_LIB=$NB_HOME/enterprise/modules | |
TOMCAT_5_HOME=/tmp/apache-tomcat-5.5.36 | |
TOMCAT_8_HOME=/tmp/apache-tomcat-8.5.49 | |
echo "### Netbeans classpath" | |
java -cp build:\ | |
$NB_LIB/ext/jsr88javax.jar:\ | |
$NB_LIB/org-netbeans-modules-tomcat5.jar \ | |
sub.optimal.Main $TOMCAT_8_HOME | |
echo | |
echo "### classpath with hidden Tomcat 5 libs" | |
java -cp build:\ | |
$TOMCAT_5_HOME/server/lib/catalina.jar:\ | |
$NB_LIB/ext/jsr88javax.jar:\ | |
$NB_LIB/org-netbeans-modules-tomcat5.jar \ | |
sub.optimal.Main $TOMCAT_8_HOME | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TOMCAT_5_HOME=/tmp/apache-tomcat-5.5.36 | |
NB_HOME=~/bin/netbeans.11.2 | |
echo "### classpath with hidden Tomcat 5 libs" | |
java -cp build:\ | |
$TOMCAT_5_HOME/server/lib/catalina.jar:\ | |
$NB_HOME/enterprise/modules/ext/jsr88javax.jar:\ | |
$NB_HOME/java/modules/org-netbeans-modules-form.jar:\ | |
$NB_HOME/ide/modules/org-netbeans-modules-schema2beans.jar:\ | |
$NB_HOME/enterprise/modules/org-netbeans-modules-tomcat5.jar:\ | |
$NB_HOME/platform/modules/org-openide-awt.jar:\ | |
$NB_HOME/platform/modules/org-openide-loaders.jar:\ | |
$NB_HOME/platform/modules/org-openide-nodes.jar:\ | |
$NB_HOME/platform/lib/org-openide-util.jar:\ | |
$NB_HOME/platform/lib/org-openide-util-lookup.jar:\ | |
$NB_HOME/platform/lib/org-openide-util-ui.jar \ | |
org.netbeans.modules.tomcat5.ui.wizard.WizardCheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NB_HOME=~/bin/netbeans.11.2 | |
echo "### Netbeans classpath" | |
java -cp build:\ | |
$NB_HOME/enterprise/modules/ext/jsr88javax.jar:\ | |
$NB_HOME/java/modules/org-netbeans-modules-form.jar:\ | |
$NB_HOME/ide/modules/org-netbeans-modules-schema2beans.jar:\ | |
$NB_HOME/enterprise/modules/org-netbeans-modules-tomcat5.jar:\ | |
$NB_HOME/platform/modules/org-openide-awt.jar:\ | |
$NB_HOME/platform/modules/org-openide-loaders.jar:\ | |
$NB_HOME/platform/modules/org-openide-nodes.jar:\ | |
$NB_HOME/platform/lib/org-openide-util.jar:\ | |
$NB_HOME/platform/lib/org-openide-util-lookup.jar:\ | |
$NB_HOME/platform/lib/org-openide-util-ui.jar \ | |
org.netbeans.modules.tomcat5.ui.wizard.WizardCheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.netbeans.modules.tomcat5.ui.wizard; | |
import java.awt.HeadlessException; | |
import java.io.File; | |
import java.lang.reflect.Field; | |
import java.lang.reflect.InvocationTargetException; | |
import java.lang.reflect.Method; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import javax.swing.JFrame; | |
import javax.swing.JTextField; | |
import javax.swing.WindowConstants; | |
import org.netbeans.modules.tomcat5.TomcatFactory; | |
public class WizardCheck { | |
static final Logger LOGGER = Logger.getGlobal(); | |
private static final Class<TomcatFactory> TOMCAT_FACTORY = TomcatFactory.class; | |
private static final Class<InstallPanelVisual> INSTALL_PANEL_VISUAL = InstallPanelVisual.class; | |
private InstallPanelVisual component; | |
private Method getTomcatVersionFallback; | |
private Field jTextFieldHomeDir; | |
public static void main(String[] args) throws NoSuchMethodException, SecurityException, NoSuchFieldException { | |
new WizardCheck().execute(); | |
} | |
private void execute() throws SecurityException, NoSuchMethodException, HeadlessException, NoSuchFieldException { | |
System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tT] [%4$-7s] %5$s %n"); | |
LOGGER.setLevel(Level.ALL); | |
initReflection(); | |
component = new InstallPanelVisual(); | |
component.addChangeListener((e) -> { | |
LOGGER.log(Level.SEVERE, "getErrorMessage: {0}", component.getErrorMessage()); | |
this.showVersions(component.getHomeDir()); | |
}); | |
JFrame frame = new JFrame(); | |
frame.add(component); | |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); | |
frame.setVisible(true); | |
frame.pack(); | |
} | |
private void showVersions(File catalinaHome) { | |
printHomeDir(); | |
printTomcatVersionString(catalinaHome); | |
} | |
private void printTomcatVersionString(File catalinaHome) { | |
// logic extracted from InstallPanelVisaul.fireChange | |
try { | |
String version = TomcatFactory.getTomcatVersionString(catalinaHome); | |
LOGGER.log(Level.INFO, "getTomcatVersionString: {0}", version); | |
} catch (IllegalStateException e) { | |
LOGGER.log(Level.INFO, "getTomcatVersionString: {0}", e.getMessage()); | |
try { | |
// this branch is executed when class 'org.apache.catalina.util.ServerInfo' | |
// is not found | |
// see: TomcatVersion.getTomcatVersion | |
String version = (String) getTomcatVersionFallback.invoke(TOMCAT_FACTORY, catalinaHome); | |
LOGGER.log(Level.INFO, "getTomcatVersionFallback: {0}", version); | |
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { | |
LOGGER.log(Level.INFO, "getTomcatVersionFallback: {0}", ex.getMessage()); | |
} | |
} | |
} | |
private void printHomeDir() { | |
try { | |
JTextField homeDir = (JTextField) jTextFieldHomeDir.get(component); | |
LOGGER.log(Level.INFO, "jTextFieldHomeDir: [{0}]", homeDir.getText()); | |
} catch (IllegalAccessException | IllegalArgumentException ex) { | |
LOGGER.log(Level.INFO, "jTextFieldHomeDir: {0}", ex.getMessage()); | |
} | |
} | |
private void initReflection() throws NoSuchMethodException, SecurityException, NoSuchFieldException { | |
getTomcatVersionFallback = TOMCAT_FACTORY.getDeclaredMethod("getTomcatVersionFallback", File.class); | |
getTomcatVersionFallback.setAccessible(true); | |
jTextFieldHomeDir = INSTALL_PANEL_VISUAL.getDeclaredField("jTextFieldHomeDir"); | |
jTextFieldHomeDir.setAccessible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment