Merge pull request #740 from abextm/pkg2plus

package: include update times and require licenses
This commit is contained in:
Abex
2020-11-05 20:13:46 -07:00
committed by GitHub
3 changed files with 57 additions and 1 deletions

View File

@@ -33,11 +33,13 @@ import com.google.common.hash.Hashing;
import com.google.common.io.ByteStreams;
import com.google.common.io.MoreFiles;
import com.google.common.io.RecursiveDeleteOption;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.MalformedURLException;
@@ -108,6 +110,8 @@ public class Plugin implements Closeable
}
}
private final File pluginCommitDescriptor;
@Getter
private final String internalName;
@@ -140,6 +144,7 @@ public class Plugin implements Closeable
public Plugin(File pluginCommitDescriptor) throws IOException, DisabledPluginException, PluginBuildException
{
this.pluginCommitDescriptor = pluginCommitDescriptor;
internalName = pluginCommitDescriptor.getName();
if (!PLUGIN_INTERNAL_NAME_TEST.matcher(internalName).matches())
{
@@ -552,6 +557,48 @@ public class Plugin implements Closeable
writeLog("warning: unused props in runelite-plugin.properties: {}\n", props.keySet());
}
}
realPluginChecks();
}
// Tests don't run this as the example plugin will fail these on purpose
protected void realPluginChecks() throws IOException, PluginBuildException
{
{
Process gitlog = new ProcessBuilder("git", "log", "--follow", "--format=%ct", "--", pluginCommitDescriptor.getAbsolutePath())
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.appendTo(logFile))
.directory(pluginCommitDescriptor.getParentFile())
.start();
try (BufferedReader br = new BufferedReader(new InputStreamReader(gitlog.getInputStream())))
{
String line = br.readLine();
manifest.setLastUpdatedAt(Long.parseLong(line));
String lastLine = line;
for (; (line = br.readLine()) != null; )
{
lastLine = line;
}
manifest.setCreatedAt(Long.parseLong(lastLine));
}
waitAndCheck(gitlog, "git log ", 30, TimeUnit.SECONDS);
}
if (!new File(repositoryDirectory, "LICENSE").exists())
{
if (manifest.getLastUpdatedAt() < 1604534400)
{
writeLog("Missing LICENSE file. This will become fatal in the future\n");
}
else
{
throw PluginBuildException.of(this, "Missing LICENSE file")
.withHelp("All plugins must be licensed under a license that allows us to freely distribute the plugin jar standalone.\n" +
"We recommend the BSD 2 Clause license.");
}
}
}
public void upload(UploadConfiguration uploadConfig) throws IOException

View File

@@ -115,7 +115,13 @@ public class PluginTest
try
{
Files.asCharSink(f, StandardCharsets.UTF_8).write(desc);
return new Plugin(f);
return new Plugin(f)
{
@Override
protected void realPluginChecks()
{
}
};
}
finally
{

View File

@@ -38,6 +38,9 @@ public class ExternalPluginManifest
private int size;
private String[] plugins;
private long createdAt;
private long lastUpdatedAt;
private String displayName;
private String version;
private String author;