public IncrementalJUnit4Runner() {
    File testRunFile = new File("testRun.properties");

    if (testRunFile.exists() && !testRunFile.canWrite()) {
      throw new IllegalStateException();
    }

    coverageMap = new Properties();
    testMethods = new HashMap<Method, Boolean>();
  }
  /**
   * Checks whether <tt>path</tt> is a valid directory for recording (creates it if necessary).
   *
   * @param path the path to the directory to check.
   * @return <tt>true</tt> if the directory <tt>path</tt> can be used for media recording,
   *     <tt>false</tt> otherwise.
   */
  private boolean checkRecordingDirectory(String path) {
    if (path == null || "".equals(path)) return false;

    File dir = new File(path);

    if (!dir.exists()) {
      dir.mkdir();
      if (!dir.exists()) return false;
    }
    if (!dir.isDirectory() || !dir.canWrite()) return false;

    return true;
  }
Пример #3
0
 public void run(String arg) {
   if (arg.equals("menus")) {
     updateMenus();
     return;
   }
   if (IJ.getApplet() != null) return;
   URL url = getClass().getResource("/ij/IJ.class");
   String ij_jar = url == null ? null : url.toString().replaceAll("%20", " ");
   if (ij_jar == null || !ij_jar.startsWith("jar:file:")) {
     error("Could not determine location of ij.jar");
     return;
   }
   int exclamation = ij_jar.indexOf('!');
   ij_jar = ij_jar.substring(9, exclamation);
   if (IJ.debugMode) IJ.log("Updater (jar loc): " + ij_jar);
   File file = new File(ij_jar);
   if (!file.exists()) {
     error("File not found: " + file.getPath());
     return;
   }
   if (!file.canWrite()) {
     String msg = "No write access: " + file.getPath();
     error(msg);
     return;
   }
   String[] list = openUrlAsList(IJ.URL + "/download/jars/list.txt");
   int count = list.length + 3;
   String[] versions = new String[count];
   String[] urls = new String[count];
   String uv = getUpgradeVersion();
   if (uv == null) return;
   versions[0] = "v" + uv;
   urls[0] = IJ.URL + "/upgrade/ij.jar";
   if (versions[0] == null) return;
   for (int i = 1; i < count - 2; i++) {
     String version = list[i - 1];
     versions[i] = version.substring(0, version.length() - 1); // remove letter
     urls[i] =
         IJ.URL + "/download/jars/ij" + version.substring(1, 2) + version.substring(3, 6) + ".jar";
   }
   versions[count - 2] = "daily build";
   urls[count - 2] = IJ.URL + "/ij.jar";
   versions[count - 1] = "previous";
   urls[count - 1] = IJ.URL + "/upgrade/ij2.jar";
   int choice = showDialog(versions);
   if (choice == -1 || !Commands.closeAll()) return;
   // System.out.println("choice: "+choice);
   // for (int i=0; i<urls.length; i++) System.out.println("  "+i+" "+urls[i]);
   byte[] jar = null;
   if ("daily build".equals(versions[choice]) && notes != null && notes.contains(" </title>"))
     jar = getJar("http://wsr.imagej.net/download/daily-build/ij.jar");
   if (jar == null) jar = getJar(urls[choice]);
   if (jar == null) {
     error("Unable to download ij.jar from " + urls[choice]);
     return;
   }
   Prefs.savePreferences();
   // System.out.println("saveJar: "+file);
   saveJar(file, jar);
   if (choice < count - 2) // force macro Function Finder to download fresh list
   new File(IJ.getDirectory("macros") + "functions.html").delete();
   System.exit(0);
 }
