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());
}
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);
}
}
}
}
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);
}
});
}
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);
}
}
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;
}
Aggregations