Skip to content

Commit cc6ca42

Browse files
authored
Merge pull request #237 from LumnitzF/feature/reintroduce_bundled_eclipse
Re-introduce bundled eclipse
2 parents 0bbd7f0 + 22d824a commit cc6ca42

27 files changed

+417
-523
lines changed

README.markdown

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Allows using Eclipse's Java code formatter directly from IntelliJ. Solves the problem of maintaining a common code style
44
in team environments where both IDEA and Eclipse are used.
55

6+
***Note:*** This project utilizes (and in some manners modifies) code licensed under [EPL-2.0](https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html). For more information see [lib/eclipse](lib/eclipse/README.md).
7+
68
---
79

810
### Sponsored by
@@ -19,10 +21,11 @@ Manage pull requests and conduct code reviews in your IDE with full source-tree
1921
- [Tutorial: Installing, Updating and Uninstalling Repository Plugins](http://www.jetbrains.com/idea/webhelp/installing-updating-and-uninstalling-repository-plugins.html)
2022
- [Plugin repository page](http://plugins.jetbrains.com/plugin/?idea&id=6546)
2123
2. Configure it
22-
1. Configure Eclipse location
24+
1. Configure Eclipse location (optional)
2325
- Install Eclipse
2426
- Got To IntelliJ Settings | Other Settings | Adapter for Eclipse Code Formatter
2527
- Set `Eclipse installation folder` (`/Users/xxx/Eclipse.app/Contents/Eclipse` for Mac)
28+
- Change `Java formatter version` to `Configured Eclipse installation folder`
2629
2. Configure formatter
2730
- Either, export formatter profiles to get a `*.xml` file
2831
1. Go to `Eclipse | Windows | Preferences | Java | Code Style | Formatter`

lib/eclipse/EPL-2.0.html

Lines changed: 300 additions & 0 deletions
Large diffs are not rendered by default.

lib/eclipse/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This directory contains a repackaged version of [`org.eclipse.jdt.core`](https://www.eclipse.org/jdt/core/) (sources can be found [here](https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tree/org.eclipse.jdt.core)), which is licensed under [EPL-2.0](https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html).
2+
3+
The original version was changed as follows:
4+
* It is repackaged together with all its dependencies into a single jar file ([`eclipse.jar`](eclipse.jar))
5+
* From all modules, the `META-INF/*.SF`, `META-INF/*.DSA`, `META-INF/*.RSA` and `plugin.xml` are removed
6+
7+
The "modified" source code can be found in [`eclipse-sources.jar`](eclipse-sources.jar).

lib/eclipse/eclipse-sources.jar

7.93 MB
Binary file not shown.

lib/eclipse/eclipse.jar

8.91 MB
Binary file not shown.

src/java/krasa/formatter/eclipse/JavaCodeFormatterFacade.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ private EclipseFormatterAdapter newCodeFormatter(LanguageLevel level, VirtualFil
9090

9191
try {
9292
ClassLoader classLoader;
93-
// if (settings.getEclipseVersion() == Settings.FormatterVersion.CUSTOM) {
94-
classLoader = getCustomClassloader(GlobalSettings.getInstance().getPathToEclipse());
95-
// } else {
96-
// classLoader = Classloaders.getEclipse();
97-
// }
93+
if (settings.getEclipseVersion() == Settings.FormatterVersion.CUSTOM) {
94+
classLoader = getCustomClassloader(GlobalSettings.getInstance().getPathToEclipse());
95+
} else {
96+
classLoader = Classloaders.getEclipse();
97+
}
9898

9999
Map<String, String> options = getEclipseProfileOptions(level, configFile, classLoader);
100100

src/java/krasa/formatter/plugin/Notifier.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,6 @@ public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
5353
showNotification(notification, psiFile.getProject());
5454
}
5555

56-
public void notifyEclipseLocationNotSet(Project project) {
57-
String content = "Please configure Eclipse's location for the Code Formatter plugin, bundled Eclipse was removed.";
58-
Notification notification = ProjectComponent.GROUP_DISPLAY_ID_ERROR.createNotification(content,
59-
NotificationType.WARNING);
60-
61-
notification.addAction(new AnAction("Open Settings") {
62-
@Override
63-
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
64-
notification.expire();
65-
ShowSettingsUtil.getInstance().showSettingsDialog(getEventProject(anActionEvent),
66-
"Adapter for Eclipse Code Formatter");
67-
}
68-
});
69-
showNotification(notification, project);
70-
}
71-
7256
void notifyFormattingWasDisabled(PsiFile psiFile) {
7357
Notification notification = ProjectComponent.GROUP_DISPLAY_ID_INFO.createNotification(
7458
psiFile.getName() + " - formatting was disabled for this file type", NotificationType.WARNING);

src/java/krasa/formatter/plugin/ProjectSettingsForm.form

Lines changed: 61 additions & 29 deletions
Large diffs are not rendered by default.

src/java/krasa/formatter/plugin/ProjectSettingsForm.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public class ProjectSettingsForm {
116116

117117
public JTextField pathToCustomEclipse;
118118
private JButton customEclipseLocationBrowse;
119+
private JRadioButton useEclipseNewest;
120+
private JRadioButton useEclipseCustom;
119121
private JLabel javaFormatterVersionLabel;
120122
private JRadioButton importOrdering451;
121123
private JRadioButton importOrdering452;
@@ -139,18 +141,17 @@ private void updateComponents() {
139141
enabledBy(new JComponent[]{eclipseSupportedFileTypesLabel, enableJavaFormatting, doNotFormatOtherFilesRadioButton,
140142
formatOtherFilesWithExceptionsRadioButton,
141143
importOrderPreferenceFileExample, importOrderConfigurationFromFileRadioButton,
142-
importOrderConfigurationManualRadioButton,
144+
importOrderConfigurationManualRadioButton, useEclipseNewest, useEclipseCustom,
143145
formatSelectedTextInAllFileTypes, useForLiveTemplates, importOrdering451, importOrdering452}, useEclipseFormatter);
144146

145147
enabledBy(new JComponent[]{pathToEclipsePreferenceFileJava, schemeEclipseJC,
146148
schemeEclipse, schemeCurrentProject,
147149
schemeEclipse21,
148150
schemeEclipseFile, eclipsePrefsExample, eclipsePreferenceFileJavaLabel, optimizeImportsCheckBox,
149-
eclipsePreferenceFilePathJavaBrowse, javaFormatterProfileLabel, javaFormatterProfile,
150-
importStyleLabel,
151+
eclipsePreferenceFilePathJavaBrowse, javaFormatterProfileLabel, javaFormatterProfile, customEclipseLocationBrowse, pathToCustomEclipse,
152+
useEclipseNewest, useEclipseCustom, javaFormatterVersionLabel, importStyleLabel,
151153
importOrdering451, importOrdering452}, enableJavaFormatting);
152154

153-
154155
enabledBy(new JComponent[]{importOrder, pathToImportOrderPreferenceFile, pathToImportOrderPreferenceFileBrowse, importOrderManualExample,
155156
importOrderPreferenceFileExample, importOrderConfigurationFromFileRadioButton, importOrderConfigurationManualRadioButton},
156157
optimizeImportsCheckBox);
@@ -458,6 +459,12 @@ public void actionPerformed(ActionEvent e) {
458459
BareBonesBrowserLaunch.openURL("http://plugins.intellij.net/plugin/?idea&id=6546");
459460
}
460461
});
462+
useEclipseNewest.addActionListener(new ActionListener() {
463+
@Override
464+
public void actionPerformed(ActionEvent e) {
465+
importOrdering452.setSelected(true);
466+
}
467+
});
461468
profileHelp.addActionListener(new ActionListener() {
462469
@Override
463470
public void actionPerformed(ActionEvent e) {
@@ -640,6 +647,8 @@ private void importFromInternal(Settings in) {
640647
doNotFormatOtherFilesRadioButton.setSelected(!in.isFormatOtherFileTypesWithIntelliJ());
641648
useDefaultFormatter.setSelected(Objects.equals(in.getFormatter(), Settings.Formatter.DEFAULT));
642649
useEclipseFormatter.setSelected(Objects.equals(in.getFormatter(), Settings.Formatter.ECLIPSE));
650+
useEclipseNewest.setSelected(Objects.equals(in.getEclipseVersion(), Settings.FormatterVersion.NEWEST));
651+
useEclipseCustom.setSelected(Objects.equals(in.getEclipseVersion(), Settings.FormatterVersion.CUSTOM));
643652
importOrdering451.setSelected(Objects.equals(in.getImportOrdering(), Settings.ImportOrdering.ECLIPSE_44));
644653
importOrdering452.setSelected(Objects.equals(in.getImportOrdering(), Settings.ImportOrdering.ECLIPSE_452));
645654
importOrderConfigurationFromFileRadioButton.setSelected(in.isImportOrderFromFile());
@@ -667,6 +676,11 @@ public Settings exportDisplayedSettings() {
667676
} else if (importOrdering452.isSelected()) {
668677
displayedSettings.setImportOrdering(Settings.ImportOrdering.ECLIPSE_452);
669678
}
679+
if (useEclipseNewest.isSelected()) {
680+
displayedSettings.setEclipseVersion(Settings.FormatterVersion.NEWEST);
681+
} else if (useEclipseCustom.isSelected()) {
682+
displayedSettings.setEclipseVersion(Settings.FormatterVersion.CUSTOM);
683+
}
670684

671685
if (schemeEclipse.isSelected()) {
672686
displayedSettings.setConfigType(Settings.ConfigType.ECLIPSE);
@@ -719,7 +733,7 @@ public void validate() throws ConfigurationException {
719733
throw new ConfigurationException("Path to Import Order file is not valid - the file does not exist");
720734
}
721735
}
722-
if (pathToCustomEclipse.isEnabled()) {
736+
if (pathToCustomEclipse.isEnabled() && useEclipseCustom.isSelected()) {
723737
if (StringUtils.isBlank(pathToCustomEclipse.getText())) {
724738
throw new ConfigurationException("Path to 'Eclipse installation folder' is not valid");
725739
}
@@ -741,6 +755,12 @@ private boolean customIsModified(Settings data) {
741755
if (useEclipseFormatter.isSelected() != Settings.Formatter.ECLIPSE.equals(data.getFormatter())) {
742756
return true;
743757
}
758+
if (useEclipseNewest.isSelected() != Settings.FormatterVersion.NEWEST.equals(data.getEclipseVersion())) {
759+
return true;
760+
}
761+
if (useEclipseCustom.isSelected() != Settings.FormatterVersion.CUSTOM.equals(data.getEclipseVersion())) {
762+
return true;
763+
}
744764
if (importOrdering451.isSelected() != Settings.ImportOrdering.ECLIPSE_44.equals(data.getImportOrdering())) {
745765
return true;
746766
}

src/java/krasa/formatter/settings/ProjectComponent.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ public void projectOpened() {
8080
}
8181

8282
public void installOrUpdate(@NotNull Settings settings) {
83-
if (settings.isEnabled()) {
84-
if (isBlank(GlobalSettings.getInstance().getPathToEclipse())) {
85-
new Notifier().notifyEclipseLocationNotSet(project);
86-
}
87-
}
8883
if (eclipseCodeStyleManager == null) {
8984
eclipseCodeStyleManager = projectCodeStyle.install(settings);
9085
} else {

0 commit comments

Comments
 (0)