Renamed package o.e.a.demo.* to o.e.a.examples.* to better comply with Eclipse naming conventions
Project: http://git-wip-us.apache.org/repos/asf/maven-aether/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-aether/commit/e86cfec6 Tree: http://git-wip-us.apache.org/repos/asf/maven-aether/tree/e86cfec6 Diff: http://git-wip-us.apache.org/repos/asf/maven-aether/diff/e86cfec6 Branch: refs/heads/demo Commit: e86cfec65ee9a8503aa2c0c803b9c1b88f513fd9 Parents: a3a0594 Author: Benjamin Bentmann <bentm...@sonatype.com> Authored: Tue Nov 1 21:26:30 2011 +0100 Committer: Benjamin Bentmann <bentm...@sonatype.com> Committed: Tue Nov 1 21:26:30 2011 +0100 ---------------------------------------------------------------------- .../aether/demo/maven/ResolveArtifactMojo.java | 97 ----------- .../examples/maven/ResolveArtifactMojo.java | 97 +++++++++++ .../org/eclipse/aether/demo/AllAetherDemos.java | 32 ---- .../eclipse/aether/demo/DeployArtifacts.java | 57 ------- .../aether/demo/FindAvailableVersions.java | 57 ------- .../eclipse/aether/demo/FindNewestVersion.java | 56 ------- .../eclipse/aether/demo/GetDependencyTree.java | 54 ------ .../aether/demo/GetDirectDependencies.java | 56 ------- .../eclipse/aether/demo/InstallArtifacts.java | 52 ------ .../eclipse/aether/demo/ResolveArtifact.java | 54 ------ .../demo/ResolveTransitiveDependencies.java | 67 -------- .../org/eclipse/aether/demo/aether/Aether.java | 120 -------------- .../eclipse/aether/demo/aether/AetherDemo.java | 67 -------- .../aether/demo/aether/AetherResult.java | 45 ----- .../manual/ManualRepositorySystemFactory.java | 41 ----- .../aether/demo/manual/ManualWagonProvider.java | 39 ----- .../plexus/PlexusRepositorySystemFactory.java | 38 ----- .../org/eclipse/aether/demo/util/Booter.java | 53 ------ .../demo/util/ConsoleDependencyGraphDumper.java | 59 ------- .../demo/util/ConsoleRepositoryListener.java | 123 -------------- .../demo/util/ConsoleTransferListener.java | 164 ------------------- .../eclipse/aether/examples/AllAetherDemos.java | 32 ++++ .../aether/examples/DeployArtifacts.java | 57 +++++++ .../aether/examples/FindAvailableVersions.java | 57 +++++++ .../aether/examples/FindNewestVersion.java | 56 +++++++ .../aether/examples/GetDependencyTree.java | 54 ++++++ .../aether/examples/GetDirectDependencies.java | 56 +++++++ .../aether/examples/InstallArtifacts.java | 52 ++++++ .../aether/examples/ResolveArtifact.java | 54 ++++++ .../examples/ResolveTransitiveDependencies.java | 67 ++++++++ .../eclipse/aether/examples/aether/Aether.java | 120 ++++++++++++++ .../aether/examples/aether/AetherDemo.java | 67 ++++++++ .../aether/examples/aether/AetherResult.java | 45 +++++ .../manual/ManualRepositorySystemFactory.java | 41 +++++ .../examples/manual/ManualWagonProvider.java | 39 +++++ .../plexus/PlexusRepositorySystemFactory.java | 38 +++++ .../eclipse/aether/examples/util/Booter.java | 53 ++++++ .../util/ConsoleDependencyGraphDumper.java | 59 +++++++ .../util/ConsoleRepositoryListener.java | 123 ++++++++++++++ .../examples/util/ConsoleTransferListener.java | 164 +++++++++++++++++++ 40 files changed, 1331 insertions(+), 1331 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/demo/maven/ResolveArtifactMojo.java ---------------------------------------------------------------------- diff --git a/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/demo/maven/ResolveArtifactMojo.java b/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/demo/maven/ResolveArtifactMojo.java deleted file mode 100644 index c613381..0000000 --- a/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/demo/maven/ResolveArtifactMojo.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo.maven; - -import java.util.List; - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.ArtifactRequest; -import org.eclipse.aether.resolution.ArtifactResolutionException; -import org.eclipse.aether.resolution.ArtifactResult; -import org.eclipse.aether.util.artifact.DefaultArtifact; - -/** - * @goal resolve-artifact - */ -public class ResolveArtifactMojo - 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 List<RemoteRepository> remoteRepos; - - /** - * The {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>} of the artifact to resolve. - * - * @parameter expression="${aether.artifactCoords}" - */ - private String artifactCoords; - - public void execute() - throws MojoExecutionException, MojoFailureException - { - Artifact artifact; - try - { - artifact = new DefaultArtifact( artifactCoords ); - } - catch ( IllegalArgumentException e ) - { - throw new MojoFailureException( e.getMessage(), e ); - } - - ArtifactRequest request = new ArtifactRequest(); - request.setArtifact( artifact ); - request.setRepositories( remoteRepos ); - - getLog().info( "Resolving artifact " + artifact + " from " + remoteRepos ); - - ArtifactResult result; - try - { - result = repoSystem.resolveArtifact( repoSession, request ); - } - catch ( ArtifactResolutionException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } - - getLog().info( "Resolved artifact " + artifact + " to " + result.getArtifact().getFile() + " from " - + result.getRepository() ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/examples/maven/ResolveArtifactMojo.java ---------------------------------------------------------------------- diff --git a/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/examples/maven/ResolveArtifactMojo.java b/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/examples/maven/ResolveArtifactMojo.java new file mode 100644 index 0000000..4dc0d47 --- /dev/null +++ b/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/examples/maven/ResolveArtifactMojo.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.examples.maven; + +import java.util.List; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.ArtifactRequest; +import org.eclipse.aether.resolution.ArtifactResolutionException; +import org.eclipse.aether.resolution.ArtifactResult; +import org.eclipse.aether.util.artifact.DefaultArtifact; + +/** + * @goal resolve-artifact + */ +public class ResolveArtifactMojo + 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 List<RemoteRepository> remoteRepos; + + /** + * The {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>} of the artifact to resolve. + * + * @parameter expression="${aether.artifactCoords}" + */ + private String artifactCoords; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + Artifact artifact; + try + { + artifact = new DefaultArtifact( artifactCoords ); + } + catch ( IllegalArgumentException e ) + { + throw new MojoFailureException( e.getMessage(), e ); + } + + ArtifactRequest request = new ArtifactRequest(); + request.setArtifact( artifact ); + request.setRepositories( remoteRepos ); + + getLog().info( "Resolving artifact " + artifact + " from " + remoteRepos ); + + ArtifactResult result; + try + { + result = repoSystem.resolveArtifact( repoSession, request ); + } + catch ( ArtifactResolutionException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + + getLog().info( "Resolved artifact " + artifact + " to " + result.getArtifact().getFile() + " from " + + result.getRepository() ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/AllAetherDemos.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/AllAetherDemos.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/AllAetherDemos.java deleted file mode 100644 index e9c06af..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/AllAetherDemos.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo; - -/** - * Runs all demos at once. - */ -public class AllAetherDemos -{ - - public static void main( String[] args ) - throws Exception - { - FindAvailableVersions.main( args ); - FindNewestVersion.main( args ); - GetDirectDependencies.main( args ); - GetDependencyTree.main( args ); - ResolveArtifact.main( args ); - ResolveTransitiveDependencies.main( args ); - InstallArtifacts.main( args ); - DeployArtifacts.main( args ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/DeployArtifacts.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/DeployArtifacts.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/DeployArtifacts.java deleted file mode 100644 index a700eff..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/DeployArtifacts.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo; - -import java.io.File; - -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.demo.util.Booter; -import org.eclipse.aether.deployment.DeployRequest; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.util.artifact.DefaultArtifact; -import org.eclipse.aether.util.artifact.SubArtifact; - - -/** - * Deploys a JAR and its POM to a remote repository. - */ -public class DeployArtifacts -{ - - public static void main( String[] args ) - throws Exception - { - System.out.println( "------------------------------------------------------------" ); - System.out.println( DeployArtifacts.class.getSimpleName() ); - - RepositorySystem system = Booter.newRepositorySystem(); - - RepositorySystemSession session = Booter.newRepositorySystemSession( system ); - - Artifact jarArtifact = new DefaultArtifact( "test", "org.eclipse.aether.demo", "", "jar", "0.1-SNAPSHOT" ); - jarArtifact = jarArtifact.setFile( new File( "org.eclipse.aether.demo.jar" ) ); - - Artifact pomArtifact = new SubArtifact( jarArtifact, "", "pom" ); - pomArtifact = pomArtifact.setFile( new File( "pom.xml" ) ); - - RemoteRepository distRepo = - new RemoteRepository( "org.eclipse.aether.demo", "default", new File( "target/dist-repo" ).toURI().toString() ); - - DeployRequest deployRequest = new DeployRequest(); - deployRequest.addArtifact( jarArtifact ).addArtifact( pomArtifact ); - deployRequest.setRepository( distRepo ); - - system.deploy( session, deployRequest ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/FindAvailableVersions.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/FindAvailableVersions.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/FindAvailableVersions.java deleted file mode 100644 index b827864..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/FindAvailableVersions.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo; - -import java.util.List; - -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.demo.util.Booter; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.VersionRangeRequest; -import org.eclipse.aether.resolution.VersionRangeResult; -import org.eclipse.aether.util.artifact.DefaultArtifact; -import org.eclipse.aether.version.Version; - - -/** - * Determines all available versions of an artifact. - */ -public class FindAvailableVersions -{ - - public static void main( String[] args ) - throws Exception - { - System.out.println( "------------------------------------------------------------" ); - System.out.println( FindAvailableVersions.class.getSimpleName() ); - - RepositorySystem system = Booter.newRepositorySystem(); - - RepositorySystemSession session = Booter.newRepositorySystemSession( system ); - - Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-util:[0,)" ); - - RemoteRepository repo = Booter.newCentralRepository(); - - VersionRangeRequest rangeRequest = new VersionRangeRequest(); - rangeRequest.setArtifact( artifact ); - rangeRequest.addRepository( repo ); - - VersionRangeResult rangeResult = system.resolveVersionRange( session, rangeRequest ); - - List<Version> versions = rangeResult.getVersions(); - - System.out.println( "Available versions " + versions ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/FindNewestVersion.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/FindNewestVersion.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/FindNewestVersion.java deleted file mode 100644 index 4ca2fa0..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/FindNewestVersion.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo; - -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.demo.util.Booter; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.VersionRangeRequest; -import org.eclipse.aether.resolution.VersionRangeResult; -import org.eclipse.aether.util.artifact.DefaultArtifact; -import org.eclipse.aether.version.Version; - - -/** - * Determines the newest version of an artifact. - */ -public class FindNewestVersion -{ - - public static void main( String[] args ) - throws Exception - { - System.out.println( "------------------------------------------------------------" ); - System.out.println( FindNewestVersion.class.getSimpleName() ); - - RepositorySystem system = Booter.newRepositorySystem(); - - RepositorySystemSession session = Booter.newRepositorySystemSession( system ); - - Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-util:[0,)" ); - - RemoteRepository repo = Booter.newCentralRepository(); - - VersionRangeRequest rangeRequest = new VersionRangeRequest(); - rangeRequest.setArtifact( artifact ); - rangeRequest.addRepository( repo ); - - VersionRangeResult rangeResult = system.resolveVersionRange( session, rangeRequest ); - - Version newestVersion = rangeResult.getHighestVersion(); - - System.out.println( "Newest version " + newestVersion + " from repository " - + rangeResult.getRepository( newestVersion ) ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/GetDependencyTree.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/GetDependencyTree.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/GetDependencyTree.java deleted file mode 100644 index 9468395..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/GetDependencyTree.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo; - -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.collection.CollectRequest; -import org.eclipse.aether.collection.CollectResult; -import org.eclipse.aether.demo.util.Booter; -import org.eclipse.aether.demo.util.ConsoleDependencyGraphDumper; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.util.artifact.DefaultArtifact; - - -/** - * Collects the transitive dependencies of an artifact. - */ -public class GetDependencyTree -{ - - public static void main( String[] args ) - throws Exception - { - System.out.println( "------------------------------------------------------------" ); - System.out.println( GetDependencyTree.class.getSimpleName() ); - - RepositorySystem system = Booter.newRepositorySystem(); - - RepositorySystemSession session = Booter.newRepositorySystemSession( system ); - - Artifact artifact = new DefaultArtifact( "org.apache.maven:maven-aether-provider:3.0.2" ); - - RemoteRepository repo = Booter.newCentralRepository(); - - CollectRequest collectRequest = new CollectRequest(); - collectRequest.setRoot( new Dependency( artifact, "" ) ); - collectRequest.addRepository( repo ); - - CollectResult collectResult = system.collectDependencies( session, collectRequest ); - - collectResult.getRoot().accept( new ConsoleDependencyGraphDumper() ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/GetDirectDependencies.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/GetDirectDependencies.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/GetDirectDependencies.java deleted file mode 100644 index 44f9e63..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/GetDirectDependencies.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo; - -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.demo.util.Booter; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.ArtifactDescriptorRequest; -import org.eclipse.aether.resolution.ArtifactDescriptorResult; -import org.eclipse.aether.util.artifact.DefaultArtifact; - - -/** - * Determines the direct dependencies of an artifact as declared in its artifact descriptor (POM). - */ -public class GetDirectDependencies -{ - - public static void main( String[] args ) - throws Exception - { - System.out.println( "------------------------------------------------------------" ); - System.out.println( GetDirectDependencies.class.getSimpleName() ); - - RepositorySystem system = Booter.newRepositorySystem(); - - RepositorySystemSession session = Booter.newRepositorySystemSession( system ); - - Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-impl:1.13" ); - - RemoteRepository repo = Booter.newCentralRepository(); - - ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest(); - descriptorRequest.setArtifact( artifact ); - descriptorRequest.addRepository( repo ); - - ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor( session, descriptorRequest ); - - for ( Dependency dependency : descriptorResult.getDependencies() ) - { - System.out.println( dependency ); - } - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/InstallArtifacts.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/InstallArtifacts.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/InstallArtifacts.java deleted file mode 100644 index 75db100..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/InstallArtifacts.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo; - -import java.io.File; - -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.demo.util.Booter; -import org.eclipse.aether.installation.InstallRequest; -import org.eclipse.aether.util.artifact.DefaultArtifact; -import org.eclipse.aether.util.artifact.SubArtifact; - - -/** - * Installs a JAR and its POM to the local repository. - */ -public class InstallArtifacts -{ - - public static void main( String[] args ) - throws Exception - { - System.out.println( "------------------------------------------------------------" ); - System.out.println( InstallArtifacts.class.getSimpleName() ); - - RepositorySystem system = Booter.newRepositorySystem(); - - RepositorySystemSession session = Booter.newRepositorySystemSession( system ); - - Artifact jarArtifact = new DefaultArtifact( "test", "org.eclipse.aether.demo", "", "jar", "0.1-SNAPSHOT" ); - jarArtifact = jarArtifact.setFile( new File( "org.eclipse.aether.demo.jar" ) ); - - Artifact pomArtifact = new SubArtifact( jarArtifact, "", "pom" ); - pomArtifact = pomArtifact.setFile( new File( "pom.xml" ) ); - - InstallRequest installRequest = new InstallRequest(); - installRequest.addArtifact( jarArtifact ).addArtifact( pomArtifact ); - - system.install( session, installRequest ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/ResolveArtifact.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/ResolveArtifact.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/ResolveArtifact.java deleted file mode 100644 index 766b6ac..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/ResolveArtifact.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo; - -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.demo.util.Booter; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.ArtifactRequest; -import org.eclipse.aether.resolution.ArtifactResult; -import org.eclipse.aether.util.artifact.DefaultArtifact; - - -/** - * Resolves a single artifact. - */ -public class ResolveArtifact -{ - - public static void main( String[] args ) - throws Exception - { - System.out.println( "------------------------------------------------------------" ); - System.out.println( ResolveArtifact.class.getSimpleName() ); - - RepositorySystem system = Booter.newRepositorySystem(); - - RepositorySystemSession session = Booter.newRepositorySystemSession( system ); - - Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-util:1.13" ); - - RemoteRepository repo = Booter.newCentralRepository(); - - ArtifactRequest artifactRequest = new ArtifactRequest(); - artifactRequest.setArtifact( artifact ); - artifactRequest.addRepository( repo ); - - ArtifactResult artifactResult = system.resolveArtifact( session, artifactRequest ); - - artifact = artifactResult.getArtifact(); - - System.out.println( artifact + " resolved to " + artifact.getFile() ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/ResolveTransitiveDependencies.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/ResolveTransitiveDependencies.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/ResolveTransitiveDependencies.java deleted file mode 100644 index dd3f6ce..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/ResolveTransitiveDependencies.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo; - -import java.util.List; - -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.collection.CollectRequest; -import org.eclipse.aether.demo.util.Booter; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.graph.DependencyFilter; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.ArtifactResult; -import org.eclipse.aether.resolution.DependencyRequest; -import org.eclipse.aether.util.artifact.DefaultArtifact; -import org.eclipse.aether.util.artifact.JavaScopes; -import org.eclipse.aether.util.filter.DependencyFilterUtils; - - -/** - * Resolves the transitive (compile) dependencies of an artifact. - */ -public class ResolveTransitiveDependencies -{ - - public static void main( String[] args ) - throws Exception - { - System.out.println( "------------------------------------------------------------" ); - System.out.println( ResolveTransitiveDependencies.class.getSimpleName() ); - - RepositorySystem system = Booter.newRepositorySystem(); - - RepositorySystemSession session = Booter.newRepositorySystemSession( system ); - - Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-impl:1.13" ); - - RemoteRepository repo = Booter.newCentralRepository(); - - DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter( JavaScopes.COMPILE ); - - CollectRequest collectRequest = new CollectRequest(); - collectRequest.setRoot( new Dependency( artifact, JavaScopes.COMPILE ) ); - collectRequest.addRepository( repo ); - - DependencyRequest dependencyRequest = new DependencyRequest( collectRequest, classpathFlter ); - - List<ArtifactResult> artifactResults = - system.resolveDependencies( session, dependencyRequest ).getArtifactResults(); - - for ( ArtifactResult artifactResult : artifactResults ) - { - System.out.println( artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile() ); - } - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/aether/Aether.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/aether/Aether.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/aether/Aether.java deleted file mode 100644 index 274d41f..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/aether/Aether.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo.aether; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; - -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.collection.CollectRequest; -import org.eclipse.aether.demo.util.Booter; -import org.eclipse.aether.demo.util.ConsoleDependencyGraphDumper; -import org.eclipse.aether.deployment.DeployRequest; -import org.eclipse.aether.deployment.DeploymentException; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.installation.InstallRequest; -import org.eclipse.aether.installation.InstallationException; -import org.eclipse.aether.repository.Authentication; -import org.eclipse.aether.repository.LocalRepository; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.DependencyRequest; -import org.eclipse.aether.resolution.DependencyResolutionException; -import org.eclipse.aether.util.DefaultRepositorySystemSession; -import org.eclipse.aether.util.artifact.DefaultArtifact; -import org.eclipse.aether.util.graph.PreorderNodeListGenerator; - - -public class Aether -{ - private String remoteRepository; - - private RepositorySystem repositorySystem; - - private LocalRepository localRepository; - - public Aether( String remoteRepository, String localRepository ) - { - this.remoteRepository = remoteRepository; - this.repositorySystem = Booter.newRepositorySystem(); - this.localRepository = new LocalRepository( localRepository ); - } - - private RepositorySystemSession newSession() - { - DefaultRepositorySystemSession session = Booter.newRepositorySystemSession( repositorySystem ); - session.setLocalRepositoryManager( repositorySystem.newLocalRepositoryManager( localRepository ) ); - return session; - } - - public AetherResult resolve( String groupId, String artifactId, String version ) - throws DependencyResolutionException - { - RepositorySystemSession session = newSession(); - Dependency dependency = - new Dependency( new DefaultArtifact( groupId, artifactId, "", "jar", version ), "runtime" ); - RemoteRepository central = new RemoteRepository( "central", "default", remoteRepository ); - - CollectRequest collectRequest = new CollectRequest(); - collectRequest.setRoot( dependency ); - collectRequest.addRepository( central ); - - DependencyRequest dependencyRequest = new DependencyRequest(); - dependencyRequest.setCollectRequest( collectRequest ); - - DependencyNode rootNode = repositorySystem.resolveDependencies( session, dependencyRequest ).getRoot(); - - StringBuilder dump = new StringBuilder(); - displayTree( rootNode, dump ); - - PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); - rootNode.accept( nlg ); - - return new AetherResult( rootNode, nlg.getFiles(), nlg.getClassPath() ); - } - - public void install( Artifact artifact, Artifact pom ) - throws InstallationException - { - RepositorySystemSession session = newSession(); - - InstallRequest installRequest = new InstallRequest(); - installRequest.addArtifact( artifact ).addArtifact( pom ); - - repositorySystem.install( session, installRequest ); - } - - public void deploy( Artifact artifact, Artifact pom, String remoteRepository ) - throws DeploymentException - { - RepositorySystemSession session = newSession(); - - RemoteRepository nexus = new RemoteRepository( "nexus", "default", remoteRepository ); - Authentication authentication = new Authentication( "admin", "admin123" ); - nexus.setAuthentication( authentication ); - - DeployRequest deployRequest = new DeployRequest(); - deployRequest.addArtifact( artifact ).addArtifact( pom ); - deployRequest.setRepository( nexus ); - - repositorySystem.deploy( session, deployRequest ); - } - - private void displayTree( DependencyNode node, StringBuilder sb ) - { - ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 ); - node.accept( new ConsoleDependencyGraphDumper( new PrintStream( os ) ) ); - sb.append( os.toString() ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/aether/AetherDemo.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/aether/AetherDemo.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/aether/AetherDemo.java deleted file mode 100644 index 8d21429..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/aether/AetherDemo.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo.aether; - -import java.io.File; -import java.util.List; - -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.deployment.DeploymentException; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.installation.InstallationException; -import org.eclipse.aether.resolution.DependencyResolutionException; -import org.eclipse.aether.util.artifact.DefaultArtifact; -import org.eclipse.aether.util.artifact.SubArtifact; - -@SuppressWarnings( "unused" ) -public class AetherDemo -{ - - public void resolve() - throws DependencyResolutionException - { - Aether aether = new Aether( "http://localhost:8081/nexus/content/groups/public", "/Users/jvanzyl/aether-repo" ); - - AetherResult result = aether.resolve( "com.mycompany.app", "super-app", "1.0" ); - - // Get the root of the resolved tree of artifacts - // - DependencyNode root = result.getRoot(); - - // Get the list of files for the artifacts resolved - // - List<File> artifacts = result.getResolvedFiles(); - - // Get the classpath of the artifacts resolved - // - String classpath = result.getResolvedClassPath(); - } - - public void installAndDeploy() - throws InstallationException, DeploymentException - { - Aether aether = new Aether( "http://localhost:8081/nexus/content/groups/public", "/Users/jvanzyl/aether-repo" ); - - Artifact artifact = new DefaultArtifact( "com.mycompany.super", "super-core", "jar", "0.1-SNAPSHOT" ); - artifact = artifact.setFile( new File( "jar-from-whatever-process.jar" ) ); - Artifact pom = new SubArtifact( artifact, null, "pom" ); - pom = pom.setFile( new File( "pom-from-whatever-process.xml" ) ); - - // Install into the local repository specified - // - aether.install( artifact, pom ); - - // Deploy to a remote reposistory - // - aether.deploy( artifact, pom, "http://localhost:8081/nexus/content/repositories/snapshots/" ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/aether/AetherResult.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/aether/AetherResult.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/aether/AetherResult.java deleted file mode 100644 index cf2b449..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/aether/AetherResult.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo.aether; - -import java.io.File; -import java.util.List; - -import org.eclipse.aether.graph.DependencyNode; - -public class AetherResult -{ - private DependencyNode root; - private List<File> resolvedFiles; - private String resolvedClassPath; - - public AetherResult( DependencyNode root, List<File> resolvedFiles, String resolvedClassPath ) - { - this.root = root; - this.resolvedFiles = resolvedFiles; - this.resolvedClassPath = resolvedClassPath; - } - - public DependencyNode getRoot() - { - return root; - } - - public List<File> getResolvedFiles() - { - return resolvedFiles; - } - - public String getResolvedClassPath() - { - return resolvedClassPath; - } -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/manual/ManualRepositorySystemFactory.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/manual/ManualRepositorySystemFactory.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/manual/ManualRepositorySystemFactory.java deleted file mode 100644 index 11aa788..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/manual/ManualRepositorySystemFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo.manual; - -import org.apache.maven.repository.internal.DefaultServiceLocator; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.connector.file.FileRepositoryConnectorFactory; -import org.eclipse.aether.connector.wagon.WagonProvider; -import org.eclipse.aether.connector.wagon.WagonRepositoryConnectorFactory; -import org.eclipse.aether.spi.connector.RepositoryConnectorFactory; - -/** - * A factory for repository system instances that employs Aether's built-in service locator infrastructure to wire up - * the system's components. - */ -public class ManualRepositorySystemFactory -{ - - public static RepositorySystem newRepositorySystem() - { - /* - * Aether's components implement org.eclipse.aether.spi.locator.Service to ease manual wiring and using the - * prepopulated DefaultServiceLocator, we only need to register the repository connector factories. - */ - DefaultServiceLocator locator = new DefaultServiceLocator(); - locator.addService( RepositoryConnectorFactory.class, FileRepositoryConnectorFactory.class ); - locator.addService( RepositoryConnectorFactory.class, WagonRepositoryConnectorFactory.class ); - locator.setServices( WagonProvider.class, new ManualWagonProvider() ); - - return locator.getService( RepositorySystem.class ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/manual/ManualWagonProvider.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/manual/ManualWagonProvider.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/manual/ManualWagonProvider.java deleted file mode 100644 index 0a48c56..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/manual/ManualWagonProvider.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo.manual; - -import org.apache.maven.wagon.Wagon; -import org.eclipse.aether.connector.wagon.WagonProvider; -import org.sonatype.maven.wagon.AhcWagon; - -/** - * A simplistic provider for wagon instances when no Plexus-compatible IoC container is used. - */ -public class ManualWagonProvider - implements WagonProvider -{ - - public Wagon lookup( String roleHint ) - throws Exception - { - if ( "http".equals( roleHint ) ) - { - return new AhcWagon(); - } - return null; - } - - public void release( Wagon wagon ) - { - - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/plexus/PlexusRepositorySystemFactory.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/plexus/PlexusRepositorySystemFactory.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/plexus/PlexusRepositorySystemFactory.java deleted file mode 100644 index 8d3f41e..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/plexus/PlexusRepositorySystemFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo.plexus; - -import org.codehaus.plexus.DefaultPlexusContainer; -import org.eclipse.aether.RepositorySystem; - -/** - * A factory for repository system instances that employs Plexus to wire up the system's components. - */ -public class PlexusRepositorySystemFactory -{ - - public static RepositorySystem newRepositorySystem() - { - /* - * Aether's components are equipped with plexus-specific metadata to enable discovery and wiring of components - * by a Plexus container so this is as easy as looking up the implementation. - */ - try - { - return new DefaultPlexusContainer().lookup( RepositorySystem.class ); - } - catch ( Exception e ) - { - throw new IllegalStateException( "dependency injection failed", e ); - } - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/Booter.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/Booter.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/Booter.java deleted file mode 100644 index 8be5593..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/Booter.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo.util; - -import org.apache.maven.repository.internal.MavenRepositorySystemSession; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.demo.manual.ManualRepositorySystemFactory; -import org.eclipse.aether.repository.LocalRepository; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.util.DefaultRepositorySystemSession; - - -/** - * A helper to boot the repository system and a repository system session. - */ -public class Booter -{ - - public static RepositorySystem newRepositorySystem() - { - return ManualRepositorySystemFactory.newRepositorySystem(); - } - - public static DefaultRepositorySystemSession newRepositorySystemSession( RepositorySystem system ) - { - MavenRepositorySystemSession session = new MavenRepositorySystemSession(); - - LocalRepository localRepo = new LocalRepository( "target/local-repo" ); - session.setLocalRepositoryManager( system.newLocalRepositoryManager( localRepo ) ); - - session.setTransferListener( new ConsoleTransferListener() ); - session.setRepositoryListener( new ConsoleRepositoryListener() ); - - // uncomment to generate dirty trees - // session.setDependencyGraphTransformer( null ); - - return session; - } - - public static RemoteRepository newCentralRepository() - { - return new RemoteRepository( "central", "default", "http://repo1.maven.org/maven2/" ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/ConsoleDependencyGraphDumper.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/ConsoleDependencyGraphDumper.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/ConsoleDependencyGraphDumper.java deleted file mode 100644 index 960eeda..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/ConsoleDependencyGraphDumper.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo.util; - -import java.io.PrintStream; - -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.graph.DependencyVisitor; - -/** - * A dependency visitor that dumps the graph to the console. - */ -public class ConsoleDependencyGraphDumper - implements DependencyVisitor -{ - - private PrintStream out; - - private String currentIndent = ""; - - public ConsoleDependencyGraphDumper() - { - this( null ); - } - - public ConsoleDependencyGraphDumper( PrintStream out ) - { - this.out = ( out != null ) ? out : System.out; - } - - public boolean visitEnter( DependencyNode node ) - { - out.println( currentIndent + node ); - if ( currentIndent.length() <= 0 ) - { - currentIndent = "+- "; - } - else - { - currentIndent = "| " + currentIndent; - } - return true; - } - - public boolean visitLeave( DependencyNode node ) - { - currentIndent = currentIndent.substring( 3, currentIndent.length() ); - return true; - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/ConsoleRepositoryListener.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/ConsoleRepositoryListener.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/ConsoleRepositoryListener.java deleted file mode 100644 index 3bf0cb5..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/ConsoleRepositoryListener.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo.util; - -import java.io.PrintStream; - -import org.eclipse.aether.AbstractRepositoryListener; -import org.eclipse.aether.RepositoryEvent; - -/** - * A simplistic repository listener that logs events to the console. - */ -public class ConsoleRepositoryListener - extends AbstractRepositoryListener -{ - - private PrintStream out; - - public ConsoleRepositoryListener() - { - this( null ); - } - - public ConsoleRepositoryListener( PrintStream out ) - { - this.out = ( out != null ) ? out : System.out; - } - - public void artifactDeployed( RepositoryEvent event ) - { - out.println( "Deployed " + event.getArtifact() + " to " + event.getRepository() ); - } - - public void artifactDeploying( RepositoryEvent event ) - { - out.println( "Deploying " + event.getArtifact() + " to " + event.getRepository() ); - } - - public void artifactDescriptorInvalid( RepositoryEvent event ) - { - out.println( "Invalid artifact descriptor for " + event.getArtifact() + ": " - + event.getException().getMessage() ); - } - - public void artifactDescriptorMissing( RepositoryEvent event ) - { - out.println( "Missing artifact descriptor for " + event.getArtifact() ); - } - - public void artifactInstalled( RepositoryEvent event ) - { - out.println( "Installed " + event.getArtifact() + " to " + event.getFile() ); - } - - public void artifactInstalling( RepositoryEvent event ) - { - out.println( "Installing " + event.getArtifact() + " to " + event.getFile() ); - } - - public void artifactResolved( RepositoryEvent event ) - { - out.println( "Resolved artifact " + event.getArtifact() + " from " + event.getRepository() ); - } - - public void artifactDownloading( RepositoryEvent event ) - { - out.println( "Downloading artifact " + event.getArtifact() + " from " + event.getRepository() ); - } - - public void artifactDownloaded( RepositoryEvent event ) - { - out.println( "Downloaded artifact " + event.getArtifact() + " from " + event.getRepository() ); - } - - public void artifactResolving( RepositoryEvent event ) - { - out.println( "Resolving artifact " + event.getArtifact() ); - } - - public void metadataDeployed( RepositoryEvent event ) - { - out.println( "Deployed " + event.getMetadata() + " to " + event.getRepository() ); - } - - public void metadataDeploying( RepositoryEvent event ) - { - out.println( "Deploying " + event.getMetadata() + " to " + event.getRepository() ); - } - - public void metadataInstalled( RepositoryEvent event ) - { - out.println( "Installed " + event.getMetadata() + " to " + event.getFile() ); - } - - public void metadataInstalling( RepositoryEvent event ) - { - out.println( "Installing " + event.getMetadata() + " to " + event.getFile() ); - } - - public void metadataInvalid( RepositoryEvent event ) - { - out.println( "Invalid metadata " + event.getMetadata() ); - } - - public void metadataResolved( RepositoryEvent event ) - { - out.println( "Resolved metadata " + event.getMetadata() + " from " + event.getRepository() ); - } - - public void metadataResolving( RepositoryEvent event ) - { - out.println( "Resolving metadata " + event.getMetadata() + " from " + event.getRepository() ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/ConsoleTransferListener.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/ConsoleTransferListener.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/ConsoleTransferListener.java deleted file mode 100644 index 04be132..0000000 --- a/aether-demo-snippets/src/main/java/org/eclipse/aether/demo/util/ConsoleTransferListener.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.demo.util; - -import java.io.PrintStream; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.Locale; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.eclipse.aether.transfer.AbstractTransferListener; -import org.eclipse.aether.transfer.TransferEvent; -import org.eclipse.aether.transfer.TransferResource; - -/** - * A simplistic transfer listener that logs uploads/downloads to the console. - */ -public class ConsoleTransferListener - extends AbstractTransferListener -{ - - private PrintStream out; - - private Map<TransferResource, Long> downloads = new ConcurrentHashMap<TransferResource, Long>(); - - private int lastLength; - - public ConsoleTransferListener() - { - this( null ); - } - - public ConsoleTransferListener( PrintStream out ) - { - this.out = ( out != null ) ? out : System.out; - } - - @Override - public void transferInitiated( TransferEvent event ) - { - String message = event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploading" : "Downloading"; - - out.println( message + ": " + event.getResource().getRepositoryUrl() + event.getResource().getResourceName() ); - } - - @Override - public void transferProgressed( TransferEvent event ) - { - TransferResource resource = event.getResource(); - downloads.put( resource, Long.valueOf( event.getTransferredBytes() ) ); - - StringBuilder buffer = new StringBuilder( 64 ); - - for ( Map.Entry<TransferResource, Long> entry : downloads.entrySet() ) - { - long total = entry.getKey().getContentLength(); - long complete = entry.getValue().longValue(); - - buffer.append( getStatus( complete, total ) ).append( " " ); - } - - int pad = lastLength - buffer.length(); - lastLength = buffer.length(); - pad( buffer, pad ); - buffer.append( '\r' ); - - out.print( buffer ); - } - - private String getStatus( long complete, long total ) - { - if ( total >= 1024 ) - { - return toKB( complete ) + "/" + toKB( total ) + " KB "; - } - else if ( total >= 0 ) - { - return complete + "/" + total + " B "; - } - else if ( complete >= 1024 ) - { - return toKB( complete ) + " KB "; - } - else - { - return complete + " B "; - } - } - - private void pad( StringBuilder buffer, int spaces ) - { - String block = " "; - while ( spaces > 0 ) - { - int n = Math.min( spaces, block.length() ); - buffer.append( block, 0, n ); - spaces -= n; - } - } - - @Override - public void transferSucceeded( TransferEvent event ) - { - transferCompleted( event ); - - TransferResource resource = event.getResource(); - long contentLength = event.getTransferredBytes(); - if ( contentLength >= 0 ) - { - String type = ( event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded" ); - String len = contentLength >= 1024 ? toKB( contentLength ) + " KB" : contentLength + " B"; - - String throughput = ""; - long duration = System.currentTimeMillis() - resource.getTransferStartTime(); - if ( duration > 0 ) - { - DecimalFormat format = new DecimalFormat( "0.0", new DecimalFormatSymbols( Locale.ENGLISH ) ); - double kbPerSec = ( contentLength / 1024.0 ) / ( duration / 1000.0 ); - throughput = " at " + format.format( kbPerSec ) + " KB/sec"; - } - - out.println( type + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len - + throughput + ")" ); - } - } - - @Override - public void transferFailed( TransferEvent event ) - { - transferCompleted( event ); - - event.getException().printStackTrace( out ); - } - - private void transferCompleted( TransferEvent event ) - { - downloads.remove( event.getResource() ); - - StringBuilder buffer = new StringBuilder( 64 ); - pad( buffer, lastLength ); - buffer.append( '\r' ); - out.print( buffer ); - } - - public void transferCorrupted( TransferEvent event ) - { - event.getException().printStackTrace( out ); - } - - protected long toKB( long bytes ) - { - return ( bytes + 1023 ) / 1024; - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/AllAetherDemos.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/AllAetherDemos.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/AllAetherDemos.java new file mode 100644 index 0000000..bb85d29 --- /dev/null +++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/AllAetherDemos.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.examples; + +/** + * Runs all demos at once. + */ +public class AllAetherDemos +{ + + public static void main( String[] args ) + throws Exception + { + FindAvailableVersions.main( args ); + FindNewestVersion.main( args ); + GetDirectDependencies.main( args ); + GetDependencyTree.main( args ); + ResolveArtifact.main( args ); + ResolveTransitiveDependencies.main( args ); + InstallArtifacts.main( args ); + DeployArtifacts.main( args ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/DeployArtifacts.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/DeployArtifacts.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/DeployArtifacts.java new file mode 100644 index 0000000..916c3bf --- /dev/null +++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/DeployArtifacts.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.examples; + +import java.io.File; + +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.deployment.DeployRequest; +import org.eclipse.aether.examples.util.Booter; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.util.artifact.DefaultArtifact; +import org.eclipse.aether.util.artifact.SubArtifact; + + +/** + * Deploys a JAR and its POM to a remote repository. + */ +public class DeployArtifacts +{ + + public static void main( String[] args ) + throws Exception + { + System.out.println( "------------------------------------------------------------" ); + System.out.println( DeployArtifacts.class.getSimpleName() ); + + RepositorySystem system = Booter.newRepositorySystem(); + + RepositorySystemSession session = Booter.newRepositorySystemSession( system ); + + Artifact jarArtifact = new DefaultArtifact( "test", "org.eclipse.aether.examples", "", "jar", "0.1-SNAPSHOT" ); + jarArtifact = jarArtifact.setFile( new File( "org.eclipse.aether.examples.jar" ) ); + + Artifact pomArtifact = new SubArtifact( jarArtifact, "", "pom" ); + pomArtifact = pomArtifact.setFile( new File( "pom.xml" ) ); + + RemoteRepository distRepo = + new RemoteRepository( "org.eclipse.aether.examples", "default", new File( "target/dist-repo" ).toURI().toString() ); + + DeployRequest deployRequest = new DeployRequest(); + deployRequest.addArtifact( jarArtifact ).addArtifact( pomArtifact ); + deployRequest.setRepository( distRepo ); + + system.deploy( session, deployRequest ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindAvailableVersions.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindAvailableVersions.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindAvailableVersions.java new file mode 100644 index 0000000..b3d5219 --- /dev/null +++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindAvailableVersions.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.examples; + +import java.util.List; + +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.examples.util.Booter; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.VersionRangeRequest; +import org.eclipse.aether.resolution.VersionRangeResult; +import org.eclipse.aether.util.artifact.DefaultArtifact; +import org.eclipse.aether.version.Version; + + +/** + * Determines all available versions of an artifact. + */ +public class FindAvailableVersions +{ + + public static void main( String[] args ) + throws Exception + { + System.out.println( "------------------------------------------------------------" ); + System.out.println( FindAvailableVersions.class.getSimpleName() ); + + RepositorySystem system = Booter.newRepositorySystem(); + + RepositorySystemSession session = Booter.newRepositorySystemSession( system ); + + Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-util:[0,)" ); + + RemoteRepository repo = Booter.newCentralRepository(); + + VersionRangeRequest rangeRequest = new VersionRangeRequest(); + rangeRequest.setArtifact( artifact ); + rangeRequest.addRepository( repo ); + + VersionRangeResult rangeResult = system.resolveVersionRange( session, rangeRequest ); + + List<Version> versions = rangeResult.getVersions(); + + System.out.println( "Available versions " + versions ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindNewestVersion.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindNewestVersion.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindNewestVersion.java new file mode 100644 index 0000000..4bf8eb5 --- /dev/null +++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindNewestVersion.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.examples; + +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.examples.util.Booter; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.VersionRangeRequest; +import org.eclipse.aether.resolution.VersionRangeResult; +import org.eclipse.aether.util.artifact.DefaultArtifact; +import org.eclipse.aether.version.Version; + + +/** + * Determines the newest version of an artifact. + */ +public class FindNewestVersion +{ + + public static void main( String[] args ) + throws Exception + { + System.out.println( "------------------------------------------------------------" ); + System.out.println( FindNewestVersion.class.getSimpleName() ); + + RepositorySystem system = Booter.newRepositorySystem(); + + RepositorySystemSession session = Booter.newRepositorySystemSession( system ); + + Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-util:[0,)" ); + + RemoteRepository repo = Booter.newCentralRepository(); + + VersionRangeRequest rangeRequest = new VersionRangeRequest(); + rangeRequest.setArtifact( artifact ); + rangeRequest.addRepository( repo ); + + VersionRangeResult rangeResult = system.resolveVersionRange( session, rangeRequest ); + + Version newestVersion = rangeResult.getHighestVersion(); + + System.out.println( "Newest version " + newestVersion + " from repository " + + rangeResult.getRepository( newestVersion ) ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDependencyTree.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDependencyTree.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDependencyTree.java new file mode 100644 index 0000000..8694f5e --- /dev/null +++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDependencyTree.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.examples; + +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.collection.CollectRequest; +import org.eclipse.aether.collection.CollectResult; +import org.eclipse.aether.examples.util.Booter; +import org.eclipse.aether.examples.util.ConsoleDependencyGraphDumper; +import org.eclipse.aether.graph.Dependency; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.util.artifact.DefaultArtifact; + + +/** + * Collects the transitive dependencies of an artifact. + */ +public class GetDependencyTree +{ + + public static void main( String[] args ) + throws Exception + { + System.out.println( "------------------------------------------------------------" ); + System.out.println( GetDependencyTree.class.getSimpleName() ); + + RepositorySystem system = Booter.newRepositorySystem(); + + RepositorySystemSession session = Booter.newRepositorySystemSession( system ); + + Artifact artifact = new DefaultArtifact( "org.apache.maven:maven-aether-provider:3.0.2" ); + + RemoteRepository repo = Booter.newCentralRepository(); + + CollectRequest collectRequest = new CollectRequest(); + collectRequest.setRoot( new Dependency( artifact, "" ) ); + collectRequest.addRepository( repo ); + + CollectResult collectResult = system.collectDependencies( session, collectRequest ); + + collectResult.getRoot().accept( new ConsoleDependencyGraphDumper() ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDirectDependencies.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDirectDependencies.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDirectDependencies.java new file mode 100644 index 0000000..af6a349 --- /dev/null +++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDirectDependencies.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.examples; + +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.examples.util.Booter; +import org.eclipse.aether.graph.Dependency; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.ArtifactDescriptorRequest; +import org.eclipse.aether.resolution.ArtifactDescriptorResult; +import org.eclipse.aether.util.artifact.DefaultArtifact; + + +/** + * Determines the direct dependencies of an artifact as declared in its artifact descriptor (POM). + */ +public class GetDirectDependencies +{ + + public static void main( String[] args ) + throws Exception + { + System.out.println( "------------------------------------------------------------" ); + System.out.println( GetDirectDependencies.class.getSimpleName() ); + + RepositorySystem system = Booter.newRepositorySystem(); + + RepositorySystemSession session = Booter.newRepositorySystemSession( system ); + + Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-impl:1.13" ); + + RemoteRepository repo = Booter.newCentralRepository(); + + ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest(); + descriptorRequest.setArtifact( artifact ); + descriptorRequest.addRepository( repo ); + + ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor( session, descriptorRequest ); + + for ( Dependency dependency : descriptorResult.getDependencies() ) + { + System.out.println( dependency ); + } + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/InstallArtifacts.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/InstallArtifacts.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/InstallArtifacts.java new file mode 100644 index 0000000..f0ecf11 --- /dev/null +++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/InstallArtifacts.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.examples; + +import java.io.File; + +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.examples.util.Booter; +import org.eclipse.aether.installation.InstallRequest; +import org.eclipse.aether.util.artifact.DefaultArtifact; +import org.eclipse.aether.util.artifact.SubArtifact; + + +/** + * Installs a JAR and its POM to the local repository. + */ +public class InstallArtifacts +{ + + public static void main( String[] args ) + throws Exception + { + System.out.println( "------------------------------------------------------------" ); + System.out.println( InstallArtifacts.class.getSimpleName() ); + + RepositorySystem system = Booter.newRepositorySystem(); + + RepositorySystemSession session = Booter.newRepositorySystemSession( system ); + + Artifact jarArtifact = new DefaultArtifact( "test", "org.eclipse.aether.examples", "", "jar", "0.1-SNAPSHOT" ); + jarArtifact = jarArtifact.setFile( new File( "org.eclipse.aether.examples.jar" ) ); + + Artifact pomArtifact = new SubArtifact( jarArtifact, "", "pom" ); + pomArtifact = pomArtifact.setFile( new File( "pom.xml" ) ); + + InstallRequest installRequest = new InstallRequest(); + installRequest.addArtifact( jarArtifact ).addArtifact( pomArtifact ); + + system.install( session, installRequest ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/e86cfec6/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveArtifact.java ---------------------------------------------------------------------- diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveArtifact.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveArtifact.java new file mode 100644 index 0000000..8b05cfc --- /dev/null +++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveArtifact.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.examples; + +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.examples.util.Booter; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.ArtifactRequest; +import org.eclipse.aether.resolution.ArtifactResult; +import org.eclipse.aether.util.artifact.DefaultArtifact; + + +/** + * Resolves a single artifact. + */ +public class ResolveArtifact +{ + + public static void main( String[] args ) + throws Exception + { + System.out.println( "------------------------------------------------------------" ); + System.out.println( ResolveArtifact.class.getSimpleName() ); + + RepositorySystem system = Booter.newRepositorySystem(); + + RepositorySystemSession session = Booter.newRepositorySystemSession( system ); + + Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-util:1.13" ); + + RemoteRepository repo = Booter.newCentralRepository(); + + ArtifactRequest artifactRequest = new ArtifactRequest(); + artifactRequest.setArtifact( artifact ); + artifactRequest.addRepository( repo ); + + ArtifactResult artifactResult = system.resolveArtifact( session, artifactRequest ); + + artifact = artifactResult.getArtifact(); + + System.out.println( artifact + " resolved to " + artifact.getFile() ); + } + +}