private static void loadPlatformZipPropertiesFromFile() {
   File installLocation = getInstallLocation();
   if (installLocation != null) {
     // parent will be "eclipse" and the parent's parent will be "eclipse-testing"
     File parent = installLocation.getParentFile();
     if (parent != null) {
       parent = parent.getParentFile();
       if (parent != null) {
         File propertiesFile = new File(parent, "equinoxp2tests.properties");
         if (!propertiesFile.exists()) return;
         archiveAndRepositoryProperties = new Properties();
         try {
           InputStream is = null;
           try {
             is = new BufferedInputStream(new FileInputStream(propertiesFile));
             archiveAndRepositoryProperties.load(is);
           } finally {
             is.close();
           }
         } catch (IOException e) {
           return;
         }
       }
     }
   }
 }
 /** Saves the authorization database to disk. */
 public void save() throws CoreException {
   if (!needsSaving || file == null) return;
   try {
     file.delete();
     if ((!file.getParentFile().exists() && !file.getParentFile().mkdirs())
         || !canWrite(file.getParentFile()))
       throw new CoreException(
           new Status(
               IStatus.ERROR,
               Platform.PI_RUNTIME,
               Platform.FAILED_WRITE_METADATA,
               NLS.bind(Messages.meta_unableToWriteAuthorization, file),
               null));
     file.createNewFile();
     FileOutputStream out = new FileOutputStream(file);
     try {
       save(out);
     } finally {
       out.close();
     }
   } catch (IOException e) {
     throw new CoreException(
         new Status(
             IStatus.ERROR,
             Platform.PI_RUNTIME,
             Platform.FAILED_WRITE_METADATA,
             NLS.bind(Messages.meta_unableToWriteAuthorization, file),
             e));
   }
   needsSaving = false;
 }
示例#3
0
  private BufferedWriter getExternLogFile(AutomatedInstallData installdata) {
    String logfile = installdata.getVariable(LOGFILE_PATH);
    BufferedWriter extLogWriter = null;
    if (logfile != null) {
      if (logfile.toLowerCase().startsWith("default")) {
        logfile = installdata.getInfo().getUninstallerPath() + "/install.log";
      }
      logfile = IoHelper.translatePath(logfile, variableSubstitutor);
      File outFile = new File(logfile);
      if (!outFile.getParentFile().exists()) {
        outFile.getParentFile().mkdirs();
      }
      FileOutputStream out = null;
      try {
        out = new FileOutputStream(outFile);
      } catch (FileNotFoundException e) {
        Debug.trace("Cannot create logfile!");
        Debug.error(e);
      }
      if (out != null) {
        extLogWriter = new BufferedWriter(new OutputStreamWriter(out));
      }
    }

    return extLogWriter;
  }
 /**
  * Return the ConfiguratorConfigFile which is determined by the parameters set in Manipulator.
  *
  * @param manipulator
  * @return File
  */
 private static File getConfigFile(Manipulator manipulator) throws IllegalStateException {
   File fwConfigLoc = manipulator.getLauncherData().getFwConfigLocation();
   File baseDir = null;
   if (fwConfigLoc == null) {
     baseDir = manipulator.getLauncherData().getHome();
     if (baseDir == null) {
       if (manipulator.getLauncherData().getLauncher() != null) {
         baseDir = manipulator.getLauncherData().getLauncher().getParentFile();
       } else {
         throw new IllegalStateException(
             "All of fwConfigFile, home, launcher are not set."); //$NON-NLS-1$
       }
     }
   } else {
     if (fwConfigLoc.exists())
       if (fwConfigLoc.isDirectory()) baseDir = fwConfigLoc;
       else baseDir = fwConfigLoc.getParentFile();
     else {
       // TODO We need to decide whether launcher data configLocation is the location of a file or
       // a directory
       if (fwConfigLoc.getName().endsWith(".ini")) // $NON-NLS-1$
       baseDir = fwConfigLoc.getParentFile();
       else baseDir = fwConfigLoc;
     }
   }
   File configuratorFolder =
       new File(baseDir, SimpleConfiguratorManipulatorImpl.CONFIGURATOR_FOLDER);
   File targetFile = new File(configuratorFolder, SimpleConfiguratorManipulatorImpl.CONFIG_LIST);
   if (!Utils.createParentDir(targetFile)) return null;
   return targetFile;
 }
  private void saveConfiguration(
      BundleInfo[] configuration, File outputFile, URI installArea, boolean backup)
      throws IOException {
    if (backup && outputFile.exists()) {
      File backupFile = Utils.getSimpleDataFormattedFile(outputFile);
      if (!outputFile.renameTo(backupFile)) {
        throw new IOException("Fail to rename from (" + outputFile + ") to (" + backupFile + ")");
      }
    }

    org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] simpleInfos =
        convertBundleInfos(configuration, installArea);

    // if empty remove the configuration file
    if (simpleInfos == null || simpleInfos.length == 0) {
      if (outputFile.exists()) {
        outputFile.delete();
      }
      File parentDir = outputFile.getParentFile();
      if (parentDir.exists()) {
        parentDir.delete();
      }
      return;
    }
    SimpleConfiguratorManipulatorUtils.writeConfiguration(simpleInfos, outputFile);
    if (CONFIG_LIST.equals(outputFile.getName())
        && installArea != null
        && isSharedInstallSetup(URIUtil.toFile(installArea), outputFile))
      rememberSharedBundlesInfoTimestamp(installArea, outputFile.getParentFile());
  }
