tech.guyi.ipojo.compile.lib.maven.util.Booter Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright (c) 2010, 2014 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 tech.guyi.ipojo.compile.lib.maven.util;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.RemoteRepository;
import tech.guyi.ipojo.compile.lib.maven.manual.ManualRepositorySystemFactory;
import tech.guyi.ipojo.compile.lib.configuration.entry.Project;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 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, Project project) {
return newRepositorySystemSession(system,project.getLocalRepository());
}
public static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system, String localRepository) {
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
LocalRepository localRepo = new LocalRepository(localRepository);
session.setLocalRepositoryManager( system.newLocalRepositoryManager(session,localRepo) );
session.setTransferListener( new ConsoleTransferListener() );
session.setRepositoryListener( new ConsoleRepositoryListener() );
return session;
}
public static List newRepositories(RepositorySystem system, RepositorySystemSession session )
{
return new ArrayList( Arrays.asList( newCentralRepository() ) );
}
private static RemoteRepository newCentralRepository()
{
return new RemoteRepository.Builder( "central", "default", "http://central.maven.org/maven2/" ).build();
}
}