Browse Source

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.
tags/8.1.0.alpha7
Mirjan Merruko 7 years ago
parent
commit
9a6ebeb5a8
30 changed files with 784 additions and 577 deletions
  1. 0
    224
      buildhelpers/src/main/java/com/vaadin/buildhelpers/GeneratePackageExports.java
  2. 6
    0
      client-compiled/bnd.bnd
  3. 20
    56
      client-compiled/pom.xml
  4. 47
    0
      client-compiled/src/main/java/com/vaadin/osgi/widgetset/DefaultWidgetsetContribution.java
  5. 6
    0
      compatibility-client-compiled/bnd.bnd
  6. 11
    54
      compatibility-client-compiled/pom.xml
  7. 47
    0
      compatibility-client-compiled/src/main/java/com/vaadin/osgi/compatibility/widgetset/CompatibilityWidgetsetContribution.java
  8. 10
    0
      compatibility-server/bnd.bnd
  9. 2
    30
      compatibility-server/pom.xml
  10. 6
    0
      compatibility-shared/bnd.bnd
  11. 2
    24
      compatibility-shared/pom.xml
  12. 6
    0
      compatibility-themes/bnd.bnd
  13. 11
    45
      compatibility-themes/pom.xml
  14. 49
    0
      compatibility-themes/src/main/java/com/vaadin/osgi/compatibility/themes/LegacyThemeContributions.java
  15. 36
    5
      pom.xml
  16. 6
    0
      push/bnd.bnd
  17. 16
    22
      push/pom.xml
  18. 51
    0
      push/src/main/java/com/vaadin/osgi/push/PushResourcesContribution.java
  19. 15
    0
      server/bnd.bnd
  20. 24
    41
      server/pom.xml
  21. 50
    0
      server/src/main/java/com/vaadin/server/osgi/BootstrapContribution.java
  22. 2
    0
      server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java
  23. 8
    0
      shared/bnd.bnd
  24. 11
    23
      shared/pom.xml
  25. 86
    0
      shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinResources.java
  26. 97
    0
      shared/src/main/java/com/vaadin/osgi/resources/VaadinResourceService.java
  27. 97
    0
      shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceServiceImpl.java
  28. 6
    0
      themes/bnd.bnd
  29. 11
    53
      themes/pom.xml
  30. 45
    0
      themes/src/main/java/com/vaadin/osgi/themes/ValoThemeContribution.java

+ 0
- 224
buildhelpers/src/main/java/com/vaadin/buildhelpers/GeneratePackageExports.java View File

@@ -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;
}
}

+ 6
- 0
client-compiled/bnd.bnd View File

@@ -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

+ 20
- 56
client-compiled/pom.xml View File

@@ -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,40 +56,19 @@
<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>
@@ -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>

+ 47
- 0
client-compiled/src/main/java/com/vaadin/osgi/widgetset/DefaultWidgetsetContribution.java View File

@@ -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;
}
}

+ 6
- 0
compatibility-client-compiled/bnd.bnd View File

@@ -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

+ 11
- 54
compatibility-client-compiled/pom.xml View File

@@ -50,40 +50,19 @@
<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>
@@ -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>

+ 47
- 0
compatibility-client-compiled/src/main/java/com/vaadin/osgi/compatibility/widgetset/CompatibilityWidgetsetContribution.java View File

@@ -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;
}
}

+ 10
- 0
compatibility-server/bnd.bnd View File

@@ -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

+ 2
- 30
compatibility-server/pom.xml View File

@@ -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>

+ 6
- 0
compatibility-shared/bnd.bnd View File

@@ -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

+ 2
- 24
compatibility-shared/pom.xml View File

@@ -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>

+ 6
- 0
compatibility-themes/bnd.bnd View File

@@ -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

+ 11
- 45
compatibility-themes/pom.xml View File

@@ -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>

+ 49
- 0
compatibility-themes/src/main/java/com/vaadin/osgi/compatibility/themes/LegacyThemeContributions.java View File

@@ -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;
}
}

+ 36
- 5
pom.xml View File

@@ -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>

+ 6
- 0
push/bnd.bnd View File

@@ -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

+ 16
- 22
push/pom.xml View File

@@ -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>

+ 51
- 0
push/src/main/java/com/vaadin/osgi/push/PushResourcesContribution.java View File

@@ -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;
}
}

+ 15
- 0
server/bnd.bnd View File

@@ -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

+ 24
- 41
server/pom.xml View File

@@ -18,6 +18,14 @@
<!-- API DEPENDENCIES -->

<!-- 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>
@@ -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>

+ 50
- 0
server/src/main/java/com/vaadin/server/osgi/BootstrapContribution.java View File

@@ -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;
}
}

+ 2
- 0
server/src/test/java/com/vaadin/tests/server/ClassesSerializableTest.java View File

@@ -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.*"
};

/**

+ 8
- 0
shared/bnd.bnd View File

@@ -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

+ 11
- 23
shared/pom.xml View File

@@ -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>

+ 86
- 0
shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinResources.java View File

@@ -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;
}
}

+ 97
- 0
shared/src/main/java/com/vaadin/osgi/resources/VaadinResourceService.java View File

@@ -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();

}

+ 97
- 0
shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceServiceImpl.java View File

@@ -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);
}
}

+ 6
- 0
themes/bnd.bnd View File

@@ -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

+ 11
- 53
themes/pom.xml View File

@@ -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>

+ 45
- 0
themes/src/main/java/com/vaadin/osgi/themes/ValoThemeContribution.java View File

@@ -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;
}
}

Loading…
Cancel
Save