Search in sources :

Example 6 with RepositorySystem

use of org.eclipse.aether.RepositorySystem in project spf4j by zolyfarkas.

the class MavenRepositoryUtils method resolveArtifactAndDependencies.

public static Set<File> resolveArtifactAndDependencies(final List<RemoteRepository> repos, final File localRepo, final String scope, final String groupId, final String artifactId, final String classifier, final String extension, final String versionExpr) throws DependencyResolutionException {
    RepositorySystem repositorySystem = getRepositorySystem();
    RepositorySystemSession session = getRepositorySystemSession(repositorySystem, localRepo);
    return resolveArtifactAndDependencies(scope, groupId, artifactId, classifier, extension, versionExpr, repos, repositorySystem, session);
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession)

Example 7 with RepositorySystem

use of org.eclipse.aether.RepositorySystem in project liferay-ide by liferay.

the class LiferayMavenProjectProvider method getData.

@Override
public <T> List<T> getData(String key, Class<T> type, Object... params) {
    List<T> retval = null;
    if ("profileIds".equals(key)) {
        List<T> profileIds = new ArrayList<>();
        try {
            IMaven maven = MavenPlugin.getMaven();
            List<Profile> profiles = maven.getSettings().getProfiles();
            for (Profile profile : profiles) {
                if (profile.getActivation() != null) {
                    if (profile.getActivation().isActiveByDefault()) {
                        continue;
                    }
                }
                profileIds.add(type.cast(profile.getId()));
            }
            if ((params[0] != null) && params[0] instanceof File) {
                File locationDir = (File) params[0];
                File pomFile = new File(locationDir, IMavenConstants.POM_FILE_NAME);
                if (FileUtil.notExists(pomFile) && FileUtil.exists(locationDir.getParentFile())) {
                    // try one level up for when user is adding new module
                    pomFile = new File(locationDir.getParentFile(), IMavenConstants.POM_FILE_NAME);
                }
                if (FileUtil.exists(pomFile)) {
                    Model model = maven.readModel(pomFile);
                    File parentDir = pomFile.getParentFile();
                    while (model != null) {
                        for (org.apache.maven.model.Profile p : model.getProfiles()) {
                            profileIds.add(type.cast(p.getId()));
                        }
                        parentDir = parentDir.getParentFile();
                        if (FileUtil.exists(parentDir)) {
                            try {
                                model = maven.readModel(new File(parentDir, IMavenConstants.POM_FILE_NAME));
                            } catch (Exception e) {
                                model = null;
                            }
                        }
                    }
                }
            }
        } catch (CoreException ce) {
            LiferayMavenCore.logError(ce);
        }
        retval = profileIds;
    } else if ("liferayVersions".equals(key)) {
        List<T> possibleVersions = new ArrayList<>();
        RepositorySystem system = AetherUtil.newRepositorySystem();
        RepositorySystemSession session = AetherUtil.newRepositorySystemSession(system);
        String groupId = params[0].toString();
        String artifactId = params[1].toString();
        String coords = groupId + ":" + artifactId + ":[6,)";
        Artifact artifact = new DefaultArtifact(coords);
        VersionRangeRequest rangeRequest = new VersionRangeRequest();
        rangeRequest.setArtifact(artifact);
        rangeRequest.addRepository(AetherUtil.newCentralRepository());
        rangeRequest.addRepository(AetherUtil.newLiferayRepository());
        try {
            VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
            List<Version> versions = rangeResult.getVersions();
            for (Version version : versions) {
                String val = version.toString();
                if (!"6.2.0".equals(val) && !val.contains("7.0.0")) {
                    possibleVersions.add(type.cast(val));
                }
            }
            retval = possibleVersions;
        } catch (VersionRangeResolutionException vrre) {
        }
    } else if ("parentVersion".equals(key)) {
        List<T> version = new ArrayList<>();
        File locationDir = (File) params[0];
        File parentPom = new File(locationDir, IMavenConstants.POM_FILE_NAME);
        if (FileUtil.exists(parentPom)) {
            try {
                IMaven maven = MavenPlugin.getMaven();
                Model model = maven.readModel(parentPom);
                version.add(type.cast(model.getVersion()));
                retval = version;
            } catch (CoreException ce) {
                LiferayMavenCore.logError("unable to get parent version", ce);
            }
        }
    } else if ("parentGroupId".equals(key)) {
        List<T> groupId = new ArrayList<>();
        File locationDir = (File) params[0];
        File parentPom = new File(locationDir, IMavenConstants.POM_FILE_NAME);
        if (FileUtil.exists(parentPom)) {
            try {
                IMaven maven = MavenPlugin.getMaven();
                Model model = maven.readModel(parentPom);
                groupId.add(type.cast(model.getGroupId()));
                retval = groupId;
            } catch (CoreException ce) {
                LiferayMavenCore.logError("unable to get parent groupId", ce);
            }
        }
    } else if ("archetypeGAV".equals(key)) {
        String frameworkType = (String) params[0];
        String value = LiferayMavenCore.getPreferenceString("archetype-gav-" + frameworkType, "");
        retval = Collections.singletonList(type.cast(value));
    }
    return retval;
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) ArrayList(java.util.ArrayList) NewLiferayProfile(com.liferay.ide.project.core.model.NewLiferayProfile) Profile(org.apache.maven.settings.Profile) CoreException(org.eclipse.core.runtime.CoreException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) RepositorySystem(org.eclipse.aether.RepositorySystem) CoreException(org.eclipse.core.runtime.CoreException) Version(org.eclipse.aether.version.Version) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) Model(org.apache.maven.model.Model) ArrayList(java.util.ArrayList) List(java.util.List) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IMaven(org.eclipse.m2e.core.embedder.IMaven) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 8 with RepositorySystem

