示例#1
0
  /**
   * adapt recursively
   *
   * @param file
   * @param elements
   * @param container
   */
  private void adapt(File file, List<IElement> elements, IElement container) {
    FileElement newElement = null;
    if (PluginInfosExtractor.isAPlugin(file)) {
      try {
        // Unzipped plugin
        if (file.isDirectory()) {
          newElement =
              PluginInfosExtractor.getPluginInfosFromManifest(
                  file.getAbsolutePath() + "/META-INF/MANIFEST.MF");
        } else {
          // Jar plugin
          newElement = PluginInfosExtractor.getPluginInfosFromJar(file.getAbsolutePath());
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {
      newElement = new FileElement();
    }

    // Set the relevant information
    newElement.setUri(file.toURI());
    newElement.setRelativeURI(rootURI.relativize(file.toURI()));

    // Add dependency to the parent folder
    if (container != null) {
      newElement.addDependency("container", container);
    }

    // Add the bundles info
    if (newElement instanceof PluginElement) {
      PluginElement plugin = (PluginElement) newElement;
      String line = bundlesInfoLines.get(plugin.getSymbName());
      // in the case of source code plugins, line will be null but no
      // problem
      plugin.setBundleInfoLine(line);

      if (plugin.getName() == null || plugin.getName().contains("%")) {
        System.out.println(
            "EclipseAdapter.adapt() No name found for: "
                + plugin.isFragment()
                + "  "
                + plugin.getSymbName());
      }
    }

    // Add to the list
    elements.add(newElement);

    // Go for the files in case of folder
    if (file.isDirectory()) {
      // Exclude the features folder
      if (!newElement.getRelativeURI().toString().equals("features/")) {
        File[] files = file.listFiles();
        for (File subFile : files) {
          adapt(subFile, elements, newElement);
        }
      }
    }
  }
示例#2
0
 @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();
     }
   }
 }