Search in sources :

Example 1 with MavenRemoteRepository

use of org.jetbrains.idea.maven.model.MavenRemoteRepository in project intellij-community by JetBrains.

the class MavenProjectTest method testCollectingRepositoriesFromParent.

public void testCollectingRepositoriesFromParent() throws Exception {
    VirtualFile m1 = createModulePom("p1", "<groupId>test</groupId>" + "<artifactId>p1</artifactId>" + "<version>1</version>" + "<packaging>pom</packaging>" + "<repositories>" + "  <repository>" + "    <id>one</id>" + "    <url>http://repository.one.com</url>" + "  </repository>" + "  <repository>" + "    <id>two</id>" + "    <url>http://repository.two.com</url>" + "  </repository>" + "</repositories>");
    VirtualFile m2 = createModulePom("p2", "<groupId>test</groupId>" + "<artifactId>p2</artifactId>" + "<version>1</version>" + "<parent>" + "  <groupId>test</groupId>" + "  <artifactId>p1</artifactId>" + "  <version>1</version>" + "</parent>");
    importProjects(m1, m2);
    List<MavenRemoteRepository> result = myProjectsTree.getRootProjects().get(0).getRemoteRepositories();
    assertEquals(3, result.size());
    assertEquals("one", result.get(0).getId());
    assertEquals("two", result.get(1).getId());
    assertEquals("central", result.get(2).getId());
    result = myProjectsTree.getRootProjects().get(1).getRemoteRepositories();
    assertEquals(3, result.size());
    assertEquals("one", result.get(0).getId());
    assertEquals("two", result.get(1).getId());
    assertEquals("central", result.get(2).getId());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository)

Example 2 with MavenRemoteRepository

use of org.jetbrains.idea.maven.model.MavenRemoteRepository in project intellij-community by JetBrains.

the class AppEngineFacetImporter method resolve.

@Override
public void resolve(Project project, MavenProject mavenProject, NativeMavenProjectHolder nativeMavenProject, MavenEmbedderWrapper embedder, ResolveContext context) throws MavenProcessCanceledException {
    String version = getVersion(mavenProject);
    if (version != null) {
        List<MavenRemoteRepository> repos = mavenProject.getRemoteRepositories();
        MavenArtifactInfo artifactInfo = new MavenArtifactInfo("com.google.appengine", "appengine-java-sdk", version, "zip", null);
        MavenArtifact artifact = embedder.resolve(artifactInfo, repos);
        File file = artifact.getFile();
        File unpackedSdkPath = new File(file.getParentFile(), "appengine-java-sdk");
        if (file.exists() && !AppEngineSdkUtil.checkPath(FileUtil.toSystemIndependentName(unpackedSdkPath.getAbsolutePath())).isOk()) {
            try {
                ZipUtil.extract(file, unpackedSdkPath, null, false);
            } catch (IOException e) {
                MavenLog.LOG.warn("cannot unpack AppEngine SDK", e);
            }
        }
    }
}
Also used : MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) IOException(java.io.IOException) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact) File(java.io.File)

Example 3 with MavenRemoteRepository

use of org.jetbrains.idea.maven.model.MavenRemoteRepository in project intellij-community by JetBrains.

the class ImportMavenRepositoriesTask method performTask.

