Java Code Examples for org.eclipse.aether.DefaultRepositorySystemSession#setLocalRepositoryManager()

The following examples show how to use org.eclipse.aether.DefaultRepositorySystemSession#setLocalRepositoryManager() . 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: 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 2
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 3
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 4
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 5
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 6
Source File: DependencyGraphBuilder.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private DependencyNode resolveCompileTimeDependencies(
    List<DependencyNode> dependencyNodes, DefaultRepositorySystemSession session)
    throws DependencyResolutionException {

  ImmutableList.Builder<Dependency> dependenciesBuilder = ImmutableList.builder();
  for (DependencyNode dependencyNode : dependencyNodes) {
    Dependency dependency = dependencyNode.getDependency();
    if (dependency == null) {
      // Root DependencyNode has null dependency field.
      dependenciesBuilder.add(new Dependency(dependencyNode.getArtifact(), "compile"));
    } else {
      // The dependency field carries exclusions
      dependenciesBuilder.add(dependency.setScope("compile"));
    }
  }
  ImmutableList<Dependency> dependencyList = dependenciesBuilder.build();
          
  if (localRepository != null) {
    LocalRepository local = new LocalRepository(localRepository.toAbsolutePath().toString());
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, local));
  }

  CollectRequest collectRequest = new CollectRequest();
  if (dependencyList.size() == 1) {
    // With setRoot, the result includes dependencies with `optional:true` or `provided`
    collectRequest.setRoot(dependencyList.get(0));
  } else {
    collectRequest.setDependencies(dependencyList);
  }
  for (RemoteRepository repository : repositories) {
    collectRequest.addRepository(repository);
  }
  DependencyRequest dependencyRequest = new DependencyRequest();
  dependencyRequest.setCollectRequest(collectRequest);

  // resolveDependencies equals to calling both collectDependencies (build dependency tree) and
  // resolveArtifacts (download JAR files).
  DependencyResult dependencyResult = system.resolveDependencies(session, dependencyRequest);
  return dependencyResult.getRoot();
}
 
Example 7
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 8
Source File: MavenContainer.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
public DefaultRepositorySystemSession setupRepoSession(final RepositorySystem repoSystem, final Settings settings)
{
   DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
   session.setOffline(false);

   Proxy activeProxy = settings.getActiveProxy();
   if (activeProxy != null)
   {
      DefaultProxySelector dps = new DefaultProxySelector();
      dps.add(convertFromMavenProxy(activeProxy), activeProxy.getNonProxyHosts());
      session.setProxySelector(dps);
   }

   final DefaultMirrorSelector mirrorSelector = createMirrorSelector(settings);
   final LazyAuthenticationSelector authSelector = createAuthSelector(settings, mirrorSelector);

   session.setMirrorSelector(mirrorSelector);
   session.setAuthenticationSelector(authSelector);

   LocalRepository localRepo = new LocalRepository(new File(settings.getLocalRepository()));
   session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
   session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_IGNORE);
   session.setCache(new DefaultRepositoryCache());
   boolean cacheNotFoundArtifacts = true;
   boolean cacheTransferErrors = true;
   session.setResolutionErrorPolicy(new SimpleResolutionErrorPolicy(cacheNotFoundArtifacts, cacheTransferErrors));
   session.setWorkspaceReader(new ClasspathWorkspaceReader());
   if (Boolean.getBoolean("org.apache.maven.log_transfer"))
   {
      session.setTransferListener(new JULMavenTransferListener());
   }
   return session;
}
 
Example 9
Source File: MavenResolverDependencyManagementVersionResolver.java    From initializr with Apache License 2.0 5 votes vote down vote up
MavenResolverDependencyManagementVersionResolver(Path cacheLocation) {
	ServiceLocator serviceLocator = createServiceLocator();
	DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
	session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(false, false));
	LocalRepository localRepository = new LocalRepository(cacheLocation.toFile());
	this.repositorySystem = serviceLocator.getService(RepositorySystem.class);
	session.setLocalRepositoryManager(this.repositorySystem.newLocalRepositoryManager(session, localRepository));
	session.setReadOnly();
	this.repositorySystemSession = session;
}
 
