Upgrade to Pro — share decks privately, control downloads, hide ads and more …

cosee Tech Talk Open Source Libraries

cosee Tech Talk Open Source Libraries

Open Source einfach selbst machen

Michael Zinn

June 29, 2017
Tweet

More Decks by Michael Zinn

Other Decks in Programming

Transcript

  1. WER? Michael Zinn Java, Kotlin, JavaScript, TypeScript, CoffeeScript, PureScript, Ruby,

    Clojure, Haskell Funktionale Programmierung, Automatisierung, Cra manship Twitter/Github: RedNifre
  2. TECH TALKS Wann Was Wozu 2016 Kotlin Besseres Java 2016

    Funktionale Programmierung Besser Programmieren 2017 Open Source Libraries Besseres Code Reuse
  3. VORTEILE VON CODE REUSE: DRY: Don't Repeat Yourself Weniger Code

    → Weniger Bugs Bugs müssen nur an einer Stelle gefixt werden
  4. MIT LICENSE Tu was du willst. Verklag mich nicht. Copyright

    (c) <year> <copyright holders> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in al copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  5. LGPL Du darfst es benutzen ohne dass du deinen eigenen

    Code opensourcen musst. Du musst vom Code abgeleitete Werke unter der LGPL veröffentlichen. Von in der Library enthaltenen Klassen zu erben oder Interfaces zu implementieren erzeugt KEIN abgeleitetes Werk.
  6. GPL Die Library darf nur in Projekten verwendet werden die

    ebenfalls unter der GPL stehen (viral) Sinn: Das Open Source Ökosystem stärken In Firmen üblicherweise verboten
  7. GO

  8. 1. Maven Central Account erstellen 2. Sonatype Account erstellen 3.

    Beide Accounts verknüpfen 4. Einen PGP-Key erzeugen 5. Den Key auf einem öffentlichen Server hinterlegen 6. Javadoc schreiben 7. Sonatype-Jira Account erstellen 8. GroupId per Jira-Ticket beantragen 9. Artefakte signieren 10. Artefakte bei einem erlaubten Provider hosten 11. Library einreichen 12. Ein paar Tage warten 13. Formfehler beheben 14. Goto 11 15. Eine Ziege opfern
  9. o_O

  10. LIBRARY IN EINEM ANDEREN REPO? <dependencies> <dependency> <groupId>biz.cosee.null4j</groupId> <artifactId>null4j</artifactId> <version>0.9.0</version>

    </dependency> </dependencies> <repositories> <repository> <id>jcenter</id> <url>http://jcenter.bintray.com </url> </repository> </repositories>
  11. JCENTER Quasi wie Maven Central Kein Sonatype Kein Javadoc Keine

    Jira-Tickets Grauenha er, aber schaffbarer Approval-Prozess
  12. JFrog: JCenter hosts open source applications using the Maven naming

    convention which has 3 components. For example, a valid allocated path might be: org/apache/maven The path of the file you have requested to include is missing one of the components. Please update your JCenter inclusion path and we will be glad to approve the request. With Regards, JFrog Support
  13. JFrog: Hi, JCenter hosts java applications that follow maven convention.

    In addition to the jar and .pom files, your version should also include a sources jar, and optionally a javadoc jar. Your files should be under a maven path layout. (See ...) Once those files are added, we'll be glad to include your package in JCenter https://bintray.com/docs
  14. JFrog: We are not sure what is meant by a

    "step- by-step tutorial".
  15. JFrog: … Maven naming convention … 3 components… Please update

    your JCenter inclusion path… Michael: … doesn't biz/cosee/null4j have three parts already? JFrog: Your request to include your package… has been approved.
  16. BINTRAY Artefact Hoster (samt Versionierung) Kann PGP-Keys verwalten Kann in

    JCenter publishen Für Open-Source-Projekte kostenlos Erträgliche Website
  17. TRAVIS C I Baut Artefakte Kann die Artefakte nach Bintray

    schicken Für Open-Source-Projekte kostenlos Tatsächlich gute Website
  18. KLASSISCH 1. Maven Central Account erstellen 2. Sonatype Account erstellen

    3. Beide Accounts verknüpfen 4. Einen PGP-Key erzeugen 5. Den Key auf einem öffentlichen Server hinterlegen 6. Eine Ziege opfern 7. Javadoc schreiben 8. Sonatype-Jira Account erstellen 9. GroupId per Jira-Ticket beantragen 10. Artefakte signieren 11. Artefakte bei einem erlaubten Provider hosten 12. Library einreichen 13. Ein paar Tage warten
  19. BUILD.GRADLE apply plugin: 'maven-publish' publishing { publications { maven(MavenPublication) {

    from components.java pom.withXml { asNode().dependencies.'*'.findAll() { it.scope.text() == 'runtime' && project.configurations dep.name == it.artifactId.text() } }.each() { it.scope*.value = 'compile' } } } }
  20. .TRAVIS.YAML language: java jdk: - oraclejdk8 before_install: - chmod +x

    gradlew before_deploy: - ./gradlew generatePomFileForMavenPublication - ./gradlew sourcesJar deploy: provider: bintray file: "descriptor.json" user: $BINTRAY_API_USER key: $BINTRAY_API_KEY dry-run: false
  21. DESCRIPTOR.JSON { "package": { "name": "null4j", "repo": "null4j", "subject": "cosee",

    "desc": "Simplified null handling", "website_url": "https://github.com/cosee/null4j", "issue_tracker_url": "https://github.com/cosee/null4j/issues" "vcs_url": "https://github.com/cosee/null4j", "licenses": ["Apache-2.0"], "labels": ["java"], "public_download_numbers": false, "public_stats": false }, "version": { "name": "0.9.2",
  22. BOILERPLATE PER SCRIPT GENERIEREN? $ cd mylibrary $ sacrifice_goat.sh Generating

    descriptor.json... Generating .travis.yaml... Augmenting build.gradle... Done! $
  23. RAVR Portierung einer .js Library Ermöglicht gleichen Code im Frontend

    und Backend Gutes Einstiegsprojekt String names = doWith(stuffList, map(Stuff::getName), reverse(), join(", "));
  24. DAS NULL-PROBLEM class Example { String chop(String string) { return

    string.substring(0, string.length - 1); } void main() { String fail = chop(null); } } 1. String hat eine substring Methode 2. null ist ein String (null ist von jedem Typ) 3. null hat keine substring Methode
  25. DAS NULL-PROBLEM class Example { String chop(String string) { return

    string.substring(0, string.length - 1); } void main() { String fail = chop(null); } } 1. String hat eine substring Methode 2. null ist ein String (null ist von jedem Typ) 3. null hat keine substring Methode
  26. DAS NULL-PROBLEM class Example { String chop(String string) { if(string

    == null) { return null; // deal with it } else { return string.substring(0, string.length - 1); } } void main() { String fail = chop(null); } } 1. String hat eine substring Methode 2. null ist ein String (null ist von jedem Typ) 3. null hat keine substring Methode
  27. DAS NULL-PROBLEM class Example { String chop(String string) { return

    string.substring(0, string.length - 1); } void main() { String fail = chop(null); } } 1. String hat eine substring Methode 2. null ist ein String (null ist von jedem Typ) 3. null hat keine substring Methode
  28. DAS NULL-PROBLEM class Example { String chop(String string) { return

    string.substring(0, string.length - 1); } void main() { String fail = chop(null); } } 1. String hat eine substring Methode 2. null ist ein String (null ist von jedem Typ) 3. null hat keine substring Methode
  29. DAS NULL-PROBLEM class Example { String chop(String string) { return

    string.substring(0, string.length - 1); } void main() { String fail = chop(Optional.empty());❌ } } 1. String hat eine substring Methode 2. Optional<String> ist ein String 3. Optional<String> hat keine substring Methode
  30. DAS NULL-PROBLEM class Example { @NotNull String chop(@NotNull String string)

    { return string.substring(0, string.length - 1); } void main() { @NotNull String fail = chop(null);❌ } } 1. @NotNull String hat eine substring Methode 2. null ist ein @Nullable String, aber KEIN @NotNull String 3. @Nullable String hat keine substring Methode
  31. NULL4J @NotNullByDefault class Example { String chop(String string) { return

    string.substring(0, string.length - 1); } void main() { String fail = chop(null);❌ } } 1. String hat eine substring Methode 2. null ist ein @Nullable String, aber KEIN String 3. @Nullable String hat keine substring Methode
  32. NULL4J Löst ein konkretes Problem Wenige, einfache, aber mächtige Funktionen

    (Nur orDefault und let, die aber kombinierbar sind) Ausführliche README, da es auch von anderen genutzt werden soll return orDefault(let(person, Person::getAddress, Address::getStreet, Street::getName), "?NO STREET NAME");
  33. JAVA STREAM API -> EXSTREAM return stream(users, flatMap(user -> user.getAccounts()),

    sorted(comparing(Account::getId)), collect(toList()));
  34. EXSTREAM Bietet nichts fundamental neues Vereinfacht bereits existierende Funktionalität //

    Viel Boilerplate Stuff return users.stream() .flatMap(user -> user.getAccounts().stream()) .sorted(Comparators.comparing(Account::getId)) .collect(Collectors.toList()); // Weniger BS return stream(users, flatMap(User::getAccounts), sortBy(Account::getId));
  35. ZUSAMMENFASSUNG Passende Lizenz aussuchen! Github → TravisCI → Bintray →

    JCenter Durchbeißen! (Oder andere Sprache benutzen) Lieblings-Libraries aus anderen Sprachen portieren Probleme lösen Programmieren angenehmer gestalten
  36. EOF