Author: tchemit Date: 2009-01-13 16:23:43 +0000 (Tue, 13 Jan 2009) New Revision: 1166 Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java jaxx/trunk/maven-jaxx-plugin/changelog.txt jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java Log: fix bug : when using addProjectClassPath property, sometimes does not retreave dependancies, force it to work whatever is the phase :) remove dirty log Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java =================================================================== --- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java 2009-01-12 16:29:46 UTC (rev 1165) +++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java 2009-01-13 16:23:43 UTC (rev 1166) @@ -169,7 +169,6 @@ /** Resets all state in preparation for a new compilation session. */ protected void reset() { - log.info("do reset!!!!!!!!!!!!"); errorCount = warningCount = 0; jaxxFiles.clear(); jaxxFileClassNames.clear(); Modified: jaxx/trunk/maven-jaxx-plugin/changelog.txt =================================================================== --- jaxx/trunk/maven-jaxx-plugin/changelog.txt 2009-01-12 16:29:46 UTC (rev 1165) +++ jaxx/trunk/maven-jaxx-plugin/changelog.txt 2009-01-13 16:23:43 UTC (rev 1166) @@ -1,3 +1,7 @@ +1.1 chemit ??? + +* 20090113 [chemit] - fix bug : when using addProjectClassPath property, sometimes does not retreave dependancies, force it to work whatever is the phase :) + 1.0 chemit 20090111 0.8 chemit 200812?? Modified: jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java =================================================================== --- jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2009-01-12 16:29:46 UTC (rev 1165) +++ jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2009-01-13 16:23:43 UTC (rev 1166) @@ -20,17 +20,30 @@ package org.codelutin.jaxx; import jaxx.beaninfos.BeanInfoUtil; +import jaxx.compiler.CompilerOptions; import jaxx.compiler.JAXXCompiler; import jaxx.compiler.JAXXCompilerLaunchor; -import jaxx.compiler.CompilerOptions; import jaxx.runtime.JAXXContext; import jaxx.tags.TagManager; -import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactCollector; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.resolver.DebugResolutionListener; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; +import org.apache.maven.project.artifact.InvalidDependencyVersionException; +import org.codehaus.plexus.logging.console.ConsoleLogger; import org.codehaus.plexus.util.DirectoryScanner; import org.codelutin.util.FileUpdaterHelper; import org.codelutin.util.MirroredFileUpdater; @@ -44,6 +57,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Set; /** * Classe permettant de transformer des sources jaxx vers du source java. @@ -53,16 +67,62 @@ * @phase process-sources */ public class JaxxGeneratorMojo extends AbstractMojo { + /** + * Artifact Factory component. + * + * @component + */ + protected ArtifactFactory factory; + /** + * Artifact collector component. + * + * @component + */ + protected ArtifactCollector collector; /** + * Artifact resolver component. + * + * @component + */ + protected ArtifactResolver resolver; + + /** + * Artifact metadata source component. + * + * @component + */ + protected ArtifactMetadataSource artifactMetadataSource; + + /** * Dépendance du projet. * * @parameter default-value="${project}" + * @required * @readonly */ protected MavenProject project; /** + * Local Repository. + * + * @parameter expression="${localRepository}" + * @required + * @readonly + */ + protected ArtifactRepository localRepository; + + + /** + * Remote repositories used for the project. + * + * @parameter expression="${project.remoteArtifactRepositories}" + * @required + * @readonly + */ + protected List remoteRepositories; + + /** * Le compilateur à utiliser (par défaut celui de Swing) * * @parameter expression="${jaxx.compilerFQN}" default-value="jaxx.compiler.SwingCompiler" @@ -420,7 +480,7 @@ @SuppressWarnings({"unchecked"}) protected URLClassLoader initClassLoader(MavenProject project, Log log) throws MalformedURLException { - URLClassLoader loader = null; + URLClassLoader loader; if (project != null) { URLClassLoader result; @@ -437,14 +497,27 @@ if (addProjectClassPath) { getLog().info("use project compile scope class-path"); // add also all dependency of the project in compile scope - for (Object o : project.getCompileClasspathElements()) { - String url = (String) o; - File f = new File(url); - if (!f.exists()) { - continue; + Set dependencyArtifacts = project.getDependencyArtifacts(); + if (dependencyArtifacts == null) { + // obtain artifacts + dependencyArtifacts = project.createArtifacts(factory, DefaultArtifact.SCOPE_COMPILE, null); + } + List listeners = new ArrayList(); + if (isVerbose()) { + listeners.add(new DebugResolutionListener(new ConsoleLogger(0, "jaxx"))); + } + // collects artifact best version + ArtifactResolutionResult resolved = collector.collect(dependencyArtifacts, project.getArtifact(), localRepository, remoteRepositories, artifactMetadataSource, new ScopeArtifactFilter(DefaultArtifact.SCOPE_COMPILE), listeners); + for (Object o : resolved.getArtifacts()) { + Artifact a = (Artifact) o; + // resolv artifact (with download if required...) + if (a.getFile() == null) { + resolver.resolve(a, remoteRepositories, localRepository); } - - lUrls.add(f.toURI().toURL()); + if (a.getFile() == null) { + throw new ArtifactNotFoundException("could not find jar", a); + } + lUrls.add(a.getFile().toURI().toURL()); } } @@ -452,8 +525,12 @@ } catch (IOException e) { throw new RuntimeException("Can't create ClassLoader for script, bad directory: " + outClass + " for reason " + e.getMessage(), e); - } catch (DependencyResolutionRequiredException e) { + } catch (InvalidDependencyVersionException e) { throw new RuntimeException(e); + } catch (ArtifactResolutionException e) { + throw new RuntimeException(e); + } catch (ArtifactNotFoundException e) { + throw new RuntimeException(e); } loader = result; } else { @@ -463,7 +540,7 @@ } loader = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader()); } - if (loader != null && isVerbose()) { + if (isVerbose()) { for (URL entry : loader.getURLs()) { log.info("classpath : " + entry); }