From: <otm...@us...> - 2008-11-05 07:30:33
|
Revision: 5544 http://jython.svn.sourceforge.net/jython/?rev=5544&view=rev Author: otmarhumbel Date: 2008-11-05 07:30:28 +0000 (Wed, 05 Nov 2008) Log Message: ----------- installation autotests now verify the shell scripts more deeply the set of calls is defined in jython_test.template and jython_test.bat.template Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/AbstractWizardPage.java trunk/installer/src/java/org/python/util/install/JarInfo.java trunk/installer/src/java/org/python/util/install/JarInstaller.java trunk/installer/src/java/org/python/util/install/JavaVersionTester.java trunk/installer/src/java/org/python/util/install/StartScriptGenerator.java trunk/installer/src/java/org/python/util/install/driver/Autotest.java trunk/installer/src/java/org/python/util/install/driver/InstallationDriver.java trunk/installer/src/java/org/python/util/install/driver/NormalVerifier.java trunk/installer/src/java/org/python/util/install/driver/StandaloneVerifier.java trunk/installer/test/java/org/python/util/install/StandalonePackagerTest.java trunk/installer/test/java/org/python/util/install/StartScriptGeneratorTest.java trunk/installer/test/java/org/python/util/install/driver/NormalVerifierTest.java trunk/installer/test/java/org/python/util/install/driver/StandaloneVerifierTest.java trunk/jython/build.xml Added Paths: ----------- trunk/installer/src/java/org/python/util/install/FileHelper.java trunk/installer/src/java/org/python/util/install/driver/jython_test.bat.template trunk/installer/src/java/org/python/util/install/driver/jython_test.template trunk/installer/test/java/org/python/util/install/FileHelperTest.java Removed Paths: ------------- trunk/installer/src/java/org/python/util/install/driver/FileHelper.java Modified: trunk/installer/src/java/org/python/util/install/AbstractWizardPage.java =================================================================== --- trunk/installer/src/java/org/python/util/install/AbstractWizardPage.java 2008-11-05 02:56:03 UTC (rev 5543) +++ trunk/installer/src/java/org/python/util/install/AbstractWizardPage.java 2008-11-05 07:30:28 UTC (rev 5544) @@ -9,6 +9,8 @@ import javax.swing.JPanel; public abstract class AbstractWizardPage extends JPanel implements TextKeys { + private static final long serialVersionUID = -5233805023557214279L; + private static final String _ICON_FILE_NAME = "jython_small_c.png"; private static ImageIcon _imageIcon = null; @@ -54,11 +56,7 @@ */ protected ImageIcon getIcon() { if (_imageIcon == null) { - String className = getClass().getName(); - String packageName = className.substring(0, className.lastIndexOf(".")); - String packagePath = packageName.replace('.', '/'); - URL iconURL = Thread.currentThread().getContextClassLoader().getResource( - packagePath + "/" + _ICON_FILE_NAME); + URL iconURL = FileHelper.getRelativeURL(getClass(), _ICON_FILE_NAME); if (iconURL != null) { _imageIcon = new ImageIcon(iconURL); } Added: trunk/installer/src/java/org/python/util/install/FileHelper.java =================================================================== --- trunk/installer/src/java/org/python/util/install/FileHelper.java (rev 0) +++ trunk/installer/src/java/org/python/util/install/FileHelper.java 2008-11-05 07:30:28 UTC (rev 5544) @@ -0,0 +1,208 @@ +package org.python.util.install; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +/** + * Helper methods for file handling during installation / installation verification + */ +public final class FileHelper { + + private final static String EXECUTABLE_MODE = "755"; + + /** + * create a temporary directory with the same name as the passed in File (which may exist as + * file, not directory) + * + * @param tempDirectory + * @return <code>true</code> only if the the directory was successfully created (or already + * existed) + */ + public static boolean createTempDirectory(File tempDirectory) { + boolean success = true; + if (!tempDirectory.isDirectory()) { + if (tempDirectory.exists()) { + success = carryOnResult(tempDirectory.delete(), success); + } + if (success) { + success = tempDirectory.mkdirs(); + } + } + return success; + } + + /** + * completely remove a directory + * + * @param dir + * @return <code>true</code> if successful, <code>false</code> otherwise. + */ + public static boolean rmdir(File dir) { + boolean success = true; + if (dir.exists()) { + File[] files = dir.listFiles(); + for (int i = 0; i < files.length; i++) { + File file = files[i]; + if (file.isFile()) { + success = carryOnResult(file.delete(), success); + } else { + if (file.isDirectory()) { + success = carryOnResult(rmdir(file), success); + } + } + } + success = carryOnResult(dir.delete(), success); + } + return success; + } + + /** + * read the contents of a file into a String + * + * @param file + * The file has to exist + * @return The contents of the file as String + * @throws IOException + */ + public static String readAll(File file) throws IOException { + FileReader fileReader = new FileReader(file); + try { + StringBuffer sb = new StringBuffer(); + char[] b = new char[8192]; + int n; + while ((n = fileReader.read(b)) > 0) { + sb.append(b, 0, n); + } + return sb.toString(); + } finally { + fileReader.close(); + } + } + + /** + * read the contents of a stream into a String + * <p> + * ATTN: does not handle encodings + * + * @param inputStream + * The input stream + * @return A String representation of the file contents + * @throws IOException + */ + public static String readAll(InputStream inputStream) throws IOException { + try { + StringBuffer sb = new StringBuffer(); + byte[] b = new byte[8192]; + int n; + while ((n = inputStream.read(b)) > 0) { + sb.append(new String(b, 0, n)); + } + return sb.toString(); + } finally { + inputStream.close(); + } + } + + /** + * Write contents to a file. + * <p> + * An existing file would be overwritten. + * + * @param file + * @param contents + * + * @throws IOException + */ + public static void write(File file, String contents) throws IOException { + FileWriter writer = new FileWriter(file); + writer.write(contents); + writer.flush(); + writer.close(); + } + + /** + * determine the url of a file relative to (in the same directory as) the specified .class file<br> + * can also be used if the .class file resides inside a .jar file + * + * @param clazz + * The class next to the file + * @param fileName + * The name of the file + * + * @return The url of the file, can be null + */ + public static URL getRelativeURL(Class<?> clazz, String fileName) { + String filePath = getRelativePackagePath(clazz) + "/" + fileName; + return Thread.currentThread().getContextClassLoader().getResource(filePath); + } + + /** + * get the input stream of a file relative to (in the same directory as) the specified .class + * file<br> + * can also be used if the .class file resides inside a .jar file + * + * @param clazz + * The class next to the file + * @param fileName + * The name of the file + * + * @return The input stream of the file, can be null + */ + public static InputStream getRelativeURLAsStream(Class<?> clazz, String fileName) { + String filePath = getRelativePackagePath(clazz) + "/" + fileName; + return Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath); + } + + /** + * do a chmod on the passed file + * + * @param scriptFile + */ + public static void makeExecutable(File scriptFile) { + try { + String command[] = new String[3]; + command[0] = "chmod"; + command[1] = EXECUTABLE_MODE; + command[2] = scriptFile.getAbsolutePath(); + long timeout = 3000; + ChildProcess childProcess = new ChildProcess(command, timeout); + childProcess.run(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + /** + * build the package path for the class loader<br> + * the class loader should be able to load a file appended to this path, if it is in the same + * directory. + * + * @param clazz + * The class + * + * @return The package path + */ + private static String getRelativePackagePath(Class<?> clazz) { + String className = clazz.getName(); + String packageName = className.substring(0, className.lastIndexOf(".")); + return packageName.replace('.', '/'); + } + + /** + * @param newResult + * @param existingResult + * @return <code>false</code> if newResult or existingResult are false, <code>true</code> + * otherwise. + */ + private static boolean carryOnResult(boolean newResult, boolean existingResult) { + if (existingResult) { + return newResult; + } else { + return existingResult; + } + } +} Modified: trunk/installer/src/java/org/python/util/install/JarInfo.java =================================================================== --- trunk/installer/src/java/org/python/util/install/JarInfo.java 2008-11-05 02:56:03 UTC (rev 5543) +++ trunk/installer/src/java/org/python/util/install/JarInfo.java 2008-11-05 07:30:28 UTC (rev 5544) @@ -75,8 +75,8 @@ return _numberOfEntries; } - public List getExcludeDirs() throws IOException { - List excludeDirs = new ArrayList(); + public List<String> getExcludeDirs() throws IOException { + List<String> excludeDirs = new ArrayList<String>(); Attributes jythonAttributes = getManifest().getAttributes(JYTHON); if (jythonAttributes != null) { // do not use containsKey @@ -122,7 +122,7 @@ throw new InstallerException(Installation.getText(TextKeys.JAR_NOT_FOUND, _jarFile.getAbsolutePath())); } JarFile jarFile = new JarFile(_jarFile); - Enumeration entries = jarFile.entries(); + Enumeration<JarEntry> entries = jarFile.entries(); _numberOfEntries = 0; while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); Modified: trunk/installer/src/java/org/python/util/install/JarInstaller.java =================================================================== --- trunk/installer/src/java/org/python/util/install/JarInstaller.java 2008-11-05 02:56:03 UTC (rev 5543) +++ trunk/installer/src/java/org/python/util/install/JarInstaller.java 2008-11-05 07:30:28 UTC (rev 5544) @@ -13,25 +13,31 @@ /** * Working horse extracting the contents of the installation .jar to the file system. <br> - * The directory stucture is preserved, but there is the possibility to exclude some entries (directories at the - * moment). + * The directory stucture is preserved, but there is the possibility to exclude some entries + * (directories at the moment). */ public class JarInstaller { + public static final String JYTHON_JAR = "jython-complete.jar"; - + private static final String PATH_SEPARATOR = "/"; + private static final String LIB_NAME_SEP = "Lib" + PATH_SEPARATOR; + private static final String LIB_PAWT_SEP = LIB_NAME_SEP + "pawt" + PATH_SEPARATOR; + private static final int BUFFER_SIZE = 1024; private ProgressListener _progressListener; + private JarInfo _jarInfo; - private List _installationListeners; + private List<InstallationListener> _installationListeners; + public JarInstaller(ProgressListener progressListener, JarInfo jarInfo) { _progressListener = progressListener; _jarInfo = jarInfo; - _installationListeners = new ArrayList(); + _installationListeners = new ArrayList<InstallationListener>(); } /** @@ -48,8 +54,8 @@ try { // has to correspond with build.xml // has to correspond with build.Lib.include.properties - List excludeDirs = _jarInfo.getExcludeDirs(); - List coreLibFiles = new ArrayList(); + List<String> excludeDirs = _jarInfo.getExcludeDirs(); + List<String> coreLibFiles = new ArrayList<String>(); if (!installationType.installSources()) { excludeDirs.add("src"); excludeDirs.add("grammar"); @@ -73,35 +79,36 @@ excludeDirs.add(LIB_NAME_SEP + "email/test"); excludeDirs.add(LIB_NAME_SEP + "test"); } - int count = 0; int percent = 0; int numberOfIntervals = 100 / _progressListener.getInterval(); int numberOfEntries = approximateNumberOfEntries(installationType); int threshold = numberOfEntries / numberOfIntervals + 1; // +1 = pessimistic boolean coreExclusionReported = false; - // unzip - ZipInputStream zipInput = new ZipInputStream(new BufferedInputStream(new FileInputStream(_jarInfo - .getJarFile()), BUFFER_SIZE)); + ZipInputStream zipInput = new ZipInputStream(new BufferedInputStream(new FileInputStream(_jarInfo.getJarFile()), + BUFFER_SIZE)); ZipEntry zipEntry = zipInput.getNextEntry(); while (zipEntry != null) { String zipEntryName = zipEntry.getName(); boolean exclude = false; // handle exclusion of directories - Iterator excludeDirsAsIterator = excludeDirs.iterator(); + Iterator<String> excludeDirsAsIterator = excludeDirs.iterator(); while (excludeDirsAsIterator.hasNext()) { - if (zipEntryName.startsWith((String) excludeDirsAsIterator.next() + PATH_SEPARATOR)) { + if (zipEntryName.startsWith((String)excludeDirsAsIterator.next() + + PATH_SEPARATOR)) { exclude = true; } } // exclude build.xml when not installing source if (!installationType.installSources() && zipEntryName.equals("build.xml")) exclude = true; - // handle exclusion of core Lib files if (!exclude) { - exclude = shouldExcludeFile(installationType, coreLibFiles, zipEntry, zipEntryName); + exclude = shouldExcludeFile(installationType, + coreLibFiles, + zipEntry, + zipEntryName); if (Installation.isVerbose() && !coreExclusionReported && exclude) { ConsoleInstaller.message("excluding some .py files, like " + zipEntryName); coreExclusionReported = true; @@ -125,7 +132,7 @@ byte[] buffer = new byte[BUFFER_SIZE]; int len; while ((len = zipInput.read(buffer)) > 0) { - output.write(buffer, 0, len); + output.write(buffer, 0, len); } output.close(); file.setLastModified(zipEntry.getTime()); @@ -150,13 +157,14 @@ _progressListener.progressChanged(90); // approx packager.addFullDirectory(libDir); packager.close(); + // TODO:Oti move to FileHelper StandalonePackager.emptyDirectory(targetDirectory, jythonJar); } - // end + // finish: inform listeners _progressListener.progressFinished(); - Iterator installationListenersIterator = _installationListeners.iterator(); + Iterator<InstallationListener> installationListenersIterator = _installationListeners.iterator(); while (installationListenersIterator.hasNext()) { - ((InstallationListener) installationListenersIterator.next()).progressFinished(); + installationListenersIterator.next().progressFinished(); } } catch (IOException ioe) { throw new InstallerException(Installation.getText(TextKeys.ERROR_ACCESS_JARFILE), ioe); @@ -194,29 +202,29 @@ int lastSepIndex = zipEntryName.lastIndexOf(PATH_SEPARATOR); if (lastSepIndex > 0) { File directory = new File(targetDirectory, zipEntryName.substring(0, lastSepIndex)); - if (directory.exists() && directory.isDirectory()) { - } else { + if (directory.exists() && directory.isDirectory()) {} else { if (!directory.mkdirs()) { - throw new InstallerException(Installation.getText(TextKeys.UNABLE_CREATE_DIRECTORY, directory - .getAbsolutePath())); + throw new InstallerException(Installation.getText(TextKeys.UNABLE_CREATE_DIRECTORY, + directory.getAbsolutePath())); } } } } - private File createFile(final File targetDirectory, final String zipEntryName) throws IOException { + private File createFile(final File targetDirectory, final String zipEntryName) + throws IOException { File file = new File(targetDirectory, zipEntryName); - if (file.exists() && file.isFile()) { - } else { + if (file.exists() && file.isFile()) {} else { if (!file.createNewFile()) { - throw new InstallerException(Installation.getText(TextKeys.UNABLE_CREATE_FILE, file.getCanonicalPath())); + throw new InstallerException(Installation.getText(TextKeys.UNABLE_CREATE_FILE, + file.getCanonicalPath())); } } return file; } - private List getCoreLibFiles() { - List coreLibFiles = new ArrayList(); + private List<String> getCoreLibFiles() { + List<String> coreLibFiles = new ArrayList<String>(); coreLibFiles.add("__future__.py"); coreLibFiles.add("copy.py"); coreLibFiles.add("dbexts.py"); @@ -247,8 +255,10 @@ return coreLibFiles; } - private boolean shouldExcludeFile(InstallationType installationType, List coreLibFiles, ZipEntry zipEntry, - String zipEntryName) { + private boolean shouldExcludeFile(InstallationType installationType, + List<String> coreLibFiles, + ZipEntry zipEntry, + String zipEntryName) { boolean exclude = false; if (!installationType.installLibraryModules()) { // handle files in Lib @@ -257,9 +267,9 @@ if (!zipEntryName.startsWith(LIB_PAWT_SEP)) { if (zipEntryName.endsWith(".py")) { // only compare *.py files exclude = true; - Iterator coreLibFilesAsIterator = coreLibFiles.iterator(); + Iterator<String> coreLibFilesAsIterator = coreLibFiles.iterator(); while (coreLibFilesAsIterator.hasNext()) { - String coreFileName = (String) coreLibFilesAsIterator.next(); + String coreFileName = (String)coreLibFilesAsIterator.next(); if (zipEntryName.endsWith(PATH_SEPARATOR + coreFileName)) { exclude = false; } @@ -270,5 +280,4 @@ } return exclude; } - } Modified: trunk/installer/src/java/org/python/util/install/JavaVersionTester.java =================================================================== --- trunk/installer/src/java/org/python/util/install/JavaVersionTester.java 2008-11-05 02:56:03 UTC (rev 5543) +++ trunk/installer/src/java/org/python/util/install/JavaVersionTester.java 2008-11-05 07:30:28 UTC (rev 5544) @@ -1,7 +1,6 @@ package org.python.util.install; import java.io.File; -import java.io.FileWriter; /** * Helper class to test a java version @@ -39,10 +38,7 @@ } private static void writeTempFile(File file) throws Exception { - FileWriter writer = new FileWriter(file); - writer.write(createFileContent()); - writer.flush(); - writer.close(); + FileHelper.write(file, createFileContent()); } private static String createFileContent() { Modified: trunk/installer/src/java/org/python/util/install/StartScriptGenerator.java =================================================================== --- trunk/installer/src/java/org/python/util/install/StartScriptGenerator.java 2008-11-05 02:56:03 UTC (rev 5543) +++ trunk/installer/src/java/org/python/util/install/StartScriptGenerator.java 2008-11-05 07:30:28 UTC (rev 5544) @@ -1,8 +1,6 @@ package org.python.util.install; import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; import java.text.MessageFormat; import java.util.Date; @@ -17,8 +15,6 @@ protected final static String WIN_CR_LF; - private final static String EXECUTABLE_MODE = "755"; - private final static String JYTHON = "jython"; private final static String JYTHON_BAT = "jython.bat"; @@ -75,20 +71,26 @@ } protected final void generateStartScripts() throws IOException { - generateJythonScript(); - } - - private final void generateJythonScript() throws IOException { + File bin = new File(getTargetDirectory(), "bin"); + File bin_jython = new File(bin, JYTHON); switch(getFlavour()){ case BOTH_FLAVOUR: - writeToFile(JYTHON_BAT, getJythonScript(WINDOWS_FLAVOUR)); - makeExecutable(writeToFile(JYTHON, getJythonScript(BOTH_FLAVOUR))); + writeToTargetDir(JYTHON_BAT, getJythonScript(WINDOWS_FLAVOUR)); + FileHelper.makeExecutable(writeToTargetDir(JYTHON, getJythonScript(BOTH_FLAVOUR))); + FileHelper.makeExecutable(bin_jython); break; case WINDOWS_FLAVOUR: - writeToFile(JYTHON_BAT, getJythonScript(WINDOWS_FLAVOUR)); + writeToTargetDir(JYTHON_BAT, getJythonScript(WINDOWS_FLAVOUR)); + // delete the *nix script in /bin dir + bin_jython.delete(); break; default: - makeExecutable(writeToFile(JYTHON, getJythonScript(UNIX_FLAVOUR))); + FileHelper.makeExecutable(writeToTargetDir(JYTHON, getJythonScript(UNIX_FLAVOUR))); + FileHelper.makeExecutable(bin_jython); + // delete the windows script in /bin dir + File bin_jython_bat = new File(bin, JYTHON_BAT); + bin_jython_bat.delete(); + break; } } @@ -116,7 +118,7 @@ parameters[0] = new Date().toString(); parameters[1] = System.getProperty("user.name"); parameters[2] = _javaHome.getCanonicalPath(); - parameters[3] = _targetDirectory.getCanonicalPath(); + parameters[3] = getTargetDirectory().getCanonicalPath(); return MessageFormat.format(template, (Object[])parameters); } @@ -183,65 +185,31 @@ */ private String readFromFile(String fileName) throws IOException { // default runtime location - File file = new File(new File(_targetDirectory, "bin"), fileName); + File targetDirectory = getTargetDirectory(); + File file = new File(new File(targetDirectory, "bin"), fileName); if (!file.exists()) { // deviation: test time location - file = new File(_targetDirectory, fileName); + file = new File(targetDirectory, fileName); } - FileReader fileReader = new FileReader(file); - try { - StringBuffer sb = new StringBuffer(); - char[] b = new char[8192]; - int n; - while ((n = fileReader.read(b)) > 0) { - sb.append(b, 0, n); - } - return sb.toString(); - } finally { - fileReader.close(); - } + return FileHelper.readAll(file); } /** + * Create (or overwrite) the specified file in the target directory + * * @param fileName * The short file name, e.g. JYTHON_BAT * @param contents * * @throws IOException */ - private File writeToFile(String fileName, String contents) throws IOException { - File file = new File(_targetDirectory, fileName); - if (file.exists()) { - file.delete(); - } - file.createNewFile(); - if (file.exists()) { - if (file.canWrite()) { - FileWriter fileWriter = new FileWriter(file); - fileWriter.write(contents); - fileWriter.flush(); - fileWriter.close(); - } - } + private File writeToTargetDir(String fileName, String contents) throws IOException { + File file = new File(getTargetDirectory(), fileName); + FileHelper.write(file, contents); return file; } - /** - * do a chmod on the passed file - * - * @param scriptFile - */ - private void makeExecutable(File scriptFile) { - try { - String command[] = new String[3]; - command[0] = "chmod"; - command[1] = EXECUTABLE_MODE; - command[2] = scriptFile.getAbsolutePath(); - long timeout = 3000; - ChildProcess childProcess = new ChildProcess(command, timeout); - childProcess.run(); - } catch (Throwable t) { - t.printStackTrace(); - } + private File getTargetDirectory() { + return _targetDirectory; } } Modified: trunk/installer/src/java/org/python/util/install/driver/Autotest.java =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/Autotest.java 2008-11-05 02:56:03 UTC (rev 5543) +++ trunk/installer/src/java/org/python/util/install/driver/Autotest.java 2008-11-05 07:30:28 UTC (rev 5544) @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; +import org.python.util.install.FileHelper; import org.python.util.install.InstallationListener; import org.python.util.install.InstallerCommandLine; Deleted: trunk/installer/src/java/org/python/util/install/driver/FileHelper.java =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/FileHelper.java 2008-11-05 02:56:03 UTC (rev 5543) +++ trunk/installer/src/java/org/python/util/install/driver/FileHelper.java 2008-11-05 07:30:28 UTC (rev 5544) @@ -1,24 +0,0 @@ -package org.python.util.install.driver; - -import java.io.File; - -public class FileHelper { - - /** - * create a temporary directory with the same name as the passed in File (which may exist as file, not directory) - * - * @param tempDirectory - * @return <code>true</code> only if the the directory was successfully created (or already existed) - */ - public static boolean createTempDirectory(File tempDirectory) { - if (!tempDirectory.isDirectory()) { - if (tempDirectory.exists()) { - tempDirectory.delete(); - } - return tempDirectory.mkdir(); - } else { - return true; - } - } - -} Modified: trunk/installer/src/java/org/python/util/install/driver/InstallationDriver.java =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/InstallationDriver.java 2008-11-05 02:56:03 UTC (rev 5543) +++ trunk/installer/src/java/org/python/util/install/driver/InstallationDriver.java 2008-11-05 07:30:28 UTC (rev 5544) @@ -110,7 +110,7 @@ private void validate(Autotest autoTest) throws DriverException { autoTest.assertTargetDirNotEmpty(); if (autoTest.getVerifier() != null) { - System.out.println("verifying installation ..."); + System.out.println("verifying installation - this can take a while ..."); autoTest.getVerifier().verify(); System.out.println("... installation ok.\n"); } Modified: trunk/installer/src/java/org/python/util/install/driver/NormalVerifier.java =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/NormalVerifier.java 2008-11-05 02:56:03 UTC (rev 5543) +++ trunk/installer/src/java/org/python/util/install/driver/NormalVerifier.java 2008-11-05 07:30:28 UTC (rev 5544) @@ -1,139 +1,263 @@ -package org.python.util.install.driver; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintStream; -import java.util.StringTokenizer; - -import org.python.util.install.ChildProcess; -import org.python.util.install.Installation; - -public class NormalVerifier implements Verifier { - - protected static final String AUTOTEST_PY = "autotest.py"; - private static final String JYTHON_UP = "jython up and running"; - private static final String JYTHON = "jython"; - - private File _targetDir; - - public void setTargetDir(File targetDir) { - _targetDir = targetDir; - } - - public File getTargetDir() { - return _targetDir; - } - - public void verify() throws DriverException { - // create the test .py script - createTestScriptFile(); - - // start jython and capture the output - ChildProcess childProcess = new ChildProcess(getCommand()); - childProcess.setDebug(true); - ByteArrayOutputStream redirectedErr = new ByteArrayOutputStream(); - ByteArrayOutputStream redirectedOut = new ByteArrayOutputStream(); - int exitValue = 0; - PrintStream oldErr = System.err; - PrintStream oldOut = System.out; - try { - System.setErr(new PrintStream(redirectedErr)); - System.setOut(new PrintStream(redirectedOut)); - exitValue = childProcess.run(); - } finally { - System.setErr(oldErr); - System.setOut(oldOut); - } - - // verify the output - String output = null; - String error = null; - try { - redirectedErr.flush(); - redirectedOut.flush(); - String encoding = "US-ASCII"; - output = redirectedOut.toString(encoding); - error = redirectedErr.toString(encoding); - } catch (IOException ioe) { - throw new DriverException(ioe); - } - if (exitValue != 0) { - throw new DriverException("start of jython failed, output:\n" + output + "\nerror:\n" + error); - } - verifyError(error); - verifyOutput(output); - } - - /** - * will be overridden in subclass StandaloneVerifier - * - * @return the command array to start jython with - * @throws DriverException if there was a problem getting the target directory path - */ - protected String[] getCommand() throws DriverException { - String parentDirName = null; - try { - parentDirName = getTargetDir().getCanonicalPath() + File.separator; - } catch (IOException ioe) { - throw new DriverException(ioe); - } - String[] command = new String[2]; - if (Installation.isWindows()) { - command[0] = parentDirName + JYTHON + ".bat"; - } else { - command[0] = parentDirName + JYTHON; - } - command[1] = parentDirName + AUTOTEST_PY; - return command; - } - - private void verifyError(String error) throws DriverException { - StringTokenizer tokenizer = new StringTokenizer(error, "\n"); - while (tokenizer.hasMoreTokens()) { - String line = tokenizer.nextToken(); - if (!line.startsWith("*sys-package-mgr*")) { - throw new DriverException(error); - } - } - } - - private void verifyOutput(String output) throws DriverException { - boolean started = false; - StringTokenizer tokenizer = new StringTokenizer(output, "\n"); - while (tokenizer.hasMoreTokens()) { - String line = tokenizer.nextToken(); - if (!line.startsWith("[ChildProcess]")) { - if (line.startsWith(JYTHON_UP)) { - started = true; - } else { - throw new DriverException(output); - } - } - } - if (!started) { - throw new DriverException("start of jython failed:\n" + output); - } - } - - private String getTestScript() { - StringBuffer buf = new StringBuffer(); - buf.append("import sys\n"); - buf.append("print '" + JYTHON_UP + "'\n"); - return buf.toString(); - } - - private void createTestScriptFile() throws DriverException { - File file = new File(getTargetDir(), AUTOTEST_PY); - try { - FileWriter writer = new FileWriter(file); - writer.write(getTestScript()); - writer.flush(); - writer.close(); - } catch (IOException ioe) { - throw new DriverException(ioe); - } - } - -} +package org.python.util.install.driver; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.text.MessageFormat; +import java.util.StringTokenizer; + +import org.python.util.install.ChildProcess; +import org.python.util.install.FileHelper; +import org.python.util.install.Installation; +import org.python.util.install.JavaVersionTester; + +public class NormalVerifier implements Verifier { + + protected static final String AUTOTEST_PY = "autotest.py"; + + protected static final String JYTHON_TEST = "jython_test"; + + private static final String BIN = "bin"; + + private static final String BAT_EXTENSION = ".bat"; + + private static final String JYTHON_UP = "jython up and running!"; + + private static final String JYTHON = "jython"; + + private static final String TEMPLATE_SUFFIX = ".template"; + + private static final String VERIFYING = "verifying"; + + private File _targetDir; + + public void setTargetDir(File targetDir) { + _targetDir = targetDir; + } + + public File getTargetDir() { + return _targetDir; + } + + public void verify() throws DriverException { + createTestScriptFile(); // create the test .py script + // verify the most simple start of jython works + verifyStart(getSimpleCommand()); + if (doShellScriptTests()) { + // verify more complex versions of starting jython + verifyStart(getShellScriptTestCommand()); + } + } + + /** + * Will be overridden in subclass StandaloneVerifier + * + * @return the command array to start jython with + * @throws DriverException + * if there was a problem getting the target directory path + */ + protected String[] getSimpleCommand() throws DriverException { + String parentDirName = null; + try { + parentDirName = getTargetDir().getCanonicalPath() + File.separator; + } catch (IOException ioe) { + throw new DriverException(ioe); + } + String[] command = new String[2]; + if (Installation.isWindows()) { + command[0] = parentDirName + JYTHON + BAT_EXTENSION; + } else { + command[0] = parentDirName + JYTHON; + } + command[1] = parentDirName + AUTOTEST_PY; + return command; + } + + /** + * @return The command to test the shell script more deeply + * @throws DriverException + */ + protected final String[] getShellScriptTestCommand() throws DriverException { + // first we have to create the shell script + File testCommandDir = getShellScriptTestCommandDir(); + if (!testCommandDir.exists()) { + if (!testCommandDir.mkdirs()) { + throw new DriverException("unable to create directory " + + testCommandDir.getAbsolutePath()); + } + } + String commandName = JYTHON_TEST; + boolean isWindows = Installation.isWindows(); + if (isWindows) { + commandName = commandName.concat(BAT_EXTENSION); + } + File command = new File(testCommandDir, commandName); + try { + if (!command.exists()) { + command.createNewFile(); + } + FileHelper.write(command, getShellScriptTestContents()); + if (!isWindows) { + FileHelper.makeExecutable(command); + } + return new String[] {command.getCanonicalPath()}; + } catch (Exception e) { + throw new DriverException(e); + } + } + + /** + * @return The contents of the shell test script + * @throws DriverException + */ + protected final String getShellScriptTestContents() throws DriverException { + String contents = ""; + String templateName = JYTHON_TEST; + if (Installation.isWindows()) { + templateName = templateName.concat(BAT_EXTENSION); + } + templateName = templateName.concat(TEMPLATE_SUFFIX); + InputStream inputStream = FileHelper.getRelativeURLAsStream(getClass(), templateName); + if (inputStream != null) { + try { + String template = FileHelper.readAll(inputStream); + String targetDirPath = getTargetDir().getCanonicalPath(); + String upScriptPath = getSimpleCommand()[1]; + String javaHomeString = System.getProperty(JavaVersionTester.JAVA_HOME, ""); + contents = MessageFormat.format(template, + targetDirPath, + upScriptPath, + javaHomeString, + VERIFYING); + } catch (Exception e) { + throw new DriverException(e); + } + } + return contents; + } + + /** + * @return The directory where to create the shell script test command in. + * + * @throws DriverException + */ + protected final File getShellScriptTestCommandDir() throws DriverException { + String dirName; + try { + dirName = getTargetDir().getCanonicalPath().concat(File.separator).concat(BIN); + return new File(dirName); + } catch (IOException ioe) { + throw new DriverException(ioe); + } + } + + /** + * Internal method verifying a jython-starting command by capturing the ouptut + * + * @param command + * + * @throws DriverException + */ + private void verifyStart(String[] command) throws DriverException { + ChildProcess childProcess = new ChildProcess(command); + childProcess.setDebug(true); + ByteArrayOutputStream redirectedErr = new ByteArrayOutputStream(); + ByteArrayOutputStream redirectedOut = new ByteArrayOutputStream(); + int exitValue = 0; + PrintStream oldErr = System.err; + PrintStream oldOut = System.out; + try { + System.setErr(new PrintStream(redirectedErr)); + System.setOut(new PrintStream(redirectedOut)); + exitValue = childProcess.run(); + } finally { + System.setErr(oldErr); + System.setOut(oldOut); + } + // verify the output + String output = null; + String error = null; + try { + redirectedErr.flush(); + redirectedOut.flush(); + String encoding = "US-ASCII"; + output = redirectedOut.toString(encoding); + error = redirectedErr.toString(encoding); + } catch (IOException ioe) { + throw new DriverException(ioe); + } + if (exitValue != 0) { + throw new DriverException("start of jython failed, output:\n" + output + "\nerror:\n" + + error); + } + verifyError(error); + verifyOutput(output); + } + + /** + * Will be overridden in subclass StandaloneVerifier + * + * @return <code>true</code> if the jython start shell script should be verified (using + * different options) + */ + protected boolean doShellScriptTests() { + return true; + } + + private void verifyError(String error) throws DriverException { + StringTokenizer tokenizer = new StringTokenizer(error, "\n"); + while (tokenizer.hasMoreTokens()) { + String line = tokenizer.nextToken(); + if (line.startsWith("*sys-package-mgr*")) { + feedback(line); + } else { + throw new DriverException(error); + } + } + } + + private void verifyOutput(String output) throws DriverException { + boolean started = false; + StringTokenizer tokenizer = new StringTokenizer(output, "\n"); + while (tokenizer.hasMoreTokens()) { + String line = tokenizer.nextToken(); + if (line.startsWith("[ChildProcess]") || line.startsWith(VERIFYING)) { + feedback(line); + } else { + if (line.startsWith(JYTHON_UP)) { + started = true; + feedback(line); + } else { + throw new DriverException(output); + } + } + } + if (!started) { + throw new DriverException("start of jython failed:\n" + output); + } + } + + private String getTestScript() { + StringBuilder b = new StringBuilder(80); + b.append("import sys\n"); + b.append("print '"); + b.append(JYTHON_UP); + b.append("'\n"); + return b.toString(); + } + + private void createTestScriptFile() throws DriverException { + File file = new File(getTargetDir(), AUTOTEST_PY); + try { + FileHelper.write(file, getTestScript()); + } catch (IOException ioe) { + throw new DriverException(ioe); + } + } + + private void feedback(String line) { + System.out.println(line); + } +} Modified: trunk/installer/src/java/org/python/util/install/driver/StandaloneVerifier.java =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/StandaloneVerifier.java 2008-11-05 02:56:03 UTC (rev 5543) +++ trunk/installer/src/java/org/python/util/install/driver/StandaloneVerifier.java 2008-11-05 07:30:28 UTC (rev 5544) @@ -1,90 +1,89 @@ -package org.python.util.install.driver; - -import java.io.File; -import java.io.IOException; -import java.util.Enumeration; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -import org.python.util.install.JavaVersionTester; - -public class StandaloneVerifier extends NormalVerifier { - - public void verify() throws DriverException { - // make sure only JYTHON_JAR is in the target directory - if (getTargetDir().listFiles().length != 1) { - throw new DriverException("more than " + JYTHON_JAR + " installed"); - } - - // make sure JYTHON_JAR contains a MANIFEST and a /Lib directory - verifyJythonJar(); - - // do the jython startup verification from the superclass - super.verify(); - } - - /** - * overrides superclass method getting the command to start jython - */ - protected String[] getCommand() throws DriverException { - String parentDirName = null; - try { - parentDirName = getTargetDir().getCanonicalPath() + File.separator; - } catch (IOException ioe) { - throw new DriverException(ioe); - } - - String command[] = new String[4]; - command[0] = null; - String javaHomeString = System.getProperty(JavaVersionTester.JAVA_HOME, null); - if (javaHomeString != null) { - File javaHome = new File(javaHomeString); - if (javaHome.exists()) { - try { - command[0] = javaHome.getCanonicalPath() + File.separator + "bin" + File.separator + "java"; - } catch (IOException ioe) { - throw new DriverException(ioe); - } - } - } - if (command[0] == null) { - command[0] = "java"; - } - command[1] = "-jar"; - command[2] = parentDirName + JYTHON_JAR; - command[3] = parentDirName + AUTOTEST_PY; - return command; - } - - private void verifyJythonJar() throws DriverException { - File jythonJar = getTargetDir().listFiles()[0]; - JarFile jar = null; - try { - jar = new JarFile(jythonJar); - if (jar.getManifest() == null) { - throw new DriverException(JYTHON_JAR + " contains no MANIFEST"); - } - boolean hasLibDir = false; - Enumeration entries = jar.entries(); - while (!hasLibDir && entries.hasMoreElements()) { - JarEntry entry = (JarEntry) entries.nextElement(); - if (entry.getName().startsWith("Lib/")) { - hasLibDir = true; - } - } - if (!hasLibDir) { - throw new DriverException(JYTHON_JAR + " contains no /Lib directory"); - } - } catch (IOException e) { - throw new DriverException(e); - } finally { - if (jar != null) { - try { - jar.close(); - } catch (IOException ioe) { - } - } - } - } - -} +package org.python.util.install.driver; + +import java.io.File; +import java.io.IOException; +import java.util.Enumeration; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import org.python.util.install.JavaVersionTester; + +public class StandaloneVerifier extends NormalVerifier { + + public void verify() throws DriverException { + // make sure only JYTHON_JAR is in the target directory + if (getTargetDir().listFiles().length > 1) { + throw new DriverException("more than " + JYTHON_JAR + " installed"); + } + // make sure JYTHON_JAR contains a MANIFEST and a /Lib directory + verifyJythonJar(); + // do the jython startup verification from the superclass + super.verify(); + } + + @Override + protected String[] getSimpleCommand() throws DriverException { + String parentDirName = null; + try { + parentDirName = getTargetDir().getCanonicalPath() + File.separator; + } catch (IOException ioe) { + throw new DriverException(ioe); + } + String command[] = new String[4]; + command[0] = null; + String javaHomeString = System.getProperty(JavaVersionTester.JAVA_HOME, null); + if (javaHomeString != null) { + File javaHome = new File(javaHomeString); + if (javaHome.exists()) { + try { + command[0] = javaHome.getCanonicalPath() + File.separator + "bin" + + File.separator + "java"; + } catch (IOException ioe) { + throw new DriverException(ioe); + } + } + } + if (command[0] == null) { + command[0] = "java"; + } + command[1] = "-jar"; + command[2] = parentDirName + JYTHON_JAR; + command[3] = parentDirName + AUTOTEST_PY; + return command; + } + + @Override + protected boolean doShellScriptTests() { + return false; + } + + private void verifyJythonJar() throws DriverException { + File jythonJar = getTargetDir().listFiles()[0]; + JarFile jar = null; + try { + jar = new JarFile(jythonJar); + if (jar.getManifest() == null) { + throw new DriverException(JYTHON_JAR + " contains no MANIFEST"); + } + boolean hasLibDir = false; + Enumeration<JarEntry> entries = jar.entries(); + while (!hasLibDir && entries.hasMoreElements()) { + JarEntry entry = (JarEntry)entries.nextElement(); + if (entry.getName().startsWith("Lib/")) { + hasLibDir = true; + } + } + if (!hasLibDir) { + throw new DriverException(JYTHON_JAR + " contains no /Lib directory"); + } + } catch (IOException e) { + throw new DriverException(e); + } finally { + if (jar != null) { + try { + jar.close(); + } catch (IOException ioe) {} + } + } + } +} Added: trunk/installer/src/java/org/python/util/install/driver/jython_test.bat.template =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/jython_test.bat.template (rev 0) +++ trunk/installer/src/java/org/python/util/install/driver/jython_test.bat.template 2008-11-05 07:30:28 UTC (rev 5544) @@ -0,0 +1,43 @@ +@echo off + +rem 3 variables to be set from the caller, UNquoted: +set _INSTALL_DIR={0} +set _SCRIPT={1} +set _JAVA_HOME={2} + +rem save old home env vars: +set _OLD_JAVA_HOME=%JAVA_HOME% +set _OLD_JYTHON_HOME=%JYTHON_HOME% + +cd /d "%_INSTALL_DIR%\bin" + +echo {3}: only JAVA_HOME, quoted: +set JAVA_HOME="%_JAVA_HOME%" +set JYTHON_HOME= +call jython.bat "%_SCRIPT%" +set E=%ERRORLEVEL% + +echo {3}: only JAVA_HOME, UNquoted: +set JAVA_HOME=%_JAVA_HOME% +set JYTHON_HOME= +call jython.bat "%_SCRIPT%" +set E=%ERRORLEVEL% + +echo {3}: both homes quoted: +set JAVA_HOME="%_JAVA_HOME%" +set JYTHON_HOME="%_INSTALL_DIR%" +call jython.bat "%_SCRIPT%" +set E=%ERRORLEVEL% + +rem this exposes the last part of issue 1125 +rem echo "{3}: both homes UNquoted:" +rem set JAVA_HOME=%_JAVA_HOME% +rem set JYTHON_HOME=%_INSTALL_DIR% +rem call jython.bat "%_SCRIPT%" +rem set E=%ERRORLEVEL% + +rem cleanup: +set JAVA_HOME=%_OLD_JAVA_HOME% +set JYTHON_HOME=%_OLD_JYTHON_HOME% +cd /d "%~dp0%" +exit /b %E% Added: trunk/installer/src/java/org/python/util/install/driver/jython_test.template =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/jython_test.template (rev 0) +++ trunk/installer/src/java/org/python/util/install/driver/jython_test.template 2008-11-05 07:30:28 UTC (rev 5544) @@ -0,0 +1,30 @@ +# 3 variables to be set from the caller (unquoted) -> quoted in here: +_INSTALL_DIR="{0}" +_SCRIPT="{1}" +_JAVA_HOME="{2}" + +# save old home env vars: +_OLD_JAVA_HOME=$JAVA_HOME +_OLD_JYTHON_HOME=$JYTHON_HOME + +cd "$_INSTALL_DIR/bin" + +# auto detection of JYTHON_HOME does not yet work +#echo "{3}: only JAVA_HOME:" +#export JAVA_HOME="$_JAVA_HOME" +#export JYTHON_HOME= +#./jython "$_SCRIPT" + +echo "{3}: only JYTHON_HOME:" +export JAVA_HOME= +export JYTHON_HOME="$_INSTALL_DIR" +./jython "$_SCRIPT" + +echo "{3}: both homes:" +export JAVA_HOME="$_JAVA_HOME" +export JYTHON_HOME="$_INSTALL_DIR" +./jython "$_SCRIPT" + +# cleanup: +export JAVA_HOME=$_OLD_JAVA_HOME +export JYTHON_HOME=$_OLD_JYTHON_HOME Added: trunk/installer/test/java/org/python/util/install/FileHelperTest.java =================================================================== --- trunk/installer/test/java/org/python/util/install/FileHelperTest.java (rev 0) +++ trunk/installer/test/java/org/python/util/install/FileHelperTest.java 2008-11-05 07:30:28 UTC (rev 5544) @@ -0,0 +1,271 @@ +package org.python.util.install; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import junit.framework.TestCase; +import junit.runner.TestSuiteLoader; + +import org.python.util.install.driver.Autotest; + +public class FileHelperTest extends TestCase { + + private static final String JYTHON_TEST_TEMPLATE = "jython_test.template"; + + private static final String LOGO_GIF = "logo.gif"; + + private static final String JYTHON_SMALL_C_PNG = "jython_small_c.png"; + + public void testCreateTempDirectory_WasFile() throws IOException { + File file = File.createTempFile("some_prefix", ""); + assertTrue(file.exists()); + assertTrue(file.isFile()); + assertTrue(FileHelper.createTempDirectory(file)); + assertTrue(file.exists()); + assertTrue(file.isDirectory()); + } + + public void testCreateTempDirectory_AlreadyPresent() throws IOException { + File dir = new File(System.getProperty("user.dir")); + assertTrue(dir.exists()); + assertTrue(dir.isDirectory()); + assertTrue(FileHelper.createTempDirectory(dir)); + assertTrue(dir.exists()); + assertTrue(dir.isDirectory()); + } + + public void testCreateTempDirectory() throws IOException { + File dir = new File(System.getProperty("user.dir")); + assertTrue(dir.exists()); + assertTrue(dir.isDirectory()); + File tmpDir = new File(dir, "tmp"); + assertFalse(tmpDir.exists()); + try { + assertTrue(FileHelper.createTempDirectory(tmpDir)); + assertTrue(tmpDir.exists()); + assertTrue(dir.isDirectory()); + } finally { + if (tmpDir.exists()) { + assertTrue(tmpDir.delete()); + } + } + } + + public void testCreateTempDirectory_Failure() throws Exception { + File dir = new File(System.getProperty("user.dir")); + assertTrue(dir.exists()); + assertTrue(dir.isDirectory()); + File tmpFile = new File(dir, "tmpFailure"); + assertFalse(tmpFile.exists()); + try { + tmpFile.createNewFile(); + assertTrue(tmpFile.exists()); + assertTrue(tmpFile.isFile()); + Lock lock = null; + try { + lock = new Lock(tmpFile); + boolean created = FileHelper.createTempDirectory(tmpFile); + if (Installation.isWindows()) { + // locking currently only effective on windows + assertFalse(created); + } else { + // change if there is a locking mechanism + assertTrue(created); + } + } finally { + if (lock != null) { + lock.release(); + } + } + } finally { + if (tmpFile.exists()) { + assertTrue(tmpFile.delete()); + } + } + } + + public void testRmdir() throws IOException { + File dir = new File(System.getProperty("java.io.tmpdir"), "StartScriptGeneratorTest"); + if (!dir.exists()) { + assertTrue(dir.mkdirs()); + } + File bin = new File(dir, "bin"); + if (!bin.exists()) { + assertTrue(bin.mkdirs()); + } + File jython = new File(bin, "jython"); + if (!jython.exists()) { + assertTrue(jython.createNewFile()); + } + File jython_bat = new File(bin, "jython.bat"); + if (!jython_bat.exists()) { + assertTrue(jython_bat.createNewFile()); + } + assertTrue(FileHelper.rmdir(dir)); + } + + public void testRmdir_Failure() throws Exception { + File dir = new File(System.getProperty("java.io.tmpdir"), "StartScriptGeneratorTest"); + if (!dir.exists()) { + assertTrue(dir.mkdirs()); + } + File bin = new File(dir, "bin"); + if (!bin.exists()) { + assertTrue(bin.mkdirs()); + } + File jython = new File(bin, "jython"); + if (!jython.exists()) { + assertTrue(jython.createNewFile()); + } + File jython_bat = new File(bin, "jython.bat"); + if (!jython_bat.exists()) { + assertTrue(jython_bat.createNewFile()); + } + Lock lock = null; + try { + lock = new Lock(jython_bat); + boolean removed = FileHelper.rmdir(dir); + if (Installation.isWindows()) { + // locking currently only effective on windows + assertFalse(removed); + } else { + // change if there is a locking mechanism + assertTrue(removed); + } + } finally { + if (lock != null) { + lock.release(); + } + assertTrue(FileHelper.rmdir(dir)); + } + } + + public void testReadAll() throws Exception { + File file = File.createTempFile("testReadAll", ""); + final String contents = new String("line1 \n line2 \n"); + FileHelper.write(file, contents); + String readContents = FileHelper.readAll(file); + assertEquals(contents, readContents); + } + + public void testReadAll_InputStream() throws Exception { + URL url = FileHelper.getRelativeURL(Autotest.class, JYTHON_TEST_TEMPLATE); + assertNotNull(url); + URI uri = new URI(url.toString()); + File file = new File(uri); + assertNotNull(file); + assertTrue(file.exists()); + String expectedContents = FileHelper.readAll(file); + InputStream is = FileHelper.getRelativeURLAsStream(Autotest.class, JYTHON_TEST_TEMPLATE); + assertNotNull(is); + String contents = FileHelper.readAll(is); + assertEquals(expectedContents, contents); + // now from a .jar + is = FileHelper.getRelativeURLAsStream(TestSuiteLoader.class, LOGO_GIF); + assertNotNull(is); + contents = FileHelper.readAll(is); + assertNotNull(contents); + assertEquals(964, contents.length()); + assertTrue(contents.startsWith("GIF89a&")); + } + + public void testReadAll_NonExisting() { + String readContents = null; + try { + readContents = FileHelper.readAll(new File("_non_existing")); + fail("FileNotFoundException expected"); + } catch (IOException e) { + assertNull(readContents); + } + } + + public void testGetRelativeURL() { + URL url = FileHelper.getRelativeURL(Installation.class, JYTHON_SMALL_C_PNG); + assertNotNull(url); + assertTrue(url.getPath().endsWith("org/python/util/install/".concat(JYTHON_SMALL_C_PNG))); + // now from a .jar + ... [truncated message content] |