Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UnsupportedOperationException from OperationBuilders #27

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public AbstractOperationBuilderImpl(Feature feature) {
this.feature = feature;
this.isCompleted = false;
this.useDefaultRepositories = true;
this.artifactRepositories = getDefaultRepositories();
this.artifactRepositories = new HashMap<>();
this.variables = new HashMap<>();
this.decorators = new ArrayList<>();
this.extensionHandlers = new HashMap<>();
Expand All @@ -259,8 +259,6 @@ public T addRepository(String name, ArtifactRepository repository) {

ensureNotCompletedYet();

maybeResetDefaultRepositories();

this.artifactRepositories.put(name, repository);

return castThis();
Expand All @@ -276,8 +274,6 @@ public T useDefaultRepositories(boolean include) {

this.useDefaultRepositories = include;

maybeResetDefaultRepositories();

return castThis();
}

Expand Down Expand Up @@ -365,6 +361,11 @@ public T withExtensionHandler(String extensionName, FeatureExtensionHandler exte
public InstalledFeature complete() throws FeatureRuntimeException {
this.isCompleted = true;

if(this.useDefaultRepositories) {
getDefaultRepositories().forEach(
(k,v) -> this.artifactRepositories.putIfAbsent(k, v));
}

return addOrUpdateFeature(feature);
}

Expand Down Expand Up @@ -587,12 +588,6 @@ protected void validateFeatureExtensions(Feature feature) {
}
}

private void maybeResetDefaultRepositories() {
if (!this.useDefaultRepositories) {
this.artifactRepositories = new HashMap<>();
}
}

protected void ensureNotCompletedYet() {
if (this.isCompleted == true) {
throw new IllegalStateException("Operation already completed!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
Expand Down Expand Up @@ -176,8 +178,9 @@ public void testInstallFeatureWithNoConfigWithDefaultRepositories(
}
}

@Test
public void testInstallFeatureWithNoConfigWithCustomRepositories(
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testInstallFeatureWithNoConfigWithCustomRepositories(boolean useDefault,
@InjectService(cardinality = 1, timeout = 5000) ServiceAware<FeatureRuntime> featureRuntimeServiceAware)
throws URISyntaxException, IOException {
assertEquals(1, featureRuntimeServiceAware.getServices().size());
Expand All @@ -201,7 +204,7 @@ public void testInstallFeatureWithNoConfigWithCustomRepositories(
// Install Feature using default repositories
// @formatter:off
InstalledFeature installedFeature = featureRuntimeService.install(featureReader)
.useDefaultRepositories(false)
.useDefaultRepositories(useDefault)
.addRepository("local", localArtifactRepository)
.addRepository("central", remoteRepository)
.install();
Expand Down
Loading