示例#6
0
  private static List<File> createPossibleHomeDirList() {
    List<File> homeDirCheckList = new ArrayList<File>(4);

    // include codeSource dir in check list
    CodeSource lib = OCSSWRuntimeConfig.class.getProtectionDomain().getCodeSource();
    if (lib != null) {
      URL libUrl = lib.getLocation();
      if (libUrl.getProtocol().equals("file")) {
        String libPath = libUrl.getPath();
        File libParentDir = new File(libPath).getParentFile();
        if (libParentDir != null) {
          // include one above libParentDir
          if (libParentDir.getParentFile() != null) {
            homeDirCheckList.add(libParentDir.getParentFile());
          }
          // include libParentDir
          homeDirCheckList.add(libParentDir);
        }
      }
    }
    // include CWD in check list
    homeDirCheckList.add(new File(".").getAbsoluteFile());
    // include one above CWD in check list
    homeDirCheckList.add(new File("src/test").getAbsoluteFile());
    return homeDirCheckList;
  }
  private void copyAllFilesToLogDir(File node, File parent) throws IOException {
    if (!node.getAbsoluteFile().equals(parent.getAbsoluteFile())
        && node.isFile()
        && !node.getParentFile().equals(parent)) {
      String fileNamePrefix = node.getName().substring(0, node.getName().lastIndexOf('.'));
      String fileNameSuffix = node.getName().substring(node.getName().lastIndexOf('.'));
      String newFilePath =
          node.getParentFile().getAbsolutePath()
              + File.separator
              + fileNamePrefix.replace(".", "_")
              + fileNameSuffix;

      File newNode = new File(newFilePath);
      if (node.renameTo(newNode)) {
        FileUtils.copyFileToDirectory(newNode, parent);
      }
    }
    if (node.isDirectory()) {
      String[] subNote = node.list();
      for (String filename : subNote) {
        copyAllFilesToLogDir(new File(node, filename), parent);
      }
      if (!node.equals(parent)) {
        FileUtils.deleteDirectory(node);
      }
    }
  }
示例#8
0
  File writeFile(File ff, String ss) throws IOException {
    if (ff.getParentFile() != null) ff.getParentFile().mkdirs();

    try (FileWriter out = new FileWriter(ff)) {
      out.write(ss);
    }
    return ff;
  }
示例#9
0
 /** Write a file containing the given string. Parent directories are created as needed. */
 File writeFile(File f, String s) throws IOException {
   if (f.getParentFile() != null) f.getParentFile().mkdirs();
   FileWriter out = new FileWriter(f);
   try {
     out.write(s);
   } finally {
     out.close();
   }
   return f;
 }
