Notes about Eclipse and Ptolemy II

Contents

VersionControl

Synchronizing with the repository

  1. In the Navigator view scroll/open until you see the resource (directory or file) to be synchronized.
  2. Right click that resource and select Team->Synchronize With Repository...
  3. The Synchronize view should then be visible.
  4. Select the Incoming, Outgoing, or Incoming/Outgoing menu bar icon as appropriate

Restoring a file from the repository

  1. In the Navigator view scroll/open until you see the resource (directory or file) to be restored.
  2. Right click that resource and select Replace With->Latest From Head.

Copying Files

Usually, it is better to extend Java classes than to copy them, but sometimes copying files under Subversion is useful. To copy files, use the svn cp command. Do not drag and drop directories as the directories contain a .svn directory that will have settings for the source location. Instead, use svn cp. See also svn mv.

Debugging Tcl Tests

See Testing Ptolemy II for details.
  1. In Eclipse, go to Run -> Debug Configurations
  2. Select Java Application and then click the New icon.
  3. In the Main tab, set the "Name:" to ptjacl, in "Main class:", enter tcl.lang.Shell. If tcl.lang.Shell is not found, then be sure that $PTII/lib/ptlang.jar is in the class path of the project by right clicking on the project and selecting Properties > Java Build Path >> Libraries.
  4. Optional: In the Arguments tab, under "Program arguments", enter alljtests.tcl or any individual test tcl file. (E.g. SimpleDelay.tcl). Or, leave the "Program arguments" field blank and when ptjacl is running (see below), enter text in to the Eclipse console.
  5. Optional: In the Arguments tab, under "VM arguments", enter -Dptolemy.ptII.dir=your PtII directory
    (E.g. -Dptolemy.ptII.dir=c:/hyzheng/ptII).
    In case your directory path contains spaces, you need to use quotes. (E.g. -Dptolemy.ptII.dir="c:/my workspace/ptII").
  6. In the "Working directory:" pane, select "Other:", browse to the directory containing the tcl tests.
    (E.g. C:\hyzheng\ptII\ptolemy\domains\de\lib\test)
  7. Select Debug.
The nice thing of using Eclipse is that you can very easily locate where the exception is thrown by clicking the classes listed in the stack trace. You may further register a breakpoint to do more diagnosis.

Troubleshooting

Preferences

If you have already used Eclipse and you would like to start over with new projects and preferences, remove the workspace directory in the Eclipse directory. The workspace directory will only appear if you have already run Eclipse. Note that removing the workspace directory will cause Eclipse to 'forget' about any projects that you may have set up

Build Error: Assert cannot be resolved

If, when building, the Problem tab shows "Assert cannot be resolved", then the problem is that Junit is not being found.

Rebuilding Briefly flashes a window

If you have problems where clicking on build briefly flashes up a window, look in $PTII/.classpath for and empty exclusion that looks like ||

If you have problems with the classpath, look in the workspace/.metadata/log file that is in the directory where eclipse is installed. For more information about the .metadata directory, see below.

Eclipse takes a long time to start up

If Eclipse takes a long time to start up, then the problem could be a problem in your .metadata file.

Basically, when eclipse starts up, it might try to update H:/workspace/.metadata . The solution is covered in http://www.eclipse.org/documentation/html/plugins/org.eclipse.platform.doc.user/doc/tasks/running_eclipse.htm: The way I figured this out was by running Norton Antivirus and doing View -> File System Realtime Scan Statistics and then I noticed that my machine was updating H:/workspace/.metadata

I think I introduced the problem by clicking on the Eclipse.exe binary and selecting Pin to Start Menu. My solution was to remove the Eclipse bogus entry in the start menu and then create a shortcut, change Start in property and then pin that shortcut to my start menu.

Adding an actor in Eclipse

Based on text by Mehran Meschian. See also Adding An Actor to Ptolemy II at $PTII/doc/coding/addinganactor.htm.

In this example, we copy ptolemy/actor/lib/Ramp.java and create a new actor called Ramp2

  1. Open Eclipse and choose the work space that you have your Ptolemy project there (mine is PtII 8.1.devel)
  2. Open the PtII8.1.devel folder in eclipse and then open Ptolemy -> actor -> lib -> string
  3. In string folder copy the java class (our simple actor)
  4. Rename the java file to Bmh and debug the errors that come because of this renaming.
  5. At the first line of the Java code add: package ptolemy.actor.lib.string;
  6. When there is no more error Run the java file and you should see a Bmh.class file in the tree as well (In the string branch). For now close the GUI window that opened after running.
  7. In the same place that Bmh.java and Bmh.class files exist, there is a string.xml file. Open it.
  8. At the top of the eclipse console, you should see two options: Design & Source. Click on Source to see the content of the xml
  9. Add the following bold and red text to the location in the xml file. Then save and run the xml file:
    <property name="_icon" class="ptolemy.vergil.icon.AttributeValueIcon">
              <property name="attributeName" value="function"/>
              <property name="displayWidth" value="11"/>
            </property>
          </entity>
    
          <entity name="Bmh" class="ptolemy.actor.lib.string.Bmh">
           <doc>Boyer Moore Horspool</doc>
          </entity>
    
          <entity name="StringIndexOf" class="ptolemy.actor.lib.string.StringIndexOf">
           <doc>Output the length of an input string</doc>
          </entity>
    
  10. Again in the same tree there is makefile. Open and add the following bold and red text to the location and save and run:
    PTDIST =        $(PTPACKAGE)$(PTVERSION)
    PTCLASSJAR = 	$(PTPACKAGE).jar
    
    # Keep this list alphabetized.
    JSRCS = \
            Bmh.java \
    	StringCompare.java \
    	StringFunction.java \
    	StringIndexOf.java \
    	StringLength.java \
    	StringMatches.java \
    
  11. Now, back to your Bmh.java and run it again. You should see the welcome window of Vergil.
  12. Now in the window, go to file- > New -> Graph editor. You should see a new window of graph editor.
  13. Go to Graph -> instantiate Entity. Then type Ptolemy.actor.lib.string.Bmh in the class name and you will see our Bmh actor in the window.
  14. Right click on the actor and choose Save Actor in Library. Now if you open the User Library (left side) you can see the Bmh actor there.
  15. In the case after all of these steps it doesn't work, restart your eclipse and make sure you have saved your xml file and there are Bmh.java and Bmh.class there. If again it doesn't work, there should be something wrong regarding your Ptolemy installation in eclipse. Hope not!!

Adding a File

See the style guide at $PTII/doc/coding/style_index.htm for details, but the main tasks are:
  1. Add the file to the makefile.
  2. Run ant. If the core of Ptolemy II depends on the new file, then it may be necessary to add the new file to $PTII/pt-modules/projects/pt-akore/pt-jar.files. This file is used to build the jar file uses for Eclipse Ptolemy modules.
  3. The ant rule will build the jar files.