/* XBN Java: Generically useful, non-GUI Java code. http://sourceforge.net/projects/xbnjava Copyright (C) 1997-2003, Jeff Epstein All rights reserved. Modifications: No Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * If modifications are made to source code then this license should indicate that fact in the "Modifications" section above. * Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [NOTE: This license contains NO advertising clause.] */ package xbn.programs; import xbn.AssertException; import xbn.array.VWString; import xbn.output.Outputter; import xbn.output.OWFile; import xbn.placeholder.s_acs_acs; import xbn.string.SOBStringBuffer; import xbn.template.TOGOne; import xbn.template.TOGThree; import xbn.template.TemplateFiller; import xbn.template.util.GetTOG1FFile; import xbn.template.util.GetTOG3FFile; import xbn.util.Utility; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import java.util.StringTokenizer; /**
An application to report all the packages dependended on by another set of packages. This uses Utility.getPackageDependencies() at its heart.
Source code: ReportPackageDependencies.java.
Providing a specific set of templates to this application allows you to specifically customize the format of this report. If no templates are provided, a trivial format is used.
If templates are provided, they must be conform to these requirement exactly. Any formatting errors will generate a specific (and helpful) error message.
The templates I actually use for XBN Java, can be viewed by clicking on the name of any template. Here's the directory.
Template | Required gaps | Description |
overall.tmpl |
all_dependency_lists |
The top level template that contains all other templates. |
package.tmpl |
package_name
depends_on_section
depended_on_by_section |
The package template that contains all below templates. |
depends_on_section.tmpl |
all_depends_on_rows |
Used to fill package.tmpl .depends_on_section . Contains all depends-on rows. That is, the list of all packages on which this package depends. |
depends_on_section_NOTHING.txt |
None. Not a template | When this package depends on no others, then this text is used to fill package.tmpl .depends_on_section , instead of the depends_on_section.tmpl template. |
depends_on_row.tmpl |
package_name |
A row, representing a single package that depends on this package. Used to fill depends_on_section.tmpl .all_depends_on_rows |
depends_on_row_newline.txt |
None. Not a template | The text to use as a newline. This is printed after every depends-on row, except the last. |
depended_on_by_section.tmpl |
all_depended_on_by_rows |
Used to fill package.tmpl .depended_on_by_section . Contains all depends-on rows. That is, the list of all packages that depend on this package. |
depended_on_by_section_NOTHING.txt |
None. Not a template | When no other packages depend on this package, then this text is used to fill package.tmpl .depended_on_by_section , instead of the depended_on_by_section.tmpl template. |
depended_on_by_row.tmpl |
package_name |
A row, representing a single package that is depended on by this package. Used to fill depended_on_by_section.tmpl .all_depended_on_by_rows |
depended_on_by_row_newline.txt |
None. Not a template | The text to use as a newline. This is printed after every depended-on-by row, except the last. |
Create a ReportPackageDependencies. This constructor does nothing.
**/ public ReportPackageDependencies() { } /**Run the application.
**/ public final static void main(String[] as_cmdLineParams) { sopl("ReportPackageDependencies...START"); //Prepare for testing and get command line parameters...START opts.addOption(optDirToAnalyze); opts.addOption(optTmplDir); opts.addOption(optOutputFile); opts.addOption(optSubDirLvls); opts.addOption(optPkgPrefxs); opts.addOption(optDbgFile); UtilCommandLine ucl = new UtilCommandLine(opts, 80, "xbn.programs.ReportPackageDependencies", null, "\nFor documentation on many of these parameters, see the documentation for Utility.getPackageDependencies().", true); CommandLine cl = ucl.getCommandLine(as_cmdLineParams); Outputter optrDbg = ucl.getOSDOOrOSDOAndFile("dbgfile", false); String sOutputFile = cl.getOptionValue("outfile"); String sDirToAnalyze = cl.getOptionValue("dir2nlz"); int iSubDirLevels = ucl.getInt("subdirlvls", -1); String sTmplDir = cl.getOptionValue("tmpldir"); String sPkgPrefixes = cl.getOptionValue("pkgprfxs"); //Prepare for testing and get command line parameters...END if(iSubDirLevels == 0) { throwAXS(sAXS_PRE + "SUB_DIR_LEVELS (" + iSubDirLevels + ") must equal -1, or be greater than zero."); } String[] asPkgPrefixes = null; if(!sPkgPrefixes.equals(sZERO)) { StringTokenizer stPkgPrefixes = new StringTokenizer(sPkgPrefixes, "/"); asPkgPrefixes = new String[stPkgPrefixes.countTokens()]; for(int i = 0; i < asPkgPrefixes.length; i++) { asPkgPrefixes[i] = stPkgPrefixes.nextToken(); } } optrDbg.write("Reporting all dependencies...START"); TOGOne tog1Overall = null; TOGThree tog3Pkg = null; TOGOne tog1DOSection = null; TOGOne tog1DOSRow = null; TOGOne tog1DOBSection = null; TOGOne tog1DOBSRow = null; String sDOSctnNothing = null; String sDOBSctnNothing = null; String sDOSRNewline = null; String sDOBSRNewline = null; if(sTmplDir.equals(sZERO)) { optrDbg.write("No templates supplied. Will output plain text only..."); } else { optrDbg.write("Templates exist in '" + sTmplDir + "'. Loading..."); SOBStringBuffer ssb = new SOBStringBuffer(sES); util.appendFileText(ssb, sTmplDir + sTMPL_DOS_NOTHING); sDOSctnNothing = ssb.toString(); ssb.deleteAll(); util.appendFileText(ssb, sTmplDir + sTMPL_DOBS_NOTHING); sDOBSctnNothing = ssb.toString(); ssb.deleteAll(); util.appendFileText(ssb, sTmplDir + sTMPL_DOS_ROW_NEWLINE); sDOSRNewline = ssb.toString(); ssb.deleteAll(); util.appendFileText(ssb, sTmplDir + sTMPL_DOBS_ROW_NEWLINE); sDOBSRNewline = ssb.toString(); try { tog3Pkg = (new GetTOG3FFile( sTmplDir + sTMPL_PACKAGE, sTMPL_PKG_package_name, sTMPL_PKG_depends_on_section, sTMPL_PKG_depended_on_by_section, optrDbg)).getTOGThree(); } catch(AssertException ax) { String sErr = sAXS_PRE + "Attempting to load " + sTMPL_PACKAGE + ". " + ax.toString(); optrDbg.write(sErr); throwAXS(sErr); } tog1Overall = getTOG1FFile(sTmplDir + sTMPL_OVERALL, sTMPL_PKG_all_dependency_lists, optrDbg); tog1DOSection = getTOG1FFile(sTmplDir + sTMPL_DEPENDS_ON_SCTN, sTMPL_DOS_all_depends_on_rows, optrDbg); tog1DOSRow = getTOG1FFile(sTmplDir + sTMPL_DOS_ROW, sTMPL_DOSR_package_name, optrDbg); tog1DOBSection = getTOG1FFile(sTmplDir + sTMPL_DEPENDED_ON_BY_SCTN, sTMPL_DOBS_all_depended_on_by_rows, optrDbg); tog1DOBSRow = getTOG1FFile(sTmplDir + sTMPL_DOBS_ROW, sTMPL_DOBSR_package_name, optrDbg); } optrDbg.write("...SUCCESS: Templates loaded."); Outputter optrOutput = null; if(sOutputFile.equals(sZERO)) { //Output will only go to screen. optrDbg.write("Outputting to screen (and file, if debugging output goes there, too)..."); optrOutput = optrDbg; } else { optrDbg.write("Outputting to '" + sOutputFile + "'..."); optrOutput = new Outputter(new OWFile(sOutputFile, false)); } s_acs_acs[] aSacsacs = util.getPackageDependencies(sDirToAnalyze, iSubDirLevels, optrDbg, asPkgPrefixes, true, null); optrDbg.write("Reporting all dependencies...START"); if(sTmplDir.equals(sZERO)) { optrDbg.write("No templates supplied. Outputting text only..."); for(int i = 0; i < aSacsacs.length; i++) { optrDbg.write(aSacsacs[i].s + "\n Depends on:"); for(int j = 0; j < aSacsacs[i].acs1.size(); j++) { optrDbg.write(" " + aSacsacs[i].acs1.getString(j)); } optrDbg.write(" Depended on by:"); for(int j = 0; j < aSacsacs[i].acs2.size(); j++) { optrDbg.write(" " + aSacsacs[i].acs2.getString(j)); } } } else { optrDbg.write("Templates exist in '" + sTmplDir + "'"); TemplateFiller tf = new TemplateFiller(false); StringBuffer sbAllPackageLists = new StringBuffer(sES); for(int i = 0; i < aSacsacs.length; i++) { String sDOSection = getSection(tf, aSacsacs[i].acs1, tog1DOSection, sTMPL_DOS_all_depends_on_rows, tog1DOSRow, sTMPL_DOSR_package_name, sDOSRNewline, sDOSctnNothing); String sDOBSection = getSection(tf, aSacsacs[i].acs2, tog1DOBSection, sTMPL_DOBS_all_depended_on_by_rows, tog1DOBSRow, sTMPL_DOBSR_package_name, sDOBSRNewline, sDOBSctnNothing); tf.setTemplate(tog3Pkg); tf.fill(sTMPL_PKG_package_name, aSacsacs[i].s); tf.fill(sTMPL_PKG_depends_on_section, sDOSection); tf.fill(sTMPL_PKG_depended_on_by_section, sDOBSection); sbAllPackageLists.append(tf.getResult()); } tf.setOWriter(optrOutput.getOWriter()); tf.setTemplate(tog1Overall); tf.fill(sTMPL_PKG_all_dependency_lists, sbAllPackageLists.toString()); optrDbg.write("Output exists in '" + sOutputFile + "'..."); } } private static String getSection(TemplateFiller template_filler, VWString acs_packages, TOGOne tog1_section, String stog1s_allRowsGap, TOGOne tog1s_row, String stog1sr_pkgName, String s_newline, String s_nothingSection) { if(acs_packages.size() == 0) { return s_nothingSection; } else { StringBuffer sb = new StringBuffer(sES); for(int i = 0; i < acs_packages.size(); i++) { template_filler.setTemplate(tog1s_row); template_filler.fill(stog1sr_pkgName, acs_packages.getString(i)); sb.append(template_filler.getResult()); if(i < acs_packages.size() - 1) { sb.append(s_newline); } } template_filler.setTemplate(tog1_section); template_filler.fill(stog1s_allRowsGap, sb.toString()); return template_filler.getResult(); } } private static final TOGOne getTOG1FFile(String s_file, String s_onlyGap, Outputter optr_dbg) { GetTOG1FFile gtog1ff = null; try { gtog1ff = new GetTOG1FFile(s_file, s_onlyGap, optr_dbg); } catch(AssertException ax) { String sErr = sAXS_PRE + "Attempting to load " + s_file + ". " + ax.toString(); optr_dbg.write(sErr); throwAXS(sErr); } return gtog1ff.getTOGOne(); } }