示例#10
0
  /** Like mkdirs but but using openide filesystems (firing events) */
  public static FileObject mkfolders(File file) throws IOException {
    file = FileUtil.normalizeFile(file);
    if (file.isDirectory()) return FileUtil.toFileObject(file);

    File parent = file.getParentFile();

    String path = file.getName();
    while (parent.isDirectory() == false) {
      path = parent.getName() + "/" + path; // NOI18N
      parent = parent.getParentFile();
    }

    FileObject fo = FileUtil.toFileObject(parent);
    return FileUtil.createFolder(fo, path);
  }
示例#11
0
 /**
  * Determines the sticky information for a given file. If the file is new then it returns its
  * parent directory's sticky info, if any.
  *
  * @param file file to examine
  * @return String sticky information for a file (without leading N, D or T specifier) or null
  */
 public static String getSticky(File file) {
   if (file == null) return null;
   FileInformation info = CvsVersioningSystem.getInstance().getStatusCache().getStatus(file);
   if (info.getStatus() == FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY) {
     return getSticky(file.getParentFile());
   } else if (info.getStatus() == FileInformation.STATUS_NOTVERSIONED_EXCLUDED) {
     return null;
   }
   if (file.isDirectory()) {
     String std =
         CvsVersioningSystem.getInstance().getAdminHandler().getStickyTagForDirectory(file);
     if (std != null) {
       std = std.substring(1);
     }
     return std;
   }
   Entry entry = info.getEntry(file);
   if (entry != null) {
     String stickyInfo = null;
     if (entry.getTag() != null) stickyInfo = entry.getTag(); // NOI18N
     else if (entry.getDate() != null) stickyInfo = entry.getDateFormatted(); // NOI18N
     return stickyInfo;
   }
   return null;
 }
示例#12
0
 /**
  * Determines CVS repository root for the given file. It does that by reading the CVS/Root file
  * from its parent directory, its parent and so on until CVS/Root is found.
  *
  * @param file the file in question
  * @return CVS root for the given file
  * @throws IOException if CVS/Root file is unreadable
  */
 public static String getCVSRootFor(File file) throws IOException {
   if (file.isFile()) file = file.getParentFile();
   for (; file != null; file = file.getParentFile()) {
     File rootFile = new File(file, "CVS/Root"); // NOI18N
     BufferedReader br = null;
     try {
       br = new BufferedReader(new FileReader(rootFile));
       return br.readLine();
     } catch (FileNotFoundException e) {
       continue;
     } finally {
       if (br != null) br.close();
     }
   }
   throw new IOException("CVS/Root not found"); // NOI18N
 }
示例#13
0
 /**
  * Computes path of this file to repository root.
  *
  * @param file a file
  * @return String path of this file in repsitory. If this path does not describe a versioned file,
  *     this method returns an empty string
  */
 public static String getRelativePath(File file) {
   String postfix = "";
   for (file = file.getParentFile(); file != null && !file.exists(); file = file.getParentFile()) {
     postfix = "/" + file.getName() + postfix;
   }
   if (file == null) return "";
   try {
     return CvsVersioningSystem.getInstance()
             .getAdminHandler()
             .getRepositoryForDirectory(file.getAbsolutePath(), "")
             .substring(1)
         + postfix; // NOI18N
   } catch (IOException e) {
     return ""; // NOI18N
   }
 }
示例#14
0
  /**
   * Add the supplied data as an entry in the deployment.
   *
   * @param path The target path of the entry when added to the archive.
   * @param data The data. Pass null to create a directory.
   * @return This archive instance.
   */
  public Archive addEntry(String path, byte[] data) {
    AssertArgument.isNotNullAndNotEmpty(path, "path");

    File entryFile = new File(tmpDir, path);

    if (entryFile.exists()) {
      entryFile.delete();
    }

    entryFile.getParentFile().mkdirs();
    if (data == null) {
      entryFile.mkdir();
    } else {
      try {
        FileUtils.writeFile(data, entryFile);
      } catch (IOException e) {
        throw new IllegalStateException(
            "Unexpected error writing Archive file '" + entryFile.getAbsolutePath() + "'.", e);
      }
    }

    entries.put(trimLeadingSlash(path.trim()), entryFile);

    return this;
  }
