private IWARProduct createPlainProducttWithLibraries() throws IOException { IWARProduct product = createPlainProduct(); File testJar = File.createTempFile("test", ".jar"); Path testPath = new Path(testJar.getAbsolutePath()); product.addLibrary(testPath, false); File bridgeJar = File.createTempFile(SERVLETBRIDGE, ".jar"); Path servletBridgePath = new Path(bridgeJar.getAbsolutePath()); product.addLibrary(servletBridgePath, false); return product; }
public void testLoadWindowsFile() throws Exception { setUpProject(); WARProductModel model = new WARProductModel(); String separator = File.separator; String fileName = separator + "testWin.warproduct"; ClassLoader classLoader = getClass().getClassLoader(); model.load(classLoader.getResourceAsStream(fileName), false); IWARProduct product = (IWARProduct) model.getProduct(); IPath webXml = product.getWebXml(); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IPath absolutWebXmlPath = wsRoot.getLocation().append(webXml); File file = new File(absolutWebXmlPath.toOSString()); assertTrue(file.exists()); }
private void addBundleToProduct( final WARProductModelFactory factory, final String id, final IWARProduct product) { IProductPlugin bundle = factory.createPlugin(); bundle.setId(id); bundle.setVersion("0.0.0"); product.addPlugins(new IProductPlugin[] {bundle}); }
public void testContainsServletBridgeLibrary() throws Exception { IWARProduct product = createBasicProduct(); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = wsRoot.getProject("warProduct"); if (!project.exists()) { project.create(null); project.open(null); } IFile jar = project.getFile(SERVLETBRIDGE + ".jar"); if (!jar.exists()) { File bridge = File.createTempFile(SERVLETBRIDGE, ".jar"); FileInputStream stream = new FileInputStream(bridge); jar.create(stream, true, null); } product.addLibrary(jar.getFullPath(), false); Validator validator = new Validator(product); Validation validation = validator.validate(); assertTrue(validation.isValid()); }
public void testLibrariesDoesntExist() { IWARProduct product = createBasicProduct(); String projectPath = File.separator + "test"; Path path = new Path(projectPath + File.separator + "test.jar"); product.addLibrary(path, false); Path servletBridgePath = new Path(projectPath + File.separator + SERVLETBRIDGE_JAR); product.addLibrary(servletBridgePath, false); Validator validator = new Validator(product); Validation validation = validator.validate(); assertFalse(validation.isValid()); ValidationError[] errors = validation.getErrors(); boolean testJarIsMissing = false; for (int i = 0; i < errors.length; i++) { ValidationError error = errors[i]; String message = error.getMessage(); if (error.getType() == ValidationError.LIBRARY_DOESNT_EXIST && message.indexOf("test.jar") != -1) { testJarIsMissing = true; } } assertTrue(testJarIsMissing); }
private void checkForBannedBundle(final String id) throws Exception { IWARProduct product = createBasicProductWithLibraries(); IProductPlugin plugin = new ProductPlugin(product.getModel()); plugin.setId(id); IProductPlugin[] plugins = new IProductPlugin[] {plugin}; product.addPlugins(plugins); Validator validator = new Validator(product); Validation validation = validator.validate(); assertFalse(validation.isValid()); ValidationError[] errors = validation.getErrors(); boolean foundBannedBundle = false; for (int i = 0; i < errors.length && !foundBannedBundle; i++) { ValidationError error = errors[i]; if (error.getType() == ValidationError.BUNDLE_BANNED) { IProductPlugin bannedPlugin = (IProductPlugin) error.getCausingObject(); String message = error.getMessage(); if (bannedPlugin.getId().equals(id) && message.indexOf(id) != -1) { foundBannedBundle = true; } } } assertTrue(foundBannedBundle); }
private IWARProduct createBasicProductWithLibraries() throws Exception { IWARProduct product = createBasicProduct(); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = wsRoot.getProject("warProduct"); if (!project.exists()) { project.create(null); project.open(null); } IFile jar = project.getFile("test.jar"); if (!jar.exists()) { File testJar = File.createTempFile("test", ".jar"); FileInputStream stream = new FileInputStream(testJar); jar.create(stream, true, null); } product.addLibrary(jar.getFullPath(), false); IFile bridge = project.getFile(SERVLETBRIDGE + ".jar"); if (!bridge.exists()) { File bridgeJar = File.createTempFile(SERVLETBRIDGE, ".jar"); FileInputStream stream = new FileInputStream(bridgeJar); bridge.create(stream, true, null); } product.addLibrary(bridge.getFullPath(), false); return product; }
public void testLoad() throws CoreException { WARProductModel model = new WARProductModel(); String separator = "/"; ClassLoader classLoader = getClass().getClassLoader(); String fileName = separator + "test.warproduct"; model.load(classLoader.getResourceAsStream(fileName), false); IWARProduct product = (IWARProduct) model.getProduct(); String webXmlPath = product.getWebXml().toString(); assertEquals( separator + "test.rap" + separator + "WEB-INF" + separator + "web.xml", webXmlPath); String launchIniPath = product.getLaunchIni().toString(); assertEquals( separator + "test.rap" + separator + "WEB-INF" + separator + "eclipse" + separator + "launch.ini", launchIniPath); String libJarPath = product.getLibraries()[0].toString(); assertEquals(separator + "test.rap" + separator + "lib.jar", libJarPath); }
private BundleDescription[] getPluginModels() { ArrayList list = new ArrayList(); State state = TargetPlatformHelper.getState(); IProductPlugin[] plugins = product.getPlugins(); for (int i = 0; i < plugins.length; i++) { BundleDescription bundle = null; String v = plugins[i].getVersion(); if (v != null && v.length() > 0) { bundle = state.getBundle(plugins[i].getId(), Version.parseVersion(v)); } // if there's no version, just grab a bundle like before if (bundle == null) { bundle = state.getBundle(plugins[i].getId(), null); } if (bundle != null) { list.add(bundle); } } Object[] bundleArray = list.toArray(new BundleDescription[list.size()]); return (BundleDescription[]) bundleArray; }