repo-scripts/rules/MVN.php

60 lines
1.6 KiB
PHP

<?php
class MVN implements IRule
{
public function getMatchingExtensions(): array
{
return ["pom", "jar"];
}
public function processFile(string $file)
{
$pom = "";
$jar = "";
$base = "";
$ext = substr($file, strrpos($file, ".") + 1);
if ($ext == "jar") {
$jar = $file;
$pom = str_replace(".jar", ".pom", $file);
$base = basename($file, ".jar");
} else {
$pom = $file;
$jar = str_replace(".pom", ".jar", $file);
$base = basename($file, ".pom");
}
if (!file_exists($pom)) {
echo "File not found " . $pom . "\n";
return;
}
if (!file_exists($jar)) {
echo "File not found " . $jar . "\n";
return;
}
$xml = simplexml_load_file($pom);
$groupId = $xml->groupId;
$artifactId = $xml->artifactId;
$version = $xml->version;
$path = str_replace(".", "/", $groupId) . "/" . $artifactId . "/" . $version;
$dest = Config::$dest . "/maven/" . $path;
if (!file_exists($dest)) mkdir($dest, 0777, true);
if (file_exists($dest . "/" . $base . ".jar")) unlink($dest . "/" . $base . ".jar");
if (file_exists($dest . "/" . $base . ".pom")) unlink($dest . "/" . $base . ".pom");
foreach ([$jar, $pom] as $f) {
copy($f, $dest . "/" . basename($f));
file_put_contents($dest . "/" . basename($f) . ".md5", md5_file($f));
file_put_contents($dest . "/" . basename($f) . ".sha1", sha1_file($f));
unlink($f);
}
}
}