diff options
30 files changed, 784 insertions, 577 deletions
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 9717c35353..0000000000 --- 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. - * <p> - * Reads the included Java packages in a jar file, generates a corresponding - * Export-Package attribute, and appends it to the jar's MANIFEST.MF. - * <p> - * 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 <package.jar> <accepted package prefixes>\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<String> 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<String> 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<String> 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.<java package>. 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<String> getPackages(JarFile jar, - List<String> acceptedPackagePrefixes, - boolean includeNumberPackages) { - HashSet<String> packages = new HashSet<>(); - - Pattern startsWithNumber = Pattern.compile("\\.\\d"); - - for (Enumeration<JarEntry> 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<String> 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 0000000000..60f79d805e --- /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 708f87e11f..185d88d9db 100644 --- a/client-compiled/pom.xml +++ b/client-compiled/pom.xml @@ -29,6 +29,13 @@ <scope>provided</scope> </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>vaadin-shared</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>vaadin-client</artifactId> @@ -49,41 +56,20 @@ <version>${project.version}</version> <scope>provided</scope> </dependency> + + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.cmpn</artifactId> + </dependency> </dependencies> <build> <plugins> <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <executions> - <execution> - <id>generate-export-package</id> - <phase>package</phase> - <goals> - <goal>exec</goal> - </goals> - <configuration> - <classpathScope>compile</classpathScope> - <executable>${java.home}/bin/java</executable> - <arguments> - <argument>-Dvaadin.version=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}</argument> - <argument>-DincludeNumberPackages=1</argument> - - <argument>-classpath</argument> - <classpath /> - - <argument>com.vaadin.buildhelpers.GeneratePackageExports</argument> - - <argument>${project.build.directory}/${project.build.finalName}.${project.packaging}</argument> - <argument>VAADIN/widgetsets</argument> - </arguments> - </configuration> - </execution> - </executions> - </plugin> - - <plugin> <groupId>com.vaadin</groupId> <artifactId>vaadin-maven-plugin</artifactId> <configuration> @@ -103,32 +89,10 @@ </execution> </executions> </plugin> - - - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-Version>${osgi.bundle.version}</Bundle-Version> - <Bundle-RequiredExecutionEnvironment>${osgi.execution.environment}</Bundle-RequiredExecutionEnvironment> - <!-- Export package is handled in exec plugin --> - <Export-Package></Export-Package> - <Import-Package></Import-Package> - </instructions> - </configuration> - <executions> - <execution> - <id>bundle-manifest</id> - <phase>prepare-package</phase> - <goals> - <goal>manifest</goal> - </goals> - </execution> - </executions> - </plugin> - + <plugin> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> + </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> 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 0000000000..8e79377930 --- /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 0000000000..665722b56b --- /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 9f09cede62..1a21712a94 100644 --- a/compatibility-client-compiled/pom.xml +++ b/compatibility-client-compiled/pom.xml @@ -50,41 +50,20 @@ <version>${project.version}</version> <scope>provided</scope> </dependency> + + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.cmpn</artifactId> + </dependency> </dependencies> <build> <plugins> <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <executions> - <execution> - <id>generate-export-package</id> - <phase>package</phase> - <goals> - <goal>exec</goal> - </goals> - <configuration> - <classpathScope>compile</classpathScope> - <executable>${java.home}/bin/java</executable> - <arguments> - <argument>-Dvaadin.version=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}</argument> - <argument>-DincludeNumberPackages=1</argument> - - <argument>-classpath</argument> - <classpath /> - - <argument>com.vaadin.buildhelpers.GeneratePackageExports</argument> - - <argument>${project.build.directory}/${project.build.finalName}.${project.packaging}</argument> - <argument>VAADIN/widgetsets</argument> - </arguments> - </configuration> - </execution> - </executions> - </plugin> - - <plugin> <groupId>com.vaadin</groupId> <artifactId>vaadin-maven-plugin</artifactId> <configuration> @@ -104,32 +83,10 @@ </execution> </executions> </plugin> - - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-Version>${osgi.bundle.version}</Bundle-Version> - <Bundle-RequiredExecutionEnvironment>${osgi.execution.environment}</Bundle-RequiredExecutionEnvironment> - <!-- Export package is handled in exec plugin --> - <Export-Package></Export-Package> - <Import-Package></Import-Package> - </instructions> - </configuration> - <executions> - <execution> - <id>bundle-manifest</id> - <phase>prepare-package</phase> - <goals> - <goal>manifest</goal> - </goals> - </execution> - </executions> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> 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 0000000000..f9c4c4d121 --- /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 0000000000..11ea914dcc --- /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 8599d352ff..ed3468a9a2 100644 --- a/compatibility-server/pom.xml +++ b/compatibility-server/pom.xml @@ -82,38 +82,10 @@ </execution> </executions> </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-RequiredExecutionEnvironment>${osgi.execution.environment}</Bundle-RequiredExecutionEnvironment> - <Bundle-Version>${osgi.bundle.version}</Bundle-Version> - <Export-Package>VAADIN;version="${osgi.bundle.version}",com.vaadin.v7.*;version="${osgi.bundle.version}"</Export-Package> - <Import-Package>!com.google.appengine.api.datastore, - !com.google.appengine.api.memcache, - !com.google.apphosting.api, - * - </Import-Package> - <Require-Bundle> - com.vaadin.server;bundle-version="${osgi.bundle.version}", - com.vaadin.shared;bundle-version="${osgi.bundle.version}" - </Require-Bundle> - </instructions> - </configuration> - <executions> - <execution> - <id>bundle-manifest</id> - <phase>prepare-package</phase> - <goals> - <goal>manifest</goal> - </goals> - </execution> - </executions> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> diff --git a/compatibility-shared/bnd.bnd b/compatibility-shared/bnd.bnd new file mode 100644 index 0000000000..754a6a4ca0 --- /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 00f92ec9c5..d17cc5253a 100644 --- a/compatibility-shared/pom.xml +++ b/compatibility-shared/pom.xml @@ -42,32 +42,10 @@ </execution> </executions> </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-RequiredExecutionEnvironment>${osgi.execution.environment}</Bundle-RequiredExecutionEnvironment> - <Bundle-Version>${osgi.bundle.version}</Bundle-Version> - <Export-Package>com.vaadin.*;version="${osgi.bundle.version}"</Export-Package> - <Require-Bundle> - com.vaadin.shared;bundle-version="${osgi.bundle.version}" - </Require-Bundle> - </instructions> - </configuration> - <executions> - <execution> - <id>bundle-manifest</id> - <phase>prepare-package</phase> - <goals> - <goal>manifest</goal> - </goals> - </execution> - </executions> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> </plugin> - <plugin> <artifactId>maven-resources-plugin</artifactId> <executions> diff --git a/compatibility-themes/bnd.bnd b/compatibility-themes/bnd.bnd new file mode 100644 index 0000000000..ee3e21796b --- /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 d510c9c262..e2bebf42fc 100644 --- a/compatibility-themes/pom.xml +++ b/compatibility-themes/pom.xml @@ -51,6 +51,15 @@ <artifactId>commons-io</artifactId> <scope>provided</scope> </dependency> + + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.cmpn</artifactId> + </dependency> </dependencies> <build> @@ -223,29 +232,6 @@ </arguments> </configuration> </execution> - <execution> - <id>generate-export-package</id> - <phase>package</phase> - <goals> - <goal>exec</goal> - </goals> - <configuration> - <classpathScope>compile</classpathScope> - <executable>${java.home}/bin/java</executable> - <arguments> - <argument>-Dvaadin.version=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}</argument> - <argument>-DincludeNumberPackages=0</argument> - - <argument>-classpath</argument> - <classpath /> - - <argument>com.vaadin.buildhelpers.GeneratePackageExports</argument> - - <argument>${project.build.directory}/${project.build.finalName}.${project.packaging}</argument> - <argument>VAADIN/themes</argument> - </arguments> - </configuration> - </execution> </executions> </plugin> @@ -281,29 +267,9 @@ </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-Version>${osgi.bundle.version}</Bundle-Version> - <Bundle-RequiredExecutionEnvironment>${osgi.execution.environment}</Bundle-RequiredExecutionEnvironment> - <!-- Export package is handled in exec plugin --> - <Export-Package></Export-Package> - <Import-Package></Import-Package> - </instructions> - </configuration> - <executions> - <execution> - <id>bundle-manifest</id> - <phase>prepare-package</phase> - <goals> - <goal>manifest</goal> - </goals> - </execution> - </executions> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> 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 0000000000..dd1b933bb9 --- /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; + } +} @@ -24,6 +24,7 @@ <!-- Used version numbers for dependencies --> <liferay.portal-service.version>6.2.5</liferay.portal-service.version> + <liferay.portal-kernel.version>2.0.0</liferay.portal-kernel.version> <vaadin.gwt.version>2.8.0</vaadin.gwt.version> <vaadin.plugin.version>8.1-SNAPSHOT</vaadin.plugin.version> @@ -37,14 +38,18 @@ <atmosphere.runtime.version>2.4.5.vaadin2</atmosphere.runtime.version> <!-- OSGi --> - <osgi.javax.servlet.version>3.0.0</osgi.javax.servlet.version> <osgi.execution.environment>JavaSE-1.8</osgi.execution.environment> <osgi.bundle.version>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}</osgi.bundle.version> + <osgi.version>6.0.0</osgi.version> + <osgi.annotation.version>6.0.1</osgi.annotation.version> + + <bnd.version>3.3.0</bnd.version> <!-- Dependency unpack directory --> <dependency.unpack.directory>${project.build.directory}/dependency-unpack</dependency.unpack.directory> - <!-- Cannot use 9.3 or 9.4 because they sometimes reset the connection too early in case of errors --> + <!-- Cannot use 9.3 or 9.4 because they sometimes reset the connection + too early in case of errors --> <!-- See e.g. https://issues.apache.org/jira/browse/SOLR-8453 --> <jetty.version>9.2.9.v20150224</jetty.version> <phantomjs.version>2.1.1</phantomjs.version> @@ -290,6 +295,25 @@ <version>${vaadin.icons.version}</version> <scope>provided</scope> </dependency> + + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.core</artifactId> + <version>${osgi.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.annotation</artifactId> + <version>${osgi.annotation.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.cmpn</artifactId> + <version>${osgi.version}</version> + <scope>provided</scope> + </dependency> </dependencies> </dependencyManagement> @@ -376,9 +400,16 @@ <version>1.8</version> </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <version>3.0.1</version> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> + <version>${bnd.version}</version> + <executions> + <execution> + <goals> + <goal>bnd-process</goal> + </goals> + </execution> + </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> diff --git a/push/bnd.bnd b/push/bnd.bnd new file mode 100644 index 0000000000..f5d0deb9a7 --- /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 af51026084..ee9d82e1fe 100644 --- a/push/pom.xml +++ b/push/pom.xml @@ -29,7 +29,20 @@ <type>war</type> <scope>provided</scope> </dependency> - + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>vaadin-shared</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.cmpn</artifactId> + </dependency> </dependencies> <build> @@ -134,28 +147,9 @@ <outputDirectory>${project.build.outputDirectory}/VAADIN</outputDirectory> </configuration> </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-Version>${osgi.bundle.version}</Bundle-Version> - <Bundle-RequiredExecutionEnvironment>${osgi.execution.environment}</Bundle-RequiredExecutionEnvironment> - <Export-Package>VAADIN</Export-Package> - <Require-Bundle>com.vaadin.external.atmosphere.runtime;bundle-version="${atmosphere.runtime.version}";visibility:=reexport</Require-Bundle> - </instructions> - </configuration> - <executions> - <execution> - <id>bundle-manifest</id> - <phase>process-classes</phase> - <goals> - <goal>manifest</goal> - </goals> - </execution> - </executions> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> 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 0000000000..8d4564c582 --- /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 0000000000..dfeb5d5d39 --- /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 d890a25462..3d2f8c47bc 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -20,6 +20,14 @@ <!-- Liferay Portal Service --> <dependency> <groupId>com.liferay.portal</groupId> + <artifactId>com.liferay.portal.kernel</artifactId> + <version>${liferay.portal-kernel.version}</version> + <scope>provided</scope> + </dependency> + + <!-- Liferay 6 --> + <dependency> + <groupId>com.liferay.portal</groupId> <artifactId>portal-service</artifactId> <version>${liferay.portal-service.version}</version> <scope>provided</scope> @@ -85,6 +93,17 @@ <version>1.2.0</version> </dependency> + <!-- OSGi API --> + + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.cmpn</artifactId> + </dependency> + <!-- TESTING DEPENDENCIES --> <!-- Test dependencies --> @@ -225,46 +244,10 @@ </execution> </executions> </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-RequiredExecutionEnvironment>${osgi.execution.environment}</Bundle-RequiredExecutionEnvironment> - <Bundle-Version>${osgi.bundle.version}</Bundle-Version> - <Export-Package>VAADIN;version="${osgi.bundle.version}",com.vaadin.*;version="${osgi.bundle.version}"</Export-Package> - <!-- Note that Liferay 6 does not use OSGi, and the dependency is optional for non-Liferay deployments --> - <Import-Package>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</Import-Package> - <Require-Bundle> - 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</Require-Bundle> - </instructions> - </configuration> - <executions> - <execution> - <id>bundle-manifest</id> - <phase>prepare-package</phase> - <goals> - <goal>manifest</goal> - </goals> - </execution> - </executions> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> @@ -277,7 +260,7 @@ </manifest> </archive> </configuration> - <!-- Package src/test into a jar so that compatbility-server + <!-- Package src/test into a jar so that compatbility-server can use the same test classes, e.g. test beans --> <executions> <execution> @@ -293,7 +276,7 @@ <artifactId>maven-surefire-plugin</artifactId> </plugin> </plugins> - + <pluginManagement> <plugins> <!-- Make Eclipse add the source folder --> @@ -334,5 +317,5 @@ </plugins> </pluginManagement> </build> - + </project> 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 0000000000..0a320ed6e5 --- /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 ec1032c797..b4f9851867 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 0000000000..1894e06bd1 --- /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 1cb9ed07dc..d182030978 100644 --- a/shared/pom.xml +++ b/shared/pom.xml @@ -24,6 +24,15 @@ <artifactId>gwt-elemental</artifactId> <scope>provided</scope> </dependency> + + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.cmpn</artifactId> + </dependency> </dependencies> <build> @@ -99,31 +108,10 @@ </execution> </executions> </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-RequiredExecutionEnvironment>${osgi.execution.environment}</Bundle-RequiredExecutionEnvironment> - <Bundle-Version>${osgi.bundle.version}</Bundle-Version> - <Export-Package>com.vaadin.*;version="${osgi.bundle.version}",elemental.*;version="${osgi.bundle.version}"</Export-Package> - <Import-Package></Import-Package> - <Require-Bundle></Require-Bundle> - </instructions> - </configuration> - <executions> - <execution> - <id>bundle-manifest</id> - <phase>prepare-package</phase> - <goals> - <goal>manifest</goal> - </goals> - </execution> - </executions> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> 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 0000000000..96f6f997ca --- /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 0000000000..819d3ac143 --- /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 0000000000..d33a56abfa --- /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. + * + * <p> + * 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 0000000000..7398d4de6e --- /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 d7c8ae333e..fc0e9fcc6d 100644 --- a/themes/pom.xml +++ b/themes/pom.xml @@ -54,6 +54,15 @@ <artifactId>commons-io</artifactId> <scope>provided</scope> </dependency> + + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.cmpn</artifactId> + </dependency> </dependencies> <build> @@ -148,61 +157,10 @@ </execution> </executions> </plugin> - - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <executions> - <execution> - <id>generate-export-package</id> - <phase>package</phase> - <goals> - <goal>exec</goal> - </goals> - <configuration> - <classpathScope>compile</classpathScope> - <executable>${java.home}/bin/java</executable> - <arguments> - <argument>-Dvaadin.version=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}</argument> - <argument>-DincludeNumberPackages=0</argument> - - <argument>-classpath</argument> - <classpath /> - - <argument>com.vaadin.buildhelpers.GeneratePackageExports</argument> - - <argument>${project.build.directory}/${project.build.finalName}.${project.packaging}</argument> - <argument>VAADIN/themes</argument> - </arguments> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-Version>${osgi.bundle.version}</Bundle-Version> - <Bundle-RequiredExecutionEnvironment>${osgi.execution.environment}</Bundle-RequiredExecutionEnvironment> - <!-- Export package is handled in exec plugin --> - <Export-Package></Export-Package> - <Import-Package></Import-Package> - </instructions> - </configuration> - <executions> - <execution> - <id>bundle-manifest</id> - <phase>prepare-package</phase> - <goals> - <goal>manifest</goal> - </goals> - </execution> - </executions> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> 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 0000000000..cd1b7a4a8e --- /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; + } +} |