Skip to content

Commit

Permalink
增加设置界面
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Wu committed Aug 16, 2017
1 parent da2f85f commit a41d89f
Show file tree
Hide file tree
Showing 22 changed files with 344 additions and 41 deletions.
Empty file modified LICENSE 100644 → 100755
Empty file.
Empty file modified README.md 100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion build.gradle.kts 100644 → 100755
Expand Up @@ -11,7 +11,7 @@ intellij {
pluginName = "Gradle Dependencies And Plugins Helper"
updateSinceUntilBuild = false
version = "IC-2017.2.1"
// version = "145.184.1"
// version = "145.258.11"
setPlugins("Groovy", "gradle", "Kotlin", "maven")
}

Expand Down
Empty file modified gradle/wrapper/gradle-wrapper.jar 100644 → 100755
Empty file.
Empty file modified gradle/wrapper/gradle-wrapper.properties 100644 → 100755
Empty file.
Empty file modified gradlew.bat 100644 → 100755
Empty file.
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="cn.bestwu.intellij.plugins.gradle.codeInsight.completion.config.ConfigurationView">
<grid id="27dc6" binding="dpPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="805" height="463"/>
</constraints>
<properties/>
<border type="none" title="Gradle Dependencies And Plugins Helper configuration">
<font style="1"/>
</border>
<children>
<vspacer id="a3320">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="9e381" binding="nexusPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="Nexus Search"/>
<children>
<component id="49c07" class="javax.swing.JCheckBox" binding="useNexus">
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Us&amp;e Nexus for search"/>
</properties>
</component>
<component id="6f8e9" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font style="1"/>
<labelFor value="8a9de"/>
<text value="nexus search url:"/>
</properties>
</component>
<component id="8a9de" class="javax.swing.JTextField" binding="nexusSearchUrlField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="http://maven.aliyun.com/nexus/service/local/lucene/search"/>
</properties>
</component>
</children>
</grid>
<grid id="ce259" binding="mavenIndexPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="MavenIndex Search"/>
<children>
<component id="3672" class="javax.swing.JCheckBox" binding="useMavenIndex">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Us&amp;e MavenIndex for search"/>
</properties>
</component>
</children>
</grid>
<component id="25b52" class="javax.swing.JButton" binding="resetButton">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&amp;Reset to default values"/>
</properties>
</component>
</children>
</grid>
</form>
@@ -0,0 +1,83 @@
package cn.bestwu.intellij.plugins.gradle.codeInsight.completion.config;

import java.util.HashSet;
import java.util.Set;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.jetbrains.idea.maven.model.MavenRemoteRepository;


public class ConfigurationView {

private JPanel nexusPanel;
private JButton resetButton;
private JCheckBox useNexus;
private JTextField nexusSearchUrlField;
private JPanel dpPanel;
private JPanel mavenIndexPanel;
private JCheckBox useMavenIndex;
// private JButton addRemoteRepo;
private Set<MavenRemoteRepository> remoteRepositories = new HashSet<>();

public ConfigurationView() {
useNexus.addActionListener(
actionEvent -> nexusSearchUrlField.setEnabled(useNexus.isSelected()));
// useMavenIndex.addActionListener(
// actionEvent -> addRemoteRepo.setEnabled(useMavenIndex.isSelected()));
// addRemoteRepo.addActionListener(e -> {
// final RemoteRepositoryEditor repositoryEditor = new RemoteRepositoryEditor(
// "Add Maven Remote Repository", "", "", new EditValidator());
// if (repositoryEditor.showAndGet()) {
// remoteRepositories.add(new MavenRemoteRepository(repositoryEditor.getName(), null,
// repositoryEditor.getValue(), null, null, null));
// }
// });
}

public JPanel getDpPanel() {
return dpPanel;
}


public String getNexusSearchUrlField() {
return nexusSearchUrlField.getText();
}

public void setNexusSearchUrlField(String nexusSearchUrlField) {
this.nexusSearchUrlField.setText(nexusSearchUrlField);
}

public boolean getUseNexus() {
return useNexus.isSelected();
}

public void setUseNexus(boolean selected) {
useNexus.setSelected(selected);
nexusSearchUrlField.setEnabled(selected);
}


public Set<MavenRemoteRepository> getRemoteRepositories() {
return remoteRepositories;
}

public void setRemoteRepositories(
Set<MavenRemoteRepository> remoteRepositories) {
this.remoteRepositories = remoteRepositories;
}

public boolean getUseMavenIndex() {
return useMavenIndex.isSelected();
}

public void setUseMavenIndex(boolean selected) {
useMavenIndex.setSelected(selected);
// addRemoteRepo.setEnabled(selected);
}

public JButton getResetButton() {
return resetButton;
}
}
22 changes: 14 additions & 8 deletions ...kotlin/cn/bestwu/intellij/plugins/gradle/codeInsight/completion/GradleArtifactSearcher.kt 100644 → 100755
@@ -1,5 +1,6 @@
package cn.bestwu.intellij.plugins.gradle.codeInsight.completion

