Search in sources :

Example 6 with MavenRemoteRepository

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

the class ImportMavenRepositoriesTask method findMavenRemoteRepositories.

@NotNull
private Collection<? extends MavenRemoteRepository> findMavenRemoteRepositories(@Nullable GrClosableBlock repositoriesBlock) {
    Set<MavenRemoteRepository> myRemoteRepositories = ContainerUtil.newHashSet();
    for (GrMethodCall repo : PsiTreeUtil.getChildrenOfTypeAsList(repositoriesBlock, GrMethodCall.class)) {
        final String expressionText = repo.getInvokedExpression().getText();
        if ("mavenCentral".equals(expressionText)) {
            myRemoteRepositories.add(mavenCentralRemoteRepository);
        } else if ("mavenRepo".equals(expressionText)) {
            for (GrNamedArgument namedArgument : repo.getNamedArguments()) {
                if ("url".equals(namedArgument.getLabelName())) {
                    URI urlArgumentValue = resolveUriFromSimpleExpression(namedArgument.getExpression());
                    if (urlArgumentValue != null) {
                        String textUri = urlArgumentValue.toString();
                        myRemoteRepositories.add(new MavenRemoteRepository(textUri, null, textUri, null, null, null));
                    }
                    break;
                }
            }
        } else if ("maven".equals(expressionText) && repo.getClosureArguments().length > 0) {
            List<GrApplicationStatement> applicationStatementList = PsiTreeUtil.getChildrenOfTypeAsList(repo.getClosureArguments()[0], GrApplicationStatement.class);
            if (!applicationStatementList.isEmpty()) {
                GrApplicationStatement statement = applicationStatementList.get(0);
                if (statement == null)
                    continue;
                GrExpression expression = statement.getInvokedExpression();
                if ("url".equals(expression.getText())) {
                    URI urlArgumentValue = resolveUriFromSimpleExpression(statement.getExpressionArguments()[0]);
                    if (urlArgumentValue != null) {
                        String textUri = urlArgumentValue.toString();
                        myRemoteRepositories.add(new MavenRemoteRepository(textUri, null, textUri, null, null, null));
                    }
                }
            }
            List<GrAssignmentExpression> assignmentExpressionList = PsiTreeUtil.getChildrenOfTypeAsList(repo.getClosureArguments()[0], GrAssignmentExpression.class);
            if (!assignmentExpressionList.isEmpty()) {
                GrAssignmentExpression statement = assignmentExpressionList.get(0);
                if (statement == null)
                    continue;
                GrExpression expression = statement.getLValue();
                if ("url".equals(expression.getText())) {
                    URI urlArgumentValue = resolveUriFromSimpleExpression(statement.getRValue());
                    if (urlArgumentValue != null) {
                        String textUri = urlArgumentValue.toString();
                        myRemoteRepositories.add(new MavenRemoteRepository(textUri, null, textUri, null, null, null));
                    }
                }
            }
        }
    }
    return myRemoteRepositories;
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) URI(java.net.URI) GrApplicationStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement) NotNull(org.jetbrains.annotations.NotNull)

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