Skip to content

Commit f6b5e08

Browse files
committed
Snoopin time
0 parents  commit f6b5e08

File tree

9 files changed

+1699
-0
lines changed

9 files changed

+1699
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This is a simple .gitignore for simple needs.
2+
3+
# To ignore files system-wide, use the global git setting core.excludesfile
4+
# For repo-specific ignoring, use .git/info/exclude
5+
# To ignore the opinions of others, cover your ears and scream "LA LA LA!"
6+
7+
# Maven makes this!
8+
/target

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

LICENSE_FILE_HEADER

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
SuperLooperSnooper
2+
Copyright (C) 2021 Matt Baxter
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SuperLooperSnooper
2+
==================
3+
4+
A simple Paper plugin to find dependency loops. Outputs findings after startup.

pom.xml

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.kitteh</groupId>
8+
<artifactId>superloopersnooper</artifactId>
9+
<version>1.0</version>
10+
<packaging>jar</packaging>
11+
12+
<name>SuperLooperSnooper</name>
13+
<description>Finds cyclical dependency issues</description>
14+
<url>https://kitteh.org</url>
15+
16+
<developers>
17+
<developer>
18+
<id>mbaxter</id>
19+
<name>Matt Baxter</name>
20+
<email>[email protected]</email>
21+
<url>https://kitteh.org</url>
22+
<organization>Kitteh</organization>
23+
<organizationUrl>https://kitteh.org</organizationUrl>
24+
<roles>
25+
<role>Lead Developer</role>
26+
<role>Cat Wrangler</role>
27+
</roles>
28+
</developer>
29+
</developers>
30+
31+
<licenses>
32+
<license>
33+
<name>GNU General Public License (GPL) version 3</name>
34+
<url>https://www.gnu.org/licenses/gpl-3.0.txt</url>
35+
</license>
36+
</licenses>
37+
38+
<issueManagement>
39+
<system>GitHub</system>
40+
<url>https://github.com/KittehOrg/SuperLooperSnooper/issues</url>
41+
</issueManagement>
42+
43+
<scm>
44+
<connection>scm:git:[email protected]:KittehOrg/SuperLooperSnooper.git</connection>
45+
<developerConnection>scm:git:[email protected]:KittehOrg/SuperLooperSnooper.git</developerConnection>
46+
<url>[email protected]:KittehOrg/SuperLooperSnooper.git</url>
47+
</scm>
48+
49+
<properties>
50+
<java.version>16</java.version>
51+
<jgrapht.version>1.5.1</jgrapht.version> <!-- Don't forget to check what Guava version it uses -->
52+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
53+
</properties>
54+
55+
<repositories>
56+
<repository>
57+
<id>papermc-repo</id>
58+
<url>https://papermc.io/repo/repository/maven-public/</url>
59+
</repository>
60+
</repositories>
61+
62+
<dependencies>
63+
<dependency>
64+
<groupId>io.papermc.paper</groupId>
65+
<artifactId>paper-api</artifactId>
66+
<version>1.17-R0.1-SNAPSHOT</version>
67+
<scope>provided</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.jgrapht</groupId>
71+
<artifactId>jgrapht-core</artifactId>
72+
<version>${jgrapht.version}</version>
73+
<scope>compile</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.jgrapht</groupId>
77+
<artifactId>jgrapht-guava</artifactId>
78+
<version>${jgrapht.version}</version>
79+
<scope>compile</scope>
80+
</dependency>
81+
<dependency>
82+
<groupId>com.google.guava</groupId>
83+
<artifactId>guava</artifactId>
84+
<version>29.0-jre</version>
85+
<scope>compile</scope>
86+
<exclusions>
87+
<exclusion>
88+
<groupId>org.checkerframework</groupId>
89+
<artifactId>checker-qual</artifactId>
90+
</exclusion>
91+
<exclusion>
92+
<groupId>com.google.code.findbugs</groupId>
93+
<artifactId>jsr305</artifactId>
94+
</exclusion>
95+
</exclusions>
96+
</dependency>
97+
</dependencies>
98+
99+
<build>
100+
<finalName>${project.name}</finalName>
101+
<resources>
102+
<resource>
103+
<directory>src/main/resources</directory>
104+
<filtering>true</filtering>
105+
</resource>
106+
</resources>
107+
<plugins>
108+
<plugin>
109+
<groupId>org.apache.maven.plugins</groupId>
110+
<artifactId>maven-compiler-plugin</artifactId>
111+
<version>3.8.1</version>
112+
<configuration>
113+
<release>${java.version}</release>
114+
</configuration>
115+
</plugin>
116+
<plugin>
117+
<groupId>org.apache.maven.plugins</groupId>
118+
<artifactId>maven-shade-plugin</artifactId>
119+
<version>3.3.0-SNAPSHOT</version>
120+
<executions>
121+
<execution>
122+
<phase>package</phase>
123+
<goals>
124+
<goal>shade</goal>
125+
</goals>
126+
<configuration>
127+
<createDependencyReducedPom>false</createDependencyReducedPom>
128+
<filters>
129+
<filter>
130+
<artifact>*:*</artifact>
131+
<excludes>
132+
<exclude>META-INF/MANIFEST.MF</exclude>
133+
</excludes>
134+
</filter>
135+
</filters>
136+
<relocations>
137+
<relocation>
138+
<pattern>com.google</pattern>
139+
<shadedPattern>org.kitteh.superloopersnooperlibs.com.google</shadedPattern>
140+
</relocation>
141+
<relocation>
142+
<pattern>org.jgrapht</pattern>
143+
<shadedPattern>org.kitteh.superloopersnooperlibs.org.jgrapht</shadedPattern>
144+
</relocation>
145+
<relocation>
146+
<pattern>org.jheaps</pattern>
147+
<shadedPattern>org.kitteh.superloopersnooperlibs.org.jheaps</shadedPattern>
148+
</relocation>
149+
</relocations>
150+
</configuration>
151+
</execution>
152+
</executions>
153+
</plugin>
154+
<plugin>
155+
<groupId>com.mycila</groupId>
156+
<artifactId>license-maven-plugin</artifactId>
157+
<version>3.0</version>
158+
<executions>
159+
<execution>
160+
<phase>clean</phase>
161+
<goals>
162+
<goal>format</goal>
163+
</goals>
164+
</execution>
165+
</executions>
166+
<configuration>
167+
<quiet>true</quiet>
168+
<encoding>UTF-8</encoding>
169+
<strictCheck>true</strictCheck>
170+
<header>${basedir}/LICENSE_FILE_HEADER</header>
171+
<mapping>
172+
<java>SLASHSTAR_STYLE</java>
173+
</mapping>
174+
<includes>
175+
<include>src/main/java/org/kitteh/**</include>
176+
</includes>
177+
</configuration>
178+
</plugin>
179+
</plugins>
180+
</build>
181+
</project>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* SuperLooperSnooper
3+
* Copyright (C) 2021 Matt Baxter
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
package org.kitteh.superloopersnooper;
19+
20+
import com.google.common.graph.GraphBuilder;
21+
import com.google.common.graph.MutableGraph;
22+
import org.bukkit.plugin.SimplePluginManager;
23+
import org.bukkit.plugin.java.JavaPlugin;
24+
import org.bukkit.scheduler.BukkitRunnable;
25+
import org.jgrapht.alg.cycle.JohnsonSimpleCycles;
26+
import org.jgrapht.graph.guava.MutableGraphAdapter;
27+
28+
import java.lang.reflect.Field;
29+
import java.lang.reflect.Method;
30+
import java.util.List;
31+
import java.util.Set;
32+
import java.util.logging.Level;
33+
34+
public final class SuperLooperSnooper extends JavaPlugin {
35+
private List<List<String>> cycles;
36+
private Exception exception;
37+
38+
@Override
39+
public void onLoad() {
40+
try {
41+
this.cycles = this.whee();
42+
} catch (Exception e) {
43+
this.exception = e;
44+
}
45+
}
46+
47+
@SuppressWarnings({"UnstableApiUsage", "unchecked"})
48+
private List<List<String>> whee() throws Exception {
49+
// Get original graph.
50+
// We need to convert to a newer guava, so this is all done via reflection
51+
// and the newer guava is relocated
52+
Field graphField = SimplePluginManager.class.getDeclaredField("dependencyGraph");
53+
graphField.setAccessible(true);
54+
Object originalGraph = graphField.get(this.getServer().getPluginManager());
55+
56+
// Get nodes
57+
Method methodNodes = originalGraph.getClass().getMethod("nodes");
58+
methodNodes.setAccessible(true);
59+
Set<String> nodes = (Set<String>) methodNodes.invoke(originalGraph);
60+
61+
// Successors method
62+
Method methodSuccessors = originalGraph.getClass().getMethod("successors", Object.class);
63+
methodSuccessors.setAccessible(true);
64+
65+
// New graph
66+
MutableGraph<String> graph = GraphBuilder.directed().build();
67+
68+
// New edges!
69+
for (String node : nodes) {
70+
Set<String> successors = (Set<String>) methodSuccessors.invoke(originalGraph, node);
71+
for (String successor : successors) {
72+
graph.putEdge(node, successor);
73+
}
74+
}
75+
76+
return new JohnsonSimpleCycles<>(new MutableGraphAdapter<>(graph)).findSimpleCycles();
77+
}
78+
79+
@Override
80+
public void onEnable() {
81+
new BukkitRunnable() {
82+
@Override
83+
public void run() {
84+
boolean ex = SuperLooperSnooper.this.exception != null;
85+
boolean empty = SuperLooperSnooper.this.cycles == null || SuperLooperSnooper.this.cycles.isEmpty();
86+
Level level = (empty && !ex) ? Level.INFO : Level.SEVERE;
87+
SuperLooperSnooper.this.getLogger().log(level, "");
88+
SuperLooperSnooper.this.getLogger().log(level, "Hello! I'm here to snoop for loops!");
89+
SuperLooperSnooper.this.getLogger().log(level, "");
90+
if (ex) {
91+
SuperLooperSnooper.this.getLogger().log(Level.SEVERE, " Unfortunately, I instead encountered an error!\n", SuperLooperSnooper.this.exception);
92+
return;
93+
}
94+
if (empty) {
95+
SuperLooperSnooper.this.getLogger().log(level, "Found no dependency loops! Yay!");
96+
return;
97+
}
98+
SuperLooperSnooper.this.getLogger().log(level, " Found dependency loops:");
99+
for (List<String> list : SuperLooperSnooper.this.cycles) {
100+
SuperLooperSnooper.this.getLogger().log(level, " " + list);
101+
}
102+
SuperLooperSnooper.this.getLogger().log(level, "");
103+
}
104+
}.runTaskLater(this, 40L);
105+
}
106+
}

src/main/resources/credit.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
This plugin contains the following:
2+
3+
JGraphT - https://github.com/jgrapht/jgrapht
4+
Licensed under the terms of the GNU Lesser General Public License (LGPL) 2.1 http://www.gnu.org/licenses/lgpl-2.1.html
5+
6+
JHeaps - https://github.com/d-michail/jheaps
7+
Licensed under the terms of the Apache License 2.0 https://www.apache.org/licenses/LICENSE-2.0
8+
9+
Guava - https://github.com/google/guava
10+
Licensed under the terms of the Apache License 2.0 https://www.apache.org/licenses/LICENSE-2.0
11+
12+
13+
This combined jar operates under the following terms:
14+
15+
SuperLooperSnooper
16+
Copyright (C) 2021 Matt Baxter
17+
18+
This program is free software: you can redistribute it and/or modify
19+
it under the terms of the GNU General Public License as published by
20+
the Free Software Foundation, either version 3 of the License, or
21+
(at your option) any later version.
22+
23+
This program is distributed in the hope that it will be useful,
24+
but WITHOUT ANY WARRANTY; without even the implied warranty of
25+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+
GNU General Public License for more details.
27+
28+
You should have received a copy of the GNU General Public License
29+
along with this program. If not, see <https://www.gnu.org/licenses/>.

0 commit comments

Comments
 (0)