Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Gradle & some Refactorings #929

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import java.nio.file.Files
plugins {
id 'application'
id 'com.github.jk1.dependency-license-report' version "2.0"
id "org.sonarqube" version "3.4.0.2513"
id "org.sonarqube" version "4.4.1.3373"
id 'org.openjfx.javafxplugin' version '0.0.13'
}

Expand Down Expand Up @@ -33,26 +33,31 @@ def jarName = 'MServer.jar'
def mainClass = 'mServer.Main'

dependencies {
implementation 'de.mediathekview:MLib:3.0.13'
compileOnly "com.sun.xml.ws:jaxws-rt:2.3.6"
compileOnly "org.glassfish.jaxb:jaxb-runtime:2.3.8"

implementation 'de.mediathekview:MLib:3.0.14'
implementation 'commons-net:commons-net:3.9.0'
implementation 'org.apache.commons:commons-compress:1.22'
implementation 'org.apache.commons:commons-compress:1.24.0'
implementation 'org.apache.commons:commons-text:1.10.0'
implementation 'org.tukaani:xz:1.9'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'org.glassfish.jersey.core:jersey-client:3.0.8'
implementation 'org.glassfish.jersey.inject:jersey-hk2:3.0.8'
implementation 'org.jsoup:jsoup:1.15.4'
implementation 'org.glassfish.jersey.core:jersey-client:3.1.3'
implementation 'org.glassfish.jersey.inject:jersey-hk2:3.1.3'
implementation 'org.jsoup:jsoup:1.16.1'
implementation 'javax.activation:activation:1.1.1'
implementation 'com.google.guava:guava:31.1-jre'
implementation 'com.google.guava:guava:32.0.0-jre'
implementation 'org.apache.logging.log4j:log4j-core:2.20.0'
implementation 'fm.void.jetm:jetm:1.2.3'


testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:4.11.0'
testImplementation 'org.mockito:mockito-core:5.4.0'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.10.0'
testImplementation "org.hamcrest:hamcrest-all:1.3"
testImplementation 'org.assertj:assertj-core:3.23.1'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation "com.sun.xml.ws:jaxws-rt:2.3.6"
testImplementation "org.glassfish.jaxb:jaxb-runtime:2.3.8"

}

Expand Down Expand Up @@ -174,7 +179,7 @@ processResources.dependsOn generateLicenseReport

[distZip, distTar]*.shouldRunAfter compileJava, updateVersion, jar
distTar.compression = Compression.GZIP
distTar.extension = 'tar.gz'
distTar.archiveExtension = 'tar.gz'

jar {
manifest {
Expand All @@ -183,7 +188,7 @@ jar {
'Class-Path': configurations.compileClasspath.files.collect { "lib/$it.name" }.join(' ')
)
}
archiveName = jarName
archiveFileName = jarName
}

