Skip to content

Commit 46b566f

Browse files
committed
Merge branch 'master' of github.com:ago1024/WurmServerModLauncher into develop
2 parents 0fd419d + ce47184 commit 46b566f

File tree

10 files changed

+340
-25
lines changed

10 files changed

+340
-25
lines changed

modules/dist/pom.xml

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
<relativePath>../..</relativePath>
1414
</parent>
1515

16+
<pluginRepositories>
17+
<pluginRepository>
18+
<snapshots>
19+
<enabled>false</enabled>
20+
</snapshots>
21+
<id>bintray-cy6ergn0m-maven</id>
22+
<name>bintray-plugins</name>
23+
<url>http://dl.bintray.com/cy6ergn0m/maven</url>
24+
</pluginRepository>
25+
</pluginRepositories>
26+
1627
<dependencies>
1728
<dependency>
1829
<groupId>${project.groupId}</groupId>
@@ -126,7 +137,7 @@
126137
<plugins>
127138
<plugin>
128139
<artifactId>maven-assembly-plugin</artifactId>
129-
<version>2.6</version>
140+
<version>3.1.0</version>
130141
<executions>
131142
<execution>
132143
<id>make-assembly</id>
@@ -140,6 +151,7 @@
140151
</descriptors>
141152
<finalName>server-modlauncher-${project.version}</finalName>
142153
<appendAssemblyId>false</appendAssemblyId>
154+
<attach>false</attach> <!-- we pick it up with the groovy script below -->
143155
</configuration>
144156
</execution>
145157
<execution>
@@ -158,6 +170,68 @@
158170
</execution>
159171
</executions>
160172
</plugin>
173+
174+
<plugin>
175+
<groupId>org.codehaus.gmaven</groupId>
176+
<artifactId>groovy-maven-plugin</artifactId>
177+
<version>2.0</version>
178+
<dependencies>
179+
<dependency>
180+
<groupId>org.codehaus.groovy</groupId>
181+
<artifactId>groovy-all</artifactId>
182+
<version>2.0.6</version>
183+
</dependency>
184+
</dependencies>
185+
186+
<executions>
187+
<execution>
188+
<id>attach-modules</id>
189+
<phase>package</phase>
190+
<goals>
191+
<goal>execute</goal>
192+
</goals>
193+
<configuration>
194+
<properties>
195+
<path>${project.build.directory}/dist-${project.version}</path>
196+
</properties>
197+
<source>
198+
println 'Hello';
199+
println properties.path;
200+
println project.attachedArtifacts;
201+
def projectHelper = container.lookup("org.apache.maven.project.MavenProjectHelper")
202+
new File(properties.path).eachFile() { file ->
203+
projectHelper.attachArtifact(project, 'mod', file.name, file);
204+
}
205+
println project.attachedArtifacts;
206+
207+
</source>
208+
</configuration>
209+
</execution>
210+
</executions>
211+
212+
</plugin>
213+
214+
<plugin>
215+
<groupId>cy.github</groupId>
216+
<artifactId>github-release-plugin</artifactId>
217+
<version>0.5.1</version>
218+
219+
<configuration>
220+
<tagName>v${project.version}</tagName>
221+
<releaseTitle>Version v${project.version}</releaseTitle>
222+
<preRelease>true</preRelease>
223+
</configuration>
224+
225+
<executions>
226+
<execution>
227+
<id>github-upload</id>
228+
<goals>
229+
<goal>gh-upload</goal>
230+
</goals>
231+
<phase>deploy</phase>
232+
</execution>
233+
</executions>
234+
</plugin>
161235
</plugins>
162236
</build>
163237
</project>

modules/modlauncher/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
<version>4.12</version>
4141
<scope>test</scope>
4242
</dependency>
43+
<dependency>
44+
<groupId>org.assertj</groupId>
45+
<artifactId>assertj-core</artifactId>
46+
<version>3.8.0</version>
47+
<scope>test</scope>
48+
</dependency>
4349
</dependencies>
4450

4551
<properties>

modules/modlauncher/src/dist/modlauncher.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fi
66

