001package org.apache.maven.resolver.examples.resolver; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.File; 023import java.util.List; 024 025import org.eclipse.aether.artifact.Artifact; 026import org.eclipse.aether.artifact.DefaultArtifact; 027import org.eclipse.aether.deployment.DeploymentException; 028import org.eclipse.aether.graph.DependencyNode; 029import org.eclipse.aether.installation.InstallationException; 030import org.eclipse.aether.resolution.DependencyResolutionException; 031import org.eclipse.aether.util.artifact.SubArtifact; 032 033/** 034 */ 035@SuppressWarnings( "unused" ) 036public class ResolverDemo 037{ 038 039 public void resolve() 040 throws DependencyResolutionException 041 { 042 Resolver resolver = new Resolver( "http://localhost:8081/nexus/content/groups/public", "target/aether-repo" ); 043 044 ResolverResult result = resolver.resolve( "com.mycompany.app", "super-app", "1.0" ); 045 046 // Get the root of the resolved tree of artifacts 047 // 048 DependencyNode root = result.getRoot(); 049 050 // Get the list of files for the artifacts resolved 051 // 052 List<File> artifacts = result.getResolvedFiles(); 053 054 // Get the classpath of the artifacts resolved 055 // 056 String classpath = result.getResolvedClassPath(); 057 } 058 059 public void installAndDeploy() 060 throws InstallationException, DeploymentException 061 { 062 Resolver resolver = new Resolver( "http://localhost:8081/nexus/content/groups/public", "target/aether-repo" ); 063 064 Artifact artifact = new DefaultArtifact( "com.mycompany.super", "super-core", "jar", "0.1-SNAPSHOT" ); 065 artifact = artifact.setFile( new File( "jar-from-whatever-process.jar" ) ); 066 Artifact pom = new SubArtifact( artifact, null, "pom" ); 067 pom = pom.setFile( new File( "pom-from-whatever-process.xml" ) ); 068 069 // Install into the local repository specified 070 // 071 resolver.install( artifact, pom ); 072 073 // Deploy to a remote reposistory 074 // 075 resolver.deploy( artifact, pom, "http://localhost:8081/nexus/content/repositories/snapshots/" ); 076 } 077 078}