Skip to content

Commit ae5ed02

Browse files
author
Bram Inniger
committed
Refreshed project for the JF-2017-TUT course
1 parent c67cc93 commit ae5ed02

File tree

20 files changed

+580
-193
lines changed

20 files changed

+580
-193
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Maven
2-
target
2+
/target
3+
/dependency-reduced-pom.xml
34

45
# IntelliJ
5-
.idea
6-
*.iml
6+
/.idea
7+
/*.iml

.mvn/wrapper/maven-wrapper.jar

48.4 KB
Binary file not shown.

.mvn/wrapper/maven-wrapper.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip

README.md

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -31,60 +31,19 @@ Requirements
3131
4. A consumer's job is to keep taking in random inputs, checking if they produce a hash collision, and if so, record which input triggered the collision
3232
5. Do not manually manage your threads, recall Executors from previous lectures
3333
6. Keep the concurrent collections, and the synchronisers in mind discussed this lecture, and use them appropriately
34-
7. Absolutely do not use the following: any form of _Lock_, _synchronized_, _volatile_
35-
8. Unless really needed, try to avoid using the _Atomic\*_ classes
36-
9. Implement a clean shutdown mechanism. The Consumer and Producer are already supplied with a _shutdown()_ method, you **may** use this, or any other thread-safe, clean, shutdown mechanism
37-
10. Use the _Salt_ and _Hash_ classes to find the data you need to break
38-
11. Return a list of passwords, in the same order, so they correspond to the data in _Salt_ and _Hash_
39-
12. Do not add any new libraries, the ones in _pom.xml_ will certainly suffice to solve this
34+
7. Absolutely do not use the following: any form of `Lock`, `synchronized`, `volatile` or any other form of creative low-level locking (e.g. using `Semaphore(1)`)
35+
8. Unless really needed, try to avoid using the `Atomic\*` classes
36+
9. Implement a clean shutdown mechanism, after all 10 passwords are cracked, *cleanly* signal all consumers and producers to end their jobs, then *cleanly* wait for the executor(s) to properly shut down
37+
10. Use the `Salt` and `Hash` classes to find the data you need to break
38+
11. Return a list of passwords, in the same order, so they correspond to the data in `Salt` and `Hash`
39+
12. Do not add any new libraries, the ones in `pom.xml` will certainly suffice to solve this
4040
13. Be **absolutely completely positively** Thread Safe in **all** your operations (and look up the definition in doubt)
4141
14. Only store the very first valid password guess: if another consumer finds another valid hash, discard it
4242
15. Make an efficient program, at least make sure your implementation is faster than a single-threaded implementation
43-
16. Read up yourself on how to properly do consumer-producer design, and handle clean shutdowns, if needed. You are all University students, and do not need handholding for every single detail. "It was not covered in the lecture" is **not** a valid excuse.
43+
16. Read up yourself on how to properly do consumer-producer design, and handle clean shutdowns, if needed. You are all University students, and do not need handholding for every single detail. "It was not covered in the lecture" is **not** a valid excuse
4444

4545
Submitting your assignment
4646
--------------------------
4747

48-
For your convenience, we have set up the Maven project to ZIP up all files in your project folder so it is easy for you to attach it to an e-mail and send it our way. All you need to do is to execute the following command in your project folder:
49-
50-
```
51-
mvn clean deploy
52-
```
53-
54-
It will ask you for your full name, Student Book Number (also known as *matrikli number*), homework number and a comment (optional).
55-
56-
Example:
57-
58-
```bash
59-
mvn clean deploy
60-
61-
#...skipping building, testing and packaging output from Maven...
62-
63-
[INFO] --- maven-antrun-plugin:1.7:run (package homework ZIP) @ jf2016-hwX ---
64-
[INFO] Executing tasks
65-
66-
main:
67-
Your full name (e.g. John Smith):
68-
Jane Smith
69-
Your Student Book Number (matrikli number, e.g. B12345):
70-
B12345
71-
Homework number:
72-
1
73-
Comment:
74-
Java IO
75-
[zip] Building zip: /Users/jane/Workspaces/JF/jf-skeleton/target/jf-howework-B12345-1.zip
76-
[delete] Deleting: /Users/jane/Workspaces/JF/jf-skeleton/homework.properties
77-
[INFO] Executed tasks
78-
[INFO] ------------------------------------------------------------------------
79-
[INFO] BUILD SUCCESS
80-
[INFO] ------------------------------------------------------------------------
81-
[INFO] Total time: 45.028s
82-
[INFO] Finished at: Thu Aug 28 15:36:19 EEST 2014
83-
[INFO] Final Memory: 17M/99M
84-
[INFO] ------------------------------------------------------------------------
85-
```
86-
87-
After Maven has finished, you can find the generated ZIP file in *target* folder with name such as
88-
*jf-homework-B12345-1.zip* (it contains your Student Book Number/matrikli number and homework number).
89-
90-
Attach the ZIP to an e-mail and **send it our way**, to *[email protected]*.
48+
1. Run `./mvnw clean deploy`
49+
2. Send your solution to *[email protected]*

mvnw

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
#!/bin/sh
2+
# ----------------------------------------------------------------------------
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
# ----------------------------------------------------------------------------
20+
21+
# ----------------------------------------------------------------------------
22+
# Maven2 Start Up Batch script
23+
#
24+
# Required ENV vars:
25+
# ------------------
26+
# JAVA_HOME - location of a JDK home dir
27+
#
28+
# Optional ENV vars
29+
# -----------------
30+
# M2_HOME - location of maven2's installed home dir
31+
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
32+
# e.g. to debug Maven itself, use
33+
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34+
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35+
# ----------------------------------------------------------------------------
36+
37+
if [ -z "$MAVEN_SKIP_RC" ] ; then
38+
39+
if [ -f /etc/mavenrc ] ; then
40+
. /etc/mavenrc
41+
fi
42+
43+
if [ -f "$HOME/.mavenrc" ] ; then
44+
. "$HOME/.mavenrc"
45+
fi
46+
47+
fi
48+
49+
# OS specific support. $var _must_ be set to either true or false.
50+
cygwin=false;
51+
darwin=false;
52+
mingw=false
53+
case "`uname`" in
54+
CYGWIN*) cygwin=true ;;
55+
MINGW*) mingw=true;;
56+
Darwin*) darwin=true
57+
#
58+
# Look for the Apple JDKs first to preserve the existing behaviour, and then look
59+
# for the new JDKs provided by Oracle.
60+
#
61+
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
62+
#
63+
# Apple JDKs
64+
#
65+
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
66+
fi
67+
68+
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
69+
#
70+
# Apple JDKs
71+
#
72+
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
73+
fi
74+
75+
if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
76+
#
77+
# Oracle JDKs
78+
#
79+
export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
80+
fi
81+
82+
if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
83+
#
84+
# Apple JDKs
85+
#
86+
export JAVA_HOME=`/usr/libexec/java_home`
87+
fi
88+
;;
89+
esac
90+
91+
if [ -z "$JAVA_HOME" ] ; then
92+
if [ -r /etc/gentoo-release ] ; then
93+
JAVA_HOME=`java-config --jre-home`
94+
fi
95+
fi
96+
97+
if [ -z "$M2_HOME" ] ; then
98+
## resolve links - $0 may be a link to maven's home
99+
PRG="$0"
100+
101+
# need this for relative symlinks
102+
while [ -h "$PRG" ] ; do
103+
ls=`ls -ld "$PRG"`
104+
link=`expr "$ls" : '.*-> \(.*\)$'`
105+
if expr "$link" : '/.*' > /dev/null; then
106+
PRG="$link"
107+
else
108+
PRG="`dirname "$PRG"`/$link"
109+
fi
110+
done
111+
112+
saveddir=`pwd`
113+
114+
M2_HOME=`dirname "$PRG"`/..
115+
116+
# make it fully qualified
117+
M2_HOME=`cd "$M2_HOME" && pwd`
118+
119+
cd "$saveddir"
120+
# echo Using m2 at $M2_HOME
121+
fi
122+
123+
# For Cygwin, ensure paths are in UNIX format before anything is touched
124+
if $cygwin ; then
125+
[ -n "$M2_HOME" ] &&
126+
M2_HOME=`cygpath --unix "$M2_HOME"`
127+
[ -n "$JAVA_HOME" ] &&
128+
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
129+
[ -n "$CLASSPATH" ] &&
130+
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
131+
fi
132+
133+
# For Migwn, ensure paths are in UNIX format before anything is touched
134+
if $mingw ; then
135+
[ -n "$M2_HOME" ] &&
136+
M2_HOME="`(cd "$M2_HOME"; pwd)`"
137+
[ -n "$JAVA_HOME" ] &&
138+
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
139+
# TODO classpath?
140+
fi
141+
142+
if [ -z "$JAVA_HOME" ]; then
143+
javaExecutable="`which javac`"
144+
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
145+
# readlink(1) is not available as standard on Solaris 10.
146+
readLink=`which readlink`
147+
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
148+
if $darwin ; then
149+
javaHome="`dirname \"$javaExecutable\"`"
150+
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
151+
else
152+
javaExecutable="`readlink -f \"$javaExecutable\"`"
153+
fi
154+
javaHome="`dirname \"$javaExecutable\"`"
155+
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
156+
JAVA_HOME="$javaHome"
157+
export JAVA_HOME
158+
fi
159+
fi
160+
fi
161+
162+
if [ -z "$JAVACMD" ] ; then
163+
if [ -n "$JAVA_HOME" ] ; then
164+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
165+
# IBM's JDK on AIX uses strange locations for the executables
166+
JAVACMD="$JAVA_HOME/jre/sh/java"
167+
else
168+
JAVACMD="$JAVA_HOME/bin/java"
169+
fi
170+
else
171+
JAVACMD="`which java`"
172+
fi
173+
fi
174+
175+
if [ ! -x "$JAVACMD" ] ; then
176+
echo "Error: JAVA_HOME is not defined correctly." >&2
177+
echo " We cannot execute $JAVACMD" >&2
178+
exit 1
179+
fi
180+
181+
if [ -z "$JAVA_HOME" ] ; then
182+
echo "Warning: JAVA_HOME environment variable is not set."
183+
fi
184+
185+
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
186+
187+
# traverses directory structure from process work directory to filesystem root
188+
# first directory with .mvn subdirectory is considered project base directory
189+
find_maven_basedir() {
190+
local basedir=$(pwd)
191+
local wdir=$(pwd)
192+
while [ "$wdir" != '/' ] ; do
193+
if [ -d "$wdir"/.mvn ] ; then
194+
basedir=$wdir
195+
break
196+
fi
197+
wdir=$(cd "$wdir/.."; pwd)
198+
done
199+
echo "${basedir}"
200+
}
201+
202+
# concatenates all lines of a file
203+
concat_lines() {
204+
if [ -f "$1" ]; then
205+
echo "$(tr -s '\n' ' ' < "$1")"
206+
fi
207+
}
208+
209+
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
210+
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
211+
212+
# For Cygwin, switch paths to Windows format before running java
213+
if $cygwin; then
214+
[ -n "$M2_HOME" ] &&
215+
M2_HOME=`cygpath --path --windows "$M2_HOME"`
216+
[ -n "$JAVA_HOME" ] &&
217+
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
218+
[ -n "$CLASSPATH" ] &&
219+
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
220+
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
221+
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
222+
fi
223+
224+
# Provide a "standardized" way to retrieve the CLI args that will
225+
# work with both Windows and non-Windows executions.
226+
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
227+
export MAVEN_CMD_LINE_ARGS
228+
229+
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
230+
231+
# avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in $@
232+
exec "$JAVACMD" \
233+
$MAVEN_OPTS \
234+
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
235+
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
236+
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

0 commit comments

Comments
 (0)