From 260c927489cd2b1f03b88b9d7cc014233708c075 Mon Sep 17 00:00:00 2001 From: "Dr. Martin Goik" <goik@hdm-stuttgart.de> Date: Tue, 1 May 2018 20:55:02 +0200 Subject: [PATCH] Dependency exercise --- Doc/Sd1/objectsClasses.xml | 113 +++++++++++++++++++++++++++---------- 1 file changed, 82 insertions(+), 31 deletions(-) diff --git a/Doc/Sd1/objectsClasses.xml b/Doc/Sd1/objectsClasses.xml index 2d1446c29..ca801aa3a 100644 --- a/Doc/Sd1/objectsClasses.xml +++ b/Doc/Sd1/objectsClasses.xml @@ -5090,12 +5090,14 @@ Largest long value:9223372036854775807</screen></td> </tr> <tr> - <td valign="top"><programlisting language="java">package de.hdm_stuttgart.de.mi.sd1; - + <td valign="top"><programlisting language="java">package +de.hdm_stuttgart.de.mi.sd1; public class Helper { - static public long factorial(int n) { + static public long + factorial(int n) { long result = 1; - for (int i = 2; i <= n; i++) { + for (int i = 2; + i <= n; i++) { result *= i; } return result; @@ -5103,13 +5105,13 @@ public class Helper { }</programlisting></td> <td valign="top"><programlisting language="xml"><project xmlns="http://maven.apache.org...> - <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion> - <groupId>de.hdm_stuttgart.de.mi.sd1</groupId> - <artifactId>helper</artifactId> - <version>0.9</version> - <packaging>jar</packaging> - <name>helper</name> + <groupId><emphasis role="red">de.hdm_stuttgart.de.mi.sd1</emphasis></groupId> + <artifactId><emphasis role="red">helper</emphasis></artifactId> + <version><emphasis role="red">0.9</emphasis></version> + <packaging>jar</packaging> + <name>helper</name> ... </project></programlisting></td> </tr> @@ -5118,7 +5120,7 @@ public class Helper { <figure xml:id="sd1_fig_providerHelperPublish"> <title>Install project »<link - xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/tree/master/Doc/Sd1/Ref/ObjectsAndClasses/DependencyExample/Helper">helper</link>«</title> + xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/tree/master/Doc/Sd1/Ref/ObjectsAndClasses/DependencyExample/Helper">Helper</link>«</title> <screen>goik@goiki Helper> mvn install [INFO] Scanning for projects... @@ -5132,14 +5134,15 @@ Running de.hdm_stuttgart.de.mi.sd1.HelperTest Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, ... [INFO] Installing .../Helper/target/helper-0.9.jar to - <emphasis role="red">/ma/goik/.m2/repository/de/hdm_stuttgart/de/mi/sd1/helper/0.9/helper-0.9.jar</emphasis></screen> + /ma/goik/.m2/repository/<emphasis role="red">de/hdm_stuttgart/de/mi/sd1</emphasis>/<emphasis + role="red">helper</emphasis>/<emphasis role="red">0.9</emphasis>/helper-0.9.jar </screen> </figure> <figure xml:id="sd1_fig_archiveContent"> <title><filename>helper-0.9.jar</filename> archive content</title> - <screen>goik@goiki tmp> unzip /ma/goik/.m2/repository/de/hdm_stuttgart/de/mi/sd1/helper/0.9/helper-0.9.jar -Archive: /ma/goik/.m2/repository/de/hdm_stuttgart/de/mi/sd1/helper/0.9/helper-0.9.jar + <screen>goik@goiki tmp> unzip ...hdm_stuttgart/de/mi/sd1/helper/0.9/helper-0.9.jar +Archive: .../.m2/repository/.../sd1/helper/0.9/helper-0.9.jar creating: META-INF/ inflating: META-INF/MANIFEST.MF creating: de/ @@ -5157,9 +5160,9 @@ Archive: /ma/goik/.m2/repository/de/hdm_stuttgart/de/mi/sd1/helper/0.9/helper-0 <figure xml:id="sd1_fig_consumingProject"> <title>Consuming project »<link - xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/tree/master/Doc/Sd1/Ref/ObjectsAndClasses/DependencyExample/Lottery">lottery</link>«</title> + xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/tree/master/Doc/Sd1/Ref/ObjectsAndClasses/DependencyExample/Lottery">Lottery</link>«</title> - <programlisting language="xml"><project xmlns="http://maven.apache.org/POM/4.0.0" ...> + <programlisting language="none"><project xmlns="http://maven.apache.org/POM/4.0.0" ...> ... <groupId>de.hdm_stuttgart.mi.sd1</groupId> <artifactId>lottery</artifactId> @@ -5190,22 +5193,70 @@ Archive: /ma/goik/.m2/repository/de/hdm_stuttgart/de/mi/sd1/helper/0.9/helper-0 <title>Using <link xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/blob/master/Doc/Sd1/Ref/ObjectsAndClasses/DependencyExample/Helper/src/main/java/de/hdm_stuttgart/de/mi/sd1/Helper.java">Helper.factorial(...)</link></title> - <programlisting language="xml"><project xmlns="http://maven.apache.org/POM/4.0.0" ...> - ... - <groupId>de.hdm_stuttgart.mi.sd1</groupId> - <artifactId>lottery</artifactId> - <version>0.9</version> - <packaging>jar</packaging> - <name>lottery</name> - <dependencies> - <dependency> - <groupId><emphasis role="red">de.hdm_stuttgart.de.mi.sd1</emphasis></groupId> - <artifactId><emphasis role="red">helper</emphasis></artifactId> - <version><emphasis role="red">0.9</emphasis></version> - </dependency> -... -</project></programlisting> + <programlisting language="none">static public long binomial(int n, int k) { + return (Helper.<emphasis role="red">factorial(n)</emphasis> / Helper.<emphasis + role="red">factorial(k)</emphasis> + / Helper.<emphasis role="red">factorial(n - k)</emphasis>); +} + +<link xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/blob/master/Doc/Sd1/Ref/ObjectsAndClasses/DependencyExample/Lottery/src/main/java/de/hdm_stuttgart/mi/sd1/Lottery.java">public static void main(String[] args)</link> { + System.out.println("There are " + binomial(5, 2) + + " ways to draw 2 out of 5 numbers"); + + System.out.println("There are " + binomial(49, 6) + + " ways to draw 6 out of 49 numbers"); +}</programlisting> + </figure> + + <figure xml:id="sd1_fig_mavenRepositories"> + <title>Maven repositories</title> + + <glosslist> + <glossentry> + <glossterm>CDN</glossterm> + + <glossdef> + <para><link + xlink:href="https://mvnrepository.com/repos/central">Maven + Central</link></para> + </glossdef> + </glossentry> + + <glossentry> + <glossterm>Company local</glossterm> + + <glossdef> + <para><link + xlink:href="https://www.sonatype.com/nexus-repository-sonatype">Sonatype + Nexus</link>, e.g. <link + xlink:href="https://maven.mi.hdm-stuttgart.de/nexus/#browse/browse">MI + Maven repository</link></para> + </glossdef> + </glossentry> + </glosslist> </figure> + + <qandaset defaultlabel="qanda" xml:id="sd1_qanda_MavenLocalDependency"> + <title>Dealing with local Maven dependencies</title> + + <qandadiv> + <qandaentry> + <question> + <para>This exercise is actually a preparation for ongoing + exercises relying on importing local Maven artifacts.</para> + + <para>Follow this section's description and create two projects + A and B. Project B shall import some implementation from project + A as being previously described. If you lack an idea you may + just use the given <link + xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/tree/master/Doc/Sd1/Ref/ObjectsAndClasses/DependencyExample/Lottery">Lottery</link> + consuming <link + xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/tree/master/Doc/Sd1/Ref/ObjectsAndClasses/DependencyExample/Helper">Helper</link>. + </para> + </question> + </qandaentry> + </qandadiv> + </qandaset> </section> <section xml:id="ed1FractionCancel"> -- GitLab