org.eclipse.aether.repository.LocalRepository Java Examples

The following examples show how to use org.eclipse.aether.repository.LocalRepository. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DependencyResolver.java    From spring-init with Apache License 2.0 6 votes vote down vote up
private DefaultRepositorySystemSession createSession(Properties properties)
		throws NoLocalRepositoryManagerException {
	DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
	LocalRepository repository = localRepository(properties);
	session.setLocalRepositoryManager(
			localRepositoryManagerFactory.newInstance(session, repository));
	applySettings(session);
	ProxySelector existing = session.getProxySelector();
	if (existing == null || !(existing instanceof CompositeProxySelector)) {
		JreProxySelector fallback = new JreProxySelector();
		ProxySelector selector = existing == null ? fallback
				: new CompositeProxySelector(Arrays.asList(existing, fallback));
		session.setProxySelector(selector);
	}
	return session;
}
 
Example #2
Source File: MavenPluginRepository.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
private DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system, File localRepoFile, Settings settings) {
	DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
	if (!settings.getMirrors().isEmpty()) {
		DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
		for (Mirror mirror : settings.getMirrors()) {
			mirrorSelector.add(mirror.getId(), mirror.getUrl(), "default", true, mirror.getMirrorOf(), "*");
		}
		session.setMirrorSelector(mirrorSelector);
	}
	session.setProxySelector(proxySelector);

	LocalRepository localRepo = new LocalRepository(localRepoFile);
	session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

	return session;
}
 
Example #3
Source File: AetherFactories.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
public static RepositorySystemSession newSession(RepositorySystem system,
		boolean workOffline) {
	DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
	session.setOffline(workOffline);
	if (!workOffline) {
		session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
	}
	session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_WARN);
	String localRepositoryDirectory = localRepositoryDirectory(workOffline);
	if (log.isDebugEnabled()) {
		log.debug("Local Repository Directory set to [" + localRepositoryDirectory
				+ "]. Work offline: [" + workOffline + "]");
	}
	LocalRepository localRepo = new LocalRepository(localRepositoryDirectory);
	session.setLocalRepositoryManager(
			system.newLocalRepositoryManager(session, localRepo));
	return session;
}
 
Example #4
Source File: JavaFXRunMojoTestCase.java    From javafx-maven-plugin with Apache License 2.0 6 votes vote down vote up
private void setUpProject(File pomFile, AbstractMojo mojo) throws Exception {
    super.setUp();

    MockitoAnnotations.initMocks(this);

    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    buildingRequest.setResolveDependencies(true);
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    DefaultRepositorySystemSession repositorySession = MavenRepositorySystemUtils.newSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
            .newInstance(repositorySession, new LocalRepository(RepositorySystem.defaultUserLocalRepository)));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);

    ProjectBuilder builder = lookup(ProjectBuilder.class);
    ProjectBuildingResult build = builder.build(pomFile, buildingRequest);
    MavenProject project = build.getProject();

    project.getBuild().setOutputDirectory(new File( "target/test-classes").getAbsolutePath());
    setVariableValueToObject(mojo, "project", project);
}
 
Example #5
Source File: MavenSettingsReader.java    From spring-cloud-function with Apache License 2.0 6 votes vote down vote up
public static void applySettings(MavenSettings settings,
		DefaultRepositorySystemSession session) {
	if (settings.getLocalRepository() != null) {
		try {
			session.setLocalRepositoryManager(
					new SimpleLocalRepositoryManagerFactory().newInstance(session,
							new LocalRepository(settings.getLocalRepository())));
		}
		catch (NoLocalRepositoryManagerException e) {
			throw new IllegalStateException(
					"Cannot set local repository to " + settings.getLocalRepository(),
					e);
		}
	}
	session.setOffline(settings.getOffline());
	session.setMirrorSelector(settings.getMirrorSelector());
	session.setAuthenticationSelector(settings.getAuthenticationSelector());
	session.setProxySelector(settings.getProxySelector());
}
 
