Yet another way to use Java

Discussion in 'Java' started by Roedy Green, May 24, 2004.

  1. Roedy Green

    Roedy Green Guest

    I noticed that every time I start a new project I have to clone and
    modify some existing one. It takes a long time. Further, if I learn
    a better way of doing things, that only shows up in new projects.

    So I decide to write a Project Stomper, a cookie cutter that creates
    all the files I need.

    Here is the source. You could not use it unmodified, but it could be
    a great start on doing your own. This would have been a great project
    for JDK 1.5 enum.

    Every time I make a change the program, I can stomp out an entire new
    set of files for EVERYTHING. Some I don't override, since the ones
    this generates are just starting points.

    This program was not intended for publication. That is why you see so
    mary peculiar Roedyism's hard-coded in.


    ----------------------------------------

    package com.mindprod.stomp;

    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;

    import com.mindprod.pricelist.AppCategories;
    import com.mindprod.pricelist.AppCats;

    /**
    * prepare all the files for a new project.
    *
    * @author Roedy Green
    * @version 1.0
    * @since 2004-05-20
    */
    public class StompProject implements AppCategories
    {

    /**
    * Create a new project
    *
    * @param mainClass e.g. FontShower, that name is lower case
    becomes
    * a segment of the package name, and also the
    * directory segment where the project lives.
    * @param versionTimesTen
    * if the version is 1.7, enter 17.
    * @param description
    * one sentence description of what this project
    does.
    * @param type "Applet","application", "weblet", "
    * @param signed true if digitally singede
    * @param distributeZip true post source code.
    */
    StompProject ( String mainClass,
    int versionTimesTen,
    String description,
    String type,
    boolean signed,
    boolean distributeZip )
    {
    this.mainClass = mainClass;
    this.projectLower = mainClass.toLowerCase();
    this.projectUpper = mainClass.toUpperCase();
    this.relativeProjectDir = "com\\mindprod" + "\\" + projectLower;
    this.absoluteProjectDir = "c:\\" + relativeProjectDir;
    this.packageFullyQualified = "com.mindprod." + projectLower;
    this.mainClassFullyQualified = packageFullyQualified + "." +
    mainClass;

    websiteURL = "http://www.mindprod.com";

    this.versionTimesTen = versionTimesTen;
    this.versionString = (versionTimesTen / 10) + "." +
    (versionTimesTen % 10);

    this.description = description;

    this.type = AppCats.stringToEnum( type );

    this.signed = signed;

    this.distributeZip = distributeZip;


    switch ( this.type )
    {
    default:
    case APPLET:
    case APPLICATION:
    case WEBLET:
    case HYBRID:
    case LIBRARY:
    this.hasJar = true;
    break;

    case DOCUMENTATION:
    case UTILITY:
    this.hasJar = false;
    break;
    }


    switch ( this.type )
    {

    case APPLICATION:
    case HYBRID:
    this.jettable = true;
    break;

    default:
    case APPLET:
    case DOCUMENTATION:
    case LIBRARY:
    case UTILITY:
    case WEBLET:
    this.jettable = false;
    break;
    }


    switch ( this.type )
    {

    case APPLET:
    case HYBRID:
    case WEBLET:
    this.hasHtml = true;
    break;

    default:
    case APPLICATION:
    case DOCUMENTATION:
    case LIBRARY:
    case UTILITY:
    this.hasHtml = false;
    break;
    }
    }
    /**
    * does this project have a jar
    */
    boolean hasJar;

    /**
    * does this project have an associated html file?
    */
    boolean hasHtml;

    /**
    * can jet static compilation be used?
    */
    boolean jettable;

    /**
    * e.g. com.mindprod.fontshower
    */
    String packageFullyQualified;

    /*
    * main class name e.g. FontShower
    */
    String mainClass;

    /**
    * e.g. com.mindprod.fontshower.FontShower
    */
    String mainClassFullyQualified;

    /**
    * website where this all gets uploaded
    */
    String websiteURL;

    /**
    * enumerated type e.g. APPLICATION APPLET HYBRID WEBLET LIBRARY
    UTILITY DOCUMENTATION
    */
    int type;

    /**
    * project name in lower case, e.g. fontshower
    */
    String projectLower;

    /*
    * project name in upper case, e.g. FONTSHOWER
    */
    String projectUpper;

    /**
    * description of what this project is about.
    */
    String description;

    /**
    * e.g. com\mindprod\fontshower
    */
    String relativeProjectDir;

    /**
    * e.g. C:\com\mindprod\fontshower
    */
    String absoluteProjectDir;

    /**
    * if version is 1.7, this is 17
    */
    int versionTimesTen;

    /**
    * e.g. "1.7"
    */
    String versionString;

    /**
    * true if signed
    */
    boolean signed;

    /**
    * true if we distribute a zip with source code
    */
    boolean distributeZip;

    /**
    * create the project directory
    * where most of the other files go.
    */
    void mkDir()
    {
    // always
    new File( absoluteProjectDir ).mkdirs();
    }

    /**
    * generate 4NT descriptions of all files.
    */
    void mkDescBtm()
    {
    String contents =

    "@echo on\n"
    + "@echo desc.btm add 4NT decriptions to all files\n"
    + "\n"
    + describe( projectLower + ".use", "precis of the " + mainClass
    + " project")
    + describe( "README.TXT", "List of all files for " +
    mainClass + ", with one line descriptions.")
    + describe( "desc.btm", "creates 4NT file
    descriptions")
    + describe( "DESCRIPT.ION", "4NT file descriptions");

    if ( hasJar )
    {
    contents += describe( "compile.bat", "compile
    everything for " + mainClass)
    + describe( "forjar.list", "list of
    extra files to include in " + projectLower +".jar")
    + describe( "main.mft", mainClass +
    "jar manifest")
    + describe( mainClass +".java", mainClass + "
    main Java program source")
    + describe( projectLower +".jar", mainClass + "
    jarred class files.");

    }

    contents += describe( "distribute.bat", "publish the " +
    mainClass + " files on the website.");

    if ( distributeZip )
    {

    contents += describe( projectLower + versionTimesTen +
    ".zip",
    mainClass + " " + versionString + "
    distribution as a zip archive")

    + describe( "forzip.list", "list of
    extra files to include in " + projectLower + versionTimesTen + ".zip"
    )
    + describe( "MasterDistribution.site",
    "URL to get the the master copy of
    the " + mainClass + " program");

    }

    if ( hasHtml )
    {
    contents += describe( projectLower + ".html", "html to run
    the " + mainClass + " program")
    + describe( "run.bat", "execute the "
    + mainClass + " application");
    }
    contents += "call mkReadme.btm\n"
    + "rem -30-\n";

    save( absoluteProjectDir + "\\" + "desc.btm", contents, true );

    }

    /**
    * prepare at line for the 4NT desribe utility
    * to describe no file.
    *
    * @param file unqualified name of file
    * @param description
    * description of what the file does
    *
    * @return one line bat command with \n.
    */
    private static String describe ( String file, String description )
    {
    return "describe " + "\"" + file + "\"" + " " + "\"" +
    description + "\"" + "\n";
    }
    /**
    * make the *.use text file that
    * briefly describes the project.
    */
    void mkUse()
    {
    // always
    String contents = mainClass + " Version " + versionString + "\n"
    + description + "\n"
    + "\n"
    + AppCats.enumToDescription( type, signed ) +
    ".\n"
    + "\n"
    + "Copyright 2004 Canadian Mind Products.\n"
    + "May be used freely for any purpose but
    military.\n";
    if ( distributeZip )
    {
    contents += "All Java source code is included.\n";
    }
    save( absoluteProjectDir + "\\" + projectLower + ".use",
    contents, false );
    }

    /**
    * generate the skeleton of the Java program.
    */
    void mkJava()
    {
    if ( hasJar )
    {

    String contents = "package " + packageFullyQualified + ";\n"
    + "import java.awt.*;\n"
    + "import java.awt.event.*;\n"
    + "import java.awt.image.*;\n"
    + "import java.io.*;\n"
    + "import java.net.*;\n"
    + "import java.text.*;\n"
    + "import java.util.*;\n"
    + "import java.util.zip.*;\n"
    + "import javax.imageio.*;\n"
    + "import javax.swing.*;\n"
    + "import javax.swing.event.*;\n"
    + "import javax.swing.tree.*;\n"
    + "\n"
    + "public class " + mainClass + "\n"
    + "{\n"
    + " /**\n"
    + " * test harness\n"
    + " *\n"
    + " * @param args not used\n"
    + " */\n"
    + " public static void main ( String[]
    args )\n"
    + " {\n"
    + " }\n"
    + "}\n";

    save( absoluteProjectDir + "\\" + mainClass + ".java",
    contents, false );
    }

    }

    /**
    * create the MasterDistribute.site file pointing to the master
    * URL where this program can be downloaded
    * from.
    */
    void mkMasterDistributionSite()
    {
    if ( distributeZip )
    {
    String contents = "http://mindprod.com/products.html#" +
    projectUpper +"\n";
    save( absoluteProjectDir + "\\MasterDistribution.site",
    contents, true );
    }
    }

    /**
    * create the main.mft manifest file.
    */
    void mkMainMft()
    {
    if ( hasJar )
    {
    // picky must be no space before and a space after.
    String contents = "Main-Class: " + mainClassFullyQualified +
    "\n";
    save( absoluteProjectDir + "\\main.mft", contents, true );
    }
    }

    /**
    * generate compile.bat to build, jar, sign, and create
    * and possibly a zip file for distribution
    */
    void mkCompileBat()
    {
    if ( hasJar )
    {
    String contents = "@echo on\n"
    + "@echo compile.bat compile, create jar,
    sign jar, make zip.\n"
    + "\n"
    + "C:\n"
    + "CD " + absoluteProjectDir + "\n"
    + "\n"
    + "javac *.java\n"
    + "\n";
    contents += compileTail();

    save( absoluteProjectDir + "\\compile.bat", contents, true );
    }
    }

    /**
    * handle post complile, create jar, sign, build zip.
    *
    * @return bat commands to do this.
    */
    String compileTail ()
    {
    String jarFile = relativeProjectDir + "\\" + projectLower +
    ".jar";

    String contents = "rem jar {ctxu}[vfm0M] [jar-file]
    [manifest-file] [-C dir] files ...\n"
    + "rem -c create new archive\n"
    + "rem -t list table of contents for
    archive\n"
    + "rem -x extract named (or all) files
    from archive\n"
    + "rem -u update existing archive\n"
    + "rem -v generate verbose output on
    standard output\n"
    + "rem -f specify archive file name\n"
    + "rem -m include manifest information
    from specified manifest file\n"
    + "rem -0 store only; use no ZIP
    compression\n"
    + "rem -M do not create a manifest file
    for the entries\n"
    + "rem -i generate index information for
    the specified jar files\n"
    + "rem -C change to the specified
    directory and include the following file\n"
    + "rem If any file is a directory then it is
    processed recursively.\n"
    + "rem The manifest file name and the archive
    file name needs to be specified\n"
    + "rem in the same order the \'m\' and \'f\'
    flags are specified.\n"
    + "\n"
    + "CD \\\n"
    + "jar.exe -cvfm " + jarFile + " "
    + relativeProjectDir + "\\main.mft "
    + relativeProjectDir + "\\*.class "
    + "@" + relativeProjectDir +
    "\\forjar.list\n";

    if ( signed )
    {
    contents += "\n"
    + "CD " + absoluteProjectDir + "\n"
    + "jarsigner -storepass %jarsignerpassword " +
    projectLower + ".jar mindprodcert\n";
    }

    if ( hasHtml )
    {
    contents += "\n"
    + "CD " + absoluteProjectDir + "\n"
    + "copy E:\\mindprod\\" + projectLower +
    ".html\n";
    }
    contents += "\n"
    + "CD " + absoluteProjectDir + "\n"
    + "call desc.btm\n";

    if ( distributeZip )
    {
    String zipFile = absoluteProjectDir + "\\" + projectLower +
    versionTimesTen + ".zip";

    contents += "\n"
    + "CD " + absoluteProjectDir + "\n"
    + "rem add to zip with full folder names\n"
    + "WZZIP -uP " + zipFile + " "
    + absoluteProjectDir + "\\*.bat "
    + absoluteProjectDir + "\\*.class "
    + absoluteProjectDir + "\\*.html "
    + absoluteProjectDir + "\\*.jar "
    + absoluteProjectDir + "\\*.java "
    + absoluteProjectDir + "\\*.txt "
    + absoluteProjectDir + "\\*.use "
    + absoluteProjectDir + "\\MasterDistribution.site
    "
    + "@forzip.list\n"
    + "describe " + zipFile + " \"" + description +
    "\"\n";

    }
    contents += "\n"
    + "CD " + absoluteProjectDir + "\n"
    + "rem -30-\n";
    return contents;

    }
    /**
    * generate jk.bat to build, jar, sign, and create
    * and possibly a zip file for distribution, using jikes compiler
    */
    void mkJkBat()
    {
    if ( hasJar )
    {
    String jarFile = relativeProjectDir + "\\" + projectLower +
    ".jar";
    String contents = "@echo on\n"
    + "@echo jk.bat use jikes to compile,
    create jar, sign jar, make zip.\n"
    + "\n"
    + "C:\n"
    + "CD " + absoluteProjectDir + "\n"
    + "\n"
    + "jikes *.java\n"
    + "\n";
    contents += compileTail();

    save( absoluteProjectDir + "\\jk.bat", contents, true );
    }
    }

    /**
    * generate jt.bat to postcompile with jet from teh jar.
    */
    void mkJtBat()
    {
    if ( jettable )
    {
    String jarFile = relativeProjectDir + "\\" + projectLower +
    ".jar";
    String contents = "@echo on\n"
    + "@echo jt.bat use jet to compile the
    jar\n"
    + "C:\n"
    + "CD " + absoluteProjectDir + "\n"
    + "\n"
    + "jc " + projectLower + ".jar\n"
    + "\n"
    + "rem -30-\n";

    save( absoluteProjectDir + "\\jt.bat", contents, true );
    }
    }



    /**
    * generate compile and distribute
    */
    void mkJustBat()
    {
    if ( hasJar )
    {
    String contents = "@echo on\n"
    + "@echo just.bat\n"
    + "\n"
    + "C:\n"
    + "CD " + absoluteProjectDir + "\n"
    + "\n"
    + "call compile.bat\n"
    + "call distribute.bat\n"
    + "\n"
    + "rem -30-\n";
    save( absoluteProjectDir + "\\just.bat", contents, false );
    }
    }
    /**
    * generate the forjar.list of what extra to include in the jar
    */
    void mkForJarList()
    {
    if ( hasJar )
    {
    String contents =

    "/com/mindprod/business/BigDate.class\n"
    + "/com/mindprod/business/CMPAboutBox.class\n"
    + "/com/mindprod/business/CMPAboutBox$1.class\n"
    + "/com/mindprod/business/CMPAboutBox$2.class\n"
    + "/com/mindprod/business/CMPAboutBox$3.class\n"
    + "/com/mindprod/business/CMPAboutBox$4.class\n"
    + "/com/mindprod/business/CMPAboutBox$5.class\n"
    + "/com/mindprod/business/CMPAboutBox$6.class\n"
    + "/com/mindprod/business/CMPAboutJBox.class\n"
    + "/com/mindprod/business/CMPAboutJBox$1.class\n"
    + "/com/mindprod/business/CMPAboutJBox$2.class\n"
    + "/com/mindprod/business/CMPAboutJBox$3.class\n"
    + "/com/mindprod/business/CMPAboutJBox$4.class\n"
    + "/com/mindprod/business/CMPAboutJBox$5.class\n"
    + "/com/mindprod/business/CMPAboutJBox$6.class\n"

    + "/com/mindprod/business/Misc.class\n"
    + "/com/mindprod/pricelist/AppCategories.class\n"
    + "/com/mindprod/pricelist/AppCats.class\n"
    + "/com/mindprod/amazon/Book.class\n"
    + "/com/mindprod/business/ImageInfo.class\n"
    + "/com/mindprod/business/Misc.class\n"
    + "/com/mindprod/compactor/CompactMindprod.class\n"
    + "/com/mindprod/compactor/Compactor.class\n"
    + "/com/mindprod/entities/InsertEntities.class\n"
    + "/com/mindprod/entities/StripEntities.class\n"
    + "/com/mindprod/filter/AllFilesFilter.class\n"
    + "/com/mindprod/filter/ClamFilter.class\n"
    + "/com/mindprod/filter/CommandLine.class\n"
    + "/com/mindprod/filter/EverythingFilter.class\n"
    + "/com/mindprod/filter/FileLengthFilter.class\n"
    + "/com/mindprod/filter/FilenameLengthFilter.class\n"
    + "/com/mindprod/filter/ListFilter.class\n"
    + "/com/mindprod/filter/MultiFilter.class\n"
    + "/com/mindprod/filter/RecentFilter.class\n"
    + "/com/mindprod/filter/RegexFilter.class\n"
    + "/com/mindprod/hunkio/HunkIO.class\n"
    + "/com/mindprod/hunkio/PrintWriterPlus.class\n"
    + "/com/mindprod/isbn/ISBNValidate.class\n"
    + "/com/mindprod/ledatastream/LEDataInputStream.class\n"
    + "/com/mindprod/ledatastream/LEDataInputStream.class\n"
    + "/com/mindprod/pricelist/AppCategories.class\n"
    + "/com/mindprod/pricelist/AppCats.class\n";

    save( absoluteProjectDir + "\\forjar.list", contents, false
    );
    }
    }

    /**
    * generate the forzip. List of what extra to include in the zip
    */
    void mkForZipList()
    {
    if ( distributeZip )
    {
    String contents =

    "\\com\\mindprod\\business\\BigDate.class\n"
    + "\\com\\mindprod\\business\\CMPAboutBox*.class\n"
    + "\\com\\mindprod\\business\\CMPAboutJBox*.class\n"
    + "\\com\\mindprod\\business\\Misc.class\n"
    + "\\com\\mindprod\\pricelist\\AppCategories.class\n"
    + "\\com\\mindprod\\pricelist\\AppCats.class\n"
    + "\\com\\mindprod\\amazon\\Book.class\n"
    + "\\com\\mindprod\\business\\ImageInfo.class\n"
    + "\\com\\mindprod\\business\\Misc.class\n"
    + "\\com\\mindprod\\compactor\\CompactMindprod.class\n"
    + "\\com\\mindprod\\compactor\\Compactor.class\n"
    + "\\com\\mindprod\\entities\\*.class\n"
    + "\\com\\mindprod\\filter\\*.class\n"
    + "\\com\\mindprod\\hunkio\\*.class\n"
    + "\\com\\mindprod\\isbn\\ISBNValidate.class\n"
    + "\\com\\mindprod\\ledatastream\\LEDataInputStream.class\n"
    + "\\com\\mindprod\\ledatastream\\LEDataInputStream.class\n"
    + "\\com\\mindprod\\pricelist\\AppCategories.class\n"
    + "\\com\\mindprod\\pricelist\\AppCats.class\n";

    contents +=
    "\\com\\mindprod\\business\\BigDate.java\n"
    + "\\com\\mindprod\\business\\CMPAboutBox.java\n"
    + "\\com\\mindprod\\business\\CMPAboutJBox.java\n"
    + "\\com\\mindprod\\business\\Misc.java\n"
    + "\\com\\mindprod\\pricelist\\AppCategories.java\n"
    + "\\com\\mindprod\\pricelist\\AppCats.java\n"
    + "\\com\\mindprod\\amazon\\Book.java\n"
    + "\\com\\mindprod\\business\\ImageInfo.java\n"
    + "\\com\\mindprod\\business\\Misc.java\n"
    + "\\com\\mindprod\\compactor\\CompactMindprod.java\n"
    + "\\com\\mindprod\\compactor\\Compactor.java\n"
    + "\\com\\mindprod\\entities\\*.java\n"
    + "\\com\\mindprod\\filter\\*.java\n"
    + "\\com\\mindprod\\hunkio\\*.java\n"
    + "\\com\\mindprod\\isbn\\ISBNValidate.java\n"
    + "\\com\\mindprod\\ledatastream\\LEDataInputStream.java\n"
    + "\\com\\mindprod\\ledatastream\\LEDataInputStream.java\n"
    + "\\com\\mindprod\\pricelist\\AppCategories.java\n"
    + "\\com\\mindprod\\pricelist\\AppCats.java\n";

    save( absoluteProjectDir + "\\forzip.list", contents, false
    );
    }
    }
    /**
    * generate the run.bat file to run the program
    * as an application.
    */
    void mkRunBat()
    {
    if ( hasJar )
    {
    String contents = "@echo on\n"
    + "@echo run " + mainClass + " as an
    application\n"
    + "C:\n"
    + "CD " + absoluteProjectDir + "\n"
    + "\n"
    + "java.exe -jar " + projectLower +
    ".jar\n"
    + "\n"
    + "rem -30-\n";
    save( absoluteProjectDir + "\\run.bat", contents, true );
    }
    }

    /**
    * Make a skeleton JNLP program to run the JWSP
    */
    void mkJnlp()
    {
    if ( hasHtml && type == WEBLET )
    {
    String contents =

    "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
    + "\n"
    + "<jnlp spec=\"1.0+\" codebase=\"" + websiteURL + "\"
    href=\"" + projectLower + ".jnlp\">\n"
    + "<information>\n"
    + "<title>" + mainClass + " " + versionString + ": " +
    description + "</title>\n"
    + "\n"
    + "<vendor>Canadian Mind Products</vendor>\n"
    + "<homepage href=\"" + websiteURL + "/\" />\n"
    + "\n"
    + "<description>"+ description + "</description>\n"
    + "<description kind=\"short\">" + description +
    "</description>\n"
    + "<description kind=\"tooltip\">" + mainClass +
    "</description>\n"
    + "<icon href=\"" + websiteURL +
    "/images/greenstar64x64.gif\" width=\"64\" height=\"64\" />\n"
    + "<offline-allowed/>\n"
    + "</information>\n"
    + "\n"
    + "<resources>\n"
    + "<!-- Acceptable JVMs in preferred order, best first -->\n"
    + "<j2se version=\"1.4.2_04\"
    href=\"http://java.sun.com/products/autodl/j2se\" />\n"
    + "<j2se version=\"1.4.2_03\"
    href=\"http://java.sun.com/products/autodl/j2se\" />\n"
    + "<j2se version=\"1.4.2_02\"
    href=\"http://java.sun.com/products/autodl/j2se\" />\n"
    + "<j2se version=\"1.4.2_01\"
    href=\"http://java.sun.com/products/autodl/j2se\" />\n"
    + "<j2se version=\"1.4.2\"
    href=\"http://java.sun.com/products/autodl/j2se\" />\n"
    + "\n"
    + "<!-- application code -->\n"
    + "<jar href=\"" + projectLower + ".jar\" />\n"
    + "\n"
    + "<!-- data dictionaries in compressed form -->\n"
    + "<jar href=\"dicts.jar\" />\n"
    + "<!-- set a -D system property -->\n"
    + "<property name=\"flavour\" value=\"strawberry\" />\n"
    + "</resources>\n"
    + "\n"
    + "<!-- JNI native .so code -->\n"
    + "<resources os=\"SunOS\" arch=\"sparc\">\n"
    + "<nativelib href=\"lib/solaris/corelibs.jar\"/>\n"
    + "</resources>\n"
    + "\n"
    + "<!-- JNI native .dll code -->\n"
    + "<resources os=\"Windows\" arch=\"x86\">\n"
    + "<nativelib href=\"lib/windows/corelibs.jar\"/>\n"
    + "</resources>\n"
    + "\n"
    + "<security>\n"
    + "<all-permissions />\n"
    + "</security>\n"
    + "\n"
    + "<!-- application class with main method -->\n"
    + "<application-desc main-class=\"" + mainClassFullyQualified
    + "\" />\n"
    + "\n"
    + "<!-- code run once on install to unpack dicts.jar -->\n"
    + "<installer-desc main-class=\"" + packageFullyQualified +
    ".Installer\" />\n"
    + "</jnlp>";
    save( absoluteProjectDir + "\\" + projectLower + ".jnlp",
    contents, false );
    }
    }

    /**
    * Make a skeleton HTML program to run the Applet.
    */
    void mkAppletHtml()
    {
    if ( hasHtml && ( type == APPLET || type == HYBRID ) )
    {
    String contents = "<!-- macro AmanuensisHead \"" + mainClass
    + " Amanuensis\"\n"
    + "\"" + description + "\"\n"
    + "\"Java, amanuensis\"\n"
    + "{<img src=\"images/" + projectLower +
    ".gif\" height=\"53\" width=\"223\" alt=\"" + mainClass + "\">} -->\n"
    + "<p>This is a " +
    AppCats.enumToDescription( type, signed ) + ".\n"
    + description + "<p>\n"
    + " <!-- macro BestBrowsers Applet -->\n"
    + " <p>\n";
    if ( signed )
    {
    contents += "<table border=\"0\"><tr><td>\n";
    }

    contents += "<applet code=\"" + mainClassFullyQualified +
    ".class\" archive=\""+ projectLower + ".jar\" width=\"1000\"
    height=\"1000\" vspace=\"10\" hspace=\"10\" alt=\"Sorry, you need Java
    to run " + mainClass + "\">\n"
    + "</applet>\n"
    + "<p>\n";
    if ( signed )
    {
    contents += "</td><td>\n"
    + "<!-- macro Signed " + mainClass + " " +
    AppCats.enumToString( type ) + " -->\n"
    + "/td></tr></table>\n";
    }
    contents += "<!-- macro Foot -->\n";

    save( absoluteProjectDir + "\\" + projectLower + ".html",
    contents, false );
    }
    }

    /**
    * Make a skeleton HTML program to run the Java WebStart
    */
    void mkJwsHtml()
    {
    if ( hasHtml && type == WEBLET )
    {

    String contents = "<!-- macro AmanuensisHead \"" + mainClass
    + " Amanuensis\"\n"
    + "\"" + description + "\"\n"
    + "\"Java, java web start, amanuensis\"\n"
    + "{<img src=\"images/" + projectLower +
    ".gif\" height=\"53\" width=\"223\" alt=\"" + mainClass + "\">} -->\n"
    + "<p>This " + AppCats.enumToDescription(
    type, signed ) + "\n"
    + description + "<p>\n"
    + " <!-- macro BestBrowsers Applet -->\n"
    + " <p>\n";
    if ( signed )
    {
    contents +="<table border=\"0\"><tr><td>\n";
    }

    contents += "<a href=\"webstart/" + projectLower +
    ".jnlp\">start</a>\n"
    + " <p>\n";

    if ( signed )
    {
    contents += "</td><td>\n"
    + "<!-- macro Signed " + mainClass
    + " " + AppCats.enumToString( type ) + "
    -->\n"
    + "/td></tr></table>\n";
    }
    contents += " <!-- macro Foot -->\n";
    save( absoluteProjectDir + "\\" + projectLower + ".html",
    contents, false );

    }
    }
    /**
    * Make the distribute.bat used when application
    * is ready for distribution to the website.
    */
    void mkDistributeBat()
    {
    String contents = "@echo on\n"
    + "@echo distribute.bat: distribute zip and
    jar files.\n"
    + "\n"
    + "C:\n"
    + "CD " + absoluteProjectDir + "\n"
    + "\n";

    if ( type == APPLET || type == HYBRID || type == WEBLET )
    {
    contents += "copy " + projectLower + ".jar E:\\mindprod\n";
    }
    if ( distributeZip )
    {


    contents += "copy " + projectLower + ".use
    E:\\mindprod\\zips\\java\\" + projectLower + ".txt\n"
    + "\n";

    String zipFile = projectLower + versionTimesTen + ".zip";

    String oldZipFile = "E:\\mindprod\\zips\\java\\" +
    projectLower + (versionTimesTen-1) + ".zip";

    String newZipFile = "E:\\mindprod\\zips\\java\\" +
    projectLower + versionTimesTen + ".zip";

    contents += "rem /E means suppress error messages\n"
    + "del /E " + oldZipFile + "\n"
    + "copy /E " + zipFile + " " + newZipFile + "\n"
    + "\n";
    }
    contents += "rem -30-\n";

    save( absoluteProjectDir + "\\distribute.bat", contents, true );


    }
    /**
    * Save contents into a text file.
    *
    * @param fullyQualifiedFileName
    * fully qualified filename.
    * @param contents new contents of the file.
    *
    * @param overwrite true if should overwrite an existing file.
    */
    void save( String fullyQualifiedFileName, String contents, boolean
    overwrite )
    {
    try
    {
    File file = new File( fullyQualifiedFileName );
    if ( ! overwrite && file.exists() )
    {
    return;
    }
    System.out.println(" saving: " + fullyQualifiedFileName );
    FileWriter emit = new FileWriter( file );
    emit.write( contents );
    emit.close();
    }
    catch ( IOException e )
    {
    System.err.println( "trouble generating file:" +
    fullyQualifiedFileName );
    e.printStackTrace();
    }
    }

    /**
    * generate all the files for the new project.
    */
    public void stomp()
    {
    mkDir();
    mkDescBtm();
    mkUse();
    mkJava();
    mkMasterDistributionSite();
    mkMainMft();
    mkJnlp();
    mkAppletHtml();
    mkJwsHtml();
    mkForJarList();
    mkForZipList();
    mkCompileBat();
    mkJkBat();
    mkJtBat();
    mkRunBat();
    mkDistributeBat();
    mkJustBat();
    }

    /**
    * test harness
    *
    * @param args not used
    */
    public static void main ( String[] args )
    {
    try
    {
    (new StompProject ( "HtmlMacros", 12, "Generates HTML from
    custom macros", "application", false /* unsigned */, false /* don't
    distribute zip */ )).stomp();

    (new StompProject ( "Amazon", 17, "Generates HTML for book
    referrals", "application", false /* unsigned */, false /* don't
    distribute zip */ )).stomp();

    (new StompProject ( "MimeCheck", 16, "Tests MIME types
    servers are sending", "hybrid", true /* signed */, true /*
    distribute zip */ )).stomp();

    (new StompProject ( "Comparators", 10, "Collection of
    Comparators", "library", false /* unsigned */, true /* distribute
    zip */ )).stomp();

    (new StompProject ( "Stomp", 10, "Stomps out Java and bat
    file boilerplate", "application", false /* unsigned */, true /*
    distribute zip */ )).stomp();
    }
    catch ( Exception e )
    {
    e.printStackTrace();
    }
    }
    }

    --------------------------------------------------------


    package com.mindprod.pricelist;

    /**
    * constants for Application categories
    */
    public interface AppCategories
    {
    /**
    * run as application
    */
    static int APPLICATION = 1;
    /**
    * run a Applet
    */
    static int APPLET = 2;

    /**
    * run as Applet or application
    */
    static int HYBRID = 3;
    /**
    * run as Java Web Start
    */
    static int WEBLET = 4;

    /**
    * is a class or subroutine you include in
    * your own code.
    */
    static int LIBRARY = 5;

    /**
    * a stand alone utility.
    */
    static int UTILITY = 6;

    /**
    * just documentation.
    */
    static final int DOCUMENTATION = 7;

    }
    ---------------------------------------

    package com.mindprod.pricelist;

    /**
    * constants for Application categories
    */
    public class AppCats implements AppCategories
    {

    /**
    * converts human readable string case insensitive to enum
    */
    public static int stringToEnum ( String s )
    {
    s=s.trim().toLowerCase();
    if ( s.equals( "app" ) ) return APPLICATION;
    else if ( s.equals( "applet" ) ) return APPLET;
    else if ( s.equals( "application" ) ) return APPLICATION;
    else if ( s.equals( "class" ) ) return LIBRARY;
    else if ( s.equals( "hybrid" ) ) return HYBRID;
    else if ( s.equals( "jws" ) ) return WEBLET;
    else if ( s.equals( "library" ) ) return LIBRARY;
    else if ( s.equals( "utility" ) ) return UTILITY;
    else if ( s.equals( "weblet" ) ) return WEBLET;
    else if ( s.equals( "webstart" ) ) return WEBLET;
    else if ( s.equals( "documentation") ) return DOCUMENTATION;
    else
    {
    throw new IllegalArgumentException( "unknown Application
    Category: " + s);
    }
    }

    /*
    * converts enum to code string string
    */
    public static String enumToString( int en )
    {
    switch ( en )
    {
    default:
    case APPLICATION: return "application";

    case APPLET: return "Applet";

    case HYBRID: return "hydrid";

    case WEBLET: return "weblet";

    case LIBRARY: return "Class";

    case UTILITY: return "Utility";

    case DOCUMENTATION: return "documentation";

    }
    }

    /**
    * converts enum to human readable description string
    *
    * @param en enumeration constant
    * @param signed true if this app is signed.
    * @return long description of this type.
    */
    public static String enumToDescription( int en, boolean signed )
    {
    String desc;
    switch ( en )
    {
    default:
    case APPLICATION: desc = "Java application";
    break;
    case APPLET: desc = "Java Applet";
    break;
    case HYBRID: desc = "Java Applet that can also be run as an
    application";
    break;
    case WEBLET: desc = "Java Web Start weblet";
    break;
    case LIBRARY: desc = "Class library";
    break;
    case UTILITY: desc = "non-Java Utility";
    break;
    case DOCUMENTATION: desc = "documentation";
    break;
    } // end switch
    return( signed ? "signed " : "" ) + desc;

    }

    }

    ------------------------------------


    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, May 24, 2004
    #1
    1. Advertising

  2. Roedy Green

    Rob Shepherd Guest

    Roedy Green wrote:
    > I noticed that every time I start a new project I have to clone and
    > modify some existing one. It takes a long time. Further, if I learn
    > a better way of doing things, that only shows up in new projects.



    Have you ever tried Maven for builing projects, I find that a releatively painless way to
    start a new project, with just a few lines of XML to fill in...

    Having said that Maven is massive and most of Maven's runtime is spent downloading
    dependancies and other repository tosh..

    but it does website generation, automatic Ant generation, document building, cvs co/up,
    and makes tricky classpaths transparent...

    Rob
    --
    ------------------------------------------------------------------------
    | Rob can be contacted privately through a temporary email account. |
    | Courtesy of http://www.mailinator.com |
    | |
    | |
    | |
    | This address will not be checked after May 31st 2004 |
    ------------------------------------------------------------------------
    Rob Shepherd, May 24, 2004
    #2
    1. Advertising

  3. Roedy Green wrote:
    > I noticed that every time I start a new project I have to clone and
    > modify some existing one. It takes a long time. Further, if I learn
    > a better way of doing things, that only shows up in new projects.
    >
    > So I decide to write a Project Stomper, a cookie cutter that creates
    > all the files I need.
    >
    > Here is the source. You could not use it unmodified, but it could be
    > a great start on doing your own. This would have been a great project
    > for JDK 1.5 enum.
    >
    > Every time I make a change the program, I can stomp out an entire new
    > set of files for EVERYTHING. Some I don't override, since the ones
    > this generates are just starting points.
    >
    > This program was not intended for publication. That is why you see so
    > mary peculiar Roedyism's hard-coded in.
    >
    >

    <snip 1158 lines>

    Cor blimey, Roedy. Haven't you worn that Dvorak keyboard out yet?

    Steve
    Steve Horsley, May 25, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hermit Dave

    Re: Yet another .net bug?

    Hermit Dave, Jan 18, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    406
    Hermit Dave
    Jan 18, 2004
  2. Jan Tielens

    Re: Yet another .net bug?

    Jan Tielens, Jan 18, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    419
    Jan Tielens
    Jan 18, 2004
  3. Anon

    Re: Yet another .net bug?

    Anon, Jan 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    401
  4. Replies:
    6
    Views:
    5,322
    Alan Moore
    May 24, 2005
  5. Berehem
    Replies:
    4
    Views:
    541
    Lawrence Kirby
    Apr 28, 2005
Loading...

Share This Page