#!/usr/bin/python """ Eclipse.py by Bruce Eckel, for Thinking in Java 4e Modify or insert package statments so that Eclipse is happy with the code tree. Run this with no arguments from the root of the code tree. The Ant build will not work once you run this program! You may also want to modify the dotproject and dotclasspath text below. You must have Python 2.3 installed to run this program. See www.python.org. """ import os os.remove("reusing/Lisa.java"); for path, dirs, files in os.walk('.'): for file in files: if file.endswith(".java"): filepath = path + os.sep + file firstLine = open(filepath).readline().strip() tagPath = firstLine.split()[1] tagPath = ".".join(tagPath.split('/')[:-1]) packageStatement = "package " + tagPath + ";" code = open(filepath).readlines() found = False for line in code: if line.startswith("package "): found = True if not found: code.insert(1, packageStatement + " /* Added by Eclipse.py */\n") open(filepath, 'w').writelines(code) here = os.path.abspath('.').replace("\\", "/") if here.startswith("/cygdrive/"): # If using cygwin here = here.replace("/cygdrive/", "", 1) here = here[0] + ":" + here[1:] print "here", here open(".classpath", 'w').write(\ """ """) # % (here, here)) open(".project", 'w').write(\ """ TIJ4 org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature """) if not os.path.exists(".settings"): os.mkdir(".settings") os.chdir(".settings") open("org.eclipse.jdt.core.prefs", 'w').write(\ """#Fri Jan 14 11:03:37 MST 2005 org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.problem.enumIdentifier=error eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error """) print """Project ready to be opened with Eclipse (see www.Eclipse.org) Use DEclipse.py if you want to go back to building with Ant."""