Example #6
Source File: DependencyResolver.java    From spring-cloud-function with Apache License 2.0 6 votes vote down vote up
private DefaultRepositorySystemSession createSession(Properties properties)
		throws NoLocalRepositoryManagerException {
	DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
	LocalRepository repository = localRepository(properties);
	session.setLocalRepositoryManager(
			this.localRepositoryManagerFactory.newInstance(session, repository));
	applySettings(session);
	ProxySelector existing = session.getProxySelector();
	if (existing == null || !(existing instanceof CompositeProxySelector)) {
		JreProxySelector fallback = new JreProxySelector();
		ProxySelector selector = existing == null ? fallback
				: new CompositeProxySelector(Arrays.asList(existing, fallback));
		session.setProxySelector(selector);
	}
	return session;
}
 
Example #7
Source File: MavenArtifactResolver.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private MavenArtifactResolver(Builder builder) throws BootstrapMavenException {
    final BootstrapMavenContext mvnSettings = new BootstrapMavenContext(builder);
    this.repoSystem = mvnSettings.getRepositorySystem();

    final RepositorySystemSession session = mvnSettings.getRepositorySystemSession();
    if (builder.localRepo != null && builder.reTryFailedResolutionsAgainstDefaultLocalRepo) {
        localRepoManager = new MavenLocalRepositoryManager(
                repoSystem.newLocalRepositoryManager(session, new LocalRepository(builder.localRepo)),
                Paths.get(BootstrapMavenContext.resolveLocalRepo(mvnSettings.getEffectiveSettings())));
        this.repoSession = new DefaultRepositorySystemSession(session).setLocalRepositoryManager(localRepoManager);
    } else {
        this.repoSession = session;
        localRepoManager = null;
    }

    this.remoteRepos = mvnSettings.getRemoteRepositories();
    this.remoteRepoManager = mvnSettings.getRemoteRepositoryManager();
}
 
Example #8
Source File: InstallDeployTest.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
private MavenSession newSession(MavenProject project, File localrepo, Properties properties) throws Exception {
  MavenExecutionRequest request = new DefaultMavenExecutionRequest();
  MavenExecutionResult result = new DefaultMavenExecutionResult();
  DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession();
  LocalRepository localRepo = new LocalRepository(localrepo);
  repoSession.setLocalRepositoryManager(mojos.getContainer().lookup(LocalRepositoryManagerFactory.class, "simple").newInstance(repoSession, localRepo));
  MavenSession session = new MavenSession(mojos.getContainer(), repoSession, request, result);
  List<MavenProject> projects = new ArrayList<>();
  projects.add(project);
  for (String module : project.getModules()) {
    MavenProject moduleProject = readMavenProject(new File(project.getBasedir(), module), properties);
    moduleProject.setParent(project);
    projects.add(moduleProject);
  }

  session.setProjects(projects);
  return session;
}
 
Example #9
Source File: MavenSettingsReader.java    From spring-init with Apache License 2.0 6 votes vote down vote up
public static void applySettings(MavenSettings settings,
		DefaultRepositorySystemSession session) {
	if (settings.getLocalRepository() != null) {
		try {
			session.setLocalRepositoryManager(
					new SimpleLocalRepositoryManagerFactory().newInstance(session,
							new LocalRepository(settings.getLocalRepository())));
		}
		catch (NoLocalRepositoryManagerException e) {
			throw new IllegalStateException(
					"Cannot set local repository to " + settings.getLocalRepository(),
					e);
		}
	}
	session.setOffline(settings.getOffline());
	session.setMirrorSelector(settings.getMirrorSelector());
	session.setAuthenticationSelector(settings.getAuthenticationSelector());
	session.setProxySelector(settings.getProxySelector());
}
 
Example #10
Source File: MavenSystemManager.java    From archiva with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new aether repository system session for the given directory and assigns the
 * repository to this session.
 *
 * @param localRepoDir The repository directory
 * @return The newly created session object.
 */