private void performTask() {
    if (myProject.isDisposed())
        return;
    if (ApplicationManager.getApplication().isUnitTestMode())
        return;
    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
    final List<PsiFile> psiFileList = ContainerUtil.newArrayList();
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    for (Module module : moduleManager.getModules()) {
        if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
            continue;
        final String modulePath = ExternalSystemApiUtil.getExternalProjectPath(module);
        if (modulePath == null)
            continue;
        String buildScript = FileUtil.findFileInProvidedPath(modulePath, GradleConstants.DEFAULT_SCRIPT_NAME);
        if (StringUtil.isEmpty(buildScript))
            continue;
        VirtualFile virtualFile = localFileSystem.refreshAndFindFileByPath(buildScript);
        if (virtualFile == null)
            continue;
        final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
        if (psiFile == null)
            continue;
        psiFileList.add(psiFile);
    }
    final PsiFile[] psiFiles = ArrayUtil.toObjectArray(psiFileList, PsiFile.class);
    final Set<MavenRemoteRepository> mavenRemoteRepositories = new ReadAction<Set<MavenRemoteRepository>>() {

        @Override
        protected void run(@NotNull Result<Set<MavenRemoteRepository>> result) throws Throwable {
            Set<MavenRemoteRepository> myRemoteRepositories = ContainerUtil.newHashSet();
            for (PsiFile psiFile : psiFiles) {
                List<GrClosableBlock> repositoriesBlocks = ContainerUtil.newArrayList();
                repositoriesBlocks.addAll(findClosableBlocks(psiFile, "repositories"));
                for (GrClosableBlock closableBlock : findClosableBlocks(psiFile, "buildscript", "subprojects", "allprojects", "project", "configure")) {
                    repositoriesBlocks.addAll(findClosableBlocks(closableBlock, "repositories"));
                }
                for (GrClosableBlock repositoriesBlock : repositoriesBlocks) {
                    myRemoteRepositories.addAll(findMavenRemoteRepositories(repositoriesBlock));
                }
            }
            result.setResult(myRemoteRepositories);
        }
    }.execute().getResultObject();
    if (mavenRemoteRepositories == null || mavenRemoteRepositories.isEmpty())
        return;
    // register imported maven repository URLs but do not force to download the index
    // the index can be downloaded and/or updated later using Maven Configuration UI (Settings -> Build, Execution, Deployment -> Build tools -> Maven -> Repositories)
    MavenRepositoriesHolder.getInstance(myProject).update(mavenRemoteRepositories);
    MavenProjectIndicesManager.getInstance(myProject).scheduleUpdateIndicesList(indexes -> {
        if (myProject.isDisposed())
            return;
        final List<String> repositoriesWithEmptyIndex = ContainerUtil.mapNotNull(indexes, index -> index.getUpdateTimestamp() == -1 && MavenRepositoriesHolder.getInstance(myProject).contains(index.getRepositoryPathOrUrl()) ? index.getRepositoryPathOrUrl() : null);
        if (!repositoriesWithEmptyIndex.isEmpty()) {
            final NotificationData notificationData = new NotificationData(GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.title"), "\n<br>" + GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.text", StringUtil.join(repositoriesWithEmptyIndex, "<br>")), NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC);
            notificationData.setBalloonNotification(true);
            notificationData.setBalloonGroup(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP);
            notificationData.setListener("#open", new NotificationListener.Adapter() {

                @Override
                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                    ShowSettingsUtil.getInstance().showSettingsDialog(myProject, MavenRepositoriesConfigurable.class);
                }
            });
            notificationData.setListener("#disable", new NotificationListener.Adapter() {

                @Override
                protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                    final int result = Messages.showYesNoDialog(myProject, "Notification will be disabled for all projects.\n\n" + "Settings | Appearance & Behavior | Notifications | " + UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP + "\ncan be used to configure the notification.", "Unindexed Maven Repositories Gradle Detection", "Disable Notification", CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
                    if (result == Messages.YES) {
                        NotificationsConfigurationImpl.getInstanceImpl().changeSettings(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP, NotificationDisplayType.NONE, false, false);
                        notification.hideBalloon();
                    }
                }
            });
            ExternalSystemNotificationManager.getInstance(myProject).showNotification(GradleConstants.SYSTEM_ID, notificationData);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HyperlinkEvent(javax.swing.event.HyperlinkEvent) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) ModuleManager(com.intellij.openapi.module.ModuleManager) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) Result(com.intellij.openapi.application.Result) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) ReadAction(com.intellij.openapi.application.ReadAction) MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) MavenRepositoriesConfigurable(org.jetbrains.idea.maven.indices.MavenRepositoriesConfigurable) Module(com.intellij.openapi.module.Module) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData) NotificationListener(com.intellij.notification.NotificationListener)

