Skip to content

Commit

Permalink
google#1981: Avoid OSGi bundle's dependency on sun.misc package
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaroslav Tulach committed Oct 14, 2021
1 parent e6fae59 commit 53db9e8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions gson/bnd.bnd
Expand Up @@ -5,6 +5,7 @@ Bundle-Vendor: Google Gson Project
Bundle-ContactAddress: ${project.parent.url}
Bundle-RequiredExecutionEnvironment: JavaSE-1.6, JavaSE-1.7, JavaSE-1.8
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.6))"
Import-Package: com.google.gson.*,!sun.misc

-removeheaders: Private-Package

Expand Down
49 changes: 49 additions & 0 deletions gson/src/test/java/com/google/gson/regression/OSGiTest.java
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2016 Google Inc.
*
* 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.google.gson.regression;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.Manifest;

import junit.framework.TestCase;

public class OSGiTest extends TestCase {
public void testSunMiscImportPackage() throws Exception {
Manifest mf = findManifest("com.google.gson");
String importPkg = mf.getMainAttributes().getValue("Import-Package");
assertNotNull("Import-Package statement is currently there", importPkg);
assertEquals("There should be no sun.misc dependency, but was: " + importPkg, -1, importPkg.indexOf("sun.misc"));
}

private Manifest findManifest(String pkg) throws IOException {
Enumeration<URL> en = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
List<URL> urls = new ArrayList<URL>();
while (en.hasMoreElements()) {
URL u = en.nextElement();
Manifest mf = new Manifest(u.openStream());
if (pkg.equals(mf.getMainAttributes().getValue("Bundle-SymbolicName"))) {
return mf;
}
urls.add(u);
}
fail("Cannot find com.google.gson OSGi bundle manifest among: " + urls);
return null;
}
}

0 comments on commit 53db9e8

Please sign in to comment.