public static RepositorySystemSession newRepositorySystemSession(String localRepoDir) {
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

    LocalRepository repo = new LocalRepository(localRepoDir);

    DependencySelector depFilter = new AndDependencySelector(new ExclusionDependencySelector());
    session.setDependencySelector(depFilter);
    SimpleLocalRepositoryManagerFactory repFactory = new SimpleLocalRepositoryManagerFactory();
    try {
        LocalRepositoryManager manager = repFactory.newInstance(session, repo);
        session.setLocalRepositoryManager(manager);
    } catch (NoLocalRepositoryManagerException e) {
        log.error("Could not assign the repository manager to the session: {}", e.getMessage(), e);
    }

    return session;
}
 
Example #11
Source File: Resolver.java    From buck with Apache License 2.0 6 votes vote down vote up
public Resolver(ArtifactConfig config) {
  this.modelBuilder =
      new DefaultModelBuilderFactory()
          .newInstance()
          .setProfileSelector(new DefaultProfileSelector())
          .setPluginConfigurationExpander(new DefaultPluginConfigurationExpander())
          .setPluginManagementInjector(new DefaultPluginManagementInjector())
          .setDependencyManagementImporter(new DefaultDependencyManagementImporter())
          .setDependencyManagementInjector(new DefaultDependencyManagementInjector());
  ServiceLocator locator = AetherUtil.initServiceLocator();
  this.repoSys = locator.getService(RepositorySystem.class);
  this.localRepo = new LocalRepository(Paths.get(config.mavenLocalRepo).toFile());
  this.session = newSession(repoSys, localRepo);

  this.buckRepoRoot = Paths.get(Objects.requireNonNull(config.buckRepoRoot));
  this.buckThirdPartyRelativePath = Paths.get(Objects.requireNonNull(config.thirdParty));
  this.visibility = config.visibility;

  this.repos =
      config.repositories.stream()
          .map(AetherUtil::toRemoteRepository)
          .collect(ImmutableList.toImmutableList());
}
 
Example #12
Source File: DependencyResolver.java    From start.spring.io with Apache License 2.0 6 votes vote down vote up
DependencyResolver() {
	try {
		ServiceLocator serviceLocator = createServiceLocator();
		DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
		session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(false, false));
		this.localRepositoryLocation = Files.createTempDirectory("metadata-validation-m2");
		LocalRepository localRepository = new LocalRepository(this.localRepositoryLocation.toFile());
		this.repositorySystem = serviceLocator.getService(RepositorySystem.class);
		session.setLocalRepositoryManager(
				this.repositorySystem.newLocalRepositoryManager(session, localRepository));
		session.setReadOnly();
		this.repositorySystemSession = session;
	}
	catch (Exception ex) {
		throw new RuntimeException(ex);
	}
}
 
Example #13
Source File: MavenUtil.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public static DefaultRepositorySystemSession newRepositorySystemSession ( final RepositorySystem system )
{
    final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession ();

    final LocalRepository localRepo = new LocalRepository ( "target/local-repo" );
    session.setLocalRepositoryManager ( system.newLocalRepositoryManager ( session, localRepo ) );

    return session;
}
 
Example #14
Source File: AetherUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private RepositorySystemSession getRepositorySystemSession(RepositorySystem system, String  localRepositoryPath) {
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

    LocalRepository localRepo = new LocalRepository(localRepositoryPath);
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

    return session;
}
 
Example #15
Source File: MavenInitializer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public static RepositorySystemSession newSession(RepositorySystem system) {
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

    LocalRepository localRepo = new LocalRepository(localRepoLocation());
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

    return session;
}
 
