From 5c8be646652e20eff7b2c18608b5b051c650d943 Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 4 Apr 2011 15:33:28 +0000 Subject: [PATCH] 341788: check two new versions of windows --- build/src/$installer$/org/aspectj/Main.java | 3364 +++++++++---------- 1 file changed, 1654 insertions(+), 1710 deletions(-) diff --git a/build/src/$installer$/org/aspectj/Main.java b/build/src/$installer$/org/aspectj/Main.java index 5f610645b..24256b3c7 100644 --- a/build/src/$installer$/org/aspectj/Main.java +++ b/build/src/$installer$/org/aspectj/Main.java @@ -11,8 +11,6 @@ * Xerox/PARC initial implementation * ******************************************************************/ - - package $installer$.org.aspectj; import java.awt.BorderLayout; @@ -66,1456 +64,1447 @@ import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; /** - * Invoke the Installer gui. - * There are two ways to run without GUI by passing parameters to main: + * Invoke the Installer gui. There are two ways to run without GUI by passing parameters to main: *
    *
  1. pass -text {pathToPropertiesFile}: *
      - *
    • "-text".equals(arg[0])
    • - *
    • arg[1] is the path to a properties file which defines - * name="output.dir" value="{path to output dir}" - * name="context.javaPath" value="{path to JDKDIR}", i.e,. - *
      output.dir=c:/latest
      - *   "context.javaPath=c:/apps/jdk1.3.1
    • + *
    • "-text".equals(arg[0])
    • + *
    • arg[1] is the path to a properties file which defines name="output.dir" value="{path to output dir}" name="context.javaPath" + * value="{path to JDKDIR}", i.e,. + * + *
      + * output.dir=c:/latest
      + *   "context.javaPath=c:/apps/jdk1.3.1
      + * 
      + * + *
    • *
    • outputDir must be created and empty (i.e., no overwriting
    • *
    • the VM being invoked should be the target vm
    • *
    *
  2. *
  3. pass -to {pathToTargetDir}: *
      - *
    • "-to".equals(arg[0])
    • - *
    • arg[1] is the path to a writable install directory. - *
    • + *
    • "-to".equals(arg[0])
    • + *
    • arg[1] is the path to a writable install directory.
    • *
    *
  4. */ public class Main { - public static void main(String[] args) { - Options.loadArgs(args); - boolean hasGui = true; - Properties properties = new Properties(); - InputStream istream = null; - try { - istream = Main.class.getResourceAsStream(Installer.RESOURCE_DIR + "/properties.txt"); - if (istream == null) { - System.err.println("unable to load properties.txt using Main.class - exiting"); - Main.exit(-1); - } - properties.load(istream); - // when running outside GUI, load values into properties - // so that property-value resolution works - // (otherwise, could just set values below). - // XXX not sure if this indirection is actually needed. - if (null != Options.textProperties) { - istream.close(); - istream = new FileInputStream(Options.textProperties); - properties.load(istream); - hasGui = false; - } else if (null != Options.targetDir) { - String path = null; - try { - path = Options.targetDir.getCanonicalPath(); - } catch (IOException e) { - path = Options.targetDir.getAbsolutePath(); - } - String javaPath - = ConfigureLauncherPane.getDefaultJavaHomeLocation(); - if (null == javaPath) { - System.err.println("using GUI - unable to find java"); - } else { - properties.setProperty("output.dir", path); - properties.setProperty("context.javaPath", javaPath); - hasGui = false; - } - } - } catch (IOException ioe) { - handleException(ioe); - } finally { - if (null != istream) { - try {istream.close();} - catch (IOException e){} // ignore - } - } - - try { - String className = (String)properties.get("installer.main.class"); - //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - Installer installer = (Installer)Class.forName(className).newInstance(); - InstallContext installerContext = new InstallContext(properties); - installerContext.setHasGui(hasGui); - installer.setContext(installerContext); - if (installerContext.hasGui()) { // let context force whether or not to run gui - installer.runGUI(); - } else { - // set output dir and java path in context after minimal validation - String propName = "output.dir"; - String propValue = properties.getProperty(propName); - if (null == propValue) { - throw new Exception("expecting property " + propName); - } - String outputDirName = propValue; - propName = "context.javaPath"; - propValue = properties.getProperty(propName); - if (null == propValue) { - throw new Exception("expecting property " + propName); - } - String javaPath = propValue; - File outputDir = new File(outputDirName); - if (! outputDir.isDirectory()) { - throw new Exception("not a dir outputDirName: " + outputDirName - + " dir: " + outputDir); - } - if (! outputDir.canWrite()) { - throw new Exception("cannot write outputDirName: " + outputDirName - + " dir: " + outputDir); - } - InstallContext context = installer.getContext(); // todo: why not use installerContext? - context.setOutputDir(outputDir); - context.javaPath = new File(javaPath); - // todo: check javaPath for ... bin/java? lib/rt.jar? - if (! outputDir.isDirectory() || ! outputDir.canRead()) { - throw new Exception("invalid javaPath: " + javaPath); - } - // directly set context and run - WizardPane.setContext(installerContext); - installer.run(); - } - } catch (Exception e) { - handleException(e); - } - } - - public static void handleException(Throwable e) { - System.out.println("internal error: " + e.toString()); - e.printStackTrace(); - Main.exit(-1); - } - - /** indirection for System.exit - todo apply cleanup here as necessary */ - public static void exit(int value) { - System.exit(value); - } + public static void main(String[] args) { + Options.loadArgs(args); + boolean hasGui = true; + Properties properties = new Properties(); + InputStream istream = null; + try { + istream = Main.class.getResourceAsStream(Installer.RESOURCE_DIR + "/properties.txt"); + if (istream == null) { + System.err.println("unable to load properties.txt using Main.class - exiting"); + Main.exit(-1); + } + properties.load(istream); + // when running outside GUI, load values into properties + // so that property-value resolution works + // (otherwise, could just set values below). + // XXX not sure if this indirection is actually needed. + if (null != Options.textProperties) { + istream.close(); + istream = new FileInputStream(Options.textProperties); + properties.load(istream); + hasGui = false; + } else if (null != Options.targetDir) { + String path = null; + try { + path = Options.targetDir.getCanonicalPath(); + } catch (IOException e) { + path = Options.targetDir.getAbsolutePath(); + } + String javaPath = ConfigureLauncherPane.getDefaultJavaHomeLocation(); + if (null == javaPath) { + System.err.println("using GUI - unable to find java"); + } else { + properties.setProperty("output.dir", path); + properties.setProperty("context.javaPath", javaPath); + hasGui = false; + } + } + } catch (IOException ioe) { + handleException(ioe); + } finally { + if (null != istream) { + try { + istream.close(); + } catch (IOException e) { + } // ignore + } + } + + try { + String className = (String) properties.get("installer.main.class"); + //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + Installer installer = (Installer) Class.forName(className).newInstance(); + InstallContext installerContext = new InstallContext(properties); + installerContext.setHasGui(hasGui); + installer.setContext(installerContext); + if (installerContext.hasGui()) { // let context force whether or not to run gui + installer.runGUI(); + } else { + // set output dir and java path in context after minimal validation + String propName = "output.dir"; + String propValue = properties.getProperty(propName); + if (null == propValue) { + throw new Exception("expecting property " + propName); + } + String outputDirName = propValue; + propName = "context.javaPath"; + propValue = properties.getProperty(propName); + if (null == propValue) { + throw new Exception("expecting property " + propName); + } + String javaPath = propValue; + File outputDir = new File(outputDirName); + if (!outputDir.isDirectory()) { + throw new Exception("not a dir outputDirName: " + outputDirName + " dir: " + outputDir); + } + if (!outputDir.canWrite()) { + throw new Exception("cannot write outputDirName: " + outputDirName + " dir: " + outputDir); + } + InstallContext context = installer.getContext(); // todo: why not use installerContext? + context.setOutputDir(outputDir); + context.javaPath = new File(javaPath); + // todo: check javaPath for ... bin/java? lib/rt.jar? + if (!outputDir.isDirectory() || !outputDir.canRead()) { + throw new Exception("invalid javaPath: " + javaPath); + } + // directly set context and run + WizardPane.setContext(installerContext); + installer.run(); + } + } catch (Exception e) { + handleException(e); + } + } + + public static void handleException(Throwable e) { + System.out.println("internal error: " + e.toString()); + e.printStackTrace(); + Main.exit(-1); + } + + /** indirection for System.exit - todo apply cleanup here as necessary */ + public static void exit(int value) { + System.exit(value); + } } // class Main class Options { - public static boolean verbose = false; - public static String textProperties = null; - public static File targetDir = null; - public static boolean forceError1 = false; - public static boolean forceError2 = false; - public static boolean forceHandConfigure = false; - - public static void loadArgs(String[] args) { - if (args == null) return; - for (int i=0; i 600) x = 600; - if (y < 0) y = 0; - if (y > 400) y = 400; - - frame.setLocation(x, y); - frame.setSize(getWidth(), getHeight()); - moveToPane(getPanes()[0]); - frame.setVisible(true); - } - - public void moveToPane(WizardPane pane) { - WizardPane.setContext(this.context); - - Dimension size = frame.getContentPane().getSize(); - - JPanel contents = new JPanel(); - contents.setLayout(new BorderLayout()); - header = makeHeader(); - contents.add(header, BorderLayout.NORTH); - - body = pane.getPanel(); - contents.add(body, BorderLayout.CENTER); - - footer = pane.getButtons(); - contents.add(footer, BorderLayout.SOUTH); - - contents.revalidate(); - contents.setSize(size); - - frame.setContentPane(contents); - - //XXX deal with threading here? - pane.run(); - } - - public Icon loadImage(String name) { - return new javax.swing.ImageIcon(this.getClass().getResource(name)); - } - - public Component makeHeader() { - return new JLabel(loadImage(Installer.RESOURCE_DIR + "/aspectjBanner.gif")); - } - - public ActionListener makeNextAction(final WizardPane pane) { - int nextPaneIndex = findPaneIndex(pane) + 1; - if (nextPaneIndex >= getPanes().length) { - return null; - } - - final WizardPane nextPane = getPanes()[nextPaneIndex]; - return new ActionListener() { - public void actionPerformed(ActionEvent e) { - pane.finish(); - moveToPane(nextPane); - } - }; - } - - public ActionListener makeBackAction(final WizardPane pane) { - int nextPaneIndex = findPaneIndex(pane) - 1; - if (nextPaneIndex < 0) { - return null; - } - - final WizardPane nextPane = getPanes()[nextPaneIndex]; - return new ActionListener() { - public void actionPerformed(ActionEvent e) { - moveToPane(nextPane); - } - }; - } - - public ActionListener makeCancelAction(WizardPane pane) { - return new ActionListener() { - public void actionPerformed(ActionEvent e) { - int ret = JOptionPane.showConfirmDialog(frame, EXIT_MESSAGE, EXIT_TITLE, - JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE); - if (ret == JOptionPane.YES_OPTION) { - Main.exit(-1); - } - } - }; - } - public ActionListener makeFinishAction(WizardPane pane) { - return new ActionListener() { - public void actionPerformed(ActionEvent e) { - Main.exit(0); - } - }; - } + static final String EXIT_MESSAGE = "Are you sure you want to cancel the installation?"; + static final String EXIT_TITLE = "Exiting installer"; + /** + * relative directory in jar from package $installer$.org.aspectj for loading resources - todo must be tracked during build + */ + public static final String RESOURCE_DIR = "resources"; + + JFrame frame; + InstallContext context; + /** special pane that actually does the installation */ + InstallPane installPane; + + public Installer() { + } + + protected void setInstallPane(InstallPane installPane) { + this.installPane = installPane; + } + + public InstallPane getInstallPane() { + return installPane; + } + + /** directly run the install pane, if any */ + public void run() { + if (null != installPane) { + installPane.run(); + } + } + + public abstract String getPrefix(); + + public String getReadmeFilename() { + return "README-" + getPrefix().toUpperCase() + ".html"; + } + + public void setContext(InstallContext context) { + this.context = context; + context.installer = this; + } + + public InstallContext getContext() { + return context; + } + + public String getTitle() { + return "AspectJ(TM) Installer"; + } + + public int getWidth() { + return 640; + } + + public int getHeight() { + return 460; + } + + protected WizardPane[] panes = new WizardPane[0]; + + public WizardPane[] getPanes() { + return panes; + } + + public int findPaneIndex(WizardPane pane) { + for (int i = 0; i < panes.length; i++) { + if (panes[i] == pane) { + return i; + } + } + return -1; + } + + Component header, footer, body; + + public void runGUI() { + frame = new JFrame(getTitle()); + WindowListener wl = new WindowAdapter() { + public void windowClosing(WindowEvent arg0) { + Main.exit(-1); // -1 unless exiting through done button + } + }; + frame.addWindowListener(wl); + + if (Options.forceError1) { + throw new RuntimeException("forced error1 for testing purposes"); + } + + Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); + + int x = (int) (size.getWidth() - getWidth()) / 2; + int y = (int) (size.getHeight() - getHeight()) / 2; + + //include a few sanity checks on starting position + if (x < 0) { + x = 0; + } + if (x > 600) { + x = 600; + } + if (y < 0) { + y = 0; + } + if (y > 400) { + y = 400; + } + + frame.setLocation(x, y); + frame.setSize(getWidth(), getHeight()); + moveToPane(getPanes()[0]); + frame.setVisible(true); + } + + public void moveToPane(WizardPane pane) { + WizardPane.setContext(this.context); + + Dimension size = frame.getContentPane().getSize(); + + JPanel contents = new JPanel(); + contents.setLayout(new BorderLayout()); + header = makeHeader(); + contents.add(header, BorderLayout.NORTH); + + body = pane.getPanel(); + contents.add(body, BorderLayout.CENTER); + + footer = pane.getButtons(); + contents.add(footer, BorderLayout.SOUTH); + + contents.revalidate(); + contents.setSize(size); + + frame.setContentPane(contents); + + //XXX deal with threading here? + pane.run(); + } + + public Icon loadImage(String name) { + return new javax.swing.ImageIcon(this.getClass().getResource(name)); + } + + public Component makeHeader() { + return new JLabel(loadImage(Installer.RESOURCE_DIR + "/aspectjBanner.gif")); + } + + public ActionListener makeNextAction(final WizardPane pane) { + int nextPaneIndex = findPaneIndex(pane) + 1; + if (nextPaneIndex >= getPanes().length) { + return null; + } + + final WizardPane nextPane = getPanes()[nextPaneIndex]; + return new ActionListener() { + public void actionPerformed(ActionEvent e) { + pane.finish(); + moveToPane(nextPane); + } + }; + } + + public ActionListener makeBackAction(final WizardPane pane) { + int nextPaneIndex = findPaneIndex(pane) - 1; + if (nextPaneIndex < 0) { + return null; + } + + final WizardPane nextPane = getPanes()[nextPaneIndex]; + return new ActionListener() { + public void actionPerformed(ActionEvent e) { + moveToPane(nextPane); + } + }; + } + + public ActionListener makeCancelAction(WizardPane pane) { + return new ActionListener() { + public void actionPerformed(ActionEvent e) { + int ret = JOptionPane.showConfirmDialog(frame, EXIT_MESSAGE, EXIT_TITLE, JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE); + if (ret == JOptionPane.YES_OPTION) { + Main.exit(-1); + } + } + }; + } + + public ActionListener makeFinishAction(WizardPane pane) { + return new ActionListener() { + public void actionPerformed(ActionEvent e) { + Main.exit(0); + } + }; + } } +// willing to go up to 3 levels deep to find either jre or jdk +// jre\[*\]lib\ext +// jdk*\lib\tools.jar - // willing to go up to 3 levels deep to find either jre or jdk - - // jre\[*\]lib\ext - // jdk*\lib\tools.jar - - /***** - final static int MAX_DEPTH = 4; - public static void findPaths(String prefix, File currentDir, int currentDepth) { - if (currentDepth > MAX_DEPTH) return; - if (!currentDir.exists() || !currentDir.isDirectory()) return; - File [] files = currentDir.listFiles(); - if (files == null) return; - for (int i=0; i MAX_DEPTH) return; if (!currentDir.exists() || !currentDir.isDirectory()) return; File [] files = currentDir.listFiles(); if + * (files == null) return; for (int i=0; i"); - int stopIndex = text.indexOf(""); - if (startIndex == -1 || stopIndex == -1) return text; - stopIndex += 7; - return text.substring(0, startIndex) + text.substring(stopIndex); - } - - static String styleHeader = "";/*