Пример #4
0
 public void run(String arg) {
   if (arg.equals("menus")) {
     updateMenus();
     return;
   }
   if (IJ.getApplet() != null) return;
   // File file = new File(Prefs.getHomeDir() + File.separator + "ij.jar");
   // if (isMac() && !file.exists())
   //	file = new File(Prefs.getHomeDir() + File.separator +
   // "ImageJ.app/Contents/Resources/Java/ij.jar");
   URL url = getClass().getResource("/ij/IJ.class");
   String ij_jar = url == null ? null : url.toString().replaceAll("%20", " ");
   if (ij_jar == null || !ij_jar.startsWith("jar:file:")) {
     error("Could not determine location of ij.jar");
     return;
   }
   int exclamation = ij_jar.indexOf('!');
   ij_jar = ij_jar.substring(9, exclamation);
   if (IJ.debugMode) IJ.log("Updater: " + ij_jar);
   File file = new File(ij_jar);
   if (!file.exists()) {
     error("File not found: " + file.getPath());
     return;
   }
   if (!file.canWrite()) {
     String msg = "No write access: " + file.getPath();
     if (IJ.isVista()) msg += Prefs.vistaHint;
     error(msg);
     return;
   }
   String[] list = openUrlAsList(IJ.URL + "/download/jars/list.txt");
   int count = list.length + 2;
   String[] versions = new String[count];
   String[] urls = new String[count];
   String uv = getUpgradeVersion();
   if (uv == null) return;
   versions[0] = "v" + uv;
   urls[0] = IJ.URL + "/upgrade/ij.jar";
   if (versions[0] == null) return;
   for (int i = 1; i < count - 1; i++) {
     String version = list[i - 1];
     versions[i] = version.substring(0, version.length() - 1); // remove letter
     urls[i] =
         IJ.URL + "/download/jars/ij" + version.substring(1, 2) + version.substring(3, 6) + ".jar";
   }
   versions[count - 1] = "daily build";
   urls[count - 1] = IJ.URL + "/ij.jar";
   int choice = showDialog(versions);
   if (choice == -1) return;
   if (!versions[choice].startsWith("daily")
       && versions[choice].compareTo("v1.39") < 0
       && Menus.getCommands().get("ImageJ Updater") == null) {
     String msg =
         "This command is not available in versions of ImageJ prior\n"
             + "to 1.39 so you will need to install the plugin version at\n"
             + "<"
             + IJ.URL
             + "/plugins/imagej-updater.html>.";
     if (!IJ.showMessageWithCancel("Update ImageJ", msg)) return;
   }
   byte[] jar = getJar(urls[choice]);
   // file.renameTo(new File(file.getParent()+File.separator+"ij.bak"));
   if (version().compareTo("1.37v") >= 0) Prefs.savePreferences();
   // if (!renameJar(file)) return; // doesn't work on Vista
   saveJar(file, jar);
   if (choice < count - 1) // force macro Function Finder to download fresh list
   new File(IJ.getDirectory("macros") + "functions.html").delete();
   System.exit(0);
 }