Example 10
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 11
Source File: RepositoryUtility.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static DefaultRepositorySystemSession createDefaultRepositorySystemSession(
    RepositorySystem system) {
  DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
  LocalRepository localRepository = new LocalRepository(findLocalRepository());
  session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepository));
  return session;
}
 
Example 12
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 13
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 14
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 15
Source File: MavenDependencyResolver.java    From spring-cloud-formula with Apache License 2.0 5 votes vote down vote up
private RepositorySystemSession newSession(RepositorySystem system) {
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

    String home = System.getenv("HOME");
    LocalRepository localRepo = new LocalRepository(new File(home, ".m2/repository"));
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

    return session;
}
 
Example 16
Source File: PluginPreprocessor.java    From gyro with Apache License 2.0 4 votes vote down vote up
@Override
public List<Node> preprocess(List<Node> nodes, RootScope scope) {
    PluginSettings settings = scope.getSettings(PluginSettings.class);

    List<String> artifactCoords = new ArrayList<>();
    List<Node> repositoryNodes = new ArrayList<>();

    for (Node node : nodes) {
        if (node instanceof DirectiveNode) {
            if ("plugin".equals(((DirectiveNode) node).getName())) {
                artifactCoords.add(getArtifactCoord((DirectiveNode) node));
            } else if ("repository".equals(((DirectiveNode) node).getName())) {
                repositoryNodes.add(node);
            }
        }
    }

    if (artifactCoords.stream().allMatch(settings::pluginInitialized)) {
        return nodes;
    }

    NodeEvaluator evaluator = new NodeEvaluator();
    evaluator.evaluate(scope, repositoryNodes);

    for (String ac : artifactCoords) {
        if (settings.pluginInitialized(ac)) {
            continue;
        }

        try {
            GyroCore.ui().write("@|magenta ↓ Loading plugin:|@ %s\n", ac);

            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(ac);
            Dependency dependency = new Dependency(artifact, JavaScopes.RUNTIME);
            DependencyFilter filter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME);
            List<RemoteRepository> repositories = scope.getSettings(RepositorySettings.class).getRepositories();
            CollectRequest collectRequest = new CollectRequest(dependency, repositories);
            DependencyRequest request = new DependencyRequest(collectRequest, filter);
            DependencyResult result = system.resolveDependencies(session, request);

            settings.putDependencyResult(ac, result);

            for (ArtifactResult ar : result.getArtifactResults()) {
                settings.putArtifactIfNewer(ar.getArtifact());
            }
        } catch (Exception error) {
            throw new GyroException(
                String.format("Can't load the @|bold %s|@ plugin!", ac),
                error);
        }
    }

    settings.addAllUrls();

    return nodes;
}
 
Example 17
Source File: AetherUtil.java    From vertx-deploy-tools with Apache License 2.0 4 votes vote down vote up
public static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system) {
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    LocalRepository localRepo = new LocalRepository(System.getProperty("user.home") + "/.m2/repository");
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
    return session;
}
 
Example 18
Source File: LibertyFeatureVersionIT.java    From boost with Eclipse Public License 1.0 4 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));
    return session;
}
 
Example 19
Source File: MavenArtifactResolver.java    From javafx-maven-plugin with Apache License 2.0 4 votes vote down vote up
private DefaultRepositorySystemSession createRepositorySystemSession(RepositorySystem system, String localRepoPath) {
    DefaultRepositorySystemSession systemSession = MavenRepositorySystemUtils.newSession();
    LocalRepository localRepo = new LocalRepository(localRepoPath);
    systemSession.setLocalRepositoryManager(system.newLocalRepositoryManager(systemSession, localRepo));
    return systemSession;
}
 
Example 20
Source File: ArtifactResolverTest.java    From revapi with Apache License 2.0 3 votes vote down vote up
public static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system,
        File localRepoLocation) {

    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

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

    session.setTransferListener(new AbstractTransferListener() {});
    session.setRepositoryListener(new AbstractRepositoryListener() {});

    return session;
}