Skip to content

Commit f86c358

Browse files
author
Vasilii Burlacu
committed
Made the licenses save into the composer files
1 parent 2ad8ba7 commit f86c358

File tree

6 files changed

+114
-25
lines changed

6 files changed

+114
-25
lines changed

resources/fileTemplates/internal/Magento Module Composer.json.ft

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
},
1010
#end
1111
#if (${LICENSE})
12-
"license": [
12+
"license":
1313
${LICENSE}
14-
],
14+
,
1515
#end
1616
"autoload": {
1717
"files": [

src/com/magento/idea/magento2plugin/actions/generation/data/ModuleComposerJsonData.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package com.magento.idea.magento2plugin.actions.generation.data;
66

77
import com.intellij.psi.PsiDirectory;
8+
import java.util.List;
89

910
public class ModuleComposerJsonData {
1011
private final String packageName;
@@ -13,21 +14,24 @@ public class ModuleComposerJsonData {
1314
private final String moduleDescription;
1415
private final String composerPackageName;
1516
private final String moduleVersion;
17+
private final List moduleLicense;
1618

1719
public ModuleComposerJsonData(
1820
String packageName,
1921
String moduleName,
2022
PsiDirectory baseDir,
2123
String moduleDescription,
2224
String composerPackageName,
23-
String moduleVersion
25+
String moduleVersion,
26+
List moduleLicense
2427
) {
2528
this.packageName = packageName;
2629
this.moduleName = moduleName;
2730
this.baseDir = baseDir;
2831
this.moduleDescription = moduleDescription;
2932
this.composerPackageName = composerPackageName;
3033
this.moduleVersion = moduleVersion;
34+
this.moduleLicense = moduleLicense;
3135
}
3236

3337
public String getPackageName() {
@@ -53,4 +57,8 @@ public String getComposerPackageName() {
5357
public String getModuleVersion() {
5458
return this.moduleVersion;
5559
}
60+
61+
public List getModuleLicense() {
62+
return this.moduleLicense;
63+
}
5664
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMagentoModuleDialog.form

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.magento.idea.magento2plugin.actions.generation.dialog.NewMagentoModuleDialog">
3-
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
3+
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="10" left="10" bottom="10" right="10"/>
55
<constraints>
6-
<xy x="48" y="54" width="638" height="433"/>
6+
<xy x="48" y="54" width="462" height="381"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
1010
<children>
1111
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1212
<margin top="0" left="0" bottom="0" right="0"/>
1313
<constraints>
14-
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
14+
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
1515
</constraints>
1616
<properties/>
1717
<border type="none"/>
@@ -49,7 +49,7 @@
4949
</grid>
5050
</children>
5151
</grid>
52-
<grid id="e3588" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
52+
<grid id="e3588" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
5353
<margin top="0" left="0" bottom="0" right="0"/>
5454
<constraints>
5555
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -59,7 +59,7 @@
5959
<children>
6060
<component id="ad3ba" class="javax.swing.JTextField" binding="packageName" default-binding="true">
6161
<constraints>
62-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
62+
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
6363
<preferred-size width="150" height="-1"/>
6464
</grid>
6565
</constraints>
@@ -78,7 +78,7 @@
7878
</component>
7979
<component id="e4858" class="javax.swing.JTextField" binding="moduleName">
8080
<constraints>
81-
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
81+
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
8282
<preferred-size width="150" height="-1"/>
8383
</grid>
8484
</constraints>
@@ -97,7 +97,7 @@
9797
</component>
9898
<component id="423dc" class="javax.swing.JTextField" binding="moduleVersion">
9999
<constraints>
100-
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
100+
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
101101
<preferred-size width="150" height="-1"/>
102102
</grid>
103103
</constraints>
@@ -116,24 +116,47 @@
116116
<text value="Module Version"/>
117117
</properties>
118118
</component>
119-
<component id="8bae" class="javax.swing.JList" binding="moduleLicense">
119+
<component id="c5925" class="javax.swing.JLabel" binding="moduleLicenseLabel">
120120
<constraints>
121-
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="9" fill="0" indent="0" use-parent-layout="false">
122-
<preferred-size width="100" height="50"/>
123-
</grid>
121+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
124122
</constraints>
125123
<properties>
126-
<toolTipText value="Module's Lincese"/>
124+
<text value="License(s)"/>
127125
</properties>
128126
</component>
129-
<component id="c5925" class="javax.swing.JLabel" binding="moduleLicenseLabel">
127+
<component id="26905" class="javax.swing.JTextField" binding="moduleLicenseCustom">
130128
<constraints>
131-
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
129+
<grid row="4" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false">
130+
<preferred-size width="150" height="-1"/>
131+
</grid>
132132
</constraints>
133133
<properties>
134-
<text value="License(s)"/>
134+
<editable value="false"/>
135+
<enabled value="false"/>
136+
<toolTipText value="Module's Custom License"/>
135137
</properties>
136138
</component>
139+
<scrollpane id="a545e" binding="moduleLicenseScrollPanel">
140+
<constraints>
141+
<grid row="3" column="1" row-span="1" col-span="2" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
142+
<preferred-size width="150" height="100"/>
143+
<maximum-size width="-1" height="100"/>
144+
</grid>
145+
</constraints>
146+
<properties>
147+
<enabled value="false"/>
148+
</properties>
149+
<border type="none"/>
150+
<children>
151+
<component id="8bae" class="javax.swing.JList" binding="moduleLicense">
152+
<constraints/>
153+
<properties>
154+
<model/>
155+
<toolTipText value="Module's Lincese"/>
156+
</properties>
157+
</component>
158+
</children>
159+
</scrollpane>
137160
</children>
138161
</grid>
139162
<component id="4c5ac" class="javax.swing.JTextArea" binding="moduleDescription">

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMagentoModuleDialog.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import javax.swing.*;
2828
import java.awt.*;
2929
import java.awt.event.*;
30+
import java.util.ArrayList;
31+
import java.util.List;
32+
import java.util.Vector;
3033

3134
public class NewMagentoModuleDialog extends AbstractDialog {
3235
@NotNull
@@ -57,7 +60,10 @@ public class NewMagentoModuleDialog extends AbstractDialog {
5760
private JLabel moduleVersionLabel;
5861
private JList moduleLicense;
5962
private JLabel moduleLicenseLabel;
63+
private JTextField moduleLicenseCustom;
64+
private JScrollPane moduleLicenseScrollPanel;
6065
private String detectedPackageName;
66+
private String[] licensesNames;
6167

6268
public NewMagentoModuleDialog(@NotNull Project project, @NotNull PsiDirectory initialBaseDir, @Nullable PsiFile file, @Nullable IdeView view, @Nullable Editor editor) {
6369
this.project = project;
@@ -70,16 +76,25 @@ public NewMagentoModuleDialog(@NotNull Project project, @NotNull PsiDirectory in
7076
this.camelCaseToHyphen = CamelCaseToHyphen.getInstance();
7177
this.validator = NewMagentoModuleDialogValidator.getInstance(this);
7278
this.navigateToCreatedFile = NavigateToCreatedFile.getInstance();
79+
80+
Package.License[] licenses = Package.License.values();
81+
Vector licenseNames = new Vector<String>(licenses.length);
82+
83+
for (Package.License license: licenses) {
84+
// licensesNames.push(license.getLicenseName());
85+
licenseNames.add(license.getLicenseName());
86+
}
87+
88+
// moduleLicense.setListData(licenses);
89+
moduleLicense.setListData(licenseNames);
90+
moduleLicense.setSelectedIndex(0);
91+
7392
detectPackageName(initialBaseDir);
7493
setContentPane(contentPane);
7594
setModal(true);
7695
getRootPane().setDefaultButton(buttonOK);
7796
pushToMiddle();
7897

79-
String licenses[] = {"license 1", "license 2"};
80-
81-
moduleLicense.setListData(licenses);
82-
8398
buttonOK.addActionListener(new ActionListener() {
8499
public void actionPerformed(ActionEvent e) {
85100
onOK();
@@ -143,7 +158,8 @@ private PsiFile generateComposerJson() {
143158
getBaseDir(),
144159
getModuleDescription(),
145160
getComposerPackageName(),
146-
getModuleVersion()
161+
getModuleVersion(),
162+
getModuleLicense()
147163
), project).generate(NewModuleAction.ACTION_NAME);
148164
}
149165

@@ -187,7 +203,7 @@ public String getModuleVersion() {
187203
}
188204

189205
public List getModuleLicense() {
190-
return (List) this.moduleLicense.getSelectedValuesList();
206+
return this.moduleLicense.getSelectedValuesList();
191207
}
192208

193209
public static void open(@NotNull Project project, @NotNull PsiDirectory initialBaseDir, @Nullable PsiFile file, @Nullable IdeView view, @Nullable Editor editor) {

src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleComposerJsonGenerator.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.magento.idea.magento2plugin.magento.files.ComposerJson;
1414
import org.jetbrains.annotations.NotNull;
1515
import java.util.Properties;
16+
import java.util.List;
1617

1718
public class ModuleComposerJsonGenerator extends FileGenerator {
1819

@@ -38,5 +39,25 @@ protected void fillAttributes(Properties attributes) {
3839
attributes.setProperty("MODULE_DESCRIPTION", moduleComposerJsonData.getModuleDescription());
3940
attributes.setProperty("COMPOSER_PACKAGE_NAME", moduleComposerJsonData.getComposerPackageName());
4041
attributes.setProperty("MODULE_VERSION", moduleComposerJsonData.getModuleVersion());
42+
attributes.setProperty("LICENSE", this.getLicensesString(moduleComposerJsonData.getModuleLicense()));
43+
}
44+
45+
protected String getLicensesString(List licensesList) {
46+
String license = "[\n";
47+
Object[] licenses = licensesList.toArray();
48+
49+
for (int i = 0; i < licenses.length; i++) {
50+
license = license.concat("\"");
51+
license = license.concat(licenses[i].toString());
52+
license = license.concat("\"");
53+
54+
if (licenses.length != (i + 1)) license = license.concat(",");
55+
56+
license = license.concat("\n");
57+
}
58+
59+
license = license.concat("\n]");
60+
61+
return license;
4162
}
4263
}

src/com/magento/idea/magento2plugin/magento/packages/Package.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
package com.magento.idea.magento2plugin.magento.packages;
66

7-
import com.magento.idea.magento2plugin.magento.files.Plugin;
7+
import java.util.ArrayList;
88

99
public class Package {
1010
public static String PACKAGES_ROOT = "app/code";
@@ -23,6 +23,27 @@ public static enum Areas {
2323
graphql
2424
}
2525

26+
public static enum License {
27+
OSL("Open Software License (OSL)"),
28+
MPL("Mozilla Public License (MPL)"),
29+
MITL("Massachusetts Institute of Technology License (MITL)"),
30+
LGPL("GNU Lesser General Public License (LGPL)"),
31+
GPL("GNU General Public License (GPL)"),
32+
BSDL("Berkeley Software Distribution License (BSDL)"),
33+
ASL("Apache Software License (ASL)"),
34+
AFL("Academic Free License (AFL)");
35+
36+
private String licenseName;
37+
38+
License(String name) {
39+
this.licenseName = name;
40+
}
41+
42+
public String getLicenseName() {
43+
return licenseName;
44+
}
45+
}
46+
2647
public static Package.Areas getAreaByString(String string)
2748
{
2849
for (Package.Areas areas: Package.Areas.values()) {

0 commit comments

Comments
 (0)