1 package com.atlassian.plugins.codegen.modules.common.licensing;
2
3 import com.atlassian.plugins.codegen.ArtifactDependency;
4 import com.atlassian.plugins.codegen.BundleInstruction;
5 import com.atlassian.plugins.codegen.ClassId;
6 import com.atlassian.plugins.codegen.ComponentDeclaration;
7 import com.atlassian.plugins.codegen.ComponentImport;
8 import com.atlassian.plugins.codegen.PluginArtifact;
9 import com.atlassian.plugins.codegen.PluginProjectChangeset;
10 import com.atlassian.plugins.codegen.VersionId;
11 import com.atlassian.plugins.codegen.annotations.BambooPluginModuleCreator;
12 import com.atlassian.plugins.codegen.annotations.ConfluencePluginModuleCreator;
13 import com.atlassian.plugins.codegen.annotations.CrowdPluginModuleCreator;
14 import com.atlassian.plugins.codegen.annotations.FeCruPluginModuleCreator;
15 import com.atlassian.plugins.codegen.annotations.JiraPluginModuleCreator;
16 import com.atlassian.plugins.codegen.annotations.RefAppPluginModuleCreator;
17 import com.atlassian.plugins.codegen.annotations.StashPluginModuleCreator;
18 import com.atlassian.plugins.codegen.modules.AbstractPluginModuleCreator;
19 import com.atlassian.plugins.codegen.modules.BasicClassModuleProperties;
20 import com.atlassian.plugins.codegen.modules.common.servlet.ServletModuleCreator;
21 import com.atlassian.plugins.codegen.modules.common.servlet.ServletProperties;
22
23 import static com.atlassian.fugue.Option.some;
24 import static com.atlassian.plugins.codegen.ArtifactDependency.dependency;
25 import static com.atlassian.plugins.codegen.ArtifactDependency.Scope.COMPILE;
26 import static com.atlassian.plugins.codegen.ArtifactDependency.Scope.PROVIDED;
27 import static com.atlassian.plugins.codegen.ArtifactId.artifactId;
28 import static com.atlassian.plugins.codegen.BundleInstruction.dynamicImportPackage;
29 import static com.atlassian.plugins.codegen.BundleInstruction.privatePackage;
30 import static com.atlassian.plugins.codegen.ClassId.fullyQualified;
31 import static com.atlassian.plugins.codegen.ComponentDeclaration.componentDeclaration;
32 import static com.atlassian.plugins.codegen.ComponentImport.componentImport;
33 import static com.atlassian.plugins.codegen.MavenPlugin.mavenPlugin;
34 import static com.atlassian.plugins.codegen.PluginArtifact.pluginArtifact;
35 import static com.atlassian.plugins.codegen.PluginArtifact.ArtifactType.BUNDLED_ARTIFACT;
36 import static com.atlassian.plugins.codegen.PluginParameter.pluginParameter;
37 import static com.atlassian.plugins.codegen.ResourceFile.resourceFile;
38 import static com.atlassian.plugins.codegen.VersionId.noVersion;
39 import static com.atlassian.plugins.codegen.VersionId.version;
40 import static com.atlassian.plugins.codegen.VersionId.versionProperty;
41 import static com.atlassian.plugins.codegen.modules.Dependencies.APPLICATION_PROPERTIES_IMPORT;
42 import static com.atlassian.plugins.codegen.modules.Dependencies.COMMONS_LANG;
43 import static com.atlassian.plugins.codegen.modules.Dependencies.I18N_RESOLVER_IMPORT;
44 import static com.atlassian.plugins.codegen.modules.Dependencies.SAL_API;
45 import static com.atlassian.plugins.codegen.modules.Dependencies.TEMPLATE_RENDERER_API;
46 import static com.atlassian.plugins.codegen.modules.Dependencies.TEMPLATE_RENDERER_IMPORT;
47
48
49
50
51 @RefAppPluginModuleCreator
52 @JiraPluginModuleCreator
53 @ConfluencePluginModuleCreator
54 @BambooPluginModuleCreator
55 @FeCruPluginModuleCreator
56 @CrowdPluginModuleCreator
57 @StashPluginModuleCreator
58 public class LicensingUpm1CompatibleModuleCreator extends AbstractPluginModuleCreator<LicensingProperties>
59 {
60 public static final String MODULE_NAME = "Licensing API Support";
61
62 public static final String LICENSE_SERVLET_TEMPLATE = "templates/common/licensing/LicenseServlet.java.vtl";
63 public static final String HELLO_WORLD_SERVLET_TEMPLATE = "templates/common/licensing/HelloWorldServlet.java.vtl";
64 public static final String LICENSE_SERVLET_VELOCITY_TEMPLATE = "templates/common/licensing/license-admin.vm";
65 public static final String PROPERTIES_TEMPLATE = "templates/common/licensing/license-admin.properties.vtl";
66
67 public static final ClassId LICENSE_STORAGE_MANAGER_CLASS = fullyQualified("com.atlassian.upm.license.storage.lib.ThirdPartyPluginLicenseStorageManagerImpl");
68 public static final ClassId PLUGIN_INSTALLER_CLASS = fullyQualified("com.atlassian.upm.license.storage.lib.PluginLicenseStoragePluginInstaller");
69 public static final ClassId MARKETPLACE_URI_FACTORY_CLASS = fullyQualified("com.atlassian.upm.license.storage.lib.AtlassianMarketplaceUriFactoryImpl");
70
71 public static final String LICENSE_SERVLET_NAME_I18N_KEY = "license-servlet.name";
72 public static final String LICENSE_SERVLET_DESCRIPTION_I18N_KEY = "license-servlet.description";
73
74 public static final String HELLO_WORLD_SERVLET_CLASS_NAME = "LicenseHelloWorldServlet";
75 public static final String HELLO_WORLD_SERVLET_NAME_I18N_KEY = "license-hello-world-servlet.name";
76 public static final String HELLO_WORLD_SERVLET_DESCRIPTION_I18N_KEY = "license-hello-world-servlet.description";
77
78 public static final String LICENSE_API_VERSION = "2.4.1";
79 public static final VersionId LICENSE_API_VERSION_PROPERTY = versionProperty("upm.license.compatibility.version", LICENSE_API_VERSION);
80
81 public static final String LICENSE_API_IMPORT_VERSION = "2.0.1";
82 public static final String STORAGE_PLUGIN_IMPORT_VERSION = "${upm.license.compatibility.version}";
83
84 public static final ArtifactDependency[] DEPENDENCIES = {
85 dependency("com.atlassian.upm", "plugin-license-storage-lib", LICENSE_API_VERSION_PROPERTY, COMPILE),
86 dependency("com.atlassian.upm", "plugin-license-storage-plugin", LICENSE_API_VERSION_PROPERTY, PROVIDED),
87 dependency("com.atlassian.upm", "licensing-api", LICENSE_API_VERSION_PROPERTY, PROVIDED),
88 dependency("com.atlassian.upm", "upm-api", LICENSE_API_VERSION_PROPERTY, PROVIDED),
89 SAL_API,
90 TEMPLATE_RENDERER_API,
91 COMMONS_LANG,
92 dependency("org.springframework.osgi", "spring-osgi-core", "1.1.3", PROVIDED)
93 };
94
95 public static final PluginArtifact[] BUNDLED_ARTIFACTS = {
96 pluginArtifact(BUNDLED_ARTIFACT, artifactId("com.atlassian.upm", "plugin-license-storage-plugin"), LICENSE_API_VERSION_PROPERTY)
97 };
98
99 public static final BundleInstruction[] BUNDLE_INSTRUCTIONS = {
100 privatePackage("com.atlassian.upm.license.storage.lib*"),
101 dynamicImportPackage("com.atlassian.upm.api.license", LICENSE_API_IMPORT_VERSION),
102 dynamicImportPackage("com.atlassian.upm.api.license.entity", LICENSE_API_IMPORT_VERSION),
103 dynamicImportPackage("com.atlassian.upm.api.util", LICENSE_API_IMPORT_VERSION),
104 dynamicImportPackage("com.atlassian.upm.license.storage.plugin", STORAGE_PLUGIN_IMPORT_VERSION)
105 };
106
107 public static final ComponentImport[] COMPONENT_IMPORTS = {
108 componentImport(fullyQualified("com.atlassian.plugin.PluginAccessor")),
109 componentImport(fullyQualified("com.atlassian.plugin.PluginController")),
110 componentImport(fullyQualified("com.atlassian.sal.api.transaction.TransactionTemplate")).key(some("txTemplate")),
111 APPLICATION_PROPERTIES_IMPORT,
112 TEMPLATE_RENDERER_IMPORT,
113 componentImport(fullyQualified("com.atlassian.sal.api.pluginsettings.PluginSettingsFactory")),
114 componentImport(fullyQualified("com.atlassian.sal.api.auth.LoginUriProvider")),
115 componentImport(fullyQualified("com.atlassian.sal.api.user.UserManager")),
116 I18N_RESOLVER_IMPORT
117 };
118
119 public static final ComponentDeclaration[] COMPONENTS = {
120 componentDeclaration(LICENSE_STORAGE_MANAGER_CLASS, "thirdPartyPluginLicenseStorageManager"),
121 componentDeclaration(PLUGIN_INSTALLER_CLASS, "pluginLicenseStoragePluginInstaller"),
122 componentDeclaration(MARKETPLACE_URI_FACTORY_CLASS, "atlassianMarketplaceUriFactory")
123 };
124
125 public static final String MAVEN_DEPENDENCY_PLUGIN_ID = "maven-dependency-plugin";
126 public static final String MAVEN_DEPENDENCY_PLUGIN_CONFIG = "<executions>" +
127 "<execution>" +
128 "<id>copy-storage-plugin</id>" +
129 "<phase>process-resources</phase>" +
130 "<goals><goal>copy-dependencies</goal></goals>" +
131 "<configuration>" +
132 "<outputDirectory>${project.build.outputDirectory}</outputDirectory>" +
133 "<includeArtifactIds>plugin-license-storage-plugin</includeArtifactIds>" +
134 "<stripVersion>true</stripVersion>" +
135 "</configuration>" +
136 "</execution>" +
137 "</executions>";
138
139 @Override
140 public PluginProjectChangeset createModule(LicensingProperties props) throws Exception
141 {
142 ClassId licenseServletClass = props.getClassId();
143 ServletProperties licenseServletProps = new ServletProperties(licenseServletClass.getFullName());
144 licenseServletProps.setUrlPattern("/" + props.getLicenseServletPath());
145 licenseServletProps.setNameI18nKey(LICENSE_SERVLET_NAME_I18N_KEY);
146 licenseServletProps.setDescriptionI18nKey(LICENSE_SERVLET_DESCRIPTION_I18N_KEY);
147 licenseServletProps.setCreateClass(false);
148 BasicClassModuleProperties licenseServletClassProps = new BasicClassModuleProperties(licenseServletClass.getFullName());
149 licenseServletClassProps.putAll(props);
150 PluginProjectChangeset licenseServlet = new ServletModuleCreator().createModule(licenseServletProps)
151 .with(createClass(licenseServletClassProps, LICENSE_SERVLET_TEMPLATE));
152
153 PluginProjectChangeset ret = new PluginProjectChangeset()
154 .with(DEPENDENCIES)
155 .with(BUNDLE_INSTRUCTIONS)
156 .with(BUNDLED_ARTIFACTS)
157 .with(mavenPlugin(artifactId(MAVEN_DEPENDENCY_PLUGIN_ID), noVersion(), MAVEN_DEPENDENCY_PLUGIN_CONFIG))
158 .with(pluginParameter("atlassian-licensing-enabled", "true"))
159 .with(COMPONENT_IMPORTS)
160 .with(COMPONENTS)
161 .with(licenseServlet)
162 .with(resourceFile("", "license-admin.vm", fromFile(LICENSE_SERVLET_VELOCITY_TEMPLATE)))
163 .with(createI18nStrings(props, PROPERTIES_TEMPLATE));
164
165 if (props.includeExamples())
166 {
167 ClassId helloWorldServletClass = props.getClassId().className(HELLO_WORLD_SERVLET_CLASS_NAME);
168 ServletProperties helloWorldServletProps = new ServletProperties(helloWorldServletClass.getFullName());
169 helloWorldServletProps.setUrlPattern("/" + props.getHelloWorldServletPath());
170 helloWorldServletProps.setCreateClass(false);
171 BasicClassModuleProperties helloWorldServletClassProps = new BasicClassModuleProperties(helloWorldServletClass.getFullName());
172 helloWorldServletClassProps.putAll(props);
173 helloWorldServletClassProps.setFullyQualifiedClassname(helloWorldServletClass.getFullName());
174 PluginProjectChangeset helloWorldServlet = new ServletModuleCreator().createModule(helloWorldServletProps)
175 .with(createClass(helloWorldServletClassProps, HELLO_WORLD_SERVLET_TEMPLATE));
176
177 ret = ret.with(helloWorldServlet);
178 }
179
180 return ret;
181 }
182
183 @Override
184 public String getModuleName()
185 {
186 return MODULE_NAME;
187 }
188 }