au.net.causal.maven.plugins.boxdb.db.BoxContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boxdb-maven-plugin Show documentation
Show all versions of boxdb-maven-plugin Show documentation
Maven plugin to start databases using Docker and VMs
package au.net.causal.maven.plugins.boxdb.db;
import au.net.causal.maven.plugins.boxdb.ExceptionalSupplier;
import au.net.causal.maven.plugins.boxdb.JavaRunner;
import au.net.causal.maven.plugins.boxdb.ScriptReaderRunner;
import au.net.causal.maven.plugins.boxdb.ScriptRunner;
import io.fabric8.maven.docker.log.LogOutputSpecFactory;
import io.fabric8.maven.docker.service.ServiceHub;
import io.fabric8.maven.docker.util.AuthConfigFactory;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.shared.filtering.MavenReaderFilter;
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.DependencyResolutionException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class BoxContext
{
private final ExceptionalSupplier dockerService;
private final AuthConfigFactory authConfigFactory;
private final Path tempDirectory;
private final Path globalConfigDirectory;
private final ImageUpdateMode imageUpdateMode;
private final Log log;
private final LogOutputSpecFactory logSpecFactory;
private final MavenSession session;
private final MavenResourcesFiltering resourcesFiltering;
private final MavenReaderFilter readerFilter;
private final RepositorySystem repositorySystem;
private final RepositorySystemSession repositorySystemSession;
private final List remoteRepositories;
private final ArchiverManager archiverManager;
//Toolchain, etc. goes here
public BoxContext(ExceptionalSupplier dockerService, AuthConfigFactory authConfigFactory,
Path tempDirectory, Path globalConfigDirectory, ImageUpdateMode imageUpdateMode, Log log,
LogOutputSpecFactory logSpecFactory,
MavenSession session, MavenResourcesFiltering resourcesFiltering,
MavenReaderFilter readerFilter, RepositorySystem repositorySystem,
RepositorySystemSession repositorySystemSession, List remoteRepositories,
ArchiverManager archiverManager)
{
Objects.requireNonNull(dockerService, "dockerService == null");
Objects.requireNonNull(authConfigFactory, "authConfigFactory == null");
Objects.requireNonNull(tempDirectory, "tempDirectory == null");
Objects.requireNonNull(globalConfigDirectory, "globalConfigDirectory == null");
Objects.requireNonNull(imageUpdateMode, "updateMode == null");
Objects.requireNonNull(log, "log == null");
Objects.requireNonNull(logSpecFactory, "logSpecFactory == null");
Objects.requireNonNull(session, "session == null");
Objects.requireNonNull(resourcesFiltering, "resourcesFiltering == null");
Objects.requireNonNull(readerFilter, "readerFilter == null");
Objects.requireNonNull(repositorySystem, "repositorySystem == null");
Objects.requireNonNull(repositorySystemSession, "repositorySystemSession == null");
Objects.requireNonNull(remoteRepositories, "remoteRepositories == null");
Objects.requireNonNull(archiverManager, "archiverManager == null");
this.dockerService = dockerService;
this.authConfigFactory = authConfigFactory;
this.tempDirectory = tempDirectory;
this.globalConfigDirectory = globalConfigDirectory;
this.imageUpdateMode = imageUpdateMode;
this.log = log;
this.logSpecFactory = logSpecFactory;
this.session = session;
this.resourcesFiltering = resourcesFiltering;
this.readerFilter = readerFilter;
this.repositorySystem = repositorySystem;
this.repositorySystemSession = repositorySystemSession;
this.remoteRepositories = remoteRepositories;
this.archiverManager = archiverManager;
}
public ServiceHub getDockerServiceHub()
throws BoxDatabaseException
{
return dockerService.get().getServiceHub();
}
public String getDockerHostAddress()
throws BoxDatabaseException
{
return dockerService.get().getDockerHostAddress();
}
public AuthConfigFactory getAuthConfigFactory()
{
return authConfigFactory;
}
public Path getGlobalConfigDirectory()
throws IOException
{
if (!Files.exists(globalConfigDirectory))
Files.createDirectories(globalConfigDirectory);
return globalConfigDirectory;
}
public Path getTempDirectory()
throws IOException
{
if (!Files.exists(tempDirectory))
Files.createDirectories(tempDirectory);
return tempDirectory;
}
public Log getLog()
{
return log;
}
public LogOutputSpecFactory getLogSpecFactory()
{
return logSpecFactory;
}
public ImageUpdateMode getImageUpdateMode()
{
return imageUpdateMode;
}
public MavenSession getSession()
{
return session;
}
public RepositorySystem getRepositorySystem()
{
return repositorySystem;
}
public RepositorySystemSession getRepositorySystemSession()
{
return repositorySystemSession;
}
public List getRemoteRepositories()
{
return remoteRepositories;
}
public ScriptRunner createScriptRunner(BoxDatabase boxDatabase, BoxConfiguration boxConfiguration, ProjectConfiguration projectConfiguration)
{
return new ScriptRunner(boxDatabase, boxConfiguration, projectConfiguration, this, resourcesFiltering);
}
public ScriptReaderRunner createScriptReaderRunner(BoxDatabase boxDatabase, BoxConfiguration boxConfiguration, ProjectConfiguration projectConfiguration)
{
return new ScriptReaderRunner(boxDatabase, boxConfiguration, projectConfiguration, this, readerFilter);
}
public JavaRunner createJavaRunner(String mainClassName, List extends RunnerDependency> dependencies)
throws DependencyResolutionException
{
return JavaRunner.createFromDependencies(mainClassName, dependencies, repositorySystem, repositorySystemSession, remoteRepositories);
}
public JavaRunner createJavaRunner(String mainClassName, RunnerDependency dependency, RunnerDependency... otherDependencies)
throws DependencyResolutionException
{
List dependencies = new ArrayList<>(otherDependencies.length + 1);
dependencies.add(dependency);
dependencies.addAll(Arrays.asList(otherDependencies));
return createJavaRunner(mainClassName, dependencies);
}
public ArchiverManager getArchiverManager()
{
return archiverManager;
}
}