77
if test -x "runtime/jre1.8.0_121/bin/java"; then
88
JAVA="runtime/jre1.8.0_121/bin/java"
9-
elif test -x "../runtime/jre1.8.0_1210/bin/java"; then
9+
elif test -x "../runtime/jre1.8.0_121/bin/java"; then
1010
JAVA="../runtime/jre1.8.0_121/bin/java"
1111
else
1212
JAVA="java"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.gotti.wurmunlimited.modsupport;
2+
3+
import org.gotti.wurmunlimited.modloader.DefrostingClassLoader;
4+
import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
5+
6+
import javassist.CannotCompileException;
7+
import javassist.NotFoundException;
8+
9+
/**
10+
* Create a NamedIdParser using the DefrostingClassLoader.
11+
* <p>
12+
* This means the class generated to read the names will be defrosted
13+
* after use and is available for further modifications
14+
*/
15+
public abstract class NonFreezingNamedIdParser extends NamedIdParser {
16+
17+
/**
18+
* Get the name of the class holding the names.
19+
* @return class name
20+
*/
21+
protected abstract String getNamesClassName();
22+
23+
@Override
24+
protected final Class<?> getNamesClass() {
25+
try (DefrostingClassLoader classLoader = new DefrostingClassLoader(HookManager.getInstance().getClassPool())) {
26+
return classLoader.loadClass(getNamesClassName());
27+
} catch (ClassNotFoundException | NotFoundException | CannotCompileException e) {
28+
throw new IllegalStateException(e);
29+
}
30+
}
31+
}
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
package org.gotti.wurmunlimited.modsupport.creatures;
22

3-
import org.gotti.wurmunlimited.modsupport.NamedIdParser;
4-
5-
import com.wurmonline.server.creatures.CreatureTemplateIds;
3+
import org.gotti.wurmunlimited.modsupport.NonFreezingNamedIdParser;
64

