コード例 #1
0
 protected void modifyEclipseClasspath(
     ServiceExtensionDescriptionType desc, ServiceInformation info)
     throws CodegenExtensionException {
   // get the eclipse classpath document
   File classpathFile = new File(info.getBaseDirectory(), ".classpath");
   if (classpathFile.exists()) {
     logger.info("Modifying eclipse .classpath file");
     Set<File> libs = new HashSet<File>();
     ExtensionTypeExtensionData data = ExtensionTools.getExtensionData(desc, info);
     AdditionalLibraries additionalLibs = null;
     try {
       additionalLibs = ExtensionDataUtils.getExtensionData(data).getAdditionalLibraries();
     } catch (Exception ex) {
       throw new CodegenExtensionException("Error retrieving extension data");
     }
     if (additionalLibs != null && additionalLibs.getJarName() != null) {
       for (int i = 0; i < additionalLibs.getJarName().length; i++) {
         String jarFilename = additionalLibs.getJarName(i);
         libs.add(new File(info.getBaseDirectory(), "lib" + File.separator + jarFilename));
       }
     }
     File[] libFiles = new File[libs.size()];
     libs.toArray(libFiles);
     try {
       logger.info("Adding libraries to classpath file:");
       for (int i = 0; i < libFiles.length; i++) {
         logger.info("\t" + libFiles[i].getAbsolutePath());
       }
       ExtensionUtilities.syncEclipseClasspath(classpathFile, libFiles);
     } catch (Exception ex) {
       throw new CodegenExtensionException(
           "Error modifying Eclipse .classpath file: " + ex.getMessage(), ex);
     }
   } else {
     logger.warn("Eclipse .classpath file " + classpathFile.getAbsolutePath() + " not found!");
   }
 }
コード例 #2
0
  private void updateDataLibraries() throws UpgradeException {
    FileFilter oldDataLibFilter =
        new FileFilter() {
          public boolean accept(File pathname) {
            String name = pathname.getName();
            return name.endsWith(".jar")
                && (name.startsWith("caGrid-data-")
                    || name.startsWith("caGrid-core-")
                    || name.startsWith("caGrid-CQL-")
                    || name.startsWith("caGrid-caDSR-")
                    || name.startsWith("caGrid-metadata-"));
          }
        };
    FileFilter newDataLibFilter =
        new FileFilter() {
          public boolean accept(File pathname) {
            String name = pathname.getName();
            return name.endsWith(".jar")
                && (name.startsWith("caGrid-data-")
                    || name.startsWith("caGrid-core-")
                    || name.startsWith("caGrid-CQL-")
                    || name.startsWith("caGrid-caDSR-")
                    || name.startsWith("caGrid-metadata-")
                    || name.startsWith("caGrid-mms-")
                    || name.startsWith("castor-1.0.2"));
          }
        };
    // locate the old data service libs in the service
    File serviceLibDir = new File(getServicePath() + File.separator + "lib");
    File[] serviceDataLibs = serviceLibDir.listFiles(oldDataLibFilter);
    // delete the old libraries
    for (File oldLib : serviceDataLibs) {
      oldLib.delete();
      getStatus().addDescriptionLine("caGrid 1.5 library " + oldLib.getName() + " removed");
    }
    // copy new libraries in
    File extLibDir = new File(ExtensionsLoader.EXTENSIONS_DIRECTORY + File.separator + "lib");
    File[] dataLibs = extLibDir.listFiles(newDataLibFilter);
    List<File> outLibs = new ArrayList<File>(dataLibs.length);
    for (File newLib : dataLibs) {
      File out = new File(serviceLibDir.getAbsolutePath() + File.separator + newLib.getName());
      try {
        Utils.copyFile(newLib, out);
        getStatus()
            .addDescriptionLine(
                "caGrid "
                    + UpgraderConstants.DATA_CURRENT_VERSION
                    + " library "
                    + newLib.getName()
                    + " added");
      } catch (IOException ex) {
        throw new UpgradeException(
            "Error copying new data service library: " + ex.getMessage(), ex);
      }
      outLibs.add(out);
    }

    // update the Eclipse .classpath file
    File classpathFile = new File(getServicePath() + File.separator + ".classpath");
    File[] outLibArray = new File[dataLibs.length];
    outLibs.toArray(outLibArray);
    try {
      ExtensionUtilities.syncEclipseClasspath(classpathFile, outLibArray);
      getStatus().addDescriptionLine("Eclipse .classpath file updated");
    } catch (Exception ex) {
      throw new UpgradeException("Error updating Eclipse .classpath file: " + ex.getMessage(), ex);
    }
  }