Skip to content

Commit

Permalink
ModuleDescriptorReader ceylon/ceylon-runtime#53: declare and propagat…
Browse files Browse the repository at this point in the history
…e exception
  • Loading branch information
FroMage committed May 6, 2014
1 parent 0959f1b commit cd6ae18
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/com/redhat/ceylon/common/ModuleDescriptorReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

Expand All @@ -37,7 +38,15 @@ public class ModuleDescriptorReader {
private Method moduleLicense;
private Method moduleAuthors;

public ModuleDescriptorReader(String moduleName, File srcDir) {
@SuppressWarnings("serial")
public static class NoSuchModuleException extends Exception {

public NoSuchModuleException(String string) {
super(string);
}
}

public ModuleDescriptorReader(String moduleName, File srcDir) throws NoSuchModuleException {
try {
Class<?> mdr = ModuleDescriptorReader.class.getClassLoader().loadClass("com.redhat.ceylon.compiler.ModuleDescriptorReader");
this.moduleVersion = mdr.getMethod("getModuleVersion");
Expand All @@ -51,6 +60,10 @@ public ModuleDescriptorReader(String moduleName, File srcDir) {
Constructor<?> constructor = mdr.getConstructor(String.class, File.class);
constructor.setAccessible(true);
this.instance = constructor.newInstance(moduleName, srcDir);
} catch (InvocationTargetException e) {
if(e.getCause() instanceof NoSuchModuleException)
throw (NoSuchModuleException)e.getCause();
throw new RuntimeException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit cd6ae18

Please sign in to comment.