75
/**
86
* Parse a list of creature templates and creature template ids.
97
*/
10-
public class CreatureTemplateParser extends NamedIdParser {
8+
public class CreatureTemplateParser extends NonFreezingNamedIdParser {
119

1210
@Override
13-
protected Class<?> getNamesClass() {
14-
return CreatureTemplateIds.class;
11+
protected String getNamesClassName() {
12+
return "com.wurmonline.server.creatures.CreatureTemplateIds";
1513
}
1614

1715
@Override
1816
protected boolean isValidName(String fieldName) {
19-
return fieldName.endsWith("_cid");
17+
return fieldName.endsWith("_CID");
2018
}
2119

2220
@Override
2321
protected String cleanupFieldName(String fieldName) {
24-
return fieldName.replaceAll("_cid$", "");
22+
return fieldName.replaceAll("_CID$", "");
2523
}
2624

2725
@Override
2826
protected int unparsable(String name) {
29-
throw new IllegalArgumentException(name + "is not a valid CreatureTemplateId");
27+
throw new IllegalArgumentException(name + " is not a valid creature template id");
3028
}
3129
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package org.gotti.wurmunlimited.modsupport.creatures;
22

3-
import org.gotti.wurmunlimited.modsupport.NamedIdParser;
4-
5-
import com.wurmonline.server.creatures.CreatureTypes;
3+
import org.gotti.wurmunlimited.modsupport.NonFreezingNamedIdParser;
64

75
/**
86
* Parse a list of creature types and creature type ids.
97
*/
10-
public class CreatureTypesParser extends NamedIdParser {
8+
public class CreatureTypesParser extends NonFreezingNamedIdParser {
119

1210
@Override
13-
protected Class<?> getNamesClass() {
14-
return CreatureTypes.class;
11+
protected String getNamesClassName() {
12+
return "com.wurmonline.server.creatures.CreatureTypes";
1513
}
1614

1715
@Override
@@ -26,6 +24,6 @@ protected String cleanupFieldName(String fieldName) {
2624

2725
@Override
2826
protected int unparsable(String name) {
29-
throw new IllegalArgumentException(name + "is not a valid CreatureType");
27+
throw new IllegalArgumentException(name + " is not a valid creature type");
3028
}
3129
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
package org.gotti.wurmunlimited.modsupport.items;
22

3-
import org.gotti.wurmunlimited.modsupport.NamedIdParser;
4-
5-
import com.wurmonline.server.items.ItemList;
3+
import org.gotti.wurmunlimited.modsupport.NonFreezingNamedIdParser;
64

75
/**
86
* Parse a list of item names and ids.
97
*/
10-
public class ItemIdParser extends NamedIdParser {
8+
public class ItemIdParser extends NonFreezingNamedIdParser {
119

1210
@Override
13-
protected Class<?> getNamesClass() {
14-
return ItemList.class;
11+
protected String getNamesClassName() {
12+
return "com.wurmonline.server.items.ItemList";
1513
}
1614

1715
@Override
1816
protected int unparsable(String name) {
19-
throw new IllegalArgumentException(name + "is not a valid item name");
17+
throw new IllegalArgumentException(name + " is not a valid item name");
2018
}
2119
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.gotti.wurmunlimited.modsupport.creatures;
2+
3+
import org.assertj.core.api.Assertions;
4+
import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
5+
import org.junit.Before;
6+
import org.junit.Rule;
7+
import org.junit.Test;
8+
import org.junit.rules.ExpectedException;
9+
10+
import javassist.CtClass;
11+
import javassist.CtField;
12+
13+
public class CreatureTemplateParserTest {
14+
15+
private CreatureTemplateParser parser;
16+
17+
@Rule
18+
public ExpectedException thrown = ExpectedException.none();
19+
20+
@Before
21+
public void setup() {
22+
parser = new CreatureTemplateParser();
23+
}
24+
25+
/**
26+
* Simple test case. Parse a name
27+
*/
28+
@Test
29+
public void test() {
30+
Assertions.assertThat(parser.parse("troll king")).isEqualTo(27);
31+
}
32+
33+
/**
34+
* Simple test case. Parse an id
35+
*/
36+
@Test
37+
public void testId() {
38+
Assertions.assertThat(parser.parse("27")).isEqualTo(27);
39+
}
40+
41+
/**
42+
* Simple test case. Parse an invalid value
43+
*/
44+
@Test
45+
public void testInvalid() {
46+
thrown.expect(IllegalArgumentException.class);
47+
thrown.expectMessage("test is not a valid creature template id");
48+
Assertions.assertThat(parser.parse("test")).isEqualTo(37);
49+
}
50+
51+
/**
52+
* Test adding a new id after querying an id
53+
*/
54+
@Test
55+
public void testDefrosting() throws Exception {
56+
Assertions.assertThat(parser.parse("troll king")).isEqualTo(27);
57+
58+
// Add a new field
59+
CtClass ctIds = HookManager.getInstance().getClassPool().get("com.wurmonline.server.creatures.CreatureTemplateIds");
60+
ctIds.addField(CtField.make("public static final int TEST_CID = 37;", ctIds));
61+
62+
// Test that it works
63+
Assertions.assertThat(new CreatureTemplateParser().parse("test")).isEqualTo(37);
64+
65+
// test that same does not work on the old parser
66+
thrown.expect(IllegalArgumentException.class);
67+
thrown.expectMessage("test is not a valid creature template id");
68+
Assertions.assertThat(parser.parse("test")).isEqualTo(37);
69+
}
70+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.gotti.wurmunlimited.modsupport.creatures;
2+
3+
import org.assertj.core.api.Assertions;
4+
import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
5+
import org.junit.Before;
6+
import org.junit.Rule;
7+
import org.junit.Test;
8+
import org.junit.rules.ExpectedException;
9+
10+
import javassist.CtClass;
11+
import javassist.CtField;
12+
13+
public class CreatureTypesParserTest {
14+
15+
private CreatureTypesParser parser;
16+
17+
@Rule
18+
public ExpectedException thrown = ExpectedException.none();
19+
20+
@Before
21+
public void setup() {
22+
parser = new CreatureTypesParser();
23+
}
24+
25+
/**
26+
* Simple test case. Parse a name
27+
*/
28+
@Test
29+
public void test() {
30+
Assertions.assertThat(parser.parse("herd")).isEqualTo(10);
31+
}
32+
33+
/**
34+
* Simple test case. Parse an id
35+
*/
36+
@Test
37+
public void testId() {
38+
Assertions.assertThat(parser.parse("10")).isEqualTo(10);
39+
}
40+
41+
/**
42+
* Simple test case. Parse an invalid value
43+
*/
44+
@Test
45+
public void testInvalid() {
46+
thrown.expect(IllegalArgumentException.class);
47+
thrown.expectMessage("test is not a valid creature type");
48+
Assertions.assertThat(parser.parse("test")).isEqualTo(37);
49+
}
50+
51+
/**
52+
* Test adding a new id after querying an id
53+
*/
54+
@Test
55+
public void testDefrosting() throws Exception {
56+
Assertions.assertThat(parser.parse("herd")).isEqualTo(10);
57+
58+
// Add a new field
59+
CtClass ctIds = HookManager.getInstance().getClassPool().get("com.wurmonline.server.creatures.CreatureTypes");
60+
ctIds.addField(CtField.make("public static final int C_TYPE_TEST = 37;", ctIds));
61+
62+
// Test that it works
63+
Assertions.assertThat(new CreatureTypesParser().parse("test")).isEqualTo(37);
64+
65+
// test that same does not work on the old parser
66+
thrown.expect(IllegalArgumentException.class);
67+
thrown.expectMessage("test is not a valid creature type");
68+
Assertions.assertThat(parser.parse("test")).isEqualTo(37);
69+
}
70+
}

0 commit comments

Comments
 (0)