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.PluginArtifact;
8 import com.atlassian.plugins.codegen.PluginProjectChangeset;
9 import com.atlassian.plugins.codegen.annotations.BambooPluginModuleCreator;
10 import com.atlassian.plugins.codegen.annotations.ConfluencePluginModuleCreator;
11 import com.atlassian.plugins.codegen.annotations.CrowdPluginModuleCreator;
12 import com.atlassian.plugins.codegen.annotations.FeCruPluginModuleCreator;
13 import com.atlassian.plugins.codegen.annotations.JiraPluginModuleCreator;
14 import com.atlassian.plugins.codegen.annotations.RefAppPluginModuleCreator;
15 import com.atlassian.plugins.codegen.modules.AbstractPluginModuleCreator;
16 import com.atlassian.plugins.codegen.modules.common.servlet.ServletModuleCreator;
17 import com.atlassian.plugins.codegen.modules.common.servlet.ServletProperties;
18
19 import com.google.common.collect.ImmutableMap;
20
21 import static com.atlassian.fugue.Option.none;
22 import static com.atlassian.fugue.Option.some;
23 import static com.atlassian.plugins.codegen.ArtifactDependency.dependency;
24 import static com.atlassian.plugins.codegen.ArtifactDependency.Scope.COMPILE;
25 import static com.atlassian.plugins.codegen.ArtifactDependency.Scope.PROVIDED;
26 import static com.atlassian.plugins.codegen.ArtifactId.artifactId;
27 import static com.atlassian.plugins.codegen.BundleInstruction.dynamicImportPackage;
28 import static com.atlassian.plugins.codegen.BundleInstruction.importPackage;
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.ComponentImport.componentImport;
32 import static com.atlassian.plugins.codegen.MavenPlugin.mavenPlugin;
33 import static com.atlassian.plugins.codegen.PluginArtifact.pluginArtifact;
34
35
36
37
38 @RefAppPluginModuleCreator
39 @JiraPluginModuleCreator
40 @ConfluencePluginModuleCreator
41 @BambooPluginModuleCreator
42 @FeCruPluginModuleCreator
43 @CrowdPluginModuleCreator
44 public class LicensingUpm1CompatibleModuleCreator extends AbstractPluginModuleCreator<LicensingProperties>
45 {
46 public static final String MODULE_NAME = "License Management (pre-UPM 2 Compatibility)";
47
48 public static final String LICENSE_SERVLET_TEMPLATE = "templates/common/licensing/LicenseServlet.java.vtl";
49 public static final String HELLO_WORLD_SERVLET_TEMPLATE = "templates/common/licensing/HelloWorldServlet.java.vtl";
50
51 public static final ClassId LICENSE_STORAGE_MANAGER_CLASS = fullyQualified("com.atlassian.upm.license.storage.lib.ThirdPartyPluginLicenseStorageManagerImpl");
52 public static final ClassId PLUGIN_INSTALLER_CLASS = fullyQualified("com.atlassian.upm.license.storage.lib.PluginLicenseStoragePluginInstaller");
53 public static final ClassId LICENSE_SERVLET_CLASS = fullyQualified("com.example.plugins.tutorial.compatibility.servlet.LicenseServlet");
54 public static final ClassId HELLO_WORLD_SERVLET_CLASS = fullyQualified("com.example.plugins.tutorial.compatibility.servlet.HelloWorldServlet");
55
56 public static final String LICENSE_SERVLET_URL_PATTERN = "/licenseservlet";
57 public static final String HELLO_WORLD_SERVLET_URL_PATTERN = "/helloworldservlet";
58
59 public static final String LICENSE_API_VERSION = "2.1-m5";
60 public static final String LICENSE_API_VERSION_PROPERTY = "upm.license.compatibility.version";
61
62 public static final ArtifactDependency[] DEPENDENCIES = {
63 dependency("com.atlassian.upm", "plugin-license-storage-lib", LICENSE_API_VERSION, LICENSE_API_VERSION_PROPERTY, COMPILE),
64 dependency("com.atlassian.upm", "plugin-license-storage-plugin", LICENSE_API_VERSION, LICENSE_API_VERSION_PROPERTY, PROVIDED),
65 dependency("com.atlassian.upm", "licensing-api", LICENSE_API_VERSION, LICENSE_API_VERSION_PROPERTY, PROVIDED),
66 dependency("com.atlassian.upm", "upm-api", LICENSE_API_VERSION, LICENSE_API_VERSION_PROPERTY, PROVIDED),
67 dependency("com.atlassian.sal", "sal-api", "2.4.0", PROVIDED),
68 dependency("org.springframework.osgi", "spring-osgi-core", "1.1.3", PROVIDED),
69 dependency("commons-lang", "commons-lang", "2.4", PROVIDED)
70 };
71
72 public static final PluginArtifact[] BUNDLED_ARTIFACTS = {
73 pluginArtifact(artifactId("com.atlassian.upm", "atlassian-universal-plugin-manager-plugin"), some("1.6.3"), none(String.class)),
74 pluginArtifact(artifactId("com.atlassian.upm", "plugin-license-storage-plugin"), some(LICENSE_API_VERSION), some(LICENSE_API_VERSION_PROPERTY))
75 };
76
77 public static final BundleInstruction[] BUNDLE_INSTRUCTIONS = {
78 importPackage("com.atlassian.plugin*", "0.0"),
79 importPackage("com.atlassian.sal*", "0.0"),
80 importPackage("com.google.common*", "1.0"),
81 importPackage("javax.servlet*", "0.0"),
82 importPackage("org.apache.commons*", "0.0"),
83 importPackage("org.osgi.framework*", "0.0"),
84 importPackage("org.osgi.util*", "0.0"),
85 importPackage("org.slf4j*", "1.5"),
86 importPackage("org.springframework.beans*", "0.0"),
87 importPackage("org.springframework.context*", "0.0"),
88 importPackage("org.springframework.osgi*", "0.0"),
89 privatePackage("com.atlassian.upm.license.storage.lib*"),
90 dynamicImportPackage("com.atlassian.upm.api.license", "2.0.1"),
91 dynamicImportPackage("com.atlassian.upm.api.license.entity", "2.0.1"),
92 dynamicImportPackage("com.atlassian.upm.api.util", "2.0.1"),
93 dynamicImportPackage("com.atlassian.upm.license.storage.plugin", "2.0.1")
94 };
95
96 public static final String MAVEN_DEPENDENCY_PLUGIN_ID = "maven-dependency-plugin";
97 public static final String MAVEN_DEPENDENCY_PLUGIN_CONFIG = "<executions>" +
98 "<execution>" +
99 "<id>copy-storage-plugin</id>" +
100 "<phase>process-resources</phase>" +
101 "<goals><goal>copy-dependencies</goal></goals>" +
102 "<configuration>" +
103 "<outputDirectory>${project.build.outputDirectory}</outputDirectory>" +
104 "<includeArtifactIds>plugin-license-storage-plugin</includeArtifactIds>" +
105 "<stripVersion>true</stripVersion>" +
106 "</configuration>" +
107 "</execution>" +
108 "</executions>";
109
110 @Override
111 public PluginProjectChangeset createModule(LicensingProperties props) throws Exception
112 {
113 ComponentDeclaration licenseStorageManagerComponent = ComponentDeclaration.builder(LICENSE_STORAGE_MANAGER_CLASS, "thirdPartyPluginLicenseStorageManager").build();
114 ComponentDeclaration pluginInstallerComponent = ComponentDeclaration.builder(PLUGIN_INSTALLER_CLASS, "pluginLicenseStoragePluginInstaller").build();
115
116 PluginProjectChangeset ret = new PluginProjectChangeset()
117 .withDependencies(DEPENDENCIES)
118 .withBundleInstructions(BUNDLE_INSTRUCTIONS)
119 .withBundledArtifacts(BUNDLED_ARTIFACTS)
120 .withMavenPlugins(mavenPlugin(artifactId(MAVEN_DEPENDENCY_PLUGIN_ID), none(String.class), MAVEN_DEPENDENCY_PLUGIN_CONFIG))
121 .withPluginParameters(ImmutableMap.of("atlassian-licensing-enabled", "true"))
122 .withComponentImports(componentImport(fullyQualified("com.atlassian.plugin.PluginAccessor")),
123 componentImport(fullyQualified("com.atlassian.plugin.PluginController")),
124 componentImport(fullyQualified("com.atlassian.sal.api.transaction.TransactionTemplate")).key(some("txTemplate")),
125 componentImport(fullyQualified("com.atlassian.sal.api.ApplicationProperties")))
126 .withComponentDeclarations(pluginInstallerComponent, licenseStorageManagerComponent);
127
128 if (props.includeExamples())
129 {
130 ServletProperties licenseServletProps = new ServletProperties(LICENSE_SERVLET_CLASS.getFullName());
131 licenseServletProps.setUrlPattern(LICENSE_SERVLET_URL_PATTERN);
132 licenseServletProps.setCreateClass(false);
133 ret = ret.with(new ServletModuleCreator().createModule(licenseServletProps))
134 .with(createClass(licenseServletProps, LICENSE_SERVLET_TEMPLATE));
135
136 ServletProperties helloWorldServletProps = new ServletProperties(HELLO_WORLD_SERVLET_CLASS.getFullName());
137 helloWorldServletProps.setUrlPattern(HELLO_WORLD_SERVLET_URL_PATTERN);
138 helloWorldServletProps.setCreateClass(false);
139 ret = ret.with(new ServletModuleCreator().createModule(helloWorldServletProps))
140 .with(createClass(helloWorldServletProps, HELLO_WORLD_SERVLET_TEMPLATE));
141 }
142
143 return ret;
144 }
145
146 @Override
147 public String getModuleName()
148 {
149 return MODULE_NAME;
150 }
151 }