├── settings.gradle.kts ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src ├── main │ ├── resources │ │ ├── icons │ │ │ ├── icon.png │ │ │ └── icon@2x.png │ │ └── META-INF │ │ │ └── plugin.xml │ └── java │ │ └── com │ │ └── sourcegraph │ │ ├── action │ │ ├── Search.java │ │ ├── SearchRepository.java │ │ ├── Open.java │ │ ├── Copy.java │ │ ├── OpenRevisionAction.java │ │ ├── FileAction.java │ │ └── SearchActionBase.java │ │ ├── project │ │ ├── RepoInfo.java │ │ ├── RevisionContext.java │ │ ├── SourcegraphConfig.java │ │ └── CommitViewUriBuilder.java │ │ └── util │ │ └── SourcegraphUtil.java └── test │ └── java │ └── CommitViewUriBuilderTest.java ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── pr-auditor.yml │ ├── run-ui-tests.yml │ ├── release.yml │ └── build.yml ├── .gitignore ├── gradle.properties ├── CHANGELOG.md ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "Sourcegraph" 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcegraph/sourcegraph-jetbrains/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/icons/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcegraph/sourcegraph-jetbrains/HEAD/src/main/resources/icons/icon.png -------------------------------------------------------------------------------- /src/main/resources/icons/icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcegraph/sourcegraph-jetbrains/HEAD/src/main/resources/icons/icon@2x.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/java/com/sourcegraph/action/Search.java: -------------------------------------------------------------------------------- 1 | package com.sourcegraph.action; 2 | 3 | import com.intellij.openapi.actionSystem.AnActionEvent; 4 | 5 | public class Search extends SearchActionBase { 6 | @Override 7 | public void actionPerformed(AnActionEvent e) { 8 | super.actionPerformedMode(e, "search"); 9 | } 10 | } -------------------------------------------------------------------------------- /src/main/java/com/sourcegraph/action/SearchRepository.java: -------------------------------------------------------------------------------- 1 | package com.sourcegraph.action; 2 | 3 | import com.intellij.openapi.actionSystem.AnActionEvent; 4 | 5 | 6 | public class SearchRepository extends SearchActionBase { 7 | @Override 8 | public void actionPerformed(AnActionEvent e) { 9 | super.actionPerformedMode(e, "search.repository"); 10 | } 11 | } -------------------------------------------------------------------------------- /src/main/java/com/sourcegraph/project/RepoInfo.java: -------------------------------------------------------------------------------- 1 | package com.sourcegraph.project; 2 | 3 | public class RepoInfo { 4 | public String fileRel; 5 | public String remoteURL; 6 | public String branch; 7 | 8 | public RepoInfo(String sFileRel, String sRemoteURL, String sBranch) { 9 | fileRel = sFileRel; 10 | remoteURL = sRemoteURL; 11 | branch = sBranch; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Test plan 2 | 3 | 10 | -------------------------------------------------------------------------------- /src/main/java/com/sourcegraph/project/RevisionContext.java: -------------------------------------------------------------------------------- 1 | package com.sourcegraph.project; 2 | 3 | import com.intellij.openapi.project.Project; 4 | 5 | public class RevisionContext { 6 | private final Project project; 7 | private final String revisionNumber; 8 | 9 | public RevisionContext(Project project, String revisionNumber) { 10 | this.project = project; 11 | this.revisionNumber = revisionNumber; 12 | } 13 | 14 | public Project getProject() { 15 | return project; 16 | } 17 | 18 | public String getRevisionNumber() { 19 | return revisionNumber; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/sourcegraph/action/Open.java: -------------------------------------------------------------------------------- 1 | package com.sourcegraph.action; 2 | 3 | import com.intellij.openapi.diagnostic.Logger; 4 | 5 | import java.awt.*; 6 | import java.io.IOException; 7 | import java.net.URI; 8 | 9 | public class Open extends FileAction { 10 | 11 | @Override 12 | void handleFileUri(String uri) { 13 | Logger logger = Logger.getInstance(this.getClass()); 14 | // Open the URL in the browser. 15 | try { 16 | Desktop.getDesktop().browse(URI.create(uri)); 17 | } catch (IOException err) { 18 | logger.debug("failed to open browser"); 19 | err.printStackTrace(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.github/workflows/pr-auditor.yml: -------------------------------------------------------------------------------- 1 | # See https://docs.sourcegraph.com/dev/background-information/ci#pr-auditor 2 | name: pr-auditor 3 | on: 4 | pull_request_target: 5 | types: [ closed, edited, opened, synchronize, ready_for_review ] 6 | 7 | jobs: 8 | check-pr: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | with: 13 | repository: 'sourcegraph/pr-auditor' 14 | - uses: actions/setup-go@v4 15 | with: { go-version: '1.20' } 16 | 17 | - run: './check-pr.sh' 18 | env: 19 | GITHUB_EVENT_PATH: ${{ env.GITHUB_EVENT_PATH }} 20 | GITHUB_TOKEN: ${{ github.token }} 21 | GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 2 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 3 | 4 | *.jar 5 | !gradle-wrapper.jar 6 | 7 | # User local IDEA configuration files 8 | .idea/ 9 | 10 | #IntelliJ project 11 | *.iml 12 | 13 | # Build output & caches for IntelliJ plugin development 14 | build/ 15 | idea-sandbox/ 16 | .gradle/ 17 | 18 | ## File-based project format: 19 | *.iws 20 | 21 | # IntelliJ 22 | /out/ 23 | 24 | # mpeltonen/sbt-idea plugin 25 | .idea_modules/ 26 | 27 | # JIRA plugin 28 | atlassian-ide-plugin.xml 29 | 30 | # Crashlytics plugin (for Android Studio and IntelliJ) 31 | com_crashlytics_export_strings.xml 32 | crashlytics.properties 33 | crashlytics-build.properties 34 | fabric.properties 35 | -------------------------------------------------------------------------------- /src/main/java/com/sourcegraph/action/Copy.java: -------------------------------------------------------------------------------- 1 | package com.sourcegraph.action; 2 | 3 | import com.intellij.notification.Notification; 4 | import com.intellij.notification.NotificationType; 5 | import com.intellij.notification.Notifications; 6 | import com.intellij.openapi.ide.CopyPasteManager; 7 | 8 | import java.awt.datatransfer.StringSelection; 9 | 10 | public class Copy extends FileAction { 11 | 12 | @Override 13 | void handleFileUri(String uri) { 14 | // Remove utm tags for sharing 15 | String shortenURI = uri.replaceAll("(&utm_product_name=)(.*)", ""); 16 | // Copy file uri to clipboard 17 | CopyPasteManager.getInstance().setContents(new StringSelection(shortenURI)); 18 | 19 | // Display bubble 20 | Notification notification = new Notification("Sourcegraph", "Sourcegraph", 21 | "File URL copied to clipboard."+shortenURI, NotificationType.INFORMATION); 22 | // Editor.getProject 23 | // NotificationGroupManager.getInstance().getNotificationGroup("Sourcegraph") 24 | // .createNotification("File URL copied to clipboard."+shortenURI, NotificationType.INFORMATION) 25 | // .notify(this.); 26 | Notifications.Bus.notify(notification); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # IntelliJ Platform Artifacts Repositories 2 | # -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html 3 | 4 | pluginGroup = com.sourcegraph.jetbrains 5 | pluginName = Sourcegraph 6 | # SemVer format -> https://semver.org 7 | pluginVersion = 1.2.4 8 | 9 | # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html 10 | # for insight into build numbers and IntelliJ Platform versions. 11 | pluginSinceBuild = 162.0 12 | 13 | # IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties 14 | platformType = IC 15 | platformVersion = 2022.1 16 | 17 | # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html 18 | # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 19 | platformPlugins = 20 | 21 | # Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3 22 | javaVersion = 11 23 | 24 | # Gradle Releases -> https://github.com/gradle/gradle/releases 25 | gradleVersion = 7.4.2 26 | 27 | # Opt-out flag for bundling Kotlin standard library. 28 | # See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details. 29 | # suppress inspection "UnusedProperty" 30 | kotlin.stdlib.default.dependency = false 31 | -------------------------------------------------------------------------------- /src/main/java/com/sourcegraph/project/SourcegraphConfig.java: -------------------------------------------------------------------------------- 1 | package com.sourcegraph.project; 2 | 3 | import com.intellij.openapi.components.PersistentStateComponent; 4 | import com.intellij.openapi.components.ServiceManager; 5 | import com.intellij.openapi.components.State; 6 | import com.intellij.openapi.components.Storage; 7 | import com.intellij.openapi.project.Project; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | @State( 12 | name = "Config", 13 | storages = {@Storage("sourcegraph.xml")}) 14 | public 15 | class SourcegraphConfig implements PersistentStateComponent { 16 | 17 | public String url; 18 | 19 | public String getUrl() { 20 | return url; 21 | } 22 | 23 | public String defaultBranch; 24 | 25 | public String getDefaultBranch() { 26 | return defaultBranch; 27 | } 28 | 29 | public String remoteUrlReplacements; 30 | 31 | public String getRemoteUrlReplacements() { 32 | return remoteUrlReplacements; 33 | } 34 | 35 | @Nullable 36 | @Override 37 | public SourcegraphConfig getState() { 38 | return this; 39 | } 40 | 41 | @Override 42 | public void loadState(@NotNull SourcegraphConfig config) { 43 | this.url = config.url; 44 | this.defaultBranch = config.defaultBranch; 45 | this.remoteUrlReplacements = config.remoteUrlReplacements; 46 | } 47 | 48 | @Nullable 49 | public static SourcegraphConfig getInstance(Project project) { 50 | return ServiceManager.getService(project, SourcegraphConfig.class); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /.github/workflows/run-ui-tests.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Workflow for launching UI tests on Linux, Windows, and Mac in the following steps: 2 | # - prepare and launch IDE with your plugin and robot-server plugin, which is needed to interact with UI 3 | # - wait for IDE to start 4 | # - run UI tests with separate Gradle task 5 | # 6 | # Please check https://github.com/JetBrains/intellij-ui-test-robot for information about UI tests with IntelliJ Platform 7 | # 8 | # Workflow is triggered manually. 9 | 10 | name: Run UI Tests 11 | on: 12 | workflow_dispatch: 13 | pull_request: 14 | 15 | jobs: 16 | 17 | testUI: 18 | runs-on: ${{ matrix.os }} 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | include: 23 | - os: ubuntu-latest 24 | runIde: | 25 | export DISPLAY=:99.0 26 | Xvfb -ac :99 -screen 0 1920x1080x16 & 27 | gradle runIdeForUiTests & 28 | - os: windows-latest 29 | runIde: start gradlew.bat runIdeForUiTests 30 | - os: macos-latest 31 | runIde: ./gradlew runIdeForUiTests & 32 | 33 | steps: 34 | 35 | # Check out current repository 36 | - name: Fetch Sources 37 | uses: actions/checkout@v3 38 | 39 | # Setup Java 11 environment for the next steps 40 | - name: Setup Java 41 | uses: actions/setup-java@v2 42 | with: 43 | distribution: zulu 44 | java-version: 11 45 | cache: gradle 46 | 47 | # Run IDEA prepared for UI testing 48 | - name: Run IDE 49 | run: ${{ matrix.runIde }} 50 | 51 | # Wait for IDEA to be started 52 | - name: Health Check 53 | uses: jtalk/url-health-check-action@v2 54 | with: 55 | url: http://127.0.0.1:8082 56 | max-attempts: 15 57 | retry-delay: 30s 58 | 59 | # Run tests 60 | - name: Tests 61 | run: ./gradlew test 62 | -------------------------------------------------------------------------------- /src/main/java/com/sourcegraph/project/CommitViewUriBuilder.java: -------------------------------------------------------------------------------- 1 | package com.sourcegraph.project; 2 | 3 | import com.google.common.base.Strings; 4 | import com.sourcegraph.project.RepoInfo; 5 | import com.sourcegraph.util.SourcegraphUtil; 6 | 7 | import java.io.UnsupportedEncodingException; 8 | import java.net.URI; 9 | import java.net.URLEncoder; 10 | import java.nio.charset.StandardCharsets; 11 | 12 | public class CommitViewUriBuilder { 13 | 14 | public URI build(String sourcegraphBase, String revisionNumber, RepoInfo repoInfo, String productName, String productVersion) { 15 | if (Strings.isNullOrEmpty(sourcegraphBase)) { 16 | throw new RuntimeException("Missing sourcegraph URI for commit uri."); 17 | } else if (Strings.isNullOrEmpty(revisionNumber)) { 18 | throw new RuntimeException("Missing revision number for commit uri."); 19 | } else if (repoInfo == null || Strings.isNullOrEmpty(repoInfo.remoteURL)) { 20 | throw new RuntimeException("Missing remote URL for commit uri."); 21 | } 22 | 23 | // this is pretty hacky but to try to build the repo string we will just try to naively parse the git remote uri. Worst case scenario this 404s 24 | String remoteURL = repoInfo.remoteURL; 25 | if(remoteURL.startsWith("git")){ 26 | remoteURL = repoInfo.remoteURL.replace(".git", "").replaceFirst(":", "/").replace("git@", "https://"); 27 | } 28 | URI remote = URI.create(remoteURL); 29 | String path = remote.getPath(); 30 | 31 | String url = sourcegraphBase + 32 | String.format("/%s%s", remote.getHost(), path) + 33 | String.format("/-/commit/%s", revisionNumber) + 34 | String.format("?editor=%s", URLEncoder.encode("JetBrains", StandardCharsets.UTF_8)) + 35 | String.format("&version=%s", URLEncoder.encode(SourcegraphUtil.VERSION, StandardCharsets.UTF_8)) + 36 | String.format("&utm_product_name=%s", URLEncoder.encode(productName, StandardCharsets.UTF_8)) + 37 | String.format("&utm_product_version=%s", URLEncoder.encode(productVersion, StandardCharsets.UTF_8)); 38 | 39 | return URI.create(url); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Sourcegraph Changelog 2 | 3 | ## [Unreleased] 4 | 5 | ## [1.2.4] 6 | 7 | - Fixed an issue that prevent the latest version of the plugin to work with JetBrains 2022.1 products. 8 | 9 | ## [1.2.3] 10 | 11 | - Upgrade JetBrains IntelliJ shell to 1.3.1 and modernize the build and release pipeline. 12 | 13 | ## [1.2.2] - Minor bug fixes 14 | 15 | - It is now possible to configure the plugin per-repository using a `.idea/sourcegraph.xml` file. See the README for details. 16 | - Special thanks: @oliviernotteghem for contributing the new features in this release! 17 | - Fixed bugs where Open in Sourcegraph from the git menu does not work for repos with ssh url as their remote url 18 | 19 | ## [1.2.1] - Open Revision in Sourcegraph 20 | 21 | - Added "Open In Sourcegraph" action to VCS History and Git Log to open a revision in the Sourcegraph diff view. 22 | - Added "defaultBranch" configuration option that allows opening files in a specific branch on Sourcegraph. 23 | - Added "remoteUrlReplacements" configuration option that allow users to replace specified values in the remote url with new strings. 24 | 25 | ## [1.2.0] - Copy link to file, search in repository, per-repository configuration, bug fixes & more 26 | 27 | - The search menu entry is now no longer present when no text has been selected. 28 | - When on a branch that does not exist remotely, `master` will now be used instead. 29 | - Menu entries (Open file, etc.) are now under a Sourcegraph sub-menu. 30 | - Added a "Copy link to file" action (alt+c / opt+c). 31 | - Added a "Search in repository" action (alt+r / opt+r). 32 | - It is now possible to configure the plugin per-repository using a `.idea/sourcegraph.xml` file. See the README for details. 33 | - Special thanks: @oliviernotteghem for contributing the new features in this release! 34 | 35 | ## [1.1.2] - Minor bug fixes around searching. 36 | 37 | - Fixed an error that occurred when trying to search with no selection. 38 | - The git remote used for repository detection is now `sourcegraph` and then `origin`, instead of the previously poor choice of just the first git remote. 39 | 40 | ## [1.1.1] - Fixed search shortcut 41 | 42 | - Updated the search URL to reflect a recent Sourcegraph.com change. 43 | 44 | ## [1.1.0] - Configurable Sourcegraph URL 45 | 46 | - Added support for using the plugin with on-premises Sourcegraph instances. 47 | 48 | ## [1.0.0] - Initial Release 49 | 50 | - Basic Open File & Search functionality. 51 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | com.sourcegraph.jetbrains 3 | Sourcegraph 4 | Sourcegraph 5 | 6 | 8 | com.intellij.modules.lang 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/test/java/CommitViewUriBuilderTest.java: -------------------------------------------------------------------------------- 1 | import static org.junit.jupiter.api.Assertions.assertEquals; 2 | import static org.junit.jupiter.api.Assertions.assertThrows; 3 | 4 | import java.net.URI; 5 | 6 | import com.sourcegraph.project.CommitViewUriBuilder; 7 | import com.sourcegraph.project.RepoInfo; 8 | import org.junit.jupiter.api.Test; 9 | import org.junit.jupiter.params.ParameterizedTest; 10 | import org.junit.jupiter.params.provider.EmptySource; 11 | import org.junit.jupiter.params.provider.NullSource; 12 | 13 | public class CommitViewUriBuilderTest { 14 | 15 | @Test 16 | public void testBuild_AllValid() { 17 | CommitViewUriBuilder builder = new CommitViewUriBuilder(); 18 | 19 | RepoInfo repoInfo = new RepoInfo("", "https://github.com/sourcegraph/sourcegraph-jetbrains.git", "main"); 20 | 21 | URI got = builder.build("https://www.sourcegraph.com", 22 | "1fa8d5d6286c24924b55c15ed4d1a0b85ccab4d5", 23 | repoInfo, 24 | "intellij", 25 | "1.1"); 26 | 27 | String want = "https://www.sourcegraph.com/github.com/sourcegraph/sourcegraph-jetbrains.git/-/commit/1fa8d5d6286c24924b55c15ed4d1a0b85ccab4d5?editor=JetBrains&version=v1.2.2&utm_product_name=intellij&utm_product_version=1.1"; 28 | assertEquals(want, got.toString()); 29 | } 30 | 31 | @ParameterizedTest 32 | @NullSource 33 | @EmptySource 34 | public void testBuild_MissingRevision(String revision) { 35 | CommitViewUriBuilder builder = new CommitViewUriBuilder(); 36 | RepoInfo repoInfo = new RepoInfo("", "https://github.com/sourcegraph/sourcegraph-jetbrains.git", "main"); 37 | 38 | assertThrows(RuntimeException.class, () -> builder.build("https://www.sourcegraph.com", 39 | revision, 40 | repoInfo, 41 | "intellij", 42 | "1.1")); 43 | } 44 | 45 | @ParameterizedTest 46 | @NullSource 47 | @EmptySource 48 | public void testBuild_MissingBaseUri(String baseUri) { 49 | CommitViewUriBuilder builder = new CommitViewUriBuilder(); 50 | RepoInfo repoInfo = new RepoInfo("", "https://github.com/sourcegraph/sourcegraph-jetbrains.git", "main"); 51 | 52 | assertThrows(RuntimeException.class, () -> builder.build(baseUri, 53 | "1fa8d5d6286c24924b55c15ed4d1a0b85ccab4d5", 54 | repoInfo, 55 | "intellij", 56 | "1.1")); 57 | } 58 | @Test 59 | public void testBuild_MissingRemoteUrl() { 60 | CommitViewUriBuilder builder = new CommitViewUriBuilder(); 61 | RepoInfo repoInfo = new RepoInfo("", "", "main"); 62 | 63 | assertThrows(RuntimeException.class, () -> builder.build("https://www.sourcegraph.com", 64 | "1fa8d5d6286c24924b55c15ed4d1a0b85ccab4d5", 65 | repoInfo, 66 | "intellij", 67 | "1.1")); 68 | 69 | assertThrows(RuntimeException.class, () -> builder.build("https://www.sourcegraph.com", 70 | "1fa8d5d6286c24924b55c15ed4d1a0b85ccab4d5", 71 | null, 72 | "intellij", 73 | "1.1")); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Workflow created for handling the release process based on the draft release prepared 2 | # with the Build workflow. Running the publishPlugin task requires the PUBLISH_TOKEN secret provided. 3 | 4 | name: Release 5 | on: 6 | release: 7 | types: [prereleased, released] 8 | 9 | jobs: 10 | 11 | # Prepare and publish the plugin to the Marketplace repository 12 | release: 13 | name: Publish Plugin 14 | runs-on: ubuntu-latest 15 | steps: 16 | 17 | # Check out current repository 18 | - name: Fetch Sources 19 | uses: actions/checkout@v3 20 | with: 21 | ref: ${{ github.event.release.tag_name }} 22 | 23 | # Setup Java 11 environment for the next steps 24 | - name: Setup Java 25 | uses: actions/setup-java@v2 26 | with: 27 | distribution: zulu 28 | java-version: 11 29 | cache: gradle 30 | 31 | # Set environment variables 32 | - name: Export Properties 33 | id: properties 34 | shell: bash 35 | run: | 36 | CHANGELOG="$(cat << 'EOM' | sed -e 's/^[[:space:]]*$//g' -e '/./,$!d' 37 | ${{ github.event.release.body }} 38 | EOM 39 | )" 40 | 41 | CHANGELOG="${CHANGELOG//'%'/'%25'}" 42 | CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" 43 | CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" 44 | 45 | echo "::set-output name=changelog::$CHANGELOG" 46 | 47 | # Update Unreleased section with the current release note 48 | - name: Patch Changelog 49 | if: ${{ steps.properties.outputs.changelog != '' }} 50 | env: 51 | CHANGELOG: ${{ steps.properties.outputs.changelog }} 52 | run: | 53 | ./gradlew patchChangelog --release-note="$CHANGELOG" 54 | 55 | # Publish the plugin to the Marketplace 56 | - name: Publish Plugin 57 | env: 58 | PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }} 59 | run: ./gradlew publishPlugin 60 | 61 | # Upload artifact as a release asset 62 | - name: Upload Release Asset 63 | env: 64 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 65 | run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/* 66 | 67 | # Create pull request 68 | - name: Create Pull Request 69 | if: ${{ steps.properties.outputs.changelog != '' }} 70 | env: 71 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 72 | run: | 73 | VERSION="${{ github.event.release.tag_name }}" 74 | BRANCH="changelog-update-$VERSION" 75 | 76 | git config user.email "action@github.com" 77 | git config user.name "GitHub Action" 78 | 79 | git checkout -b $BRANCH 80 | git commit -am "Changelog update - $VERSION" 81 | git push --set-upstream origin $BRANCH 82 | 83 | gh pr create \ 84 | --title "Changelog update - \`$VERSION\`" \ 85 | --body "Current pull request contains patched \`CHANGELOG.md\` file for the \`$VERSION\` version." \ 86 | --base main \ 87 | --head $BRANCH 88 | -------------------------------------------------------------------------------- /src/main/java/com/sourcegraph/action/OpenRevisionAction.java: -------------------------------------------------------------------------------- 1 | package com.sourcegraph.action; 2 | 3 | import com.intellij.openapi.actionSystem.AnAction; 4 | import com.intellij.openapi.actionSystem.AnActionEvent; 5 | import com.intellij.openapi.application.ApplicationInfo; 6 | import com.intellij.openapi.project.DumbAware; 7 | import com.intellij.openapi.project.Project; 8 | import com.intellij.openapi.vcs.VcsDataKeys; 9 | import com.intellij.openapi.vcs.history.VcsFileRevision; 10 | import com.intellij.vcs.log.VcsLog; 11 | import com.intellij.vcs.log.VcsLogDataKeys; 12 | 13 | import java.awt.Desktop; 14 | import java.io.IOException; 15 | import java.net.URI; 16 | import java.util.Optional; 17 | 18 | import com.sourcegraph.project.CommitViewUriBuilder; 19 | import com.sourcegraph.project.RepoInfo; 20 | import com.sourcegraph.project.RevisionContext; 21 | import com.sourcegraph.util.SourcegraphUtil; 22 | 23 | import org.jetbrains.annotations.NotNull; 24 | import com.intellij.openapi.diagnostic.Logger; 25 | 26 | /** 27 | * Jetbrains IDE action to open a selected revision in Sourcegraph. 28 | */ 29 | public class OpenRevisionAction extends AnAction implements DumbAware { 30 | private final Logger logger = Logger.getInstance(this.getClass()); 31 | 32 | private Optional getHistoryRevision(AnActionEvent e) { 33 | VcsFileRevision revision = e.getDataContext().getData(VcsDataKeys.VCS_FILE_REVISION); 34 | Project project = e.getProject(); 35 | 36 | if (project == null) { 37 | return Optional.empty(); 38 | } 39 | if (revision == null) { 40 | return Optional.empty(); 41 | } 42 | 43 | String rev = revision.getRevisionNumber().toString(); 44 | return Optional.of(new RevisionContext(project, rev)); 45 | } 46 | 47 | private Optional getLogRevision(AnActionEvent e) { 48 | VcsLog log = e.getDataContext().getData(VcsLogDataKeys.VCS_LOG); 49 | Project project = e.getProject(); 50 | 51 | if (project == null) { 52 | return Optional.empty(); 53 | } 54 | if (log == null || log.getSelectedCommits().isEmpty()) { 55 | return Optional.empty(); 56 | } 57 | 58 | 59 | String rev = log.getSelectedCommits().get(0).getHash().asString(); 60 | return Optional.of(new RevisionContext(project, rev)); 61 | } 62 | 63 | @Override 64 | public void actionPerformed(@NotNull AnActionEvent e) { 65 | // This action handles events for both log and history views, so attempt to load from any possible option. 66 | RevisionContext context = getHistoryRevision(e).or(() -> getLogRevision(e)) 67 | .orElseThrow(() -> new RuntimeException("Unable to determine revision from history or log.")); 68 | 69 | try { 70 | String productName = ApplicationInfo.getInstance().getVersionName(); 71 | String productVersion = ApplicationInfo.getInstance().getFullVersion(); 72 | RepoInfo repoInfo = SourcegraphUtil.repoInfo(context.getProject().getProjectFilePath(), context.getProject()); 73 | 74 | CommitViewUriBuilder builder = new CommitViewUriBuilder(); 75 | URI uri = builder.build(SourcegraphUtil.sourcegraphURL(context.getProject()), context.getRevisionNumber(), repoInfo, productName, productVersion); 76 | 77 | // Open the URL in the browser. 78 | Desktop.getDesktop().browse(uri); 79 | } catch (IOException err) { 80 | logger.debug("failed to open browser"); 81 | err.printStackTrace(); 82 | } 83 | } 84 | 85 | @Override 86 | public void update(@NotNull AnActionEvent e) { 87 | e.getPresentation().setEnabledAndVisible(true); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/sourcegraph/action/FileAction.java: -------------------------------------------------------------------------------- 1 | package com.sourcegraph.action; 2 | 3 | import com.intellij.openapi.actionSystem.AnAction; 4 | import com.intellij.openapi.actionSystem.AnActionEvent; 5 | import com.intellij.openapi.application.ApplicationInfo; 6 | import com.intellij.openapi.diagnostic.Logger; 7 | import com.intellij.openapi.editor.*; 8 | import com.intellij.openapi.fileEditor.FileDocumentManager; 9 | import com.intellij.openapi.fileEditor.FileEditorManager; 10 | import com.intellij.openapi.project.Project; 11 | import com.intellij.openapi.vfs.VirtualFile; 12 | import com.sourcegraph.project.RepoInfo; 13 | import com.sourcegraph.util.SourcegraphUtil; 14 | 15 | 16 | import java.net.URLEncoder; 17 | import java.nio.charset.StandardCharsets; 18 | import java.util.Objects; 19 | 20 | public abstract class FileAction extends AnAction { 21 | 22 | abstract void handleFileUri(String uri); 23 | 24 | @Override 25 | public void actionPerformed(AnActionEvent e) { 26 | // Get project, editor, document, file, and position information. 27 | final Project project = e.getProject(); 28 | if (project == null) { 29 | return; 30 | } 31 | Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); 32 | if (editor == null) { 33 | return; 34 | } 35 | Document currentDoc = editor.getDocument(); 36 | VirtualFile currentFile = FileDocumentManager.getInstance().getFile(currentDoc); 37 | if (currentFile == null) { 38 | return; 39 | } 40 | SelectionModel sel = editor.getSelectionModel(); 41 | 42 | // Get repo information. 43 | RepoInfo repoInfo = SourcegraphUtil.repoInfo(currentFile.getPath(), project); 44 | if (Objects.equals(repoInfo.remoteURL, "")) { 45 | return; 46 | } 47 | 48 | // Build the URL that we will open. 49 | String productName = ApplicationInfo.getInstance().getVersionName(); 50 | String productVersion = ApplicationInfo.getInstance().getFullVersion(); 51 | String uri; 52 | 53 | VisualPosition selectionStartPosition = sel.getSelectionStartPosition(); 54 | VisualPosition selectionEndPosition = sel.getSelectionEndPosition(); 55 | LogicalPosition start = selectionStartPosition != null ? editor.visualToLogicalPosition(selectionStartPosition) : null; 56 | LogicalPosition end = selectionEndPosition != null ? editor.visualToLogicalPosition(selectionEndPosition) : null; 57 | uri = SourcegraphUtil.sourcegraphURL(project)+"-/editor" 58 | + "?remote_url=" + URLEncoder.encode(repoInfo.remoteURL, StandardCharsets.UTF_8) 59 | + "&branch=" + URLEncoder.encode(repoInfo.branch, StandardCharsets.UTF_8) 60 | + "&file=" + URLEncoder.encode(repoInfo.fileRel, StandardCharsets.UTF_8) 61 | + "&editor=" + URLEncoder.encode("JetBrains", StandardCharsets.UTF_8) 62 | + "&version=" + URLEncoder.encode(SourcegraphUtil.VERSION, StandardCharsets.UTF_8) 63 | + (start != null ? ("&start_row=" + URLEncoder.encode(Integer.toString(start.line), StandardCharsets.UTF_8) 64 | + "&start_col=" + URLEncoder.encode(Integer.toString(start.column), StandardCharsets.UTF_8)) : "") 65 | + (end != null ? ("&end_row=" + URLEncoder.encode(Integer.toString(end.line), StandardCharsets.UTF_8) 66 | + "&end_col=" + URLEncoder.encode(Integer.toString(end.column), StandardCharsets.UTF_8)) : "") 67 | + "&utm_product_name=" + URLEncoder.encode(productName, StandardCharsets.UTF_8) 68 | + "&utm_product_version=" + URLEncoder.encode(productVersion, StandardCharsets.UTF_8); 69 | 70 | handleFileUri(uri); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/sourcegraph/action/SearchActionBase.java: -------------------------------------------------------------------------------- 1 | package com.sourcegraph.action; 2 | 3 | import com.intellij.openapi.actionSystem.AnAction; 4 | import com.intellij.openapi.actionSystem.AnActionEvent; 5 | import com.intellij.openapi.editor.Document; 6 | import com.intellij.openapi.editor.Editor; 7 | import com.intellij.openapi.editor.SelectionModel; 8 | import com.intellij.openapi.fileEditor.FileDocumentManager; 9 | import com.intellij.openapi.fileEditor.FileEditorManager; 10 | import com.intellij.openapi.project.Project; 11 | import com.intellij.openapi.vfs.VirtualFile; 12 | import com.intellij.openapi.diagnostic.Logger; 13 | import com.intellij.openapi.application.ApplicationInfo; 14 | import com.sourcegraph.project.RepoInfo; 15 | import com.sourcegraph.util.SourcegraphUtil; 16 | import org.jetbrains.annotations.Nullable; 17 | 18 | import java.io.*; 19 | import java.awt.Desktop; 20 | import java.net.URI; 21 | import java.net.URLEncoder; 22 | import java.nio.charset.StandardCharsets; 23 | 24 | public abstract class SearchActionBase extends AnAction { 25 | public void actionPerformedMode(AnActionEvent e, String mode) { 26 | Logger logger = Logger.getInstance(this.getClass()); 27 | 28 | // Get project, editor, document, file, and position information. 29 | final Project project = e.getProject(); 30 | if (project == null) { 31 | return; 32 | } 33 | Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); 34 | if (editor == null) { 35 | return; 36 | } 37 | Document currentDoc = editor.getDocument(); 38 | VirtualFile currentFile = FileDocumentManager.getInstance().getFile(currentDoc); 39 | if (currentFile == null) { 40 | return; 41 | } 42 | SelectionModel sel = editor.getSelectionModel(); 43 | 44 | // Get repo information. 45 | RepoInfo repoInfo = SourcegraphUtil.repoInfo(currentFile.getPath(), project); 46 | 47 | String q = sel.getSelectedText(); 48 | if (q == null || q.equals("")) { 49 | return; // nothing to query 50 | } 51 | 52 | // Build the URL that we will open. 53 | String uri; 54 | String productName = ApplicationInfo.getInstance().getVersionName(); 55 | String productVersion = ApplicationInfo.getInstance().getFullVersion(); 56 | 57 | uri = SourcegraphUtil.sourcegraphURL(project)+"-/editor" 58 | + "?editor=" + URLEncoder.encode("JetBrains", StandardCharsets.UTF_8) 59 | + "&version=" + URLEncoder.encode(SourcegraphUtil.VERSION, StandardCharsets.UTF_8) 60 | + "&utm_product_name=" + URLEncoder.encode(productName, StandardCharsets.UTF_8) 61 | + "&utm_product_version=" + URLEncoder.encode(productVersion, StandardCharsets.UTF_8) 62 | + "&search=" + URLEncoder.encode(q, StandardCharsets.UTF_8); 63 | 64 | if (mode.equals("search.repository")) { 65 | uri += "&search_remote_url=" + URLEncoder.encode(repoInfo.remoteURL, StandardCharsets.UTF_8) 66 | + "&search_branch=" + URLEncoder.encode(repoInfo.branch, StandardCharsets.UTF_8); 67 | } 68 | 69 | // Open the URL in the browser. 70 | try { 71 | Desktop.getDesktop().browse(URI.create(uri)); 72 | } catch (IOException err) { 73 | logger.debug("failed to open browser"); 74 | err.printStackTrace(); 75 | } 76 | } 77 | 78 | @Override 79 | public void update(AnActionEvent e) { 80 | final Project project = e.getProject(); 81 | if (project == null) { 82 | return; 83 | } 84 | String selectedText = getSelectedText(project); 85 | e.getPresentation().setEnabled(selectedText != null && selectedText.length() > 0); 86 | } 87 | 88 | @Nullable 89 | private String getSelectedText(Project project) { 90 | Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); 91 | if (editor == null) { 92 | return null; 93 | } 94 | Document currentDoc = editor.getDocument(); 95 | VirtualFile currentFile = FileDocumentManager.getInstance().getFile(currentDoc); 96 | if (currentFile == null) { 97 | return null; 98 | } 99 | SelectionModel sel = editor.getSelectionModel(); 100 | 101 | return sel.getSelectedText(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 |
7 | 8 | **⚠️ Development of the JetBrains plugin has [moved to `sourcegraph/jetbrains`](https://github.com/sourcegraph/jetbrains).** 9 | 10 |
11 |
12 |
13 |
14 |
15 |
16 | 17 | 18 | 19 | # Sourcegraph for JetBrains IDEs [![JetBrains Plugin](https://img.shields.io/badge/JetBrains-Sourcegraph-green.svg)](https://plugins.jetbrains.com/plugin/9682-sourcegraph) 20 | 21 | - Search snippets of code on Sourcegraph. 22 | - Copy and share a link to code on Sourcegraph. 23 | - Quickly go from files in your editor to Sourcegraph. 24 | 25 | 26 | The plugin works with all JetBrains IDEs including: 27 | 28 | - IntelliJ IDEA 29 | - IntelliJ IDEA Community Edition 30 | - PhpStorm 31 | - WebStorm 32 | - PyCharm 33 | - PyCharm Community Edition 34 | - RubyMine 35 | - AppCode 36 | - CLion 37 | - GoLand 38 | - DataGrip 39 | - Rider 40 | - Android Studio 41 | 42 | ## Installation 43 | 44 | - Select `IntelliJ IDEA` then `Preferences` (or use ⌘,) 45 | - Click `Plugins` in the left-hand pane. 46 | - Choose `Browse repositories...` 47 | - Search for `Sourcegraph` -> `Install` 48 | - Restart your IDE if needed, then select some code and choose `Sourcegraph` in the right-click context menu to see actions and keyboard shortcuts. 49 | 50 | ## Configuring for use with a private Sourcegraph instance 51 | 52 | The plugin is configurable _globally_ by creating a `.sourcegraph-jetbrains.properties` (or `sourcegraph-jetbrains.properties` pre-v1.2.2) in your home directory. For example, modify the following URL to match your on-premises Sourcegraph instance URL: 53 | 54 | ``` 55 | url = https://sourcegraph.example.com 56 | defaultBranch = example-branch 57 | remoteUrlReplacements = git.example.com, git-web.example.com 58 | ``` 59 | 60 | You may also choose to configure it _per repository_ using a `.idea/sourcegraph.xml` (or `idea/sourcegraph.xml` pre-v1.2.2) file in your repository like so: 61 | 62 | ```xml 63 | 64 | 65 | 66 | 70 | 71 | ``` 72 | 73 | By default, the plugin will use the `origin` git remote to determine which repository on Sourcegraph corresponds to your local repository. If your `origin` remote doesn't match Sourcegraph, you may instead configure a `sourcegraph` Git remote which will take priority. 74 | 75 | ## Questions & Feedback 76 | 77 | Please file an issue: https://github.com/sourcegraph/sourcegraph-jetbrains/issues/new 78 | 79 | ## Uninstallation 80 | 81 | - Select `IntelliJ IDEA` then `Preferences` (or use ⌘,) 82 | - Click `Plugins` in the left-hand pane. 83 | - Search for `Sourcegraph` -> Right click -> `Uninstall` (or uncheck to disable) 84 | 85 | ## Development 86 | 87 | - Start IntelliJ and choose `Check out from Version Control` -> `Git` -> `https://github.com/sourcegraph/sourcegraph-jetbrains` 88 | - Develop as you would normally (hit Debug icon in top right of IntelliJ) or using gradlew commands: 89 | 1. `./gradlew runIde` to run an IDE instance with sourcegraph plugin installed. This will start the platform with the versions defined in [`gradle.properties`](https://github.com/sourcegraph/sourcegraph-jetbrains/blob/main/gradle.properties#L14-L16). _Note: 2021.3 is required for M1 Macs._ 90 | 2. `./gradlew buildPlugin` to build plugin artifact (`build/distributions/Sourcegraph.zip`) 91 | 92 | ## Publishing a new version 93 | 94 | The publishing process is based on the actions outlined in the [`intellij-platform-plugin-template`](https://github.com/JetBrains/intellij-platform-plugin-template). 95 | 96 | 1. Update `gradle.properties` and set the version number for this release (e.g. `1.2.3`). 97 | 2. Create a [new release](https://github.com/sourcegraph/sourcegraph-jetbrains/releases/new) on GitHub. 98 | 3. Pick the new version number as the git tag (e.g. `v1.2.3`). 99 | 4. Copy/paste the `[Unreleased]` section of the [`CHANGELOG.md`](https://github.com/sourcegraph/sourcegraph-jetbrains/blob/main/CHANGELOG.md) into the GitHub release text. 100 | 5. Once published, a GitHub action is triggered that will publish the release automatically and create a PR to update the changelog and version text. You may need to manually fix the content. 101 | 102 | ## Version History 103 | 104 | See [`CHANGELOG.md`](https://github.com/sourcegraph/sourcegraph-jetbrains/blob/main/CHANGELOG.md). 105 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Workflow created for testing and preparing the plugin release in following steps: 2 | # - validate Gradle Wrapper, 3 | # - run 'test' and 'verifyPlugin' tasks, 4 | # - run Qodana inspections, 5 | # - run 'buildPlugin' task and prepare artifact for the further tests, 6 | # - run 'runPluginVerifier' task, 7 | # - create a draft release. 8 | # 9 | # Workflow is triggered on push and pull_request events. 10 | # 11 | # GitHub Actions reference: https://help.github.com/en/actions 12 | 13 | name: Build 14 | on: 15 | # Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g. for dependabot pull requests) 16 | push: 17 | branches: [main] 18 | # Trigger the workflow on any pull request 19 | pull_request: 20 | 21 | jobs: 22 | # Run Gradle Wrapper Validation Action to verify the wrapper's checksum 23 | # Run verifyPlugin, IntelliJ Plugin Verifier, and test Gradle tasks 24 | # Build plugin and provide the artifact for the next workflow jobs 25 | build: 26 | name: Build 27 | runs-on: ubuntu-latest 28 | outputs: 29 | version: ${{ steps.properties.outputs.version }} 30 | changelog: ${{ steps.properties.outputs.changelog }} 31 | steps: 32 | # Check out current repository 33 | - name: Fetch Sources 34 | uses: actions/checkout@v2.4.0 35 | 36 | # Validate wrapper 37 | - name: Gradle Wrapper Validation 38 | uses: gradle/wrapper-validation-action@v1.0.4 39 | 40 | # Setup Java 11 environment for the next steps 41 | - name: Setup Java 42 | uses: actions/setup-java@v2 43 | with: 44 | distribution: zulu 45 | java-version: 11 46 | cache: gradle 47 | 48 | # Set environment variables 49 | - name: Export Properties 50 | id: properties 51 | shell: bash 52 | run: | 53 | PROPERTIES="$(./gradlew properties --console=plain -q)" 54 | VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')" 55 | NAME="$(echo "$PROPERTIES" | grep "^pluginName:" | cut -f2- -d ' ')" 56 | CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)" 57 | CHANGELOG="${CHANGELOG//'%'/'%25'}" 58 | CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" 59 | CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" 60 | 61 | echo "::set-output name=version::$VERSION" 62 | echo "::set-output name=name::$NAME" 63 | echo "::set-output name=changelog::$CHANGELOG" 64 | echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier" 65 | 66 | ./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier 67 | 68 | # Run tests 69 | - name: Run Tests 70 | run: ./gradlew test 71 | 72 | # Collect Tests Result of failed tests 73 | - name: Collect Tests Result 74 | if: ${{ failure() }} 75 | uses: actions/upload-artifact@v2 76 | with: 77 | name: tests-result 78 | path: ${{ github.workspace }}/build/reports/tests 79 | 80 | # Cache Plugin Verifier IDEs 81 | - name: Setup Plugin Verifier IDEs Cache 82 | uses: actions/cache@v2.1.7 83 | with: 84 | path: ${{ steps.properties.outputs.pluginVerifierHomeDir }}/ides 85 | key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }} 86 | 87 | # Run Verify Plugin task and IntelliJ Plugin Verifier tool 88 | - name: Run Plugin Verification tasks 89 | run: ./gradlew runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }} 90 | 91 | # Collect Plugin Verifier Result 92 | - name: Collect Plugin Verifier Result 93 | if: ${{ always() }} 94 | uses: actions/upload-artifact@v2 95 | with: 96 | name: pluginVerifier-result 97 | path: ${{ github.workspace }}/build/reports/pluginVerifier 98 | 99 | # Run Qodana inspections 100 | - name: Qodana - Code Inspection 101 | uses: JetBrains/qodana-action@v4.2.3 102 | 103 | # Prepare plugin archive content for creating artifact 104 | - name: Prepare Plugin Artifact 105 | id: artifact 106 | shell: bash 107 | run: | 108 | cd ${{ github.workspace }}/build/distributions 109 | FILENAME=`ls *.zip` 110 | unzip "$FILENAME" -d content 111 | 112 | echo "::set-output name=filename::${FILENAME:0:-4}" 113 | 114 | # Store already-built plugin as an artifact for downloading 115 | - name: Upload artifact 116 | uses: actions/upload-artifact@v2.2.4 117 | with: 118 | name: ${{ steps.artifact.outputs.filename }} 119 | path: ./build/distributions/content/*/* 120 | 121 | # Prepare a draft release for GitHub Releases page for the manual verification 122 | # If accepted and published, release workflow would be triggered 123 | releaseDraft: 124 | name: Release Draft 125 | if: github.event_name != 'pull_request' 126 | needs: build 127 | runs-on: ubuntu-latest 128 | steps: 129 | # Check out current repository 130 | - name: Fetch Sources 131 | uses: actions/checkout@v2.4.0 132 | 133 | # Remove old release drafts by using the curl request for the available releases with draft flag 134 | - name: Remove Old Release Drafts 135 | env: 136 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 137 | run: | 138 | gh api repos/{owner}/{repo}/releases \ 139 | --jq '.[] | select(.draft == true) | .id' \ 140 | | xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{} 141 | 142 | # Create new release draft - which is not publicly visible and requires manual acceptance 143 | - name: Create Release Draft 144 | env: 145 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 146 | run: | 147 | gh release create v${{ needs.build.outputs.version }} \ 148 | --draft \ 149 | --title "v${{ needs.build.outputs.version }}" \ 150 | --notes "$(cat << 'EOM' 151 | ${{ needs.build.outputs.changelog }} 152 | EOM 153 | )" 154 | -------------------------------------------------------------------------------- /src/main/java/com/sourcegraph/util/SourcegraphUtil.java: -------------------------------------------------------------------------------- 1 | package com.sourcegraph.util; 2 | 3 | import com.intellij.openapi.diagnostic.Logger; 4 | import com.intellij.openapi.project.Project; 5 | import com.sourcegraph.project.*; 6 | 7 | import java.io.*; 8 | import java.nio.file.Path; 9 | import java.nio.file.Paths; 10 | import java.util.Properties; 11 | 12 | public class SourcegraphUtil { 13 | public static String VERSION = "v1.2.2"; 14 | 15 | // gitRemoteURL returns the remote URL for the given remote name. 16 | // e.g. "origin" -> "git@github.com:foo/bar" 17 | public static String gitRemoteURL(String repoDir, String remoteName) throws Exception { 18 | String s = exec("git remote get-url " + remoteName, repoDir).trim(); 19 | if (s.isEmpty()) { 20 | throw new Exception("no such remote"); 21 | } 22 | return s; 23 | } 24 | 25 | // configuredGitRemoteURL returns the URL of the "sourcegraph" remote, if 26 | // configured, or else the URL of the "origin" remote. An exception is 27 | // thrown if neither exists. 28 | public static String configuredGitRemoteURL(String repoDir) throws Exception { 29 | try { 30 | return gitRemoteURL(repoDir, "sourcegraph"); 31 | } catch (Exception err) { 32 | try { 33 | return gitRemoteURL(repoDir, "origin"); 34 | } catch (Exception err2) { 35 | throw new Exception("no configured git remote \"sourcegraph\" or \"origin\""); 36 | } 37 | } 38 | } 39 | 40 | // gitRootDir returns the repository root directory for any directory 41 | // within the repository. 42 | public static String gitRootDir(String repoDir) throws IOException { 43 | return exec("git rev-parse --show-toplevel", repoDir).trim(); 44 | } 45 | 46 | // gitBranch returns either the current branch name of the repository OR in 47 | // all other cases (e.g. detached HEAD state), it returns "HEAD". 48 | public static String gitBranch(String repoDir) throws IOException { 49 | return exec("git rev-parse --abbrev-ref HEAD", repoDir).trim(); 50 | } 51 | 52 | // verify that provided branch exists on remote 53 | public static boolean isRemoteBranch(String branch, String repoDir) throws IOException { 54 | return exec("git show-branch remotes/origin/" + branch, repoDir).length() > 0; 55 | } 56 | 57 | public static String sourcegraphURL(Project project) { 58 | String url = SourcegraphConfig.getInstance(project).getUrl(); 59 | if (url == null || url.length() == 0) { 60 | Properties props = readProps(); 61 | url = props.getProperty("url", "https://sourcegraph.com/"); 62 | } 63 | return url.endsWith("/") ? url : url + "/"; 64 | } 65 | 66 | // get defaultBranch configuration option 67 | public static String setDefaultBranch(Project project) { 68 | String defaultBranch = SourcegraphConfig.getInstance(project).getDefaultBranch(); 69 | if (defaultBranch == null || defaultBranch.length() == 0) { 70 | Properties props = readProps(); 71 | defaultBranch = props.getProperty("defaultBranch", null); 72 | } 73 | return defaultBranch; 74 | } 75 | 76 | // get remoteUrlReplacements configuration option 77 | public static String setRemoteUrlReplacements(Project project) { 78 | String replacements = SourcegraphConfig.getInstance(project).getRemoteUrlReplacements(); 79 | if (replacements == null || replacements.length() == 0) { 80 | Properties props = readProps(); 81 | replacements = props.getProperty("remoteUrlReplacements", null); 82 | } 83 | return replacements; 84 | } 85 | 86 | // readProps returns the first properties file it's able to parse from the following paths: 87 | // $HOME/.sourcegraph-jetbrains.properties 88 | // $HOME/sourcegraph-jetbrains.properties 89 | private static Properties readProps() { 90 | Path[] candidatePaths = { 91 | Paths.get(System.getProperty("user.home"), ".sourcegraph-jetbrains.properties"), 92 | Paths.get(System.getProperty("user.home"), "sourcegraph-jetbrains.properties"), 93 | }; 94 | 95 | for (Path path : candidatePaths) { 96 | try { 97 | return readPropsFile(path.toFile()); 98 | } catch (IOException e) { 99 | // no-op 100 | } 101 | } 102 | // No files found/readable 103 | return new Properties(); 104 | } 105 | 106 | private static Properties readPropsFile(File file) throws IOException { 107 | Properties props = new Properties(); 108 | 109 | try (InputStream input = new FileInputStream(file)) { 110 | props.load(input); 111 | } 112 | 113 | return props; 114 | } 115 | 116 | // repoInfo returns the Sourcegraph repository URI, and the file path 117 | // relative to the repository root. If the repository URI cannot be 118 | // determined, a RepoInfo with empty strings is returned. 119 | public static RepoInfo repoInfo(String fileName, Project project) { 120 | String fileRel = ""; 121 | String remoteURL = ""; 122 | String branch = ""; 123 | try{ 124 | // Determine repository root directory. 125 | String fileDir = fileName.substring(0, fileName.lastIndexOf("/")); 126 | String repoRoot = gitRootDir(fileDir); 127 | 128 | // Determine file path, relative to repository root. 129 | fileRel = fileName.substring(repoRoot.length()+1); 130 | remoteURL = configuredGitRemoteURL(repoRoot); 131 | branch = SourcegraphUtil.setDefaultBranch(project)!=null ? SourcegraphUtil.setDefaultBranch(project) : gitBranch(repoRoot); 132 | 133 | // If on a branch that does not exist on the remote and no defaultBranch is configured 134 | // use "master" instead. 135 | // This allows users to check out a branch that does not exist in origin remote by setting defaultBranch 136 | if (!isRemoteBranch(branch, repoRoot) && SourcegraphUtil.setDefaultBranch(project)==null) { 137 | branch = "master"; 138 | } 139 | 140 | // replace remoteURL if config option is not null 141 | String r = SourcegraphUtil.setRemoteUrlReplacements(project); 142 | if(r!=null) { 143 | String[] replacements = r.trim().split("\\s*,\\s*"); 144 | // Check if the entered values are pairs 145 | for (int i = 0; i < replacements.length && replacements.length % 2 == 0; i += 2) { 146 | remoteURL = remoteURL.replace(replacements[i], replacements[i+1]); 147 | } 148 | } 149 | } catch (Exception err) { 150 | Logger.getInstance(SourcegraphUtil.class).info(err); 151 | err.printStackTrace(); 152 | } 153 | return new RepoInfo(fileRel, remoteURL, branch); 154 | } 155 | 156 | // exec executes the given command in the specified directory and returns 157 | // its stdout. Any stderr output is logged. 158 | public static String exec(String cmd, String dir) throws IOException { 159 | Logger.getInstance(SourcegraphUtil.class).debug("exec cmd='" + cmd + "' dir="+dir); 160 | 161 | // Create the process. 162 | Process p = Runtime.getRuntime().exec(cmd, null, new File(dir)); 163 | BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); 164 | BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream())); 165 | 166 | // Log any stderr output. 167 | Logger logger = Logger.getInstance(SourcegraphUtil.class); 168 | String s; 169 | while ((s = stderr.readLine()) != null) { 170 | logger.debug(s); 171 | } 172 | 173 | String out = ""; 174 | //noinspection StatementWithEmptyBody 175 | for (String l; (l = stdout.readLine()) != null; out += l + "\n"); 176 | return out; 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2000-2016 JetBrains s.r.o. 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------