Skip to content

Commit

Permalink
Changes to load LastFM Key and LastFM secret dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemeri123 committed Jan 6, 2025
1 parent a803b7a commit c3fdc89
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,24 @@ ext {
mockitoVersion = '3.12.4'
mockitoAllVersion = '1.10.19'
targetDir = "src/main/java/com/josdem/jmetadata"
lastfmApiKey = project.hasProperty('lastfmApiKey') ? project.getProperty('lastfmApiKey') : null
lastfmApiSecret = project.hasProperty('lastfmApiSecret') ? project.getProperty('lastfmApiSecret') : null
}

// Task to package with credentials
tasks.register('prepareDist') {
doLast {
if (!lastfmApiKey || !lastfmApiSecret) {
throw new GradleException("LastFM API Key and Secret are required.")
}
println("Packaging with LastFM API credentials")
}
}

// Pass properties to the application
tasks.named('distZip') {
dependsOn 'prepareDist'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
Expand Down Expand Up @@ -97,4 +113,4 @@ test.dependsOn("spotlessApply")
tasks.register('settingCredentials') {
ant.replace(file: "${targetDir}/Auth.java", token: "LASTFM_API_KEY", value: "${LASTFM_API_KEY}")
ant.replace(file: "${targetDir}/Auth.java", token: "LASTFM_API_SECRET", value: "${LASTFM_API_SECRET}")
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/josdem/jmetadata/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
package com.josdem.jmetadata;

public interface Auth {
static final String KEY = "LASTFM_API_KEY";
static final String SECRET = "LASTFM_API_SECRET";
String KEY = System.getProperty("lastfM.api.key", System.getenv("LASTFM_API_KEY"));
String SECRET = System.getProperty("lastfm.api.secret", System.getenv("LASTFM_API_SECRET"));
}

0 comments on commit c3fdc89

Please sign in to comment.