コード例 #1
0
ファイル: EclipseAdapter.java プロジェクト: J-Art75/but4reuse
 @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();
     }
   }
 }