Author: tchemit Date: 2008-08-10 15:18:09 +0000 (Sun, 10 Aug 2008) New Revision: 827 Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java Log: fix bug : can not use Class.forname on uncompiled classes Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java 2008-08-10 13:14:47 UTC (rev 826) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java 2008-08-10 15:18:09 UTC (rev 827) @@ -43,6 +43,8 @@ import javax.tools.JavaFileObject; import javax.tools.StandardLocation; import java.io.BufferedWriter; +import java.io.File; +import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -133,20 +135,22 @@ if ((roundEnv.processingOver())) { printDebug("round is over " + roundEnv); try { - if (providerConfig == null) { + if (providerConfig != null) { + // found the base action class to be compiled, so we have to write provider things... + writeProviderClass(); + writeProviderServiceDeclaration(); + } else { + // baseActionClass was not compiled at this time, must find it back + // this means they should have an already mapping file written - findProviderConfigFromCompiledClass(); + actionsFileLocation = findMappingFile(); - if (providerConfig == null) { - throw new IllegalStateException("no provider name found, you must add on baseaction the annotation " + ActionProviderAnnotation.class); - } - actionsFileLocation = String.format(actionsFileLocation, providerConfig.name()); - } else { - writeProviderClass(); - writeProviderServiceDeclaration(); + printInfo("reused actionFilesLocation " + actionsFileLocation); } + writeActionMapping(); + } catch (Exception e) { throw new RuntimeException(e); } finally { @@ -158,8 +162,36 @@ return true; } + protected String findMappingFile() throws IOException { + String path = String.format(actionsFileLocation, "dummy_" + System.nanoTime()); + + + FileObject oldFo = processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, "", path); + File dummyFile = new File(oldFo.toUri().toString()).getParentFile(); + File[] files = dummyFile.listFiles(new FilenameFilter() { + + public boolean accept(File dir, String name) { + return name.startsWith("jaxx-") && name.endsWith("-actions.properties"); + } + }); + if (files.length < 1) { + // this is not normal, should have exactly one file here + throw new IllegalStateException("no provider name found, you must add on baseaction the annotation " + ActionProviderAnnotation.class); + } + File f = files[0]; + int index = f.getAbsolutePath().indexOf("META-INF"); + + return f.getAbsolutePath().substring(index); + } + + /** + * @throws ClassNotFoundException ifclass not find + * @deprecated Can not use anylonger this class, beacause at compile time we are not garanted to have + * some actions classes compiled, so can not use {@link Class#forName(String)} method. + */ + @Deprecated protected void findProviderConfigFromCompiledClass() throws ClassNotFoundException { - if (!processedClass.isEmpty()) { + if (!actions.isEmpty()) { Class<?> klazz = Class.forName(processedClass.get(0)); providerConfig = klazz.getAnnotation(ActionProviderAnnotation.class); while (klazz != null && providerConfig == null) { @@ -240,11 +272,17 @@ } protected void writeActionMapping() throws IOException { + if (actions.isEmpty()) { + // nothing to write or overwrite + return; + } + BufferedWriter w = null; try { Properties oldProps = loadOldActionMapping(); if (oldProps != null) { - actions.putAll(oldProps); + oldProps.putAll(actions); + actions = oldProps; } // ecriture de toutes les actions trouvees FileObject fo = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", actionsFileLocation); @@ -260,11 +298,10 @@ protected Properties loadOldActionMapping() throws IOException { // reprise sur une ancienne compilation FileObject oldFo = processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, "", actionsFileLocation); - System.out.println("URI " + oldFo.toUri()); - if (!new java.io.File(oldFo.toUri().toString()).exists()) { + if (!new File(oldFo.toUri().toString()).exists()) { return null; } - Properties oldProps = new Properties(); + Properties oldProps = new SortedProperties(); InputStream inputStream = null; try { inputStream = oldFo.openInputStream();
participants (1)
-
tchemit@users.labs.libre-entreprise.org