distributions {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
25 changes: 17 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,11 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +198,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/mServer/crawler/FilmeSuchen.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public ArrayList<String> endeMeldung() {

// Durchschnittswerte ausgeben
double doub = (1.0 * listeSenderLaufen.get(RunSender.Count.SUM_TRAFFIC_BYTE)) / (sekunden == 0 ? 1 : sekunden) / 1000;
String rate = doub < 1 ? "<1" : String.format("%.1f", (doub));
String rate = doub < 1 ? "<1" : "%.1f".formatted((doub));
retArray.add(" -> Rate[kB/s]: " + rate);
retArray.add(" -> Dauer[Min]: " + (sekunden / 60 == 0 ? "<1" : sekunden / 60));
retArray.add(" -> Start: " + sdf.format(startZeit));
Expand Down Expand Up @@ -402,24 +402,24 @@ private void progressBar() {

private void notifyStart(ListenerFilmeLadenEvent event) {
for (Object l : listeners.getListenerList()) {
if (l instanceof ListenerFilmeLaden) {
((ListenerFilmeLaden) l).start(event);
if (l instanceof ListenerFilmeLaden laden) {
laden.start(event);
}
}
}

private void notifyProgress(ListenerFilmeLadenEvent event) {
for (Object l : listeners.getListenerList()) {
if (l instanceof ListenerFilmeLaden) {
((ListenerFilmeLaden) l).progress(event);
if (l instanceof ListenerFilmeLaden laden) {
laden.progress(event);
}
}
}

private void notifyFertig(ListenerFilmeLadenEvent event) {
for (Object l : listeners.getListenerList()) {
if (l instanceof ListenerFilmeLaden) {
((ListenerFilmeLaden) l).fertig(event);
if (l instanceof ListenerFilmeLaden laden) {
laden.fertig(event);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mServer/crawler/ListeRunSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public String getRate(String sender) {
long groesseByte = get(sender, RunSender.Count.SUM_TRAFFIC_BYTE);
if (groesseByte > 0 && dauerSender > 0) {
double doub = (1.0 * groesseByte / dauerSender / 1000); // kB/s
rate = doub < 1 ? "<1" : String.format("%.1f", (doub));
rate = doub < 1 ? "<1" : "%.1f".formatted((doub));
}
return rate;
}
Expand Down Expand Up @@ -169,12 +169,12 @@ public void getTextSum(ArrayList<String> retArray) {
String rate = "";
if (groesseByte > 0 && dauerSender > 0) {
double doub = (1.0 * groesseByte / dauerSender / 1000); // kB/s
rate = doub < 1 ? "<1" : String.format("%.1f", (doub));
rate = doub < 1 ? "<1" : "%.1f".formatted((doub));
}

String dauerProSeite = "";
if (anzahlSeiten > 0) {
dauerProSeite = String.format("%.2f", (1.0 * dauerSender / anzahlSeiten));
dauerProSeite = "%.2f".formatted((1.0 * dauerSender / anzahlSeiten));
}

// =================================
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mServer/crawler/sender/MediathekReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ protected void addFilm(DatenFilm film) {
private void setFileSize(DatenFilm film) {
// optimization for ORF and some others: don't try to determine filesize of m3u8-files
Optional<String> fileType = UrlUtils.getFileType(film.arr[DatenFilm.FILM_URL]);
if (!fileType.isPresent() || !fileType.get().equalsIgnoreCase("m3u8")) {
if (fileType.isEmpty() || !fileType.get().equalsIgnoreCase("m3u8")) {
film.setFileSize();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mServer/crawler/sender/ard/ArdCrawler.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private ConcurrentLinkedQueue<CrawlerUrlDTO> createDayUrlsToCrawl() {
private void addDayUrls(ConcurrentLinkedQueue<CrawlerUrlDTO> dayUrlsToCrawl, LocalDateTime day) {
final String formattedDay = day.format(DAY_PAGE_DATE_FORMATTER);
for (String client : ArdConstants.CLIENTS) {
final String url = String.format(ArdConstants.DAY_PAGE_URL, client, formattedDay, formattedDay, ArdConstants.DAY_PAGE_SIZE);
final String url = (ArdConstants.DAY_PAGE_URL).formatted(client, formattedDay, formattedDay, ArdConstants.DAY_PAGE_SIZE);
dayUrlsToCrawl.offer(new CrawlerUrlDTO(url));
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ private ConcurrentLinkedQueue<CrawlerUrlDTO> getTopicEntriesBySender(final Strin
private ConcurrentLinkedQueue<CrawlerUrlDTO> createTopicsOverviewUrl(final String client) {
final ConcurrentLinkedQueue<CrawlerUrlDTO> urls = new ConcurrentLinkedQueue<>();

final String url = String.format(ArdConstants.TOPICS_URL, client);
final String url = (ArdConstants.TOPICS_URL).formatted(client);

urls.add(new CrawlerUrlDTO(url));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void loadM3U8(Map<Qualities, URL> resolutionUrlMap) {
if (resolution.isPresent()) {
try {
String videoUrl = entry.getUrl();
if (!UrlUtils.getProtocol(videoUrl).isPresent()) {
if (UrlUtils.getProtocol(videoUrl).isEmpty()) {
videoUrl = baseUrl + videoUrl;
}
resolutionUrlMap.put(resolution.get(), new URL(videoUrl));
Expand All @@ -99,7 +99,7 @@ private static Optional<String> readContent(final URL aUrl) {
return Optional.of(body.string());
} else {
LOG.error(
String.format("ArdVideoInfoJsonDeserializer: Request '%s' failed: %s", aUrl, response.code()));
"ArdVideoInfoJsonDeserializer: Request '%s' failed: %s".formatted(aUrl, response.code()));
}
} catch (IOException ex) {
LOG.error("ArdVideoInfoJsonDeserializer: ", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void processRelatedFilms(final Set<ArdFilmInfoDto> relatedFilms) {
}

private String getWebsiteUrl(final ArdFilmInfoDto aDTO) {
return String.format(ArdConstants.WEBSITE_URL, aDTO.getId());
return (ArdConstants.WEBSITE_URL).formatted(aDTO.getId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private boolean isSuccessResponse(
LOG.error(logText);
});

return !error.isPresent();
return error.isEmpty();
}

private Response executeRequest(final WebTarget aTarget) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ArteCategoryFilmsDTO deserialize(JsonElement aJsonElement, Type aType, Js
if (programId.startsWith("RC-")) {
try {
long collectionId = Long.parseLong(programId.replace("RC-", ""));
dto.addCollection(String.format("RC-%06d", collectionId));
dto.addCollection("RC-%06d".formatted(collectionId));
} catch (NumberFormatException e) {
Log.errorLog(12834939, "Invalid collection id: " + programId);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mServer/crawler/sender/arte/ArteHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public static <T> T executeRequest(final String sender, Logger logger, Gson gson
stop = true;
} else {
if (response.code() != 429) {
logger.error(String.format("ARTE Request '%s' failed: %s", aUrl, response.code()));
Log.sysLog(String.format("ARTE Request '%s' failed: %s", aUrl, response.code()));
logger.error("ARTE Request '%s' failed: %s".formatted(aUrl, response.code()));
Log.sysLog("ARTE Request '%s' failed: %s".formatted(aUrl, response.code()));
FilmeSuchen.listeSenderLaufen.inc(sender, RunSender.Count.FEHLER);
stop = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Set<DatenFilm> call() throws Exception {
.registerTypeAdapter(ArteVideoDetailsDTO.class, new ArteVideoDetailsDeserializer(today))
.create();

String videosUrl = String.format(ARTE_VIDEO_INFORMATION_URL_PATTERN, programId, langCode);
String videosUrl = ARTE_VIDEO_INFORMATION_URL_PATTERN.formatted(programId, langCode);
ArteVideoDTO video = ArteHttpClient.executeRequest(senderName, LOG, gson, videosUrl, ArteVideoDTO.class);

if (video != null) {
Expand All @@ -76,7 +76,7 @@ public Set<DatenFilm> call() throws Exception {
if (video.getVideoUrls().containsKey(Qualities.NORMAL)) {
films.add(createFilm(details.getTheme(), details.getWebsite(), details.getTitle(), video.getVideoUrls(), details, durationAsTime, details.getDescription()));
} else {
Log.sysLog(String.format("%s: no normal video url found for film %s, but small/hd", senderName, programId));
Log.sysLog("%s: no normal video url found for film %s, but small/hd".formatted(senderName, programId));
FilmeSuchen.listeSenderLaufen.inc(senderName, RunSender.Count.FEHLER);
}
}
Expand All @@ -102,7 +102,7 @@ public Set<DatenFilm> call() throws Exception {
private ArteVideoDetailsDTO getVideoDetails(Gson gson, String programId) {

//https://api.arte.tv/api/opa/v3/programs/[language:de/fr]/[programId]
String videosUrlVideoDetails2 = String.format(ARTE_VIDEO_INFORMATION_URL_PATTERN_2, langCode, programId);
String videosUrlVideoDetails2 = ARTE_VIDEO_INFORMATION_URL_PATTERN_2.formatted(langCode, programId);
return ArteHttpClient.executeRequest(senderName, LOG, gson, videosUrlVideoDetails2, ArteVideoDetailsDTO.class);
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/mServer/crawler/sender/arte/MediathekArte.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void addToList() {
private void addCategories() {
senderLanguages.forEach((sender, langCode) -> {
for (String category : CATEGORIES) {
String categoryUrl = String.format(URL_CATEGORY, langCode.toLowerCase(), category);
String categoryUrl = URL_CATEGORY.formatted(langCode.toLowerCase(), category);
listeThemen.add(new String[]{sender, langCode, category, categoryUrl});
}
});
Expand All @@ -155,11 +155,11 @@ private void addTage() {
senderLanguages.forEach((sender, langCode) -> {
// http://www.arte.tv/guide/de/plus7/videos?day=-2&page=1&isLoading=true&sort=newest&country=DE
for (int i = 0; i <= 14; ++i) {
String u = String.format(ARTE_API_TAG_URL_PATTERN, langCode.toUpperCase(), LocalDate.now().minusDays(i).format(ARTE_API_DATEFORMATTER));
String u = ARTE_API_TAG_URL_PATTERN.formatted(langCode.toUpperCase(), LocalDate.now().minusDays(i).format(ARTE_API_DATEFORMATTER));
listeThemen.add(new String[]{sender, u});
}
for (int i = 1; i <= 21; ++i) {
String u = String.format(ARTE_API_TAG_URL_PATTERN, langCode.toUpperCase(), LocalDate.now().plusDays(i).format(ARTE_API_DATEFORMATTER));
String u = ARTE_API_TAG_URL_PATTERN.formatted(langCode.toUpperCase(), LocalDate.now().plusDays(i).format(ARTE_API_DATEFORMATTER));
listeThemen.add(new String[]{sender, u});
}
});
Expand Down Expand Up @@ -233,22 +233,22 @@ private void loadCategory(String sender, String langCode, String aCategory, Stri
ArteCategoryFilmsDTO dto = loadSubCategoryPage(gson, sender, aUrl);
if (dto != null) {
loadCollections(sender, langCode, gsonCollectionParent, gsonCollectionChild, dto);
Log.sysLog(String.format("%s: category %s: %d programs, %d collections", sender, aCategory, dto.getProgramIds().size(), dto.getCollectionIds().size()));
Log.sysLog("%s: category %s: %d programs, %d collections".formatted(sender, aCategory, dto.getProgramIds().size(), dto.getCollectionIds().size()));
// alle programIds verarbeiten
ListeFilme loadedFilme = loadPrograms(sender, langCode, dto);
loadedFilme.forEach(film -> addFilm(film));
Log.sysLog(String.format("%s: category %s: %d Filme", sender, aCategory, loadedFilme.size()));
Log.sysLog("%s: category %s: %d Filme".formatted(sender, aCategory, loadedFilme.size()));
}
}

private void loadCollections(String sender, String langCode, Gson gsonParent, Gson gsonChild, ArteCategoryFilmsDTO dto) {
dto.getCollectionIds().forEach(collectionId -> {
final String url = String.format(COLLECTION_URL, langCode, collectionId);
final String url = COLLECTION_URL.formatted(langCode, collectionId);
try {
final ArteCategoryFilmsDTO parentDto = ArteHttpClient.executeRequest(sender, LOG, gsonParent, url, ArteCategoryFilmsDTO.class);
if (parentDto != null) {
parentDto.getCollectionIds().forEach(childCollectionId -> {
final String urlChild = String.format(COLLECTION_URL, langCode, childCollectionId);
final String urlChild = COLLECTION_URL.formatted(langCode, childCollectionId);
final ArteCategoryFilmsDTO collectionDto = ArteHttpClient.executeRequest(sender, LOG, gsonChild, urlChild, ArteCategoryFilmsDTO.class);
if (collectionDto != null) {
collectionDto.getProgramIds().forEach(dto::addProgramId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void processElement(final D aUrlDTO) {
traceRequest();
processDocument(aUrlDTO, document);
} catch (final HttpStatusException httpStatusError) {
Log.sysLog(String.format(LOAD_DOCUMENT_HTTPERROR, crawler.getSendername(), aUrlDTO.getUrl()));
Log.sysLog(LOAD_DOCUMENT_HTTPERROR.formatted(crawler.getSendername(), aUrlDTO.getUrl()));

Log.errorLog(96459855,
crawler.getSendername() + ": crawlerDocumentLoadError: " + aUrlDTO.getUrl() + ", " + httpStatusError.getStatusCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static Optional<String> getElementString(final String aElementSelector1,
final Document aDocument) {

Optional<String> result = getElementString(aElementSelector1, aDocument);
if (!result.isPresent()) {
if (result.isEmpty()) {
result = getElementString(aElementSelector2, aDocument);
}

Expand Down
Loading
Loading