From 9a6ebeb5a80bdb1d97d47422c62a973b3f2d2cf9 Mon Sep 17 00:00:00 2001 From: Mirjan Merruko Date: Fri, 24 Mar 2017 13:33:37 +0200 Subject: [PATCH] Add OSGi support #8830 #8827 #8828 #8829 Use bnd-maven-plugin instead of maven-bundle-plugin and helper class, and add support for publishing static resources such as themes and widgetsets. --- .../buildhelpers/GeneratePackageExports.java | 224 ------------------ client-compiled/bnd.bnd | 6 + client-compiled/pom.xml | 76 ++---- .../DefaultWidgetsetContribution.java | 47 ++++ compatibility-client-compiled/bnd.bnd | 6 + compatibility-client-compiled/pom.xml | 65 +---- .../CompatibilityWidgetsetContribution.java | 47 ++++ compatibility-server/bnd.bnd | 10 + compatibility-server/pom.xml | 32 +-- compatibility-shared/bnd.bnd | 6 + compatibility-shared/pom.xml | 26 +- compatibility-themes/bnd.bnd | 6 + compatibility-themes/pom.xml | 56 +---- .../themes/LegacyThemeContributions.java | 49 ++++ pom.xml | 41 +++- push/bnd.bnd | 6 + push/pom.xml | 38 ++- .../osgi/push/PushResourcesContribution.java | 51 ++++ server/bnd.bnd | 15 ++ server/pom.xml | 65 ++--- .../server/osgi/BootstrapContribution.java | 50 ++++ .../tests/server/ClassesSerializableTest.java | 2 + shared/bnd.bnd | 8 + shared/pom.xml | 34 +-- .../osgi/resources/OSGiVaadinResources.java | 86 +++++++ .../osgi/resources/VaadinResourceService.java | 97 ++++++++ .../impl/VaadinResourceServiceImpl.java | 97 ++++++++ themes/bnd.bnd | 6 + themes/pom.xml | 64 +---- .../osgi/themes/ValoThemeContribution.java | 45 ++++ 30 files changed, 784 insertions(+), 577 deletions(-) delete mode 100644 buildhelpers/src/main/java/com/vaadin/buildhelpers/GeneratePackageExports.java create mode 100644 client-compiled/bnd.bnd create mode 100644 client-compiled/src/main/java/com/vaadin/osgi/widgetset/DefaultWidgetsetContribution.java create mode 100644 compatibility-client-compiled/bnd.bnd create mode 100644 compatibility-client-compiled/src/main/java/com/vaadin/osgi/compatibility/widgetset/CompatibilityWidgetsetContribution.java create mode 100644 compatibility-server/bnd.bnd create mode 100644 compatibility-shared/bnd.bnd create mode 100644 compatibility-themes/bnd.bnd create mode 100644 compatibility-themes/src/main/java/com/vaadin/osgi/compatibility/themes/LegacyThemeContributions.java create mode 100644 push/bnd.bnd create mode 100644 push/src/main/java/com/vaadin/osgi/push/PushResourcesContribution.java create mode 100644 server/bnd.bnd create mode 100644 server/src/main/java/com/vaadin/server/osgi/BootstrapContribution.java create mode 100644 shared/bnd.bnd create mode 100644 shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinResources.java create mode 100644 shared/src/main/java/com/vaadin/osgi/resources/VaadinResourceService.java create mode 100644 shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceServiceImpl.java create mode 100644 themes/bnd.bnd create mode 100644 themes/src/main/java/com/vaadin/osgi/themes/ValoThemeContribution.java diff --git a/buildhelpers/src/main/java/com/vaadin/buildhelpers/GeneratePackageExports.java b/buildhelpers/src/main/java/com/vaadin/buildhelpers/GeneratePackageExports.java deleted file mode 100644 index 9717c353531..00000000000 --- a/buildhelpers/src/main/java/com/vaadin/buildhelpers/GeneratePackageExports.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.buildhelpers; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.List; -import java.util.jar.Attributes; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.jar.Manifest; -import java.util.logging.Logger; -import java.util.regex.Pattern; - -/** - * Generates Export-Packages attribute for OSGi compatible manifest. - *

- * Reads the included Java packages in a jar file, generates a corresponding - * Export-Package attribute, and appends it to the jar's MANIFEST.MF. - *

