001package org.apache.maven.resolver.examples;
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;
023
024import org.apache.maven.resolver.examples.util.Booter;
025import org.eclipse.aether.RepositorySystem;
026import org.eclipse.aether.RepositorySystemSession;
027import org.eclipse.aether.artifact.Artifact;
028import org.eclipse.aether.artifact.DefaultArtifact;
029import org.eclipse.aether.deployment.DeployRequest;
030import org.eclipse.aether.repository.RemoteRepository;
031import org.eclipse.aether.util.artifact.SubArtifact;
032
033/**
034 * Deploys a JAR and its POM to a remote repository.
035 */
036public class DeployArtifacts
037{
038
039    /**
040     * Main.
041     * @param args
042     * @throws Exception
043     */
044    public static void main( String[] args )
045        throws Exception
046    {
047        System.out.println( "------------------------------------------------------------" );
048        System.out.println( DeployArtifacts.class.getSimpleName() );
049
050        RepositorySystem system = Booter.newRepositorySystem();
051
052        RepositorySystemSession session = Booter.newRepositorySystemSession( system );
053
054        Artifact jarArtifact = new DefaultArtifact( "test", "org.apache.maven.aether.examples", "", 
055            "jar", "0.1-SNAPSHOT" );
056        jarArtifact = jarArtifact.setFile( new File( "src/main/data/demo.jar" ) );
057
058        Artifact pomArtifact = new SubArtifact( jarArtifact, "", "pom" );
059        pomArtifact = pomArtifact.setFile( new File( "pom.xml" ) );
060
061        RemoteRepository distRepo =
062            new RemoteRepository.Builder( "org.apache.maven.aether.examples", "default",
063                                  new File( "target/dist-repo" ).toURI().toString() ).build();
064
065        DeployRequest deployRequest = new DeployRequest();
066        deployRequest.addArtifact( jarArtifact ).addArtifact( pomArtifact );
067        deployRequest.setRepository( distRepo );
068
069        system.deploy( session, deployRequest );
070    }
071
072}