You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.7 KiB
99 lines
3.7 KiB
package de.superx.libs; |
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
import java.io.File; |
|
import java.io.IOException; |
|
import java.nio.charset.StandardCharsets; |
|
import java.nio.file.Files; |
|
import java.util.ArrayList; |
|
import java.util.HashSet; |
|
import java.util.List; |
|
import java.util.Set; |
|
|
|
import org.junit.Assume; |
|
import org.junit.Test; |
|
|
|
/** |
|
* Verifies that all JAR files in the lib directories are declared in build.gradle. |
|
* |
|
* <p>Requires running {@code ./gradlew generateDeclaredJarsManifest} before this test, |
|
* which writes all declared JAR names to {@code superx-build/declared-jars.txt}. |
|
* If the manifest does not exist the test is silently skipped via {@link Assume} |
|
* so local developers without a prior Gradle run are not affected.</p> |
|
* |
|
* <p>Checked directories: |
|
* <ul> |
|
* <li>{@code superx/WEB-INF/lib/} — vollstaendig (alle direkten JARs)</li> |
|
* <li>{@code superx/WEB-INF/kettle-plugins/} — nur direkte JARs je Plugin-Dir, keine rekursivenSubdirs</li> |
|
* <li>{@code superx/WEB-INF/lib_ext/} wird bewusst nicht geprueft</li> |
|
* </ul> |
|
* </p> |
|
*/ |
|
public class DeclaredLibsTest { |
|
|
|
private static final String MANIFEST_PATH = "superx-build/declared-jars.txt"; |
|
|
|
private static final String LIB_DIR = "superx/WEB-INF/lib"; |
|
|
|
private static final String KETTLE_PLUGINS_DIR = "superx/WEB-INF/kettle-plugins"; |
|
|
|
@SuppressWarnings("static-method") |
|
@Test |
|
public void allJarsInLibDirsDeclaredInBuildGradle() throws IOException { |
|
File manifestFile = new File(MANIFEST_PATH); |
|
if (!manifestFile.exists()) { |
|
System.out.println("[DeclaredLibsTest] SKIP: Manifest '" + MANIFEST_PATH + "' nicht gefunden." |
|
+ " Bitte zuerst './gradlew generateDeclaredJarsManifest' ausfuehren."); |
|
} |
|
Assume.assumeTrue( |
|
"Manifest nicht gefunden – bitte zuerst './gradlew generateDeclaredJarsManifest' ausfuehren", |
|
manifestFile.exists() |
|
); |
|
|
|
Set<String> declaredJars = new HashSet<>( |
|
Files.readAllLines(manifestFile.toPath(), StandardCharsets.UTF_8) |
|
); |
|
|
|
List<String> undeclaredJars = new ArrayList<>(); |
|
|
|
File libDir = new File(LIB_DIR); |
|
if (libDir.exists()) { |
|
File[] files = libDir.listFiles(); |
|
if (files != null) { |
|
for (File f : files) { |
|
if (f.isFile() && f.getName().endsWith(".jar") && !declaredJars.contains(f.getName())) { |
|
undeclaredJars.add(LIB_DIR + "/" + f.getName()); |
|
} |
|
} |
|
} |
|
} |
|
|
|
// Kettle plugin dirs: only direct JARs in each plugin directory. |
|
// Transitive dependencies in lib/ subdirs are intentionally not tracked individually. |
|
File kettleDir = new File(KETTLE_PLUGINS_DIR); |
|
if (kettleDir.exists()) { |
|
File[] pluginDirs = kettleDir.listFiles(File::isDirectory); |
|
if (pluginDirs != null) { |
|
for (File pluginDir : pluginDirs) { |
|
File[] pluginFiles = pluginDir.listFiles(); |
|
if (pluginFiles == null) { |
|
continue; |
|
} |
|
for (File f : pluginFiles) { |
|
if (f.isFile() && f.getName().endsWith(".jar") && !declaredJars.contains(f.getName())) { |
|
undeclaredJars.add(pluginDir.getPath().replace('\\', '/') + "/" + f.getName()); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
assertTrue( |
|
"JARs gefunden, die NICHT in build.gradle deklariert sind" |
|
+ " – bitte in der passenden Configuration eintragen:\n " |
|
+ String.join("\n ", undeclaredJars), |
|
undeclaredJars.isEmpty() |
|
); |
|
} |
|
}
|
|
|