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