Example 4 with MavenRemoteRepository

use of org.jetbrains.idea.maven.model.MavenRemoteRepository in project intellij-community by JetBrains.

the class MavenVersionsRemoteManager method execute.

@NotNull
@Override
public List<String> execute(@NotNull RepositoryLibraryDescription repositoryLibraryDescription, ProgressIndicator indicator) {
    MavenEmbeddersManager manager = MavenProjectsManager.getInstance(myProject).getEmbeddersManager();
    MavenEmbedderWrapper embedder = manager.getEmbedder(MavenEmbeddersManager.FOR_GET_VERSIONS, null, null);
    embedder.customizeForGetVersions();
    try {
        List<MavenRemoteRepository> remoteRepositories = convertRepositories(repositoryLibraryDescription.getRemoteRepositories());
        List<String> versions = embedder.retrieveVersions(repositoryLibraryDescription.getGroupId(), repositoryLibraryDescription.getArtifactId(), remoteRepositories);
        Collections.sort(versions, (o1, o2) -> {
            MavenVersionComparable v1 = new MavenVersionComparable(o1);
            MavenVersionComparable v2 = new MavenVersionComparable(o2);
            return v2.compareTo(v1);
        });
        return versions;
    } catch (MavenProcessCanceledException e) {
        return Collections.emptyList();
    } finally {
        manager.release(embedder);
    }
}
Also used : MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) MavenVersionComparable(org.jetbrains.idea.maven.dom.MavenVersionComparable) MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) MavenEmbeddersManager(org.jetbrains.idea.maven.project.MavenEmbeddersManager) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with MavenRemoteRepository

use of org.jetbrains.idea.maven.model.MavenRemoteRepository in project intellij-community by JetBrains.

the class MavenProjectIndicesManager method collectRemoteRepositoriesIdsAndUrls.

private Set<Pair<String, String>> collectRemoteRepositoriesIdsAndUrls() {
    Set<Pair<String, String>> result = new THashSet<>();
    Set<MavenRemoteRepository> remoteRepositories = ContainerUtil.newHashSet(getMavenProjectManager().getRemoteRepositories());
    for (MavenRepositoryProvider repositoryProvider : MavenRepositoryProvider.EP_NAME.getExtensions()) {
        ContainerUtil.addAll(remoteRepositories, repositoryProvider.getRemoteRepositories(myProject));
    }
    for (MavenRemoteRepository each : remoteRepositories) {
        String id = each.getId();
        String url = each.getUrl();
        result.add(Pair.create(id, url));
    }
    return result;
}
Also used : MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) THashSet(gnu.trove.THashSet) Pair(com.intellij.openapi.util.Pair)

Aggregations

MavenRemoteRepository (org.jetbrains.idea.maven.model.MavenRemoteRepository)6 NotNull (org.jetbrains.annotations.NotNull)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 ReadAction (com.intellij.openapi.application.ReadAction)1 Result (com.intellij.openapi.application.Result)1 NotificationData (com.intellij.openapi.externalSystem.service.notification.NotificationData)1 Module (com.intellij.openapi.module.Module)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 Pair (com.intellij.openapi.util.Pair)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 THashSet (gnu.trove.THashSet)1 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 HyperlinkEvent (javax.swing.event.HyperlinkEvent)1 MavenVersionComparable (org.jetbrains.idea.maven.dom.MavenVersionComparable)1 MavenRepositoriesConfigurable (org.jetbrains.idea.maven.indices.MavenRepositoriesConfigurable)1 MavenArtifact (org.jetbrains.idea.maven.model.MavenArtifact)1