├── .codecov.yml ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── PULL_REQUEST_TEMPLATE │ ├── bug_fix.md │ └── new_feature.md ├── .gitignore ├── .mvn └── extensions.xml ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── bundles ├── fr.kazejiyu.discord.rpc.integration.adapters │ ├── .classpath │ ├── .project │ ├── .settings │ │ └── org.eclipse.jdt.core.prefs │ ├── META-INF │ │ └── MANIFEST.MF │ ├── build.properties │ ├── plugin.xml │ └── src │ │ └── fr │ │ └── kazejiyu │ │ └── discord │ │ └── rpc │ │ └── integration │ │ └── adapters │ │ ├── DefaultClassFileEditorInputRichPresence.java │ │ ├── DefaultFileEditorInputRichPresence.java │ │ ├── DefaultURIEditorInputRichPresence.java │ │ ├── LanguageLabel.java │ │ └── package-info.java ├── fr.kazejiyu.discord.rpc.integration.ui.preferences │ ├── .classpath │ ├── .project │ ├── .settings │ │ └── org.eclipse.jdt.core.prefs │ ├── META-INF │ │ └── MANIFEST.MF │ ├── build.properties │ ├── plugin.xml │ └── src │ │ └── fr │ │ └── kazejiyu │ │ └── discord │ │ └── rpc │ │ └── integration │ │ └── ui │ │ └── preferences │ │ ├── Activator.java │ │ ├── DiscordIntegrationIconsPreferencesPage.java │ │ ├── DiscordIntegrationPreferencesPage.java │ │ ├── DiscordIntegrationWordingPreferencesPage.java │ │ ├── internal │ │ ├── CustomWordingVariables.java │ │ ├── GroupFieldEditor.java │ │ ├── LambdaLabelProvider.java │ │ └── LinkFieldEditor.java │ │ └── properties │ │ ├── AbstractPropertyPage.java │ │ ├── ProjectPropertiesIconsPage.java │ │ ├── ProjectPropertiesPage.java │ │ └── ProjectPropertiesWordingPage.java ├── fr.kazejiyu.discord.rpc.integration │ ├── .classpath │ ├── .project │ ├── .settings │ │ └── org.eclipse.jdt.core.prefs │ ├── META-INF │ │ └── MANIFEST.MF │ ├── build.properties │ ├── plugin.xml │ ├── schema │ │ └── editor_input_adapter.exsd │ └── src │ │ └── fr │ │ └── kazejiyu │ │ └── discord │ │ └── rpc │ │ └── integration │ │ ├── Activator.java │ │ ├── Plugin.java │ │ ├── core │ │ ├── DiscordRpcLifecycle.java │ │ ├── DiscordRpcProxy.java │ │ ├── ImmutableRichPresence.java │ │ ├── PreferredRichPresence.java │ │ ├── RichPresence.java │ │ ├── SelectionTimes.java │ │ └── package-info.java │ │ ├── extensions │ │ ├── EditorInputToRichPresenceAdapter.java │ │ ├── EditorRichPresenceFromInput.java │ │ ├── internal │ │ │ ├── EditorRichPresenceFromExtensions.java │ │ │ ├── UnknownInputRichPresence.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ ├── files │ │ ├── AddListenerOnWindowOpened.java │ │ ├── EditionContext.java │ │ ├── EditorToRichPresenceAdapter.java │ │ ├── OnPostShutdown.java │ │ ├── UpdateDiscordOnEditorChange.java │ │ └── package-info.java │ │ ├── languages │ │ ├── Language.java │ │ └── package-info.java │ │ └── settings │ │ ├── DiscordIntegrationPreferencesInitializer.java │ │ ├── GlobalPreferences.java │ │ ├── GlobalPreferencesListener.java │ │ ├── Moment.java │ │ ├── ProjectPreferences.java │ │ ├── ProjectPreferencesListener.java │ │ ├── SettingChangeListener.java │ │ ├── Settings.java │ │ ├── UpdateDiscordOnSettingChange.java │ │ ├── UserPreferences.java │ │ └── package-info.java ├── java-discord-rpc │ ├── .classpath │ ├── .project │ ├── .settings │ │ └── org.eclipse.jdt.core.prefs │ ├── META-INF │ │ └── MANIFEST.MF │ ├── build.properties │ ├── discord-rpc-release-v3.4.0.jar │ ├── java-discord-rpc-2.0.2.jar │ ├── jna-4.4.0.jar │ └── pom.xml └── pom.xml ├── checkstyle.xml ├── docs ├── .gitignore ├── Makefile ├── README.md ├── conf.py ├── contribute │ └── contributing-guide.rst ├── customize │ ├── change-language-icons.rst │ ├── change-name-of-projects.rst │ ├── change-wording.rst │ ├── deactivate-plugin.rst │ ├── global-and-project-scopes.rst │ ├── hide-information.rst │ └── images │ │ ├── change_icons_preferences_page.png │ │ ├── change_wording_preferences_page.png │ │ ├── custom_icon.png │ │ ├── global_preferences.png │ │ └── project_preferences.png ├── extend │ ├── change-wording.rst │ └── support-new-editors.rst ├── images │ ├── rich-presence-examples.gif │ └── rich_presence_example.png ├── index.rst ├── install │ ├── from-marketplace.rst │ └── from-p2.rst ├── make.bat └── troubleshooting │ ├── not-detected-as-game.rst │ └── workbench-early-startup-error.rst ├── features ├── fr.kazejiyu.discord.rpc.integration.feature │ ├── .project │ ├── build.properties │ └── feature.xml ├── fr.kazejiyu.discord.rpc.integration.ui.feature │ ├── .project │ ├── build.properties │ └── feature.xml ├── java-discord-rpc.feature │ ├── .project │ ├── build.properties │ └── feature.xml └── pom.xml ├── pom.xml ├── releng ├── fr.kazejiyu.discord.rpc.integration.p2 │ ├── .project │ ├── bintray.ant │ ├── category.xml │ ├── packaging-p2composite.ant │ ├── pom.xml │ └── removeFromBintray.sh ├── fr.kazejiyu.discord.rpc.integration.target │ ├── .project │ ├── fr.kazejiyu.discord.rpc.integration.target.target │ └── pom.xml └── pom.xml ├── sonar-project.properties └── tests ├── fr.kazejiyu.discord.rpc.integration.adapters.tests ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── lib │ └── org.junit.jupiter.engine-5.1.0.v20180327-1502.jar ├── pom.xml └── src │ └── fr │ └── kazejiyu │ └── discord │ └── rpc │ └── integration │ ├── adapters │ ├── DefaultFileEditorInputRichPresenceTest.java │ └── DefaultURIEditorInputRichPresenceTest.java │ └── tests │ └── mock │ ├── MockitoExtension.java │ └── package-info.java ├── fr.kazejiyu.discord.rpc.integration.tests.report └── pom.xml ├── fr.kazejiyu.discord.rpc.integration.tests ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── lib │ └── org.junit.jupiter.engine-5.1.0.v20180327-1502.jar ├── pom.xml └── src │ └── fr │ └── kazejiyu │ └── discord │ └── rpc │ └── integration │ ├── core │ ├── ImmutableRichPresenceTest.java │ ├── PreferredRichPresenceTest.java │ └── SelectionTimesTest.java │ ├── extensions │ ├── EditorInputToRichPresenceAdapterTest.java │ └── internal │ │ ├── ChildOfIEditorInput.java │ │ ├── EditorRichPresenceFromExtensionsTest.java │ │ ├── FakeEditorInputRichPresence.java │ │ ├── GrandchildOfIEditorInput.java │ │ └── UnknownInputRichPresenceTest.java │ ├── files │ ├── AddListenerOnWindowOpenedTest.java │ ├── EditorToRichPresenceAdapterTest.java │ └── UpdateDiscordOnEditorChangeTest.java │ ├── languages │ └── LanguageTest.java │ ├── settings │ ├── GlobalPreferencesListenerTest.java │ └── UpdateDiscordOnSettingChangeTest.java │ └── tests │ └── mock │ ├── MockitoExtension.java │ └── package-info.java ├── org.assertj ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── META-INF │ └── MANIFEST.MF ├── assertj-core-3.9.0.jar └── build.properties └── pom.xml /.codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | patch: off -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve the plug-in! 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Bug description 11 | 12 | 13 | 14 | ## Expected behavior 15 | 16 | 17 | 18 | ## How to reproduce 19 | 20 | Steps to reproduce the behavior: 21 | 1. Go to '...' 22 | 2. Click on '....' 23 | 3. Scroll down to '....' 24 | 4. Witness the error 25 | 26 | ## Additional context 27 | 28 | 29 | 30 | - **Plug-in version**: 31 | - **Eclipse IDE version**: 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: feature request 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Motivation 11 | 12 | 13 | 14 | ## Proposed Solution 15 | 16 | 17 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/bug_fix.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Bug description 4 | 5 | 6 | 7 | ## Solution 8 | 9 | 10 | 11 | ## Checklist 12 | 13 | _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._ 14 | 15 | - [ ] I have read the [CONTRIBUTING](https://github.com/echebbi/eclipse-discord-integration/blob/master/CONTRIBUTING.md) doc 16 | - [ ] The Maven build pass locally with my changes 17 | - [ ] I have added tests that prove my feature works 18 | - [ ] I have added necessary documentation (if appropriate) 19 | 20 | ## Further comments 21 | 22 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/new_feature.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Proposed changes 4 | 5 | 6 | 7 | ## Checklist 8 | 9 | _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._ 10 | 11 | - [ ] I have read the [CONTRIBUTING](https://github.com/echebbi/eclipse-discord-integration/blob/master/CONTRIBUTING.md) doc 12 | - [ ] The Maven build pass locally with my changes 13 | - [ ] I have added tests that prove my feature works 14 | - [ ] I have added necessary documentation (if appropriate) 15 | 16 | ## Further comments 17 | 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | bin/ 4 | 5 | # Log file 6 | *.log 7 | 8 | # BlueJ files 9 | *.ctxt 10 | 11 | # Mobile Tools for Java (J2ME) 12 | .mtj.tmp/ 13 | 14 | # Package Files # 15 | *.jar 16 | *.war 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | # Maven 26 | target/ 27 | .polyglot.build.properties 28 | 29 | # Visual Studio Code 30 | .vscode/ -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.eclipse.tycho.extras 4 | tycho-pomless 5 | 1.6.0 6 | 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - openjdk8 5 | 6 | addons: 7 | sonarcloud: 8 | organization: "echebbi-github" 9 | 10 | # Prevents "mvn install" default step 11 | install: true 12 | 13 | before_script: 14 | - git fetch --unshallow 15 | # Prevent installed packages from being used during build 16 | - rm -rfv "$HOME/.m2/repository/fr/kazejiyu/discord/" 17 | 18 | dist: trusty 19 | 20 | script: mvn clean verify -P jacoco sonar:sonar 21 | 22 | after_success: 23 | - bash <(curl -s https://codecov.io/bash) 24 | 25 | # Keep p2 information 26 | cache: 27 | directories: 28 | - "$HOME/.m2/repository" -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). 5 | 6 | ## [1.2.2] - 2020-07-05 7 | ### Added 8 | - [#84](https://github.com/echebbi/eclipse-discord-integration/issues/84) Show "Viewing _fileName_" when the current editor displays a _.class_ file 9 | 10 | ### Fixed 11 | - [#85](https://github.com/echebbi/eclipse-discord-integration/issues/85) The 'editor_input_adapter' extension point asks for an instance of EditorInputRichPresence instead of EditorInputToRichPresenceAdapter 12 | 13 | ## [1.2.1] - 2020-06-05 14 | ### Changed 15 | - [#86](https://github.com/echebbi/eclipse-discord-integration/issues/86) The UI feature includes the core feature so that installing the first one automatically installs the later 16 | 17 | ## [1.2.0] - 2020-05-01 18 | ### Fixed 19 | - [#79](https://github.com/echebbi/eclipse-discord-integration/pull/79) Prevent [custom project names](https://discord-rich-presence-for-eclipse-ide.readthedocs.io/en/latest/customize/change-name-of-projects.html#) from being ignored 20 | 21 | ## [1.1.3] - 2020-05-01 22 | ### Added 23 | - [#67](https://github.com/echebbi/eclipse-discord-integration/issues/67) Deactivate Preferences fields when the plug-in is disabled 24 | - [#71](https://github.com/echebbi/eclipse-discord-integration/issues/71) Customize wording from Eclipse IDE's UI 25 | 26 | ### Changed 27 | - [#78](https://github.com/echebbi/eclipse-discord-integration/pull/78) Unchecking privacy settings like _Show file name_ now replaces the variable by _?_. The previous behavior (i.e. hidding the whole _Editing <file name>_ sentence) can be restored through custom wording 28 | 29 | ## [1.1.2] - 2019-10-26 30 | ### Added 31 | - [#75](https://github.com/echebbi/eclipse-discord-integration/pull/75) Display Eclipse IDE's logo in the bottom right corner of language's icon 32 | 33 | ## [1.1.1] - 2019-09-30 34 | ### Added 35 | - [#72](https://github.com/echebbi/eclipse-discord-integration/pull/72) Add link to the documentation in Preferences and Project Settings pages 36 | 37 | ## [1.1.0] - 2019-09-27 38 | ### Added 39 | - [#66](https://github.com/echebbi/eclipse-discord-integration/issues/66) Allow users to customize icons shown on Discord 40 | 41 | ## [1.0.3] - 2019-02-26 42 | ### Fixed 43 | - [#56](https://github.com/echebbi/eclipse-discord-integration/issues/56) Prevent the plug-in from not working in some environments 44 | 45 | ## [1.0.1] - 2018-11-24 46 | ### Fixed 47 | - [#55](https://github.com/echebbi/eclipse-discord-integration/issues/55) Properly close connection with Discord on workbench shutdown 48 | 49 | ## [1.0.0] - 2018-08-23 50 | ### Added 51 | - [#50](https://github.com/echebbi/eclipse-discord-integration/pull/50) Allow to deactivate the Rich Presence integration 52 | - [#52](https://github.com/echebbi/eclipse-discord-integration/pull/52) Handle the C language (_*.c_ and _*.h_ files) 53 | - [#54](https://github.com/echebbi/eclipse-discord-integration/pull/54) First deployment on the [Eclipse Marketplace](https://marketplace.eclipse.org/content/discord-rich-presence-eclipse-ide) 54 | 55 | ### Fixed 56 | - Prevent elapsed time from not showing at startup when set on file change 57 | 58 | ## [0.8.4] - 2018-07-01 59 | ### Added 60 | - [#34](https://github.com/echebbi/eclipse-discord-integration/pull/34) Log errors in Eclipse "Error Log" views 61 | 62 | ### Fixed 63 | - [#26](https://github.com/echebbi/eclipse-discord-integration/issues/26) Make the plug-in available on macOS 64 | 65 | ## [0.8.3] - 2018-05-29 66 | ### Added 67 | - [#32](https://github.com/echebbi/eclipse-discord-integration/pull/32) Make possible to change the name displayed in Discord for a given project 68 | - Update plug-in's name to "Discord Rich Presence for Eclipse IDE" 69 | 70 | ## [0.8.2] - 2018-05-26 71 | ### Fixed 72 | - [#29](https://github.com/echebbi/eclipse-discord-integration/issues/29) Make the plug-in available from Eclipse Mars (4.5) 73 | 74 | ## [0.8.1] - 2018-05-25 75 | ### Fixed 76 | - [#23](https://github.com/echebbi/eclipse-discord-integration/issues/23) Settings were not always shown in projet Properties 77 | 78 | ### Added 79 | - Explanations about how to install the plug-in 80 | 81 | ## [0.8.0] - 2018-05-08 82 | ### Added 83 | - Notify Discord of file change on Windows and GNU/Linux 84 | - Provide settings in Eclipse Preferences to tailor integration 85 | - Provide settings in projet Properties to tailor integration per project 86 | - Automate deployment to Bintray with Maven -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.adapters/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.adapters/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fr.kazejiyu.discord.rpc.integration.adapters 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | net.sf.eclipsecs.core.CheckstyleBuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.pde.PluginNature 31 | org.eclipse.jdt.core.javanature 32 | net.sf.eclipsecs.core.CheckstyleNature 33 | 34 | 35 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.adapters/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.adapters/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Discord Rich Presence for Eclipse IDE — Default Adapters 4 | Bundle-SymbolicName: fr.kazejiyu.discord.rpc.integration.adapters;singleton:=true 5 | Bundle-Version: 1.2.2 6 | Automatic-Module-Name: fr.kazejiyu.discord.rpc.integration.adapters 7 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 8 | Require-Bundle: fr.kazejiyu.discord.rpc.integration;bundle-version="0.8.2", 9 | org.eclipse.ui.workbench;bundle-version="[3.107.0,4.0.0)", 10 | org.eclipse.ui.ide;bundle-version="[3.11.0,4.0.0)", 11 | org.eclipse.core.resources;bundle-version="[3.10.0,4.0.0)", 12 | org.eclipse.jdt.ui;bundle-version="[3.0.0,4.0.0)";resolution:=optional, 13 | org.eclipse.jdt.core;bundle-version="[3.0.0,4.0.0)";resolution:=optional, 14 | org.eclipse.core.runtime;bundle-version="[3.0.0,4.0.0)";resolution:=optional 15 | Bundle-Vendor: Emmanuel CHEBBI 16 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.adapters/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = META-INF/,\ 4 | .,\ 5 | plugin.xml -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.adapters/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 8 | 9 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.adapters/src/fr/kazejiyu/discord/rpc/integration/adapters/LanguageLabel.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.adapters; 11 | 12 | import static fr.kazejiyu.discord.rpc.integration.languages.Language.BINARY; 13 | import static fr.kazejiyu.discord.rpc.integration.languages.Language.DOCKER; 14 | import static fr.kazejiyu.discord.rpc.integration.languages.Language.GIT; 15 | import static fr.kazejiyu.discord.rpc.integration.languages.Language.SCALA; 16 | import static fr.kazejiyu.discord.rpc.integration.languages.Language.TERMINAL; 17 | import static fr.kazejiyu.discord.rpc.integration.languages.Language.TEXT; 18 | import static fr.kazejiyu.discord.rpc.integration.languages.Language.UNKNOWN; 19 | 20 | import fr.kazejiyu.discord.rpc.integration.languages.Language; 21 | 22 | /** 23 | * Creates a label for a given {@link Language}. 24 | * 25 | * @author Emmanuel CHEBBI 26 | */ 27 | // TODO [Refactor] Consider turning Language into an OO architecture to get rid of this class 28 | final class LanguageLabel { 29 | 30 | private LanguageLabel() { 31 | // utility classes do not need to be instantiated 32 | } 33 | 34 | protected static String labelOf(Language language, String fileName) { 35 | if (language == UNKNOWN) { 36 | return ""; 37 | } 38 | if (language == BINARY) { 39 | return "Binary file"; 40 | } 41 | if (language == DOCKER) { 42 | return "Configuring Docker image"; 43 | } 44 | if (language == GIT) { 45 | return "Configuring Git"; 46 | } 47 | if (language == SCALA && fileName.endsWith(".sbt")) { 48 | return "Configuring SBT build"; 49 | } 50 | if (language == TERMINAL) { 51 | return "Configuring an OS script"; 52 | } 53 | if (language == TEXT) { 54 | return "Text file"; 55 | } 56 | return "Programming in " + language.getName(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.adapters/src/fr/kazejiyu/discord/rpc/integration/adapters/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | /** 11 | * Default implementations for {@link fr.kazejiyu.discord.rpc.integration.core.ImmutableRichPresence RichPresence} 12 | * interface. 13 | * 14 | * @author Emmanuel CHEBBI 15 | */ 16 | package fr.kazejiyu.discord.rpc.integration.adapters; 17 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fr.kazejiyu.discord.rpc.integration.ui.preferences 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | net.sf.eclipsecs.core.CheckstyleBuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.pde.PluginNature 31 | org.eclipse.jdt.core.javanature 32 | net.sf.eclipsecs.core.CheckstyleNature 33 | 34 | 35 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Discord Rich Presence for Eclipse IDE — Preferences 4 | Bundle-SymbolicName: fr.kazejiyu.discord.rpc.integration.ui.preferences;singleton:=true 5 | Bundle-Version: 1.2.2 6 | Bundle-Activator: fr.kazejiyu.discord.rpc.integration.ui.preferences.Activator 7 | Require-Bundle: org.eclipse.ui;bundle-version="[3.107.0,4.0.0)", 8 | org.eclipse.core.runtime;bundle-version="[3.11.0,4.0.0)", 9 | fr.kazejiyu.discord.rpc.integration;bundle-version="1.2.1", 10 | org.eclipse.core.resources;bundle-version="[3.10.0,4.0.0)" 11 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 12 | Automatic-Module-Name: fr.kazejiyu.discord.rpc.integration.ui.preferences 13 | Bundle-ActivationPolicy: lazy 14 | Bundle-Vendor: Emmanuel CHEBBI 15 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = META-INF/,\ 4 | .,\ 5 | plugin.xml 6 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 10 | 11 | 16 | 17 | 22 | 23 | 24 | 26 | 31 | 32 | 34 | 35 | 36 | 37 | 42 | 43 | 45 | 46 | 47 | 48 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/src/fr/kazejiyu/discord/rpc/integration/ui/preferences/Activator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.ui.preferences; 11 | 12 | import org.eclipse.ui.plugin.AbstractUIPlugin; 13 | import org.osgi.framework.BundleContext; 14 | 15 | /** 16 | * The activator class controls the plug-in life cycle. 17 | */ 18 | public class Activator extends AbstractUIPlugin { 19 | 20 | // The plug-in ID 21 | public static final String PLUGIN_ID = "fr.kazejiyu.discord.rpc.integration.ui.preferences"; //$NON-NLS-1$ 22 | 23 | // The shared instance 24 | private static Activator plugin; 25 | 26 | @Override 27 | public void start(BundleContext context) throws Exception { 28 | super.start(context); 29 | plugin = this; 30 | } 31 | 32 | @Override 33 | public void stop(BundleContext context) throws Exception { 34 | plugin = null; 35 | super.stop(context); 36 | } 37 | 38 | /** 39 | * Returns the shared instance. 40 | * @return the shared instance 41 | */ 42 | public static Activator getDefault() { 43 | return plugin; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/src/fr/kazejiyu/discord/rpc/integration/ui/preferences/DiscordIntegrationIconsPreferencesPage.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.ui.preferences; 11 | 12 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.CUSTOM_APP_ID; 13 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.USE_CUSTOM_APP; 14 | import static fr.kazejiyu.discord.rpc.integration.ui.preferences.DiscordIntegrationPreferencesPage.PREFERENCES_STORE_ID; 15 | 16 | import org.eclipse.core.runtime.preferences.InstanceScope; 17 | import org.eclipse.jface.preference.BooleanFieldEditor; 18 | import org.eclipse.jface.preference.FieldEditorPreferencePage; 19 | import org.eclipse.jface.preference.StringFieldEditor; 20 | import org.eclipse.ui.IWorkbench; 21 | import org.eclipse.ui.IWorkbenchPreferencePage; 22 | import org.eclipse.ui.preferences.ScopedPreferenceStore; 23 | 24 | /** 25 | * A page allowing users to tailor icons shown in Discord. 26 | */ 27 | public class DiscordIntegrationIconsPreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { 28 | 29 | /** 30 | * Creates a new page. 31 | */ 32 | public DiscordIntegrationIconsPreferencesPage() { 33 | super(FLAT); 34 | } 35 | 36 | @Override 37 | public void init(IWorkbench workbench) { 38 | setPreferenceStore(new ScopedPreferenceStore(InstanceScope.INSTANCE, PREFERENCES_STORE_ID)); 39 | setDescription("Customize icons shown in Discord by using your own Discord application (https://discordapp.com/developers):"); 40 | } 41 | 42 | @Override 43 | public void createFieldEditors() { 44 | BooleanFieldEditor useCustomApplication = new BooleanFieldEditor(USE_CUSTOM_APP.property(), "Use &custom application", getFieldEditorParent()); 45 | StringFieldEditor customApplicationId = new StringFieldEditor(CUSTOM_APP_ID.property(), "ID of the Discord application to use:", getFieldEditorParent()); 46 | 47 | addField(useCustomApplication); 48 | addField(customApplicationId); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/src/fr/kazejiyu/discord/rpc/integration/ui/preferences/internal/CustomWordingVariables.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.ui.preferences.internal; 11 | 12 | /** 13 | * The variables that can be used by the user when defining a custom wording. 14 | */ 15 | public enum CustomWordingVariables { 16 | 17 | /** 18 | * A variable replaced by the name of the file with its extension. 19 | */ 20 | FILE_NAME("${file}", "the name of the file with its extension"), 21 | 22 | /** 23 | * A variable replaced by the name of the file without its extension. 24 | */ 25 | FILE_WITHOUT_EXTENSION("${file.baseName}", "the name of the file without its extension"), 26 | 27 | /** 28 | * A variable replaced by the extension of the file. 29 | */ 30 | FILE_EXTENSION("${file.extension}", "the extension of the file"), 31 | 32 | /** 33 | * A variable replaced by the name of the programming language. 34 | */ 35 | LANGUAGE("${language}", "the name of the programming language"), 36 | 37 | /** 38 | * A variable replaced by the name of the project. 39 | */ 40 | PROJECT("${project}", "the name of the project"); 41 | 42 | private final String template; 43 | 44 | private final String replacedBy; 45 | 46 | private CustomWordingVariables(String template, String replacedBy) { 47 | this.template = template; 48 | this.replacedBy = replacedBy; 49 | } 50 | 51 | /** 52 | * Returns the template associated with the variable. 53 | * @return the template associated with the variable 54 | */ 55 | public String template() { 56 | return template; 57 | } 58 | 59 | /** 60 | * Returns a description of the value by which the variable is replaced. 61 | * @return a description of the value by which the variable is replaced. 62 | */ 63 | public String replacedBy() { 64 | return replacedBy; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/src/fr/kazejiyu/discord/rpc/integration/ui/preferences/internal/GroupFieldEditor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.ui.preferences.internal; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Collection; 14 | 15 | import org.eclipse.jface.preference.FieldEditor; 16 | import org.eclipse.jface.preference.IPreferenceStore; 17 | import org.eclipse.swt.SWT; 18 | import org.eclipse.swt.layout.FillLayout; 19 | import org.eclipse.swt.layout.GridLayout; 20 | import org.eclipse.swt.widgets.Composite; 21 | import org.eclipse.swt.widgets.Group; 22 | 23 | /** 24 | * A field editor allowing to group {@link FieldEditor}s under the same {@link Group}. 25 | * 26 | * @author Emmanuel CHEBBI 27 | */ 28 | public class GroupFieldEditor extends FieldEditor { 29 | 30 | private static final int MARGIN = 6; 31 | 32 | private Collection fields = new ArrayList<>(); 33 | 34 | private final Group group; 35 | 36 | /** 37 | * Creates a new group field. 38 | * 39 | * @param name 40 | * The name of the group. 41 | * @param parent 42 | * The parent of the group. 43 | */ 44 | public GroupFieldEditor(String name, Composite parent) { 45 | 46 | FillLayout layout = new FillLayout(); 47 | layout.marginWidth = MARGIN; 48 | layout.marginHeight = MARGIN; 49 | parent.setLayout(layout); 50 | 51 | this.group = new Group(parent, SWT.DEFAULT); 52 | this.group.setText(name); 53 | } 54 | 55 | /** 56 | * Returns the parent of the group. 57 | * @return the parent of the group 58 | */ 59 | public Composite getFieldEditorParent() { 60 | return group; 61 | } 62 | 63 | /** 64 | * Adds a new field editor to the group. 65 | * 66 | * @param field 67 | * The field to add to the group. 68 | */ 69 | public void addFieldEditor(FieldEditor field) { 70 | fields.add(field); 71 | } 72 | 73 | @Override 74 | protected void adjustForNumColumns(int numColumns) { 75 | // is something really needed here? 76 | } 77 | 78 | @Override 79 | protected void doFillIntoGrid(Composite parent, int numColumns) { 80 | group.setLayout(new GridLayout()); 81 | group.getParent().layout(); 82 | group.getParent().redraw(); 83 | 84 | for (FieldEditor field : fields) { 85 | field.fillIntoGrid(getFieldEditorParent(), numColumns); 86 | } 87 | } 88 | 89 | @Override 90 | protected void doLoad() { 91 | for (FieldEditor field : fields) { 92 | field.load(); 93 | } 94 | } 95 | 96 | @Override 97 | protected void doLoadDefault() { 98 | for (FieldEditor field : fields) { 99 | field.loadDefault(); 100 | } 101 | } 102 | 103 | @Override 104 | protected void doStore() { 105 | for (FieldEditor field : fields) { 106 | field.store(); 107 | } 108 | } 109 | 110 | @Override 111 | public void store() { 112 | if (getPreferenceStore() == null) { 113 | return; 114 | } 115 | if (presentsDefaultValue()) { 116 | for (FieldEditor field : fields) { 117 | getPreferenceStore().setToDefault(field.getPreferenceName()); 118 | } 119 | } 120 | else { 121 | doStore(); 122 | } 123 | } 124 | 125 | @Override 126 | public int getNumberOfControls() { 127 | return 1; 128 | } 129 | 130 | @Override 131 | public void setPreferenceStore(IPreferenceStore store) { 132 | super.setPreferenceStore(store); 133 | for (FieldEditor field : fields) { 134 | field.setPreferenceStore(store); 135 | } 136 | } 137 | 138 | @Override 139 | public void setEnabled(boolean enabled, Composite parent) { 140 | super.setEnabled(enabled, parent); 141 | for (FieldEditor field : fields) { 142 | field.setEnabled(enabled, parent); 143 | } 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/src/fr/kazejiyu/discord/rpc/integration/ui/preferences/internal/LambdaLabelProvider.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.ui.preferences.internal; 11 | 12 | import java.util.function.Function; 13 | 14 | import org.eclipse.jface.viewers.ColumnLabelProvider; 15 | 16 | /** 17 | * Provides a column label based on a given lambda. 18 | * 19 | * @author Emmanuel Chebbi 20 | * 21 | * @param The type of the objects contained by the column 22 | */ 23 | public class LambdaLabelProvider extends ColumnLabelProvider { 24 | 25 | private final Function labelProvider; 26 | 27 | /** 28 | * Creates a new label provider. 29 | * 30 | * @param labelProvider 31 | * The lambda actually used to compute elements' label. 32 | */ 33 | public LambdaLabelProvider(Function labelProvider) { 34 | super(); 35 | this.labelProvider = labelProvider; 36 | } 37 | 38 | @Override 39 | @SuppressWarnings("unchecked") 40 | public String getText(Object element) { 41 | try { 42 | return labelProvider.apply((T) element); 43 | } 44 | catch (ClassCastException e) { 45 | throw new IllegalArgumentException("cannot compute label of " + element, e); 46 | } 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/src/fr/kazejiyu/discord/rpc/integration/ui/preferences/internal/LinkFieldEditor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.ui.preferences.internal; 11 | 12 | import org.eclipse.jface.preference.FieldEditor; 13 | import org.eclipse.swt.SWT; 14 | import org.eclipse.swt.custom.StyleRange; 15 | import org.eclipse.swt.custom.StyledText; 16 | import org.eclipse.swt.layout.GridData; 17 | import org.eclipse.swt.program.Program; 18 | import org.eclipse.swt.widgets.Composite; 19 | 20 | /** 21 | * A field editor showing an external link as a clickable text. 22 | *

