Skip to content

Commit

Permalink
Fix #92: NullPointerException in AuthConfigFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanKanojia committed Mar 5, 2020
1 parent a7b0036 commit d97c14d
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,12 @@ public class AuthConfigFactory {

static final String DOCKER_LOGIN_DEFAULT_REGISTRY = "https://index.docker.io/v1/";

private KitLogger log;
private final KitLogger log;
private static final String[] DEFAULT_REGISTRIES = new String[]{
"docker.io", "index.docker.io", "registry.hub.docker.com"
};

/**
* Constructor which should be used during startup phase of a plugin
*
*/
public AuthConfigFactory() {
}

public void setLog(KitLogger log) {
public AuthConfigFactory(KitLogger log) {
this.log = log;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,22 +428,19 @@ public abstract class AbstractDockerMojo extends AbstractMojo implements ConfigH
@Override
public void contextualize(Context context) throws ContextException {
plexusContainer = ((PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY));
authConfigFactory = new AuthConfigFactory();
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (!skip) {
boolean ansiRestore = Ansi.isEnabled();
log = new AnsiLogger(getLog(), useColorForLogging(), verbose, !settings.getInteractiveMode(), getLogPrefix());
authConfigFactory = new AuthConfigFactory(log);
imageConfigResolver.setLog(log);

try {
authConfigFactory.setLog(log);
imageConfigResolver.setLog(log);

LogOutputSpecFactory logSpecFactory = new LogOutputSpecFactory(useColor, logStdout, logDate);


DockerAccess access = null;
try {
JKubeProject jkubeProject = MavenUtil.convertMavenProjectToJKubeProject(project, session);
Expand Down Expand Up @@ -575,7 +572,7 @@ protected void processDmpPluginDescription(URL pluginDesc, File outputDir) throw
}
}

protected RegistryService.RegistryConfig getRegistryConfig(String specificRegistry) throws MojoExecutionException {
protected RegistryService.RegistryConfig getRegistryConfig(String specificRegistry) {
return new RegistryService.RegistryConfig.Builder()
.settings(MavenUtil.getRegistryServerFromMavenSettings(settings))
.authConfig(authConfig != null ? authConfig.toMap() : null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.jkube.kit.build.service.docker.ServiceHub;
import org.eclipse.jkube.kit.build.service.docker.access.DockerAccess;
import org.eclipse.jkube.kit.build.service.docker.access.log.LogOutputSpecFactory;
import org.eclipse.jkube.kit.build.service.docker.auth.AuthConfigFactory;
import org.eclipse.jkube.kit.build.service.docker.config.ConfigHelper;
import org.eclipse.jkube.kit.common.util.AnsiLogger;
import org.eclipse.jkube.kit.common.util.MavenUtil;
Expand Down Expand Up @@ -86,7 +87,7 @@ public void executeInternal(ServiceHub hub) throws MojoExecutionException {
public void executeDockerBuild() throws MojoExecutionException, MojoFailureException {
if (!skip) {
log = new AnsiLogger(getLog(), useColor, verbose, !settings.getInteractiveMode(), getLogPrefix());
authConfigFactory.setLog(log);
authConfigFactory = new AuthConfigFactory(log);
imageConfigResolver.setLog(log);

LogOutputSpecFactory logSpecFactory = new LogOutputSpecFactory(useColor, logStdout, logDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
super.execute();
}

@Override
public void contextualize(Context context) throws ContextException {
authConfigFactory = new AuthConfigFactory();
}

@Override
public void executeInternal(ServiceHub serviceHub) throws MojoExecutionException {
if (skipPush) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ public class WatchMojo extends AbstractDockerMojo {
private KubernetesClient kubernetes;
private ServiceHub hub;

@Override
public void contextualize(Context context) throws ContextException {
authConfigFactory = new AuthConfigFactory();
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.eclipse.jkube.generator.api.GeneratorContext;
import org.eclipse.jkube.kit.build.api.auth.AuthConfig;
import org.eclipse.jkube.kit.build.core.GavLabel;
import org.eclipse.jkube.kit.build.core.JKubeBuildContext;
import org.eclipse.jkube.kit.build.core.config.JKubeBuildConfiguration;
Expand Down Expand Up @@ -428,22 +429,19 @@ public abstract class AbstractDockerMojo extends AbstractMojo implements ConfigH
@Override
public void contextualize(Context context) throws ContextException {
plexusContainer = ((PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY));
authConfigFactory = new AuthConfigFactory();
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (!skip) {
boolean ansiRestore = Ansi.isEnabled();
log = new AnsiLogger(getLog(), useColorForLogging(), verbose, !settings.getInteractiveMode(), getLogPrefix());
authConfigFactory = new AuthConfigFactory(log);
imageConfigResolver.setLog(log);

try {
authConfigFactory.setLog(log);
imageConfigResolver.setLog(log);

LogOutputSpecFactory logSpecFactory = new LogOutputSpecFactory(useColor, logStdout, logDate);


DockerAccess access = null;
try {
ConfigHelper.validateExternalPropertyActivation(MavenUtil.convertMavenProjectToJKubeProject(project, session), images);
Expand Down Expand Up @@ -574,7 +572,7 @@ protected void processDmpPluginDescription(URL pluginDesc, File outputDir) throw
}
}

protected RegistryService.RegistryConfig getRegistryConfig(String specificRegistry) throws MojoExecutionException {
protected RegistryService.RegistryConfig getRegistryConfig(String specificRegistry) {
return new RegistryService.RegistryConfig.Builder()
.settings(MavenUtil.getRegistryServerFromMavenSettings(settings))
.authConfig(authConfig != null ? authConfig.toMap() : null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
@Mojo(name = "build", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.COMPILE)
public class BuildMojo extends AbstractDockerMojo implements Contextualizable {

// Handler dealing with authentication credentials
private AuthConfigFactory authConfigFactory;

@Override
protected boolean isDockerAccessRequired() {
boolean ret = false;
Expand All @@ -74,11 +71,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
executeDockerBuild();
}

@Override
public void contextualize(Context context) throws ContextException {
authConfigFactory = new AuthConfigFactory();
}

@Override
public void executeInternal(ServiceHub hub) throws MojoExecutionException {
if (skipBuild) {
Expand Down Expand Up @@ -114,7 +106,7 @@ public void executeInternal(ServiceHub hub) throws MojoExecutionException {
public void executeDockerBuild() throws MojoExecutionException, MojoFailureException {
if (!skip) {
log = new AnsiLogger(getLog(), useColor, verbose, !settings.getInteractiveMode(), getLogPrefix());
authConfigFactory.setLog(log);
authConfigFactory = new AuthConfigFactory(log);
imageConfigResolver.setLog(log);

LogOutputSpecFactory logSpecFactory = new LogOutputSpecFactory(useColor, logStdout, logDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ public class WatchMojo extends AbstractDockerMojo {
private KubernetesClient kubernetes;
private ServiceHub hub;

@Override
public void contextualize(Context context) throws ContextException {
authConfigFactory = new AuthConfigFactory();
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
Expand Down

0 comments on commit d97c14d

Please sign in to comment.