mirror of
https://github.com/runelite/plugin-hub.git
synced 2025-12-23 22:48:49 -05:00
packager: block use of net.runelite namespace
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user