23 | * Clicking on the text opens the link in the default external web browser. 24 | */ 25 | public class LinkFieldEditor extends FieldEditor { 26 | 27 | /** 28 | * The text displayed in the Preferences page. 29 | */ 30 | private final String text; 31 | 32 | /** 33 | * The link to open in the external browser. 34 | */ 35 | private final String link; 36 | 37 | /** 38 | * The index of the first text character corresponding to the link. 39 | */ 40 | private final int linkStartIndex; 41 | 42 | /** 43 | * The length of the link from linkStartIndex. 44 | */ 45 | private final int linkLength; 46 | 47 | /** 48 | * Creates a new clickable text that opens a link on mouse click. 49 | * 50 | * @param text 51 | * The text to show in the Preferences page. 52 | * @param link 53 | * The link to open in the external web browser on mouse click. 54 | * @param parent 55 | * The parent of the link. 56 | */ 57 | public LinkFieldEditor(String text, String link, Composite parent) { 58 | this(text, link, 0, text.length(), parent); 59 | } 60 | 61 | /** 62 | * Creates a new clickable text that opens a link on mouse click. 63 | * 64 | * @param text 65 | * The text to show in the Preferences page. 66 | * @param link 67 | * The link to open in the external web browser on mouse click. 68 | * @param linkStartIndex 69 | * The index of the first text character corresponding to the link. 70 | * @param linkLength 71 | * The length of the link starting from linkStartIndex. 72 | * @param parent 73 | * The parent of the link. 74 | */ 75 | public LinkFieldEditor(String text, String link, int linkStartIndex, int linkLength, Composite parent) { 76 | super(); 77 | this.text = text; 78 | this.link = link; 79 | this.linkStartIndex = linkStartIndex; 80 | this.linkLength = linkLength; 81 | createControl(parent); 82 | } 83 | 84 | @Override 85 | protected void doFillIntoGrid(Composite parent, int numColumns) { 86 | StyledText styledText = new StyledText(parent, SWT.NONE); 87 | styledText.setText(" " + text); 88 | styledText.setBackground(parent.getBackground()); 89 | styledText.setMarginColor(parent.getBackground()); 90 | 91 | GridData gd = new GridData(); 92 | gd.horizontalSpan = numColumns; 93 | styledText.setLayoutData(gd); 94 | styledText.setLeftMargin(0); 95 | 96 | StyleRange style = new StyleRange(); 97 | style.underline = true; 98 | style.underlineStyle = SWT.UNDERLINE_LINK; 99 | style.start = this.linkStartIndex; 100 | style.length = this.linkLength; 101 | styledText.setStyleRange(style); 102 | 103 | styledText.addListener(SWT.MouseDown, event -> { 104 | int clickOffset = styledText.getCaretOffset(); 105 | if (this.linkStartIndex <= clickOffset && clickOffset < this.linkStartIndex + this.linkLength) { 106 | // Open the documentation with external browser 107 | Program.launch(link); 108 | } 109 | }); 110 | styledText.setBottomMargin(5); 111 | styledText.setToolTipText(link); 112 | } 113 | 114 | @Override 115 | protected void adjustForNumColumns(int numColumns) { 116 | // is something really needed here? 117 | } 118 | 119 | @Override 120 | protected void doLoad() { 121 | // nothing to load 122 | } 123 | 124 | @Override 125 | protected void doLoadDefault() { 126 | // nothing to load 127 | } 128 | 129 | @Override 130 | protected void doStore() { 131 | // nothing to store 132 | } 133 | 134 | @Override 135 | public int getNumberOfControls() { 136 | return 1; 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration.ui.preferences/src/fr/kazejiyu/discord/rpc/integration/ui/preferences/properties/AbstractPropertyPage.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.ui.preferences.properties; 11 | 12 | import org.eclipse.core.resources.IProject; 13 | import org.eclipse.core.runtime.IAdaptable; 14 | import org.eclipse.swt.SWT; 15 | import org.eclipse.swt.layout.GridData; 16 | import org.eclipse.swt.widgets.Composite; 17 | import org.eclipse.swt.widgets.Label; 18 | import org.eclipse.ui.dialogs.PropertyPage; 19 | 20 | /** 21 | * Abstract PropertyPage providing new services to sub-classes. 22 | * 23 | * @author Emmanuel CHEBBI 24 | */ 25 | abstract class AbstractPropertyPage extends PropertyPage { 26 | 27 | /** The project which properties are shown by this page. */ 28 | protected IProject project; 29 | 30 | /** 31 | * Sets {@link #project} to the value of the current project. 32 | * 33 | * @return {@code true} if the current project has been resolved successfully, 34 | * {@code false} otherwise. 35 | */ 36 | protected boolean resolveCurrentProject() { 37 | final IAdaptable adaptable = getElement(); 38 | 39 | if (adaptable == null) { 40 | return false; 41 | } 42 | project = adaptable.getAdapter(IProject.class); 43 | return project != null; 44 | } 45 | 46 | protected static void addSeparator(Composite parent) { 47 | Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); 48 | GridData gridData = new GridData(); 49 | gridData.horizontalAlignment = GridData.FILL; 50 | gridData.grabExcessHorizontalSpace = true; 51 | separator.setLayoutData(gridData); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fr.kazejiyu.discord.rpc.integration 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | net.sf.eclipsecs.core.CheckstyleBuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.pde.PluginNature 31 | org.eclipse.jdt.core.javanature 32 | net.sf.eclipsecs.core.CheckstyleNature 33 | 34 | 35 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Discord Rich Presence for Eclipse IDE 4 | Bundle-SymbolicName: fr.kazejiyu.discord.rpc.integration;singleton:=true 5 | Bundle-Version: 1.2.2 6 | Bundle-Activator: fr.kazejiyu.discord.rpc.integration.Activator 7 | Require-Bundle: org.eclipse.ui;bundle-version="[3.107.0,4.0.0)", 8 | org.eclipse.core.runtime;bundle-version="[3.11.0,4.0.0)", 9 | org.eclipse.ui.editors;bundle-version="[3.9.0,4.0.0)", 10 | org.eclipse.ui.ide;bundle-version="[3.11.0,4.0.0)", 11 | org.eclipse.core.resources;bundle-version="[3.10.0,4.0.0)", 12 | java-discord-rpc;bundle-version="[2.0.0,3.0.0)" 13 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 14 | Export-Package: fr.kazejiyu.discord.rpc.integration;x-friends:="fr.kazejiyu.discord.rpc.integration.ui.preferences", 15 | fr.kazejiyu.discord.rpc.integration.core, 16 | fr.kazejiyu.discord.rpc.integration.extensions, 17 | fr.kazejiyu.discord.rpc.integration.languages, 18 | fr.kazejiyu.discord.rpc.integration.settings 19 | Automatic-Module-Name: fr.kazejiyu.discord.rpc.integration 20 | Bundle-Vendor: Emmanuel CHEBBI 21 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = META-INF/,\ 4 | .,\ 5 | plugin.xml -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 9 | 10 | 11 | 13 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/schema/editor_input_adapter.exsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | For providing an adapter extracting information from a specific editor in order to show it in Discord. 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 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | The adapter that extracts Rich Presence from a specific IEditorInput. 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | [Enter the first release in which this extension point appears.] 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | [Enter extension point usage example here.] 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | [Enter API information here.] 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | [Enter information about supplied implementation of this extension point.] 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/Plugin.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration; 11 | 12 | import org.eclipse.core.runtime.IStatus; 13 | import org.eclipse.core.runtime.Status; 14 | import org.eclipse.ui.statushandlers.StatusManager; 15 | 16 | /** 17 | *

Represents Discord Rich Presence for Eclipse IDE plug-in.

18 | * 19 | *

Provides utility methods to deal with Eclipse environment.

20 | * 21 | * @author Emmanuel CHEBBI 22 | */ 23 | public final class Plugin { 24 | 25 | public static final String ID = Activator.PLUGIN_ID; 26 | 27 | /** ID of the 'editor_input_adapter' extension point. */ 28 | public static final String EDITOR_INPUT_ADAPTER_EXTENSION_ID = "fr.kazejiyu.discord.rpc.integration.editor_input_adapter"; 29 | 30 | private Plugin() { 31 | // does not make sense to instantiate it 32 | } 33 | 34 | /** 35 | * Logs a specified message in Eclipse Error Log view. 36 | * 37 | * @param message 38 | * The message to log. 39 | */ 40 | public static void log(String message) { 41 | IStatus status = new Status(IStatus.INFO, ID, message); 42 | StatusManager.getManager().handle(status); 43 | } 44 | 45 | /** 46 | *

Logs a specific Exception in Eclipse Error Log view.

47 | * 48 | *

The exception's message is used as log's status message.

49 | * 50 | * @param e 51 | * The exception to log. Must not be {@code null}. 52 | * 53 | * @see #logException(String, Exception) 54 | * @see #logExceptionWithDialog(String, Exception) 55 | */ 56 | public static void logException(Exception e) { 57 | logException(e.getMessage(), e); 58 | } 59 | 60 | /** 61 | * Logs a specific Exception in Eclipse Error Log view. 62 | * 63 | * @param message 64 | * The log message. 65 | * @param e 66 | * The exception to log. Must not be {@code null}. 67 | * 68 | * @see #logException(String) 69 | * @see #logExceptionWithDialog(String, Exception) 70 | */ 71 | public static void logException(String message, Exception e) { 72 | IStatus status = new Status(IStatus.ERROR, ID, message, e); 73 | StatusManager.getManager().handle(status); 74 | } 75 | 76 | /** 77 | * Logs a specific Exception in Eclipse Error Log view and opens a non-modal error dialog. 78 | * 79 | * @param message 80 | * The log message. 81 | * @param e 82 | * The exception to log. Must not be {@code null}. 83 | * 84 | * @see #logException(Exception) 85 | * @see #logException(String, Exception) 86 | */ 87 | public static void logExceptionWithDialog(String message, Exception e) { 88 | IStatus status = new Status(IStatus.ERROR, ID, message, e); 89 | StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/core/DiscordRpcLifecycle.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.core; 11 | 12 | import java.util.Optional; 13 | 14 | /** 15 | * Defines an object aimed to manage plug-in's Rich Presence by communicating with Discord. 16 | */ 17 | public interface DiscordRpcLifecycle extends AutoCloseable { 18 | 19 | /** 20 | * Initializes the connection to Discord session. 21 | * 22 | * @param applicationId 23 | * The ID of the Discord application to connect. 24 | * 25 | * @see #shutdown() 26 | */ 27 | void initialize(String applicationId); 28 | 29 | /** 30 | * Returns whether the instance is currently connected to a Discord client. 31 | * @return {@code true} if the instance is connected to a Discord client, 32 | * {@code false} otherwise 33 | */ 34 | boolean isConnected(); 35 | 36 | /** 37 | * Returns whether the proxy is connected to the given Discord application. 38 | * 39 | * @param applicationId 40 | * The ID of the Discord application to which the proxy may be connected. 41 | * 42 | * @return true if the proxy is connected to the given Discord application, false otherwise 43 | */ 44 | default boolean isConnectedTo(String applicationId) { 45 | return this.discordApplicationId() 46 | .map(id -> id.equals(applicationId)) 47 | .orElse(false); 48 | } 49 | 50 | /** 51 | * Returns the ID of the Discord application to which the object is currently connected. 52 | * @return the ID of the Discord application if a connection has been made, nothing otherwise 53 | */ 54 | Optional discordApplicationId(); 55 | 56 | /** 57 | *

Shows given presence on Discord.

58 | * 59 | *

Has no effect if {@link #isConnected()} is false.

60 | * 61 | * @param rp 62 | * Contains the elements to show on Discord. 63 | * Must not be {@code null}. 64 | * 65 | * @see #showNothing() 66 | */ 67 | void show(RichPresence rp); 68 | 69 | /** 70 | * Clear Discord's rich presence so that only "Playing Eclipse IDE" is shown. 71 | * 72 | * @see #show(RichPresence) 73 | */ 74 | void showNothing(); 75 | 76 | /** 77 | *

Shutdowns the connection to Discord session.

78 | * 79 | *

If this method is called while the connection has already being closed, it has no effect.

80 | * 81 | * @see #initialize(String) 82 | */ 83 | void shutdown(); 84 | 85 | @Override 86 | default void close() { 87 | shutdown(); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/core/DiscordRpcProxy.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.core; 11 | 12 | import java.util.Optional; 13 | 14 | import club.minnced.discord.rpc.DiscordEventHandlers; 15 | import club.minnced.discord.rpc.DiscordRPC; 16 | import club.minnced.discord.rpc.DiscordRichPresence; 17 | import fr.kazejiyu.discord.rpc.integration.Plugin; 18 | import fr.kazejiyu.discord.rpc.integration.languages.Language; 19 | 20 | /** 21 | * Sends {@link RichPresence}s to Discord.
22 | *
23 | * The information detailed by the presence (state, image, etc.) are then shown in Discord's UI. 24 | * 25 | * @author Emmanuel CHEBBI 26 | */ 27 | public class DiscordRpcProxy implements DiscordRpcLifecycle { 28 | 29 | /** Whether the proxy is connected to a Discord client. */ 30 | private boolean isConnected = false; 31 | 32 | /** The ID of the Discord application we're currently connected to. */ 33 | private String discordApplicationId; 34 | 35 | @Override 36 | public void initialize(String applicationId) { 37 | DiscordRPC.INSTANCE.Discord_Initialize(applicationId, createHandlers(), true, ""); 38 | 39 | // Following attributes should be set in the 'ready' handlers 40 | // but for some reason it does not work very well. 41 | // Maybe just temporal issues? May investigate if I find the time to. 42 | 43 | this.isConnected = true; 44 | this.discordApplicationId = applicationId; 45 | } 46 | 47 | /** Returns the handlers handling Discord events. */ 48 | private DiscordEventHandlers createHandlers() { 49 | DiscordEventHandlers handlers = new DiscordEventHandlers(); 50 | handlers.ready = user -> isConnected = true; 51 | handlers.errored = (status, message) -> Plugin.log(message); 52 | handlers.disconnected = (status, message) -> isConnected = false; 53 | 54 | return handlers; 55 | } 56 | 57 | @Override 58 | public boolean isConnected() { 59 | return this.isConnected; 60 | } 61 | 62 | @Override 63 | public Optional discordApplicationId() { 64 | if (! isConnected()) { 65 | return Optional.empty(); 66 | } 67 | return Optional.of(discordApplicationId); 68 | } 69 | 70 | @Override 71 | public void show(RichPresence rp) { 72 | if (isConnected) { 73 | DiscordRichPresence presence = new DiscordRichPresence(); 74 | 75 | presence.smallImageKey = "eclipse-ide-logo"; 76 | presence.smallImageText = "Eclipse IDE"; 77 | 78 | rp.getState().ifPresent(state -> presence.state = state); 79 | rp.getDetails().ifPresent(details -> presence.details = details); 80 | rp.getStartTimestamp().ifPresent(start -> presence.startTimestamp = start); 81 | rp.getLargeImageText().ifPresent(text -> presence.largeImageText = text); 82 | rp.getLanguage().map(Language::getKey).ifPresent(key -> presence.largeImageKey = key); 83 | 84 | DiscordRPC.INSTANCE.Discord_UpdatePresence(presence); 85 | DiscordRPC.INSTANCE.Discord_RunCallbacks(); 86 | } 87 | } 88 | 89 | @Override 90 | public void showNothing() { 91 | show(new ImmutableRichPresence()); 92 | } 93 | 94 | @Override 95 | public void shutdown() { 96 | DiscordRPC.INSTANCE.Discord_Shutdown(); 97 | this.isConnected = false; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/core/PreferredRichPresence.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.core; 11 | 12 | import static java.util.Objects.requireNonNull; 13 | 14 | import java.util.Optional; 15 | 16 | import org.eclipse.core.resources.IProject; 17 | 18 | import fr.kazejiyu.discord.rpc.integration.languages.Language; 19 | import fr.kazejiyu.discord.rpc.integration.settings.UserPreferences; 20 | 21 | /** 22 | * A {@link RichPresence} that cares about {@link UserPreferences}.
23 | *
24 | * An instance of this class decorates another {@link RichPresence} and enhances it 25 | * in order to in order to follow user's preferences: 26 | *
    27 | *
  • hide the {@link Language}, 28 | *
  • select the right start timestamp. 29 | *
30 | */ 31 | public final class PreferredRichPresence implements RichPresence { 32 | 33 | /** Used to determine which information the user wants to hide. */ 34 | private final UserPreferences preferences; 35 | 36 | /** The original, decorated presence. */ 37 | public final RichPresence presence; 38 | 39 | /** Provides access to the different timestamps. */ 40 | private final SelectionTimes times; 41 | 42 | /** 43 | * Creates a new {@link RichPresence} caring about user's preferences. 44 | * 45 | * @param prefs 46 | * The preferences to follow. Must not be null. 47 | * @param presence 48 | * The original presence to decorate. Must not be null. 49 | * @param times 50 | * The available timestamps. Must not be null. 51 | */ 52 | public PreferredRichPresence(UserPreferences prefs, RichPresence presence, SelectionTimes times) { 53 | this.preferences = requireNonNull(prefs, "The preferences must not be null"); 54 | this.presence = requireNonNull(presence, "The decorated presence must not be null"); 55 | this.times = requireNonNull(times, "The times must not be null"); 56 | } 57 | 58 | @Override 59 | public Optional getLanguage() { 60 | if (! preferences.showsLanguageIcon()) { 61 | return Optional.empty(); 62 | } 63 | return presence.getLanguage(); 64 | } 65 | 66 | @Override 67 | public Optional getStartTimestamp() { 68 | if (! preferences.showsElapsedTime()) { 69 | return Optional.empty(); 70 | } 71 | if (preferences.resetsElapsedTimeOnNewFile()) { 72 | return Optional.of(times.onSelection()); 73 | } 74 | if (preferences.resetsElapsedTimeOnNewProject()) { 75 | return Optional.of(times.onNewProject()); 76 | } 77 | // last possible case: the time starts on startup 78 | return Optional.of(times.onStartup()); 79 | } 80 | 81 | @Override 82 | public Optional getDetails() { 83 | return presence.getDetails(); 84 | } 85 | 86 | @Override 87 | public Optional getState() { 88 | return presence.getState(); 89 | } 90 | 91 | @Override 92 | public Optional getLargeImageText() { 93 | return presence.getLargeImageText(); 94 | } 95 | 96 | @Override 97 | public Optional getProject() { 98 | return presence.getProject(); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/core/RichPresence.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.core; 11 | 12 | import java.util.Optional; 13 | 14 | import org.eclipse.core.resources.IProject; 15 | 16 | import fr.kazejiyu.discord.rpc.integration.languages.Language; 17 | 18 | /** 19 | * The information about current selection to show in Discord. 20 | */ 21 | public interface RichPresence { 22 | 23 | /** 24 | * Returns the details to show on Discord, if any. 25 | * @return the details to show on Discord, if any 26 | */ 27 | Optional getDetails(); 28 | 29 | /** 30 | * Returns the state to show on Discord, if any. 31 | * @return the state to show on Discord, if any 32 | */ 33 | Optional getState(); 34 | 35 | /** 36 | * Returns the start timestamp, if any. 37 | * @return the start timestamp, if any 38 | */ 39 | Optional getStartTimestamp(); 40 | 41 | /** 42 | * Returns the language of the active file, if known. 43 | * @return the language of the active file, if known 44 | */ 45 | Optional getLanguage(); 46 | 47 | /** 48 | * Returns the text to show when hovering the large icon, if any. 49 | * @return the text to show when hovering the large icon, if any 50 | */ 51 | Optional getLargeImageText(); 52 | 53 | /** 54 | * Returns the Eclipse project owning the resource related to this presence, if any. 55 | * @return the Eclipse project owning the resource related to this presence, if any 56 | */ 57 | Optional getProject(); 58 | } 59 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/core/SelectionTimes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.core; 11 | 12 | import java.util.Objects; 13 | 14 | import org.eclipse.core.resources.IProject; 15 | 16 | /** 17 | * The times at which selection changed. 18 | * 19 | * TODO Rename as "ElapsedTimes" 20 | */ 21 | public class SelectionTimes { 22 | 23 | private final long timeOnStartup; 24 | 25 | private long timeOnNewProject; 26 | 27 | private long timeOnNewSelection; 28 | 29 | private IProject lastSelectedProject = null; 30 | 31 | /** 32 | * Creates a new object that keep tracks of selection times. 33 | */ 34 | public SelectionTimes() { 35 | long currentTime = System.currentTimeMillis() / 1000; 36 | 37 | this.timeOnStartup = currentTime; 38 | this.timeOnNewProject = currentTime; 39 | this.timeOnNewSelection = currentTime; 40 | } 41 | 42 | /** 43 | * Sets the time on new selection to now, and change the time on new project 44 | * if the given project is not the last selected project. 45 | * 46 | * @param project 47 | * The project from which a resource has been selected. 48 | * 49 | * @return the current instance to enable method chaining 50 | */ 51 | public SelectionTimes updateWithNewSelectionIn(IProject project) { 52 | this.timeOnNewProject = isANewProject(project) ? System.currentTimeMillis() / 1000 : timeOnNewProject; 53 | this.timeOnNewSelection = System.currentTimeMillis() / 1000; 54 | this.lastSelectedProject = project; 55 | 56 | return this; 57 | } 58 | 59 | private boolean isANewProject(IProject project) { 60 | return ! Objects.equals(project, lastSelectedProject); 61 | } 62 | 63 | /** 64 | * Returns the timestamp corresponding to Eclipse IDE startup. 65 | * @return the timestamp on Eclipse startup 66 | */ 67 | public long onStartup() { 68 | return timeOnStartup; 69 | } 70 | 71 | /** 72 | * Returns the timestamp corresponding to the first time a resource 73 | * has been selected on current project. 74 | * 75 | * @return the timestamp on the current project 76 | */ 77 | public long onNewProject() { 78 | return timeOnNewProject; 79 | } 80 | 81 | /** 82 | * Returns the timestamp corresponding to the last time current resource has been selected. 83 | * @return the timestamp on the current resource 84 | */ 85 | public long onSelection() { 86 | return timeOnNewSelection; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/core/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | /** 11 | * Classes aimed to deal with Discord RPC's API.
12 | * 13 | * @author Emmanuel CHEBBI 14 | */ 15 | package fr.kazejiyu.discord.rpc.integration.core; 16 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/extensions/EditorInputToRichPresenceAdapter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.extensions; 11 | 12 | import java.util.Optional; 13 | 14 | import org.eclipse.ui.IEditorInput; 15 | import org.eclipse.ui.part.FileEditorInput; 16 | 17 | import fr.kazejiyu.discord.rpc.integration.core.RichPresence; 18 | import fr.kazejiyu.discord.rpc.integration.settings.GlobalPreferences; 19 | 20 | /** 21 | * Extracts {@link RichPresence} from an {@link IEditorInput}. 22 | *

23 | * This interface should be implemented by clients who aim to define 24 | * the information shown in Discord for their own editor. 25 | * 26 | * @author Emmanuel CHEBBI 27 | */ 28 | public interface EditorInputToRichPresenceAdapter extends Comparable { 29 | 30 | /** 31 | * Helps to choose an adapter over another when several ones 32 | * are registered for the same {@code IEditorInput}. 33 | *

34 | * The higher the priority, the more the adapter will be favored. 35 | *

36 | * For instance, given two adapters registering themselves for inputs of type 37 | * {@link FileEditorInput} and which priorities are 0 and 1, then the adapter 38 | * of priority 1 will be chosen to handle the input. 39 | *

40 | * Built-in adapters have a priority of 0. Hence, giving a higher priority 41 | * ensures that the adapter will be preferred over default ones. This allows 42 | * to dynamically override other adapters if needed. 43 | *

44 | * It is advised to only choose tens, such as 10 or 20, instead of digits 45 | * so that it is easier to add new adapters later if needed. 46 | * 47 | * @return the priority associated with this adapter. 48 | */ 49 | int getPriority(); 50 | 51 | /** 52 | * Returns the class of the input expected as an argument of {@link #createRichPresence(GlobalPreferences, IEditorInput)}. 53 | * @return the class of the input expected as an argument of {@link #createRichPresence(GlobalPreferences, IEditorInput)} 54 | */ 55 | Class getExpectedEditorInputClass(); 56 | 57 | /** 58 | * Creates the Rich Presence information to send to Discord. 59 | *

60 | * Important: this method may be called several times in a row with the same editor input. 61 | * 62 | * @param preferences 63 | * User's preferences regarding the information to show in Discord. 64 | * Must not be {@code null}. 65 | * @param input 66 | * The input of the active editor. 67 | * Must satisfy {@code getExpectedEditorInputClass().isInstance(input) == true}. 68 | * 69 | * @return the information to show in Discord if the input can be handled 70 | */ 71 | Optional createRichPresence(GlobalPreferences preferences, IEditorInput input); 72 | 73 | /** 74 | * Compares this with an other {@code EditorInputRichPresence} based on their priority. 75 | * 76 | * @return a negative integer, zero, or a positive integer as this object's priority is less than, 77 | * equal to, or greater than the specified object's priority. 78 | */ 79 | @Override 80 | default int compareTo(EditorInputToRichPresenceAdapter rhs) { 81 | return Integer.compare(this.getPriority(), rhs.getPriority()); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/extensions/EditorRichPresenceFromInput.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.extensions; 11 | 12 | import java.util.Optional; 13 | 14 | import org.eclipse.ui.IEditorInput; 15 | 16 | import fr.kazejiyu.discord.rpc.integration.core.ImmutableRichPresence; 17 | 18 | /** 19 | * Turns an {@link IEditorInput} into an {@link EditorInputToRichPresenceAdapter}. 20 | * 21 | * @author Emmanuel CHEBBI 22 | */ 23 | @FunctionalInterface 24 | public interface EditorRichPresenceFromInput { 25 | 26 | /** 27 | *

Returns an adapter able to turn {@code input} into a {@link ImmutableRichPresence} 28 | * instance.

29 | * 30 | *

The adapter is one of the adapters registered to the 31 | * {@value #EDITOR_INPUT_ADAPTER_EXTENSION_ID} extension point.

32 | * 33 | * @param input 34 | * The input to turn into a {@code RichPresence} instance. 35 | * Must not be {@code null}. 36 | * 37 | * @return an adapter able to handle {@code input}, if any. 38 | */ 39 | Optional findAdapterFor(IEditorInput input); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/extensions/internal/UnknownInputRichPresence.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.extensions.internal; 11 | 12 | import java.util.Optional; 13 | 14 | import org.eclipse.ui.IEditorInput; 15 | 16 | import fr.kazejiyu.discord.rpc.integration.core.ImmutableRichPresence; 17 | import fr.kazejiyu.discord.rpc.integration.core.RichPresence; 18 | import fr.kazejiyu.discord.rpc.integration.extensions.EditorInputToRichPresenceAdapter; 19 | import fr.kazejiyu.discord.rpc.integration.settings.GlobalPreferences; 20 | 21 | /** 22 | * Used when no valid adapter can be found for a given {@link IEditorInput}.
23 | *
24 | * Show no information in Discord. 25 | * 26 | * @author Emmanuel CHEBBI 27 | */ 28 | public class UnknownInputRichPresence implements EditorInputToRichPresenceAdapter { 29 | 30 | @Override 31 | public int getPriority() { 32 | return Integer.MIN_VALUE; 33 | } 34 | 35 | @Override 36 | public Class getExpectedEditorInputClass() { 37 | return IEditorInput.class; 38 | } 39 | 40 | @Override 41 | public Optional createRichPresence(GlobalPreferences preferences, IEditorInput input) { 42 | return Optional.of(new ImmutableRichPresence()); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/extensions/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | /** 11 | * Default implementations for {@link fr.kazejiyu.discord.rpc.integration.core.ImmutableRichPresence RichPresence} 12 | * interface. 13 | * 14 | * @author Emmanuel CHEBBI 15 | */ 16 | package fr.kazejiyu.discord.rpc.integration.extensions.internal; 17 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/extensions/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | /** 11 | * Provides interfaces for extensions points. 12 | * 13 | * @author Emmanuel CHEBBI 14 | */ 15 | package fr.kazejiyu.discord.rpc.integration.extensions; 16 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/files/AddListenerOnWindowOpened.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.files; 11 | 12 | import static java.util.Objects.requireNonNull; 13 | 14 | import org.eclipse.ui.IPartListener2; 15 | import org.eclipse.ui.ISelectionListener; 16 | import org.eclipse.ui.IWindowListener; 17 | import org.eclipse.ui.IWorkbenchPage; 18 | import org.eclipse.ui.IWorkbenchWindow; 19 | 20 | /** 21 | * Adds a given {@link ISelectionListener} to each window that opens. 22 | * 23 | * @param The exact type of the listener to register. 24 | * 25 | * @author Emmanuel CHEBBI 26 | */ 27 | public class AddListenerOnWindowOpened implements IWindowListener { 28 | 29 | /** The listener to add to each window that opens. */ 30 | private final T listener; 31 | 32 | /** 33 | * Creates a object charged of adding a given listener to each window that opens. 34 | * 35 | * @param listener 36 | * The listener that should be added to each window that opens. 37 | * Must not be {@code null}. 38 | */ 39 | public AddListenerOnWindowOpened(T listener) { 40 | this.listener = requireNonNull(listener, "The listener must not be null"); 41 | } 42 | 43 | @Override 44 | public void windowOpened(IWorkbenchWindow window) { 45 | addSelectionListener(window); 46 | } 47 | 48 | @Override 49 | public void windowClosed(IWorkbenchWindow window) { 50 | removeSelectionListener(window); 51 | } 52 | 53 | /** Adds {@code listener} as an ISelectionListener of {@code window}. */ 54 | private void addSelectionListener(IWorkbenchWindow window) { 55 | if (window != null) { 56 | window.getSelectionService().addSelectionListener(listener); 57 | 58 | for (IWorkbenchPage page : window.getPages()) { 59 | page.addPartListener(listener); 60 | } 61 | } 62 | } 63 | 64 | /** Removes {@code listener} from {@code window}'s ISelectionListeners. */ 65 | private void removeSelectionListener(IWorkbenchWindow window) { 66 | if (window != null) { 67 | window.getSelectionService().removeSelectionListener(listener); 68 | 69 | for (IWorkbenchPage page : window.getPages()) { 70 | page.removePartListener(listener); 71 | } 72 | } 73 | } 74 | 75 | @Override 76 | public void windowActivated(IWorkbenchWindow window) { 77 | // irrelevant event 78 | } 79 | 80 | @Override 81 | public void windowDeactivated(IWorkbenchWindow window) { 82 | // irrelevant event 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/files/EditionContext.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.files; 11 | 12 | import java.util.Optional; 13 | 14 | import org.eclipse.ui.IEditorPart; 15 | 16 | import fr.kazejiyu.discord.rpc.integration.core.SelectionTimes; 17 | 18 | /** 19 | * Indicates what the user is working on. 20 | * 21 | * @author Emmanuel CHEBBI 22 | */ 23 | public class EditionContext { 24 | 25 | private IEditorPart editor; 26 | 27 | /** Provides access to the different timestamps. */ 28 | private SelectionTimes times = new SelectionTimes(); 29 | 30 | /** 31 | * Returns the last IEditorPart selected by the user and that is still open. 32 | * @return the last IEditorPart selected by the user, or nothing if there is none 33 | */ 34 | public Optional lastSelectedEditor() { 35 | return Optional.ofNullable(editor); 36 | } 37 | 38 | /** 39 | * Sets the last IEditorPart selected by the user. 40 | *

41 | * Accepts {@code null} for indicating that no editor is activated. 42 | * 43 | * @param editor 44 | * The last editor selected by the user or null if there is none 45 | */ 46 | public void setLastSelectedEditor(IEditorPart editor) { 47 | this.editor = editor; 48 | } 49 | 50 | /** 51 | * Returns the elapsed times. 52 | * @return the elapsed times 53 | */ 54 | public SelectionTimes getElapsedTimes() { 55 | return times; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/files/EditorToRichPresenceAdapter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.files; 11 | 12 | import static java.util.Objects.requireNonNull; 13 | 14 | import java.util.Optional; 15 | import java.util.function.Function; 16 | import java.util.function.Supplier; 17 | 18 | import org.eclipse.ui.IEditorPart; 19 | 20 | import fr.kazejiyu.discord.rpc.integration.core.PreferredRichPresence; 21 | import fr.kazejiyu.discord.rpc.integration.core.RichPresence; 22 | import fr.kazejiyu.discord.rpc.integration.core.SelectionTimes; 23 | import fr.kazejiyu.discord.rpc.integration.extensions.EditorInputToRichPresenceAdapter; 24 | import fr.kazejiyu.discord.rpc.integration.extensions.EditorRichPresenceFromInput; 25 | import fr.kazejiyu.discord.rpc.integration.extensions.internal.UnknownInputRichPresence; 26 | import fr.kazejiyu.discord.rpc.integration.settings.GlobalPreferences; 27 | 28 | /** 29 | * An adapter able to turn {@link EditionContext} instances into {@link RichPresence} ones. 30 | * 31 | * @author Emmanuel CHEBBI 32 | */ 33 | public class EditorToRichPresenceAdapter implements Function> { 34 | 35 | /** Used to to create a RichPresence from the selected editor. */ 36 | private final EditorRichPresenceFromInput adapters; 37 | 38 | /** User's preferences regarding the information to show in Discord. */ 39 | private final GlobalPreferences preferences; 40 | 41 | /** 42 | * Creates a new adapter able to turn EditionContext instances into RichPresence ones. 43 | * 44 | * @param preferences 45 | * User's preferences regarding the information to show in Discord. 46 | * Must not be {@code null}. 47 | * @param adapters 48 | * Will be notified with a new {@link RichPresence} instance each time 49 | * the active editor changes. Must not be null. 50 | */ 51 | public EditorToRichPresenceAdapter(GlobalPreferences preferences, EditorRichPresenceFromInput adapters) { 52 | this.adapters = requireNonNull(adapters, "adapters"); 53 | this.preferences = requireNonNull(preferences, "preferences"); 54 | } 55 | 56 | @Override 57 | public Optional apply(EditionContext context) { 58 | return context.lastSelectedEditor() 59 | .flatMap(this::createRichPresenceFrom) 60 | .map(presence -> tailorToPreferences(presence, context.getElapsedTimes())); 61 | } 62 | 63 | private Optional createRichPresenceFrom(IEditorPart editor) { 64 | return adapters.findAdapterFor(editor.getEditorInput()) 65 | .orElseGet(defaultAdapter()) 66 | .createRichPresence(preferences, editor.getEditorInput()); 67 | } 68 | 69 | /** Returns a built-in adapter that sends nothing to Discord. */ 70 | private static Supplier defaultAdapter() { 71 | return UnknownInputRichPresence::new; 72 | } 73 | 74 | /** Returns a new RPC equivalent to the given one but which attributes follow user's presences. */ 75 | private RichPresence tailorToPreferences(RichPresence presence, SelectionTimes times) { 76 | return new PreferredRichPresence( 77 | preferences.getApplicablePreferencesFor(presence.getProject().orElse(null)), 78 | presence, 79 | times 80 | ); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/files/OnPostShutdown.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.files; 11 | 12 | import static java.util.Objects.requireNonNull; 13 | 14 | import java.util.function.Consumer; 15 | 16 | import org.eclipse.ui.IWorkbench; 17 | import org.eclipse.ui.IWorkbenchListener; 18 | 19 | /** 20 | * An {@link IWorkbenchListener} which behavior on {@link #postShutdown(IWorkbench) postShutdown} 21 | * event can be parameterized. 22 | */ 23 | public class OnPostShutdown implements IWorkbenchListener { 24 | 25 | /** Called on {@link #postShutdown(IWorkbench)}. */ 26 | private final Consumer postShutdownCallback; 27 | 28 | /** 29 | * Creates a new listener. 30 | * 31 | * @param postShutdownCallback 32 | * The callback to execute when the workbench is closed. 33 | */ 34 | public OnPostShutdown(Consumer postShutdownCallback) { 35 | this.postShutdownCallback = requireNonNull(postShutdownCallback, "The callback must not be null"); 36 | } 37 | 38 | @Override 39 | public boolean preShutdown(IWorkbench workbench, boolean forced) { 40 | return true; 41 | } 42 | 43 | @Override 44 | public void postShutdown(IWorkbench workbench) { 45 | postShutdownCallback.accept(workbench); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/files/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | /** 11 | * Classes used to listen for Eclipse's current selection. 12 | *

13 | * Each time a new editor is activated by the user, Discord is notified and updates its overlay accordingly. 14 | * 15 | * @author Emmanuel CHEBBI 16 | */ 17 | package fr.kazejiyu.discord.rpc.integration.files; 18 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/languages/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | /** 11 | * Defines the languages handled by the plug-in. 12 | */ 13 | package fr.kazejiyu.discord.rpc.integration.languages; 14 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/settings/DiscordIntegrationPreferencesInitializer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.settings; 11 | 12 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.CUSTOM_DISCORD_DETAILS_WORDING; 13 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.CUSTOM_DISCORD_STATE_WORDING; 14 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.RESET_ELAPSED_TIME; 15 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.RESET_ELAPSED_TIME_ON_NEW_PROJECT; 16 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.SHOW_ELAPSED_TIME; 17 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.SHOW_FILE_NAME; 18 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.SHOW_LANGUAGE_ICON; 19 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.SHOW_PROJECT_NAME; 20 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.SHOW_RICH_PRESENCE; 21 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.USE_CUSTOM_APP; 22 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.USE_CUSTOM_WORDING; 23 | 24 | import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; 25 | import org.eclipse.core.runtime.preferences.InstanceScope; 26 | import org.eclipse.jface.preference.IPreferenceStore; 27 | import org.eclipse.ui.preferences.ScopedPreferenceStore; 28 | 29 | import fr.kazejiyu.discord.rpc.integration.Activator; 30 | 31 | /** 32 | * Initializes the preferences for the preferences page. 33 | * 34 | * @author Emmanuel CHEBBI 35 | */ 36 | public class DiscordIntegrationPreferencesInitializer extends AbstractPreferenceInitializer { 37 | 38 | @Override 39 | public void initializeDefaultPreferences() { 40 | IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID); 41 | 42 | store.setDefault(SHOW_FILE_NAME.property(), true); 43 | store.setDefault(SHOW_PROJECT_NAME.property(), true); 44 | store.setDefault(SHOW_ELAPSED_TIME.property(), true); 45 | store.setDefault(SHOW_LANGUAGE_ICON.property(), true); 46 | store.setDefault(SHOW_RICH_PRESENCE.property(), true); 47 | store.setDefault(RESET_ELAPSED_TIME.property(), RESET_ELAPSED_TIME_ON_NEW_PROJECT.property()); 48 | 49 | store.setDefault(USE_CUSTOM_APP.property(), false); 50 | 51 | store.setDefault(USE_CUSTOM_WORDING.property(), false); 52 | store.setDefault(CUSTOM_DISCORD_DETAILS_WORDING.property(), "Editing ${file}"); 53 | store.setDefault(CUSTOM_DISCORD_STATE_WORDING.property(), "Working on ${project}"); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/settings/GlobalPreferencesListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.settings; 11 | 12 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.CUSTOM_APP_ID; 13 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.CUSTOM_DISCORD_DETAILS_WORDING; 14 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.CUSTOM_DISCORD_STATE_WORDING; 15 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.RESET_ELAPSED_TIME; 16 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.RESET_ELAPSED_TIME_ON_NEW_FILE; 17 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.RESET_ELAPSED_TIME_ON_NEW_PROJECT; 18 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.RESET_ELAPSED_TIME_ON_STARTUP; 19 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.SHOW_ELAPSED_TIME; 20 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.SHOW_FILE_NAME; 21 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.SHOW_LANGUAGE_ICON; 22 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.SHOW_PROJECT_NAME; 23 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.SHOW_RICH_PRESENCE; 24 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.USE_CUSTOM_APP; 25 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.USE_CUSTOM_WORDING; 26 | import static fr.kazejiyu.discord.rpc.integration.settings.Settings.fromProperty; 27 | import static java.lang.Boolean.parseBoolean; 28 | import static java.util.Objects.requireNonNull; 29 | 30 | import java.util.Collection; 31 | import java.util.HashMap; 32 | import java.util.Map; 33 | import java.util.function.BiConsumer; 34 | 35 | import org.eclipse.jface.util.IPropertyChangeListener; 36 | import org.eclipse.jface.util.PropertyChangeEvent; 37 | 38 | /** 39 | *

Listens for change in plug-in's global preferences.

40 | * 41 | *

Each change event is forwarded to a one or several 42 | * {@link SettingChangeListener SettingChangeListeners}.

43 | * 44 | * @author Emmanuel CHEBBI 45 | */ 46 | public class GlobalPreferencesListener implements IPropertyChangeListener { 47 | 48 | private static final BiConsumer DO_NOTHING = (evt, listener) -> {}; 49 | 50 | private final Collection listeners; 51 | 52 | private final Map> events = new HashMap<>(); 53 | 54 | /** 55 | * Creates a new instance aimed to listen for change in global preferences. 56 | * 57 | * @param listeners 58 | * Every change event in global preferences will be forwarded to them. 59 | * Must not be {@code null}. 60 | */ 61 | public GlobalPreferencesListener(Collection listeners) { 62 | this.listeners = requireNonNull(listeners, "The collection of listeners must not be null"); 63 | 64 | events.put(SHOW_FILE_NAME.property(), (event, listener) -> listener.fileNameVisibilityChanged(parseBoolean((String) event.getNewValue()))); 65 | events.put(SHOW_PROJECT_NAME.property(), (event, listener) -> listener.projectNameVisibilityChanged(parseBoolean((String) event.getNewValue()))); 66 | events.put(SHOW_ELAPSED_TIME.property(), (event, listener) -> listener.elapsedTimeVisibilityChanged(parseBoolean((String) event.getNewValue()))); 67 | events.put(SHOW_LANGUAGE_ICON.property(), (event, listener) -> listener.languageIconVisibilityChanged(parseBoolean((String) event.getNewValue()))); 68 | events.put(SHOW_RICH_PRESENCE.property(), (event, listener) -> listener.richPresenceVisibilityChanged(parseBoolean((String) event.getNewValue()))); 69 | events.put(RESET_ELAPSED_TIME.property(), (event, listener) -> listener.elapsedTimeResetMomentChanged(toMoment(event.getOldValue()), toMoment(event.getNewValue()))); 70 | events.put(USE_CUSTOM_APP.property(), (event, listener) -> listener.customDiscordApplicationVisibilityChanged(parseBoolean((String) event.getNewValue()))); 71 | events.put(CUSTOM_APP_ID.property(), (event, listener) -> listener.discordApplicationIdChanged((String) event.getNewValue()));events.put(USE_CUSTOM_WORDING.property(), (event, listener) -> listener.useCustomWording(parseBoolean((String) event.getNewValue()))); 72 | events.put(CUSTOM_DISCORD_DETAILS_WORDING.property(), (event, listener) -> listener.detailsWordingChanged(String.valueOf(event.getOldValue()), String.valueOf(event.getNewValue()))); 73 | events.put(CUSTOM_DISCORD_STATE_WORDING.property(), (event, listener) -> listener.stateWordingChanged(String.valueOf(event.getOldValue()), String.valueOf(event.getNewValue()))); 74 | } 75 | 76 | @Override 77 | public void propertyChange(PropertyChangeEvent event) { 78 | BiConsumer callback = events.getOrDefault(event.getProperty(), DO_NOTHING); 79 | 80 | for (SettingChangeListener listener : listeners) { 81 | callback.accept(event, listener); 82 | } 83 | } 84 | 85 | private static Moment toMoment(Object value) { 86 | Settings setting = fromProperty((String) value); 87 | 88 | if (setting == RESET_ELAPSED_TIME_ON_NEW_FILE) { 89 | return Moment.ON_NEW_FILE; 90 | } 91 | if (setting == RESET_ELAPSED_TIME_ON_NEW_PROJECT) { 92 | return Moment.ON_NEW_PROJECT; 93 | } 94 | if (setting == RESET_ELAPSED_TIME_ON_STARTUP) { 95 | return Moment.ON_STARTUP; 96 | } 97 | return null; 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/settings/Moment.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.settings; 11 | 12 | /** 13 | * Represents an instant in plug-in's lifecycle. 14 | * 15 | * @author Emmanuel CHEBBI 16 | */ 17 | public enum Moment { 18 | 19 | /** Eclipse startup. */ 20 | ON_STARTUP, 21 | 22 | /** Each time a new file is selected. */ 23 | ON_NEW_FILE, 24 | 25 | /** Each time the current project changes. */ 26 | ON_NEW_PROJECT; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/settings/SettingChangeListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.settings; 11 | 12 | /** 13 | * Listens for changes in plug-in's settings. 14 | * 15 | * @author Emmanuel CHEBBI 16 | */ 17 | public interface SettingChangeListener { 18 | 19 | /** 20 | * Called when the user whether global preferences or project-specific ones. 21 | * 22 | * @param use 23 | * {@code true} if the user wants to use project preferences, 24 | * {@code false} otherwise. 25 | */ 26 | void useProjectProperties(boolean use); 27 | 28 | /** 29 | * Called when the user changes file name's visibility. 30 | * 31 | * @param isVisible 32 | * {@code true} if the user wants to show the file name, 33 | * {@code false} otherwise. 34 | */ 35 | void fileNameVisibilityChanged(boolean isVisible); 36 | 37 | /** 38 | * Called when the user changes project name's visibility. 39 | * 40 | * @param isVisible 41 | * {@code true} if the user wants to show the project name, 42 | * {@code false} otherwise. 43 | */ 44 | void projectNameVisibilityChanged(boolean isVisible); 45 | 46 | /** 47 | * Called when the user changes language icon's visibility. 48 | * 49 | * @param isVisible 50 | * {@code true} if the user wants to show the language icon, 51 | * {@code false} otherwise. 52 | */ 53 | void languageIconVisibilityChanged(boolean isVisible); 54 | 55 | /** 56 | * Called when the user changes elapsed time's visibility. 57 | * 58 | * @param isVisible 59 | * {@code true} if the user wants to show the elapsed time, 60 | * {@code false} otherwise. 61 | */ 62 | void elapsedTimeVisibilityChanged(boolean isVisible); 63 | 64 | /** 65 | * Called when the user changes the moment where the elapsed time should be reset. 66 | * 67 | * @param oldMoment 68 | * The previous value. 69 | * @param newMoment 70 | * The new value. 71 | */ 72 | void elapsedTimeResetMomentChanged(Moment oldMoment, Moment newMoment); 73 | 74 | /** 75 | * Called when the user choose to display a new name for a given project. 76 | * 77 | * @param oldName 78 | * The previous name. May be {@code null} or empty. 79 | * @param newName 80 | * The new name to display 81 | */ 82 | void projectNameChanged(String oldName, String newName); 83 | 84 | /** 85 | * Called when the user choose to whether show or hide rich presence in Discord. 86 | * 87 | * @param isVisible 88 | * {@code true} if the user wants to show rich presence in Discord, 89 | * {@code false} otherwise. 90 | */ 91 | void richPresenceVisibilityChanged(boolean isVisible); 92 | 93 | /** 94 | * Called when the user choose whether to use a custom Discord application. 95 | * 96 | * @param shouldUse 97 | * Whether a custom Discord application should be used instead of the default one. 98 | */ 99 | void customDiscordApplicationVisibilityChanged(boolean shouldUse); 100 | 101 | /** 102 | * Called when the user specifies that informations should now be sent to another Discord application. 103 | * 104 | * @param newApplicationId 105 | * The ID of the new Discord application. 106 | */ 107 | void discordApplicationIdChanged(String newApplicationId); 108 | 109 | /** 110 | * Called when the user chooses whether a custom wording should be use. 111 | * 112 | * @param shouldUse 113 | * Whether a custom wording should be used. 114 | */ 115 | void useCustomWording(boolean shouldUse); 116 | 117 | /** 118 | * Called when the user chooses a new wording for Discord's "details" field. 119 | * 120 | * @param oldWording 121 | * The previous wording. 122 | * @param newWording 123 | * The wording chosen by the user. 124 | */ 125 | void detailsWordingChanged(String oldWording, String newWording); 126 | 127 | /** 128 | * Called when the user chooses a new wording for Discord's "state" field. 129 | * 130 | * @param oldWording 131 | * The previous wording. 132 | * @param newWording 133 | * The wording chosen by the user. 134 | */ 135 | void stateWordingChanged(String oldWording, String newWording); 136 | 137 | } 138 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/settings/Settings.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.settings; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import org.eclipse.core.runtime.QualifiedName; 16 | 17 | import fr.kazejiyu.discord.rpc.integration.Activator; 18 | 19 | /** 20 | * Constants used to identify the different available settings. 21 | * 22 | * @author Emmanuel CHEBBI 23 | */ 24 | // TODO [Refactor] Add a field specifying setting's default value 25 | public enum Settings { 26 | 27 | /** Whether the name of the file being edited should be shown in Discord. */ 28 | SHOW_FILE_NAME("SHOW_FILE_NAME"), 29 | 30 | /** Whether the name of the project being worked on should be shown in Discord. */ 31 | SHOW_PROJECT_NAME("SHOW_PROJECT_NAME"), 32 | 33 | /** Whether the time elapsed since starting to work should be shown in Discord. */ 34 | SHOW_ELAPSED_TIME("SHOW_ELAPSED_TIME"), 35 | 36 | /** 37 | * The reset elapsed time policy. 38 | *

39 | * Should be one of: 40 | *

    41 | *
  • {@link #RESET_ELAPSED_TIME_ON_NEW_FILE} 42 | *
  • {@link #RESET_ELAPSED_TIME_ON_NEW_PROJECT} 43 | *
  • {@link #RESET_ELAPSED_TIME_ON_STARTUP} 44 | *
45 | */ 46 | RESET_ELAPSED_TIME("RESET_ELAPSED_TIME"), 47 | 48 | /** Indicates that the elapsed time should only be reset when the software is started. */ 49 | RESET_ELAPSED_TIME_ON_STARTUP("RESET_ELAPSED_TIME_ON_STARTUP"), 50 | 51 | /** Indicates that the elapsed time should be reset each time an editor opens for a file located in another project. */ 52 | RESET_ELAPSED_TIME_ON_NEW_PROJECT("RESET_ELAPSED_TIME_ON_NEW_PROJECT"), 53 | 54 | /** Indicates that the elapsed time should be reset each time a new editor is focused. */ 55 | RESET_ELAPSED_TIME_ON_NEW_FILE("RESET_ELAPSED_TIME_ON_NEW_FILE"), 56 | 57 | /** Whether the icon representing the language of the file being edited should be shown in Discord. */ 58 | SHOW_LANGUAGE_ICON("SHOW_LANGUAGE_ICON"), 59 | 60 | /** Whether the project uses project-scope settings or global-scope settings. */ 61 | USE_PROJECT_SETTINGS("USE_PROJECT_SETTINGS"), 62 | 63 | /** 64 | * Whether any information should be shown in Discord. 65 | *

66 | * False means that the connection with Discord should not be set at all. */ 67 | SHOW_RICH_PRESENCE("SHOW_RICH_PRESENCE"), 68 | 69 | /** Indicates a nickname that should be shown in Discord instead of the project's name. */ 70 | PROJECT_NAME("PROJECT_NAME"), 71 | 72 | /** Whether a custom Discord Application should be used instead of the default one. */ 73 | USE_CUSTOM_APP("USE_CUSTOM_APP"), 74 | 75 | /** Indicates the ID of the custom Discord Application ID to use. */ 76 | CUSTOM_APP_ID("CUSTOM_APP_ID"), 77 | 78 | /** Whether a custom wording, provided by the user, should be used instead of the built-in one. */ 79 | USE_CUSTOM_WORDING("USE_CUSTOM_WORDING"), 80 | 81 | /** 82 | * The custom wording provided by the user for Discord's state field. 83 | * (https://discordapp.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload-fields). */ 84 | CUSTOM_DISCORD_STATE_WORDING("CUSTOM_DISCORD_STATE_WORDING"), 85 | 86 | /** 87 | * The custom wording provided by the user for Discord's details field. 88 | * (https://discordapp.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload-fields). */ 89 | CUSTOM_DISCORD_DETAILS_WORDING("CUSTOM_DISCORD_DETAILS_WORDING"); 90 | 91 | /** Identifies the Discord application to which information has to be sent 92 | * in order to appear in Discord's UI. */ 93 | public static final String DEFAULT_DISCORD_APPLICATION_ID = "413038514616139786"; 94 | 95 | private static final Map propertyToSetting = new HashMap<>(); 96 | 97 | static { 98 | for (Settings setting : Settings.values()) { 99 | propertyToSetting.put(setting.property, setting); 100 | } 101 | } 102 | 103 | /** A key identifying the setting. */ 104 | private final String property; 105 | 106 | private Settings(String property) { 107 | this.property = property; 108 | } 109 | 110 | /** 111 | * Returns a unique string identifying the setting. 112 | * @return a unique string identifying the setting 113 | */ 114 | public String property() { 115 | return property; 116 | } 117 | 118 | /** 119 | * Returns a unique qualified name for this setting. 120 | * @return a unique qualified name for this setting 121 | */ 122 | public QualifiedName qualifiedName() { 123 | return new QualifiedName(Activator.PLUGIN_ID, property()); 124 | } 125 | 126 | /** 127 | * Returns the setting identified by the given property. 128 | * 129 | * @param property 130 | * The property to turn into a setting. 131 | * 132 | * @return the setting corresponding to the given key, or null if no one match 133 | */ 134 | public static Settings fromProperty(String property) { 135 | return propertyToSetting.get(property); 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/settings/UserPreferences.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | package fr.kazejiyu.discord.rpc.integration.settings; 11 | 12 | import java.util.Optional; 13 | 14 | /** 15 | * User preferences regarding the way information are shown in Discord. 16 | * 17 | * @author Emmanuel CHEBBI 18 | */ 19 | public interface UserPreferences { 20 | 21 | /** 22 | * Returns whether the name of the edited file should be shown in Discord. 23 | * @return true if the name of the edited file should be shown, false otherwise 24 | */ 25 | boolean showsFileName(); 26 | 27 | /** 28 | * Returns whether the name of the current project should be shown in Discord. 29 | * @return true if the name of the current project should be shown, false otherwise 30 | */ 31 | boolean showsProjectName(); 32 | 33 | /** 34 | * Returns whether the elapsed time should be shown in Discord. 35 | * @return true if the elapsed time should be shown, false otherwise 36 | */ 37 | boolean showsElapsedTime(); 38 | 39 | /** 40 | * Returns whether the programming language's icon should be shown in Discord. 41 | * @return true of the programming language's icon should be shown, false otherwise 42 | */ 43 | boolean showsLanguageIcon(); 44 | 45 | /** 46 | * Returns whether the Rich Presence should be shown in Discord. 47 | * @return true if the Rich Presence should be shown, false otherwise 48 | */ 49 | boolean showsRichPresence(); 50 | 51 | /** 52 | * Returns whether the elapsed time should be reset only when the workbench starts.. 53 | * @return true if the elapsed time should be reset only when the workbench starts, false otherwise 54 | */ 55 | boolean resetsElapsedTimeOnStartup(); 56 | 57 | /** 58 | * Returns whether the elapsed time should be reset when an editor for a resource in another project is activated. 59 | * @return true if the elapsed time should be reset when an editor for a resource in another project is activated, false otherwise 60 | */ 61 | boolean resetsElapsedTimeOnNewProject(); 62 | 63 | /** 64 | * Returns whether the elapsed time should be reset each time a new editor is activated. 65 | * @return true if the elapsed time should be reset each time a new editor is activated, false otherwise 66 | */ 67 | boolean resetsElapsedTimeOnNewFile(); 68 | 69 | /** 70 | * Returns the name of the current project, if the user specified one. 71 | * @return the name of the current project, if the user specified one 72 | */ 73 | Optional getProjectName(); 74 | 75 | /** 76 | * Returns whether a custom Discord application should be used. 77 | * @return true if a custom Discord application should be used, false otherwise 78 | */ 79 | boolean usesCustomDiscordApplication(); 80 | 81 | /** 82 | * Returns the ID of the Discord application to connect, if the user specified one. 83 | * @return the ID of the Discord application to connect, if the user specified one 84 | */ 85 | Optional getDiscordApplicationId(); 86 | 87 | 88 | /** 89 | * Registers a new listener that will be called each time a property change. 90 | * 91 | * @param listener 92 | * The listener to register. 93 | */ 94 | void addSettingChangeListener(SettingChangeListener listener); 95 | 96 | /** 97 | * Unregisters a listener so that it will no longer being notified of events. 98 | * 99 | * @param listener 100 | * The listener to unregister. 101 | */ 102 | void removeSettingChangeListener(SettingChangeListener listener); 103 | 104 | /** 105 | * Returns whether a custom wording should be used when printing on Discord. 106 | * @return whether a custom wording should be used when printing on Discord 107 | */ 108 | boolean usesCustomWording(); 109 | 110 | /** 111 | * Returns the custom wording for Discord's "details" field, if the user specified one. 112 | * @return the custom wording for Discord's "details" field, if the user specified one 113 | */ 114 | Optional getCustomDetailsWording(); 115 | 116 | /** 117 | * Returns the custom wording for Discord's "state" field, if the user specified one. 118 | * @return the custom wording for Discord's "state" field, if the user specified one 119 | */ 120 | Optional getCustomStateWording(); 121 | 122 | } 123 | -------------------------------------------------------------------------------- /bundles/fr.kazejiyu.discord.rpc.integration/src/fr/kazejiyu/discord/rpc/integration/settings/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2018-2020 Emmanuel CHEBBI 3 | * 4 | * This program and the accompanying materials are made 5 | * available under the terms of the Eclipse Public License 2.0 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/ 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | ******************************************************************************/ 10 | /** 11 | * Classes relative to Discord Integration's settings. 12 | * 13 | * @author Emmanuel CHEBBI 14 | */ 15 | package fr.kazejiyu.discord.rpc.integration.settings; 16 | -------------------------------------------------------------------------------- /bundles/java-discord-rpc/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /bundles/java-discord-rpc/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | java-discord-rpc 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /bundles/java-discord-rpc/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /bundles/java-discord-rpc/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: java-discord-rpc 4 | Bundle-SymbolicName: java-discord-rpc 5 | Bundle-Version: 2.0.2 6 | Bundle-ClassPath: jna-4.4.0.jar, 7 | discord-rpc-release-v3.4.0.jar, 8 | java-discord-rpc-2.0.2.jar 9 | Bundle-Vendor: Florian Spieß 10 | Export-Package: club.minnced.discord.rpc, 11 | com.sun.jna, 12 | com.sun.jna.ptr, 13 | com.sun.jna.win32 14 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 15 | Automatic-Module-Name: java-discord-rpc 16 | -------------------------------------------------------------------------------- /bundles/java-discord-rpc/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = META-INF/,\ 2 | jna-4.4.0.jar,\ 3 | discord-rpc-release-v3.4.0.jar,\ 4 | java-discord-rpc-2.0.2.jar 5 | -------------------------------------------------------------------------------- /bundles/java-discord-rpc/discord-rpc-release-v3.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/bundles/java-discord-rpc/discord-rpc-release-v3.4.0.jar -------------------------------------------------------------------------------- /bundles/java-discord-rpc/java-discord-rpc-2.0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/bundles/java-discord-rpc/java-discord-rpc-2.0.2.jar -------------------------------------------------------------------------------- /bundles/java-discord-rpc/jna-4.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/bundles/java-discord-rpc/jna-4.4.0.jar -------------------------------------------------------------------------------- /bundles/java-discord-rpc/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | fr.kazejiyu.discord.rpc.integration 7 | fr.kazejiyu.discord.rpc.integration.bundles 8 | 1.2.2 9 | 10 | 11 | java-discord-rpc 12 | eclipse-plugin 13 | 2.0.2 14 | 15 | 16 | true 17 | 18 | -------------------------------------------------------------------------------- /bundles/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | fr.kazejiyu.discord.rpc.integration.bundles 5 | pom 6 | 7 | 8 | fr.kazejiyu.discord.rpc.integration 9 | fr.kazejiyu.discord.rpc.integration.root 10 | 1.2.2 11 | 12 | 13 | 14 | java-discord-rpc 15 | fr.kazejiyu.discord.rpc.integration 16 | fr.kazejiyu.discord.rpc.integration.adapters 17 | fr.kazejiyu.discord.rpc.integration.ui.preferences 18 | 19 | 20 | 21 | 22 | 23 | org.apache.maven.plugins 24 | maven-checkstyle-plugin 25 | ${checkstyle.version} 26 | 27 | 28 | com.puppycrawl.tools 29 | checkstyle 30 | ${checkstyle.latest.version} 31 | 32 | 33 | 34 | 35 | validate 36 | validate 37 | 38 | ../checkstyle.xml 39 | UTF-8 40 | true 41 | true 42 | 43 | 44 | check 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | # Sphinx 2 | _build/ -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SOURCEDIR = . 8 | BUILDDIR = _build 9 | 10 | # Put it first so that "make" without argument is like "make help". 11 | help: 12 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 13 | 14 | .PHONY: help Makefile 15 | 16 | # Catch-all target: route all unknown targets to Sphinx using the new 17 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 18 | %: Makefile 19 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Discord Rich Presence for Eclipse IDE documentation 2 | 3 | This documentation is built with Sphinx in order to be hosted by ReadTheDocs. 4 | 5 | Published at https://discord-rich-presence-for-eclipse-ide.readthedocs.io/en/latest/ 6 | 7 | ## Generate the documentation 8 | 9 | ```bash 10 | make clean && make html 11 | ``` -------------------------------------------------------------------------------- /docs/contribute/contributing-guide.rst: -------------------------------------------------------------------------------- 1 | Contributing Guide 2 | ================== 3 | 4 | Please read the `contributing guide `_ for a technical introduction to the project. -------------------------------------------------------------------------------- /docs/customize/change-name-of-projects.rst: -------------------------------------------------------------------------------- 1 | Change displayed project names 2 | =============================== 3 | 4 | By default the plug-in shows on Discord the name of the Eclipse project. However, it may happen that this name is not really accurate. This may happen, for example, when the different Eclipse projects are sub-modules of a bigger one. In such a case you may want to provide a custom name that will be used instead. 5 | 6 | The name shown for a given Eclipse project can be changed in the project's preferences page: 7 | 8 | 1. Right-click on the project > ``Properties`` 9 | 2. Click on ``Discord Rich Presence`` 10 | 3. Look at the ``Display`` section 11 | 4. Type a name in ``Name displayed for the project`` text field 12 | 5. Click on ``Apply`` 13 | 14 | .. note:: This preference is the only one that is taken into account even if the ``Use project settings`` preference is unchecked. This allows you to customize a project's name while benefiting from global preferences. -------------------------------------------------------------------------------- /docs/customize/change-wording.rst: -------------------------------------------------------------------------------- 1 | Change wording 2 | ===================== 3 | 4 | Motivation 5 | ---------- 6 | 7 | By default, the plug-in uses the following sentences: *Editing * and *Working on *: 8 | 9 | .. image:: ../images/rich_presence_example.png 10 | :align: center 11 | :alt: Example of a Rich Presence showing a Java icon 12 | 13 | Provide custom templates 14 | ------------------------ 15 | 16 | However, they may not fit your needs. Hopefully you can specify your own sentences from the preferences page: 17 | 18 | 1. Click on ``Window`` > ``Preference`` 19 | 2. Select ``Discord Rich Presence`` > ``Wording`` 20 | 3. The following page should open: 21 | 22 | .. image:: images/change_wording_preferences_page.png 23 | :align: center 24 | :alt: The Preferences dialog with the 'Discord Wording' page opened 25 | 26 | 4. Check ``Use custom wording`` 27 | 5. Fill the *Details* and *State* fields with your own templates 28 | 29 | .. tip:: In Discord, *Details* is the top text and *State* the bottom text. See also `Discord's Rich Presence documentation `_. 30 | 31 | The following variables can be used in the templates: 32 | 33 | +-----------------------+-------------------------------------------------+ 34 | | Variable | Replaced by | 35 | +=======================+=================================================+ 36 | | ``${file}`` | the name of the file with its extension | 37 | +-----------------------+-------------------------------------------------+ 38 | | ``${file.baseName}`` | the name of the file without its extension | 39 | +-----------------------+-------------------------------------------------+ 40 | | ``${file.extension}`` | the extension of the file | 41 | +-----------------------+-------------------------------------------------+ 42 | | ``${language}`` | the name of the programming language | 43 | +-----------------------+-------------------------------------------------+ 44 | | ``${project}`` | the name of the project | 45 | +-----------------------+-------------------------------------------------+ 46 | 47 | The wording can also be customize per project: 48 | 49 | 1. Right-click on a project > ``Properties`` 50 | 2. Select ``Discord Rich Presence`` > ``Wording`` -------------------------------------------------------------------------------- /docs/customize/deactivate-plugin.rst: -------------------------------------------------------------------------------- 1 | Deactivate the plug-in 2 | ====================== 3 | 4 | Once the plug-in is installed, Discord Rich Presence is automatically started on Eclipse startup. As a result, Discord displays **Playing Eclipse IDE** as a status message as soon as Eclipse IDE is opened. This behavior may not be desirable but can be easily deactivated. 5 | 6 | Deactivate occasionally 7 | ----------------------- 8 | 9 | The plug-in provides a preference to deactivate its behavior: 10 | 11 | 1. Open Eclipse Preferences (``Window`` > ``Preferences``) 12 | 2. Open the plug-in's page (``Discord Rich Presence``) 13 | 3. Uncheck *Activate Rich Presence Integration* 14 | 4. Click on *Apply* 15 | 16 | From that time on, Discord won't be notified anymore by Eclipse IDE. In order to re-activate Rich Presence, follow the steps above and check *Activate Rich Presence Integration* again. 17 | 18 | Deactive the plug-in for a long time 19 | ------------------------------------ 20 | 21 | While convenient, the previous method is not really optimized. Indeed, even if no Rich Presence is shown on Discord the plug-in is still activated and is notified each time a new editor opens, which may cause a little overhead. 22 | 23 | Follow the steps below to completely deactivate the plug-in: 24 | 25 | 1. Open Eclipse Preferences (``Window`` > ``Preferences``) 26 | 2. Open the *Startup and Shutdown* page (``General`` > ``Startup and Shutdown``) 27 | 3. Uncheck *Discord Rich Presence for Eclipse IDE* 28 | 4. Reboot Eclipse IDE 29 | 30 | From that time on, Discord won't be notified anymore by Eclipse IDE. In order to re-activate Rich Presence, follow the steps above and check *Discord Rich Presence for Eclipse IDE* again then reboot the IDE. -------------------------------------------------------------------------------- /docs/customize/global-and-project-scopes.rst: -------------------------------------------------------------------------------- 1 | Differentiate global and project scopes 2 | ======================================= 3 | 4 | The *Discord Rich Presence for Eclipse IDE* plug-in offers numerous preferences allowing you to choose the information to show on Discord. Most of these preferences can be changed at both global and project scope. 5 | 6 | .. _part-global-scope-preferences: 7 | 8 | Global scope 9 | ------------ 10 | 11 | Preferences changed at the global scope are applied to all the projects in the active workspace. They are not shared between workspaces so different workspaces can have different global preferences. 12 | 13 | Those preferences can be edited through the *Preferences* dialog: 14 | 15 | 1. Go to ``Window`` > ``Preferences`` 16 | 2. Click on ``Discord Rich Presence`` 17 | 3. The following page should open: 18 | 19 | .. image:: images/global_preferences.png 20 | :align: center 21 | :alt: Screenshot of the global-scope preferences dialog 22 | 23 | See the different sections on the left menu to discover what can be customized. 24 | 25 | .. _part-project-scope-preferences: 26 | 27 | Project scope 28 | -------------- 29 | 30 | Preferences changed at the project scope are only applied to one project. They have precedence over global scope. 31 | 32 | Those preferences can be edited through the *Project Settings* dialog: 33 | 34 | 1. Right-click on a project > ``Properties`` 35 | 2. Click on ``Discord Rich Presence`` 36 | 3. The following page should open: 37 | 38 | .. image:: images/project_preferences.png 39 | :align: center 40 | :alt: Screenshot of the project-scope preferences dialog 41 | 42 | By default each project uses the global preferences (notice the ``Use workspace settings`` checkbox). In order to set the preferences at the project-scope you have to check the ``Use project settings`` checkbox. -------------------------------------------------------------------------------- /docs/customize/hide-information.rst: -------------------------------------------------------------------------------- 1 | Hide some information 2 | ====================== 3 | 4 | Plug-in's preferences allow you to prevent some information to be shown on Discord. These preferences can be set at both :ref:`global and project scopes `. 5 | 6 | Open the preferences page and take a look at the *Privacy* section: 7 | 8 | .. image:: images/global_preferences.png 9 | :align: center 10 | :alt: Screenshot of the global-scope preferences dialog 11 | 12 | The checkboxes allow you to select whether the following information should be shown on Discord: 13 | 14 | - the name of the edited file, 15 | - the name of the edited file's project, 16 | - the time elapsed working, 17 | - the icon of the edited file's programming language. -------------------------------------------------------------------------------- /docs/customize/images/change_icons_preferences_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/docs/customize/images/change_icons_preferences_page.png -------------------------------------------------------------------------------- /docs/customize/images/change_wording_preferences_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/docs/customize/images/change_wording_preferences_page.png -------------------------------------------------------------------------------- /docs/customize/images/custom_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/docs/customize/images/custom_icon.png -------------------------------------------------------------------------------- /docs/customize/images/global_preferences.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/docs/customize/images/global_preferences.png -------------------------------------------------------------------------------- /docs/customize/images/project_preferences.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/docs/customize/images/project_preferences.png -------------------------------------------------------------------------------- /docs/extend/change-wording.rst: -------------------------------------------------------------------------------- 1 | Change wordings 2 | ############################# 3 | 4 | .. important:: This section requires some knowledge about `Eclipse RCP development `_ and `Eclipse Extension Points `_. 5 | 6 | You must also have read :ref:`part-support-new-editors`. 7 | 8 | Motivation 9 | ---------- 10 | 11 | By default, information is displayed on Discord using the following format: 12 | 13 | .. code-block:: 14 | 15 | Editing 16 | Working on 17 | 18 | It is very simple but maybe that it does not fulfil your needs. Read below to learn how to change it. 19 | 20 | Implementation 21 | -------------- 22 | 23 | I plan to add preferences allowing one to customize these default wordings easily from the Eclipse IDE (see `issue #71 `_) but it will take some time so in the meantime you'll have to get your hands a little dirty. 24 | 25 | In order to provide your own wording you have to create two ``EditorInputToRichPresenceAdapter`` as explained in :ref:`part-support-new-editors`. 26 | 27 | These adapters must: 28 | 29 | - expect editor input which are respectively instances of ``IFileEditorInput`` and ``FileStoreEditorInput``, 30 | - have a priority greater than 0 in order to be favoured over built-in ones. 31 | 32 | You can now implement the ``createRichPresence`` method as you wish to create a Rich Presence that follows your own wording. 33 | 34 | .. tip:: I advise you to create those adapters by copying the code of: 35 | 36 | - `DefaultFileEditorInputRichPresence `_ 37 | - `DefaultURIEditorInputRichPresence `_ -------------------------------------------------------------------------------- /docs/images/rich-presence-examples.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/docs/images/rich-presence-examples.gif -------------------------------------------------------------------------------- /docs/images/rich_presence_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/docs/images/rich_presence_example.png -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | 2 | =================================================== 3 | Discord Rich Presence for Eclipse IDE 4 | =================================================== 5 | 6 | The *Discord Rich Presence for Eclipse IDE* is a plug-in for Eclipse IDE that shows on Discord the projects and files you're currently working on: 7 | 8 | .. image:: images/rich-presence-examples.gif 9 | :align: center 10 | :alt: an example of Rich Presence shown in Discord 11 | 12 | This plug-in can be installed on any application and IDE based on Eclipse Mars 1 or newer. Please see the following table of contents for instructions on how to install the plug-in, change its preferences or extend it. 13 | 14 | .. tip:: See also the sources on `GitHub `_! 15 | 16 | Table of Contents 17 | ----------------- 18 | 19 | .. toctree:: 20 | :maxdepth: 2 21 | :caption: Install the plug-in 22 | 23 | install/from-marketplace 24 | install/from-p2 25 | 26 | .. toctree:: 27 | :maxdepth: 2 28 | :caption: Customize the plug-in 29 | 30 | customize/global-and-project-scopes 31 | customize/change-name-of-projects 32 | customize/change-wording 33 | customize/change-language-icons 34 | customize/hide-information 35 | customize/deactivate-plugin 36 | 37 | .. toctree:: 38 | :maxdepth: 2 39 | :caption: Extend the plug-in 40 | 41 | extend/support-new-editors 42 | extend/change-wording 43 | 44 | .. toctree:: 45 | :maxdepth: 2 46 | :caption: Contribute to the plug-in 47 | 48 | contribute/contributing-guide 49 | 50 | .. toctree:: 51 | :maxdepth: 2 52 | :caption: Troubleshooting 53 | 54 | troubleshooting/not-detected-as-game 55 | troubleshooting/workbench-early-startup-error -------------------------------------------------------------------------------- /docs/install/from-marketplace.rst: -------------------------------------------------------------------------------- 1 | .. _part-install-from-marketplace: 2 | 3 | ############################ 4 | From the Eclipse Marketplace 5 | ############################ 6 | 7 | The plug-in is available on the Eclipse Marketplace: 8 | 9 | - https://marketplace.eclipse.org/content/discord-rich-presence-eclipse-ide 10 | 11 | You can also drag the following button and drop it into your workspace to start the installation: 12 | 13 | .. image:: https://marketplace.eclipse.org/sites/all/themes/solstice/public/images/marketplace/btn-install.png 14 | :target: http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=4240174 15 | :align: center 16 | :alt: Marketplace installation button: drag it to your workspace to start the installation -------------------------------------------------------------------------------- /docs/install/from-p2.rst: -------------------------------------------------------------------------------- 1 | .. _part-install-from-p2: 2 | 3 | ###################### 4 | From the P2 repository 5 | ###################### 6 | 7 | All versions of the plug-in are also deployed on the following P2 repository: 8 | 9 | - https://dl.bintray.com/kazejiyu/eclipse-discord-integration/updates/ 10 | 11 | To use it: 12 | 13 | 1. Open Eclipse IDE 14 | 2. Click on ``Help`` > ``Install new software...`` 15 | 3. Paste the P2's URL in the ``Work with`` field 16 | 17 | Under the ``Discord Rich Presence Integration`` category, check the following features: 18 | 19 | - Discord Rich Presence 20 | - Discord Rich Presence UI 21 | 22 | .. note:: The latter is not required for the plug-in to work but adds dedicated preferences pages to the IDE Preferences and Project Settings dialogs. 23 | 24 | Click on ``Next >``, accept the licenses then ``Finish``. 25 | 26 | Wait for the installation to end then restart the IDE. -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/troubleshooting/not-detected-as-game.rst: -------------------------------------------------------------------------------- 1 | Discord does not detect Eclipse IDE as a game 2 | ============================================= 3 | 4 | If Discord is not showing anything, ensure that Eclipse IDE is detected as a game. To this end: 5 | 6 | 1. Open *Discord User Settings* 7 | 2. Go to the *Games* tab 8 | 3. Click on the *Add it!* button 9 | 4. Select *Eclipse IDE*. -------------------------------------------------------------------------------- /docs/troubleshooting/workbench-early-startup-error.rst: -------------------------------------------------------------------------------- 1 | A 'Workbench early startup error' occurs since the plug-in is installed 2 | ======================================================================= 3 | 4 | In case you encounter the following error on startup: 5 | 6 | .. code-block:: 7 | 8 | An internal error occurred during: "Workbench early startup". 9 | 10 | There is an incompatible JNA native library installed on this system 11 | Expected: 5.1.0 12 | Found: 4.0.1 13 | 14 | you can try to modify the *eclipse.ini* file which is located next to *eclipse.exe* (within Eclipse IDE's installation directory) in order to set the ``jna.nosys`` property to true as follows: 15 | 16 | .. code-block:: 17 | 18 | -vmargs 19 | -Djna.nosys=true 20 | 21 | .. note:: The ``-vmargs`` line should already exist, otherwise you can append it at the end of the file. -------------------------------------------------------------------------------- /features/fr.kazejiyu.discord.rpc.integration.feature/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fr.kazejiyu.discord.rpc.integration.feature 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.pde.FeatureBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.pde.FeatureNature 16 | 17 | 18 | -------------------------------------------------------------------------------- /features/fr.kazejiyu.discord.rpc.integration.feature/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = feature.xml 2 | -------------------------------------------------------------------------------- /features/fr.kazejiyu.discord.rpc.integration.ui.feature/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fr.kazejiyu.discord.rpc.integration.ui.feature 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.pde.FeatureBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.pde.FeatureNature 16 | 17 | 18 | -------------------------------------------------------------------------------- /features/fr.kazejiyu.discord.rpc.integration.ui.feature/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = feature.xml 2 | -------------------------------------------------------------------------------- /features/java-discord-rpc.feature/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | java-discord-rpc.feature 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.pde.FeatureBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.pde.FeatureNature 16 | 17 | 18 | -------------------------------------------------------------------------------- /features/java-discord-rpc.feature/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = feature.xml 2 | -------------------------------------------------------------------------------- /features/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | fr.kazejiyu.discord.rpc.integration.features 5 | pom 6 | 7 | 8 | fr.kazejiyu.discord.rpc.integration 9 | fr.kazejiyu.discord.rpc.integration.root 10 | 1.2.2 11 | 12 | 13 | 14 | java-discord-rpc.feature 15 | fr.kazejiyu.discord.rpc.integration.feature 16 | fr.kazejiyu.discord.rpc.integration.ui.feature 17 | 18 | 19 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | fr.kazejiyu.discord.rpc.integration.root 5 | fr.kazejiyu.discord.rpc.integration 6 | 1.2.2 7 | pom 8 | 9 | Discord Rich Presence for Eclipse IDE 10 | A set of plug-ins for the Eclipse IDE providing a Discord Rich Presence integration. 11 | 12 | 13 | bundles 14 | features 15 | releng 16 | tests 17 | 18 | 19 | 20 | 1.6.0 21 | 3.0.0 22 | 8.19 23 | 24 | UTF-8 25 | 1.8 26 | 1.8 27 | 28 | 32 | ../../tests/${project.artifactId}.tests/target/jacoco.exec 33 | 34 | 39 | **/*Exception.java,**/Activator.java,**/Plugin.java 40 | 41 | 42 | Discord Rich Presence for Eclipse IDE 43 | 44 | 45 | 52 | 53 | 54 | 55 | 56 | 57 | org.eclipse.tycho 58 | tycho-maven-plugin 59 | ${tycho.version} 60 | true 61 | 62 | 63 | 64 | org.eclipse.tycho 65 | tycho-versions-plugin 66 | ${tycho.version} 67 | 68 | 69 | 70 | org.eclipse.tycho 71 | target-platform-configuration 72 | ${tycho.version} 73 | 74 | 75 | 76 | fr.kazejiyu.discord.rpc.integration 77 | fr.kazejiyu.discord.rpc.integration.target 78 | 1.2.2 79 | 80 | 81 | 82 | 83 | linux 84 | gtk 85 | x86 86 | 87 | 88 | linux 89 | gtk 90 | x86_64 91 | 92 | 93 | win32 94 | win32 95 | x86 96 | 97 | 98 | win32 99 | win32 100 | x86_64 101 | 102 | 103 | macosx 104 | cocoa 105 | x86_64 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /releng/fr.kazejiyu.discord.rpc.integration.p2/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fr.kazejiyu.discord.rpc.integration.p2 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.pde.UpdateSiteBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.pde.UpdateSiteNature 16 | 17 | 18 | -------------------------------------------------------------------------------- /releng/fr.kazejiyu.discord.rpc.integration.p2/category.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Plug-ins integrating Discord Rich Presence within Eclipse IDE. 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /releng/fr.kazejiyu.discord.rpc.integration.p2/packaging-p2composite.ant: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | version=1 80 | metadata.repository.factory.order=compositeContent.xml,\! 81 | artifact.repository.factory.order=compositeArtifacts.xml,\! 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /releng/fr.kazejiyu.discord.rpc.integration.p2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | fr.kazejiyu.discord.rpc.integration 9 | fr.kazejiyu.discord.rpc.integration.releng 10 | 1.2.2 11 | 12 | 13 | fr.kazejiyu.discord.rpc.integration.p2 14 | eclipse-repository 15 | 16 | 17 | 18 | eclipse-discord-integration 19 | 20 | releases 21 | 22 | Discord Rich Presence for Eclipse IDE 23 | 24 | ${bintray.user} 25 | 26 | 27 | releases 28 | updates 29 | zipped 30 | 32 | ../../releases/ 33 | 34 | 35 | 36 | 37 | 38 | release-composite 39 | 40 | false 41 | 42 | 43 | 44 | 45 | 46 | maven-antrun-plugin 47 | 1.7 48 | 49 | 50 | 51 | update-local-repository 52 | prepare-package 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | run 61 | 62 | 63 | 64 | 65 | 66 | deploy-repository 67 | verify 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | run 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.eclipse.tycho.extras 83 | tycho-eclipserun-plugin 84 | ${tycho.version} 85 | 86 | 87 | 88 | -application org.eclipse.ant.core.antRunner -buildfile packaging-p2composite.ant p2.composite.add -Dsite.label="${site.label}" -Dproject.build.directory=${project.build.directory} -DunqualifiedVersion=${unqualifiedVersion} -Dchild.repository.path.prefix="${child.repository.path.prefix}" 89 | 90 | 91 | mars 92 | p2 93 | http://download.eclipse.org/releases/mars 94 | 95 | 96 | 97 | 98 | org.eclipse.ant.core 99 | eclipse-plugin 100 | 101 | 102 | org.apache.ant 103 | eclipse-plugin 104 | 105 | 106 | org.eclipse.equinox.p2.repository.tools 107 | eclipse-plugin 108 | 109 | 110 | org.eclipse.equinox.p2.core.feature 111 | eclipse-feature 112 | 113 | 114 | org.eclipse.equinox.p2.extras.feature 115 | eclipse-feature 116 | 117 | 118 | org.eclipse.equinox.ds 119 | eclipse-plugin 120 | 121 | 122 | 123 | 124 | 125 | add-p2-composite-repository 126 | package 127 | 128 | eclipse-run 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /releng/fr.kazejiyu.discord.rpc.integration.p2/removeFromBintray.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # remove p2 metadata artifacts from bintray remote path 3 | #Sample Usage: removeFromBintray.sh apikey remotePath 4 | BINTRAY_API_KEY=$1 5 | PATH_TO_REPOSITORY=$2 6 | 7 | BINTRAY_USER=lorenzobettini 8 | BINTRAY_REPO=p2-composite-example 9 | 10 | function main() { 11 | remove_p2_metadata 12 | } 13 | 14 | function remove_p2_metadata() { 15 | echo "${BINTRAY_USER}" 16 | echo "${BINTRAY_API_KEY}" 17 | echo "${BINTRAY_REPO}" 18 | echo "${PCK_NAME}" 19 | echo "${PCK_VERSION}" 20 | echo "${PATH_TO_REPOSITORY}" 21 | 22 | 23 | echo "Removing metadata content.jar..." 24 | curl -X DELETE -u${BINTRAY_USER}:${BINTRAY_API_KEY} "https://api.bintray.com/content/${BINTRAY_USER}/${BINTRAY_REPO}/${PATH_TO_REPOSITORY}/content.jar" 25 | echo "" 26 | echo "Removing metadata artifacts.jar..." 27 | curl -X DELETE -u${BINTRAY_USER}:${BINTRAY_API_KEY} "https://api.bintray.com/content/${BINTRAY_USER}/${BINTRAY_REPO}/${PATH_TO_REPOSITORY}/artifacts.jar" 28 | echo "" 29 | echo "Removing metadata compositeContent.xml..." 30 | curl -X DELETE -u${BINTRAY_USER}:${BINTRAY_API_KEY} "https://api.bintray.com/content/${BINTRAY_USER}/${BINTRAY_REPO}/${PATH_TO_REPOSITORY}/compositeContent.xml" 31 | echo "" 32 | echo "Removing metadata compositeArtifacts.xml..." 33 | curl -X DELETE -u${BINTRAY_USER}:${BINTRAY_API_KEY} "https://api.bintray.com/content/${BINTRAY_USER}/${BINTRAY_REPO}/${PATH_TO_REPOSITORY}/compositeArtifacts.xml" 34 | echo "" 35 | echo "Removing metadata p2.index..." 36 | curl -X DELETE -u${BINTRAY_USER}:${BINTRAY_API_KEY} "https://api.bintray.com/content/${BINTRAY_USER}/${BINTRAY_REPO}/${PATH_TO_REPOSITORY}/p2.index" 37 | echo "" 38 | 39 | } 40 | 41 | 42 | 43 | main "$@" -------------------------------------------------------------------------------- /releng/fr.kazejiyu.discord.rpc.integration.target/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fr.kazejiyu.discord.rpc.integration.target 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /releng/fr.kazejiyu.discord.rpc.integration.target/fr.kazejiyu.discord.rpc.integration.target.target: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /releng/fr.kazejiyu.discord.rpc.integration.target/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | fr.kazejiyu.discord.rpc.integration.target 5 | eclipse-target-definition 6 | 7 | 8 | fr.kazejiyu.discord.rpc.integration 9 | fr.kazejiyu.discord.rpc.integration.releng 10 | 1.2.2 11 | 12 | 13 | -------------------------------------------------------------------------------- /releng/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | fr.kazejiyu.discord.rpc.integration.releng 5 | pom 6 | 7 | 8 | fr.kazejiyu.discord.rpc.integration 9 | fr.kazejiyu.discord.rpc.integration.root 10 | 1.2.2 11 | 12 | 13 | 14 | fr.kazejiyu.discord.rpc.integration.target 15 | fr.kazejiyu.discord.rpc.integration.p2 16 | 17 | 18 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectName=Discord Rich Presence for Eclipse IDE 2 | 3 | # ===================================================== 4 | # Meta-data for the project 5 | # ===================================================== 6 | 7 | sonar.links.homepage=https://github.com/echebbi/eclipse-discord-integration 8 | sonar.links.ci=https://travis-ci.org/echebbi/eclipse-discord-integration 9 | sonar.links.scm=https://github.com/echebbi/eclipse-discord-integration 10 | sonar.links.issue=https://github.com/echebbi/eclipse-discord-integration/issues 11 | 12 | 13 | # ===================================================== 14 | # Properties that will be shared amongst all modules 15 | # ===================================================== 16 | 17 | sonar.host.url=https://sonarcloud.io 18 | 19 | # ===================================================== 20 | # Java config 21 | # ===================================================== 22 | 23 | sonar.java.source=8 -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.adapters.tests/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.adapters.tests/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fr.kazejiyu.discord.rpc.integration.adapters.tests 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.adapters.tests/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.adapters.tests/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Discord Rich Presence for Eclipse IDE — Default Adapters (Tests) 4 | Bundle-SymbolicName: fr.kazejiyu.discord.rpc.integration.adapters.tests 5 | Bundle-Version: 1.2.2 6 | Bundle-Vendor: Emmanuel CHEBBI 7 | Fragment-Host: fr.kazejiyu.discord.rpc.integration.adapters;bundle-version="0.8.4" 8 | Automatic-Module-Name: fr.kazejiyu.discord.rpc.integration.adapters.tests 9 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 10 | Require-Bundle: org.junit.jupiter.api;bundle-version="5.0.0", 11 | org.junit.jupiter.params;bundle-version="5.0.0", 12 | org.junit.platform.launcher;bundle-version="1.0.0", 13 | org.opentest4j;bundle-version="1.0.0", 14 | org.assertj, 15 | org.junit.platform.commons;bundle-version="1.0.0", 16 | org.junit.platform.engine;bundle-version="1.0.0", 17 | org.junit.platform.commons;bundle-version="1.0.0", 18 | org.junit.platform.runner;bundle-version="1.1.0", 19 | org.objenesis;bundle-version="1.0.0", 20 | org.hamcrest.core;bundle-version="1.3.0", 21 | org.mockito;bundle-version="2.13.0", 22 | net.bytebuddy.byte-buddy;bundle-version="1.7.9", 23 | org.eclipse.core.runtime;bundle-version="3.13.0" 24 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.adapters.tests/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = META-INF/,\ 4 | . 5 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.adapters.tests/lib/org.junit.jupiter.engine-5.1.0.v20180327-1502.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/tests/fr.kazejiyu.discord.rpc.integration.adapters.tests/lib/org.junit.jupiter.engine-5.1.0.v20180327-1502.jar -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.adapters.tests/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | fr.kazejiyu.discord.rpc.integration.adapters.tests 5 | eclipse-test-plugin 6 | 7 | 8 | fr.kazejiyu.discord.rpc.integration 9 | tests 10 | 1.2.2 11 | 12 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.adapters.tests/src/fr/kazejiyu/discord/rpc/integration/tests/mock/MockitoExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package fr.kazejiyu.discord.rpc.integration.tests.mock; 12 | 13 | import static org.mockito.Mockito.mock; 14 | 15 | import java.lang.reflect.Parameter; 16 | 17 | import org.junit.jupiter.api.extension.ExtensionContext; 18 | import org.junit.jupiter.api.extension.ExtensionContext.Namespace; 19 | import org.junit.jupiter.api.extension.ExtensionContext.Store; 20 | import org.junit.jupiter.api.extension.ParameterContext; 21 | import org.junit.jupiter.api.extension.ParameterResolver; 22 | import org.junit.jupiter.api.extension.TestInstancePostProcessor; 23 | import org.mockito.Mock; 24 | import org.mockito.MockitoAnnotations; 25 | 26 | /** 27 | * Inject mocks into JUnit tests. 28 | */ 29 | public class MockitoExtension implements TestInstancePostProcessor, ParameterResolver { 30 | 31 | @Override 32 | public void postProcessTestInstance(Object testInstance, ExtensionContext context) { 33 | MockitoAnnotations.initMocks(testInstance); 34 | } 35 | 36 | @Override 37 | public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { 38 | return parameterContext.getParameter().isAnnotationPresent(Mock.class); 39 | } 40 | 41 | @Override 42 | public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { 43 | return getMock(parameterContext.getParameter(), extensionContext); 44 | } 45 | 46 | private Object getMock(Parameter parameter, ExtensionContext extensionContext) { 47 | 48 | Class mockType = parameter.getType(); 49 | Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType)); 50 | String mockName = getMockName(parameter); 51 | 52 | if (mockName != null) { 53 | return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName)); 54 | } 55 | else { 56 | return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType)); 57 | } 58 | } 59 | 60 | private String getMockName(Parameter parameter) { 61 | String explicitMockName = parameter.getAnnotation(Mock.class).name().trim(); 62 | if (!explicitMockName.isEmpty()) { 63 | return explicitMockName; 64 | } 65 | else if (parameter.isNamePresent()) { 66 | return parameter.getName(); 67 | } 68 | return null; 69 | } 70 | } -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.adapters.tests/src/fr/kazejiyu/discord/rpc/integration/tests/mock/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Mocking utilities. 3 | */ 4 | package fr.kazejiyu.discord.rpc.integration.tests.mock; -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests.report/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | fr.kazejiyu.discord.rpc.integration.tests.report 5 | 6 | pom 7 | 8 | 9 | fr.kazejiyu.discord.rpc.integration 10 | tests 11 | 1.2.2 12 | 13 | 14 | 15 | 16 | jacoco 17 | 18 | false 19 | 20 | 21 | 22 | 23 | org.jacoco 24 | jacoco-maven-plugin 25 | ${jacoco-version} 26 | 27 | 28 | verify 29 | 30 | report-aggregate 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | fr.kazejiyu.discord.rpc.integration 43 | fr.kazejiyu.discord.rpc.integration 44 | 1.2.2 45 | compile 46 | 47 | 48 | fr.kazejiyu.discord.rpc.integration 49 | fr.kazejiyu.discord.rpc.integration.tests 50 | 1.2.2 51 | test 52 | 53 | 54 | fr.kazejiyu.discord.rpc.integration 55 | fr.kazejiyu.discord.rpc.integration.adapters 56 | 1.2.2 57 | compile 58 | 59 | 60 | fr.kazejiyu.discord.rpc.integration 61 | fr.kazejiyu.discord.rpc.integration.adapters.tests 62 | 1.2.2 63 | test 64 | 65 | 66 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fr.kazejiyu.discord.rpc.integration.tests 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Discord Rich Presence for Eclipse IDE (Tests) 4 | Bundle-SymbolicName: fr.kazejiyu.discord.rpc.integration.tests 5 | Bundle-Version: 1.2.2 6 | Bundle-Vendor: Emmanuel CHEBBI 7 | Fragment-Host: fr.kazejiyu.discord.rpc.integration;bundle-version="0.8.4" 8 | Automatic-Module-Name: fr.kazejiyu.discord.rpc.integration.tests 9 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 10 | Require-Bundle: org.junit.jupiter.api;bundle-version="5.0.0", 11 | org.junit.jupiter.params;bundle-version="5.0.0", 12 | org.junit.platform.launcher;bundle-version="1.0.0", 13 | org.opentest4j;bundle-version="1.0.0", 14 | org.assertj, 15 | org.junit.platform.commons;bundle-version="1.0.0", 16 | org.junit.platform.engine;bundle-version="1.0.0", 17 | org.junit.platform.commons;bundle-version="1.0.0", 18 | org.junit.platform.runner;bundle-version="1.1.0", 19 | org.objenesis;bundle-version="1.0.0", 20 | org.hamcrest.core;bundle-version="1.3.0", 21 | org.mockito;bundle-version="2.13.0", 22 | net.bytebuddy.byte-buddy;bundle-version="1.7.9" 23 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = META-INF/,\ 4 | . 5 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/lib/org.junit.jupiter.engine-5.1.0.v20180327-1502.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/tests/fr.kazejiyu.discord.rpc.integration.tests/lib/org.junit.jupiter.engine-5.1.0.v20180327-1502.jar -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | fr.kazejiyu.discord.rpc.integration.tests 5 | eclipse-test-plugin 6 | 7 | 8 | fr.kazejiyu.discord.rpc.integration 9 | tests 10 | 1.2.2 11 | 12 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/src/fr/kazejiyu/discord/rpc/integration/core/SelectionTimesTest.java: -------------------------------------------------------------------------------- 1 | package fr.kazejiyu.discord.rpc.integration.core; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.assertj.core.api.SoftAssertions; 6 | import org.eclipse.core.resources.IProject; 7 | import org.junit.jupiter.api.BeforeEach; 8 | import org.junit.jupiter.api.DisplayName; 9 | import org.junit.jupiter.api.Test; 10 | import org.junit.jupiter.api.extension.ExtendWith; 11 | import org.mockito.Mock; 12 | 13 | import fr.kazejiyu.discord.rpc.integration.tests.mock.MockitoExtension; 14 | 15 | /** 16 | * Unit test the {@link SelectionTimes} class. 17 | */ 18 | @ExtendWith(MockitoExtension.class) 19 | @DisplayName("A SelectionTimes") 20 | public class SelectionTimesTest { 21 | 22 | private long before; 23 | private long after; 24 | 25 | private SelectionTimes times; 26 | 27 | @Mock 28 | private IProject selectedProject; 29 | 30 | @BeforeEach 31 | void createSelectionTimes() { 32 | before = System.currentTimeMillis() / 1000; 33 | times = new SelectionTimes(); 34 | after = System.currentTimeMillis() / 1000; 35 | 36 | times.updateWithNewSelectionIn(selectedProject); 37 | } 38 | 39 | @Test @DisplayName("is initialized with current timestamp") 40 | void is_initialized_with_current_timestamp() { 41 | SoftAssertions softly = new SoftAssertions(); 42 | softly.assertThat(times.onStartup()).isEqualTo(times.onNewProject()) 43 | .isEqualTo(times.onSelection()) 44 | .isBetween(before, after); 45 | softly.assertAll(); 46 | } 47 | 48 | @Test @DisplayName("returns the same instance when configured with a new selection") 49 | void returns_the_same_instance_when_configured_with_a_new_selection(@Mock IProject newProject) { 50 | assertThat(times).isSameAs(times.updateWithNewSelectionIn(newProject)); 51 | } 52 | 53 | @Test @DisplayName("does not reset time on startup on new selection") 54 | void does_not_reset_time_on_new_project_on_new_selection(@Mock IProject newProject) { 55 | long expectedTimeOnStartup = times.onStartup(); 56 | assertThat(times.updateWithNewSelectionIn(newProject).onStartup()).isEqualTo(expectedTimeOnStartup); 57 | } 58 | 59 | @Test @DisplayName("does not reset time on new project if selection is in the same project") 60 | void does_not_reset_time_on_new_project_if_selection_is_in_the_same_project() { 61 | long expectedTimeOnNewProject = times.onNewProject(); 62 | assertThat(times.updateWithNewSelectionIn(selectedProject).onNewProject()).isEqualTo(expectedTimeOnNewProject); 63 | } 64 | 65 | @Test @DisplayName("resets time on new project if selection is in the same project") 66 | void resets_time_on_new_project_if_selection_is_in_the_same_project() { 67 | long beforeNewSelection = System.currentTimeMillis() / 1000; 68 | SelectionTimes timesAtNewSelection = times.updateWithNewSelectionIn(selectedProject); 69 | long afterNewSelection = System.currentTimeMillis() / 1000; 70 | 71 | assertThat(timesAtNewSelection.onNewProject()).isBetween(beforeNewSelection, afterNewSelection); 72 | } 73 | 74 | @Test @DisplayName("resets time on selection if selection changes") 75 | void resets_time_on__selection_if_selection_changes() { 76 | long beforeNewSelection = System.currentTimeMillis() / 1000; 77 | SelectionTimes timesAtNewSelection = times.updateWithNewSelectionIn(selectedProject); 78 | long afterNewSelection = System.currentTimeMillis() / 1000; 79 | 80 | assertThat(timesAtNewSelection.onSelection()).isBetween(beforeNewSelection, afterNewSelection); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/src/fr/kazejiyu/discord/rpc/integration/extensions/EditorInputToRichPresenceAdapterTest.java: -------------------------------------------------------------------------------- 1 | package fr.kazejiyu.discord.rpc.integration.extensions; 2 | 3 | import static org.mockito.ArgumentMatchers.any; 4 | import static org.mockito.Mockito.when; 5 | 6 | import org.assertj.core.api.WithAssertions; 7 | import org.junit.jupiter.api.BeforeEach; 8 | import org.junit.jupiter.api.DisplayName; 9 | import org.junit.jupiter.api.Test; 10 | import org.junit.jupiter.api.extension.ExtendWith; 11 | import org.mockito.Mock; 12 | 13 | import fr.kazejiyu.discord.rpc.integration.extensions.EditorInputToRichPresenceAdapter; 14 | import fr.kazejiyu.discord.rpc.integration.tests.mock.MockitoExtension; 15 | 16 | /** 17 | * Unit test the {@link EditorInputToRichPresenceAdapter} class. 18 | */ 19 | @ExtendWith(MockitoExtension.class) 20 | @DisplayName("An EditorInputRichPresence") 21 | public class EditorInputToRichPresenceAdapterTest implements WithAssertions { 22 | 23 | @Mock 24 | private EditorInputToRichPresenceAdapter iut; 25 | 26 | @Mock 27 | private EditorInputToRichPresenceAdapter compared; 28 | 29 | @BeforeEach 30 | private void setupMockToCallRealMethod() { 31 | when(iut.compareTo(any(EditorInputToRichPresenceAdapter.class))).thenCallRealMethod(); 32 | } 33 | 34 | @Test @DisplayName("returns a negative integer when compared to another object with a greater priority") 35 | void returns_a_negative_integer_when_compared_to_another_object_with_a_greater_priority() { 36 | when(iut.getPriority()).thenReturn(5); 37 | when(compared.getPriority()).thenReturn(12); 38 | 39 | assertThat(iut.compareTo(compared)).isLessThan(0); 40 | } 41 | 42 | @Test @DisplayName("returns a positive integer when compared to another object with a lower priority") 43 | void returns_a_positive_integer_when_compared_to_another_object_with_a_lower_priority() { 44 | when(iut.getPriority()).thenReturn(-5); 45 | when(compared.getPriority()).thenReturn(-12); 46 | 47 | assertThat(iut.compareTo(compared)).isGreaterThan(0); 48 | } 49 | 50 | @Test @DisplayName("returns zero when compared to another object with an equal priority") 51 | void returns_zero_when_compared_to_another_object_with_an_equal_priority() { 52 | when(iut.getPriority()).thenReturn(5); 53 | when(compared.getPriority()).thenReturn(5); 54 | 55 | assertThat(iut.compareTo(compared)).isZero(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/src/fr/kazejiyu/discord/rpc/integration/extensions/internal/ChildOfIEditorInput.java: -------------------------------------------------------------------------------- 1 | package fr.kazejiyu.discord.rpc.integration.extensions.internal; 2 | 3 | import org.eclipse.jface.resource.ImageDescriptor; 4 | import org.eclipse.ui.IEditorInput; 5 | import org.eclipse.ui.IPersistableElement; 6 | 7 | /** 8 | * A simple fake class that extends IEditorInput. 9 | */ 10 | public class ChildOfIEditorInput implements IEditorInput { 11 | 12 | @Override 13 | public T getAdapter(Class adapter) { 14 | return null; 15 | } 16 | 17 | @Override 18 | public boolean exists() { 19 | return false; 20 | } 21 | 22 | @Override 23 | public ImageDescriptor getImageDescriptor() { 24 | return null; 25 | } 26 | 27 | @Override 28 | public String getName() { 29 | return null; 30 | } 31 | 32 | @Override 33 | public IPersistableElement getPersistable() { 34 | return null; 35 | } 36 | 37 | @Override 38 | public String getToolTipText() { 39 | return null; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/src/fr/kazejiyu/discord/rpc/integration/extensions/internal/EditorRichPresenceFromExtensionsTest.java: -------------------------------------------------------------------------------- 1 | package fr.kazejiyu.discord.rpc.integration.extensions.internal; 2 | 3 | import static org.mockito.Mockito.mock; 4 | import static org.mockito.Mockito.when; 5 | 6 | import org.assertj.core.api.WithAssertions; 7 | import org.eclipse.core.runtime.CoreException; 8 | import org.eclipse.core.runtime.IConfigurationElement; 9 | import org.eclipse.core.runtime.IExtensionRegistry; 10 | import org.eclipse.ui.IEditorInput; 11 | import org.eclipse.ui.part.FileEditorInput; 12 | import org.junit.jupiter.api.BeforeEach; 13 | import org.junit.jupiter.api.DisplayName; 14 | import org.junit.jupiter.api.Nested; 15 | import org.junit.jupiter.api.Test; 16 | import org.junit.jupiter.api.extension.ExtendWith; 17 | import org.mockito.Mock; 18 | 19 | import fr.kazejiyu.discord.rpc.integration.Plugin; 20 | import fr.kazejiyu.discord.rpc.integration.extensions.EditorInputToRichPresenceAdapter; 21 | import fr.kazejiyu.discord.rpc.integration.tests.mock.MockitoExtension; 22 | 23 | /** 24 | * Unit test the {@link EditorRichPresenceFromExtensions} class. 25 | */ 26 | @ExtendWith(MockitoExtension.class) 27 | @DisplayName("An EditorRichPresenceFromExtensions") 28 | public class EditorRichPresenceFromExtensionsTest implements WithAssertions { 29 | 30 | EditorRichPresenceFromExtensions adapters; 31 | 32 | @Mock 33 | IExtensionRegistry registry; 34 | 35 | EditorInputToRichPresenceAdapter expectedAdapter; 36 | 37 | @BeforeEach 38 | void setup() throws CoreException { 39 | adapters = new EditorRichPresenceFromExtensions(registry); 40 | 41 | expectedAdapter = new FakeEditorInputRichPresence(50, GrandchildOfIEditorInput.class); 42 | 43 | // Create different elements to test all cases 44 | // Test cases should be smaller, but... 45 | 46 | IConfigurationElement notAnEditorInputRichPresence = elementThatCreates(this); 47 | IConfigurationElement nullEditorInputRichPresence = elementThatCreates(null); 48 | IConfigurationElement highPriorityButWrongInput = 49 | elementThatCreates(new FakeEditorInputRichPresence(100, FileEditorInput.class)); 50 | IConfigurationElement highPriorityButLessAccurate = 51 | elementThatCreates(new FakeEditorInputRichPresence(80, ChildOfIEditorInput.class)); 52 | IConfigurationElement accurateAndHighPriority = 53 | elementThatCreates(expectedAdapter); 54 | IConfigurationElement accurateButLowPriority = 55 | elementThatCreates(new FakeEditorInputRichPresence(30, GrandchildOfIEditorInput.class)); 56 | 57 | IConfigurationElement[] elements = new IConfigurationElement[] { 58 | notAnEditorInputRichPresence, nullEditorInputRichPresence, 59 | highPriorityButWrongInput, highPriorityButLessAccurate, 60 | accurateAndHighPriority, accurateButLowPriority 61 | }; 62 | 63 | when(registry.getConfigurationElementsFor(Plugin.EDITOR_INPUT_ADAPTER_EXTENSION_ID)) 64 | .thenReturn(elements); 65 | } 66 | 67 | @Nested @DisplayName("during instanciation") 68 | class DuringInstanciation { 69 | 70 | @Test @DisplayName("throws if registry is null") 71 | void throws_if_registry_is_null() { 72 | assertThatNullPointerException().isThrownBy(() -> 73 | new EditorRichPresenceFromExtensions(null) 74 | ); 75 | } 76 | 77 | } 78 | 79 | @Nested @DisplayName("when no adapter can handle the input") 80 | class WhenNoAdapterCanHandleTheInput { 81 | 82 | @Test @DisplayName("returns nothing") 83 | void returns_nothing(@Mock IEditorInput input) { 84 | assertThat(adapters.findAdapterFor(input)).isEmpty(); 85 | } 86 | 87 | } 88 | 89 | @Test @DisplayName("finds the right adapter") 90 | void finds_the_right_adapter() { 91 | assertThat(adapters.findAdapterFor(new GrandchildOfIEditorInput())) 92 | .contains(expectedAdapter); 93 | } 94 | 95 | private static IConfigurationElement elementThatCreates(Object editorInputRichPresence) throws CoreException { 96 | IConfigurationElement element = mock(IConfigurationElement.class); 97 | when(element.createExecutableExtension("class")).thenReturn(editorInputRichPresence); 98 | return element; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/src/fr/kazejiyu/discord/rpc/integration/extensions/internal/FakeEditorInputRichPresence.java: -------------------------------------------------------------------------------- 1 | package fr.kazejiyu.discord.rpc.integration.extensions.internal; 2 | 3 | import java.util.Optional; 4 | 5 | import org.eclipse.ui.IEditorInput; 6 | 7 | import fr.kazejiyu.discord.rpc.integration.core.RichPresence; 8 | import fr.kazejiyu.discord.rpc.integration.extensions.EditorInputToRichPresenceAdapter; 9 | import fr.kazejiyu.discord.rpc.integration.settings.GlobalPreferences; 10 | 11 | /** 12 | * A fake {@link EditorInputToRichPresenceAdapter} which priority and input class can be parameterized. 13 | */ 14 | public class FakeEditorInputRichPresence implements EditorInputToRichPresenceAdapter { 15 | 16 | private final int priority; 17 | 18 | private final Class inputClass; 19 | 20 | /** 21 | * Creates a new fake. 22 | * 23 | * @param priority 24 | * Fake's priority. 25 | * @param inputClass 26 | * Fake's expected input class. 27 | */ 28 | public FakeEditorInputRichPresence(int priority, Class inputClass) { 29 | this.priority = priority; 30 | this.inputClass = inputClass; 31 | } 32 | 33 | @Override 34 | public int getPriority() { 35 | return priority; 36 | } 37 | 38 | @Override 39 | public Class getExpectedEditorInputClass() { 40 | return inputClass; 41 | } 42 | 43 | @Override 44 | public Optional createRichPresence(GlobalPreferences preferences, IEditorInput input) { 45 | return Optional.empty(); 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "FakeEditorInputRichPresence [priority=" + priority + ", inputClass=" + inputClass + "]"; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/src/fr/kazejiyu/discord/rpc/integration/extensions/internal/GrandchildOfIEditorInput.java: -------------------------------------------------------------------------------- 1 | package fr.kazejiyu.discord.rpc.integration.extensions.internal; 2 | 3 | /** 4 | *

A simple fake class that extends ChildOfIEditorInput.

5 | * 6 | *

This class is used to test resolution of extensions in {@link EditorRichPresenceFromExtensionsTest}.

7 | */ 8 | public class GrandchildOfIEditorInput extends ChildOfIEditorInput { 9 | 10 | 11 | } 12 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/src/fr/kazejiyu/discord/rpc/integration/extensions/internal/UnknownInputRichPresenceTest.java: -------------------------------------------------------------------------------- 1 | package fr.kazejiyu.discord.rpc.integration.extensions.internal; 2 | 3 | import java.util.Optional; 4 | 5 | import org.assertj.core.api.WithAssertions; 6 | import org.eclipse.ui.IEditorInput; 7 | import org.junit.jupiter.api.BeforeEach; 8 | import org.junit.jupiter.api.DisplayName; 9 | import org.junit.jupiter.api.Test; 10 | import org.junit.jupiter.api.extension.ExtendWith; 11 | 12 | import fr.kazejiyu.discord.rpc.integration.core.RichPresence; 13 | import fr.kazejiyu.discord.rpc.integration.extensions.internal.UnknownInputRichPresence; 14 | import fr.kazejiyu.discord.rpc.integration.tests.mock.MockitoExtension; 15 | 16 | /** 17 | * Unit test the {@link UnknownInputRichPresence} class. 18 | */ 19 | @ExtendWith(MockitoExtension.class) 20 | @DisplayName("An UnkownInputRichPresence") 21 | public class UnknownInputRichPresenceTest implements WithAssertions { 22 | 23 | private UnknownInputRichPresence adapter; 24 | 25 | @BeforeEach 26 | void instanciate() { 27 | adapter = new UnknownInputRichPresence(); 28 | } 29 | 30 | @Test @DisplayName("has the lower possible priority") 31 | void has_the_lower_priority() { 32 | assertThat(adapter.getPriority()).isEqualTo(Integer.MIN_VALUE); 33 | } 34 | 35 | @Test @DisplayName("expects any instance of IEditorInput") 36 | void expects_any_instance_of_IEditorInput() { 37 | assertThat(adapter.getExpectedEditorInputClass()).isEqualTo(IEditorInput.class); 38 | } 39 | 40 | @Test @DisplayName("can create presences") 41 | void can_create_presences() { 42 | assertThat(adapter.createRichPresence(null, null)).isNotEmpty(); 43 | } 44 | 45 | @Test @DisplayName("creates presences holding no state") 46 | void creates_presences_holding_no_state() { 47 | Optional presence = adapter.createRichPresence(null, null); 48 | assertThat(presence.get().getState()).isEmpty(); 49 | } 50 | 51 | @Test @DisplayName("creates presences holding no details") 52 | void creates_presences_holding_no_details() { 53 | Optional presence = adapter.createRichPresence(null, null); 54 | assertThat(presence.get().getDetails()).isEmpty(); 55 | } 56 | 57 | @Test @DisplayName("creates presences holding no language") 58 | void creates_presences_holding_no_language() { 59 | Optional presence = adapter.createRichPresence(null, null); 60 | assertThat(presence.get().getLanguage()).isEmpty(); 61 | } 62 | 63 | @Test @DisplayName("creates presences holding no text for the large image") 64 | void creates_presences_holding_no_text_for_the_large_image() { 65 | Optional presence = adapter.createRichPresence(null, null); 66 | assertThat(presence.get().getLargeImageText()).isEmpty(); 67 | } 68 | 69 | @Test @DisplayName("creates presences holding no start timestamp") 70 | void creates_presences_holding_no_start_timestamp() { 71 | Optional presence = adapter.createRichPresence(null, null); 72 | assertThat(presence.get().getStartTimestamp()).isEmpty(); 73 | } 74 | 75 | @Test @DisplayName("creates presences holding no project") 76 | void creates_presences_holding_no_project() { 77 | Optional presence = adapter.createRichPresence(null, null); 78 | assertThat(presence.get().getProject()).isEmpty(); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/src/fr/kazejiyu/discord/rpc/integration/languages/LanguageTest.java: -------------------------------------------------------------------------------- 1 | package fr.kazejiyu.discord.rpc.integration.languages; 2 | 3 | import java.util.stream.Stream; 4 | 5 | import org.assertj.core.api.WithAssertions; 6 | import org.junit.jupiter.api.DisplayName; 7 | import org.junit.jupiter.params.ParameterizedTest; 8 | import org.junit.jupiter.params.provider.Arguments; 9 | import org.junit.jupiter.params.provider.MethodSource; 10 | import org.junit.jupiter.params.provider.ValueSource; 11 | 12 | import fr.kazejiyu.discord.rpc.integration.languages.Language; 13 | 14 | /** 15 | * Unit test the {@link Language} enumeration. 16 | */ 17 | @DisplayName("A Language") 18 | public class LanguageTest implements WithAssertions { 19 | 20 | @ParameterizedTest 21 | @MethodSource("specialFileNames") 22 | @DisplayName("can be found from the exact name of a file") 23 | void according_to_the_exact_name_of_the_file(String fileName, Language expectedLanguage) { 24 | assertThat(Language.fromFileName(fileName)).isEqualTo(expectedLanguage); 25 | } 26 | 27 | @ParameterizedTest 28 | @ValueSource(strings= {"", "some file", "anotherone.", "pom", "xml", "md", ".cpp", ".classpath"}) 29 | @DisplayName("cannot be found when the file has no extension") 30 | void but_not_when_the_file_has_no_extension(String fileName) { 31 | assertThat(Language.fromFileName(fileName)).isEqualTo(Language.UNKNOWN); 32 | } 33 | 34 | @ParameterizedTest 35 | @ValueSource(strings= {"a.blo"}) 36 | @DisplayName("cannot be found when the extension is unknown") 37 | void but_not_when_the_extension_is_unkown(String fileName) { 38 | assertThat(Language.fromFileName(fileName)).isEqualTo(Language.UNKNOWN); 39 | } 40 | 41 | @ParameterizedTest 42 | @MethodSource("fileNamesForAllExtensions") 43 | @DisplayName("can be found according to the extension of the file") 44 | void according_to_the_extension_of_the_file(String fileName, Language expectedLanguage) { 45 | assertThat(Language.fromFileName(fileName)).isEqualTo(expectedLanguage); 46 | } 47 | 48 | static Stream fileNamesForAllExtensions() { 49 | Stream.Builder fileNames = Stream.builder(); 50 | 51 | for (Language language : Language.values()) { 52 | for (String extension : language.getFileExtensions()) { 53 | fileNames.add(Arguments.of("a." + extension, language)); 54 | } 55 | } 56 | return fileNames.build(); 57 | } 58 | 59 | static Stream specialFileNames() { 60 | Stream.Builder fileNames = Stream.builder(); 61 | 62 | for (Language language : Language.values()) { 63 | for (String fileName : language.getFileNames()) { 64 | fileNames.add(Arguments.of(fileName, language)); 65 | } 66 | } 67 | return fileNames.build(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/src/fr/kazejiyu/discord/rpc/integration/tests/mock/MockitoExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package fr.kazejiyu.discord.rpc.integration.tests.mock; 12 | 13 | import static org.mockito.Mockito.mock; 14 | 15 | import java.lang.reflect.Parameter; 16 | 17 | import org.junit.jupiter.api.extension.ExtensionContext; 18 | import org.junit.jupiter.api.extension.ExtensionContext.Namespace; 19 | import org.junit.jupiter.api.extension.ExtensionContext.Store; 20 | import org.junit.jupiter.api.extension.ParameterContext; 21 | import org.junit.jupiter.api.extension.ParameterResolver; 22 | import org.junit.jupiter.api.extension.TestInstancePostProcessor; 23 | import org.mockito.Mock; 24 | import org.mockito.MockitoAnnotations; 25 | 26 | /** 27 | * Inject mocks into JUnit tests. 28 | */ 29 | public class MockitoExtension implements TestInstancePostProcessor, ParameterResolver { 30 | 31 | @Override 32 | public void postProcessTestInstance(Object testInstance, ExtensionContext context) { 33 | MockitoAnnotations.initMocks(testInstance); 34 | } 35 | 36 | @Override 37 | public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { 38 | return parameterContext.getParameter().isAnnotationPresent(Mock.class); 39 | } 40 | 41 | @Override 42 | public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { 43 | return getMock(parameterContext.getParameter(), extensionContext); 44 | } 45 | 46 | private Object getMock(Parameter parameter, ExtensionContext extensionContext) { 47 | 48 | Class mockType = parameter.getType(); 49 | Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType)); 50 | String mockName = getMockName(parameter); 51 | 52 | if (mockName != null) { 53 | return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName)); 54 | } 55 | else { 56 | return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType)); 57 | } 58 | } 59 | 60 | private String getMockName(Parameter parameter) { 61 | String explicitMockName = parameter.getAnnotation(Mock.class).name().trim(); 62 | if (!explicitMockName.isEmpty()) { 63 | return explicitMockName; 64 | } 65 | else if (parameter.isNamePresent()) { 66 | return parameter.getName(); 67 | } 68 | return null; 69 | } 70 | } -------------------------------------------------------------------------------- /tests/fr.kazejiyu.discord.rpc.integration.tests/src/fr/kazejiyu/discord/rpc/integration/tests/mock/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Mocking utilities. 3 | */ 4 | package fr.kazejiyu.discord.rpc.integration.tests.mock; -------------------------------------------------------------------------------- /tests/org.assertj/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/org.assertj/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.assertj 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/org.assertj/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /tests/org.assertj/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: AssertJ 4 | Bundle-SymbolicName: org.assertj 5 | Bundle-Version: 3.9.0 6 | Bundle-ClassPath: assertj-core-3.9.0.jar 7 | Export-Package: org.assertj.core.api, 8 | org.assertj.core.api.exception, 9 | org.assertj.core.api.filter, 10 | org.assertj.core.api.iterable, 11 | org.assertj.core.condition, 12 | org.assertj.core.configuration, 13 | org.assertj.core.data, 14 | org.assertj.core.description, 15 | org.assertj.core.error, 16 | org.assertj.core.error.future, 17 | org.assertj.core.error.uri, 18 | org.assertj.core.extractor, 19 | org.assertj.core.groups, 20 | org.assertj.core.internal, 21 | org.assertj.core.internal.asm, 22 | org.assertj.core.internal.asm.signature, 23 | org.assertj.core.internal.cglib.asm, 24 | org.assertj.core.internal.cglib.beans, 25 | org.assertj.core.internal.cglib.core, 26 | org.assertj.core.internal.cglib.core.internal, 27 | org.assertj.core.internal.cglib.proxy, 28 | org.assertj.core.internal.cglib.reflect, 29 | org.assertj.core.internal.cglib.transform, 30 | org.assertj.core.internal.cglib.transform.impl, 31 | org.assertj.core.internal.cglib.util, 32 | org.assertj.core.matcher, 33 | org.assertj.core.presentation, 34 | org.assertj.core.util, 35 | org.assertj.core.util.diff, 36 | org.assertj.core.util.diff.myers, 37 | org.assertj.core.util.introspection, 38 | org.assertj.core.util.xml 39 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 40 | Automatic-Module-Name: org.assertj 41 | -------------------------------------------------------------------------------- /tests/org.assertj/assertj-core-3.9.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/echebbi/eclipse-discord-integration/f0b152d6b54df06255d0b53a4b0e0389204ad916/tests/org.assertj/assertj-core-3.9.0.jar -------------------------------------------------------------------------------- /tests/org.assertj/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = META-INF/,\ 2 | assertj-core-3.9.0.jar 3 | -------------------------------------------------------------------------------- /tests/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | tests 5 | pom 6 | 7 | 8 | fr.kazejiyu.discord.rpc.integration 9 | fr.kazejiyu.discord.rpc.integration.root 10 | 1.2.2 11 | 12 | 13 | 14 | org.assertj 15 | fr.kazejiyu.discord.rpc.integration.tests 16 | fr.kazejiyu.discord.rpc.integration.adapters.tests 17 | fr.kazejiyu.discord.rpc.integration.tests.report 18 | 19 | 20 | 21 | 0.8.2 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.eclipse.tycho 32 | tycho-surefire-plugin 33 | ${tycho.version} 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | jacoco 42 | 43 | false 44 | 45 | 46 | 47 | 48 | org.jacoco 49 | jacoco-maven-plugin 50 | ${jacoco-version} 51 | 52 | 53 | 54 | **/integration/Plugin.class 55 | **/integration/Activator.class 56 | 57 | 58 | 59 | 60 | 61 | prepare-agent 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | --------------------------------------------------------------------------------