Re: Sort dependencies topologically
Here it is, it sorts only the artifactId, I retrieved the versions through other means. import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.collection.CollectRequest; import org.sonatype.aether.collection.CollectResult; import org.sonatype.aether.collection.DependencyCollectionException; import org.sonatype.aether.graph.Dependency; import org.sonatype.aether.graph.DependencyNode; import org.sonatype.aether.repository.RemoteRepository; import org.sonatype.aether.util.DefaultRepositorySystemSession; import org.sonatype.aether.util.artifact.DefaultArtifact; import org.sonatype.aether.util.graph.PostorderNodeListGenerator; import org.sonatype.aether.util.graph.transformer.NoopDependencyGraphTransformer; /** * * @goal z * */ public class MyMojo extends AbstractMojo { /** * The entry point to Aether, i.e. the component doing all the work. * * @component */ private RepositorySystem repoSystem; /** * The current repository/network configuration of Maven. * * @parameter default-value=${repositorySystemSession} * @readonly */ private RepositorySystemSession repoSession; /** * The project's remote repositories to use for the resolution. * * @parameter default-value=${project.remoteProjectRepositories} * @readonly */ private ListRemoteRepository remoteRepos; /** * @parameter default-value=${project} * @readonly */ private MavenProject project; public void execute() throws MojoFailureException, MojoExecutionException { // Create the root node Dependency dependency = new Dependency(new DefaultArtifact(project.getArtifact().getId()), compile); // Collect the whole expanded dependency tree, where nodes can be // duplicated and no conflicts have been resolved CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(dependency); collectRequest.setRepositories(remoteRepos); CollectResult collectResult = null; try { DefaultRepositorySystemSession myRepoSession = new DefaultRepositorySystemSession(repoSession); NoopDependencyGraphTransformer myVisitor = new NoopDependencyGraphTransformer(); myRepoSession = myRepoSession.setDependencyGraphTransformer(myVisitor); collectResult = repoSystem.collectDependencies(myRepoSession, collectRequest); } catch (DependencyCollectionException e) { e.printStackTrace(); } // Sorting the whole dependency tree using Postorder from Aether PostorderNodeListGenerator nlg = new PostorderNodeListGenerator(); DependencyNode node = collectResult.getRoot(); node.accept(nlg); // Excluding the duplicated nodes, we start from the top of the list and // exclude any node which has already been seen ListDependencyNode nodesList = nlg.getNodes(); ListDependencyNode seenList = new ArrayListDependencyNode(); for (IteratorDependencyNode it = nodesList.iterator(); it.hasNext();) { DependencyNode dep = it.next(); if (contains(seenList, dep)) { it.remove(); } else { seenList.add(dep); } } // Topological sort is a revert postorder sort Collections.reverse(nodesList); // Finally, only the artifactIds are extracted. The versions don't match // Maven's resolver. // We can resolve versions by using Aether's // NearestVersionConflictResolver graph transformer, but in our case the // artifactIds were sufficient. ListString sortedDependencies = new LinkedListString(); for (DependencyNode dependencyNode : nodesList) { sortedDependencies.add(dependencyNode.getDependency().getArtifact().getArtifactId()); } System.out.println(Sorted dependencies:); for (String artifactId : sortedDependencies) { System.out.println(artifactId); } } private boolean contains(ListDependencyNode seenList, DependencyNode dep) { for (DependencyNode node : seenList) { if (dep.getDependency().getArtifact().getArtifactId() .equals(node.getDependency().getArtifact().getArtifactId())) { return true; } } return false; } } On Sat, Nov 26, 2011 at 8:56 PM, Barrie Treloar baerr...@gmail.com wrote: On Fri, Nov 25, 2011 at 11:41 PM, Jérémy mer...@gmail.com wrote: Hi guys, I've finally succeeded! The trick was to play with the DependencyGraphTransformers in order to get a non-reducted dependency tree. Then I used Aether's PostorderNodeListGenerator to sort the nodes, and finally I removed the duplicated nodes. Any code snippets? - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Sort dependencies topologically
Hi guys, I've finally succeeded! The trick was to play with the DependencyGraphTransformers in order to get a non-reducted dependency tree. Then I used Aether's PostorderNodeListGenerator to sort the nodes, and finally I removed the duplicated nodes. Thanks a lot, Jérémy On Wed, Nov 9, 2011 at 2:32 PM, Jérémy mer...@gmail.com wrote: Thank you guys! I'll give a try to the Aether implementation :-) Regards, Jérémy On Tue, Nov 8, 2011 at 9:41 PM, Ansgar Konermann ansgar.konerm...@googlemail.com wrote: Am 08.11.2011 21:36, schrieb Ansgar Konermann: Example code can be found [...] Some more example code here: https://docs.sonatype.org/display/AETHER/Home Ansgar - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Sort dependencies topologically
Thank you guys! I'll give a try to the Aether implementation :-) Regards, Jérémy On Tue, Nov 8, 2011 at 9:41 PM, Ansgar Konermann ansgar.konerm...@googlemail.com wrote: Am 08.11.2011 21:36, schrieb Ansgar Konermann: Example code can be found [...] Some more example code here: https://docs.sonatype.org/display/AETHER/Home Ansgar - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Sort dependencies topologically
Hi Laird, Thanks for your answer! It's funny because I already tried your piece of code, but couldn't get it running. That's the reason why I went on another direction :-) Can you please provide a complete example? Because I have problems when it comes to retrieve MavenProject objects with the buildFromRepository method. It throws some exceptions. I suspect that my artifacts are not always resolved when I call this method. Thank you so much! Jérémy On Mon, Nov 7, 2011 at 6:44 PM, Laird Nelson ljnel...@gmail.com wrote: On Mon, Nov 7, 2011 at 12:29 PM, Jérémy mer...@gmail.com wrote: I'm trying to sort the dependencies expressed in the pom.xml (including the transitive ones) in a topological way. Hello; I faced the same problem and found a solution. Given that most of the classes involved were undocumented, it remains hard to know if this is the proper way to do it, but it works for me. http://maven.40175.n5.nabble.com/Topologically-sorting-dependencies-td3384898.html Best, Laird -- http://about.me/lairdnelson
Sort dependencies topologically
Hi, I'm trying to sort the dependencies expressed in the pom.xml (including the transitive ones) in a topological way. I'm using the maven-* API 3.0-alpha-2 and it is in the context of a plugin. I tried to use Maven's embedded API to do so, but I get a NPE when I call getTopologicallySortedProjects(). Here's a snippet of my Mojo: MavenExecutionResult dm = new DefaultMavenExecutionResult(); dm = dm.setProject(getMavenProject()); //Maven project provided by plexus ListMavenProject list = dm.getTopologicallySortedProjects(); Anyone has any experience with that? Cheers, Jérémy
xercesImpl-2.10.0
Hi, Anybody else is having problem with the artifact xercesImpl-2.10.0 from Maven Central? My build fails because it cannot find: groupIdxml-apis/groupId artifactIdxml-apis/artifactId version1.4.01/version Indeed, this GAV is missing in Maven Central repo. Here's xercesImpl's pom ( http://search.maven.org/remotecontent?filepath=xerces/xercesImpl/2.10.0/xercesImpl-2.10.0.pom ) Cheers, Jérémy
Re: Repositories in settings.xml
Hi Ron, Thanks for your advices! I grouped all the repos in a single group so the developers just have to point to a single group repo for development and release. But I am considering to split that in several group repos to make it cleaner :-) Anyway I opened an issue for my problem, I believe that it is a bug. Cheers, Jérémy On Tue, May 24, 2011 at 6:33 PM, Ron Wheeler rwhee...@artifact-software.com wrote: On 24/05/2011 3:24 AM, Jérémy wrote: Hi Ron, thanks for your answer, How are builds repeatable in your case? Production builds are only allowed to only depend on releases. Releases are immutable. If we rebuild a released artifact it will contain exactly the same dependencies each time. The people looking after QA and support have a great deal of difficulty saying what was in a build if you use SNAPSHOTS. In the corporate pom, I try to change only plugins configuration for stuff that does not involve the jar (aka javadoc, attached-sources, etc...) Why is your corporate POM so unstable? We're still in migration process, we're moving away from a in-house build tool. Because of the amount of projects, the migration might take more than a year... so to ease the updates (because new requirements will come up all the time), I'd like to keep the parent-pom as SNAPSHOT. You might find it easier to use an application specific parent. You will need more but at least, you can stabilize each application as you get it Mavenized. Anders asked for a specific piece of information. The effective-pom shows the exact same piece of configuration I sent: repositories repository idpublic/id urlhttp://artifacts/content/groups/public/url releases enabledtrue/enabled /releases snapshots enabledfalse/enabled /snapshots /repository repository idallowed-snapshots/id urlhttp://artifacts/content/groups/allowed-snapshots//url snapshots enabledtrue/enabled /snapshots /repository /repositories So my question is, why does Maven fetch SNAPSHOTS from the first repository? Another interesting question is why are there SAPSHOTs in the first repository? One generally separates Releases from SNAPSHOTS I hope that all this helps move the problem forward. Ron Cheers, Jérémy Cheers, Jérémy On Mon, May 23, 2011 at 10:24 AM, Anders Hammarand...@hammar.net wrote: Check the effective pom to see what Maven is working on. This will show what repositories are enabled and how configured. mvn help:effective-pom -P theprofileyoursusing But, I seriously wonder why you would like to use a snapshot repo when doing a release. A release should never use snapshots. /Anders On Mon, May 23, 2011 at 10:15, Jérémymer...@gmail.com wrote: Hi, I noticed a weird behavior with the versions resolution of Maven 3.0.3. Here's my setup: I use Nexus and have a first repository group containing release and snapshots versions and a second repository group with only snapshots. When I want to release a product, I want to pick only the release versions of the first repository group and snapshots versions of the second repository group. In my settings.xml, I have a profile with the following configurations: repositories repository idpublic/id urlhttp://artifacts/content/groups/public/url releases enabledtrue/enabled /releases snapshots enabledfalse/enabled /snapshots /repository repository idallowed-snapshots/id urlhttp://artifacts/content/groups/allowed-snapshots//url snapshots enabledtrue/enabled /snapshots /repository /repositories With this configuration, Maven picks up snapshots from the public repository. However if I remove the second repository, the resolution works as attended. It seems that the enabled variable acts as a global variable across settings.xml. Is that a bug? Cheers, Jérémy - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Repositories in settings.xml
Hi Ron, thanks for your answer, How are builds repeatable in your case? The people looking after QA and support have a great deal of difficulty saying what was in a build if you use SNAPSHOTS. In the corporate pom, I try to change only plugins configuration for stuff that does not involve the jar (aka javadoc, attached-sources, etc...) Why is your corporate POM so unstable? We're still in migration process, we're moving away from a in-house build tool. Because of the amount of projects, the migration might take more than a year... so to ease the updates (because new requirements will come up all the time), I'd like to keep the parent-pom as SNAPSHOT. Anders asked for a specific piece of information. The effective-pom shows the exact same piece of configuration I sent: repositories repository idpublic/id urlhttp://artifacts/content/groups/public/url releases enabledtrue/enabled /releases snapshots enabledfalse/enabled /snapshots /repository repository idallowed-snapshots/id urlhttp://artifacts/content/groups/allowed-snapshots//url snapshots enabledtrue/enabled /snapshots /repository /repositories So my question is, why does Maven fetch SNAPSHOTS from the first repository? Cheers, Jérémy Cheers, Jérémy On Mon, May 23, 2011 at 10:24 AM, Anders Hammarand...@hammar.net wrote: Check the effective pom to see what Maven is working on. This will show what repositories are enabled and how configured. mvn help:effective-pom -P theprofileyoursusing But, I seriously wonder why you would like to use a snapshot repo when doing a release. A release should never use snapshots. /Anders On Mon, May 23, 2011 at 10:15, Jérémymer...@gmail.com wrote: Hi, I noticed a weird behavior with the versions resolution of Maven 3.0.3. Here's my setup: I use Nexus and have a first repository group containing release and snapshots versions and a second repository group with only snapshots. When I want to release a product, I want to pick only the release versions of the first repository group and snapshots versions of the second repository group. In my settings.xml, I have a profile with the following configurations: repositories repository idpublic/id urlhttp://artifacts/content/groups/public/url releases enabledtrue/enabled /releases snapshots enabledfalse/enabled /snapshots /repository repository idallowed-snapshots/id urlhttp://artifacts/content/groups/allowed-snapshots//url snapshots enabledtrue/enabled /snapshots /repository /repositories With this configuration, Maven picks up snapshots from the public repository. However if I remove the second repository, the resolution works as attended. It seems that the enabled variable acts as a global variable across settings.xml. Is that a bug? Cheers, Jérémy - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Repositories in settings.xml
Hi, I noticed a weird behavior with the versions resolution of Maven 3.0.3. Here's my setup: I use Nexus and have a first repository group containing release and snapshots versions and a second repository group with only snapshots. When I want to release a product, I want to pick only the release versions of the first repository group and snapshots versions of the second repository group. In my settings.xml, I have a profile with the following configurations: repositories repository idpublic/id urlhttp://artifacts/content/groups/public/url releases enabledtrue/enabled /releases snapshots enabledfalse/enabled /snapshots /repository repository idallowed-snapshots/id urlhttp://artifacts/content/groups/allowed-snapshots//url snapshots enabledtrue/enabled /snapshots /repository /repositories With this configuration, Maven picks up snapshots from the public repository. However if I remove the second repository, the resolution works as attended. It seems that the enabled variable acts as a global variable across settings.xml. Is that a bug? Cheers, Jérémy
Re: Repositories in settings.xml
Hi Anders, Hehe I knew that this question would pop-up: I have a corporate pom which I keep as SNAPSHOT version. So I can update it and it is transparent to the users. In my organization we have a huge amount of projects, I can't imagine to ask them to update the version of the parent-pom at each update. Unfortunately it's not possible to declare a parent-pom with a version range. Back to my initial question, the effective-pom has the same configuration as the one I showed you. I clean up my local repository each time before resolving the dependencies. Any clue? Cheers, Jérémy On Mon, May 23, 2011 at 10:24 AM, Anders Hammar and...@hammar.net wrote: Check the effective pom to see what Maven is working on. This will show what repositories are enabled and how configured. mvn help:effective-pom -P theprofileyoursusing But, I seriously wonder why you would like to use a snapshot repo when doing a release. A release should never use snapshots. /Anders On Mon, May 23, 2011 at 10:15, Jérémy mer...@gmail.com wrote: Hi, I noticed a weird behavior with the versions resolution of Maven 3.0.3. Here's my setup: I use Nexus and have a first repository group containing release and snapshots versions and a second repository group with only snapshots. When I want to release a product, I want to pick only the release versions of the first repository group and snapshots versions of the second repository group. In my settings.xml, I have a profile with the following configurations: repositories repository idpublic/id urlhttp://artifacts/content/groups/public/url releases enabledtrue/enabled /releases snapshots enabledfalse/enabled /snapshots /repository repository idallowed-snapshots/id urlhttp://artifacts/content/groups/allowed-snapshots//url snapshots enabledtrue/enabled /snapshots /repository /repositories With this configuration, Maven picks up snapshots from the public repository. However if I remove the second repository, the resolution works as attended. It seems that the enabled variable acts as a global variable across settings.xml. Is that a bug? Cheers, Jérémy