Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca1df7f

Browse files
Jaroslav TulachMarcono1234
Jaroslav Tulach
andauthored
#1981: Optional OSGi bundle's dependency on sun.misc package (#1993)
*#1981: Avoid OSGi bundle's dependency on sun.misc package* Specify optional dependency on sun.misc.Unsafe* Adjusting the test to sun.misc import being optional* Using Collections.list and for loop* Let the fail message include name of packageCo-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>* Closing the input stream* Dedicated assertSubstring methodCo-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
1 parentc54caf3 commitca1df7f

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

‎gson/bnd.bnd‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Bundle-ContactAddress: ${project.parent.url}
66
Bundle-RequiredExecutionEnvironment: JavaSE-1.6, JavaSE-1.7, JavaSE-1.8
77
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.6))"
88

9+
# Optional dependency for JDK's sun.misc.Unsafe
10+
# https://bnd.bndtools.org/chapters/920-faq.html#remove-unwanted-imports-
11+
Import-Package: sun.misc;resolution:=optional, *
12+
913
-removeheaders: Private-Package
1014

1115
-exportcontents:\

‎gson/src/main/java/module-info.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010

1111
// Optional dependency on java.sql
1212
requiresstaticjava.sql;
13+
14+
// Optional dependency on jdk.unsupported for JDK's sun.misc.Unsafe
15+
requiresstaticjdk.unsupported;
1316
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (C) 2016 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
packagecom.google.gson.regression;
17+
18+
importjava.io.InputStream;
19+
importjava.io.IOException;
20+
importjava.net.URL;
21+
importjava.util.ArrayList;
22+
importjava.util.Collections;
23+
importjava.util.List;
24+
importjava.util.jar.Manifest;
25+
26+
importjunit.framework.TestCase;
27+
28+
publicclassOSGiTestextendsTestCase {
29+
publicvoidtestComGoogleGsonAnnotationsPackage()throwsException {
30+
Manifestmf =findManifest("com.google.gson");
31+
StringimportPkg =mf.getMainAttributes().getValue("Import-Package");
32+
assertNotNull("Import-Package statement is there",importPkg);
33+
assertSubstring("There should be com.google.gson.annotations dependency",importPkg,"com.google.gson.annotations");
34+
}
35+
36+
publicvoidtestSunMiscImportPackage()throwsException {
37+
Manifestmf =findManifest("com.google.gson");
38+
StringimportPkg =mf.getMainAttributes().getValue("Import-Package");
39+
assertNotNull("Import-Package statement is there",importPkg);
40+
for (Stringdep :importPkg.split(",")) {
41+
if (dep.contains("sun.misc")) {
42+
assertSubstring("sun.misc import is optional",dep,"resolution:=optional");
43+
return;
44+
}
45+
}
46+
fail("There should be sun.misc dependency, but was: " +importPkg);
47+
}
48+
49+
privateManifestfindManifest(Stringpkg)throwsIOException {
50+
List<URL>urls =newArrayList<URL>();
51+
for (URLu :Collections.list(getClass().getClassLoader().getResources("META-INF/MANIFEST.MF"))) {
52+
InputStreamis =u.openStream();
53+
Manifestmf =newManifest(is);
54+
is.close();
55+
if (pkg.equals(mf.getMainAttributes().getValue("Bundle-SymbolicName"))) {
56+
returnmf;
57+
}
58+
urls.add(u);
59+
}
60+
fail("Cannot find " +pkg +" OSGi bundle manifest among: " +urls);
61+
returnnull;
62+
}
63+
64+
privatestaticvoidassertSubstring(Stringmsg,StringwholeText,StringsubString) {
65+
if (wholeText.contains(subString)) {
66+
return;
67+
}
68+
fail(msg +". Expecting " +subString +" but was: " +wholeText);
69+
}
70+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp