From: <js...@us...> - 2008-05-09 17:08:18
|
Revision: 48 http://jcontracts.svn.sourceforge.net/jcontracts/?rev=48&view=rev Author: jstuyts Date: 2008-05-09 10:08:10 -0700 (Fri, 09 May 2008) Log Message: ----------- Removed obsolote options. Removed unused classes. Some small code cleanups. Modified Paths: -------------- trunk/source/java/net/sf/jcontracts/argparser/ArgParser.java trunk/source/java/net/sf/jcontracts/icontract/ArgMetaclassFactory.java trunk/source/java/net/sf/jcontracts/icontract/Class.java trunk/source/java/net/sf/jcontracts/icontract/FileTarget.java trunk/source/java/net/sf/jcontracts/icontract/HelpOption.java trunk/source/java/net/sf/jcontracts/icontract/MergeOption.java trunk/source/java/net/sf/jcontracts/icontract/Method.java trunk/source/java/net/sf/jcontracts/icontract/Option.java trunk/source/java/net/sf/jcontracts/icontract/Repository.java trunk/source/java/net/sf/jcontracts/icontract/Tool.java Removed Paths: ------------- trunk/source/java/net/sf/jcontracts/icontract/CleanOption.java trunk/source/java/net/sf/jcontracts/icontract/CompilerOption.java trunk/source/java/net/sf/jcontracts/icontract/Darwin.java trunk/source/java/net/sf/jcontracts/icontract/Internal0Option.java trunk/source/java/net/sf/jcontracts/icontract/InvCheckCallOption.java trunk/source/java/net/sf/jcontracts/icontract/NoInitialCompilationOption.java trunk/source/java/net/sf/jcontracts/icontract/NoRepositoryCompilationOption.java trunk/source/java/net/sf/jcontracts/icontract/OneOneOption.java trunk/source/java/net/sf/jcontracts/icontract/QuietOption.java trunk/source/java/net/sf/jcontracts/icontract/SourceCompilerOption.java trunk/source/java/net/sf/jcontracts/icontract/VerboseOption.java trunk/source/java/net/sf/jcontracts/icontract/WrapExceptionOption.java trunk/source/java/net/sf/jcontracts/icontract/XOption.java trunk/source/java/net/sf/jcontracts/icontract/util/ trunk/source/java/net/sf/jcontracts/util/ Modified: trunk/source/java/net/sf/jcontracts/argparser/ArgParser.java =================================================================== --- trunk/source/java/net/sf/jcontracts/argparser/ArgParser.java 2008-05-09 17:07:10 UTC (rev 47) +++ trunk/source/java/net/sf/jcontracts/argparser/ArgParser.java 2008-05-09 17:08:10 UTC (rev 48) @@ -185,7 +185,8 @@ Token j = null; j = LT(1); match(6); - TargetMetaclass t = getMetaclassFactory().newTarget(j.getText()); + String tokenText = j.getText(); + TargetMetaclass t = getMetaclassFactory().newTarget(tokenText); return t; } Modified: trunk/source/java/net/sf/jcontracts/icontract/ArgMetaclassFactory.java =================================================================== --- trunk/source/java/net/sf/jcontracts/icontract/ArgMetaclassFactory.java 2008-05-09 17:07:10 UTC (rev 47) +++ trunk/source/java/net/sf/jcontracts/icontract/ArgMetaclassFactory.java 2008-05-09 17:08:10 UTC (rev 48) @@ -34,30 +34,10 @@ { o = new HelpOption(name, parameters); } - else if (name.compareTo("v") == 0) - { - o = new VerboseOption(name, parameters); - } - else if (name.compareTo("c") == 0) - { - o = new CompilerOption(name, parameters); - } - else if (name.compareTo("b") == 0) - { - o = new SourceCompilerOption(name, parameters); - } - else if (name.compareTo("n") == 0) - { - o = new NoRepositoryCompilationOption(name, parameters); - } else if (name.compareTo("o") == 0) { o = new OutputOption(name, parameters); } - else if (name.compareTo("y") == 0) - { - o = new OneOneOption(name, parameters); - } else if (name.compareTo("k") == 0) { o = new RepositoryOutputOption(name, parameters); @@ -66,42 +46,14 @@ { o = new DefaultExceptionOption(name, parameters); } - else if (name.compareTo("r") == 0) - { - o = new CleanOption(name, parameters); - } else if (name.compareTo("m") == 0) { o = new MergeOption(name, parameters); } - else if (name.compareTo("i") == 0) - { - o = new InvCheckCallOption(name, parameters); - } - else if (name.compareTo("w") == 0) - { - o = new WrapExceptionOption(name, parameters); - } - else if (name.compareTo("q") == 0) - { - o = new QuietOption(name, parameters); - } else if (name.compareTo("a") == 0) { o = new AllOption(name, parameters); } - else if (name.compareTo("x") == 0) - { - o = new XOption(name, parameters); - } - else if (name.compareTo("Z") == 0) - { - o = new Internal0Option(name, parameters); - } - else if (name.compareTo("j") == 0) - { - o = new NoInitialCompilationOption(name, parameters); - } else { throw new RuntimeException("Java Contract Suite: error: unknown option -" + name); Modified: trunk/source/java/net/sf/jcontracts/icontract/Class.java =================================================================== --- trunk/source/java/net/sf/jcontracts/icontract/Class.java 2008-05-09 17:07:10 UTC (rev 47) +++ trunk/source/java/net/sf/jcontracts/icontract/Class.java 2008-05-09 17:08:10 UTC (rev 48) @@ -43,10 +43,6 @@ public static final char EXCEPTION_CLASS_MARKER = 35; - public static boolean generateSuperCheckCallFlag = false; - - public static boolean doWrapExceptionOptionFlag = false; - public static String defaultExceptionClassName = "RuntimeException"; public Class(String name, String filename, int line_number) @@ -335,10 +331,7 @@ throw new RuntimeException("Java Contract Suite:error: more than 4 arguments (" + f + ") not supported at the moment [991]. Easy to be added though."); } - else - { - return m; - } + return m; } public Vector getAllNonImplementedMethods() @@ -693,7 +686,7 @@ super_interfaces = new Vector(); } boolean inv_check_method_exists = false; - if (generateSuperCheckCallFlag && supercName != null) + if (supercName != null) { String invCheckMethodName = supercName.replace('.', '_'); invCheckMethodName = "__check_invariant____" + invCheckMethodName; @@ -743,15 +736,8 @@ } } } - if (generateSuperCheckCallFlag) + if (supercName != null && !inv_check_method_exists) { - if (supercName != null && !inv_check_method_exists) - { - super_interfaces.insertElementAt(supercName, 0); - } - } - else if (supercName != null) - { super_interfaces.insertElementAt(supercName, 0); } if (getParent() != null) @@ -844,10 +830,10 @@ Vector closure_source = new Vector(); for (int i = 0; i < inv_conds.size(); i++) { - if (!closure_conds.contains((String) inv_conds.elementAt(i))) + if (!closure_conds.contains(inv_conds.elementAt(i))) { - closure_conds.addElement((String) inv_conds.elementAt(i)); - closure_source.addElement((String) inv_source.elementAt(i)); + closure_conds.addElement(inv_conds.elementAt(i)); + closure_source.addElement(inv_source.elementAt(i)); } else { @@ -894,35 +880,20 @@ String inst_var_decl = "// Keeps track of calling chain to avoid recursive invariant checks.\n"; inst_var_decl = inst_var_decl + "// Avoids inv checks in public methods that are called from private ones.\n"; inst_var_decl = inst_var_decl + "// Stores bookkeeping information -- key: thread, value: call level\n"; - boolean do_not_enforce_precompilation_of_source = Boolean - .getBoolean("jcontracts.internal.do_not_enforce_precompilation_of_source"); - if (do_not_enforce_precompilation_of_source) - { - System.err - .println("Java Contract Suite:SWITCH:jcontracts.internal.do_not_enforce_precompilation_of_source=true"); - } boolean icl_already_defined = false; - if (!do_not_enforce_precompilation_of_source) + try { - try - { - icl_already_defined = checkIfFieldExistsInSuperclassClosure(java.lang.Class.forName(getName()), - "__icl_"); - } - catch (ClassNotFoundException _ex) - { - throw new RuntimeException( - getLocationDescription() - + "Java Contract Suite: ERROR: could not find " - + getName() - + ". Please compile the sourcefile, see -j option (Java Contract Suite needs the compiled file to determine whether or not to create invariant bookkeeping variables (__icl_)). Exiting Java Contract Suite.", - _ex); - } + icl_already_defined = checkIfFieldExistsInSuperclassClosure(java.lang.Class.forName(getName()), + "__icl_"); } - if (do_not_enforce_precompilation_of_source) + catch (ClassNotFoundException _ex) { - System.err - .println("Java Contract Suite: SWITCH:invariant bookkeeping may NOT work correctly because the check for the existence of the __icl_ variable in superclasses was disables. This means that there is an __icl_ varaible at each level of the inheritance rather than one and one only per inheritance chain! THIS IS ONLY SUITABLE FOR CERTAIN SPECIAL TESTCASES. REMOVE the 'java -Djcontracts.internal.do_not_enforce_precompilation_of_source' property to make Java Contract Suite work in normal (correct) mode!"); + throw new RuntimeException( + getLocationDescription() + + "Java Contract Suite: ERROR: could not find " + + getName() + + ". Please compile the sourcefile (Java Contract Suite needs the compiled file to determine whether or not to create invariant bookkeeping variables (__icl_)). Exiting Java Contract Suite.", + _ex); } if (!icl_already_defined) { @@ -1011,7 +982,7 @@ header = header + " {"; } String code = "\n"; - if (generateSuperCheckCallFlag && supercName != null) + if (supercName != null) { if (inv_check_method_exists) { @@ -1117,14 +1088,7 @@ code = "try {" + code; code = code + "}\n"; - if (!doWrapExceptionOptionFlag) - { - code = code + "catch ( " + "RuntimeException" + " ex ) {\n"; - } - else - { - code = code + "catch ( Exception ex ) {\n"; - } + code = code + "catch ( Exception ex ) {\n"; code = code + " String msg = \"\";\n"; code = code + " if (ex.getClass()==" @@ -1199,10 +1163,7 @@ { return Void.TYPE; } - else - { - return null; - } + return null; } public String getTypeOfValue(String value) throws UnableToDetermineTypeException @@ -1699,9 +1660,9 @@ Vector closure_conds = new Vector(); for (int i = 0; i < inv_conds.size(); i++) { - if (!closure_conds.contains((String) inv_conds.elementAt(i))) + if (!closure_conds.contains(inv_conds.elementAt(i))) { - closure_conds.addElement((String) inv_conds.elementAt(i)); + closure_conds.addElement(inv_conds.elementAt(i)); } } Deleted: trunk/source/java/net/sf/jcontracts/icontract/CleanOption.java =================================================================== --- trunk/source/java/net/sf/jcontracts/icontract/CleanOption.java 2008-05-09 17:07:10 UTC (rev 47) +++ trunk/source/java/net/sf/jcontracts/icontract/CleanOption.java 2008-05-09 17:08:10 UTC (rev 48) @@ -1,30 +0,0 @@ -/* - * Copyright 1997-2000 Reto Kramer - * Copyright 2006 John Swapceinski, Johan Stuyts - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.sf.jcontracts.icontract; - -import java.util.Vector; - -public class CleanOption extends ParameterOption -{ - - public static final String NAME = "r"; - - public CleanOption(String name, Vector arguments) - { - super(name, arguments); - } -} Deleted: trunk/source/java/net/sf/jcontracts/icontract/CompilerOption.java =================================================================== --- trunk/source/java/net/sf/jcontracts/icontract/CompilerOption.java 2008-05-09 17:07:10 UTC (rev 47) +++ trunk/source/java/net/sf/jcontracts/icontract/CompilerOption.java 2008-05-09 17:08:10 UTC (rev 48) @@ -1,239 +0,0 @@ -/* - * Copyright 1997-2000 Reto Kramer - * Copyright 2006 John Swapceinski, Johan Stuyts - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.sf.jcontracts.icontract; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.Enumeration; -import java.util.Vector; - -import org.apache.log4j.Logger; - -import sun.tools.javac.Main; - -public class CompilerOption extends ParameterOption -{ - private static final Logger log = Logger.getLogger(CompilerOption.class); - - public static final String NAME = "c"; - - public CompilerOption(String name, Vector arguments) - { - super(name, arguments); - } - - boolean doCompile(Vector fileList, boolean useFilenameOnly) - { - boolean result = true; - if (shallCompile() && fileList.size() > 0) - { - String comp = getCompiler(); - boolean useCallToCompiler = comp.startsWith(":"); - if (useCallToCompiler) - { - Vector options = new Vector(); - if (comp.indexOf(" ") != -1) - { - int lastsp = 1; - for (int sp = 0; (sp = comp.indexOf(" ", lastsp)) != -1;) - { - options.addElement(comp.substring(lastsp, sp).trim()); - lastsp = sp + 1; - } - - options.addElement(comp.substring(lastsp, comp.length()).trim()); - } - else if (comp.length() > 1) - { - options.addElement(comp.substring(1, comp.length()).trim()); - } - String fargs[] = new String[options.size() + fileList.size()]; - int pos = 0; - String cmdstr = ""; - for (Enumeration oenum = options.elements(); oenum.hasMoreElements();) - { - String o = (String) oenum.nextElement(); - fargs[pos] = o; - pos++; - cmdstr = cmdstr + o + " "; - } - - for (Enumeration fenum = fileList.elements(); fenum.hasMoreElements();) - { - String fn = (String) fenum.nextElement(); - if (useFilenameOnly) - { - File f = new File(fn); - fn = f.getName(); - } - fargs[pos] = fn; - pos++; - cmdstr = cmdstr + fn + " "; - } - - log.info("javac (sun.tools.javac.Main) " + cmdstr); - java.io.OutputStream javacout = new ByteArrayOutputStream(1024); - try - { - java.lang.Class.forName("sun.tools.javac.Main"); - Main theCompiler = new Main(javacout, ""); - result = theCompiler.compile(fargs); - if (!result) - { - System.err.println("\nJava Contract Suite: ERROR: compilation failed " + javacout.toString()); - } - } - catch (NoClassDefFoundError _ex) - { - throw new RuntimeException( - "Attempt to perform in-process call to sun.tools.javac.Main failed because the class could not be found! In Java-2, make sure that the JDK's tools.jar (contain sun.tools.javac.*) is on your classpath!", - _ex); - } - catch (ClassNotFoundException _ex) - { - throw new RuntimeException( - "Attempt to perform in-process call to sun.tools.javac.Main failed because the class could not be found! In Java-2, make sure that the JDK's tools.jar (contain sun.tools.javac.*) is on your classpath!", - _ex); - } - } - else - { - String files = ""; - for (Enumeration fenum = fileList.elements(); fenum.hasMoreElements();) - { - String fn = (String) fenum.nextElement(); - if (useFilenameOnly) - { - File f = new File(fn); - fn = f.getName(); - } - files = files + fn + " "; - } - - String cmd = getCompiler() + " -source 1.4 " + files; - log.info(cmd); - try - { - Process child = Runtime.getRuntime().exec(cmd); - InputStreamReader err = new InputStreamReader(child.getErrorStream()); - StringBuffer errmsg = new StringBuffer(); - if (err != null) - { - for (char buffer[] = new char[1]; err.read(buffer, 0, 1) != -1; errmsg.append(buffer[0])) - { - } - } - else - { - errmsg.append(" <could not open err stream to compiler!>"); - } - InputStreamReader out = new InputStreamReader(child.getInputStream()); - StringBuffer outmsg = new StringBuffer(); - if (out != null) - { - for (char buffer[] = new char[1]; out.read(buffer, 0, 1) != -1; outmsg.append(buffer[0])) - { - } - } - else - { - outmsg.append(" <could not open out stream of compiler!>"); - } - if (child.waitFor() != 0) - { - System.err.println("\nJava Contract Suite: ERROR: compilation failed(error code: " - + child.exitValue() + ") " + errmsg.toString() + " " + outmsg.toString()); - result = false; - } - } - catch (InterruptedException _ex) - { - result = false; - System.err.println("\nJava Contract Suite: ERROR: compilation failed."); - } - catch (IOException _ex) - { - result = false; - System.err.println("\nJava Contract Suite: ERROR: compilation failed."); - } - } - if (!result) - { - log.info("failed"); - } - } - if (!Internal0Option.isActive() && !result) - { - log - .info("deleting instrumented files .java to ensure regeneration and recompilation at the next tool invocation."); - for (Enumeration fenum = fileList.elements(); fenum.hasMoreElements();) - { - String fn = (String) fenum.nextElement(); - File f = new File(fn); - File fcopy = new File(fn + "_TO_DEBUG"); - try - { - FileReader frSource = new FileReader(f); - FileWriter fwTarget = new FileWriter(fcopy); - char buffer[] = new char[2048]; - int len = 0; - try - { - while ((len = frSource.read(buffer, 0, 2048)) != -1) - { - fwTarget.write(buffer, 0, len); - } - } - finally - { - fwTarget.close(); - frSource.close(); - } - log.info("file with errors copied for debugging: " + fn + "_TO_DEBUG"); - } - catch (IOException e) - { - throw new RuntimeException("Problems copying file " + fn + " to the " + fn + "_TO_DEBUG", e); - } - boolean success = f.delete(); - if (!success) - { - throw new RuntimeException( - "the deletion of the instrumented file (" - + fn - + ") failed although the tool just generated it a split second ago itself - were the permissions changed?"); - } - } - - } - return result; - } - - String getCompiler() - { - return (String) getArguments().firstElement(); - } - - boolean shallCompile() - { - return getArguments().size() > 0; - } -} Deleted: trunk/source/java/net/sf/jcontracts/icontract/Darwin.java =================================================================== --- trunk/source/java/net/sf/jcontracts/icontract/Darwin.java 2008-05-09 17:07:10 UTC (rev 47) +++ trunk/source/java/net/sf/jcontracts/icontract/Darwin.java 2008-05-09 17:08:10 UTC (rev 48) @@ -1,255 +0,0 @@ -/* - * Copyright 1997-2000 Reto Kramer - * Copyright 2006 John Swapceinski, Johan Stuyts - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.sf.jcontracts.icontract; - -import java.lang.reflect.Constructor; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -import net.sf.jcontracts.argparser.Parser; -import net.sf.jcontracts.codeparser.CodeMetaclass; -import net.sf.jcontracts.codeparser.CodeMetaclassCache; -import net.sf.jcontracts.codeparser.DottyVisitor; -import net.sf.jcontracts.codeparser.DottyVisitorConstants; -import net.sf.jcontracts.codeparser.IDependencyFilter; -import net.sf.jcontracts.idarwin.specification.openapi.IArchitectureSpecification; - -import org.apache.log4j.Logger; - -public class Darwin -{ - private static final Logger log = Logger.getLogger(Darwin.class); - - public static boolean process(String args[], Vector specset, boolean layoutLR, boolean directed, - String outputfilename, boolean check, int componentDetailLevel, boolean showPackages, Vector quietList, - Vector allFiles, Vector changedFiles, String srcbase, boolean do_not_show_dependecy_details, - IDependencyFilter filter) throws Exception - { - String recent_file = null; - try - { - Vector options; - Vector targets; - if (args.length != 0) - { - String s = ""; - for (int i = 0; i < args.length; i++) - { - if (args[i].startsWith("-") && args[i].indexOf(" ") != -1) - { - s = s + args[i].substring(0, 2) + "\"" + args[i].substring(2, args[i].length()) + "\" "; - } - else - { - s = s + args[i] + " "; - } - } - - Parser argParser = new Parser(s); - argParser.setMetaclassFactory(new ArgMetaclassFactory()); - argParser.doParse(); - options = argParser.getOptions(); - targets = argParser.getTargets(); - if (targets.isEmpty()) - { - System.err.println("iDarwin: list of source files empty, reading from standard input."); - targets.addElement(new SystemInTarget()); - } - else - { - Vector newTargets = new Vector(); - for (int i = 0; i < targets.size(); i++) - { - Target ft = (Target) targets.elementAt(i); - for (Enumeration e = ft.expand().elements(); e.hasMoreElements(); newTargets.addElement(e - .nextElement())) - { - } - } - - targets = newTargets; - } - } - else - { - options = new Vector(); - options.addElement(new HelpOption("h", new Vector())); - targets = new Vector(); - targets.addElement(new SystemInTarget()); - } - for (int i = 0; i < options.size(); i++) - { - if (!((Option) options.elementAt(i)).doesProcessing()) - { - ((ParameterOption) options.elementAt(i)).activateOnTargets(targets); - } - } - - log.info("iDarwin, Version 0.1a"); - log.info("Copyright (C) 1997-1999 Reto Kramer"); - log.info("Copyright (C) 2006 John Swapceinski, Johan\xA0Stuyts"); - log.info("options:" + options); - log.info("all files:" + targets); - if (targets.isEmpty()) - { - throw new RuntimeException( - "iDarwin: error list of source files is empty or no matches for pattern(s), no files to process!"); - } - log.info("parsing input files to determine dependencies."); - IArchitectureSpecification totalArchSpec = null; - if (check) - { - boolean atleastone = false; - for (Enumeration e = specset.elements(); e.hasMoreElements();) - { - String spec = (String) e.nextElement(); - if (!atleastone && spec.length() > 0) - { - atleastone = true; - } - int currentStart = spec.indexOf("<idarwin language="); - String languageFactory = null; - String body = null; - while (currentStart != -1 && spec.indexOf("<idarwin language=", currentStart) != -1) - { - if (spec.indexOf("<idarwin language=", currentStart) != -1 - && spec.indexOf("</idarwin>", currentStart) == -1) - { - throw new RuntimeException("iDarwin: error missing tag: </idarwin> in\n" + spec); - } - int equalPos = spec.indexOf("<idarwin language=", currentStart) + "<idarwin language=".length(); - int closingPos = spec.indexOf(">", equalPos); - if (closingPos == -1) - { - throw new RuntimeException( - "iDarwin: error missing the closing '>' after the tag '<idarwin language=' in\n" - + spec); - } - languageFactory = spec.substring(equalPos, closingPos); - int end = spec.indexOf("</idarwin>", currentStart); - if (end != -1) - { - body = spec.substring(closingPos + 1, end); - currentStart = spec.indexOf("<idarwin language=", currentStart + 1); - } - else - { - throw new RuntimeException("iDarwin: error missing tag: </idarwin> in\n" + spec); - } - String mName = "newArchitectureSpecification"; - java.lang.Class cl = java.lang.Class.forName(languageFactory); - java.lang.Class noArgArray[] = new java.lang.Class[0]; - Constructor theDefaultConstructor = cl.getConstructor(noArgArray); - Object noinitargs[] = new Object[0]; - Object o = theDefaultConstructor.newInstance(noinitargs); - java.lang.reflect.Method theMethod = cl.getMethod(mName, noArgArray); - IArchitectureSpecification archspec = (IArchitectureSpecification) theMethod.invoke(o, - noArgArray); - if (archspec == null) - { - throw new RuntimeException( - "iDarwin: error the architecture specification is null - error in the implementation of the language factory (newArchitectureSpecification() must not return null)"); - } - archspec.parseFrom(body); - if (totalArchSpec == null) - { - totalArchSpec = archspec; - } - else - { - totalArchSpec = totalArchSpec.composeWith(archspec); - } - } - } - - } - if (check) - { - totalArchSpec.prepareForCheck(); - } - DottyVisitor dv = new DottyVisitor(totalArchSpec, outputfilename, "Title goes here ...", layoutLR, - directed, componentDetailLevel, showPackages, quietList, check, do_not_show_dependecy_details, - filter); - try - { - new Vector(); - Hashtable anntable = new Hashtable(); - Vector annotations = (new CodeMetaclassCache()).getAnnotations(allFiles, changedFiles, srcbase); - for (int j = 0; j < annotations.size(); j++) - { - CodeMetaclass cm = (CodeMetaclass) annotations.elementAt(j); - String thisPackage = DottyVisitorConstants.extractPackage(cm.getName()); - if (!anntable.containsKey(thisPackage)) - { - anntable.put(thisPackage, new Vector()); - } - ((Vector) anntable.get(thisPackage)).addElement(cm); - } - - Vector ann; - for (Enumeration e = anntable.keys(); e.hasMoreElements(); ann.size()) - { - String packagename = (String) e.nextElement(); - ann = (Vector) anntable.get(packagename); - dv.startSubGraph(); - CodeMetaclass cm; - for (Enumeration annenum = ann.elements(); annenum.hasMoreElements(); cm.accept(dv)) - { - cm = (CodeMetaclass) annenum.nextElement(); - } - - dv.endSubGraph(packagename); - } - - if (check) - { - dv.export("architecture-evolution-spec.dotty"); - String finalReport = totalArchSpec.reportAfterAllChecks(); - System.err.println(); - System.err.println(finalReport); - System.err.println(); - System.err.println("\n" + dv.getNumberOfLinks() + " dependencies checked."); - if (dv.getNumberOfErrors() > 0) - { - System.err.println(dv.getNumberOfErrors() + " errors found!"); - } - else - { - System.err.println("No error found!"); - } - System.err.println(); - } - boolean flag = dv.getError(); - return flag; - } - finally - { - dv.close(); - log.info("done (file written: " + outputfilename + ")"); - } - } - catch (Exception e) - { - throw new RuntimeException("iDarwin: file being processed when the problem occured:\n" + recent_file, e); - } - } - - public Darwin() - { - } -} Modified: trunk/source/java/net/sf/jcontracts/icontract/FileTarget.java =================================================================== --- trunk/source/java/net/sf/jcontracts/icontract/FileTarget.java 2008-05-09 17:07:10 UTC (rev 47) +++ trunk/source/java/net/sf/jcontracts/icontract/FileTarget.java 2008-05-09 17:08:10 UTC (rev 48) @@ -18,11 +18,9 @@ import java.io.BufferedReader; import java.io.File; +import java.io.FileFilter; import java.io.FileReader; -import java.io.FileWriter; -import java.io.FilenameFilter; import java.io.IOException; -import java.io.PrintWriter; import java.io.Reader; import java.util.Enumeration; import java.util.Vector; @@ -40,83 +38,25 @@ super(name); } - private void copyWithoutLinesStartingWith(FileReader is, PrintWriter os, String header) throws IOException + Vector enumerateFilesIn(File dir, FileFilter filter) { - char buf[] = new char[300]; - for (int ch = is.read(); ch != -1;) - { - int pos = 0; - while (ch != -1 && (char) ch != '\n') - { - buf[pos] = (char) ch; - pos++; - ch = is.read(); - if ((char) ch == '\r') - { - ch = is.read(); - } - } - if ((char) ch == '\n') - { - ch = is.read(); - if ((char) ch == '\r') - { - ch = is.read(); - } - String strb = new String(buf, 0, pos); - if (!strb.trim().startsWith(header)) - { - os.println(strb); - } - } - } - - } - - protected Reader createStreamForCodeParsing() throws IOException - { - FileReader is = null; - PrintWriter os = null; - try - { - is = new FileReader(getName()); - os = new PrintWriter(new FileWriter(getName() + ".clean")); - copyWithoutLinesStartingWith(is, os, "/*|*/"); - } - finally - { - if (is != null) - { - is.close(); - } - if (os != null) - { - os.close(); - } - } - return new FileReader(getName() + ".clean"); - } - - Vector enumerateFilesIn(String dir, FilenameFilter filter) - { Vector fs = new Vector(); - File localroot = new File(dir); - String filenames[] = localroot.list(filter); - if (filenames != null) + File[] files = dir.listFiles(filter); + if (files != null) { - for (int i = 0; i < filenames.length; i++) + for (int i = 0; i < files.length; i++) { - File f = new File(dir + File.separator + filenames[i]); + File f = files[i]; if (f.isDirectory()) { - for (Enumeration e = enumerateFilesIn(dir + File.separator + filenames[i], filter).elements(); e + for (Enumeration e = enumerateFilesIn(f, filter).elements(); e .hasMoreElements(); fs.addElement(e.nextElement())) { } } else { - fs.addElement(dir + File.separator + filenames[i]); + fs.addElement(f.getPath()); } } @@ -137,11 +77,26 @@ } try { - BufferedReader f = new BufferedReader(new FileReader(fn)); - for (String line = null; (line = f.readLine()) != null;) + FileReader fileReader = new FileReader(fn); + try { - v.addElement(new FileTarget(line)); + BufferedReader f = new BufferedReader(fileReader); + try + { + for (String line = null; (line = f.readLine()) != null;) + { + v.addElement(new FileTarget(line)); + } + } + finally + { + f.close(); + } } + finally + { + fileReader.close(); + } } catch (IOException _ex) @@ -154,26 +109,21 @@ int pos = getName().indexOf("*"); final String pattern = getName().substring(pos, getName().length()); File dir = new File(getName()); - String tmp_parent = ""; + File parent; if (dir.getParent() == null) { - tmp_parent = "."; + parent = new File("."); } else { - dir = new File(dir.getParent()); - tmp_parent = dir.getName(); + parent = dir.getParentFile(); } - String parent = tmp_parent; - Vector filenames = enumerateFilesIn(parent, new FilenameFilter() + Vector filenames = enumerateFilesIn(parent, new FileFilter() { - - public boolean accept(File dir, String name) + public boolean accept(File file) { - File f = new File(dir + File.separator + name); - return match(name, pattern) || f.isDirectory(); + return match(file.getName(), pattern) || file.isDirectory(); } - }); for (Enumeration e = filenames.elements(); e.hasMoreElements(); v.addElement(new FileTarget((String) e .nextElement()))) @@ -224,44 +174,36 @@ Vector process(Vector options) throws Exception { Vector fileList = new Vector(); - Reader is = null; - CleanOption cleanOption = null; - for (int i = 0; i < options.size(); i++) + Reader is = new FileReader(getName()); + try { - if ("r".compareTo(((Option) options.elementAt(i)).getName()) == 0) + BufferedReader bufferedIs = new BufferedReader(is); + try { - cleanOption = (CleanOption) options.elementAt(i); - } - } - - if (cleanOption != null) - { - System.err - .println("Java Contract Suite: -r option enabled -- create a file " - + getName() - + ".clean" - + " with all instrumentation code from previous run removed. Also the cleaned file will be the input to the new instrumentation run."); - is = createStreamForCodeParsing(); - } - else - { - is = new FileReader(getName()); - } - Parser parser = new Parser(is, getName()); - MetaclassFactory metaclassFactory = new MetaclassFactory(getName()); - parser.setMetaclassFactory(metaclassFactory); - Vector intermediate = parser.getAnnotations(); - is.close(); - for (int i = 0; i < options.size(); i++) - { - if (((Option) options.elementAt(i)).doesProcessing()) - { - Vector files = ((ProcessingOption) options.elementAt(i)).process(intermediate, options, getName()); - for (Enumeration e = files.elements(); e.hasMoreElements(); fileList.addElement(e.nextElement())) + Parser parser = new Parser(bufferedIs, getName()); + MetaclassFactory metaclassFactory = new MetaclassFactory(getName()); + parser.setMetaclassFactory(metaclassFactory); + Vector intermediate = parser.getAnnotations(); + for (int i = 0; i < options.size(); i++) { + if (((Option) options.elementAt(i)).doesProcessing()) + { + Vector files = ((ProcessingOption) options.elementAt(i)).process(intermediate, options, getName()); + for (Enumeration e = files.elements(); e.hasMoreElements(); fileList.addElement(e.nextElement())) + { + } + } } } + finally + { + bufferedIs.close(); + } } + finally + { + is.close(); + } return fileList; } Modified: trunk/source/java/net/sf/jcontracts/icontract/HelpOption.java =================================================================== --- trunk/source/java/net/sf/jcontracts/icontract/HelpOption.java 2008-05-09 17:07:10 UTC (rev 47) +++ trunk/source/java/net/sf/jcontracts/icontract/HelpOption.java 2008-05-09 17:08:10 UTC (rev 48) @@ -30,6 +30,14 @@ private static final String VERSION_RESOURCE_NAME = "version.txt"; + private static final String LABEL_SPACES = " "; + + private static final int INDENT_SIZE = LABEL_SPACES.length() + 1; + + private static final int MAX_TOTAL_WIDTH = 79; + + private static final int MAX_PARAGRAPH_WIDTH = MAX_TOTAL_WIDTH - INDENT_SIZE; + public static final String NAME = "h"; static @@ -77,113 +85,139 @@ protected void activateOnTargets(Vector targets) { - System.out.println("NAME: Java Contract Suite, Version " + VERSION); - System.out.println("AUTHOR: Copyright (C) 1997-1999 Reto Kramer"); - System.out.println(" Copyright (C) 2006 John Swapceinski, Johan Stuyts"); - System.out.println("SYNOPSIS: java net.sf.jcontracts.icontract.Tool {option} {file}"); - System.out.println("DESCRIPTION: Provides Java with full support for \"Design by Contract\"."); - System.out.println(" Instruments java source code files with checks to enforce:"); - System.out.println(" - method pre- and post-conditions"); - System.out.println(" - class/interface invariants"); - System.out.println(" based on comments in the code (@pre, @post, @invariant)."); - System.out.println(" Java Contract Suite operates on classes, interfaces, and methods."); - System.out.println(" file: Is a list of java sourcecode files (space separated)."); - System.out.println(" If a name of the form @file is in the list, each line in file"); - System.out.println(" is interpreted as a filename."); - System.out.println(" If a name is a pattern (e.g. ./x/*.java), all files in x and"); - System.out.println(" subdirectories thereof are searched for *.java files."); - System.out.println(" {option}: Is a list of options, Java Contract Suite accepts the following options:"); - System.out.println(" (if no option is given, Java Contract Suite uses the -h option)"); - System.out.println(""); - System.out.println(" GENERAL:"); - System.out.println(" -h prints version, synopsis and a brief description."); - System.out.println(" -vA,B,C control how much information is displayed."); - System.out.println(" if -v is not present, errors and warnings are displayed."); - System.out.println(" -v (no args) displays errors, warnings and progress information."); - System.out.println(" A,B,C may be error*, warning*, note*, info*, progress* and debug*"); - System.out.println(" -a regenerates all files, even if the timestamps say that"); - System.out.println(" the instrumented version is up to date."); - System.out.println(""); - System.out.println(" OUTPUT:"); - System.out.println(" -oF Store the instrumented code output into file F."); - System.out.println(" F may include @p, @f and @e which will be substituted with path"); - System.out.println(" filename and file extension of the file being processed."); - System.out.println(" NOTE: add that location to the classpath for -c compiler"); - System.out.println(" e.g. ... -c'java -classpath @p' ..."); - System.out.println(""); - System.out.println(" -jF Copy the original sourcefiles into file F before compilation."); - System.out.println(" F may include @p, @f and @e which will be substituted with path"); - System.out.println(" filename and file extension of the file being processed."); - System.out.println(" [useful if working with sourcefiles of extensions other than .java]"); - System.out.println(" NOTE: add that location to the classpath for -b compiler"); - System.out.println(" e.g. ... -b'java -classpath @p' ..."); - System.out.println(""); - System.out.println(" -kF Rewrite the repository filename using F (F=specific dir)."); - System.out.println(" F may include @p (neither @f nor @e) which will be substituted"); - System.out.println(" with the path of the file being processed."); - System.out.println(" [useful if the repository shall be stored at a specific place]"); - System.out.println(" NOTE: add that location to the classpath for -n compiler"); - System.out.println(" e.g. ... -n'java -classpath @p' ..."); - System.out.println(""); - System.out.println(" COMPILERS:"); - System.out.println(" Note: C denotes the compiler command(e.g. javac). if the colon (:) is."); - System.out.println(" used the sun.tools.javac.Main compiler is called in the same VM."); - System.out.println(" For small files this results in speedups and lower mem consumtion"); - System.out.println(" -bC use compiler C to compile the sourcefiles BEFORE instrumentation."); - System.out.println(" If the -jC option is missing (default), 'javac' is invoked."); - System.out.println(" If -j (no C) is used, initial sourcefiles will not be compiled."); - System.out.println(" [NOTE: the -j output option allow redirection of file-location]"); - System.out.println(""); - System.out.println(" -cC use compiler C to compile the sourcefiles AFTER instrumentation."); - System.out.println(" If the -cC option is missing (default), 'javac' is invoked."); - System.out.println(" If -c (no C) is used, instrumented sourcefiles will not be compiled."); - System.out.println(" [NOTE: the -o output option allow redirection of file-location]"); - System.out.println(""); - System.out.println(" -y ensures that the -o/-c options work with JDK 1.1 by passing"); - System.out.println(" the filename (excl. dir prefix) to the -c compiler only."); - System.out.println(""); - System.out.println(" -nC use compiler C to automatically compile the repository files."); - System.out.println(" [useful if working with a non JDK compiler.]"); - System.out.println(" If the -nC option is missing (default), 'javac' is invoked."); - System.out.println(" If -n (no C) is used, repositories will not be compiled."); - System.out.println(" [NOTE: the -k output option allow redirection of file-location]"); - System.out.println(""); - System.out.println(" CONTROL:"); - System.out.println(" -mOPT{,OPT} Instruments the source code depending on the list of flags OPT:"); - System.out.println(" OPT can be either \"@<file>\", \"pre\", \"post\" or \"inv\""); - System.out.println(" -mpre instruments only the method pre-conditions (@pre <bool expr>)"); - System.out.println(" -mpost instruments only the method post-conditions (@post <bool expr>)"); - System.out.println(" -minv instruments only the class invariants (@invariant <bool expr>)"); - System.out.println(" -m@file reads each line in file <package.type.method> <pre,post,inv>"); - System.out.println(" to allow fine control over what is instrumented."); - System.out.println(" NOTE: -mpre,post,inv override @file entries!"); - System.out.println(""); - System.out.println(" -qA,B,C disables warnings related to contract propagation from"); - System.out.println(" classes A,B and C."); - System.out.println(" A,B and C may be qualified (e.g. package.class)"); - System.out.println(" NOTE: Only the first warning related to a type will be displayed!"); - System.out.println(" The special name :all: (-q:all:,A,B) disables warning suppresion"); - System.out.println(""); - System.out.println(" -i (experimental) in subclasses instrument a call to the superclass'"); - System.out.println(" invariant check method to allow private fields to be part of the"); - System.out.println(" superclass invariant expression"); - System.out.println(""); - System.out.println(" -w generate code that ensures that pre/post/inv-checks do not throw"); - System.out.println(" checked exceptions - they will be 'converted' to RuntimeException."); - System.out.println(" This option is not compatible with the -d option."); - System.out.println(" -dE Use exception class E as the default exception throw for contract"); - System.out.println(" volation. E may be qualified (e.g. package.class)."); - System.out.println(" This option is not compatible with the -w option."); - System.out.println(""); - System.out.println(" MISC:"); - System.out.println(" -r Before instrumenting, remove all instrumentation code in the"); - System.out.println(" source file (removes all lines starting with \"/*|*/\")."); - System.out.println(" Also creates a clean file <inputfile>.clean"); - System.out.println(""); - System.out.println(" PROBLEMS:"); - System.out.println(" Please enter problem reports and requests for new features in"); - System.out.println(" the issue tracker, which can be found at:"); - System.out.println(" https://sourceforge.net/tracker/?group_id=175492&atid=889550"); + printParagraph("NAME:", "Java Contract Suite, Version " + VERSION); + System.out.println(); + + printParagraph("AUTHOR:", "Copyright (C) 1997-1999 Reto Kramer"); + printParagraph("Copyright (C) 2006 John Swapceinski, Johan Stuyts"); + System.out.println(); + + printParagraph("SYNOPSIS:", "java net.sf.jcontracts.icontract.Tool {options} {files}"); + System.out.println(); + + printParagraph("DESCRIPTION:", "Provides Java with full support for \"Design by Contract\". " + + "Instruments java source code files with checks to enforce:"); + printParagraph("- method pre- and post-conditions"); + printParagraph("- class/interface invariants"); + printParagraph("based on comments in the code (@pre, @post, @invariant). " + + "Java Contract Suite operates on classes, interfaces, and methods."); + System.out.println(); + + printParagraph("CLASSPATH:", "The following items need to be on the class path " + + "so Java Contract Suite can generate instrumented and repository sources " + + "for your project:"); + printParagraph("- JAR files of Java Contract Suite and Log4j"); + printParagraph("- JAR files containing instrumented classes of \"Design by Contract\" enabled dependencies"); + printParagraph("- JAR files containing repository classes of \"Design by Contract\" enabled dependencies"); + printParagraph("- JAR files of regular dependencies"); + printParagraph("- uninstrumented classes of project"); + System.out.println(); + + printLabel("PARAMETERS:"); + + printParagraph("files", "Is a list of java sourcecode files (space separated)."); + System.out.println(); + printParagraph("If a name of the form @file is in the list, each line in file " + + "is interpreted as a filename."); + System.out.println(); + printParagraph("If a name is a pattern (e.g. ./x/*.java), all files in x and " + + "subdirectories thereof are searched for *.java files."); + System.out.println(); + + printParagraph("options", "Is a list of options, Java Contract Suite accepts the following " + + "options: (if no parameters are given, Java Contract Suite uses the -h " + + "option)"); + System.out.println(); + + printLabel("GENERAL:"); + + printParagraph("-h", "prints version, synopsis and a brief description."); + System.out.println(); + + printParagraph("-a", "regenerates all files, even if the timestamps say that " + + "the instrumented version is up to date."); + System.out.println(); + + printLabel("OUTPUT:"); + + printParagraph("-oF", "Store the instrumented code output into file F. " + + "F may include @p, @f and @e which will be substituted with path, " + + "filename and file extension of the file being processed."); + System.out.println(); + + printParagraph("-kD", "Rewrite the repository filename using D (D=specific dir). " + + "D may include @p (neither @f nor @e) which will be substituted " + + "with the path of the file being processed."); + printParagraph("[useful if the repository shall be stored at a specific place]"); + System.out.println(); + + printLabel("CONTROL:"); + + printParagraph("-mOPT,{OPT}", "Instruments the source code depending on the list of flags OPT. " + + "OPT can be either \"@<file>\", \"pre\", \"post\" or \"inv\"."); + printParagraph("-mpre", "Instruments only the method pre-conditions (@pre <bool expr>)."); + printParagraph("-mpost", "Instruments only the method post-conditions (@post <bool expr>)."); + printParagraph("-minv", "Instruments only the class invariants (@invariant <bool expr>)."); + printParagraph("-m@file", "Reads each line in file <package.type.method> <pre,post,inv> " + + "to allow fine control over what is instrumented."); + printParagraph("NOTE:", "-mpre,post,inv override @file entries!"); + System.out.println(); + + printParagraph("-dE", "Use exception class E as the default exception thrown for contract " + + "volations. E may be qualified (e.g. package.class)."); + System.out.println(); + + printParagraph("PROBLEMS:", "Please enter problem reports and requests for new features in " + + "the issue tracker, which can be found at:"); + printParagraph("https://sourceforge.net/tracker/?group_id=175492&atid=889550"); + System.exit(0); } + + private void printParagraph(String text) + { + printParagraph("", text); + } + + private void printParagraph(String label, String text) + { + printLabelWithoutNewLine(label); + System.out.print(' '); + printParagraphText(text); + } + + private void printLabel(String label) + { + printLabelWithoutNewLine(label); + System.out.println(); + } + + private void printLabelWithoutNewLine(String label) + { + System.out.print(LABEL_SPACES.substring(label.length())); + System.out.print(label); + } + + private void printParagraphText(String text) + { + if (text.length() <= MAX_PARAGRAPH_WIDTH) + { + System.out.println(text); + } + else + { + int lastIndexOfSpaceWithinParagraphWidth = text.lastIndexOf(' ', MAX_PARAGRAPH_WIDTH); + if (lastIndexOfSpaceWithinParagraphWidth == -1) + { + System.out.println(text); + } + else + { + System.out.println(text.substring(0, lastIndexOfSpaceWithinParagraphWidth)); + System.out.print(LABEL_SPACES); + System.out.print(' '); + printParagraphText(text.substring(lastIndexOfSpaceW... [truncated message content] |