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

Disable the IPC sync context factory by default (can be enabled using… #469

Merged
merged 1 commit into from
Sep 6, 2021
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 @@ -247,7 +247,11 @@ public enum Environment {
/**
* Regexp pattern that will force eviction of the plugin realms if one of its dependencies matches.
*/
MVND_PLUGIN_REALM_EVICT_PATTERN("mvnd.pluginRealmEvictPattern", null, "", OptionType.STRING, Flags.OPTIONAL);
MVND_PLUGIN_REALM_EVICT_PATTERN("mvnd.pluginRealmEvictPattern", null, "", OptionType.STRING, Flags.OPTIONAL),
/**
* The SyncContextFactory to use (can be either 'noop' or 'ipc' for a server-wide factory).
*/
MVND_SYNC_CONTEXT_FACTORY("mvnd.syncContextFactory", null, "noop", OptionType.BOOLEAN, Flags.OPTIONAL);

static Properties properties;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mvndaemon.mvnd.sync;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Named;
import javax.inject.Singleton;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.SyncContext;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.impl.SyncContextFactory;
import org.eclipse.aether.metadata.Metadata;
import org.eclipse.sisu.Priority;
import org.mvndaemon.mvnd.common.Environment;

@Singleton
@Named
@Priority(20)
public class MvndSyncContextFactory implements SyncContextFactory {

public static final String FACTORY_NOOP = "noop";
public static final String FACTORY_IPC = "ipc";

public static final String IPC_SYNC_CONTEXT_FACTORY = "org.mvndaemon.mvnd.sync.IpcSyncContextFactory";

private final Map<String, SyncContextFactory> factories;

@SuppressWarnings("unchecked")
public MvndSyncContextFactory() {
try {
Map<String, SyncContextFactory> map = new HashMap<>();
map.put(FACTORY_NOOP, new NoopSyncContextFactory());
Class<? extends SyncContextFactory> factoryClass = (Class<? extends SyncContextFactory>) getClass().getClassLoader()
.loadClass(IPC_SYNC_CONTEXT_FACTORY);
map.put(FACTORY_IPC, factoryClass.getDeclaredConstructor().newInstance());
factories = Collections.unmodifiableMap(map);
} catch (Exception e) {
throw new RuntimeException("Unable to create IpcSyncContextFactory instance", e);
}
}

@Override
public SyncContext newInstance(RepositorySystemSession repositorySystemSession, boolean shared) {
String name = Environment.MVND_SYNC_CONTEXT_FACTORY.asOptional()
.orElseGet(Environment.MVND_SYNC_CONTEXT_FACTORY::getDefault);
SyncContextFactory factory = factories.get(name);
if (factory == null) {
throw new RuntimeException("Unable to find SyncContextFactory named '" + name + "'");
}
return factory.newInstance(repositorySystemSession, shared);
}

private static class NoopSyncContextFactory implements SyncContextFactory {
@Override
public SyncContext newInstance(RepositorySystemSession repositorySystemSession, boolean shared) {
return new SyncContext() {
@Override
public void acquire(Collection<? extends Artifact> artifacts, Collection<? extends Metadata> metadatas) {
}

@Override
public void close() {
}
};
}
}
}