Skip to content

Commit ff91c27

Browse files
committed
Merge branch 'trycatch'
Conflicts: src/main/java/com/laytonsmith/core/functions/ArrayHandling.java
2 parents 0e2d5c8 + 29be7c7 commit ff91c27

File tree

184 files changed

+11242
-4724
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+11242
-4724
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ notifications:
44
channels:
55
- "irc.esper.net#CommandHelper"
66
sudo: false
7+
install: mvn test -Pfail-on-test-failures

pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,56 @@
823823
</reportPlugins>
824824
</configuration>
825825
</plugin>
826+
<plugin>
827+
<groupId>org.jacoco</groupId>
828+
<artifactId>jacoco-maven-plugin</artifactId>
829+
<version>0.7.1.201405082137</version>
830+
<configuration>
831+
<excludes>
832+
<!-- Application starter -->
833+
<exclude>ac/simons/biking2/Application.class</exclude>
834+
<!-- Configuration -->
835+
<exclude>ac/simons/biking2/config/*</exclude>
836+
</excludes>
837+
</configuration>
838+
<executions>
839+
<execution>
840+
<id>pre-unit-test</id>
841+
<goals>
842+
<goal>prepare-agent</goal>
843+
</goals>
844+
</execution>
845+
<execution>
846+
<id>post-unit-test</id>
847+
<phase>test</phase>
848+
<goals>
849+
<goal>report</goal>
850+
<goal>check</goal>
851+
</goals>
852+
<configuration>
853+
<rules>
854+
<!-- implmentation is needed only for Maven 2 -->
855+
<rule implementation="org.jacoco.maven.RuleConfiguration">
856+
<element>BUNDLE</element>
857+
<limits>
858+
<limit implementation="org.jacoco.report.check.Limit">
859+
<counter>INSTRUCTION</counter>
860+
<value>COVEREDRATIO</value>
861+
<minimum>0.01</minimum>
862+
</limit>
863+
<!-- implmentation is needed only for Maven 2 -->
864+
<limit implementation="org.jacoco.report.check.Limit">
865+
<counter>COMPLEXITY</counter>
866+
<value>COVEREDRATIO</value>
867+
<minimum>0.01</minimum>
868+
</limit>
869+
</limits>
870+
</rule>
871+
</rules>
872+
</configuration>
873+
</execution>
874+
</executions>
875+
</plugin>
826876
</plugins>
827877
</build>
828878
<profiles>
@@ -841,6 +891,12 @@
841891
</plugins>
842892
</build>
843893
</profile>
894+
<profile>
895+
<id>fail-on-test-failures</id>
896+
<properties>
897+
<maven.test.failure.ignore>false</maven.test.failure.ignore>
898+
</properties>
899+
</profile>
844900
</profiles>
845901
<pluginRepositories>
846902
<pluginRepository>

src/main/java/com/laytonsmith/PureUtilities/Common/ReflectionUtils.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import java.util.HashSet;
1111
import java.util.List;
1212
import java.util.Set;
13-
import java.util.logging.Level;
14-
import java.util.logging.Logger;
1513

1614
/**
1715
*
@@ -404,5 +402,23 @@ public static boolean hasMethod(Class<?> c, String methodName, Class returnType,
404402
return true;
405403
}
406404

405+
/**
406+
* Instantiates a class without calling its constructor. In general, the object
407+
* will be in an unknown state. This method should not generally be relied on, and
408+
* only used in limited cases.
409+
* @param cls The class to instantiate
410+
* @return The newly instantiated object.
411+
* @throws RuntimeException If the underlying code throws an InstantiationException, it is
412+
* wrapped and re-thrown in a RuntimeException.
413+
*/
414+
public static Object instantiateUnsafe(Class cls) throws RuntimeException{
415+
sun.misc.Unsafe unsafe = (sun.misc.Unsafe) ReflectionUtils.get(sun.misc.Unsafe.class, "theUnsafe");
416+
try {
417+
return unsafe.allocateInstance(cls);
418+
} catch(InstantiationException ex){
419+
// I mean, why not, we're already abusing things.
420+
throw new RuntimeException(ex);
421+
}
422+
}
407423

408424
}

src/main/java/com/laytonsmith/PureUtilities/Common/UIUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import java.net.URI;
1313
import java.net.URISyntaxException;
1414
import java.net.URL;
15-
import java.util.logging.Level;
16-
import java.util.logging.Logger;
1715

1816
/**
1917
* Provides common UI utilites

src/main/java/com/laytonsmith/abstraction/Convertor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import com.laytonsmith.commandhelper.CommandHelperPlugin;
1111
import com.laytonsmith.core.constructs.Target;
1212
import com.laytonsmith.core.environments.Environment;
13-
import com.laytonsmith.core.functions.Exceptions;
13+
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
1414

1515
import java.util.List;
1616
import java.util.concurrent.Callable;
@@ -191,7 +191,7 @@ public interface Convertor {
191191
* @param t
192192
* @return
193193
*/
194-
public MCColor GetColor(String colorName, Target t) throws Exceptions.FormatException;
194+
public MCColor GetColor(String colorName, Target t) throws CREFormatException;
195195