示例#15
0
  /**
   * Output the entries to the specified output folder on the file system.
   *
   * @param outputFolder The target output folder.
   * @throws java.io.IOException Write failure.
   */
  public void toFileSystem(File outputFolder) throws IOException {
    AssertArgument.isNotNull(outputFolder, "outputFolder");

    if (outputFolder.isFile()) {
      throw new IOException(
          "Cannot write Archive entries to '"
              + outputFolder.getAbsolutePath()
              + "'.  This is a normal file i.e. not a directory.");
    }
    if (!outputFolder.exists()) {
      outputFolder.mkdirs();
    }

    Set<Map.Entry<String, File>> entrySet = entries.entrySet();
    for (Map.Entry<String, File> entry : entrySet) {
      File archEntryFile = entry.getValue();
      byte[] fileBytes;
      File entryFile = new File(outputFolder, entry.getKey());

      if (archEntryFile != null) {
        fileBytes = FileUtils.readFile(archEntryFile);
        entryFile.getParentFile().mkdirs();
        FileUtils.writeFile(fileBytes, entryFile);
      } else {
        entryFile.mkdirs();
      }
    }
  }
  /**
   * GML (Graph Modeling Language) is a text file format supporting network data with a very easy
   * syntax. It is used by Graphlet, Pajek, yEd, LEDA and NetworkX.
   */
  public void exportAsGML(File gmlFile, List<SemanticPath> paths) {
    gmlFile.getParentFile().mkdirs();

    try (PrintWriter writer = new PrintWriter(Files.newWriter(gmlFile, Charsets.UTF_8)); ) {

      writer.println("graph\n[");
      // write vertex
      for (SemanticPath path : paths) {
        for (int i = 0; i < path.length(); i++) {
          writer.println("\tnode\n\t[");
          writer.println("\t\tid " + path.id(i));
          writer.println("\t\tlabel \"" + path.name(i) + "\"");
          writer.println("\t]");
        }
      }

      // write edge
      for (SemanticPath path : paths) {
        for (int i = 0; i < path.length() - 1; i++) {
          writer.println("\tedge\n\t[");
          writer.println("\t\tsource " + path.id(i + 1));
          writer.println("\t\ttarget " + path.id(i));
          writer.println("\t]");
        }
      }
      writer.println(']');
      writer.flush();
    } catch (IOException e) {
      LOG.error("Export to GML file error!", e);
    }
  }
示例#17
0
  /** Initialize the panel UI component values from the current site profile settings. */
  public void updatePanel() {
    {
      File dir = pApp.getHomeDirectory();

      if (dir == null) {
        String home = System.getProperty("user.home");
        if (home != null) {
          File hdir = new File(home);
          if ((hdir != null) && hdir.isDirectory()) dir = hdir.getParentFile();
        }
      }

      if (dir == null) dir = new File("/home");

      pHomeDirComp.setDir(dir);
    }

    {
      File dir = pApp.getTemporaryDirectory();
      if (dir == null) dir = new File("/var/tmp");
      pTempDirComp.setDir(dir);
    }

    {
      File dir = pApp.getUnixJavaHome();
      if (dir == null) dir = new File(pApp.getJavaHome());
      pJavaHomeDirComp.setDir(dir);
    }

    pJavadocDirComp.setDir(pApp.getUnixLocalJavadocDirectory());
    pExtraJavaLibsComp.setJars(pApp.getUnixLocalJavaLibraries());
  }
