public Object[] getElements(Object element) { Set<String> possibleValues = new HashSet<String>(); if (element instanceof File) { File file = (File) element; if (file.exists()) { try (JarFile jar = new JarFile(file)) { Enumeration<JarEntry> enu = jar.entries(); while (enu.hasMoreElements()) { JarEntry entry = enu.nextElement(); String name = entry.getName(); if ((name.startsWith("META-INF/resources/") && (name.endsWith(".jsp") || name.endsWith(".jspf"))) || name.equals("portlet.properties")) { possibleValues.add(name); } } } catch (IOException e) { } } } for (OverrideFilePath file : files) { String currentFile = file.getValue().content(); possibleValues.remove(currentFile); } return possibleValues.toArray(); }
@Override protected Object run(Presentation context) { final NewModuleFragmentOp op = context.part().getModelElement().nearest(NewModuleFragmentOp.class); final ElementList<OverrideFilePath> currentFiles = op.getOverrideFiles(); final String projectName = op.getProjectName().content(); final OSGiBundleFileSelectionDialog dialog = new OSGiBundleFileSelectionDialog(null, currentFiles, projectName); final String runtimeName = op.getLiferayRuntimeName().content(); final IRuntime runtime = ServerUtil.getRuntime(runtimeName); final IPath temp = GradleCore.getDefault().getStateLocation(); dialog.setTitle("Add files from OSGi bundle to override"); final PortalBundle portalBundle = LiferayServerCore.newPortalBundle(runtime.getLocation()); String currentOSGiBundle = op.getHostOsgiBundle().content(); if (!currentOSGiBundle.endsWith("jar")) { currentOSGiBundle = currentOSGiBundle + ".jar"; } ServerUtil.getModuleFileFrom70Server(runtime, currentOSGiBundle, temp); if (portalBundle != null) { try { File module = portalBundle.getOSGiBundlesDir().append("modules").append(currentOSGiBundle).toFile(); if (!module.exists()) { module = GradleCore.getDefault().getStateLocation().append(currentOSGiBundle).toFile(); } dialog.setInput(module); } catch (Exception e) { } } if (dialog.open() == Window.OK) { Object[] selected = dialog.getResult(); for (int i = 0; i < selected.length; i++) { OverrideFilePath file = op.getOverrideFiles().insert(); file.setValue(selected[i].toString()); } } return Status.createOkStatus(); }