THINK FIRST·CODE LATER

← All labs

Third-party notices generator

Problem

Permissive licences require that copyright and licence notices travel with the product. Generate StudyBuddy's THIRD-PARTY NOTICES screen.

Input: lines component|version|licence|copyright holder until the end of input (fields separated by |; the copyright holder may contain spaces and may be empty).

Output:

  1. THIRD-PARTY NOTICES and an empty line.
  2. Components grouped by licence, licences in alphabetical order; within a licence, components in alphabetical order (case-insensitive). For each licence print == LICENCE == and then one line per component: component version - Copyright (c) holder.
  3. After the groups, an empty line and Problems: with one line per problem, in input order: - component: missing copyright holder (empty holder) or - component: unknown licence (licence UNKNOWN) — or Problems: none (on the same line).

Components with licence UNKNOWN are not listed in the groups.

Input:

gson|2.10.1|Apache-2.0|Google Inc.
jsoup|1.17.2|MIT|Jonathan Hedley
Commons-Text|1.10.0|Apache-2.0|The Apache Software Foundation
tinyjson|0.3|UNKNOWN|

Output:

THIRD-PARTY NOTICES

== Apache-2.0 ==
Commons-Text 1.10.0 - Copyright (c) The Apache Software Foundation
gson 2.10.1 - Copyright (c) Google Inc.
== MIT ==
jsoup 1.17.2 - Copyright (c) Jonathan Hedley

Problems:
- tinyjson: missing copyright holder
- tinyjson: unknown licence

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

s12-2-data-1.txt

gson|2.10.1|Apache-2.0|Google Inc.
jsoup|1.17.2|MIT|Jonathan Hedley
Commons-Text|1.10.0|Apache-2.0|The Apache Software Foundation
tinyjson|0.3|UNKNOWN|
What your program must print for s12-2-data-1.txt
THIRD-PARTY NOTICES

== Apache-2.0 ==
Commons-Text 1.10.0 - Copyright (c) The Apache Software Foundation
gson 2.10.1 - Copyright (c) Google Inc.
== MIT ==
jsoup 1.17.2 - Copyright (c) Jonathan Hedley

Problems:
- tinyjson: missing copyright holder
- tinyjson: unknown licence

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < s12-2-data-1.txt

Windows PowerShell does not understand <:

Get-Content s12-2-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.