/** * Convenience method to delete the given file and any content (if the file is a * directory). Equivalent to calling {@link #deleteContent(File, IProgressMonitor)} * with <code>null</code> as the monitor. This operation cannot be undone. * * @param fileToDelete the file to delete */ public static void deleteContent(File fileToDelete) { deleteContent(fileToDelete, null); }
public static org.eclipse.jface.text.Document getTextDocument(File bundleLocation, String path) { ZipFile jarFile = null; InputStream stream = null; try { String extension = new Path(bundleLocation.getName()).getFileExtension(); if ("jar".equals(extension) && bundleLocation.isFile()) { //$NON-NLS-1$ jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ); ZipEntry manifestEntry = jarFile.getEntry(path); if (manifestEntry != null) { stream = jarFile.getInputStream(manifestEntry); } } else { File file = new File(bundleLocation, path); if (file.exists()) stream = new FileInputStream(file); } return getTextDocument(stream); } catch (IOException e) { } finally { try { if (jarFile != null) jarFile.close(); } catch (IOException e) { } } return null; }
@Override protected void setAdditionalAttributes(Element plugin, BundleDescription bundle) { plugin.setAttribute("unpack", Boolean.toString(CoreUtility.guessUnpack(bundle))); //$NON-NLS-1$ } }
dir.mkdirs(); plist = new File(dir, "Info.plist"); //$NON-NLS-1$ CoreUtility.readFile(in, plist); scriptFile = createScriptFile("macbuild.xml"); //$NON-NLS-1$ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); } catch (IOException e) { CoreUtility.deleteContent(new File(location, "Eclipse.app")); //$NON-NLS-1$ if (scriptFile != null && scriptFile.exists()) scriptFile.delete();
@Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { int numUnits = fWebLocation == null ? 3 : 4; monitor.beginTask(PDEUIMessages.NewSiteWizard_creatingProject, numUnits); CoreUtility.createProject(fProject, fPath, monitor); fProject.open(monitor); CoreUtility.addNatureToProject(fProject, PDE.SITE_NATURE, monitor); monitor.worked(1); if (fWebLocation != null) { CoreUtility.createFolder(fProject.getFolder(fWebLocation)); createXSLFile(); createCSSFile(); createHTMLFile(); monitor.worked(1); } monitor.subTask(PDEUIMessages.NewSiteWizard_creatingManifest); IFile file = createSiteManifest(); monitor.worked(1); openFile(file); monitor.worked(1); }
public String getJavadocLocation(IPluginModelBase model) { File file = new File(model.getInstallLocation()); if (file.isDirectory()) { File doc = new File(file, "doc"); //$NON-NLS-1$ if (new File(doc, "package-list").exists()) //$NON-NLS-1$ return doc.getAbsolutePath(); } else if (CoreUtility.jarContainsResource(file, "doc/package-list", false)) { //$NON-NLS-1$ return file.getAbsolutePath() + "!/doc"; //$NON-NLS-1$ } return getEntry(model); }
private void checkPropertiesFile(IFile file) { if (!file.exists()) { String propertiesFileComment = ExternalizeStringsOperation.getPropertiesFileComment(file); try (ByteArrayInputStream pStream = new ByteArrayInputStream(propertiesFileComment.getBytes())) { IContainer container = file.getParent(); if (!container.exists()) // project will exists, therefore we can assume if !IContainer.exist(), the object is an IFolder CoreUtility.createFolder((IFolder) container); file.create(pStream, true, new NullProgressMonitor()); } catch (CoreException | IOException e1) { } } } }
private String getProgramArguments(String os) { IArgumentsInfo info = fProduct.getLauncherArguments(); return info != null ? CoreUtility.normalize(info.getCompleteProgramArguments(os)) : "";//$NON-NLS-1$ }
@Override public void configure(IProject project, Set<IPath> ignoredDirectories, IProgressMonitor monitor) { if (!PDE.hasFeatureNature(project)) { try { CoreUtility.addNatureToProject(project, PDE.FEATURE_NATURE, monitor); } catch (CoreException ex) { PDEPlugin.log(ex); } } }
throw new IOException(); CoreUtility.readFile(in, fTargetFile); return fTargetFile; } finally {
private void ensureProductFilesExist(IPath productArea) { File productDir = productArea.toFile(); File marker = new File(productDir, ".eclipseproduct"); //$NON-NLS-1$ IPath eclipsePath = new Path(TargetPlatform.getLocation()); if (!marker.exists()) CoreUtility.copyFile(eclipsePath, ".eclipseproduct", marker); //$NON-NLS-1$ File configDir = new File(productDir, "configuration"); //$NON-NLS-1$ if (!configDir.exists()) configDir.mkdirs(); File ini = new File(configDir, "config.ini"); //$NON-NLS-1$ if (!ini.exists()) CoreUtility.copyFile(eclipsePath.append("configuration"), "config.ini", ini); //$NON-NLS-1$ //$NON-NLS-2$ }
dir.mkdirs(); plist = new File(dir, "Info.plist"); //$NON-NLS-1$ CoreUtility.readFile(in, plist); scriptFile = createScriptFile("macbuild.xml"); //$NON-NLS-1$ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); } catch (IOException e) { CoreUtility.deleteContent(new File(location, "Eclipse.app")); //$NON-NLS-1$ if (scriptFile != null && scriptFile.exists()) scriptFile.delete();
private IProject createProject() throws CoreException { IProject project = fProjectProvider.getProject(); if (!project.exists()) { CoreUtility.createProject(project, fProjectProvider.getLocationPath(), null); project.open(null); } if (!project.hasNature(PDE.PLUGIN_NATURE)) CoreUtility.addNatureToProject(project, PDE.PLUGIN_NATURE, null); if (!fData.isSimple() && !project.hasNature(JavaCore.NATURE_ID)) CoreUtility.addNatureToProject(project, JavaCore.NATURE_ID, null); if (!fData.isSimple() && fData.getSourceFolderName() != null && fData.getSourceFolderName().trim().length() > 0) { IFolder folder = project.getFolder(fData.getSourceFolderName()); if (!folder.exists()) CoreUtility.createFolder(folder); } return project; }
private static URL getSchemaURL(IPluginModelBase model, String schema) { try { if (model == null) return null; String location = model.getInstallLocation(); if (location == null) return null; File file = new File(location); if (file.isDirectory()) { File schemaFile = new File(file, schema); if (schemaFile.exists()) return schemaFile.toURL(); } else if (CoreUtility.jarContainsResource(file, schema, false)) { //$NON-NLS-1$ return new URL("jar:file:" + file.getAbsolutePath() + "!/" + schema); //$NON-NLS-1$ //$NON-NLS-2$ } } catch (MalformedURLException e) { } return null; }
public static void createFolder(IFolder folder) throws CoreException { if (!folder.exists()) { IContainer parent = folder.getParent(); if (parent instanceof IFolder) { createFolder((IFolder) parent); } folder.create(true, true, null); } }
private String getVMArguments(String os) { IArgumentsInfo info = fProduct.getLauncherArguments(); return (info != null) ? CoreUtility.normalize(info.getCompleteVMArguments(os)) : ""; //$NON-NLS-1$ }
private void setProjectNatures(IProject project, IPluginModelBase model) throws CoreException { IProjectDescription desc = project.getDescription(); if (!desc.hasNature(PDE.PLUGIN_NATURE)) { CoreUtility.addNatureToProject(project, PDE.PLUGIN_NATURE, null); } if (!desc.hasNature(JavaCore.NATURE_ID) && needsJavaNature(project, model)) { CoreUtility.addNatureToProject(project, JavaCore.NATURE_ID, null); } }
private String createMacInfoPList() { String entryName = TargetPlatformHelper.getTargetVersion() >= 3.3 ? "macosx/Info.plist" //$NON-NLS-1$ : "macosx/Info.plist.32"; //$NON-NLS-1$ URL url = PDECore.getDefault().getBundle().getEntry(entryName); if (url == null) return null; File plist = null; InputStream in = null; String location = fFeatureLocation; try { in = url.openStream(); File dir = new File(location, ECLIPSE_APP_CONTENTS); dir.mkdirs(); plist = new File(dir, "Info.plist"); //$NON-NLS-1$ CoreUtility.readFile(in, plist); return plist.getAbsolutePath(); } catch (IOException e) { // nothing to do } finally { try { if (in != null) in.close(); } catch (IOException e) { } } return null; }
private void ensureProductFilesExist(IPath productArea) { File productDir = productArea.toFile(); File marker = new File(productDir, ".eclipseproduct"); //$NON-NLS-1$ IPath eclipsePath = new Path(TargetPlatform.getLocation()); if (!marker.exists()) CoreUtility.copyFile(eclipsePath, ".eclipseproduct", marker); //$NON-NLS-1$ File configDir = new File(productDir, "configuration"); //$NON-NLS-1$ if (!configDir.exists()) configDir.mkdirs(); File ini = new File(configDir, "config.ini"); //$NON-NLS-1$ if (!ini.exists()) CoreUtility.copyFile(eclipsePath.append("configuration"), "config.ini", ini); //$NON-NLS-1$ //$NON-NLS-2$ }
protected IStatus run(IProgressMonitor monitor) { CoreUtility.deleteContent(configDir, monitor); if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } return Status.OK_STATUS; } };