From 0e36b8630049184b285a13faaa1cf400665a62a1 Mon Sep 17 00:00:00 2001 From: PFHJYG0 Date: Mon, 7 Aug 2017 08:12:24 -0400 Subject: [PATCH] Added validation back in on download request. --- .../jenkins/scm/IspwConfiguration.java | 241 ++++++++---------- 1 file changed, 107 insertions(+), 134 deletions(-) diff --git a/src/main/java/com/compuware/jenkins/scm/IspwConfiguration.java b/src/main/java/com/compuware/jenkins/scm/IspwConfiguration.java index 32bc5ed..363e463 100644 --- a/src/main/java/com/compuware/jenkins/scm/IspwConfiguration.java +++ b/src/main/java/com/compuware/jenkins/scm/IspwConfiguration.java @@ -109,8 +109,7 @@ public void checkout(Run build, Launcher launcher, FilePath workspaceFileP try { - // TODO (pfhjyg0) : Leave commented out for now; see comment in IspwConfiguration.java#validateParameters() - // validateParameters(launcher, listener, build.getParent()); + validateParameters(launcher, listener, build.getParent()); IspwDownloader downloader = new IspwDownloader(this); rtnValue = downloader.getSource(build, launcher, workspaceFilePath, listener, changelogFile); @@ -245,30 +244,6 @@ public String getFilterName() return m_filterName; } - /** - * Retrieves host connection information given a host connection id. - * - * @return a Jenkins host connection - */ - protected HostConnection getHostConnection() - { - HostConnection connection = null; - - CpwrGlobalConfiguration globalConfig = CpwrGlobalConfiguration.get(); - HostConnection[] hostConnections = globalConfig.getHostConnections(); - - String connectionId = getConnectionId(); - for (HostConnection c : hostConnections) - { - if (connectionId.matches(c.getConnectionId())) - { - connection = c; - } - } - - return connection; - } - /** * Retrieves login information given a credential ID * @@ -296,114 +271,112 @@ protected StandardUsernamePasswordCredentials getLoginInformation(Item project) return credential; } - // TODO (pfhjyg0: validation duplication??? Leave commented for now until we decide if validation performed in CLI is - // adequate. - // /** - // * Validates the configuration parameters. - // * - // * @param launcher - // * The machine that the files will be checked out. - // * @param listener - // * Build listener - // * @param project the Jenkins project - // */ - // public void validateParameters(Launcher launcher, TaskListener listener, Item project) - // { - // - // if (getLoginInformation(project) != null) - // { - // listener.getLogger().println(Messages.username() + " = " + getLoginInformation(project).getUsername()); //$NON-NLS-1$ - // } - // else - // { - // throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.loginCredentials())); - // } - // - // HostConnection connection = getHostConnection(); - // if (connection != null) - // { - // listener.getLogger().println(Messages.hostPort() + " = " + connection.getHost() + ":" + connection.getPort()); - // //$NON-NLS-1$ //$NON-NLS-2$ - // } - // else - // { - // throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.hostPort())); - // } - // - // if (getServerConfig() != null) - // { - // listener.getLogger().println(Messages.ispwServerConfig() + " = " + getServerConfig()); //$NON-NLS-1$ - // } - // else - // { - // throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwServerConfig())); - // } - // - // if (!getServerStream().isEmpty()) - // { - // listener.getLogger().println(Messages.ispwServerStream() + " = " + getServerStream()); //$NON-NLS-1$ - // } - // else - // { - // throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwServerStream())); - // } - // - // if (!getServerApplication().isEmpty()) - // { - // listener.getLogger().println(Messages.ispwServerApp() + " = " + getServerApplication()); //$NON-NLS-1$ - // } - // else - // { - // throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwServerApp())); - // } - // - // if (!getServerLevel().isEmpty()) - // { - // listener.getLogger().println(Messages.ispwServerLevel() + " = " + getServerLevel()); //$NON-NLS-1$ - // } - // else - // { - // throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwServerLevel())); - // } - // - // if (!getLevelOption().isEmpty()) - // { - // listener.getLogger().println(Messages.ispwLevelOption() + " = " + getLevelOption()); //$NON-NLS-1$ - // } - // else - // { - // throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwLevelOption())); - // } - // - // if (getFilterName() != null) - // { - // listener.getLogger().println(Messages.ispwfilterName() + " = " + getFilterName()); //$NON-NLS-1$ - // } - // else - // { - // throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwfilterName())); - // } - // - // if (getFilterType() != null) - // { - // listener.getLogger().println(Messages.ispwfilterType() + " = " + getFilterType()); //$NON-NLS-1$ - // } - // else - // { - // throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwfilterType())); - // } - // - // CpwrGlobalConfiguration globalConfig = CpwrGlobalConfiguration.get(); - // String cliLocation = globalConfig.getTopazCLILocation(launcher); - // if ((cliLocation != null) && !cliLocation.isEmpty()) - // { - // listener.getLogger().println(Messages.topazCLILocation() + " = " + cliLocation); //$NON-NLS-1$ - // } - // else - // { - // throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.topazCLILocation())); - // } - // } + /** + * Validates the configuration parameters. + * + * @param launcher + * The machine that the files will be checked out. + * @param listener + * Build listener + * @param project + * the Jenkins project + */ + public void validateParameters(Launcher launcher, TaskListener listener, Item project) + { + CpwrGlobalConfiguration globalConfig = CpwrGlobalConfiguration.get(); + + if (getLoginInformation(project) != null) + { + listener.getLogger().println(Messages.username() + " = " + getLoginInformation(project).getUsername()); //$NON-NLS-1$ + } + else + { + throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.loginCredentials())); + } + + HostConnection connection = globalConfig.getHostConnection(m_connectionId); + if (connection != null) + { + listener.getLogger().println(Messages.hostPort() + " = " + connection.getHost() + ":" + connection.getPort()); //$NON-NLS-1$ //$NON-NLS-2$ + } + else + { + throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.hostPort())); + } + + if (getServerConfig() != null) + { + listener.getLogger().println(Messages.ispwServerConfig() + " = " + getServerConfig()); //$NON-NLS-1$ + } + else + { + throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwServerConfig())); + } + + if (!getServerStream().isEmpty()) + { + listener.getLogger().println(Messages.ispwServerStream() + " = " + getServerStream()); //$NON-NLS-1$ + } + else + { + throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwServerStream())); + } + + if (!getServerApplication().isEmpty()) + { + listener.getLogger().println(Messages.ispwServerApp() + " = " + getServerApplication()); //$NON-NLS-1$ + } + else + { + throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwServerApp())); + } + + if (!getServerLevel().isEmpty()) + { + listener.getLogger().println(Messages.ispwServerLevel() + " = " + getServerLevel()); //$NON-NLS-1$ + } + else + { + throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwServerLevel())); + } + + if (!getLevelOption().isEmpty()) + { + listener.getLogger().println(Messages.ispwLevelOption() + " = " + getLevelOption()); //$NON-NLS-1$ + } + else + { + throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwLevelOption())); + } + + if (getFilterName() != null) + { + listener.getLogger().println(Messages.ispwfilterName() + " = " + getFilterName()); //$NON-NLS-1$ + } + else + { + throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwfilterName())); + } + + if (getFilterType() != null) + { + listener.getLogger().println(Messages.ispwfilterType() + " = " + getFilterType()); //$NON-NLS-1$ + } + else + { + throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.ispwfilterType())); + } + + String cliLocation = globalConfig.getTopazCLILocation(launcher); + if ((cliLocation != null) && !cliLocation.isEmpty()) + { + listener.getLogger().println(Messages.topazCLILocation() + " = " + cliLocation); //$NON-NLS-1$ + } + else + { + throw new IllegalArgumentException(Messages.checkoutMissingParameterError(Messages.topazCLILocation())); + } + } /** * Plugin does not support polling. We handle file changes in the CLI.