Package com.envoisolutions.sxc.builder

Examples of com.envoisolutions.sxc.builder.BuildException


        try {
            jaxbEnumClass = builderContext.getCodeModel()._class(className);
            jaxbEnumClass._extends(builderContext.getCodeModel().ref(JAXBEnum.class).narrow(type));
        } catch (JClassAlreadyExistsException e) {
            throw new BuildException(e);
        }

        // INSTANCE variable
        JFieldVar instanceVar = jaxbEnumClass.field(JMod.PUBLIC | JMod.STATIC | JMod.FINAL, jaxbEnumClass, "INSTANCE", JExpr._new(jaxbEnumClass));
View Full Code Here


                }
               
            };
           
        } catch (Exception e) {
            throw new BuildException(e);
        }
    }
View Full Code Here

                dir.mkdirs();
                write(dir);
               
               
            } catch (IOException e) {
                throw new BuildException(e);
            }
        }
       
        ClassLoader cl = compiler.compile(file);
View Full Code Here

       
        try {
            writerClass = model._class(getContextClassName());
            writerClass._implements(GeneratedWriter.class);
        } catch (JClassAlreadyExistsException e) {
            throw new BuildException(e);
        }
       
        method = writerClass.method(JMod.PUBLIC | JMod.FINAL, void.class, "write");
        addBasicArgs(method);
        objectVar = method.param(Object.class, "o");
View Full Code Here

        model = buildContext.getCodeModel();
        try {
            readerClass = model._class(getContextClassName());
            readerClass._implements(GeneratedReader.class);
        } catch (JClassAlreadyExistsException e) {
            throw new BuildException(e);
        }
       
        method = readerClass.method(JMod.PUBLIC | JMod.FINAL, Object.class, "read");
       
        addBasicArgs(method);
View Full Code Here

            boolean accessibility = field.isAccessible();
            field.setAccessible(true);
            field.set(method, type);
            field.setAccessible(accessibility);
        } catch (Exception e) {
            throw new BuildException(e);
        }
    }
View Full Code Here

        map.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
       
        EclipseJavaCompiler compiler = new EclipseJavaCompiler(settings);
        
        if (!dir.exists()) {
            throw new BuildException("Compilation directory does not exist!");
        }
       
        FileResourceReader reader = new FileResourceReader(dir);
       
        List<String> classes = new ArrayList<String>();
        for (String s : reader.list()) {
            String name = AbstractJavaCompiler.convertResourceNameToClassName(s);
            name = name.replace('/', '.');
            name = name.replace('\\', '.');
           
            classes.add(name);
        }
       
        MemoryResourceStore store = new MemoryResourceStore();
        CompilationResult result
            = compiler.compile(classes.toArray(new String[classes.size()]), reader, store);
       
        CompilationProblem[] errors = result.getErrors();
        for (CompilationProblem p : errors) {
            System.out.println(p.getMessage());
        }
       
        // TODO throw better errors!
        if (errors.length > 0) {
            throw new BuildException("Could not compile generated files!");
        }
       
        return new ResourceStoreClassLoader(Thread.currentThread().getContextClassLoader(),
                                            new ResourceStore[] { store });
    }
View Full Code Here

        try {
            String tmpdir = System.getProperty("java.io.tmpdir");
            File classDir = new File(new File(tmpdir), "classes" + hashCode() + System.currentTimeMillis());

            if (!classDir.mkdir()) {
                throw new BuildException("Could not create output directory.");
            }
            ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
            Set<URL> urlSet = getClasspathURLs(oldCl);
            String classpath = createClasspath(urlSet);

            URLClassLoader newCL = createNewClassLoader();
           
            String[] args = {srcDir.getAbsolutePath() + "/generated/sxc/Reader.java",
                             srcDir.getAbsolutePath() + "/generated/sxc/Writer.java",
                             "-g",
                             "-d", classDir.getAbsolutePath(),
                             "-classpath", classpath,
                             "-sourcepath", srcDir.getAbsolutePath()};

            // System.out.println("Args: " + Arrays.toString(args));

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            PrintWriter writer = new PrintWriter(bos);
            int i;
            try {
                Class<?> main = newCL.loadClass("com.sun.tools.javac.Main");
                Method method = main.getMethod("compile", new Class[] {String[].class, PrintWriter.class});
                i = (Integer)method.invoke(null, new Object[] {args, writer});
            } catch (ClassNotFoundException e1) {
                throw new BuildException("Could not find javac compiler!", e1);
            } catch (Exception e) {
                throw new BuildException("Could not invoke javac compiler!", e);
            }

            if (i != 0) {
                writer.close();
               
                System.out.println(bos.toString());
               
                throw new BuildException("Could not compile generated files! Code: " + i);
            }

            Thread.currentThread().setContextClassLoader(oldCl);
            URLClassLoader cl = new URLClassLoader(new URL[] {classDir.toURL()}, oldCl);
            try {
                cl.loadClass("generated.sxc.Reader");
                cl.loadClass("generated.sxc.Writer");
            } catch (ClassNotFoundException e) {
                throw new BuildException("Could not load generated classes.", e);
            }

            Util.delete(classDir);

            return cl;

        } catch (IOException e) {
            throw new BuildException(e);
        }

    }
View Full Code Here

        File toolsJar = new File(System.getProperty("java.home"), "../lib/tools.jar");
        if (toolsJar.exists()) {
            try {
                urls = new URL[] { toolsJar.toURL() };
            } catch (MalformedURLException e) {
                throw new BuildException("Could not convert the file reference to tools.jar to a URL, path to tools.jar: '"
                                                + toolsJar.getAbsolutePath() + "'.");
            }
        } else {
            urls = new URL[0];
        }
View Full Code Here

TOP

Related Classes of com.envoisolutions.sxc.builder.BuildException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.