import cn.bestwu.intellij.plugins.gradle.codeInsight.completion.config.Settings
import com.intellij.notification.NotificationType
import com.intellij.openapi.project.Project
import groovy.json.JsonSlurper
Expand Down Expand Up @@ -183,14 +184,19 @@ class GradleArtifactSearcher {
}
var result: MutableList<ArtifactInfo>
if (searchParam.advancedSearch.isNotEmpty()) {
result = searchByClassNameInNexus(searchParam, project)
if (result.isEmpty())
if (Settings.getInstance(project).useNexus) {
result = searchByClassNameInNexus(searchParam, project)
if (result.isEmpty())
result = searchByClassNameInMavenCentral(searchParam, project)
} else {
result = searchByClassNameInMavenCentral(searchParam, project)
}
} else {

result = searchInMavenIndexs(searchParam, project)
// result = searchInNexus(searchParam, project)
// result = searchInJcenter(searchParam, project)
// result = searchInMavenIndexs(searchParam, project)
if (Settings.getInstance(project).useNexus)
result = searchInNexus(searchParam, project)
else
result = searchInJcenter(searchParam, project)
}
artifactsCaches.put(searchParam.q, result)
return result
Expand Down Expand Up @@ -221,7 +227,7 @@ class GradleArtifactSearcher {
@Suppress("UNCHECKED_CAST")
private fun searchByClassNameInNexus(searchParam: SearchParam, project: Project): MutableList<ArtifactInfo> {
val result: MutableList<ArtifactInfo> = mutableListOf()
val url = "http://maven.aliyun.com/nexus/service/local/lucene/search?repositoryId=central&cn=${searchParam.id}"
val url = "${Settings.getInstance(project).nexusSearchUrl}?repositoryId=central&cn=${searchParam.id}"
val connection = getConnection(url)
connection.setRequestProperty("Accept", "application/json")
val stream = getResponse(connection, project) ?: return result
Expand All @@ -236,7 +242,7 @@ class GradleArtifactSearcher {
return result
}

private fun searchInMavenIndexs(searchParam: SearchParam, project: Project): MutableList<ArtifactInfo> {
private fun searchInMavenIndexes(searchParam: SearchParam, project: Project): MutableList<ArtifactInfo> {
val result: MutableList<ArtifactInfo> = mutableListOf()
MavenRepositoriesHolder.getInstance(project).checkNotIndexedRepositories()
val m = MavenProjectIndicesManager.getInstance(project)
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
60 changes: 30 additions & 30 deletions src/main/kotlin/cn/bestwu/intellij/plugins/gradle/codeInsight/completion/GradleProject.kt 100644 → 100755
@@ -1,5 +1,6 @@
package cn.bestwu.intellij.plugins.gradle.codeInsight.completion

import cn.bestwu.intellij.plugins.gradle.codeInsight.completion.config.Settings
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter
Expand Down Expand Up @@ -27,49 +28,47 @@ import java.util.stream.Collectors


class ImportMavenRepositoriesTask(project: Project) : ReadTask() {
private val mavenCentralRemoteRepository: MavenRemoteRepository
private var myProject: Project = project
private var myDumbService: DumbService


companion object {
fun performTask(project: Project, remoteRepositories: MutableSet<MavenRemoteRepository>) {
if (project.isDisposed) return
if (ApplicationManager.getApplication().isUnitTestMode) return

val repositoriesHolder = MavenRepositoriesHolder.getInstance(project)
// remoteRepositories.addAll(repositoriesHolder.remoteRepositories)
repositoriesHolder.update(remoteRepositories)
MavenProjectIndicesManager.getInstance(project).scheduleUpdateIndicesList(Consumer<List<MavenIndex>> { indexes ->
if (project.isDisposed) return@Consumer

val repositoriesWithEmptyIndex = indexes.stream()
.filter({ index ->
index.updateTimestamp == -1L &&
index.failureMessage == null &&
repositoriesHolder.contains(index.repositoryPathOrUrl)
})
.map(MavenIndex::getRepositoryPathOrUrl)
.collect(Collectors.toList<String>())
repositoriesHolder.updateNotIndexedUrls(repositoriesWithEmptyIndex)
})
}
}

init {
myDumbService = DumbService.getInstance(myProject)
mavenCentralRemoteRepository = MavenRemoteRepository("central", null, "https://repo1.maven.org/maven2/", null, null, null)
}

@Throws(ProcessCanceledException::class)
override fun runBackgroundProcess(indicator: ProgressIndicator): ReadTask.Continuation {
return myDumbService.runReadActionInSmartMode<ReadTask.Continuation> {
Continuation({
performTask()
performTask(myProject, Settings.getInstance(myProject).remoteRepositories.toMutableSet())
})
}
}

private fun performTask() {
if (myProject.isDisposed) return
if (ApplicationManager.getApplication().isUnitTestMode) return

// val remoteRepository = MavenRemoteRepository("my", null, "http://127.0.0.1:8081/remote-repos/", null, null, null)
val repositoriesHolder = MavenRepositoriesHolder.getInstance(myProject)
val remoteRepositories = mutableSetOf<MavenRemoteRepository>()
remoteRepositories.addAll(repositoriesHolder.remoteRepositories)
remoteRepositories.add(mavenCentralRemoteRepository)
repositoriesHolder.update(remoteRepositories)
MavenProjectIndicesManager.getInstance(myProject).scheduleUpdateIndicesList(Consumer<List<MavenIndex>> { indexes ->
if (myProject.isDisposed) return@Consumer

val repositoriesWithEmptyIndex = indexes.stream()
.filter({ index ->
index.updateTimestamp == -1L &&
index.failureMessage == null &&
repositoriesHolder.contains(index.repositoryPathOrUrl)
})
.map(MavenIndex::getRepositoryPathOrUrl)
.collect(Collectors.toList<String>())
repositoriesHolder.updateNotIndexedUrls(repositoriesWithEmptyIndex)
})
}

override fun onCanceled(indicator: ProgressIndicator) {
if (!myProject.isDisposed) {
ProgressIndicatorUtils.scheduleWithWriteActionPriority(this)
Expand All @@ -81,7 +80,7 @@ class ImportMavenRepositoriesTask(project: Project) : ReadTask() {
class GradleProjectStartupActivity : StartupActivity {

override fun runActivity(project: Project) {
if (ApplicationManager.getApplication().isUnitTestMode) return
if (ApplicationManager.getApplication().isUnitTestMode || !Settings.getInstance(project).useMavenIndex) return
ProgressIndicatorUtils.scheduleWithWriteActionPriority(ImportMavenRepositoriesTask(project))
}
}
Expand All @@ -91,7 +90,8 @@ class GradleMavenProjectImportNotificationListener : ExternalSystemTaskNotificat
override fun onSuccess(id: ExternalSystemTaskId) {
if (GradleConstants.SYSTEM_ID.id == id.projectSystemId.id && id.type == ExternalSystemTaskType.RESOLVE_PROJECT) {
val project = id.findProject() ?: return
ProgressIndicatorUtils.scheduleWithWriteActionPriority(ImportMavenRepositoriesTask(project))
if (Settings.getInstance(project).useMavenIndex)
ProgressIndicatorUtils.scheduleWithWriteActionPriority(ImportMavenRepositoriesTask(project))
}
}
}
Empty file.
Empty file.

0 comments on commit a41d89f

Please sign in to comment.