Author: kmorin Date: 2009-07-31 16:42:59 +0200 (Fri, 31 Jul 2009) New Revision: 1547 Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileParser.java trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java Log: Look in the source dirctory the guix files corresponding to tags without compiled classes Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-07-31 14:41:51 UTC (rev 1546) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-07-31 14:42:59 UTC (rev 1547) @@ -56,7 +56,7 @@ /** original list of files to compile */ protected final File[] files; /** original list of classes to compile */ - protected final String[] classNames; + protected final List<String> classNames = new ArrayList<String>(); /** Files to be treated while compilation. */ protected List<File> guixFiles = new ArrayList<File>(); /** Class names corresponding to the files in the guixFiles list. */ @@ -102,26 +102,30 @@ this.targetDirectory = targetDirectory; this.rootPackage = rootPackage != null ? rootPackage : ""; if (files != null) { - classNames = new String[files.length]; for (int i = 0; i < files.length; i++) { String path = files[i].getAbsolutePath(); if (baseDir != null) { - classNames[i] = (rootPackage.length() > 0 ? rootPackage + "." : "") + path.substring(baseDir.getAbsolutePath().length() + 1, - path.lastIndexOf('.')).replace(File.separatorChar, '.'); + classNames.add((rootPackage.length() > 0 ? rootPackage + "." : "") + path.substring(baseDir.getAbsolutePath().length() + 1, + path.lastIndexOf('.')).replace(File.separatorChar, '.')); } else { - classNames[i] = path.substring(0, path.lastIndexOf('.')); + classNames.add( path.substring(0, path.lastIndexOf('.'))); } } } - else { - classNames = null; - } this.mainClass = mainClass != null ? mainClass : ""; this.launcherName = launcherName != null ? launcherName : "Main"; this.generatorClass = generatorClass; } + public File getSrcDirectory() { + return srcDirectory; + } + + public File getTargetDirectory() { + return targetDirectory; + } + /** * Compiles a set of files. * @@ -134,7 +138,7 @@ log.info("Start compiling"); } guixFiles.addAll(Arrays.asList(files)); - guixFileClassNames.addAll(Arrays.asList(classNames)); + guixFileClassNames.addAll(classNames); boolean success = true; try { @@ -226,7 +230,7 @@ gen.setLastModification(rootModelObjects.get(mo)); gen.setMainClass((mo.getClassDescriptor().getPackageName() + "." + mo.getClassDescriptor().getName()).equals(mainClass)); gen.setSerializer(serializer); - gen.setClasses(Arrays.asList(classNames)); + gen.setClasses(classNames); gen.setLauncherName(launcherName); gen.setCSSFiles(mo.getCssFiles()); //generates the file without databinding @@ -475,4 +479,39 @@ } return result; } + + /** + * Adds a root GuixModelObject with its last modification time + * + * @param gmo the root GuixModelObject to add + * @param l its last modification time + */ + public void addRootModelObject(GuixModelObject gmo, Long l) { + rootModelObjects.put(gmo, l); + } + + public void addClassName(String className) { + if(!classNames.contains(className)) { + classNames.add(className); + } + } + + /** + * Ads a file to the compiled files list + * + * @param f the file to add + */ + public void addCompiledFile(File f) { + compiledFiles.add(f); + } + + /** + * Has the file f already been compiled + * + * @param f the file we'd like to know if it has already been compiled + * @return true if f has already been compiled + */ + public boolean isFileAlreadyCompiled(File f) { + return compiledFiles.contains(f); + } } Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java 2009-07-31 14:41:51 UTC (rev 1546) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java 2009-07-31 14:42:59 UTC (rev 1547) @@ -299,6 +299,32 @@ tagName = xpp.getName(); } + try { + Class.forName(tagPackageName + "." + tagName); + + } + catch(ClassNotFoundException eee) { + try { + File f = new File(launcher.getSrcDirectory(), tagPackageName.replace('.', File.separatorChar) + File.separatorChar + tagName + ".guix"); + if(!f.exists()) { + f = new File(launcher.getSrcDirectory(), tagPackageName.replace('.', File.separatorChar) + File.separatorChar + tagName + ".jaxx"); + } + if(f.exists() && !launcher.isFileAlreadyCompiled(f)) { + GuixCompiler gc = new GuixCompiler(f, launcher, tagPackageName); + GuixModelObject rootMO = gc.compile(); + launcher.addCompiledFile(f); + launcher.addClassName(tagPackageName + "." + tagName); + launcher.addRootModelObject(rootMO, gc.getLastModification()); + if (gc.isFailed()) { + failed = true; + } + } + } + catch(NullPointerException eeee) { + + } + } + String id = ((xpp.getAttributeValue("", "id") != null) ? xpp.getAttributeValue("", "id") : "_" + tagName + index++); Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileParser.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileParser.java 2009-07-31 14:41:51 UTC (rev 1546) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileParser.java 2009-07-31 14:42:59 UTC (rev 1547) @@ -19,8 +19,6 @@ package org.nuiton.guix.generator; import org.nuiton.guix.CompilerException; -import org.nuiton.guix.compiler.GuixCompiler; -import org.nuiton.guix.GuixLauncher; import org.nuiton.guix.parser.JavaParser; import org.nuiton.guix.parser.JavaParserTreeConstants; import org.nuiton.guix.parser.ParseException; Modified: trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java =================================================================== --- trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java 2009-07-31 14:41:51 UTC (rev 1546) +++ trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java 2009-07-31 14:42:59 UTC (rev 1547) @@ -42,7 +42,7 @@ GuixInitializer.initialize(); GuixLauncher gl = new GuixLauncher(null,null,null,null,null,null,null,null); - assertTrue(gl.files == null || gl.classNames.length == gl.files.length); + assertTrue(gl.files == null || gl.classNames.size() == gl.files.length); assertTrue(gl.compile()); assertTrue(gl.files == null || gl.rootModelObjects.size() == gl.files.length); @@ -51,7 +51,7 @@ File dir = new File("target/test"); File dir2 = new File(dir.getAbsolutePath()); gl = new GuixLauncher(new File[]{f2},dir2,"org.nuiton.guix",null,f2.getParentFile(),null,null,null); - assertTrue(gl.files == null || gl.classNames.length == gl.files.length); + assertTrue(gl.files == null || gl.classNames.size() == gl.files.length); assertTrue(gl.compile()); }