Example #16
Source File: DependencyResolver.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system) {
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    session.setCache(newRepositoryCache());
    String localRepositoryPath = resolveLocalRepository();
    if (logger.isLoggable(Level.INFO)) {
        logger.info("Local repository: " + localRepositoryPath);
    }
    LocalRepository localRepository = new LocalRepository(localRepositoryPath);

    LocalRepositoryManager localRepositoryManager = system.newLocalRepositoryManager(session, localRepository);
    session.setLocalRepositoryManager(localRepositoryManager);

    return session;
}
 
Example #17
Source File: Aether.java    From pro with GNU General Public License v3.0 5 votes vote down vote up
public static Aether create(Path mavenLocalRepository, List<URI> remoteRepositories) {
  // respository system
  var locator = MavenRepositorySystemUtils.newServiceLocator();
  locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
  locator.addService(TransporterFactory.class, FileTransporterFactory.class);
  locator.addService(TransporterFactory.class, HttpTransporterFactory.class);

  locator.setErrorHandler(new DefaultServiceLocator.ErrorHandler() {
    @Override
    public void serviceCreationFailed(Class<?> type, Class<?> impl, Throwable exception) {
      exception.printStackTrace();
    }
  });
  RepositorySystem system = locator.getService(RepositorySystem.class);

  // session
  var session = MavenRepositorySystemUtils.newSession();
  var localRepository = new LocalRepository(mavenLocalRepository.toString());
  session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepository));

  // central repository
  var central = new RemoteRepository.Builder("central", "default",
      "https://repo1.maven.org/maven2/").build();
  
  // remote repositories
  var remotes = Stream.concat(
        remoteRepositories.stream().map(uri -> new RemoteRepository.Builder(null, "default", uri.toString()).build()),
        Stream.of(central)
      )
      .collect(Collectors.toUnmodifiableList());
  
  return new Aether(system, session, remotes);
}
 
Example #18
Source File: ArtifactTransporter.java    From jenkins-build-monitor-plugin with MIT License 5 votes vote down vote up
private DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system) {
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

    LocalRepository localRepo = new LocalRepository(localRepositoryLocation.toAbsolutePath().toString());
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

    session.setTransferListener(new ConsoleTransferListener());
    session.setRepositoryListener(new ConsoleRepositoryListener());

    return session;
}
 
Example #19
Source File: RemotePluginRepository.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system) {
	DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

	LocalRepository localRepo = new LocalRepository("target/local-repo");
	session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

	session.setTransferListener(new ConsoleTransferListener());
	session.setRepositoryListener(new ConsoleRepositoryListener());

	// uncomment to generate dirty trees
	// session.setDependencyGraphTransformer( null );

	return session;
}
 
Example #20
Source File: ModifiedClassPathRunner.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
private List<URL> resolveCoordinates(String[] coordinates) throws Exception {
	DefaultServiceLocator serviceLocator = MavenRepositorySystemUtils
			.newServiceLocator();
	serviceLocator.addService(RepositoryConnectorFactory.class,
			BasicRepositoryConnectorFactory.class);
	serviceLocator.addService(TransporterFactory.class, HttpTransporterFactory.class);
	RepositorySystem repositorySystem = serviceLocator
			.getService(RepositorySystem.class);
	DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
	LocalRepository localRepository = new LocalRepository(
			System.getProperty("user.home") + "/.m2/repository");
	session.setLocalRepositoryManager(
			repositorySystem.newLocalRepositoryManager(session, localRepository));
	CollectRequest collectRequest = new CollectRequest(null,
			Arrays.asList(new RemoteRepository.Builder("central", "default",
					"https://repo.maven.apache.org/maven2").build()));

	collectRequest.setDependencies(createDependencies(coordinates));
	DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null);
	DependencyResult result = repositorySystem.resolveDependencies(session,
			dependencyRequest);
	List<URL> resolvedArtifacts = new ArrayList<>();
	for (ArtifactResult artifact : result.getArtifactResults()) {
		resolvedArtifacts.add(artifact.getArtifact().getFile().toURI().toURL());
	}
	return resolvedArtifacts;
}
 