示例#18
0
  private void copy(File workspaceDir, InputStream in, Pattern glob, boolean overwrite)
      throws Exception {

    Jar jar = new Jar("dot", in);
    try {
      for (Entry<String, Resource> e : jar.getResources().entrySet()) {

        String path = e.getKey();
        bnd.trace("path %s", path);

        if (glob != null && !glob.matcher(path).matches()) continue;

        Resource r = e.getValue();
        File dest = Processor.getFile(workspaceDir, path);
        if (overwrite
            || !dest.isFile()
            || dest.lastModified() < r.lastModified()
            || r.lastModified() <= 0) {

          bnd.trace("copy %s to %s", path, dest);

          File dp = dest.getParentFile();
          if (!dp.exists() && !dp.mkdirs()) {
            throw new IOException("Could not create directory " + dp);
          }

          IO.copy(r.openInputStream(), dest);
        }
      }
    } finally {
      jar.close();
    }
  }
示例#19
0
文件: Import.java 项目: dlitz/resin
  public void resolve(Unmarshaller u) throws JAXBException {
    Object obj = null;

    try {
      obj = u.unmarshal(new URL(getSchemaLocation()));
    } catch (MalformedURLException e) {
    }

    File file = new File(getSchemaLocation());

    if (!file.exists()) {
      if (!file.getName().startsWith("/")) {
        file = new File(_location.getSystemId());

        file = file.getParentFile();

        if (file == null) throw new JAXBException("File not found: " + getSchemaLocation());

        file = new File(file, getSchemaLocation());
      }
    }

    obj = u.unmarshal(file);

    if (obj instanceof Schema) _schema = (Schema) obj;
  }
示例#20
0
  /**
   * Load the database from the database file given in "database.json" if the file doesn't exist, it
   * gets created here if the file has a database in it already, it is loaded here
   *
   * @return false if there is an error opening the database
   */
  public boolean open() {
    try {
      System.out.println(dbPath);
      File dbFile = new File(dbPath);

      // Only read the database from the file if it exists
      if (dbFile.exists()) {
        FileInputStream fileIn = new FileInputStream(dbPath);
        ObjectInputStream in = new ObjectInputStream(fileIn);
        // load the database here
        database = (HashMap<K, V>) in.readObject();
        // make sure the streams close properly
        in.close();
        fileIn.close();

        Debug.println("Database loaded");
      } else {
        dbFile.getParentFile().mkdirs();
        dbFile.createNewFile();

        Debug.println("Database created");
      }
      return true;
    } catch (Exception e) {
      System.err.println("Error opening database");
      System.err.println(e);
      return false;
    }
  }
  // Contructor that takes in the usernames of the users
  public ServerFileIO(String username1, String username2) throws IOException {
    // Sets the naming convention for the files
    // The convention is:
    // <Smaller Username><Larger Username>.txt

    user1 = username1;
    user2 = username2;

    if (username1.compareTo(username2) < 0)
      file =
          new File(
              System.getProperty("user.home")
                  + "\\Server Message Files\\"
                  + username1
                  + username2
                  + ".txt");
    else if (username1.compareTo(username2) > 0)
      file =
          new File(
              System.getProperty("user.home")
                  + "\\Server Message Files\\"
                  + username2
                  + username1
                  + ".txt");
    else {
      throw new IllegalArgumentException("Both usernames are the same");
    }

    file.getParentFile().mkdirs();
    file.createNewFile();

    output = new PrintWriter(new FileWriter(file, true));
    input = new Scanner(file);
  }