use of org.eclipse.aether.RepositorySystem in project ceylon by eclipse.

the class Bug2414 method bug.

public static void bug(Artifact jarArtifact) {
    // locator.getService(RepositorySystem.class);
    final RepositorySystem system = null;
    // MavenRepositorySystemUtils.newSession();
    final DefaultRepositorySystemSession session = null;
    ModuleCopycat copycat = new ModuleCopycat(rmb.buildManager(), new RepositoryManager() {

        @Override
        public void putArtifact(ArtifactContext artifactContext, File file) throws RepositoryException {
            try {
                InstallRequest installRequest = new InstallRequest();
                installRequest.addArtifact(jarArtifact);
                InstallResult result = system.install(session, installRequest);
            } catch (InstallationException e) {
                throw new RepositoryException(e);
            }
        }
    });
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) InstallRequest(org.eclipse.aether.installation.InstallRequest) InstallationException(org.eclipse.aether.installation.InstallationException) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) ModuleCopycat(org.eclipse.ceylon.cmr.ceylon.ModuleCopycat) InstallResult(org.eclipse.aether.installation.InstallResult)

Example 9 with RepositorySystem

use of org.eclipse.aether.RepositorySystem in project launcher by runelite.

the class ArtifactResolver method resolveArtifacts.

public List<ArtifactResult> resolveArtifacts(Artifact artifact) throws DependencyResolutionException {
    RepositorySystem system = newRepositorySystem();
    RepositorySystemSession session = newRepositorySystemSession(system);
    DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE, JavaScopes.RUNTIME);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
    collectRequest.setRepositories(repositories);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
    List<ArtifactResult> results = system.resolveDependencies(session, dependencyRequest).getArtifactResults();
    // check to see if they're from the right repository
    validate(results);
    return results;
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 10 with RepositorySystem

use of org.eclipse.aether.RepositorySystem in project mule by mulesoft.

the class RepositoryServiceFactory method createRepositoryService.

public RepositoryService createRepositoryService() {
    RepositorySystem repositorySystem = new SpiRepositorySystemFactory().createRepositorySystem();
    File repositoryFolder = createRepositoryFolderIfDoesNotExists();
    List<RemoteRepository> remoteRepositories = collectRemoteRepositories();
    DefaultRepositorySystemSession repositorySystemSession = new DefaultRepositorySystemSession();
    repositorySystemSession.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(repositorySystemSession, new LocalRepository(repositoryFolder)));
    return new DefaultRepositoryService(repositorySystem, repositorySystemSession, remoteRepositories);
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) LocalRepository(org.eclipse.aether.repository.LocalRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) File(java.io.File)

Aggregations

RepositorySystem (org.eclipse.aether.RepositorySystem)27 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)18 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)12 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)9 Artifact (org.eclipse.aether.artifact.Artifact)8 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)8 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 DefaultServiceLocator (org.eclipse.aether.impl.DefaultServiceLocator)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 LocalRepository (org.eclipse.aether.repository.LocalRepository)5 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)4 IOException (java.io.IOException)3 CollectRequest (org.eclipse.aether.collection.CollectRequest)3 Dependency (org.eclipse.aether.graph.Dependency)3 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)3 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)3 URL (java.net.URL)2 Path (java.nio.file.Path)2 List (java.util.List)2