001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.dependencyfinder.cli;
034:
035: import com.jeantessier.classreader.*;
036: import com.jeantessier.commandline.*;
037: import com.jeantessier.diff.*;
038: import org.apache.log4j.*;
039:
040: public class JarJarDiff extends DiffCommand {
041: public JarJarDiff() throws CommandLineException {
042: super ("JarJarDiff");
043: }
044:
045: protected void doProcessing() throws Exception {
046: // Collecting data, first classfiles from JARs,
047: // then package/class trees using NodeFactory.
048:
049: PackageMapper oldPackages = new PackageMapper();
050: ClassfileLoader oldJar = new AggregatingClassfileLoader();
051: oldJar.addLoadListener(oldPackages);
052: oldJar.addLoadListener(getVerboseListener());
053: oldJar.load(getCommandLine().getMultipleSwitch("old"));
054:
055: PackageMapper newPackages = new PackageMapper();
056: ClassfileLoader newJar = new AggregatingClassfileLoader();
057: newJar.addLoadListener(newPackages);
058: newJar.addLoadListener(getVerboseListener());
059: newJar.load(getCommandLine().getMultipleSwitch("new"));
060:
061: DifferenceStrategy baseStrategy = getBaseStrategy(getCommandLine()
062: .getToggleSwitch("code"));
063: DifferenceStrategy strategy = getStrategy(getCommandLine()
064: .getSingleSwitch("level"), baseStrategy);
065:
066: if (getCommandLine().isPresent("filter")) {
067: strategy = new ListBasedDifferenceStrategy(strategy,
068: getCommandLine().getSingleSwitch("filter"));
069: }
070:
071: // Starting to compare, first at package level,
072: // then descending to class level for packages
073: // that are in both the old and the new codebase.
074:
075: Logger.getLogger(getClass()).info("Comparing ...");
076: getVerboseListener().print("Comparing ...");
077:
078: String name = getCommandLine().getSingleSwitch("name");
079: String oldLabel = getCommandLine().isPresent("old-label") ? getCommandLine()
080: .getSingleSwitch("old-label")
081: : getCommandLine().getMultipleSwitch("old").toString();
082: String newLabel = getCommandLine().isPresent("new-label") ? getCommandLine()
083: .getSingleSwitch("new-label")
084: : getCommandLine().getMultipleSwitch("new").toString();
085:
086: DifferencesFactory factory = new DifferencesFactory(strategy);
087: Differences differences = factory.createProjectDifferences(
088: name, oldLabel, oldPackages, newLabel, newPackages);
089:
090: Logger.getLogger(getClass()).info("Printing results ...");
091: getVerboseListener().print("Printing results ...");
092:
093: com.jeantessier.diff.Printer printer = new Report(
094: getCommandLine().getSingleSwitch("encoding"),
095: getCommandLine().getSingleSwitch("dtd-prefix"));
096: if (getCommandLine().isPresent("indent-text")) {
097: printer.setIndentText(getCommandLine().getSingleSwitch(
098: "indent-text"));
099: }
100:
101: differences.accept(printer);
102: out.print(printer);
103: }
104:
105: public static void main(String[] args) throws Exception {
106: new JarJarDiff().run(args);
107: }
108: }
|