public int runDirectorToInstall( String message, File installFolder, String sourceRepo, String iuToInstall) { String[] command = new String[] { // "-application", "org.eclipse.equinox.p2.director", // "-repository", sourceRepo, "-installIU", iuToInstall, // "-destination", installFolder.getAbsolutePath(), // "-bundlepool", installFolder.getAbsolutePath(), // "-roaming", "-profile", "PlatformProfile", "-profileProperties", "org.eclipse.update.install.features=true", // "-p2.os", Platform.getOS(), "-p2.ws", Platform.getWS(), "-p2.arch", Platform.getOSArch() }; return runEclipse(message, command); }
protected int runEclipse(String message, File location, String[] args, File extensions) { File root = new File(Activator.getBundleContext().getProperty("java.home")); root = new File(root, "bin"); File exe = new File(root, "javaw.exe"); if (!exe.exists()) exe = new File(root, "java"); assertTrue("Java executable not found in: " + exe.getAbsolutePath(), exe.exists()); List<String> command = new ArrayList<String>(); Collections.addAll( command, new String[] { (new File(location == null ? output : location, getExeFolder() + "eclipse")) .getAbsolutePath(), "--launcher.suppressErrors", "-nosplash", "-vm", exe.getAbsolutePath() }); Collections.addAll(command, args); Collections.addAll(command, new String[] {"-vmArgs", "-Dosgi.checkConfiguration=true"}); // command-line if you want to run and allow a remote debugger to connect if (debug) Collections.addAll( command, new String[] { "-Xdebug", "-Xnoagent", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787" }); int result = run(message, command.toArray(new String[command.size()])); // 13 means that we wrote something out in the log file. // so try and parse it and fail via that message if we can. if (result == 13) parseExitdata(message); return result; }
/* * Remove the given filename from the given folder. */ public boolean remove(String message, String target, String filename) { if (!(target.startsWith("dropins") || target.startsWith("plugins") || target.startsWith("features"))) fail("Target folder for resource deletion should be either dropins, plugins or features."); File folder = new File(output, getRootFolder() + target); File targetFile = new File(folder, filename); if (!targetFile.exists()) return false; return delete(targetFile); }
/* * Add the given bundle to the given folder (do a copy). * The folder can be one of dropins, plugins or features. * If the file handle points to a directory, then do a deep copy. */ public void add(String message, String target, File file) { if (!(target.startsWith("dropins") || target.startsWith("plugins") || target.startsWith("features"))) fail( "Destination folder for resource copying should be either dropins, plugins or features."); File destinationParent = new File(output, getRootFolder() + target); destinationParent.mkdirs(); copy(message, file, new File(destinationParent, file.getName())); }
/* * Save the given configuration to disk. */ public void save(String message, Configuration configuration) { File configLocation = new File(output, getRootFolder() + "configuration/org.eclipse.update/platform.xml"); File installLocation = new File(output, getRootFolder()); try { configuration.save(configLocation, installLocation.toURL()); } catch (ProvisionException e) { fail(message, e); } catch (MalformedURLException e) { fail(message, e); } }
/* * Iterate over the sites in the given configuration and remove the one which * has a url matching the given location. */ public boolean removeSite(Configuration configuration, String location) throws IOException, URISyntaxException { File left = new File(new URI(location)).getCanonicalFile(); List sites = configuration.getSites(); for (Iterator iter = sites.iterator(); iter.hasNext(); ) { Site tempSite = (Site) iter.next(); String siteURL = tempSite.getUrl(); File right = new File(new URI(siteURL)).getCanonicalFile(); if (left.equals(right)) { return configuration.removeSite(tempSite); } } return false; }
/* * Set up the platform binary download and get it ready to run the tests. * This method is not intended to be called by clients, it will be called * automatically when the clients use a ReconcilerTestSuite. If the executable isn't * found on the file-system after the call, then we fail. */ public void initialize() throws Exception { initialized = false; File file = getPlatformZip(); output = getUniqueFolder(); toRemove.add(output); // for now we will exec to un-tar archives to keep the executable bits if (file.getName().toLowerCase().endsWith(".zip")) { try { FileUtils.unzipFile(file, output); } catch (IOException e) { fail("0.99", e); } } else { untar("1.0", file); } File exe = new File(output, getExeFolder() + "eclipse.exe"); if (!exe.exists()) { exe = new File(output, getExeFolder() + "eclipse"); if (!exe.exists()) fail( "Executable file: " + exe.getAbsolutePath() + "(or .exe) not found after extracting: " + file.getAbsolutePath() + " to: " + output); } initialized = true; }
/* * Copy the bundle with the given id to the specified location. (location * is parent directory) */ public void copyBundle(String bundlename, File source, File destination) throws IOException { if (destination == null) destination = output; destination = new File(destination, "eclipse/plugins"); if (source == null) { Bundle bundle = TestActivator.getBundle(bundlename); if (bundle == null) { throw new IOException("Could not find: " + bundlename); } String location = bundle.getLocation(); if (location.startsWith("reference:")) location = location.substring("reference:".length()); source = new File(FileLocator.toFileURL(new URL(location)).getFile()); } destination = new File(destination, source.getName()); if (destination.exists()) return; FileUtils.copy(source, destination, new File(""), false); // if the target of the copy doesn't exist, then signal an error assertTrue("Unable to copy " + source + " to " + destination, destination.exists()); }
/* * Untar the given file in the output directory. */ private void untar(String message, File file) { String name = file.getName(); File gzFile = new File(output, name); output.mkdirs(); run(message, new String[] {"cp", file.getAbsolutePath(), gzFile.getAbsolutePath()}); run(message, new String[] {"tar", "-zpxf", gzFile.getAbsolutePath()}); gzFile.delete(); }
/* * Create a link file in the links folder. Point it to the given extension location. */ public void createLinkFile(String message, String filename, String extensionLocation) { File file = new File(output, getRootFolder() + "links/" + filename + ".link"); file.getParentFile().mkdirs(); Properties properties = new Properties(); properties.put("path", extensionLocation); OutputStream stream = null; try { stream = new BufferedOutputStream(new FileOutputStream(file)); properties.store(stream, null); } catch (IOException e) { fail(message, e); } finally { try { if (stream != null) stream.close(); } catch (IOException e) { // ignore } } }
public Configuration loadConfiguration(File configLocation, File installLocation) { try { return Configuration.load(configLocation, installLocation.toURL()); } catch (ProvisionException e) { fail("Error while reading configuration from " + configLocation); } catch (MalformedURLException e) { fail("Unable to convert install location to URL " + installLocation); } assertTrue("Unable to read configuration from " + configLocation, false); // avoid compiler error return null; }
private static void loadPlatformZipPropertiesFromFile() { File installLocation = getInstallLocation(); if (installLocation != null) { // parent will be "eclipse" and the parent's parent will be "eclipse-testing" File parent = installLocation.getParentFile(); if (parent != null) { parent = parent.getParentFile(); if (parent != null) { File propertiesFile = new File(parent, "equinoxp2tests.properties"); if (!propertiesFile.exists()) return; archiveAndRepositoryProperties = new Properties(); try { InputStream is = null; try { is = new BufferedInputStream(new FileInputStream(propertiesFile)); archiveAndRepositoryProperties.load(is); } finally { is.close(); } } catch (IOException e) { return; } } } } }
private void deleteVerifierBundle(File destination) { if (destination == null) destination = output; destination = new File(destination, getRootFolder() + "plugins"); File[] verifierBundle = destination.listFiles( new FilenameFilter() { public boolean accept(File dir, String name) { if (name.startsWith(VERIFIER_BUNDLE_ID)) return true; return false; } }); if (verifierBundle != null && verifierBundle.length > 0) verifierBundle[0].delete(); }
// Fully read the file pointed to by the given path private String read(String path) { File file = new File(path); if (!file.exists()) return null; StringBuffer buffer = new StringBuffer(); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); for (String line = reader.readLine(); line != null; line = reader.readLine()) { buffer.append(line); buffer.append('\n'); } } catch (IOException e) { // TODO } finally { if (reader != null) try { reader.close(); } catch (IOException e) { // ignore } } return buffer.toString(); }
protected static int run(String message, String[] commandArray, File outputFile) { PrintStream out = System.out; PrintStream err = System.err; PrintStream fileStream = null; try { outputFile.getParentFile().mkdirs(); fileStream = new PrintStream(new FileOutputStream(outputFile)); System.setErr(fileStream); System.setOut(fileStream); return run(message, commandArray); } catch (FileNotFoundException e) { return -1; } finally { System.setOut(out); System.setErr(err); if (fileStream != null) fileStream.close(); } }
/* * Return a file handle pointing to the platform binary zip. Method never returns null because * it will fail an assert before that. */ private File getPlatformZip() { String property = null; File file = null; if (propertyToPlatformArchive != null) { property = getValueFor(propertyToPlatformArchive); String message = "Need to set the " + "\"" + propertyToPlatformArchive + "\" system property with a valid path to the platform binary drop or copy the archive to be a sibling of the install folder."; if (property == null) { fail(message); } file = new File(property); assertNotNull(message, file); assertTrue(message, file.exists()); assertTrue("File is zero length: " + file.getAbsolutePath(), file.length() > 0); return file; } property = getValueFor("org.eclipse.equinox.p2.reconciler.tests.platform.archive"); if (property == null) { // the releng test framework copies the zip so let's look for it... // it will be a sibling of the eclipse/ folder that we are running File installLocation = getInstallLocation(); if (Platform.getWS().equals(Platform.WS_COCOA)) installLocation = installLocation.getParentFile().getParentFile(); if (installLocation != null) { // parent will be "eclipse" and the parent's parent will be "eclipse-testing" File parent = installLocation.getParentFile(); if (parent != null) { parent = parent.getParentFile(); if (parent != null) { File[] children = parent.listFiles( new FileFilter() { public boolean accept(File pathname) { String name = pathname.getName(); return name.startsWith("eclipse-platform-"); } }); if (children != null && children.length == 1) file = children[0]; } } } } else { file = new File(property); } StringBuffer detailedMessage = new StringBuffer(600); detailedMessage .append(" propertyToPlatformArchive was ") .append(propertyToPlatformArchive == null ? " not set " : propertyToPlatformArchive) .append('\n'); detailedMessage .append(" org.eclipse.equinox.p2.reconciler.tests.platform.archive was ") .append(property == null ? " not set " : property) .append('\n'); detailedMessage.append(" install location is ").append(getInstallLocation()).append('\n'); String message = "Need to set the \"org.eclipse.equinox.p2.reconciler.tests.platform.archive\" system property with a valid path to the platform binary drop or copy the archive to be a sibling of the install folder."; assertNotNull(message + "\n" + detailedMessage, file); assertTrue(message, file.exists()); assertTrue("File is zero length: " + file.getAbsolutePath(), file.length() > 0); return file; }
/* * Delete the link file with the given name from the links folder. */ public void removeLinkFile(String message, String filename) { File file = new File(output, getRootFolder() + "links/" + filename + ".link"); file.delete(); }