/** * @param configURI * @param feature * @throws IOException */ public static void createConfiguration(URI configURI, List<String> features) throws IOException { File configFile = FileUtils.getFile(configURI); FileUtils.createFile(configFile); BufferedWriter output = new BufferedWriter(new FileWriter(configFile)); for (String feature : features) { output.append(validFeatureName(feature)); output.newLine(); } output.close(); }
public static void exportFeatureModel(URI featureModelURI, FeatureModel fm) { File fmFile = FileUtils.getFile(featureModelURI); try { FileUtils.createFile(fmFile); } catch (IOException e) { e.printStackTrace(); } save(fm, fmFile); // Refresh in case of workspace IFile file = WorkbenchUtils.getIFileFromFile(fmFile); if (file != null) { WorkbenchUtils.refreshIResource(file); } }
/** * Provides the atomic elements (plugins) this distribution is made of * * @param uri URI of the distribution * @param monitor */ @Override public List<IElement> adapt(URI uri, IProgressMonitor monitor) { List<IElement> elements = new ArrayList<IElement>(); File file = FileUtils.getFile(uri); rootURI = file.toURI(); // A hashmap of bundle symbolic names and the complete line in the // bundles.info file bundlesInfoLines = PluginInfosExtractor.createBundlesInfoMap(uri); // start the containment tree traversal, with null as initial container adapt(file, elements, null); // plugin dependencies for (IElement elem : elements) { if (elem instanceof PluginElement) { PluginElement pe = (PluginElement) elem; DependenciesBuilder.build(pe, elements); } } // in elements we have the result return elements; }
/** This method check if the artefact is adaptable with the EclipseAdapter */ @Override public boolean isAdaptable(URI uri, IProgressMonitor monitor) { File file = FileUtils.getFile(uri); if (file.isDirectory()) { File pluginsFolder = new File(file.getAbsolutePath() + "/plugins"); if (pluginsFolder.exists() && pluginsFolder.isDirectory()) { return true; } else { return false; } } return false; }
@Override public void construct(URI uri, List<IElement> elements, IProgressMonitor monitor) { boolean constructBundlesInfo = false; String bundlesInfoContent = "#version=1\n"; for (IElement element : elements) { // check user cancel for each element if (!monitor.isCanceled()) { // provide user info monitor.subTask(element.getText()); if (element instanceof FileElement) { FileElement fileElement = (FileElement) element; if (fileElement .getRelativeURI() .toString() .equals(PluginInfosExtractor.BUNDLESINFO_RELATIVEPATH)) { constructBundlesInfo = true; } try { // Create parent folders structure URI newDirectoryURI = uri.resolve(fileElement.getRelativeURI()); File destinationFile = FileUtils.getFile(newDirectoryURI); if (destinationFile != null && !destinationFile.getParentFile().exists()) { destinationFile.getParentFile().mkdirs(); } if (destinationFile != null && !destinationFile.exists()) { // Copy the content. In the case of a folder, its // content is not copied File file = FileUtils.getFile(fileElement.getUri()); Files.copy( file.toPath(), destinationFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } } catch (IOException e) { e.printStackTrace(); } } // prepare the bundles.info configuration file // just in case we need to construct it if (element instanceof PluginElement) { PluginElement pluginElement = (PluginElement) element; String line = pluginElement.getBundleInfoLine(); if (line != null) { String[] lineFields = line.split(","); bundlesInfoContent += pluginElement.getSymbName() + ","; bundlesInfoContent += pluginElement.getVersion() + ","; bundlesInfoContent += pluginElement.getRelativeURI() + ","; bundlesInfoContent += lineFields[3] + ","; bundlesInfoContent += lineFields[4] + "\n"; } } } monitor.worked(1); } // Replace bundles.info content if (constructBundlesInfo) { try { File tmpFile = File.createTempFile("tempBundles", "info"); FileUtils.appendToFile(tmpFile, bundlesInfoContent); File file = FileUtils.getFile(uri); File bundlesInfo = new File(file.getAbsolutePath() + "/" + PluginInfosExtractor.BUNDLESINFO_RELATIVEPATH); FileUtils.replace(bundlesInfo, tmpFile); tmpFile.deleteOnExit(); } catch (Exception e) { e.printStackTrace(); } } }