Skip to content

Commit

Permalink
Merge pull request #40 from vlambat/master
Browse files Browse the repository at this point in the history
Fix JENKINS-33475
  • Loading branch information
anuragsen committed Oct 24, 2016
2 parents ccec403 + 53a3be8 commit a946c0f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 102 deletions.
24 changes: 23 additions & 1 deletion src/main/java/hudson/scm/AbstractIntegritySCM.java
Expand Up @@ -14,6 +14,8 @@
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.export.Exported;

import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.scm.IntegrityCheckpointAction.IntegrityCheckpointDescriptorImpl;
import hudson.scm.IntegritySCM.DescriptorImpl;
import hudson.scm.browsers.IntegrityWebUI;
Expand Down Expand Up @@ -556,5 +558,25 @@ public DescriptorImpl getDescriptor()
{
return DescriptorImpl.INTEGRITY_DESCRIPTOR;
}


/**
* Gets the project specific user/password for this build
*/
public IntegrityConfigurable getProjectSettings()
{
IntegrityConfigurable desSettings = DescriptorImpl.INTEGRITY_DESCRIPTOR
.getConfiguration(serverConfig);
String strUserName = null == userName
? desSettings.getUserName()
: userName;
String strPassword = null == password ? desSettings
.getPasswordInPlainText() : password.getPlainText();
IntegrityConfigurable ciSettings = new IntegrityConfigurable("TEMP_ID",
desSettings.getIpHostName(), desSettings.getIpPort(),
desSettings.getHostName(), desSettings.getPort(),
desSettings.getSecure(), strUserName, strPassword);
LOGGER.fine("Project Userame = " + strUserName);
LOGGER.fine("Project User password = " + strPassword);
return ciSettings;
}
}
32 changes: 7 additions & 25 deletions src/main/java/hudson/scm/IntegrityCheckinAction.java
Expand Up @@ -183,34 +183,16 @@ public void setConfigurationName(String configurationName)
* @param thisBuild Jenkins AbstractBuild
* @return
*/
private IntegrityConfigurable getProjectSettings(AbstractBuild<?, ?> thisBuild)
{
IntegrityConfigurable desSettings =
DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig);
IntegrityConfigurable ciSettings =
new IntegrityConfigurable("TEMP_ID", desSettings.getIpHostName(), desSettings.getIpPort(),
desSettings.getHostName(), desSettings.getPort(), desSettings.getSecure(), "", "");
AbstractProject<?, ?> thisProject = thisBuild.getProject();
if (thisProject.getScm() instanceof IntegritySCM)
{
String userName = ((IntegritySCM) thisProject.getScm()).getUserName();
ciSettings.setUserName(userName);
LOGGER.fine("IntegrityCheckinAction - Project Userame = " + userName);

Secret password = ((IntegritySCM) thisProject.getScm()).getSecretPassword();
ciSettings.setPassword(password.getEncryptedValue());
LOGGER
.fine("IntegrityCheckinAction - Project User password = " + password.getEncryptedValue());
} else
private IntegrityConfigurable getProjectSettings(
AbstractBuild<?, ?> thisBuild)
{
LOGGER.severe(
"IntegrityCheckinAction - Failed to initialize project specific connection settings!");
return desSettings;
AbstractProject<?, ?> thisProject = thisBuild.getProject();
if (!(thisProject.getScm() instanceof IntegritySCM)) {
LOGGER.severe("IntegrityCheckinAction - Failed to initialize project specific connection settings!");
}
return ((IntegritySCM) thisProject.getScm()).getProjectSettings();
}

return ciSettings;
}