Example #21
Source File: Main.java    From revapi with Apache License 2.0 5 votes vote down vote up
private static ArchivesAndSupplementaryArchives convertGavs(String[] gavs, String errorMessagePrefix,
        File localRepo, List<RemoteRepository> remoteRepositories) {
    RepositorySystem repositorySystem = MavenBootstrap.newRepositorySystem();
    DefaultRepositorySystemSession session = MavenBootstrap.newRepositorySystemSession(repositorySystem,
            new LocalRepository(localRepo));

    session.setDependencySelector(getRevapiDependencySelector(true, false));
    session.setDependencyTraverser(getRevapiDependencyTraverser(true, false));

    ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, remoteRepositories);

    List<FileArchive> archives = new ArrayList<>();
    List<FileArchive> supplementaryArchives = new ArrayList<>();

    for (String gav : gavs) {
        try {
            archives.add(new FileArchive(resolver.resolveArtifact(gav).getFile()));
            ArtifactResolver.CollectionResult res = resolver.collectTransitiveDeps(gav);

            res.getResolvedArtifacts().
                    forEach(a -> supplementaryArchives.add(new FileArchive(a.getFile())));
            if (!res.getFailures().isEmpty()) {
                LOG.warn("Failed to resolve some transitive dependencies: " + res.getFailures().toString());
            }
        } catch (RepositoryException e) {
            throw new IllegalArgumentException(errorMessagePrefix + " " + e.getMessage());
        }
    }

    return new ArchivesAndSupplementaryArchives(archives, supplementaryArchives);
}
 
Example #22
Source File: Cadfael.java    From Poseidon with Apache License 2.0 5 votes vote down vote up
private RepositorySystemSession newSession(RepositorySystem system) {
        DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
        LocalRepository localRepo = new LocalRepository("target/local-repo");
        session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
        // set possible proxies and mirrors
//        session.setProxySelector(new DefaultProxySelector().add(new Proxy(Proxy.TYPE_HTTP, "host", 3625), Arrays.asList("localhost", "127.0.0.1")));
//        session.setMirrorSelector(new DefaultMirrorSelector().add("my-mirror", "http://mirror", "default", false, "external:*", null));
        return session;
    }
 
Example #23
Source File: Booter.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system)
{
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

    LocalRepository localRepo = new LocalRepository("target/local-repo");
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

    session.setTransferListener(new ConsoleTransferListener());
    session.setRepositoryListener(new ConsoleRepositoryListener());

    // uncomment to generate dirty trees
    // session.setDependencyGraphTransformer( null );

    return session;
}
 
Example #24
Source File: RepositoryHandler.java    From maven-repository-tools with Eclipse Public License 1.0 5 votes vote down vote up
private static DefaultRepositorySystemSession newRepositorySystemSession( RepositorySystem system, 
                                                                         File localRepoPath )
{
    DefaultRepositorySystemSession newSession = MavenRepositorySystemUtils.newSession();

    LocalRepository localRepo = new LocalRepository( localRepoPath );
    newSession.setLocalRepositoryManager( system.newLocalRepositoryManager( newSession, localRepo ) );

    newSession.setTransferListener( getTransferListener() );
    newSession.setRepositoryListener( repositoryListener );

    return newSession;
}
 
Example #25
Source File: RemotePluginLoader.java    From digdag with Apache License 2.0 5 votes vote down vote up
private static RepositorySystemSession newRepositorySystemSession(RepositorySystem system, Path localRepositoryPath)
{
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

    LocalRepository localRepo = new LocalRepository(localRepositoryPath.toString());
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

    //session.setTransferListener(new ConsoleTransferListener());
    //session.setRepositoryListener(new ConsoleRepositoryListener());

    return session;
}
 
Example #26
Source File: Maven.java    From bazel-deps with MIT License 5 votes vote down vote up
public static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system) {
  DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

  LocalRepository localRepo = new LocalRepository("target/local-repo");
  session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

  return session;
}
 
