示例#1
0
  /** Constructor. */
  public RunClasspath() {
    super(ProjectLocator.getAntProject());
    type = "RUN";
    createPathElement().setLocation(ModulesTxt.instance().getParentFile());
    for (Module module : ModuleTree.instance()) {
      append(makeRunClasspathPart(module));
    }

    // add the files from the CLASSPATH environement variable
    String classpath = System.getenv("CLASSPATH");
    if (classpath != null && !classpath.trim().isEmpty()) {
      final Path path = new Path(ProjectLocator.getAntProject());
      for (String pathStr : classpath.split(File.pathSeparator)) {
        path.createPathElement().setPath(pathStr);
      }
      append(path);
      System.out.println("adding $CLASSPATH to RunClassPath: " + path);
    }
  }
  @Override
  public void reloadFromDisk(@NotNull final Document document) {
    ApplicationManager.getApplication().assertIsDispatchThread();

    final VirtualFile file = getFile(document);
    assert file != null;

    if (!fireBeforeFileContentReload(file, document)) {
      return;
    }

    final Project project = ProjectLocator.getInstance().guessProjectForFile(file);
    CommandProcessor.getInstance()
        .executeCommand(
            project,
            new Runnable() {
              @Override
              public void run() {
                ApplicationManager.getApplication()
                    .runWriteAction(
                        new ExternalChangeAction.ExternalDocumentChange(document, project) {
                          @Override
                          public void run() {
                            boolean wasWritable = document.isWritable();
                            DocumentEx documentEx = (DocumentEx) document;
                            documentEx.setReadOnly(false);
                            LoadTextUtil.setCharsetWasDetectedFromBytes(file, null);
                            documentEx.replaceText(
                                LoadTextUtil.loadText(file), file.getModificationStamp());
                            documentEx.setReadOnly(!wasWritable);
                          }
                        });
              }
            },
            UIBundle.message("file.cache.conflict.action"),
            null,
            UndoConfirmationPolicy.REQUEST_CONFIRMATION);

    myUnsavedDocuments.remove(document);

    myMultiCaster.fileContentReloaded(file, document);
  }
  private void doSaveDocumentInWriteAction(@NotNull Document document, @NotNull VirtualFile file)
      throws IOException {
    if (!file.isValid()) {
      removeFromUnsaved(document);
      return;
    }

    if (!file.equals(getFile(document))) {
      registerDocument(document, file);
    }

    if (!isSaveNeeded(document, file)) {
      if (document instanceof DocumentEx) {
        ((DocumentEx) document).setModificationStamp(file.getModificationStamp());
      }
      removeFromUnsaved(document);
      updateModifiedProperty(file);
      return;
    }

    myMultiCaster.beforeDocumentSaving(document);

    LOG.assertTrue(file.isValid());

    String text = document.getText();
    String lineSeparator = getLineSeparator(document, file);
    if (!lineSeparator.equals("\n")) {
      text = StringUtil.convertLineSeparators(text, lineSeparator);
    }

    Project project = ProjectLocator.getInstance().guessProjectForFile(file);
    LoadTextUtil.write(project, file, this, text, document.getModificationStamp());

    myUnsavedDocuments.remove(document);
    LOG.assertTrue(!myUnsavedDocuments.contains(document));
    myTrailingSpacesStripper.clearLineModificationFlags(document);
  }
示例#4
0
  /** Make part of the run classpath. */
  private Path makeRunClasspathPart(Module module) {
    Path classpathPart = new Path(ProjectLocator.getAntProject());
    File targetClassesDir = module.getTargetClasses();
    classpathPart.createPathElement().setLocation(targetClassesDir);
    classpathPart.createPathElement().setLocation(module.getSrc());
    // System.out.println("RunClasspath:" + m + " " + m.getSrc());
    classpathPart.createPathElement().setLocation(module.getResourcesDir());
    classpathPart.createPathElement().setLocation(module.getConfigsDir());

    // see if we should add the 64 bit library to the classpath
    // NOTE: we want the 64 bit library directory in the classpath
    // since ptolemy.data.expr.UtilityFunctions.loadLibrary() searches
    // the classpath for a JNI library if it is not found in
    // java.library.path.
    if (LibPath.use64BitLibs()) {
      classpathPart.createPathElement().setLocation(module.getLib64Dir());
    }
    classpathPart.createPathElement().setLocation(module.getLibDir());
    classpathPart.createPathElement().setLocation(module.getLibImagesDir());

    // Add target jar if the target classes dir does not exist
    if (!targetClassesDir.exists()) {
      if (module.getTargetJar().exists()) {
        classpathPart.createPathElement().setLocation(module.getTargetJar());
      }
    }
    // End add target jar
    if (!module.getLibDir().exists()) {
      return classpathPart;
    }

    // Get jars from the lib directory.
    if (module.getLibDir().isDirectory()) {
      // use wildcards to reduce the size of the classpath.
      // this gets around the maximum path length on windows.
      DirSet jarDirs = new DirSet();
      jarDirs.setProject(ProjectLocator.getAntProject());
      jarDirs.setDir(module.getLibDir());
      jarDirs.setIncludes("**/*");
      Iterator<Resource> i = jarDirs.iterator();
      while (i.hasNext()) {
        Resource resource = i.next();
        if (resource instanceof FileResource) {
          File file = ((FileResource) resource).getFile();
          // System.out.println(file);
          if (file.isDirectory()) {
            File wildcardFile = new File(file, "*");
            classpathPart.createPathElement().setLocation(wildcardFile);
            // System.out.println("adding to cp: " + wildcardFile);
          }
        }
      }
    }
    // Add the jars in ptolemy, which are located in src/lib
    if (module.isPtolemy()) {
      File srcFile = module.getSrc();
      File srcLibDir = new File(srcFile, "lib");
      if (srcLibDir.isDirectory()) {
        File wildcardFile = new File(srcLibDir, "*");
        classpathPart.createPathElement().setLocation(wildcardFile);
      }
    }

    // add the workflow demos directory so that the demos may be accessed
    // by ptolemy.actor.gui.HTMLViewer when showing the Help documentation
    // see http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5194
    File userModuleWorkflowDir =
        new File(
            DotKeplerManager.getInstance().getPersistentModuleWorkflowsDirString()
                + File.separator
                + module.getName()
                + File.separator
                + "demos");

    File systemModuleDemoDir = module.getDemosDir();
    // NOTE: the first time kepler starts with a new version of a module,
    // the demos directories have not been copied into KeplerData. if
    // the demo directory exists for the module in the location where
    // kepler is installed, add the demo directory for where it will be
    // copied once kepler starts.
    // see http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5895
    if (systemModuleDemoDir.exists() && systemModuleDemoDir.isDirectory()) {

      // it appears that a directory needs to exist before it can be added
      // to the classpath
      if (!userModuleWorkflowDir.exists() && !userModuleWorkflowDir.mkdirs()) {
        PrintError.message("Could not create directory " + userModuleWorkflowDir);
      }
      classpathPart.createPathElement().setLocation(userModuleWorkflowDir);
    }
    return classpathPart;
  }