示例#22
0
 /**
  * Get the test suite specifications from the suite file, apply the options to all, and report any
  * messages to the holder.
  *
  * @param suitePath the String path to the harness suite file
  * @param options the String[] options for the tests - may be null
  * @param holder the IMessageHolder for any messages - may be null
  * @return AjcTest.Suite.Spec test descriptions (non-null but empty if some error)
  */
 public static AjcTest.Suite.Spec getSuiteSpec(
     String suitePath, String[] options, IMessageHolder holder) {
   if (null == suitePath) {
     MessageUtil.fail(holder, "null suitePath");
     return EmptySuite.ME;
   }
   File suiteFile = new File(suitePath);
   if (!suiteFile.canRead() || !suiteFile.isFile()) {
     MessageUtil.fail(holder, "unable to read file " + suitePath);
     return EmptySuite.ME;
   }
   try {
     AjcTest.Suite.Spec tempSpec;
     AbstractRunSpec.RT runtime = new AbstractRunSpec.RT();
     tempSpec = AjcSpecXmlReader.getReader().readAjcSuite(suiteFile);
     tempSpec.setSuiteDirFile(suiteFile.getParentFile());
     if (null == options) {
       options = new String[0];
     }
     runtime.setOptions(options);
     boolean skip = !tempSpec.adoptParentValues(runtime, holder);
     if (skip) {
       tempSpec = EmptySuite.ME;
     }
     return tempSpec;
   } catch (IOException e) {
     MessageUtil.abort(holder, "IOException", e);
     return EmptySuite.ME;
   }
 }
示例#23
0
 public static File makeDuplicate(File thisFile) {
   mylogger.log(Level.INFO, "Duplicating {0}", new Object[] {thisFile.getAbsolutePath()});
   return copyToFolderAs(
       thisFile,
       thisFile.getParentFile(),
       stripExtension(thisFile) + "_copy" + getExtension(thisFile));
 }
示例#24
0
 public void saveCache(
     JMXInstrumentedCache<K, V> cache, File savedCachePath, Function<K, byte[]> converter)
     throws IOException {
   long start = System.currentTimeMillis();
   String msgSuffix = " " + savedCachePath.getName() + " for " + cfname + " of " + ksname;
   logger.debug("saving" + msgSuffix);
   int count = 0;
   File tmpFile =
       File.createTempFile(savedCachePath.getName(), null, savedCachePath.getParentFile());
   FileOutputStream fout = new FileOutputStream(tmpFile);
   ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(fout));
   FileDescriptor fd = fout.getFD();
   for (K key : cache.getKeySet()) {
     byte[] bytes = converter.apply(key);
     out.writeInt(bytes.length);
     out.write(bytes);
     ++count;
   }
   out.flush();
   fd.sync();
   out.close();
   if (!tmpFile.renameTo(savedCachePath))
     throw new IOException("Unable to rename cache to " + savedCachePath);
   if (logger.isDebugEnabled())
     logger.debug(
         "saved "
             + count
             + " keys in "
             + (System.currentTimeMillis() - start)
             + " ms from"
             + msgSuffix);
 }
示例#25
0
  public static String[] listFiles(File dir, Boolean includeSubDirs) throws IOException {
    FileFilter fileFilter =
        new FileFilter() {
          public boolean accept(File file) {
            return file.isDirectory();
          }
        };
    File[] subFolders = dir.listFiles(fileFilter);

    List<String> files = new ArrayList<String>();

    List<File> fileArray =
        new ArrayList<File>(
            FileUtils.listFiles(
                dir, TrueFileFilter.INSTANCE, includeSubDirs ? TrueFileFilter.INSTANCE : null));

    for (File file : fileArray) {
      if (file.isFile()) {
        if (includeSubDirs && containsParentFolder(file, subFolders)) {
          files.add(file.getParentFile().getName() + File.separator + file.getName());
        } else {
          files.add(file.getName());
        }
      }
    }

    return (String[]) files.toArray(new String[0]);
  }
示例#26
0
  public void run() throws Exception {
    File rtDir = new File("rt.dir");
    File javaHome = new File(System.getProperty("java.home"));
    if (javaHome.getName().equals("jre")) javaHome = javaHome.getParentFile();
    File rtJar = new File(new File(new File(javaHome, "jre"), "lib"), "rt.jar");
    expand(rtJar, rtDir);

    String[] rtDir_opts = {
      "-bootclasspath", rtDir.toString(),
      "-classpath", "",
      "-sourcepath", "",
      "-extdirs", ""
    };
    test(rtDir_opts, "HelloPathWorld");

    if (isJarFileSystemAvailable()) {
      String[] rtJar_opts = {
        "-bootclasspath", rtJar.toString(),
        "-classpath", "",
        "-sourcepath", "",
        "-extdirs", ""
      };
      test(rtJar_opts, "HelloPathWorld");

      String[] default_opts = {};
      test(default_opts, "HelloPathWorld");

      // finally, a non-trivial program
      test(default_opts, "CompileTest");
    } else System.err.println("jar file system not available: test skipped");
  }