196196
/**
197197
* Returns a pattern object

src/main/java/com/laytonsmith/abstraction/ConvertorHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.laytonsmith.abstraction;
22

33
import com.laytonsmith.core.constructs.Target;
4-
import com.laytonsmith.core.functions.Exceptions;
4+
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
55

66
/**
77
* Some methods in Convertor can be abstract regardless of the server implementation,
@@ -10,11 +10,11 @@
1010
*/
1111
public class ConvertorHelper {
1212

13-
public static MCColor GetColor(String colorName, Target t) throws Exceptions.FormatException {
13+
public static MCColor GetColor(String colorName, Target t) throws CREFormatException {
1414
if(MCColor.STANDARD_COLORS.containsKey(colorName.toUpperCase())){
1515
return MCColor.STANDARD_COLORS.get(colorName.toUpperCase());
1616
} else {
17-
throw new Exceptions.FormatException("Unknown color type: " + colorName, t);
17+
throw new CREFormatException("Unknown color type: " + colorName, t);
1818
}
1919
}
2020

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
import com.laytonsmith.core.constructs.Target;
6565
import com.laytonsmith.core.environments.CommandHelperEnvironment;
6666
import com.laytonsmith.core.environments.Environment;
67-
import com.laytonsmith.core.functions.Exceptions;
67+
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
6868
import org.bukkit.Bukkit;
6969
import org.bukkit.Color;
7070
import org.bukkit.Location;
@@ -608,7 +608,7 @@ public MCPlugin GetPlugin() {
608608
}
609609

610610
@Override
611-
public MCColor GetColor(String colorName, Target t) throws Exceptions.FormatException {
611+
public MCColor GetColor(String colorName, Target t) throws CREFormatException {
612612
return ConvertorHelper.GetColor(colorName, t);
613613
}
614614

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCInventory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.laytonsmith.core.CHLog.Tags;
1212
import com.laytonsmith.core.LogLevel;
1313
import com.laytonsmith.core.constructs.Target;
14-
import com.laytonsmith.core.functions.Exceptions;
14+
import com.laytonsmith.core.exceptions.CRE.CRERangeException;
1515
import org.bukkit.entity.HumanEntity;
1616
import org.bukkit.entity.Player;
1717
import org.bukkit.inventory.Inventory;
@@ -53,7 +53,7 @@ public MCItemStack getItem(int slot) {
5353
+ " This is the fault of the server and can't be helped by "
5454
+ Implementation.GetServerType().getBranding() + ".", Target.UNKNOWN);
5555
} else {
56-
throw new Exceptions.RangeException("No slot " + slot + " exists in the given inventory", Target.UNKNOWN);
56+
throw new CRERangeException("No slot " + slot + " exists in the given inventory", Target.UNKNOWN);
5757
}
5858
return null;
5959
}
@@ -70,7 +70,7 @@ public void setItem(int slot, MCItemStack stack) {
7070
+ " This is the fault of the server and can't be helped by "
7171
+ Implementation.GetServerType().getBranding() + ".", Target.UNKNOWN);
7272
} else {
73-
throw new Exceptions.RangeException("No slot " + slot + " exists in the given inventory", Target.UNKNOWN);
73+
throw new CRERangeException("No slot " + slot + " exists in the given inventory", Target.UNKNOWN);
7474
}
7575
}
7676
if(this.i.getHolder() instanceof Player){

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCPotionMeta.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.laytonsmith.abstraction.MCPotionMeta;
55
import com.laytonsmith.core.Static;
66
import com.laytonsmith.core.constructs.Target;
7+
import com.laytonsmith.core.exceptions.CRE.CRERangeException;
78
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
8-
import com.laytonsmith.core.functions.Exceptions.ExceptionType;
99
import java.util.ArrayList;
1010
import java.util.List;
1111
import org.bukkit.inventory.meta.PotionMeta;
@@ -24,7 +24,7 @@ public BukkitMCPotionMeta(PotionMeta pomet) {
2424
public boolean addCustomEffect(int potionID, int strength, int seconds, boolean ambient, boolean overwrite, Target t) {
2525
int maxID = PotionEffectType.values().length;
2626
if (potionID < 1 || potionID > maxID) {
27-
throw ConfigRuntimeException.BuildException("Invalid effect ID, must be from 1-" + maxID, ExceptionType.RangeException, t);
27+
throw ConfigRuntimeException.BuildException("Invalid effect ID, must be from 1-" + maxID, CRERangeException.class, t);
2828
}
2929
PotionEffect pe = new PotionEffect(PotionEffectType.getById(potionID),
3030
(int) Static.msToTicks(seconds * 1000), strength, ambient);

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCWorld.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
import com.laytonsmith.core.constructs.CArray;
5656
import com.laytonsmith.core.constructs.CString;
5757
import com.laytonsmith.core.constructs.Target;
58+
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
5859
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
59-
import com.laytonsmith.core.functions.Exceptions.ExceptionType;
6060
import org.bukkit.Chunk;
6161
import org.bukkit.Effect;
6262
import org.bukkit.Location;
@@ -466,7 +466,7 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
466466
}
467467
} catch (IllegalArgumentException e) {
468468
throw ConfigRuntimeException.BuildException("No mob of type " + name + " exists",
469-
ExceptionType.FormatException, t);
469+
CREFormatException.class, t);
470470
}
471471
for (int i = 0; i < qty; i++) {
472472
MCEntity e = l.getWorld().spawn(l, mobType);
@@ -484,7 +484,7 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
484484
s.setColor(BukkitMCDyeColor.getConvertor().getConcreteEnum(color));
485485
} catch (IllegalArgumentException ex) {
486486
throw ConfigRuntimeException.BuildException(type + " is not a valid color",
487-
ExceptionType.FormatException, t);
487+
CREFormatException.class, t);
488488
}
489489
}
490490
}
@@ -497,7 +497,7 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
497497
o.setCatType(BukkitMCOcelotType.getConvertor().getConcreteEnum(otype));
498498
} catch (IllegalArgumentException ex){
499499
throw ConfigRuntimeException.BuildException(type + " is not an ocelot type",
500-
ExceptionType.FormatException, t);
500+
CREFormatException.class, t);
501501
}
502502
}
503503
}
@@ -515,7 +515,7 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
515515
}
516516
} catch (IllegalArgumentException ex){
517517
throw ConfigRuntimeException.BuildException(type + " is not a creeper state",
518-
ExceptionType.FormatException, t);
518+
CREFormatException.class, t);
519519
}
520520
}
521521
}
@@ -536,7 +536,7 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
536536
}
537537
} catch (IllegalArgumentException ex){
538538
throw ConfigRuntimeException.BuildException(type + " is not a wolf state",
539-
ExceptionType.FormatException, t);
539+
CREFormatException.class, t);
540540
}
541541
}
542542
}
@@ -549,7 +549,7 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
549549
v.setProfession(BukkitMCProfession.getConvertor().getConcreteEnum(job));
550550
} catch (IllegalArgumentException ex) {
551551
throw ConfigRuntimeException.BuildException(type + " is not a valid profession",
552-
ExceptionType.FormatException, t);
552+
CREFormatException.class, t);
553553
}
554554
}
555555
}
@@ -561,7 +561,7 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
561561
en.setCarriedMaterial(held);
562562
} catch (IllegalArgumentException ex) {
563563
throw ConfigRuntimeException.BuildException(type + " is not a valid material",
564-
ExceptionType.FormatException, t);
564+
CREFormatException.class, t);
565565
}
566566
}
567567
}
@@ -573,7 +573,7 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
573573
sl.setSize(Integer.parseInt(type));
574574
} catch (IllegalArgumentException ex){
575575
throw ConfigRuntimeException.BuildException(type + " is not a valid size",
576-
ExceptionType.FormatException, t);
576+
CREFormatException.class, t);
577577
}
578578
}
579579
}
@@ -587,7 +587,7 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
587587
sk.setSkeletonType(BukkitMCSkeletonType.getConvertor().getConcreteEnum(stype));
588588
} catch (IllegalArgumentException ex){
589589
throw ConfigRuntimeException.BuildException(type + " is not a skeleton type",
590-
ExceptionType.FormatException, t);
590+
CREFormatException.class, t);
591591
}
592592
}
593593
}
@@ -610,11 +610,11 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
610610
((PigZombie) z).setAnger(Integer.valueOf(type));
611611
} catch (IllegalArgumentException iae) {
612612
throw ConfigRuntimeException.BuildException(type + " was neither a zombie state nor a number.",
613-
ExceptionType.FormatException, t);
613+
CREFormatException.class, t);
614614
}
615615
} else {
616616
throw ConfigRuntimeException.BuildException(type + " is not a zombie state",
617-
ExceptionType.FormatException, t);
617+
CREFormatException.class, t);
618618
}
619619
}
620620
}
@@ -633,7 +633,7 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
633633
}
634634
} catch (IllegalArgumentException ex){
635635
throw ConfigRuntimeException.BuildException(type + " is not a pig state",
636-
ExceptionType.FormatException, t);
636+
CREFormatException.class, t);
637637
}
638638
}
639639
}
@@ -653,7 +653,7 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
653653
h.setStyle(BukkitMCHorse.BukkitMCHorsePattern.getConvertor().getConcreteEnum(hpattern));
654654
} catch (IllegalArgumentException notAnything) {
655655
throw ConfigRuntimeException.BuildException("Type " + type + " did not match any horse variants,"
656-
+ " colors, or patterns.", ExceptionType.FormatException, t);
656+
+ " colors, or patterns.", CREFormatException.class, t);
657657
}
658658
}
659659
}

0 commit comments

Comments
 (0)