- * See #3521 for details. - * - * @author magi - */ -public class GeneratePackageExports { - - private static final String EXPORT_PACKAGE_ATTRIBUTE = "Export-Package"; - - public static void main(String[] args) { - if (args.length < 2) { - System.err.println("Invalid number of parameters\n" - + "Usage: java -cp .. GenerateManifest \n" - + "Use -Dvaadin.version to specify the version to be used for the packages\n" - + "Use -DincludeNumberPackages=1 to include package names which start with a number (not 100% OSGi compatible)"); - System.exit(1); - } - - // Open the JAR - String jarFilename = args[0]; - JarFile jar = null; - try { - jar = new JarFile(jarFilename); - } catch (IOException e) { - System.err.println("Unable to open JAR '" + jarFilename + "'"); - System.exit(1); - } - - // Accepted packages - List acceptedPackagePrefixes = new ArrayList<>(); - for (int i = 1; i < args.length; i++) { - acceptedPackagePrefixes.add(args[i]); - } - - boolean includeNumberPackages = false; - if ("1".equals(System.getProperty("includeNumberPackages"))) { - includeNumberPackages = true; - } - - // List the included Java packages - HashSet packages = getPackages(jar, acceptedPackagePrefixes, - includeNumberPackages); - - // Avoid writing empty Export-Package attribute - if (packages.isEmpty()) { - return; - } - - String exportPackage = sortAndJoinPackages(packages); - - // Read old manifest - Manifest oldMF = null; - try { - oldMF = jar.getManifest(); - } catch (IOException e) { - e.printStackTrace(); - } - Attributes mainAttributes = oldMF.getMainAttributes(); - - String existingExportPackage = mainAttributes - .getValue(EXPORT_PACKAGE_ATTRIBUTE); - if (existingExportPackage != null) { - exportPackage = existingExportPackage + "," + exportPackage; - } - - // Jar must be closed before updating it below, as it's - // locked in Windows until closed. (#6045) - try { - jar.close(); - } catch (IOException e) { - System.err.println("Unable to close JAR '" + jarFilename + "'"); - } - - // Create the modified manifest - ManifestWriter manifest = new ManifestWriter(); - manifest.writeAttribute(EXPORT_PACKAGE_ATTRIBUTE, exportPackage); - - // Update the manifest in the Jar. The jar must be closed - // before this is done. - int status = manifest.updateJar(jarFilename); - - if (status != 0) { - System.exit(status); - } - } - - private static String sortAndJoinPackages(HashSet packages) { - // Produce an ordered listing of the package names - String packageArray[] = new String[packages.size()]; - packages.toArray(packageArray); - Arrays.sort(packageArray); - StringBuilder joinedPackages = new StringBuilder(); - for (int i = 0; i < packageArray.length; i++) { - if (i != 0) { - joinedPackages.append(","); - } - String version = getVersion(packageArray[i]); - String packageAndVersion = packageArray[i]; - if (version != null) { - packageAndVersion += ";version=\"" + version + "\""; - } else { - Logger.getLogger(GeneratePackageExports.class.getName()) - .severe("No version defined for " + packageArray[i]); - } - joinedPackages.append(packageAndVersion); - } - - return joinedPackages.toString(); - } - - /** - * Tries to find version specified using system properties of type - * version.. Searches for the packge and then its parents - * recursively. Falls back to the "vaadin.version" system property if no - * other properties are found. - * - * @param javaPackage - * The package to determine a version for - * @return A version or null if no version has been defined - */ - private static String getVersion(String javaPackage) { - String packageVersion = System.getProperty("version." + javaPackage); - if (packageVersion != null) { - return packageVersion; - } - String parentPackage = null; - if (javaPackage.contains(".")) { - parentPackage = javaPackage.substring(0, - javaPackage.lastIndexOf('.')); - String parentVersion = getVersion(parentPackage); - if (parentVersion != null) { - return parentVersion; - } - } - - String vaadinVersion = System.getProperty("vaadin.version"); - if (vaadinVersion != null) { - return vaadinVersion; - } - - return null; - } - - private static HashSet getPackages(JarFile jar, - List acceptedPackagePrefixes, - boolean includeNumberPackages) { - HashSet packages = new HashSet<>(); - - Pattern startsWithNumber = Pattern.compile("\\.\\d"); - - for (Enumeration it = jar.entries(); it.hasMoreElements();) { - JarEntry entry = it.nextElement(); - - boolean classFile = entry.getName().endsWith(".class"); - boolean directory = entry.isDirectory(); - - if (!classFile && !directory) { - continue; - } - - if (!acceptEntry(entry.getName(), acceptedPackagePrefixes)) { - continue; - } - - int lastSlash = entry.getName().lastIndexOf('/'); - String pkg = entry.getName().substring(0, lastSlash).replace('/', - '.'); - - if (!includeNumberPackages - && startsWithNumber.matcher(pkg).find()) { - continue; - } - - packages.add(pkg); - } - - return packages; - } - - private static boolean acceptEntry(String name, - List acceptedPackagePrefixes) { - for (String prefix : acceptedPackagePrefixes) { - if (name.startsWith(prefix)) { - return true; - } - } - return false; - } -} diff --git a/client-compiled/bnd.bnd b/client-compiled/bnd.bnd new file mode 100644 index 00000000000..60f79d805e7 --- /dev/null +++ b/client-compiled/bnd.bnd @@ -0,0 +1,6 @@ +Bundle-SymbolicName: ${project.groupId}.client.compiled +Bundle-Name: Default Widgetset +Bundle-Version: ${osgi.bundle.version} +Import-Package: com.vaadin*;version='[${osgi.bundle.version},${osgi.bundle.version}]',\ + * +Export-Package: com.vaadin.osgi.widgetset;-noimport:=true diff --git a/client-compiled/pom.xml b/client-compiled/pom.xml index 708f87e11fc..185d88d9dba 100644 --- a/client-compiled/pom.xml +++ b/client-compiled/pom.xml @@ -29,6 +29,13 @@ provided + + ${project.groupId} + vaadin-shared + ${project.version} + provided + + ${project.groupId} vaadin-client @@ -49,40 +56,19 @@ ${project.version} provided + + + org.osgi + osgi.core + + + org.osgi + osgi.cmpn + - - org.codehaus.mojo - exec-maven-plugin - - - generate-export-package - package - - exec - - - compile - ${java.home}/bin/java - - -Dvaadin.version=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion} - -DincludeNumberPackages=1 - - -classpath - - - com.vaadin.buildhelpers.GeneratePackageExports - - ${project.build.directory}/${project.build.finalName}.${project.packaging} - VAADIN/widgetsets - - - - - - com.vaadin vaadin-maven-plugin @@ -103,32 +89,10 @@ - - - - org.apache.felix - maven-bundle-plugin - true - - - ${osgi.bundle.version} - ${osgi.execution.environment} - - - - - - - - bundle-manifest - prepare-package - - manifest - - - - - + + biz.aQute.bnd + bnd-maven-plugin + org.apache.maven.plugins maven-jar-plugin diff --git a/client-compiled/src/main/java/com/vaadin/osgi/widgetset/DefaultWidgetsetContribution.java b/client-compiled/src/main/java/com/vaadin/osgi/widgetset/DefaultWidgetsetContribution.java new file mode 100644 index 00000000000..8e793779300 --- /dev/null +++ b/client-compiled/src/main/java/com/vaadin/osgi/widgetset/DefaultWidgetsetContribution.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.osgi.widgetset; + +import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.http.HttpService; + +import com.vaadin.osgi.resources.OSGiVaadinResources; +import com.vaadin.osgi.resources.VaadinResourceService; + +@Component(immediate = true) +public class DefaultWidgetsetContribution { + private HttpService httpService; + + private static final String WIDGETSET_NAME = "com.vaadin.DefaultWidgetSet"; + + @Activate + void startup(ComponentContext context) throws Exception { + VaadinResourceService service = OSGiVaadinResources.getService(); + service.publishWidgetset(WIDGETSET_NAME, httpService); + } + + @Reference + void setHttpService(HttpService httpService) { + this.httpService = httpService; + } + + void unsetHttpService(HttpService httpService) { + this.httpService = null; + } +} diff --git a/compatibility-client-compiled/bnd.bnd b/compatibility-client-compiled/bnd.bnd new file mode 100644 index 00000000000..665722b56b4 --- /dev/null +++ b/compatibility-client-compiled/bnd.bnd @@ -0,0 +1,6 @@ +Bundle-SymbolicName: ${project.groupId}.compatibility.client.compiled +Bundle-Name: Compatibility Widgetset +Bundle-Version: ${osgi.bundle.version} +Import-Package: com.vaadin*;version='[${osgi.bundle.version},${osgi.bundle.version}]',\ + * +Export-Package: com.vaadin.osgi.compatibility.widgetset;-noimport:=true diff --git a/compatibility-client-compiled/pom.xml b/compatibility-client-compiled/pom.xml index 9f09cede62d..1a21712a94f 100644 --- a/compatibility-client-compiled/pom.xml +++ b/compatibility-client-compiled/pom.xml @@ -50,40 +50,19 @@ ${project.version} provided + + + org.osgi + osgi.core + + + org.osgi + osgi.cmpn + - - org.codehaus.mojo - exec-maven-plugin - - - generate-export-package - package - - exec - - - compile - ${java.home}/bin/java - - -Dvaadin.version=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion} - -DincludeNumberPackages=1 - - -classpath - - - com.vaadin.buildhelpers.GeneratePackageExports - - ${project.build.directory}/${project.build.finalName}.${project.packaging} - VAADIN/widgetsets - - - - - - com.vaadin vaadin-maven-plugin @@ -104,32 +83,10 @@ - - - org.apache.felix - maven-bundle-plugin - true - - - ${osgi.bundle.version} - ${osgi.execution.environment} - - - - - - - - bundle-manifest - prepare-package - - manifest - - - + biz.aQute.bnd + bnd-maven-plugin - org.apache.maven.plugins maven-jar-plugin diff --git a/compatibility-client-compiled/src/main/java/com/vaadin/osgi/compatibility/widgetset/CompatibilityWidgetsetContribution.java b/compatibility-client-compiled/src/main/java/com/vaadin/osgi/compatibility/widgetset/CompatibilityWidgetsetContribution.java new file mode 100644 index 00000000000..f9c4c4d121e --- /dev/null +++ b/compatibility-client-compiled/src/main/java/com/vaadin/osgi/compatibility/widgetset/CompatibilityWidgetsetContribution.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.osgi.compatibility.widgetset; + +import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.http.HttpService; + +import com.vaadin.osgi.resources.OSGiVaadinResources; +import com.vaadin.osgi.resources.VaadinResourceService; + +@Component(immediate = true) +public class CompatibilityWidgetsetContribution { + private HttpService httpService; + + private static final String WIDGETSET_NAME = "com.vaadin.v7.Vaadin7WidgetSet"; + + @Activate + void startup(ComponentContext context) throws Exception { + VaadinResourceService service = OSGiVaadinResources.getService(); + service.publishWidgetset(WIDGETSET_NAME, httpService); + } + + @Reference + void setHttpService(HttpService httpService) { + this.httpService = httpService; + } + + void unsetHttpService(HttpService httpService) { + this.httpService = null; + } +} diff --git a/compatibility-server/bnd.bnd b/compatibility-server/bnd.bnd new file mode 100644 index 00000000000..11ea914dcc7 --- /dev/null +++ b/compatibility-server/bnd.bnd @@ -0,0 +1,10 @@ +Bundle-SymbolicName: ${project.groupId}.compatibility.server +Bundle-Name: Vaadin Compatibility Server +Import-Package: com.vaadin*;version="[${osgi.bundle.version},${osgi.bundle.version}]",\ + !com.google*,\ + org.osgi*,\ + javax.validation*;resolution:=optional;version='${javax.validation.version}',\ + * +Export-Package: !com.vaadin.v7.shared*,\ + !com.vaadin.v7.client*,\ + com.vaadin.v7*;-noimport:=true diff --git a/compatibility-server/pom.xml b/compatibility-server/pom.xml index 8599d352ff2..ed3468a9a2e 100644 --- a/compatibility-server/pom.xml +++ b/compatibility-server/pom.xml @@ -82,38 +82,10 @@ - - org.apache.felix - maven-bundle-plugin - true - - - ${osgi.execution.environment} - ${osgi.bundle.version} - VAADIN;version="${osgi.bundle.version}",com.vaadin.v7.*;version="${osgi.bundle.version}" - !com.google.appengine.api.datastore, - !com.google.appengine.api.memcache, - !com.google.apphosting.api, - * - - - com.vaadin.server;bundle-version="${osgi.bundle.version}", - com.vaadin.shared;bundle-version="${osgi.bundle.version}" - - - - - - bundle-manifest - prepare-package - - manifest - - - + biz.aQute.bnd + bnd-maven-plugin - org.apache.maven.plugins maven-jar-plugin diff --git a/compatibility-shared/bnd.bnd b/compatibility-shared/bnd.bnd new file mode 100644 index 00000000000..754a6a4ca0c --- /dev/null +++ b/compatibility-shared/bnd.bnd @@ -0,0 +1,6 @@ +Bundle-SymbolicName: ${project.groupId}.compatibility.shared +Bundle-Name: Vaadin Compatibility Shared +Import-Package: com.vaadin*;version="[${osgi.bundle.version},${osgi.bundle.version}]",\ + org.osgi* +Export-Package: \ + com.vaadin.v7.shared*;-noimport:=true diff --git a/compatibility-shared/pom.xml b/compatibility-shared/pom.xml index 00f92ec9c57..d17cc5253a7 100644 --- a/compatibility-shared/pom.xml +++ b/compatibility-shared/pom.xml @@ -42,32 +42,10 @@ - - org.apache.felix - maven-bundle-plugin - true - - - ${osgi.execution.environment} - ${osgi.bundle.version} - com.vaadin.*;version="${osgi.bundle.version}" - - com.vaadin.shared;bundle-version="${osgi.bundle.version}" - - - - - - bundle-manifest - prepare-package - - manifest - - - + biz.aQute.bnd + bnd-maven-plugin - maven-resources-plugin diff --git a/compatibility-themes/bnd.bnd b/compatibility-themes/bnd.bnd new file mode 100644 index 00000000000..ee3e21796bc --- /dev/null +++ b/compatibility-themes/bnd.bnd @@ -0,0 +1,6 @@ +Bundle-SymbolicName: ${project.groupId}.compatibility.themes +Bundle-Name: Vaadin Compatibility Themes +Bundle-Version: ${osgi.bundle.version} +Import-Package: com.vaadin*;version='[${osgi.bundle.version},${osgi.bundle.version}]',\ + * +Export-Package: com.vaadin.osgi.compatibility.themes;-noimport:=true diff --git a/compatibility-themes/pom.xml b/compatibility-themes/pom.xml index d510c9c2626..e2bebf42fc1 100644 --- a/compatibility-themes/pom.xml +++ b/compatibility-themes/pom.xml @@ -51,6 +51,15 @@ commons-io provided + + + org.osgi + osgi.core + + + org.osgi + osgi.cmpn + @@ -223,29 +232,6 @@ - - generate-export-package - package - - exec - - - compile - ${java.home}/bin/java - - -Dvaadin.version=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion} - -DincludeNumberPackages=0 - - -classpath - - - com.vaadin.buildhelpers.GeneratePackageExports - - ${project.build.directory}/${project.build.finalName}.${project.packaging} - VAADIN/themes - - - @@ -281,29 +267,9 @@ - org.apache.felix - maven-bundle-plugin - true - - - ${osgi.bundle.version} - ${osgi.execution.environment} - - - - - - - - bundle-manifest - prepare-package - - manifest - - - + biz.aQute.bnd + bnd-maven-plugin - org.apache.maven.plugins maven-jar-plugin diff --git a/compatibility-themes/src/main/java/com/vaadin/osgi/compatibility/themes/LegacyThemeContributions.java b/compatibility-themes/src/main/java/com/vaadin/osgi/compatibility/themes/LegacyThemeContributions.java new file mode 100644 index 00000000000..dd1b933bb98 --- /dev/null +++ b/compatibility-themes/src/main/java/com/vaadin/osgi/compatibility/themes/LegacyThemeContributions.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.osgi.compatibility.themes; + +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.http.HttpService; + +import com.vaadin.osgi.resources.OSGiVaadinResources; +import com.vaadin.osgi.resources.VaadinResourceService; + +@Component(immediate = true) +public class LegacyThemeContributions { + private static final String[] LEGACY_THEMES = { "base", "chameleon", + "reindeer", "runo" }; + + private HttpService httpService; + + @Activate + void startup() throws Exception { + VaadinResourceService service = OSGiVaadinResources.getService(); + for (String themeName : LEGACY_THEMES) { + service.publishTheme(themeName, httpService); + } + } + + @Reference + void setHttpService(HttpService httpService) { + this.httpService = httpService; + } + + void unsetHttpService(HttpService httpService) { + this.httpService = null; + } +} diff --git a/pom.xml b/pom.xml index d09f300290c..a26d7b0801a 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ 6.2.5 + 2.0.0 2.8.0 8.1-SNAPSHOT @@ -37,14 +38,18 @@ 2.4.5.vaadin2 - 3.0.0 JavaSE-1.8 ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion} + 6.0.0 + 6.0.1 + + 3.3.0 ${project.build.directory}/dependency-unpack - + 9.2.9.v20150224 2.1.1 @@ -290,6 +295,25 @@ ${vaadin.icons.version} provided + + + org.osgi + osgi.core + ${osgi.version} + provided + + + org.osgi + osgi.annotation + ${osgi.annotation.version} + provided + + + org.osgi + osgi.cmpn + ${osgi.version} + provided + @@ -376,9 +400,16 @@ 1.8 - org.apache.felix - maven-bundle-plugin - 3.0.1 + biz.aQute.bnd + bnd-maven-plugin + ${bnd.version} + + + + bnd-process + + + org.apache.maven.plugins diff --git a/push/bnd.bnd b/push/bnd.bnd new file mode 100644 index 00000000000..f5d0deb9a7e --- /dev/null +++ b/push/bnd.bnd @@ -0,0 +1,6 @@ +Bundle-SymbolicName: ${project.groupId}.push +Bundle-Name: Vaadin Push +Bundle-Version: ${osgi.bundle.version} +Import-Package: com.vaadin*;version='[${osgi.bundle.version},${osgi.bundle.version}]',\ + * +Export-Package: com.vaadin.osgi.push;-noimport:=true diff --git a/push/pom.xml b/push/pom.xml index af510260846..ee9d82e1fef 100644 --- a/push/pom.xml +++ b/push/pom.xml @@ -29,7 +29,20 @@ war provided - + + ${project.groupId} + vaadin-shared + ${project.version} + provided + + + org.osgi + osgi.core + + + org.osgi + osgi.cmpn + @@ -134,28 +147,9 @@ ${project.build.outputDirectory}/VAADIN - - org.apache.felix - maven-bundle-plugin - true - - - ${osgi.bundle.version} - ${osgi.execution.environment} - VAADIN - com.vaadin.external.atmosphere.runtime;bundle-version="${atmosphere.runtime.version}";visibility:=reexport - - - - - bundle-manifest - process-classes - - manifest - - - + biz.aQute.bnd + bnd-maven-plugin org.apache.maven.plugins diff --git a/push/src/main/java/com/vaadin/osgi/push/PushResourcesContribution.java b/push/src/main/java/com/vaadin/osgi/push/PushResourcesContribution.java new file mode 100644 index 00000000000..8d4564c5829 --- /dev/null +++ b/push/src/main/java/com/vaadin/osgi/push/PushResourcesContribution.java @@ -0,0 +1,51 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.osgi.push; + +import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.http.HttpService; + +import com.vaadin.osgi.resources.OSGiVaadinResources; +import com.vaadin.osgi.resources.VaadinResourceService; + +@Component(immediate = true) +public class PushResourcesContribution { + private HttpService httpService; + + private static final String[] RESOURCES = { "vaadinPush.js", + "vaadinPush.js.gz", "vaadinPush.debug.js", + "vaadinPush.debug.js.gz" }; + + @Activate + void startup(ComponentContext context) throws Exception { + VaadinResourceService service = OSGiVaadinResources.getService(); + for (String resourceName : RESOURCES) { + service.publishResource(resourceName, httpService); + } + } + + @Reference + void setHttpService(HttpService httpService) { + this.httpService = httpService; + } + + void unsetHttpService(HttpService httpService) { + this.httpService = null; + } +} diff --git a/server/bnd.bnd b/server/bnd.bnd new file mode 100644 index 00000000000..dfeb5d5d391 --- /dev/null +++ b/server/bnd.bnd @@ -0,0 +1,15 @@ +Bundle-SymbolicName: ${project.groupId}.server +Bundle-Name: Vaadin Server +Bundle-Version: ${osgi.bundle.version} +Import-Package: com.vaadin.sass.*;resolution:=optional,\ + com.liferay.portal.kernel.util;resolution:=optional,\ + javax.portlet*;resolution:=optional,\ + javax.validation*;resolution:=optional;version='${javax.validation.version}',\ + org.atmosphere*;resolution:=optional,\ + com.vaadin*;version='[${osgi.bundle.version},${osgi.bundle.version}]',\ + * +Export-Package: !com.vaadin.sass*,\ + !com.vaadin.shared*,\ + !com.vaadin.osgi.resources*,\ + !com.vaadin.osgi.push*,\ + com.vaadin*;-noimport:=true diff --git a/server/pom.xml b/server/pom.xml index d890a254629..3d2f8c47bc7 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -18,6 +18,14 @@ + + com.liferay.portal + com.liferay.portal.kernel + ${liferay.portal-kernel.version} + provided + + + com.liferay.portal portal-service @@ -85,6 +93,17 @@ 1.2.0 + + + + org.osgi + osgi.core + + + org.osgi + osgi.cmpn + + @@ -225,46 +244,10 @@ - - org.apache.felix - maven-bundle-plugin - true - - - ${osgi.execution.environment} - ${osgi.bundle.version} - VAADIN;version="${osgi.bundle.version}",com.vaadin.*;version="${osgi.bundle.version}" - - javax.servlet;version="${osgi.javax.servlet.version}", - javax.servlet.http;version="${osgi.javax.servlet.version}", - javax.validation;version="${javax.validation.version}";resolution:=optional, - org.jsoup;version="${jsoup.version}", - org.jsoup.parser;version="${jsoup.version}", - org.jsoup.nodes;version="${jsoup.version}", - org.jsoup.helper;version="${jsoup.version}", - org.jsoup.safety;version="${jsoup.version}", - org.jsoup.select;version="${jsoup.version}", - javax.portlet;version="[${javax.portlet.version},3)";resolution:=optional, - javax.portlet.filter;version="[${javax.portlet.version},3)";resolution:=optional, - com.liferay.portal.kernel.util;version="[7,8)";resolution:=optional - - com.vaadin.shared;bundle-version="${osgi.bundle.version}", - com.vaadin.push;bundle-version="${osgi.bundle.version}";resolution:=optional, - com.vaadin.sass-compiler;bundle-version="${vaadin.sass.version}";resolution:=optional - - - - - bundle-manifest - prepare-package - - manifest - - - + biz.aQute.bnd + bnd-maven-plugin - org.apache.maven.plugins maven-jar-plugin @@ -277,7 +260,7 @@ - @@ -293,7 +276,7 @@ maven-surefire-plugin - + @@ -334,5 +317,5 @@ - + diff --git a/server/src/main/java/com/vaadin/server/osgi/BootstrapContribution.java b/server/src/main/java/com/vaadin/server/osgi/BootstrapContribution.java new file mode 100644 index 00000000000..0a320ed6e54 --- /dev/null +++ b/server/src/main/java/com/vaadin/server/osgi/BootstrapContribution.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.server.osgi; + +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.http.HttpService; +import org.osgi.service.http.NamespaceException; + +import com.vaadin.osgi.resources.OSGiVaadinResources; +import com.vaadin.osgi.resources.VaadinResourceService; +import com.vaadin.osgi.resources.OSGiVaadinResources.ResourceBundleInactiveException; + +@Component(immediate = true) +public class BootstrapContribution { + private static final String[] RESOURCES = { "vaadinBootstrap.js", + "vaadinBootstrap.js.gz" }; + private HttpService httpService; + + @Activate + void startup() throws NamespaceException, ResourceBundleInactiveException { + VaadinResourceService service = OSGiVaadinResources.getService(); + for (String resourceName : RESOURCES) { + service.publishResource(resourceName, httpService); + } + } + + @Reference + void setHttpService(HttpService service) { + this.httpService = service; + } + + void unsetHttpService(HttpService service) { + this.httpService = null; + } +} diff --git a/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java b/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java index ec1032c7978..b4f98518670 100644 --- a/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java +++ b/server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java @@ -100,6 +100,8 @@ public class ClassesSerializableTest { "com\\.vaadin\\.themes\\.valoutil\\.BodyStyleName", // "com\\.vaadin\\.server\\.communication\\.JSR356WebsocketInitializer.*", // "com\\.vaadin\\.screenshotbrowser\\.ScreenshotBrowser.*", // + "com\\.vaadin\\.osgi.*",// + "com\\.vaadin\\.server\\.osgi.*" }; /** diff --git a/shared/bnd.bnd b/shared/bnd.bnd new file mode 100644 index 00000000000..1894e06bd1d --- /dev/null +++ b/shared/bnd.bnd @@ -0,0 +1,8 @@ +Bundle-SymbolicName: ${project.groupId}.shared +Bundle-Activator: com.vaadin.osgi.resources.OSGiVaadinResources +Bundle-Name: Vaadin Shared +Import-Package: com.vaadin*;version="[${osgi.bundle.version},${osgi.bundle.version}]",\ + org.osgi* +Export-Package: com.vaadin.osgi.resources;-noimport:=true,\ + com.vaadin.shared*;-noimport:=true,\ + elemental*;-noimport:=true diff --git a/shared/pom.xml b/shared/pom.xml index 1cb9ed07dca..d1820309782 100644 --- a/shared/pom.xml +++ b/shared/pom.xml @@ -24,6 +24,15 @@ gwt-elemental provided + + + org.osgi + osgi.core + + + org.osgi + osgi.cmpn + @@ -99,31 +108,10 @@ - - org.apache.felix - maven-bundle-plugin - true - - - ${osgi.execution.environment} - ${osgi.bundle.version} - com.vaadin.*;version="${osgi.bundle.version}",elemental.*;version="${osgi.bundle.version}" - - - - - - - bundle-manifest - prepare-package - - manifest - - - + biz.aQute.bnd + bnd-maven-plugin - org.apache.maven.plugins maven-jar-plugin diff --git a/shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinResources.java b/shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinResources.java new file mode 100644 index 00000000000..96f6f997caa --- /dev/null +++ b/shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinResources.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.osgi.resources; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Version; + +import com.vaadin.osgi.resources.impl.VaadinResourceServiceImpl; + +/** + * {@link BundleActivator} used to provide access to the + * {@link VaadinResourceService} singleton for publishing themes, widgetsets and + * other necessary resources. + * + * @author Vaadin Ltd. + * + * @since 8.1 + */ +public class OSGiVaadinResources implements BundleActivator { + + /** + * Thrown if a method is called when the Resource bundle is not active. + * + * @author Vaadin Ltd. + * + * @since 8.1 + */ + @SuppressWarnings("serial") + public static class ResourceBundleInactiveException extends Exception { + public ResourceBundleInactiveException(String message) { + super(message); + } + } + + private static OSGiVaadinResources instance; + + private VaadinResourceServiceImpl service; + private Version version; + + /** + * Returns the {@link VaadinResourceService} instance. Always returns + * non-null. + * + * @return the {@link VaadinResourceService resource service} to use for + * publishing themes, widgetsets and other necessary resources + * @throws ResourceBundleInactiveException + * if the bundle is not active + */ + public static VaadinResourceService getService() + throws ResourceBundleInactiveException { + if (instance == null) { + throw new ResourceBundleInactiveException( + "Vaadin Shared is not active!"); + } + return instance.service; + } + + @Override + public void start(BundleContext context) throws Exception { + version = context.getBundle().getVersion(); + service = new VaadinResourceServiceImpl(); + service.setBundleVersion(version.toString()); + instance = this; + } + + @Override + public void stop(BundleContext context) throws Exception { + instance = null; + service = null; + version = null; + } +} diff --git a/shared/src/main/java/com/vaadin/osgi/resources/VaadinResourceService.java b/shared/src/main/java/com/vaadin/osgi/resources/VaadinResourceService.java new file mode 100644 index 00000000000..819d3ac1438 --- /dev/null +++ b/shared/src/main/java/com/vaadin/osgi/resources/VaadinResourceService.java @@ -0,0 +1,97 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.osgi.resources; + +import org.osgi.service.http.HttpService; +import org.osgi.service.http.NamespaceException; + +/** + * Service used to publish themes, widgetsets and static resources at the root + * of a versioned namespaced /VAADIN/ folder. + * + * @author Vaadin Ltd. + * + * @since 8.1 + */ +public interface VaadinResourceService { + + /** + * Register the theme with the given name under the + * {@link VaadinResourceService} versioned namespace. The theme folder is + * expected to be compiled and under "/VAADIN/themes/" in the calling + * bundle. + * + * The theme will become accessible under the url + * "/vaadin-x.x.x/VAADIN/themes/themeName" where x.x.x is the version of the + * Vaadin Shared bundle + * + * @param themeName + * the name of the theme + * @param httpService + * the {@link HttpService} instance for the calling bundle + * @throws NamespaceException + * if there is a clash during the theme registration + */ + void publishTheme(String themeName, HttpService httpService) + throws NamespaceException; + + /** + * Register the resource with the given name under the + * {@link VaadinResourceService} versioned namespace. The resource is + * expected to be under "/VAADIN/" in the calling bundle. + * + * The resource will become accessible under the url "/vaadin-x.x.x/VAADIN/" + * where x.x.x is the version of the Vaadin Shared bundle + * + * @param resourceName + * the name of the resource + * @param httpService + * the {@link HttpService} instance for the calling bundle + * @throws NamespaceException + * if there is a clash during the theme registration + */ + void publishResource(String resourceName, HttpService httpService) + throws NamespaceException; + + /** + * Register the widgetset with the given name under the + * {@link VaadinResourceService} versioned namespace. The resource is + * expected to be under "/VAADIN/widgetsets" in the calling bundle. + * + * The resource will become accessible under the url + * "/vaadin-x.x.x/VAADIN/widgetsets" where x.x.x is the version of the + * Vaadin Shared bundle + * + * @param widgetsetName + * the name of the resource + * @param httpService + * the {@link HttpService} instance for the calling bundle + * @throws NamespaceException + * if there is a clash during the theme registration + */ + void publishWidgetset(String widgetsetName, HttpService httpService) + throws NamespaceException; + + /** + * Returns the prefix of the versioned namespace for the resources. The + * result can't be null and is of the format "vaadin-x.x.x" where x.x.x the + * version of the Vaadin Shared bundle. + * + * @return the prefix of the resources folder managed by this service + */ + String getResourcePathPrefix(); + +} diff --git a/shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceServiceImpl.java b/shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceServiceImpl.java new file mode 100644 index 00000000000..d33a56abfa4 --- /dev/null +++ b/shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceServiceImpl.java @@ -0,0 +1,97 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.osgi.resources.impl; + +import org.osgi.service.http.HttpService; +import org.osgi.service.http.NamespaceException; + +import com.vaadin.osgi.resources.VaadinResourceService; + +/** + * Implementation of {@link VaadinResourceService}. Uses bundle version as a + * prefix for the /VAADIN/ folder. + * + * @author Vaadin Ltd. + * + * @since 8.1 + */ +public class VaadinResourceServiceImpl implements VaadinResourceService { + private static final String NAMESPACE_PREFIX = "vaadin-%s"; + + private static final String VAADIN_ROOT_ALIAS_FORMAT = "/%s/VAADIN/%s"; + private static final String VAADIN_ROOT_FORMAT = "/VAADIN/%s"; + + private static final String VAADIN_THEME_ALIAS_FORMAT = "/%s/VAADIN/themes/%s"; + private static final String VAADIN_WIDGETSET_ALIAS_FORMAT = "/%s/VAADIN/widgetsets/%s"; + + private static final String VAADIN_THEME_PATH_FORMAT = "/VAADIN/themes/%s"; + private static final String VAADIN_WIDGETSET_PATH_FORMAT = "/VAADIN/widgetsets/%s"; + + private String bundleVersion; + + /** + * Sets the version of the bundle managing this service. + * + *

