MP1: Java and Build System Basics
The best way to learn software engineering is to practice software engineering in the actual software development process. Therefore, in this and the following MPs, you will work with a real-world project named Jsoup to learn basic concepts, methodologies, and techniques in software engineering.
Jsoup ( https://jsoup.org ) is a popular Java library for working with HTML. It provides a very convenient API for fetching URLs and extracting and manipulating data, using the best HTML5 DOM methods and CSS selectors.
Please make sure that you obtain the above Jsoup version before you start any of the MPs. You can use the same copy for all your MPs (i.e., you do not need to clone a fresh copy of the above Jsoup version for each MP). You can use Mac, Linux, or Windows to complete all the MPs (Mac/Linux will be recommended). You are also recommended to install the required software below before proceeding to the rest of MPs: •Java: 1.8+ –The Java tutorials: https://docs.oracle.com/javase/tutorial/ –Introduction to programming in Java: https://math.hws.edu/javanotes/index.html •Maven: 3.5+ –Maven in 5min: https://maven.apache.org/guides/getting-started/ maven-in-five-minutes.html –Maven getting started guide: https://maven.apache.org/guides/getting-started/ index.html •Ant: 1.10+ (needed only for MP1, not later MPs) –Ant manual: https://ant.apache.org/manual/ –Installation: ∗Mac:brew install ant ∗Windows & Linux https://ant.apache.org/manual/install.html •Gradle: 7.5+ (needed only for MP1, not later MPs) –Gradle manual: https://docs.gradle.org/current/userguide/userguide.html –Installation: ∗Mac:brew install Gradle ∗Linux :sdk install gradle 7.5.1 ∗Windows : https://stackoverflow.com/questions/34856932/ how-do-i-install-gradle-on-windows-10
2 Instructions for Ant
•Your build file should include the following steps (avoid including other steps, as this may interfere with the auto-grading): –Variable declarations : All the jar files used in the Maven build file have been downloaded for you and stored in the ant-libs directory. Inthepath declarationtag,introduce allthe jarfilesinthe”ant-libs” directory. Not including these jar files in the path declaration will fail the test execution. Use relativepaths to access the libs when building the project. Your path id in the Ant build file should be set to your NetID.classpath. –Compile all source Java files from src/main/java toant-target/classes . You can achieve this via modifying the build target from “scm-example”. Please make sure that you in- clude the encoding=”UTF-8” option for javac to avoid encoding issues on some specific OS settings. –Compile all test Java files from src/test/java toant-target/test-classes . You can achieve this via modifying the build-test target from “scm-example”. Please make sure that you include the encoding="UTF-8" option for javac to avoid encoding issues on some specific OS settings. –Copy all test resource files from src/test/resources toant-target/test-classes . You can either add this to the existing build-test target or define a new target. If you define a new target, make sure that the “test” target depends on the new target so that the tests can access the resource files. –Define the actual test execution target. You only need to change the classpath setting for thetest target from “scm-example”. Please change the report output directory (under junitreport tag in the build file) to ant-target/reports ; otherwise, the autograder may not be able to find the HTML report for your test execution and you may lose all your points. •You can test the correctness of written build files via the following commands: ant test Note that you may receive the “build successful” message in the command line, while your tests failed during execution. You should look into the test results to ensure the correct build and test execution (all the tests pass). You will get the full score only if the “success rate” in the HTML report is 100%. Ant does not print the test execution results by default. To obtain the number of test executions, you can check the corresponding HTML report: ant-target/reports/html/index.html (automatically generated once you follow the above instructions and correctly configure the report output directory under junitreport ). Please make sure that you can generate the HTML report under the specified report path; otherwise you may lose all the points. Figure 1: Example of an Ant test report where some tests fail because the test resources are not properly copied
3 Instructions for Gradle
•Your build file should include the following components: –Plugins : Identifies that the build is for a Java project. –Repositories : Use https://repo.maven.apache.org/maven2 to resolve all the required dependencies in the project. –Dependencies : You should specify the same dependency versions used in the Maven build file so that Gradle can automatically fetch them from the Maven repo, or directly use the downloaded jar files in the ant-libs directory. Failing to do so will result in exceptions while running the build file. –Description : The value for description should be your NetID ( description = ’Your NetID’ ) Figure 2: Example of a successful Ant build report (note the difference in the success rate) •You can test the correctness of written build files via the following commands: gradle test Note that you may receive the “build successful” message in the command line, while your tests failed during execution. You should look into the test results to ensure the correct build and test execution (all the tests pass). You will get the full score if the “success” in the HTML report is 100%. Like Ant, Gradle does not print the test execution results by default. To obtain the number of test executions, you can check the corresponding HTML report: gradle-target/reports/tests/test/index.html (default report directory for Gradle once you set the output directory to gradle-target ). Here is the example output for Gradle: Figure 3: A successful build results in 100% success for test execution in the report
You are expected to upload to this Campuswire assignment a zip file including only the build.xml and build.gradle files you completed (no folders please). The name of the zip file should be your NetID. The autograder will copy your zip file into the jsoup directory, unzip it, and run the build files. Failing to follow this structure may result in losing all the points. •Please DONOT useanyabsolutepaths in your solution since your absolute paths will not match our grading machines. Also, please only use“/” as the file separator in your relative paths (if needed for this MP) since Java will usually make the correct conversions if you use the Unix file separator “/” in relative paths (for both Windows and Unix-style systems). •Please make sure that you followthedetailed instruc tions to use the specified output direc- tories. The autograder will only look for the specified directories; thus you may lose all points if you fail to use the same directories (even if you can pass all tests).
5 Grading rubric
Overall score (5pt) •Ant build file (3pt): the autograder will check ant-target/reports/html/index.html –If you pass all 658 tests, you get 3pt –Else if you pass 600+ tests, you get 2pt –Else if you pass some tests, you get 1pt –Else you get 0pt •Gradle build file (2pt): the autograder will check gradle-target/reports/tests/test/index.html –If you pass all 658 tests, you get 2pt –Else if you pass 600+ tests, you get 1pt –Else you get 0pt