Example #27
Source File: PluginAddCommand.java    From gyro with Apache License 2.0 5 votes vote down vote up
private boolean validate(String plugin) {
    try {
        DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();

        locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
        locator.addService(TransporterFactory.class, FileTransporterFactory.class);
        locator.addService(TransporterFactory.class, HttpTransporterFactory.class);

        RepositorySystem system = locator.getService(RepositorySystem.class);
        DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
        String localDir = Paths.get(System.getProperty("user.home"), ".m2", "repository").toString();
        LocalRepository local = new LocalRepository(localDir);
        LocalRepositoryManager manager = system.newLocalRepositoryManager(session, local);

        session.setLocalRepositoryManager(manager);

        Artifact artifact = new DefaultArtifact(plugin);
        Dependency dependency = new Dependency(artifact, JavaScopes.RUNTIME);
        DependencyFilter filter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME);
        CollectRequest collectRequest = new CollectRequest(dependency, repositories);
        DependencyRequest request = new DependencyRequest(collectRequest, filter);
        system.resolveDependencies(session, request);

        return true;
    } catch (DependencyResolutionException e) {
        GyroCore.ui().write("@|bold %s|@ was not installed for the following reason(s):\n", plugin);

        for (Exception ex : e.getResult().getCollectExceptions()) {
            GyroCore.ui().write("   @|red %s|@\n", ex.getMessage());
        }

        GyroCore.ui().write("\n");

        return false;
    }
}
 
Example #28
Source File: BetterAbstractMojoTestCase.java    From markdown-page-generator-plugin with MIT License 5 votes vote down vote up
protected MavenSession newMavenSession() {
    try {
        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
        MavenExecutionResult result = new DefaultMavenExecutionResult();

        // populate sensible defaults, including repository basedir and remote repos
        MavenExecutionRequestPopulator populator;
        populator = getContainer().lookup(MavenExecutionRequestPopulator.class);
        populator.populateDefaults(request);

        // this is needed to allow java profiles to get resolved; i.e. avoid during project builds:
        // [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14
        request.setSystemProperties(System.getProperties());

        // and this is needed so that the repo session in the maven session
        // has a repo manager, and it points at the local repo
        // (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done)
        DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class);
        DefaultRepositorySystemSession repoSession =
                (DefaultRepositorySystemSession) maven.newRepositorySession(request);
        repoSession.setLocalRepositoryManager(
                new SimpleLocalRepositoryManagerFactory().newInstance(repoSession,
                        new LocalRepository(request.getLocalRepository().getBasedir())));

        @SuppressWarnings("deprecation")
        MavenSession session = new MavenSession(getContainer(),
                repoSession,
                request, result);
        return session;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #29
Source File: Publisher.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * @param localRepoPath Typically obtained as {@link ProjectFilesystem#getRootPath}
 * @param remoteRepoUrl Canonically {@link #MAVEN_CENTRAL_URL}
 * @param dryRun if true, a dummy {@link DeployResult} will be returned, with the fully
 *     constructed {@link DeployRequest}. No actual publishing will happen
 */
public Publisher(
    Path localRepoPath,
    URL remoteRepoUrl,
    Optional<String> username,
    Optional<String> password,
    boolean dryRun) {
  this.localRepo = new LocalRepository(localRepoPath.toFile());
  this.remoteRepo = AetherUtil.toRemoteRepository(remoteRepoUrl, username, password);
  this.locator = AetherUtil.initServiceLocator();
  this.dryRun = dryRun;
}
 
Example #30
Source File: Resolver.java    From buck with Apache License 2.0 5 votes vote down vote up
private static RepositorySystemSession newSession(
    RepositorySystem repoSys, LocalRepository localRepo) {
  DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

  session.setLocalRepositoryManager(repoSys.newLocalRepositoryManager(session, localRepo));
  session.setReadOnly();

  return session;
}