Part III: Creating a HcryptoJ Eclipse Project

From Notes

Jump to: navigation, search

Contents

Introduction

In this tutorial we will create an Eclipse project for HcryptoJ by cloning the Mercurial repository into Eclipse.

If you haven't already down so, you should complete the following tutorials:

Let's suppose that the repository that you have been working with the in the previous tutorials is a shared repository that you and other programmers will be contributing to. It's name is hcryptoj-hg-repo.

Creating an Eclipse Project from a Mercurial Repository

In Eclipse, choose: File > New > Other > Mercurial > Clone Existing Mercurial Repository. You should see something like this:

Browse to the shared Mercurial repository, hcryptoj-hg-repo. Eclipse will clone this repository and place the clone in your Eclipse workspace. That will be your personal copy of the cloned repository.

Adjusting the Build Path

If your project doesn't look like this after Eclipse finishes creating it, you may have to adjust your build path:

To adjust your build path, right click on the project in the Package Explorer and choose Build Path > Configure Build Path. This will bring up the following dialog window. Move the JRE library to the top of this list.


Because the Mercurial repository is also set up as a Java project, you should be able to run it by right clicking on it and selecting Run As > Java applications. Eclipse will then give you a list of all files in the package that contain a main() method. Choose the applications.cryptotoolj.CryptoToolJ class.

The Eclipse Project File

If there are problems compiling or running the project, it may be because the .project file is incorrect. Here is what it should look like:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
        <name>hcryptoj</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
                <buildCommand>
                        <name>org.eclipse.jdt.core.javabuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
        </buildSpec>
        <natures>
                <nature>org.eclipse.jdt.core.javanature</nature>
        </natures>
</projectDescription>

Exercise

One problem with the new ciphers we created in the previous exercise is that they don't ignore characters that are not in the cipher alphabet. So whereas they correctly encrypt and decrypt strings of lower case letters, they don't work properly for blank spaces, numbers and other characters.

Let's fix this by telling the cipher engine to skip characters that are not in the alphabet. Add the following code segments into the proper place in the engineEncode() and engineDecode() methods of the MySillyEngine.java class (or the Engine class that you created).

// Encode
if (!alphabet.isInAlphabet(ch))
    return s;

// Decode
if (!cipherAlphabet.isInAlphabet(ch))
    return s;

Committing Your Change

After you have correctly finished that task, commit your change by right clicking on the project name and choosing Commit from the Team menu. Eclipse will prompt you for the commit message.

To push your changes back to the original repository, hcrypto-hg-rep, you would use the Push command from the Team menu.

Setting up a Best Practices Workflow

It's very important that you follow these best practices.

  • Clone your main Eclipse repository to perform a particular coding task. When the task is completed and committed to the clone, push it back to your main Eclipse repository.
  • When you have changes to save with shared repository that is the source of your main Eclipse repository, push those changes.
  • Keep your commits small and focused.
Personal tools
NSF K-12