+ * This needs to be called before any other method after the service is + * created. + * + * @param bundleVersion + * the version of the bundle managing this service + */ + public void setBundleVersion(String bundleVersion) { + this.bundleVersion = bundleVersion; + } + + @Override + public void publishTheme(String themeName, HttpService httpService) + throws NamespaceException { + doPublish(themeName, VAADIN_THEME_ALIAS_FORMAT, + VAADIN_THEME_PATH_FORMAT, httpService); + } + + private void doPublish(String resourceName, String aliasFormat, + String pathFormat, HttpService httpService) + throws NamespaceException { + String bundleVersionPrefix = String.format(NAMESPACE_PREFIX, + bundleVersion); + + String resourcePath = String.format(pathFormat, resourceName); + String resourceAlias = String.format(aliasFormat, bundleVersionPrefix, + resourceName); + + httpService.registerResources(resourceAlias, resourcePath, null); + } + + @Override + public void publishResource(String resource, HttpService httpService) + throws NamespaceException { + doPublish(resource, VAADIN_ROOT_ALIAS_FORMAT, VAADIN_ROOT_FORMAT, + httpService); + } + + @Override + public void publishWidgetset(String widgetset, HttpService httpService) + throws NamespaceException { + doPublish(widgetset, VAADIN_WIDGETSET_ALIAS_FORMAT, + VAADIN_WIDGETSET_PATH_FORMAT, httpService); + } + + @Override + public String getResourcePathPrefix() { + return String.format(NAMESPACE_PREFIX, bundleVersion); + } +} diff --git a/themes/bnd.bnd b/themes/bnd.bnd new file mode 100644 index 00000000000..7398d4de6e7 --- /dev/null +++ b/themes/bnd.bnd @@ -0,0 +1,6 @@ +Bundle-SymbolicName: ${project.groupId}.themes +Bundle-Name: Vaadin Themes +Bundle-Version: ${osgi.bundle.version} +Import-Package: com.vaadin.*;version='[${osgi.bundle.version},${osgi.bundle.version}]',\ + * +Export-Package: com.vaadin.osgi.themes;-noimport:=true diff --git a/themes/pom.xml b/themes/pom.xml index d7c8ae333e6..fc0e9fcc6da 100644 --- a/themes/pom.xml +++ b/themes/pom.xml @@ -54,6 +54,15 @@ commons-io provided + + + org.osgi + osgi.core + + + org.osgi + osgi.cmpn + @@ -148,61 +157,10 @@ - - - org.codehaus.mojo - exec-maven-plugin - - - generate-export-package - package - - exec - - - compile - ${java.home}/bin/java - - -Dvaadin.version=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion} - -DincludeNumberPackages=0 - - -classpath - - - com.vaadin.buildhelpers.GeneratePackageExports - - ${project.build.directory}/${project.build.finalName}.${project.packaging} - VAADIN/themes - - - - - - - org.apache.felix - maven-bundle-plugin - true - - - ${osgi.bundle.version} - ${osgi.execution.environment} - - - - - - - - bundle-manifest - prepare-package - - manifest - - - + biz.aQute.bnd + bnd-maven-plugin - org.apache.maven.plugins maven-jar-plugin diff --git a/themes/src/main/java/com/vaadin/osgi/themes/ValoThemeContribution.java b/themes/src/main/java/com/vaadin/osgi/themes/ValoThemeContribution.java new file mode 100644 index 00000000000..cd1b7a4a8e9 --- /dev/null +++ b/themes/src/main/java/com/vaadin/osgi/themes/ValoThemeContribution.java @@ -0,0 +1,45 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.osgi.themes; + +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.http.HttpService; + +import com.vaadin.osgi.resources.OSGiVaadinResources; +import com.vaadin.osgi.resources.VaadinResourceService; + +@Component(immediate = true) +public class ValoThemeContribution { + + private HttpService httpService; + + @Activate + void startup() throws Exception { + VaadinResourceService service = OSGiVaadinResources.getService(); + service.publishTheme("valo", httpService); + } + + @Reference + void setHttpService(HttpService httpService) { + this.httpService = httpService; + } + + void unsetHttpService(HttpService httpService) { + this.httpService = null; + } +}