Skip to content

Commit

Permalink
Implementation of "160. Feature Launcher Service Specification" (c.d.)
Browse files Browse the repository at this point in the history
 - Applied changes requested in PR review:
   * Fix copyright headers and year - previously used those from code
templates defined in Eclipse via Gecko IDE
   * Link 160 specification sections in integration tests like in
implementation classes
   * Use dedicated M2 repository instead of system-wide local M2
repository
   * Assert based on "Bundle-SymbolicName" in
'#testGetArtifactFromLocalArtifactRepository' test case
   * Allow multiple artifact repositories be added to
'FeatureLauncher.LaunchBuilder'

Signed-off-by: Michael H. Siemaszko <mhs@into.software>
  • Loading branch information
ideas-into-software committed Sep 21, 2024
1 parent fd508c7 commit b4bc4d2
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 97 deletions.
84 changes: 66 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
<m2RepoPath>${project.build.directory}/m2Repo</m2RepoPath>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -78,17 +79,17 @@
<artifactId>org.apache.felix.feature</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.9</version>
</dependency>

<!-- Testing -->
<dependency>
<groupId>junit</groupId>
Expand All @@ -108,21 +109,21 @@
<version>1.2.19</version>
<classifier>jakarta</classifier>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<!-- default OSGi framework -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>7.0.5</version>
<scope>test</scope>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>7.0.5</version>
<scope>test</scope>
</dependency>

<!-- ensure "gogo console feature" bundles are present in local repo -->
<dependency>
<groupId>org.apache.felix</groupId>
Expand Down Expand Up @@ -222,6 +223,53 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>generate-test-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${m2RepoPath}</outputDirectory>
<useRepositoryLayout>true</useRepositoryLayout>
<copyPom>true</copyPom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>set-system-properties</goal>
</goals>
<configuration>
<properties>
<property>
<name>M2_REPO_PATH</name>
<value>${m2RepoPath}</value>
</property>
</properties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- needed to make system properties set via 'properties-maven-plugin' available in Java code -->
<forkCount>0</forkCount>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012 - 2024 Data In Motion and others.
* Copyright (c) 2024 Kentyou and others.
* All rights reserved.
*
* This program and the accompanying materials are made
Expand All @@ -9,7 +9,7 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
* Kentyou - initial implementation
*/
package com.kentyou.featurelauncher.impl;