/**
* Executes the actual Integrity Checkpoint operation
*/
Expand Down
34 changes: 8 additions & 26 deletions src/main/java/hudson/scm/IntegrityCheckpointAction.java
Expand Up @@ -230,35 +230,17 @@ private void applyProjectLabel(IntegrityConfigurable serverConf, BuildListener l
*
* @param thisBuild Jenkins AbstractBuild
* @return
*/
private IntegrityConfigurable getProjectSettings(AbstractBuild<?, ?> thisBuild)
{
IntegrityConfigurable desSettings =
DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig);
IntegrityConfigurable ciSettings =
new IntegrityConfigurable("TEMP_ID", desSettings.getIpHostName(), desSettings.getIpPort(),
desSettings.getHostName(), desSettings.getPort(), desSettings.getSecure(), "", "");
AbstractProject<?, ?> thisProject = thisBuild.getProject();
if (thisProject.getScm() instanceof IntegritySCM)
{
String userName = ((IntegritySCM) thisProject.getScm()).getUserName();
ciSettings.setUserName(userName);
LOGGER.fine("IntegrityCheckpointAction - Project Userame = " + userName);

Secret password = ((IntegritySCM) thisProject.getScm()).getSecretPassword();
ciSettings.setPassword(password.getEncryptedValue());
LOGGER.fine(
"IntegrityCheckpointAction - Project User password = " + password.getEncryptedValue());
} else
*/
private IntegrityConfigurable getProjectSettings(
AbstractBuild<?, ?> thisBuild)
{
LOGGER.severe(
"IntegrityCheckpointAction - Failed to initialize project specific connection settings!");
return desSettings;
AbstractProject<?, ?> thisProject = thisBuild.getProject();
if (!(thisProject.getScm() instanceof IntegritySCM)) {
LOGGER.severe("IntegrityCheckpointAction - Failed to initialize project specific connection settings!");
}
return ((IntegritySCM) thisProject.getScm()).getProjectSettings();
}

return ciSettings;
}

/**
* Executes the actual Integrity Checkpoint operation
*/
Expand Down
32 changes: 7 additions & 25 deletions src/main/java/hudson/scm/IntegrityItemAction.java
Expand Up @@ -682,33 +682,15 @@ private boolean collectTestResults(AbstractBuild<?, ?> build, BuildListener list
*
* @param thisBuild Jenkins AbstractBuild
* @return
*/
*/
private IntegrityConfigurable getProjectSettings(AbstractBuild<?, ?> thisBuild)
{
IntegrityConfigurable desSettings =
DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig);
IntegrityConfigurable ciSettings =
new IntegrityConfigurable("TEMP_ID", desSettings.getIpHostName(), desSettings.getIpPort(),
desSettings.getHostName(), desSettings.getPort(), desSettings.getSecure(), "", "");
AbstractProject<?, ?> thisProject = thisBuild.getProject();
if (thisProject.getScm() instanceof IntegritySCM)
{
String userName = ((IntegritySCM) thisProject.getScm()).getUserName();
ciSettings.setUserName(userName);
LOGGER.fine("IntegrityItemAction - Project Userame = " + userName);

Secret password = ((IntegritySCM) thisProject.getScm()).getSecretPassword();
ciSettings.setPassword(password.getEncryptedValue());
LOGGER.fine("IntegrityItemAction - Project User password = " + password.getEncryptedValue());
} else
{
LOGGER.severe(
"IntegrityItemAction - Failed to initialize project specific connection settings!");
return desSettings;
}

return ciSettings;
}
AbstractProject<?, ?> thisProject = thisBuild.getProject();
if (!(thisProject.getScm() instanceof IntegritySCM)) {
LOGGER.severe("IntegrityItemAction - Failed to initialize project specific connection settings!");
}
return ((IntegritySCM) thisProject.getScm()).getProjectSettings();
}