Пример #5
0
  public static void main(String[] argv) {
    try {
      if (argv.length != 1) {
        System.err.println(
            "java " + JdbcProxyGenerator.class.getName() + " <source-root-directory>");
        return;
      }

      File srcroot = new File(argv[0]);
      if (!srcroot.exists() || !srcroot.canWrite()) {
        System.err.println(
            JdbcProxyGenerator.class.getName()
                + " -- sourceroot: "
                + argv[0]
                + " must exist and be writable");
        return;
      }

      DelegatorGenerator mdgen = new NewProxyMetaDataGenerator();
      DelegatorGenerator rsgen = new NewProxyResultSetGenerator();
      DelegatorGenerator stgen = new NewProxyAnyStatementGenerator();
      DelegatorGenerator cngen = new NewProxyConnectionGenerator();

      /*
       * Eliminating for c3p0-0.9.5

      // Usually stgen can be used for all three Statement types. However, we have temporarily
      // implemented some very partial JDBC4 methods to maintain Hibernate support, prior to full JDBC4
      // support in a future version. To do this, we'll need to force some methods into the PreparedStatement
      // (and therefore CallableStatement) interfaces, methods that don't exist in the current JDBC3 build.
      // We should be able to get rid of psgen (in favor of stgen above) when we are actually building against
      // JDBC4 (so we don't need to artificially inject methods).
             //DelegatorGenerator psgen = new NewProxyAnyStatementGenerator();
      //psgen.setReflectiveDelegateMethods( JDBC4TemporaryPreparedStatementMethods.class.getMethods() );

      */

      genclass(cngen, Connection.class, "com.mchange.v2.c3p0.impl.NewProxyConnection", srcroot);
      genclass(stgen, Statement.class, "com.mchange.v2.c3p0.impl.NewProxyStatement", srcroot);
      // genclass( psgen, PreparedStatement.class,
      // "com.mchange.v2.c3p0.impl.NewProxyPreparedStatement", srcroot );
      // genclass( psgen, CallableStatement.class,
      // "com.mchange.v2.c3p0.impl.NewProxyCallableStatement", srcroot );
      genclass(
          stgen,
          PreparedStatement.class,
          "com.mchange.v2.c3p0.impl.NewProxyPreparedStatement",
          srcroot);
      genclass(
          stgen,
          CallableStatement.class,
          "com.mchange.v2.c3p0.impl.NewProxyCallableStatement",
          srcroot);
      genclass(rsgen, ResultSet.class, "com.mchange.v2.c3p0.impl.NewProxyResultSet", srcroot);
      genclass(
          mdgen,
          DatabaseMetaData.class,
          "com.mchange.v2.c3p0.impl.NewProxyDatabaseMetaData",
          srcroot);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #6
0
  public void deinit(Appendable out, boolean force) throws Exception {
    Settings settings = new Settings(platform.getConfigFile());

    if (!force) {
      Justif justify = new Justif(80, 40);
      StringBuilder sb = new StringBuilder();
      Formatter f = new Formatter(sb);

      try {
        String list = listFiles(platform.getGlobal());
        if (list != null) {
          f.format("In global default environment:%n");
          f.format(list);
        }

        list = listFiles(platform.getLocal());
        if (list != null) {
          f.format("In local default environment:%n");
          f.format(list);
        }

        if (settings.containsKey(JPM_CACHE_GLOBAL)) {
          list = listFiles(IO.getFile(settings.get(JPM_CACHE_GLOBAL)));
          if (list != null) {
            f.format("In global configured environment:%n");
            f.format(list);
          }
        }

        if (settings.containsKey(JPM_CACHE_LOCAL)) {
          list = listFiles(IO.getFile(settings.get(JPM_CACHE_LOCAL)));
          if (list != null) {
            f.format("In local configured environment:%n");
            f.format(list);
          }
        }

        list = listSupportFiles();
        if (list != null) {
          f.format("jpm support files:%n");
          f.format(list);
        }

        f.format("%n%n");

        f.format(
            "All files listed above will be deleted if deinit is run with the force flag set"
                + " (\"jpm deinit -f\" or \"jpm deinit --force\"%n%n");
        f.flush();

        justify.wrap(sb);
        out.append(sb.toString());
      } finally {
        f.close();
      }
    } else { // i.e. if(force)
      int count = 0;
      File[] caches = {platform.getGlobal(), platform.getLocal(), null, null};
      if (settings.containsKey(JPM_CACHE_LOCAL)) {
        caches[2] = IO.getFile(settings.get(JPM_CACHE_LOCAL));
      }
      if (settings.containsKey(JPM_CACHE_GLOBAL)) {
        caches[3] = IO.getFile(settings.get(JPM_CACHE_GLOBAL));
      }
      ArrayList<File> toDelete = new ArrayList<File>();

      for (File cache : caches) {
        if (cache == null || !cache.exists()) {
          continue;
        }
        listFiles(cache, toDelete);
        if (toDelete.size() > count) {
          count = toDelete.size();
          if (!cache.canWrite()) {
            reporter.error(PERMISSION_ERROR + " (" + cache + ")");
            return;
          }
          toDelete.add(cache);
        }
      }
      listSupportFiles(toDelete);

      for (File f : toDelete) {
        if (f.exists() && !f.canWrite()) {
          reporter.error(PERMISSION_ERROR + " (" + f + ")");
        }
      }
      if (reporter.getErrors().size() > 0) {
        return;
      }

      for (File f : toDelete) {
        if (f.exists()) {
          IO.deleteWithException(f);
        }
      }
    }
  }
Пример #7
0
  public boolean hasAccess() {
    assert (binDir != null);
    assert (homeDir != null);

    return binDir.canWrite() && homeDir.canWrite();
  }