Skip to content

Commit b796fc1

Browse files
authored
Merge pull request #81 from tjwatson/fixIssue76
Don't add empty directories as packages provided by a bundle
2 parents 83f21f0 + 19d4ee1 commit b796fc1

5 files changed

Lines changed: 60 additions & 19 deletions

File tree

atomos.tests/atomos.tests.index.bundles/src/test/java/org/apache/felix/atomos/tests/index/bundles/IndexLaunchTest.java

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import java.io.InputStreamReader;
2626
import java.net.URL;
2727
import java.nio.file.Path;
28+
import java.util.ArrayList;
2829
import java.util.Collection;
30+
import java.util.Collections;
2931
import java.util.HashMap;
3032
import java.util.List;
3133
import java.util.Map;
@@ -48,11 +50,17 @@
4850
import org.osgi.framework.BundleContext;
4951
import org.osgi.framework.BundleException;
5052
import org.osgi.framework.Constants;
53+
import org.osgi.framework.FrameworkUtil;
5154
import org.osgi.framework.InvalidSyntaxException;
5255
import org.osgi.framework.ServiceReference;
5356
import org.osgi.framework.Version;
5457
import org.osgi.framework.launch.Framework;
58+
import org.osgi.framework.namespace.PackageNamespace;
5559
import org.osgi.framework.wiring.BundleWiring;
60+
import org.osgi.framework.wiring.FrameworkWiring;
61+
import org.osgi.resource.Namespace;
62+
import org.osgi.resource.Requirement;
63+
import org.osgi.resource.Resource;
5664

5765
public class IndexLaunchTest
5866
{
@@ -274,23 +282,26 @@ void doTestFindEntries(@TempDir Path storage, String indexPath,
274282
{
275283
AtomosContent content = runtime.getBootLayer().findAtomosContent(
276284
"bundle." + i).get();
277-
List<String> expectedEntries = List.of( //
278-
"/META-INF/", //
279-
"/META-INF/MANIFEST.MF", //
280-
"/OSGI-INF/", //
281-
"/OSGI-INF/common.txt", //
282-
"/OSGI-INF/bundle." + i + "-1.txt", //
283-
"/OSGI-INF/bundle." + i + "-2.txt", //
284-
"/org/", //
285-
"/org/apache/", //
286-
"/org/apache/felix/", //
287-
"/org/apache/felix/atomos/", //
288-
"/org/apache/felix/atomos/tests/", //
289-
"/org/apache/felix/atomos/tests/index/", //
290-
"/org/apache/felix/atomos/tests/index/bundles/", //
291-
"/org/apache/felix/atomos/tests/index/bundles/b" + i + "/", //
292-
"/org/apache/felix/atomos/tests/index/bundles/b" + i + "/ActivatorBundle" + i + ".class" //
293-
);
285+
List<String> expectedEntries = new ArrayList<>();
286+
expectedEntries.add("/META-INF/");
287+
expectedEntries.add("/META-INF/MANIFEST.MF");
288+
expectedEntries.add("/OSGI-INF/");
289+
expectedEntries.add("/OSGI-INF/common.txt");
290+
expectedEntries.add("/OSGI-INF/bundle." + i + "-1.txt");
291+
expectedEntries.add("/OSGI-INF/bundle." + i + "-2.txt");
292+
expectedEntries.add("/org/");
293+
expectedEntries.add("/org/apache/");
294+
expectedEntries.add("/org/apache/felix/");
295+
expectedEntries.add("/org/apache/felix/atomos/");
296+
expectedEntries.add("/org/apache/felix/atomos/tests/");
297+
expectedEntries.add("/org/apache/felix/atomos/tests/index/");
298+
expectedEntries.add("/org/apache/felix/atomos/tests/index/bundles/");
299+
if (i == 3) {
300+
expectedEntries.add("/org/apache/felix/atomos/tests/index/bundles/TestClass.class");
301+
}
302+
expectedEntries.add("/org/apache/felix/atomos/tests/index/bundles/b" + i + "/");
303+
expectedEntries.add("/org/apache/felix/atomos/tests/index/bundles/b" + i + "/ActivatorBundle" + i + ".class");
304+
294305
Bundle bundle = content.getBundle();
295306
BundleWiring wiring = bundle.adapt(BundleWiring.class);
296307
List<URL> entryURLs = wiring.findEntries("/", "*",
@@ -305,6 +316,14 @@ void doTestFindEntries(@TempDir Path storage, String indexPath,
305316
}
306317
}
307318

319+
@Test
320+
void testEmptyDirectoryPackages(@TempDir Path storage) throws BundleException {
321+
testFramework = getTestFramework(storage, null);
322+
Bundle b3 = FrameworkUtil.getBundle(TestClass.class);
323+
assertNotNull(b3, "no bundle found.");
324+
assertEquals("bundle.3", b3.getSymbolicName(), "Wrong BSN");
325+
}
326+
308327
private void assertContent(String expected, URL url) throws IOException
309328
{
310329
try (BufferedReader br = new BufferedReader(
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package org.apache.felix.atomos.tests.index.bundles;
15+
16+
public class TestClass {
17+
// nothing needed here; just need a class to load
18+
}

atomos.tests/atomos.tests.index.bundles/src/test/resources/atomos/bundles.index

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ org/apache/felix/atomos/
5353
org/apache/felix/atomos/tests/
5454
org/apache/felix/atomos/tests/index/
5555
org/apache/felix/atomos/tests/index/bundles/
56+
org/apache/felix/atomos/tests/index/bundles/TestClass.class
5657
org/apache/felix/atomos/tests/index/bundles/b3/
5758
org/apache/felix/atomos/tests/index/bundles/b3/ActivatorBundle3.class
5859
ATOMOS_BUNDLE

atomos.tests/atomos.tests.index.bundles/src/test/resources/testIndex/test.index

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ org/apache/felix/atomos/
1515
org/apache/felix/atomos/tests/
1616
org/apache/felix/atomos/tests/index/
1717
org/apache/felix/atomos/tests/index/bundles/
18+
org/apache/felix/atomos/tests/index/bundles/TestClass.class
1819
org/apache/felix/atomos/tests/index/bundles/b3/
1920
org/apache/felix/atomos/tests/index/bundles/b3/ActivatorBundle3.class
2021
ATOMOS_BUNDLE

atomos/src/main/java/org/apache/felix/atomos/impl/base/AtomosBase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,9 +1663,11 @@ void addPackages(Bundle b)
16631663
try
16641664
{
16651665
content.getEntries().forEach((s) -> {
1666-
if (s.length() > 1 && s.endsWith("/") && s.indexOf('-') < 0)
1666+
int sLen = s.length();
1667+
int lastSlash = s.lastIndexOf('/');
1668+
if (sLen > 1 && s.indexOf('-') < 0 && lastSlash > 0 && lastSlash != sLen - 1)
16671669
{
1668-
String pkg = s.substring(0, s.length() - 1).replace('/', '.');
1670+
String pkg = s.substring(0, lastSlash).replace('/', '.');
16691671
packageToAtomosContent.put(pkg,
16701672
(AtomosContentIndexed) atomosContent);
16711673
}

0 commit comments

Comments
 (0)