示例#27
0
  private boolean unpackFile(ZipFile zip, byte[] buf, ZipEntry fileEntry, String name)
      throws IOException, FileNotFoundException {
    if (fileEntry == null) fileEntry = zip.getEntry(name);
    if (fileEntry == null)
      throw new FileNotFoundException("Can't find " + name + " in " + zip.getName());

    File outFile = new File(sGREDir, name);
    if (outFile.lastModified() == fileEntry.getTime() && outFile.length() == fileEntry.getSize())
      return false;

    File dir = outFile.getParentFile();
    if (!dir.exists()) dir.mkdirs();

    InputStream fileStream;
    fileStream = zip.getInputStream(fileEntry);

    OutputStream outStream = new FileOutputStream(outFile);

    while (fileStream.available() > 0) {
      int read = fileStream.read(buf, 0, buf.length);
      outStream.write(buf, 0, read);
    }

    fileStream.close();
    outStream.close();
    outFile.setLastModified(fileEntry.getTime());
    return true;
  }
示例#28
0
  private void loadObjects() throws ConfigurationException {
    if (!isExecutionMode()) {
      // Import objects from file system
      File objectsDirectory = new File(tangaraPath.getParentFile(), "objects");
      System.out.println("using path " + objectsDirectory.getAbsolutePath());

      // 1st Load libraries
      File libDirectory = new File(objectsDirectory, "lib");
      File libraries[] = libDirectory.listFiles();
      for (int i = 0; i < libraries.length; i++) {
        if (libraries[i].getName().endsWith(".jar")) {
          System.out.println("Loading library " + libraries[i].getName());
          addClassPathToScriptEngine(libraries[i]);
        }
      }

      // 2nd load objects
      File objects[] = objectsDirectory.listFiles();
      for (int i = 0; i < objects.length; i++) {
        if (objects[i].getName().endsWith(".jar")) {
          System.out.println("Loading object " + objects[i].getName());
          addClassPathToScriptEngine(objects[i]);
        }
      }
    }
    // import the localized objects package
    importLocalizedObjectsPackage();
  }
示例#29
0
 @NotNull
 private String createLocalFile(@NotNull ObjectId id, @NotNull ObjectLoader loader)
     throws IOException {
   // Create LFS stream.
   final File tmpFile = new File(tempPath, UUID.randomUUID().toString());
   final MessageDigest md = createSha256();
   try (InputStream istream = loader.openStream();
       OutputStream ostream = new FileOutputStream(tmpFile)) {
     byte[] buffer = new byte[0x10000];
     while (true) {
       int size = istream.read(buffer);
       if (size <= 0) break;
       ostream.write(buffer, 0, size);
       md.update(buffer, 0, size);
     }
   }
   final String hash = new String(Hex.encodeHex(md.digest(), true));
   cacheSha256.putIfAbsent(id.name(), hash);
   cache.commit();
   // Rename file.
   final File lfsFile =
       new File(
           basePath,
           "lfs/objects/" + hash.substring(0, 2) + "/" + hash.substring(2, 4) + "/" + hash);
   makeParentDirs(lfsFile.getParentFile());
   if (lfsFile.exists()) {
     if (!tmpFile.delete()) {
       log.warn("Can't delete temporary file: {}", lfsFile.getAbsolutePath());
     }
   } else if (!tmpFile.renameTo(lfsFile)) {
     throw new IOException("Can't rename file: " + tmpFile + " -> " + lfsFile);
   }
   return hash;
 }
 public static boolean isFilePathAcceptable(@NotNull File root, @Nullable FileFilter fileFilter) {
   File file = root;
   do {
     if (fileFilter != null && !fileFilter.accept(file)) return false;
     file = file.getParentFile();
   } while (file != null);
   return true;
 }