/**
* Executes the actual Integrity Update Item operation
Expand Down
38 changes: 13 additions & 25 deletions src/main/java/hudson/scm/IntegritySCM.java
Expand Up @@ -267,8 +267,7 @@ private Response initializeCMProject(EnvVars environment, String projectCacheTab
IntegrityCheckpointAction.evalGroovyExpression(environment, configPath);

// Get the project information for this project
IAPICommand command = CommandFactory.createCommand(IAPICommand.PROJECT_INFO_COMMAND,
DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig));
IAPICommand command = CommandFactory.createCommand(IAPICommand.PROJECT_INFO_COMMAND, getProjectSettings());
command.addOption(new APIOption(IAPIOption.PROJECT, resolvedConfigPath));

Response infoRes = command.execute();
Expand Down Expand Up @@ -343,8 +342,7 @@ private Response initializeCMProjectMembers()
IntegrityCMProject siProject = getIntegrityProject();

// Lets parse this project
IAPICommand command = CommandFactory.createCommand(IAPICommand.VIEW_PROJECT_COMMAND,
DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig));
IAPICommand command = CommandFactory.createCommand(IAPICommand.VIEW_PROJECT_COMMAND, getProjectSettings());

command.addOption(new APIOption(IAPIOption.PROJECT, siProject.getConfigurationPath()));
MultiValue mv = APIUtils.createMultiValueField(IAPIFields.FIELD_SEPARATOR, IAPIFields.NAME,
Expand Down Expand Up @@ -396,12 +394,7 @@ public void checkout(Run<?, ?> run, Launcher launcher, FilePath workspace, TaskL

// Lets start with creating an authenticated Integrity API Session for various parts of this
// operation...
IntegrityConfigurable desSettings =
DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig);
IntegrityConfigurable coSettings = new IntegrityConfigurable("TEMP_ID",
desSettings.getIpHostName(), desSettings.getIpPort(), desSettings.getHostName(),
desSettings.getPort(), desSettings.getSecure(), userName, password.getPlainText());

IntegrityConfigurable coSettings = getProjectSettings();
// Lets also open the change log file for writing...
// Override file.encoding property so that we write as UTF-8 and do not have problems with
// special characters
Expand Down Expand Up @@ -448,12 +441,9 @@ public void checkout(Run<?, ?> run, Launcher launcher, FilePath workspace, TaskL
if (lastSuccjob != null)
{
Date lastSuccBuildDate = new Date(lastSuccjob.getStartTimeInMillis());
projectCPIDs = siProject.projectCPDiff(
DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig),
lastSuccBuildDate);
projectCPIDs = siProject.projectCPDiff(coSettings, lastSuccBuildDate);

IntegrityCMMember.viewCP(
DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig), projectCPIDs,
IntegrityCMMember.viewCP(coSettings, projectCPIDs,
job.getFullName().replace("/", "_"), membersInCP);
}
}
Expand Down Expand Up @@ -515,7 +505,7 @@ public void checkout(Run<?, ?> run, Launcher launcher, FilePath workspace, TaskL
}
listener.getLogger()
.println("Change log successfully generated: " + changeLogFile.getAbsolutePath());
// Delete non-members in this workspace.
// Delete non-members in this workspace, if appropriate.
if (deleteNonMembers)
{
IntegrityDeleteNonMembersTask deleteNonMembers = new IntegrityDeleteNonMembersTask(
Expand Down Expand Up @@ -586,7 +576,7 @@ private void checkPointBeforeBuild(Run<?, ?> run, TaskListener listener,
listener.getLogger().println(
"Preparing to execute pre-build si checkpoint for " + siProject.getConfigurationPath());
Response res =
siProject.checkpoint(DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig),
siProject.checkpoint(this.getProjectSettings(),
IntegrityCheckpointAction.evalGroovyExpression(run.getEnvironment(listener),
checkpointLabel));
LOGGER.fine(res.getCommandString() + " returned " + res.getExitCode());
Expand All @@ -596,10 +586,9 @@ private void checkPointBeforeBuild(Run<?, ?> run, TaskListener listener,
+ siProject.getConfigurationPath() + ", new revision is " + chkpt);
// Update the siProject to use the new checkpoint as the basis for this build
IAPICommand command = CommandFactory.createCommand(IAPICommand.PROJECT_INFO_COMMAND,
DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig));

command.addOption(new APIOption(IAPIOption.PROJECT, siProject.getProjectName()));
command.addOption(new APIOption(IAPIOption.PROJECT_REVISION, chkpt));
getProjectSettings());
command.addOption(new APIOption(IAPIOption.PROJECT,
siProject.getConfigurationPath() + "#forceJump=#b=" + chkpt));

Response infoRes = command.execute();
siProject.initializeProject(infoRes.getWorkItems().next());
Expand Down Expand Up @@ -652,13 +641,12 @@ public PollingResult compareRemoteRevisionWith(Job<?, ?> job, Launcher launcher,
Run<?, ?> lastSuccjob = job.getLastSuccessfulBuild();
if (lastSuccjob != null)
{
IntegrityConfigurable coSettings = this.getProjectSettings();
Date lastSuccBuildDate = new Date(lastSuccjob.getStartTimeInMillis());
projectCPIDs = getIntegrityProject().projectCPDiff(
DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig),
lastSuccBuildDate);
this.getProjectSettings(), lastSuccBuildDate);

IntegrityCMMember.viewCP(
DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig), projectCPIDs,
IntegrityCMMember.viewCP(coSettings, projectCPIDs,
job.getFullName().replace("/", ""), membersInCP);
changeCount = membersInCP.size();
}
Expand Down

0 comments on commit a946c0f

Please sign in to comment.