packager: block use of net.runelite namespace

This commit is contained in:
Rhea
2025-12-04 16:17:29 -05:00
parent d1706421b9
commit d1f5b09fd5
2 changed files with 32 additions and 1 deletions

View File

@@ -714,6 +714,12 @@ public class Plugin implements Closeable
.withFile(fileName);
}
if (name != null && name.startsWith("net/runelite/"))
{
throw PluginBuildException.of(Plugin.this, "use of net.runelite package namespace is not allowed")
.withFile(fileName);
}
jarClasses.add(name.replace('/', '.'));
extendsPlugin = "net/runelite/client/plugins/Plugin".equals(superName);

View File

@@ -136,6 +136,31 @@ public class PluginTest
}
}
@Test
public void testNetRuneLitePackage() throws InterruptedException, DisabledPluginException, PluginBuildException, IOException
{
try (Plugin p = createExamplePlugin("net-runelite-package"))
{
File pluginClassFile = new File(p.repositoryDirectory, "src/main/java/com/example/TestExamplePlugin.java");
String pluginClassSrc = Files.asCharSource(pluginClassFile, StandardCharsets.UTF_8).read();
pluginClassSrc = pluginClassSrc.replace("package com.example;", "package net.runelite;");
Files.asCharSink(pluginClassFile, StandardCharsets.UTF_8).write(pluginClassSrc);
File configClassFile = new File(p.repositoryDirectory, "src/main/java/com/example/TestExampleConfig.java");
String configClassSrc = Files.asCharSource(configClassFile, StandardCharsets.UTF_8).read();
configClassSrc = configClassSrc.replace("package com.example;", "package net.runelite;");
Files.asCharSink(configClassFile, StandardCharsets.UTF_8).write(configClassSrc);
p.build(Util.readRLVersion(), true);
Assert.fail();
}
catch (PluginBuildException e)
{
assertContains(e.getMessage(), "use of net.runelite package namespace is not allowed");
log.info("ok: ", e);
}
}
private static void writeProperties(Properties props, File fi) throws IOException
{
try (FileOutputStream fos = new FileOutputStream(fi))
@@ -191,4 +216,4 @@ public class PluginTest
{
Assert.assertTrue(haystack, haystack.contains(needle));
}
}
}