Expand Down Expand Up @@ -95,7 +95,7 @@ class LaunchBuilderImpl implements LaunchBuilder {
private final Feature feature;
private boolean isLaunched;
private List<Bundle> installedBundles;
private ArtifactRepository artifactRepository;
private List<ArtifactRepository> artifactRepositories;
private Map<String, Object> configuration;
private Map<String, Object> variables;
private Map<String, Object> frameworkProps;
Expand All @@ -108,6 +108,7 @@ class LaunchBuilderImpl implements LaunchBuilder {
this.feature = feature;
this.isLaunched = false;
this.installedBundles = new ArrayList<>();
this.artifactRepositories = new ArrayList<>();
this.configuration = new HashMap<>();
this.variables = new HashMap<>();
this.frameworkProps = new HashMap<>();
Expand All @@ -125,7 +126,7 @@ public LaunchBuilder withRepository(ArtifactRepository repository) {

ensureNotLaunchedYet();

this.artifactRepository = repository;
this.artifactRepositories.add(repository);

return this;
}
Expand Down Expand Up @@ -213,7 +214,11 @@ public LaunchBuilder withExtensionHandler(String extensionName, FeatureExtension
@Override
public Framework launchFramework() {
Objects.requireNonNull(feature, "Feature is required!");
Objects.requireNonNull(artifactRepository, "Artifact Repository is required!");

if (this.artifactRepositories.isEmpty()) {
LOG.error("At least one Artifact Repository is required!");
throw new NullPointerException("At least one Artifact Repository is required!");
}

ensureNotLaunchedYet();

Expand All @@ -229,11 +234,8 @@ public Framework launchFramework() {

///////////////////////////////////////////
// 160.4.3.3: Creating a Framework instance

Framework framework = createFramework(frameworkFactory, Collections.emptyMap());

addLogListeners(framework);

/////////////////////////////////////////////////////////
// 160.4.3.4: Installing bundles and configurations
installBundles(framework);
Expand All @@ -253,6 +255,9 @@ private Framework createFramework(FrameworkFactory frameworkFactory, Map<String,
Framework framework = frameworkFactory.newFramework(frameworkProperties);
try {
framework.init();

addLogListeners(framework);

} catch (BundleException e) {
LOG.error("Could not initialize framework!", e);
throw new LaunchException("Could not initialize framework!", e);
Expand Down Expand Up @@ -313,20 +318,32 @@ private void installBundles(Framework framework) {
private void installBundle(Framework framework, FeatureBundle featureBundle) {
ID featureBundleID = featureBundle.getID();

try (InputStream featureBundleIs = artifactRepository.getArtifact(featureBundleID)) {
Bundle installedBundle = framework.getBundleContext().installBundle(featureBundleID.toString(),
featureBundleIs);
installedBundles.add(installedBundle);

LOG.info(String.format("Installed bundle '%s'", installedBundle.getSymbolicName()));
try (InputStream featureBundleIs = getArtifact(featureBundleID)) {
if (featureBundleIs.available() != 0) {
Bundle installedBundle = framework.getBundleContext().installBundle(featureBundleID.toString(),
featureBundleIs);
installedBundles.add(installedBundle);

LOG.info(String.format("Installed bundle '%s'", installedBundle.getSymbolicName()));
}
} catch (IOException | BundleException e) {
LOG.error(String.format("Could not install bundle '%s'!", featureBundleID.toString()), e);
throw new LaunchException(String.format("Could not install bundle '%s'!", featureBundleID.toString()),
e);
}
}

private InputStream getArtifact(ID featureBundleID) {
for (ArtifactRepository artifactRepository : artifactRepositories) {
InputStream featureBundleIs = artifactRepository.getArtifact(featureBundleID);
if (featureBundleIs != null) {
return featureBundleIs;
}
}

return InputStream.nullInputStream();
}

private void logFrameworkEvent(FrameworkEvent frameworkEvent) {
if (frameworkEvent.getType() == FrameworkEvent.ERROR) {
LOG.error(String.format("Framework ERROR event %s", frameworkEvent.toString()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012 - 2024 Data In Motion and others.
* Copyright (c) 2024 Kentyou and others.
* All rights reserved.
*
* This program and the accompanying materials are made
Expand All @@ -9,7 +9,7 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
* Kentyou - initial implementation
*/
package com.kentyou.featurelauncher.impl.decorator;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012 - 2024 Data In Motion and others.
* Copyright (c) 2024 Kentyou and others.
* All rights reserved.
*
* This program and the accompanying materials are made
Expand All @@ -9,7 +9,7 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
* Kentyou - initial implementation
*/
package com.kentyou.featurelauncher.impl.decorator;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012 - 2024 Data In Motion and others.
* Copyright (c) 2024 Kentyou and others.
* All rights reserved.
*
* This program and the accompanying materials are made
Expand All @@ -9,7 +9,7 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
* Kentyou - initial implementation
*/
package com.kentyou.featurelauncher.impl.decorator;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012 - 2024 Data In Motion and others.
* Copyright (c) 2024 Kentyou and others.
* All rights reserved.
*
* This program and the accompanying materials are made
Expand All @@ -9,7 +9,7 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
* Kentyou - initial implementation
*/
package com.kentyou.featurelauncher.impl.repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012 - 2024 Data In Motion and others.
* Copyright (c) 2024 Kentyou and others.
* All rights reserved.
*
* This program and the accompanying materials are made
Expand All @@ -9,10 +9,11 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
* Kentyou - initial implementation
*/
package com.kentyou.featurelauncher.impl.repository;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
Expand Down Expand Up @@ -74,12 +75,18 @@ public InputStream getArtifact(ID id) {

Path path = getArtifactM2RepoPath(id);

try {
return new FileInputStream(path.toFile());
} catch (FileNotFoundException e) {
LOG.error(String.format("Error getting artifact ID '%s'", id.toString()), e);
File file = path.toFile();

throw new RuntimeException(e); // TODO: clarify with Tim
if (file.exists()) {
try {
return new FileInputStream(file);
} catch (FileNotFoundException e) {
LOG.error(String.format("Error getting artifact ID '%s'", id.toString()), e);
throw new RuntimeException(e); // TODO: clarify with Tim regarding exception thrown
}
} else {
LOG.warn(String.format("Artifact ID '%s' does not exist in this repository!", id.toString()));
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012 - 2024 Data In Motion and others.
* Copyright (c) 2024 Kentyou and others.
* All rights reserved.
*
* This program and the accompanying materials are made
Expand All @@ -9,7 +9,7 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
* Kentyou - initial implementation
*/
package com.kentyou.featurelauncher.impl.repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012 - 2024 Data In Motion and others.
* Copyright (c) 2024 Kentyou and others.
* All rights reserved.
*
* This program and the accompanying materials are made
Expand All @@ -9,7 +9,7 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
* Kentyou - initial implementation
*/
package com.kentyou.featurelauncher.impl.runtime;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012 - 2024 Data In Motion and others.
* Copyright (c) 2024 Kentyou and others.
* All rights reserved.
*
* This program and the accompanying materials are made
Expand All @@ -9,7 +9,7 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
* Kentyou - initial implementation
*/
package com.kentyou.featurelauncher.impl.runtime;

Expand Down
Loading

0 comments on commit b4bc4d2

Please sign in to comment.