You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by tj...@apache.org on 2020/02/27 17:16:47 UTC
[felix-atomos] branch master updated: FELIX-6226: Code clean up
This is an automated email from the ASF dual-hosted git repository.
tjwatson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-atomos.git
The following commit(s) were added to refs/heads/master by this push:
new 9386f9d FELIX-6226: Code clean up
new 196b7a5 Merge pull request #3 from tjwatson/FELIX-6226
9386f9d is described below
commit 9386f9d898d32ac42f4fd50e2d5e0d574d56f4fd
Author: Thomas Watson <tj...@us.ibm.com>
AuthorDate: Wed Feb 26 15:31:31 2020 -0600
FELIX-6226: Code clean up
- Move LoaderType from AtomosRuntime to AtomosLayer
- remove unnecessary public modifier
- Use method references where possible
- Remove extra lambdas where possible
- Fix up javadoc link issues
- remove unused params
- remove unused methods/constructors
---
atomos.runtime/pom.xml | 2 +-
.../atomos/impl/runtime/base/AtomosCommands.java | 9 +--
.../impl/runtime/base/AtomosFrameworkHooks.java | 1 -
.../impl/runtime/base/AtomosModuleConnector.java | 16 +----
.../impl/runtime/base/AtomosRuntimeBase.java | 80 ++++++++--------------
.../impl/runtime/base/AtomosRuntimeClassPath.java | 1 +
.../atomos/impl/runtime/base/AtomosStorage.java | 9 ++-
.../impl/runtime/base/FileConnectContent.java | 6 +-
.../impl/runtime/modules/AtomosRuntimeModules.java | 11 ++-
.../impl/runtime/modules/ModuleConnectLoader.java | 15 ++--
.../runtime/substrate/AtomosRuntimeSubstrate.java | 8 +--
.../apache/felix/atomos/launch/AtomosLauncher.java | 7 +-
.../apache/felix/atomos/runtime/AtomosContent.java | 20 +++---
.../apache/felix/atomos/runtime/AtomosLayer.java | 41 ++++++++---
.../apache/felix/atomos/runtime/AtomosRuntime.java | 18 ++---
.../service/test/ClasspathLaunchTest.java | 2 +-
.../modulepath/service/ModulepathLaunchTest.java | 54 ++++++---------
17 files changed, 129 insertions(+), 171 deletions(-)
diff --git a/atomos.runtime/pom.xml b/atomos.runtime/pom.xml
index 8a735fd..1c91d22 100644
--- a/atomos.runtime/pom.xml
+++ b/atomos.runtime/pom.xml
@@ -101,7 +101,7 @@
<exclude>module-info.java</exclude>
<exclude>org/atomos/framework/modules/*.java</exclude>
</excludes>
- <release combine.self="override"></release>
+ <release combine.self="override"/>
<source>1.8</source>
<target>1.8</target>
</configuration>
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosCommands.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosCommands.java
index cc9656c..7fa52ad 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosCommands.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosCommands.java
@@ -25,7 +25,7 @@ import java.util.stream.Stream;
import org.apache.felix.atomos.runtime.AtomosContent;
import org.apache.felix.atomos.runtime.AtomosLayer;
-import org.apache.felix.atomos.runtime.AtomosRuntime.LoaderType;
+import org.apache.felix.atomos.runtime.AtomosLayer.LoaderType;
import org.apache.felix.service.command.Descriptor;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -55,7 +55,7 @@ public class AtomosCommands
public void list()
{
AtomosLayer bl = runtime.getBootLayer();
- layers(bl.getParents().stream().findFirst().orElseGet(() -> bl), new HashSet<>());
+ layers(bl.getParents().stream().findFirst().orElse(bl), new HashSet<>());
}
private void layers(AtomosLayer layer, Set<AtomosLayer> visited)
@@ -121,9 +121,10 @@ public class AtomosCommands
Optional<LoaderType> oLoaderType = Stream.of(LoaderType.values()).filter(
e -> e.name().equalsIgnoreCase(loaderType)).findAny();
- if (!oLoaderType.isPresent())
+ if (oLoaderType.isEmpty())
{
- String v = Stream.of(LoaderType.values()).map(LoaderType::name).collect(
+ String v = Stream.of(LoaderType.values()).map(
+ LoaderType::name).collect(
Collectors.joining(", "));
System.out.printf("The specified loaderType is not valid. Use one of %s", v);
return;
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosFrameworkHooks.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosFrameworkHooks.java
index e580421..8296a16 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosFrameworkHooks.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosFrameworkHooks.java
@@ -61,7 +61,6 @@ public class AtomosFrameworkHooks implements ResolverHookFactory, CollisionHook
return;
default:
atomosRuntime.filterNotVisible(atomosBundle, candidates);
- return;
}
}
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosModuleConnector.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosModuleConnector.java
index 47c0b1d..7b31008 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosModuleConnector.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosModuleConnector.java
@@ -19,7 +19,6 @@ import java.util.Map;
import java.util.Optional;
import org.apache.felix.atomos.impl.runtime.base.AtomosRuntimeBase.AtomosLayerBase.AtomosContentBase;
-import org.apache.felix.atomos.runtime.AtomosRuntime;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.connect.ConnectModule;
@@ -29,18 +28,9 @@ public class AtomosModuleConnector implements ModuleConnector
{
final AtomosRuntimeBase atomosRuntime;
- public AtomosModuleConnector()
+ public AtomosModuleConnector(AtomosRuntimeBase atomosRuntime)
{
- this(null);
- }
-
- public AtomosModuleConnector(AtomosRuntime atomosRuntime)
- {
- if (atomosRuntime == null)
- {
- atomosRuntime = AtomosRuntime.newAtomosRuntime();
- }
- this.atomosRuntime = (AtomosRuntimeBase) atomosRuntime;
+ this.atomosRuntime = atomosRuntime;
}
@Override
@@ -75,7 +65,7 @@ public class AtomosModuleConnector implements ModuleConnector
return Optional.empty();
}
atomosRuntime.addManagingConnected(atomosBundle, location);
- return Optional.ofNullable(() -> atomosBundle.getConnectContent());
+ return Optional.of(atomosBundle::getConnectContent);
}
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeBase.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeBase.java
index 505e732..63c962c 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeBase.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeBase.java
@@ -30,7 +30,6 @@ import java.util.Deque;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -47,14 +46,9 @@ import org.apache.felix.atomos.impl.runtime.base.AtomosRuntimeBase.AtomosLayerBa
import org.apache.felix.atomos.impl.runtime.substrate.AtomosRuntimeSubstrate;
import org.apache.felix.atomos.runtime.AtomosContent;
import org.apache.felix.atomos.runtime.AtomosLayer;
+import org.apache.felix.atomos.runtime.AtomosLayer.LoaderType;
import org.apache.felix.atomos.runtime.AtomosRuntime;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
-import org.osgi.framework.SynchronousBundleListener;
-import org.osgi.framework.Version;
+import org.osgi.framework.*;
import org.osgi.framework.connect.ConnectContent;
import org.osgi.framework.connect.ConnectFrameworkFactory;
import org.osgi.framework.connect.FrameworkUtilHelper;
@@ -103,6 +97,8 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
protected final AtomicLong nextLayerId = new AtomicLong(0);
+ ServiceRegistration<?> atomosCommandsReg = null;
+
public static AtomosRuntime newAtomosRuntime()
{
String runtimeClass = System.getProperty(ATOMOS_RUNTIME_CLASS);
@@ -158,8 +154,7 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
public static File findSubstrateLibDir()
{
String substrateProp = System.getProperty(ATOMOS_SUBSTRATE);
- File result = new File(substrateProp, SUBSTRATE_LIB_DIR);
- return result;
+ return new File(substrateProp, SUBSTRATE_LIB_DIR);
}
protected AtomosRuntimeBase()
@@ -356,14 +351,7 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
return context.get();
}
- final ThreadLocal<Deque<AtomosContent>> managingConnected = new ThreadLocal<Deque<AtomosContent>>()
- {
- @Override
- protected Deque<AtomosContent> initialValue()
- {
- return new ArrayDeque<>();
- }
- };
+ final ThreadLocal<Deque<AtomosContent>> managingConnected = ThreadLocal.withInitial(ArrayDeque::new);
final Bundle installAtomosContent(String prefix,
AtomosContentBase atomosContent)
@@ -394,7 +382,7 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
}
AtomosLayerBase atomosLayer = (AtomosLayerBase) atomosContent.getAtomosLayer();
- if (!atomosLayer.isValid())
+ if (atomosLayer.isNotValid())
{
throw new BundleException("Atomos layer has been uninstalled.",
BundleException.INVALID_OPERATION);
@@ -430,7 +418,7 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
finally
{
// check if the layer is still valid
- if (!atomosLayer.isValid())
+ if (atomosLayer.isNotValid())
{
// The atomosLayer became invalid while installing
if (result != null)
@@ -790,7 +778,7 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
BundleContext bc = getBundleContext();
if (bc != null)
{
- uninstallLayer(uninstalledBundles, bc);
+ uninstallLayer(uninstalledBundles);
}
lockWrite();
@@ -822,12 +810,12 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
{
((AtomosLayerBase) child).removeLayerFromRuntime();
}
- getAtomosContents().forEach(c -> c.disconnect());
+ getAtomosContents().forEach(AtomosContent::disconnect);
idToLayer.remove(getId());
removedLayer(this);
}
- final void uninstallLayer(List<Bundle> uninstalledBundles, BundleContext bc)
+ final void uninstallLayer(List<Bundle> uninstalledBundles)
throws BundleException
{
// mark as invalid first to prevent installs
@@ -840,17 +828,17 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
// first uninstall all children
for (AtomosLayer child : getChildren())
{
- ((AtomosLayerBase) child).uninstallLayer(uninstalledBundles, bc);
+ ((AtomosLayerBase) child).uninstallLayer(uninstalledBundles);
}
- uninstallBundles(uninstalledBundles, bc);
+ uninstallBundles(uninstalledBundles);
}
- final boolean isValid()
+ final boolean isNotValid()
{
- return valid;
+ return !valid;
}
- private void uninstallBundles(List<Bundle> uninstalled, BundleContext bc)
+ private void uninstallBundles(List<Bundle> uninstalled)
throws BundleException
{
for (AtomosContent content : getAtomosContents())
@@ -1153,18 +1141,11 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
{
if (atomosContent != null)
{
- for (Iterator<BundleCapability> iCands = candidates.iterator(); iCands.hasNext();)
- {
- BundleCapability candidate = iCands.next();
- if (!isVisible(atomosContent, candidate))
- {
- iCands.remove();
- }
- }
+ candidates.removeIf(candidate -> !isVisible(atomosContent, candidate));
}
}
- private final boolean isVisible(
+ private boolean isVisible(
AtomosContent atomosContent,
BundleCapability candidate)
{
@@ -1205,17 +1186,13 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
}
Thread saveOnVMExit = new Thread(() -> {
- BundleContext bc = context.get();
- if (bc != null)
+ try
{
- try
- {
- new AtomosStorage(this).saveLayers(storeRoot.get(), bc.getBundles());
- }
- catch (IOException e)
- {
- throw new RuntimeException("Failed to save atomos runtime.", e);
- }
+ new AtomosStorage(this).saveLayers(storeRoot.get());
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Failed to save atomos runtime.", e);
}
});
@@ -1232,13 +1209,13 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
bc.registerService(ResolverHookFactory.class, hooks, null);
bc.registerService(CollisionHook.class, hooks, null);
- boolean installBundles = Boolean.valueOf(
+ boolean installBundles = Boolean.parseBoolean(
getProperty(bc, AtomosRuntime.ATOMOS_CONTENT_INSTALL, "true"));
- boolean startBundles = Boolean.valueOf(
+ boolean startBundles = Boolean.parseBoolean(
getProperty(bc, AtomosRuntime.ATOMOS_CONTENT_START, "true"));
installAtomosContents(getBootLayer(), installBundles, startBundles);
bc.registerService(AtomosRuntime.class, this, null);
- new AtomosCommands(this).register(bc);
+ atomosCommandsReg = new AtomosCommands(this).register(bc);
}
protected void stop(BundleContext bc) throws BundleException
@@ -1248,7 +1225,7 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
try
{
Runtime.getRuntime().removeShutdownHook(saveOnVMExit);
- new AtomosStorage(this).saveLayers(storeRoot.get(), bc.getBundles());
+ new AtomosStorage(this).saveLayers(storeRoot.get());
}
catch (IllegalStateException e)
{
@@ -1263,6 +1240,7 @@ public abstract class AtomosRuntimeBase implements AtomosRuntime, SynchronousBun
bc.removeBundleListener(this);
AtomosFrameworkUtilHelper.removeHelper(this);
+ atomosCommandsReg.unregister();
}
private String getProperty(BundleContext bc, String key, String defaultValue)
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeClassPath.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeClassPath.java
index 5254e51..f7fa06b 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeClassPath.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosRuntimeClassPath.java
@@ -24,6 +24,7 @@ import java.util.Set;
import org.apache.felix.atomos.runtime.AtomosContent;
import org.apache.felix.atomos.runtime.AtomosLayer;
+import org.apache.felix.atomos.runtime.AtomosLayer.LoaderType;
import org.osgi.framework.connect.ConnectFrameworkFactory;
import org.osgi.framework.wiring.BundleCapability;
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosStorage.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosStorage.java
index 0e0e36e..e59415b 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosStorage.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/AtomosStorage.java
@@ -34,8 +34,7 @@ import org.apache.felix.atomos.impl.runtime.base.AtomosRuntimeBase.AtomosLayerBa
import org.apache.felix.atomos.impl.runtime.base.AtomosRuntimeBase.AtomosLayerBase.AtomosContentBase;
import org.apache.felix.atomos.runtime.AtomosContent;
import org.apache.felix.atomos.runtime.AtomosLayer;
-import org.apache.felix.atomos.runtime.AtomosRuntime.LoaderType;
-import org.osgi.framework.Bundle;
+import org.apache.felix.atomos.runtime.AtomosLayer.LoaderType;
import org.osgi.framework.Constants;
public class AtomosStorage
@@ -82,7 +81,7 @@ public class AtomosStorage
}
}
- void saveLayers(File root, Bundle[] bundles) throws IOException
+ void saveLayers(File root) throws IOException
{
File atomosStore = new File(root, ATOMOS_STORE);
atomosRuntime.lockRead();
@@ -92,7 +91,7 @@ public class AtomosStorage
out.writeInt(VERSION);
out.writeLong(atomosRuntime.nextLayerId.get());
List<AtomosLayerBase> writeOrder = getLayerWriteOrder(
- (AtomosLayerBase) atomosRuntime.getBootLayer(), new HashSet<>(),
+ atomosRuntime.getBootLayer(), new HashSet<>(),
new ArrayList<>());
out.writeInt(writeOrder.size());
for (AtomosLayerBase layer : writeOrder)
@@ -225,7 +224,7 @@ public class AtomosStorage
out.writeInt(parents.size());
for (AtomosLayer parent : parents)
{
- out.writeLong(((AtomosLayerBase) parent).getId());
+ out.writeLong(parent.getId());
}
Set<AtomosContent> contents = layer.getAtomosContents();
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/FileConnectContent.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/FileConnectContent.java
index 64681d4..3f422e4 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/FileConnectContent.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/base/FileConnectContent.java
@@ -27,7 +27,7 @@ import org.osgi.framework.connect.ConnectContent;
public class FileConnectContent implements ConnectContent
{
- public class FileConnectEntry implements ConnectEntry
+ public static class FileConnectEntry implements ConnectEntry
{
private final File entry;
private final String name;
@@ -132,9 +132,7 @@ public class FileConnectContent implements ConnectContent
{
return Optional.empty();
}
- final boolean checkInFile = path != null
- && path.indexOf(POINTER_UPPER_DIRECTORY) >= 0;
- if (checkInFile)
+ if (path.contains(POINTER_UPPER_DIRECTORY))
{
try
{
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/modules/AtomosRuntimeModules.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/modules/AtomosRuntimeModules.java
index 2e27a22..ca66d41 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/modules/AtomosRuntimeModules.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/modules/AtomosRuntimeModules.java
@@ -47,6 +47,7 @@ import org.apache.felix.atomos.impl.runtime.base.AtomosRuntimeBase;
import org.apache.felix.atomos.impl.runtime.base.JavaServiceNamespace;
import org.apache.felix.atomos.runtime.AtomosContent;
import org.apache.felix.atomos.runtime.AtomosLayer;
+import org.apache.felix.atomos.runtime.AtomosLayer.LoaderType;
import org.apache.felix.atomos.runtime.AtomosRuntime;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -121,10 +122,9 @@ public class AtomosRuntimeModules extends AtomosRuntimeBase
getClass().getModule().getLayer(), //
ConnectFrameworkFactory.class);
}
- ConnectFrameworkFactory factory = loader.findFirst() //
+ return loader.findFirst() //
.orElseThrow(
() -> new RuntimeException("No Framework implementation found."));
- return factory;
}
AtomosLayerBase createAtomosLayer(Configuration config, String name, long id,
@@ -190,7 +190,7 @@ public class AtomosRuntimeModules extends AtomosRuntimeBase
protected void addingLayer(AtomosLayerBase atomosLayer)
{
Configuration config = atomosLayer.adapt(ModuleLayer.class).map(
- (m) -> m.configuration()).orElse(null);
+ ModuleLayer::configuration).orElse(null);
if (byConfig.putIfAbsent(config, atomosLayer) != null)
{
throw new IllegalStateException(
@@ -202,7 +202,7 @@ public class AtomosRuntimeModules extends AtomosRuntimeBase
protected void removedLayer(AtomosLayerBase atomosLayer)
{
byConfig.remove(
- atomosLayer.adapt(ModuleLayer.class).map((l) -> l.configuration()).orElse(
+ atomosLayer.adapt(ModuleLayer.class).map(ModuleLayer::configuration).orElse(
null));
}
@@ -410,8 +410,7 @@ public class AtomosRuntimeModules extends AtomosRuntimeBase
capabilities.append(
JavaServiceNamespace.CAPABILITY_PROVIDES_WITH_ATTRIBUTE).append(
"=\"").append(
- provides.providers().stream().collect(
- Collectors.joining(","))).append("\"");
+ String.join(",", provides.providers())).append("\"");
}
// map uses to a made up namespace only to give proper resolution errors
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/modules/ModuleConnectLoader.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/modules/ModuleConnectLoader.java
index 79152ac..055f34b 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/modules/ModuleConnectLoader.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/modules/ModuleConnectLoader.java
@@ -45,12 +45,11 @@ public final class ModuleConnectLoader extends SecureClassLoader implements Bund
}
private final ResolvedModule resolvedModule;
- private final ModuleReference reference;
private final ModuleReader reader;
private final AtomosRuntimeModules atomosRuntime;
private final AtomicReference<Module> module = new AtomicReference<>();
- private final HashMap<String, ClassLoader> edges = new HashMap<String, ClassLoader>();
+ private final HashMap<String, ClassLoader> edges = new HashMap<>();
public ModuleConnectLoader(ResolvedModule resolvedModule, AtomosRuntimeModules atomosRuntimeModules) throws IOException
{
@@ -58,7 +57,7 @@ public final class ModuleConnectLoader extends SecureClassLoader implements Bund
this.resolvedModule = resolvedModule;
//TODO remove reference and reader? Or Reader needs to be closed?
- this.reference = resolvedModule.reference();
+ ModuleReference reference = resolvedModule.reference();
this.reader = reference.open();
this.atomosRuntime = atomosRuntimeModules;
}
@@ -75,7 +74,6 @@ public final class ModuleConnectLoader extends SecureClassLoader implements Bund
*
* @param module module associated with this class loader
* @param loaderConfig configuration containing
- * @param parentLayers
* @param loaders
*/
void initEdges(Module module, Configuration loaderConfig,
@@ -128,11 +126,7 @@ public final class ModuleConnectLoader extends SecureClassLoader implements Bund
protected URL findResource(String moduleName, String name) throws IOException
{
URL resource = null;
- if (!this.resolvedModule.name().equals(moduleName))
- {
- resource = null;
- }
- else
+ if (this.resolvedModule.name().equals(moduleName))
{
try
{
@@ -192,8 +186,7 @@ public final class ModuleConnectLoader extends SecureClassLoader implements Bund
@Override
public URL getResource(String name)
{
- URL retVal = null;
- retVal = findResource(name);
+ URL retVal = findResource(name);
if (retVal == null)
{
retVal = ClassLoader.getSystemResource(name);
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/substrate/AtomosRuntimeSubstrate.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/substrate/AtomosRuntimeSubstrate.java
index a6bc537..449a200 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/substrate/AtomosRuntimeSubstrate.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/impl/runtime/substrate/AtomosRuntimeSubstrate.java
@@ -36,6 +36,7 @@ import java.util.jar.JarFile;
import org.apache.felix.atomos.impl.runtime.base.AtomosRuntimeBase;
import org.apache.felix.atomos.runtime.AtomosContent;
import org.apache.felix.atomos.runtime.AtomosLayer;
+import org.apache.felix.atomos.runtime.AtomosLayer.LoaderType;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -62,16 +63,11 @@ import sun.misc.Signal;
*/
public class AtomosRuntimeSubstrate extends AtomosRuntimeBase
{
- private final String ATOMOS_BUNDLE = "ATOMOS_BUNDLE";
+ private static final String ATOMOS_BUNDLE = "ATOMOS_BUNDLE";
private final File substrateLibDir;
private final AtomosLayerSubstrate bootLayer;
private final List<SubstrateBundleIndexInfo> indexBundles;
- public AtomosRuntimeSubstrate()
- {
- this(null);
- }
-
static class SubstrateBundleIndexInfo
{
final String index;
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/launch/AtomosLauncher.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/launch/AtomosLauncher.java
index 448e4c8..deed6c4 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/launch/AtomosLauncher.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/launch/AtomosLauncher.java
@@ -148,11 +148,8 @@ public class AtomosLauncher
frameworkConfig.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "");
}
- if (frameworkConfig.get("osgi.console") == null)
- {
- // Always allow the console to work
- frameworkConfig.put("osgi.console", "");
- }
+ // Always allow the console to work
+ frameworkConfig.putIfAbsent("osgi.console", "");
return ((AtomosRuntimeBase) atomosRuntime).findFrameworkFactory().newFramework(
frameworkConfig, atomosRuntime.getModuleConnector());
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosContent.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosContent.java
index 9d189a4..9929fc6 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosContent.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosContent.java
@@ -37,38 +37,38 @@ public interface AtomosContent extends Comparable<AtomosContent>
* @return the location of the Atomos content.
* @see AtomosContent#install(String)
*/
- public String getAtomosLocation();
+ String getAtomosLocation();
/**
* The symbolic name of the Atomos content.
* @return the symbolic name.
*/
- public String getSymbolicName();
+ String getSymbolicName();
/**
* The version of the Atomos content.
* @return the version
*/
- public Version getVersion();
+ Version getVersion();
/**
* Adapt this Atomos content to the specified type. For example,
* if running in a module layer then the module of the Atomos
* content is returned in the optional value.
- * @param <A> The type to which this Atomos content is to be adapted.
+ * @param <T> The type to which this Atomos content is to be adapted.
* @param type Class object for the type to which this Atomos content is to be
* adapted.
* @return The object, of the specified type, to which this Atomos content has been
* adapted or {@code null} if this content cannot be adapted to the
* specified type.
*/
- public <T> Optional<T> adapt(Class<T> type);
+ <T> Optional<T> adapt(Class<T> type);
/**
* The Atomos layer this Atomos content is in.
* @return the Atomos layer
*/
- public AtomosLayer getAtomosLayer();
+ AtomosLayer getAtomosLayer();
/**
* Installs this Atomos content as a connected bundle using the specified location prefix.
@@ -97,7 +97,7 @@ public interface AtomosContent extends Comparable<AtomosContent>
* @return the installed connected bundle.
* @throws BundleException if an error occurs installing the Atomos content
*/
- public Bundle install(String prefix) throws BundleException;
+ Bundle install(String prefix) throws BundleException;
/**
* Returns the connected bundle location for this Atomos content or {@code null} if
@@ -107,7 +107,7 @@ public interface AtomosContent extends Comparable<AtomosContent>
* into the framework using this bundle location.
* @return the bundle location or {@code null}
*/
- public String getConnectLocation();
+ String getConnectLocation();
/**
* Connects the specified bundle location to this Atomos content. Unlike
@@ -121,13 +121,13 @@ public interface AtomosContent extends Comparable<AtomosContent>
* @throws IllegalStateException if the connect location is already being used as a connect location
* or if this content already has a different connect location set
*/
- public void connect(String bundleLocation);
+ void connect(String bundleLocation);
/**
* Disconnects this Atomos content from the bundle location, if the bundle location
* is set. This method does nothing if this content is not connected.
*/
- public void disconnect();
+ void disconnect();
/**
* Returns the OSGi bundle installed which is connected with this Atomos content.
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosLayer.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosLayer.java
index 2ba1d06..5d5b3ce 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosLayer.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosLayer.java
@@ -15,34 +15,58 @@ package org.apache.felix.atomos.runtime;
import java.nio.file.Path;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.Set;
-import org.apache.felix.atomos.runtime.AtomosRuntime.LoaderType;
import org.osgi.framework.BundleException;
+import org.osgi.framework.connect.ConnectFrameworkFactory;
+import org.osgi.framework.connect.ModuleConnector;
/**
* An Atomos Layer may represents a {@link ModuleLayer} that was added to
- * a {@link AtomosRuntime} using the {@link AtomosRuntime#addLayer(Configuration) addLayer}
+ * a {@link AtomosRuntime} using the {@link AtomosLayer#addLayer(String, LoaderType, Path...)} addLayer}
* method or the Atomos Layer could represent the {@link AtomosRuntime#getBootLayer() boot layer}.
* An Atomos Layer will contain one or more {@link AtomosContent Atomos contents} which can
* then be used to {@link AtomosContent#install(String) install } them as OSGi connected bundles into the
- * {@link AtomosRuntime#newFramework(java.util.Map) framework}.
+ * {@link ConnectFrameworkFactory#newFramework(Map, ModuleConnector)} framework}.
*/
public interface AtomosLayer
{
/**
+ * The loader type used for the class loaders of an Atomos layer.
+ */
+ enum LoaderType
+ {
+ /**
+ * Loader type that will use a unique loader for each connected bundle in the
+ * layer and the loader will implement the {@link org.osgi.framework.BundleReference}
+ * interface.
+ */
+ OSGI,
+ /**
+ * Loader type that will use a single loader for each connected bundle in the
+ * layer.
+ */
+ SINGLE,
+ /**
+ * Loader type that will use a unique loader for each connected bundle in the
+ * layer.
+ */
+ MANY
+ }
+ /**
* Adapt this Atomos layer to the specified type. For example,
* if running in a module layer then the layer can be adapted
* to a ModuleLayer associated with this Atomos Layer.
- * @param <A> The type to which this Atomos layer is to be adapted.
+ * @param <T> The type to which this Atomos layer is to be adapted.
* @param type Class object for the type to which this Atomos layer is to be
* adapted.
* @return The object, of the specified type, to which this Atomos layer has been
* adapted or {@code null} if this layer cannot be adapted to the
* specified type.
*/
- public <T> Optional<T> adapt(Class<T> type);
+ <T> Optional<T> adapt(Class<T> type);
/**
* Adds a layer as a child of this layer and loads modules from the specified
@@ -65,7 +89,7 @@ public interface AtomosLayer
* folder with the same name as the specified name of the layer.
* @throws UnsupportedOperationException if {@link #isAddLayerSupported()} returns false.
*/
- public AtomosLayer addModules(String name, Path path);
+ AtomosLayer addModules(String name, Path path);
/**
* Returns {@code true} if additional layers are supported.
@@ -109,7 +133,7 @@ public interface AtomosLayer
* The name of the Atomos Layer. By default the Atomos Layer
* name is the empty string. Atomos Layer names are not
* required to be unique. All Atomos contents contained in a
- * layer will have {@link AtomosBundleInfo#getAtomosLocation() locations}
+ * layer will have {@link AtomosContent#getAtomosLocation() locations}
* that use the layer name as a prefix. If the layer
* name is not the empty string then the location prefix will be
* the layer name followed by a colon ({@code :}).
@@ -146,7 +170,8 @@ public interface AtomosLayer
/**
* Uninstalls this Atomos Layer along with any {@link #getChildren() children}
* layers.
- * @throws BundleException
+ * @throws BundleException If an error happened while uninstalling any connected
+ * bundles in the layer
*/
void uninstall() throws BundleException;
}
diff --git a/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosRuntime.java b/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosRuntime.java
index fe4a270..bdfe4ad 100644
--- a/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosRuntime.java
+++ b/atomos.runtime/src/main/java/org/apache/felix/atomos/runtime/AtomosRuntime.java
@@ -138,14 +138,6 @@ import org.osgi.framework.launch.FrameworkFactory;
public interface AtomosRuntime
{
/**
- * The loader type used for the class loaders of an Atomos layer.
- */
- public enum LoaderType
- {
- OSGI, SINGLE, MANY
- }
-
- /**
* Framework launching property specifying if the Atomos contents
* will not be automatically installed as bundles. Default is true, which
* will install all discovered Atomos content as bundles.
@@ -193,15 +185,15 @@ public interface AtomosRuntime
* Creates a new AtomosRuntime that can be used to create a new OSGi framework
* instance. If Atomos is running as a Java Module then this AtomosRuntime can
* be used to create additional layers by using the
- * {@link AtomosLayer#addLayer(String, LoaderType, Path...)} method. If the additional layers are added
- * before {@link #newFramework(Map) creating} and {@link Framework#init()
+ * {@link AtomosLayer#addLayer(String, AtomosLayer.LoaderType, Path...)} method. If the additional layers are added
+ * before {@link ConnectFrameworkFactory#newFramework(Map, ModuleConnector)} creating} and {@link Framework#init()
* initializing} the framework then the Atomos contents found in the added layers
* will be automatically installed and started according to the
* {@link #ATOMOS_CONTENT_INSTALL} and {@link #ATOMOS_CONTENT_START} options.
* <p>
- * Note that this AtomosRuntime {@link #newFramework(Map)} must be used for a
- * new {@link Framework framework} instance to use the layers added to this
- * AtomosRuntime.
+ * Note that this {@code AtomosRuntime} must be used for creating a new
+ * {@link ConnectFrameworkFactory#newFramework(Map, ModuleConnector)} instance to use
+ * the layers added to this {@code AtomosRuntime}.
*
* @return a new AtomosRuntime.
*/
diff --git a/atomos.tests/atomos.tests.classpath.service/src/test/java/org/apache/felix/atomos/tests/classpath/service/test/ClasspathLaunchTest.java b/atomos.tests/atomos.tests.classpath.service/src/test/java/org/apache/felix/atomos/tests/classpath/service/test/ClasspathLaunchTest.java
index bb1ecda..0ea5509 100644
--- a/atomos.tests/atomos.tests.classpath.service/src/test/java/org/apache/felix/atomos/tests/classpath/service/test/ClasspathLaunchTest.java
+++ b/atomos.tests/atomos.tests.classpath.service/src/test/java/org/apache/felix/atomos/tests/classpath/service/test/ClasspathLaunchTest.java
@@ -30,8 +30,8 @@ import java.util.Optional;
import org.apache.felix.atomos.impl.runtime.base.AtomosCommands;
import org.apache.felix.atomos.runtime.AtomosContent;
import org.apache.felix.atomos.runtime.AtomosLayer;
+import org.apache.felix.atomos.runtime.AtomosLayer.LoaderType;
import org.apache.felix.atomos.runtime.AtomosRuntime;
-import org.apache.felix.atomos.runtime.AtomosRuntime.LoaderType;
import org.apache.felix.atomos.tests.classpath.service.ClasspathLaunch;
import org.apache.felix.atomos.tests.testbundles.service.contract.Echo;
import org.junit.jupiter.api.AfterEach;
diff --git a/atomos.tests/atomos.tests.modulepath.service/src/test/java/org/apache/felix/atomos/tests/modulepath/service/ModulepathLaunchTest.java b/atomos.tests/atomos.tests.modulepath.service/src/test/java/org/apache/felix/atomos/tests/modulepath/service/ModulepathLaunchTest.java
index 58038e3..9186079 100644
--- a/atomos.tests/atomos.tests.modulepath.service/src/test/java/org/apache/felix/atomos/tests/modulepath/service/ModulepathLaunchTest.java
+++ b/atomos.tests/atomos.tests.modulepath.service/src/test/java/org/apache/felix/atomos/tests/modulepath/service/ModulepathLaunchTest.java
@@ -26,22 +26,14 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
import java.util.stream.Collectors;
import org.apache.felix.atomos.launch.AtomosLauncher;
import org.apache.felix.atomos.runtime.AtomosContent;
import org.apache.felix.atomos.runtime.AtomosLayer;
+import org.apache.felix.atomos.runtime.AtomosLayer.LoaderType;
import org.apache.felix.atomos.runtime.AtomosRuntime;
-import org.apache.felix.atomos.runtime.AtomosRuntime.LoaderType;
import org.apache.felix.atomos.tests.testbundles.service.contract.Echo;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
@@ -343,14 +335,14 @@ public class ModulepathLaunchTest
final List<Bundle> allChildBundles = layers.stream().flatMap(
(l) -> l.getAtomosContents().stream()).map(
- (a) -> a.getBundle()).filter(
+ AtomosContent::getBundle).filter(
Objects::nonNull).collect(Collectors.toList());
final AtomosLayer firstChild = layers.iterator().next();
final Set<AtomosContent> firstChildContents = firstChild.getAtomosContents();
List<Bundle> firstChildBundles = firstChildContents.stream().map(
- (a) -> a.getBundle()).filter(
+ AtomosContent::getBundle).filter(
Objects::nonNull).collect(Collectors.toList());
assertEquals(5, firstChildBundles.size(),
@@ -373,7 +365,7 @@ public class ModulepathLaunchTest
});
firstChildBundles = firstChildContents.stream().map(
- (a) -> a.getBundle()).filter(
+ AtomosContent::getBundle).filter(
Objects::nonNull).collect(Collectors.toList());
assertEquals(0, firstChildBundles.size(),
"Wrong number of bundles in first child.");
@@ -391,10 +383,8 @@ public class ModulepathLaunchTest
checkServices(bc, 4);
// uninstalling the layer forces all of its content to get disconnected
- allChildBundles.forEach((b) -> {
- assertNull(atomosRuntime.getConnectedContent(b.getLocation()),
- "Atomos content not expected.");
- });
+ allChildBundles.forEach((b) -> assertNull(atomosRuntime.getConnectedContent(b.getLocation()),
+ "Atomos content not expected."));
assertEquals(originalNum, bc.getBundles().length,
"Wrong number of final bundles.");
@@ -529,7 +519,7 @@ public class ModulepathLaunchTest
@Test
void testLoaderType(@TempDir Path storage) throws BundleException,
- InvalidSyntaxException, InterruptedException, ClassNotFoundException
+ ClassNotFoundException
{
ModulepathLaunch.main(new String[] {
Constants.FRAMEWORK_STORAGE + '=' + storage.toFile().getAbsolutePath() });
@@ -549,7 +539,7 @@ public class ModulepathLaunchTest
@Test
void testLoadFromModule(@TempDir Path storage)
- throws BundleException, InvalidSyntaxException, InterruptedException
+ throws BundleException
{
ModulepathLaunch.main(new String[] {
Constants.FRAMEWORK_STORAGE + '=' + storage.toFile().getAbsolutePath(),
@@ -596,7 +586,7 @@ public class ModulepathLaunchTest
@Test
void testModuleDirServices(@TempDir Path storage)
- throws BundleException, InvalidSyntaxException, InterruptedException
+ throws BundleException, InvalidSyntaxException
{
ModulepathLaunch.main(new String[] {
Constants.FRAMEWORK_STORAGE + '=' + storage.toFile().getAbsolutePath(),
@@ -685,7 +675,7 @@ public class ModulepathLaunchTest
assertEquals(3, bootLayer.getChildren().size(), "Wrong number of children.");
final List<AtomosLayer> children = bootLayer.getChildren().stream().sorted(
- (l1, l2) -> Long.compare(l1.getId(), l2.getId())).collect(
+ Comparator.comparingLong(AtomosLayer::getId)).collect(
Collectors.toList());
checkLayer(children.get(0), LoaderType.SINGLE, 2);
checkLayer(children.get(1), LoaderType.MANY, 3);
@@ -693,7 +683,7 @@ public class ModulepathLaunchTest
// uninstall service.impl.a bundle from the first child
children.iterator().next().getAtomosContents().stream().map(
- (a) -> a.getBundle()).filter(
+ AtomosContent::getBundle).filter(
Objects::nonNull).filter(
(b) -> b.getSymbolicName().equals(
TESTBUNDLES_SERVICE_IMPL_A)).findFirst().orElseThrow().uninstall();
@@ -742,7 +732,7 @@ public class ModulepathLaunchTest
@Test
void testResourceGetMissingResource(@TempDir Path storage)
- throws ClassNotFoundException, BundleException
+ throws BundleException
{
try
{
@@ -759,15 +749,15 @@ public class ModulepathLaunchTest
@Test
void testResourceLoadResource(@TempDir Path storage)
- throws ClassNotFoundException, BundleException
+ throws BundleException
{
try
{
final Class<?> clazz = getCLForResourceTests(storage).loadClass(
RESSOURCE_A_CLAZZ_NAME);
final URL resc = clazz.getResource("/META-TEXT/file.txt");
- assertTrue(resc != null, "Expected URL, got null ");
- assertTrue(resc.getFile() != null, "Could not get resource from URL");
+ assertNotNull(resc, "Expected URL, got null ");
+ assertNotNull(resc.getFile(), "Could not get resource from URL");
}
catch (final ClassNotFoundException e)
{
@@ -777,7 +767,7 @@ public class ModulepathLaunchTest
@Test
void testResourcePackagedResource(@TempDir Path storage)
- throws ClassNotFoundException, BundleException, IOException
+ throws BundleException, IOException
{
try
{
@@ -797,16 +787,16 @@ public class ModulepathLaunchTest
@Test
void testResourceRootResource(@TempDir Path storage)
- throws ClassNotFoundException, BundleException, IOException
+ throws BundleException, IOException
{
try
{
final Class<?> clazz = getCLForResourceTests(storage).loadClass(
RESSOURCE_A_CLAZZ_NAME);
final URL resc = clazz.getResource("/file.txt");
- assertTrue(resc != null, "Expected URL, got null ");
- assertTrue(new BufferedReader(
- new InputStreamReader(resc.openStream())).readLine().equals("/file.txt"),
+ assertNotNull(resc, "Expected URL, got null ");
+ assertEquals("/file.txt", new BufferedReader(
+ new InputStreamReader(resc.openStream())).readLine(),
"Incorrect contents from URL");
}
catch (final ClassNotFoundException e)
@@ -819,7 +809,7 @@ public class ModulepathLaunchTest
private static String BSN_SERVICE_IMPL = "org.apache.felix.atomos.tests.testbundles.service.impl";
@Test
void testConnectLocation(@TempDir Path storage)
- throws BundleException, InvalidSyntaxException, InterruptedException
+ throws BundleException, InterruptedException
{
String[] args = new String[] {
Constants.FRAMEWORK_STORAGE + '=' + storage.toFile().getAbsolutePath(),