package: fail prs with certain api uses present

This commit is contained in:
Max Weber
2022-08-29 23:46:03 -06:00
parent c58e94c926
commit 79494b3bb4
6 changed files with 99 additions and 10 deletions

View File

@@ -74,7 +74,12 @@ public class API
public static API decode(InputStream is)
{
return new API(new BufferedReader(new InputStreamReader(new InflaterInputStream(is), StandardCharsets.UTF_8))
return decodePlain(new InflaterInputStream(is));
}
public static API decodePlain(InputStream is)
{
return new API(new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))
.lines()
.filter(line -> !line.isEmpty())
.collect(ImmutableSet.toImmutableSet()));
@@ -91,6 +96,12 @@ public class API
.filter(a -> !other.getApis().contains(a));
}
public Stream<String> in(API other)
{
return apis.stream()
.filter(a -> other.getApis().contains(a));
}
public static String modifiersToString(int modifiers, boolean member)
{
String s = "";

View File

@@ -183,7 +183,7 @@ public class Packager implements Closeable
try (Closeable ignored = acquireBuild(p))
{
p.build(runeliteVersion);
p.assembleManifest();
p.assembleManifest(alwaysPrintLog);
}
String logURL = "";
if (uploadConfig.isComplete())
@@ -262,11 +262,15 @@ public class Packager implements Closeable
}
}
@SneakyThrows
private void loadApi() throws IOException
{
diff.setOldManifestVersion(apiFilesVersion);
previousApi = calculateAPI();
}
@SneakyThrows
public static API calculateAPI() throws IOException
{
Process gradleApi = new ProcessBuilder(new File(PACKAGE_ROOT, "gradlew").getAbsolutePath(), "--console=plain", ":apirecorder:api")
.directory(PACKAGE_ROOT)
.inheritIO()
@@ -279,7 +283,7 @@ public class Packager implements Closeable
try (InputStream is = new FileInputStream(new File(PACKAGE_ROOT, "apirecorder/build/api")))
{
previousApi = API.decode(is);
return API.decode(is);
}
}

View File

@@ -120,6 +120,8 @@ public class Plugin implements Closeable
private static final File TMP_ROOT;
private static final File GRADLE_HOME;
private static final API DISALLOWED_API;
static
{
ImageIO.setUseCache(false);
@@ -134,6 +136,11 @@ public class Plugin implements Closeable
{
throw new RuntimeException("gradle home has moved");
}
try (InputStream is = Packager.class.getResourceAsStream("disallowed-apis.txt"))
{
DISALLOWED_API = API.decodePlain(is);
}
}
catch (IOException e)
{
@@ -516,7 +523,7 @@ public class Plugin implements Closeable
}
}
public void assembleManifest() throws IOException, PluginBuildException
public void assembleManifest(boolean disallowedFatal) throws IOException, PluginBuildException
{
manifest.setInternalName(internalName);
manifest.setCommit(commit);
@@ -663,7 +670,21 @@ public class Plugin implements Closeable
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (FileInputStream fis = new FileInputStream(apiFile))
{
API.encode(out, API.decode(fis).missingFrom(builtinApi.getApi()));
API api = API.decode(fis);
API.encode(out, api.missingFrom(builtinApi.getApi()));
String disallowed = DISALLOWED_API.in(api)
.collect(Collectors.joining("\n"));
if (!disallowed.isEmpty())
{
if (disallowedFatal)
{
throw PluginBuildException.of(this, "plugin uses terminally deprecated APIs:\n{}", disallowed);
}
else
{
writeLog("plugin uses terminally deprecated APIs:\n{}\n", disallowed);
}
}
}
Files.write(apiFile.toPath(), out.toByteArray());
}

View File

@@ -0,0 +1,3 @@
Lnet/runelite/api/Client;.getVar(I)I:ab
Lnet/runelite/api/Client;.getVar(Lnet/runelite/api/VarPlayer;)I:ab
Lnet/runelite/client/chat/ChatMessageManager;.update(Lnet/runelite/api/MessageNode;)V:b

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2022 Abex
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.pluginhub.packager;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Collectors;
import net.runelite.pluginhub.apirecorder.API;
import org.junit.Assert;
import org.junit.Test;
public class DisallowedAPIsTest
{
@Test
public void testDisallowedExist() throws IOException
{
API api = Packager.calculateAPI();
API disallowed;
try (InputStream is = Packager.class.getResourceAsStream("disallowed-apis.txt"))
{
disallowed = API.decodePlain(is);
}
String missing = disallowed.missingFrom(api)
.collect(Collectors.joining("\n"));
Assert.assertEquals("", missing);
}
}

View File

@@ -76,7 +76,7 @@ public class PluginTest
try (Plugin p = createExamplePlugin("example"))
{
p.build(Util.readRLVersion());
p.assembleManifest();
p.assembleManifest(true);
}
}
@@ -90,7 +90,7 @@ public class PluginTest
props.setProperty("plugins", "com.nonexistent");
writeProperties(props, propFile);
p.build(Util.readRLVersion());
p.assembleManifest();
p.assembleManifest(true);
Assert.fail();
}
catch (PluginBuildException e)
@@ -110,7 +110,7 @@ public class PluginTest
props.setProperty("plugins", "");
writeProperties(props, propFile);
p.build(Util.readRLVersion());
p.assembleManifest();
p.assembleManifest(true);
Assert.fail();
}
catch (PluginBuildException e)
@@ -131,7 +131,7 @@ public class PluginTest
" implementation 'org.apache.httpcomponents:httpclient:4.5.13'");
Files.asCharSink(buildFile, StandardCharsets.UTF_8).write(buildSrc);
p.build(Util.readRLVersion());
p.assembleManifest();
p.assembleManifest(true);
Assert.fail();
}
catch (PluginBuildException e)