Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-39916 - Resolve conflicts
  • Loading branch information
alvarolobato committed Dec 1, 2016
2 parents 557fa79 + 32847d1 commit 75e5701
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 71 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -93,7 +93,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>config-file-provider</artifactId>
<version>2.11</version>
<version>2.14.2-beta</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down
Expand Up @@ -26,12 +26,15 @@

import com.google.common.collect.ImmutableSet;
import hudson.EnvVars;
import hudson.model.ItemGroup;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.plugins.configfiles.ConfigFiles;
import org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig.GlobalMavenSettingsConfigProvider;
import org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig.MavenSettingsConfigProvider;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

Expand Down Expand Up @@ -210,27 +213,21 @@ public ListBoxModel doFillJdkItems() {
}

@Restricted(NoExternalUse.class) // Only for UI calls
public ListBoxModel doFillMavenSettingsConfigItems() {
ExtensionList<MavenSettingsConfigProvider> providers = Jenkins.getActiveInstance().getExtensionList(MavenSettingsConfigProvider.class);
public ListBoxModel doFillMavenSettingsConfigItems(@AncestorInPath ItemGroup context) {
ListBoxModel r = new ListBoxModel();
r.add("--- Use system default settings or file path ---",null);
for (ConfigProvider provider : providers) {
for(Config config:provider.getAllConfigs()){
r.add(config.name, config.id);
}
for (Config config : ConfigFiles.getConfigsInContext(context, MavenSettingsConfigProvider.class)) {
r.add(config.name, config.id);
}
return r;
}

@Restricted(NoExternalUse.class) // Only for UI calls
public ListBoxModel doFillGlobalMavenSettingsConfigItems() {
ExtensionList<GlobalMavenSettingsConfigProvider> providers = Jenkins.getActiveInstance().getExtensionList(GlobalMavenSettingsConfigProvider.class);
public ListBoxModel doFillGlobalMavenSettingsConfigItems(@AncestorInPath ItemGroup context) {
ListBoxModel r = new ListBoxModel();
r.add("--- Use system default settings or file path ---",null);
for (ConfigProvider provider : providers) {
for(Config config:provider.getAllConfigs()){
r.add(config.name, config.id);
}
for (Config config : ConfigFiles.getConfigsInContext(context, GlobalMavenSettingsConfigProvider.class)) {
r.add(config.name, config.id);
}
return r;
}
Expand Down
Expand Up @@ -45,6 +45,7 @@

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.plugins.configfiles.ConfigFiles;
import org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig;
import org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig;
import org.jenkinsci.plugins.configfiles.maven.security.CredentialsHelper;
Expand Down Expand Up @@ -522,40 +523,41 @@ private String setupGlobalSettingFile() throws IOException, InterruptedException
* @throws AbortException in case of error
*/
private void settingsFromConfig(String settingsConfigId, FilePath settingsFile) throws AbortException {
Config c = Config.getByIdOrNull(settingsConfigId);
if (c != null) {
MavenSettingsConfig config;
if (c instanceof MavenSettingsConfig) {
config = (MavenSettingsConfig) c;
} else {
config = new MavenSettingsConfig(c.id, c.name, c.comment, c.content, MavenSettingsConfig.isReplaceAllDefault, null);
}

final Boolean isReplaceAll = config.getIsReplaceAll();
console.println("Using settings config with name " + config.name);
console.println("Replacing all maven server entries not found in credentials list is " + isReplaceAll);
if (StringUtils.isNotBlank(config.content)) {
try {
String fileContent = config.content;
Config c = ConfigFiles.getByIdOrNull(build, settingsConfigId);
if (c == null) {
throw new AbortException("Could not find the Maven settings.xml config file id:" + settingsConfigId + ". Make sure it exists on Managed Files");
}
if (StringUtils.isBlank(c.content)) {
throw new AbortException("Could not create Maven settings.xml config file id:" + settingsConfigId + ". Content of the file is empty");
}

final List<ServerCredentialMapping> serverCredentialMappings = config.getServerCredentialMappings();
final Map<String, StandardUsernameCredentials> resolvedCredentials = CredentialsHelper.resolveCredentials(build, serverCredentialMappings);
MavenSettingsConfig config;
if (c instanceof MavenSettingsConfig) {
config = (MavenSettingsConfig) c;
} else {
config = new MavenSettingsConfig(c.id, c.name, c.comment, c.content, MavenSettingsConfig.isReplaceAllDefault, null);
}

if (!resolvedCredentials.isEmpty()) {
List<String> tempFiles = new ArrayList<String>();
fileContent = CredentialsHelper.fillAuthentication(fileContent, isReplaceAll, resolvedCredentials, tempBinDir, tempFiles);
}
final Boolean isReplaceAll = config.getIsReplaceAll();
console.println("Using settings config with name " + config.name);
console.println("Replacing all maven server entries not found in credentials list is " + isReplaceAll);

settingsFile.write(fileContent, getComputer().getDefaultCharset().name());
LOGGER.log(Level.FINE, "Created config file {0}", new Object[] { settingsFile });
} catch (Exception e) {
throw new IllegalStateException("the settings.xml could not be supplied for the current build: " + e.getMessage(), e);
}
} else {
throw new AbortException("Could not create Maven settings.xml config file id:" + settingsConfigId + ". Content of the file is empty");
try {
String fileContent = config.content;

final List<ServerCredentialMapping> serverCredentialMappings = config.getServerCredentialMappings();
final Map<String, StandardUsernameCredentials> resolvedCredentials = CredentialsHelper.resolveCredentials(build, serverCredentialMappings);

if (!resolvedCredentials.isEmpty()) {
List<String> tempFiles = new ArrayList<String>();
fileContent = CredentialsHelper.fillAuthentication(fileContent, isReplaceAll, resolvedCredentials, tempBinDir, tempFiles);
}
} else {
throw new AbortException("Could not find the Maven settings.xml config file id:" + settingsConfigId + ". Make sure it exists on Managed Files");

settingsFile.write(fileContent, getComputer().getDefaultCharset().name());
LOGGER.log(Level.FINE, "Created config file {0}", new Object[]{settingsFile});
} catch (Exception e) {
throw new IllegalStateException("the settings.xml could not be supplied for the current build: " + e.getMessage(), e);
}
}

Expand All @@ -569,40 +571,40 @@ private void settingsFromConfig(String settingsConfigId, FilePath settingsFile)
* @throws AbortException in case of error
*/
private void globalSettingsFromConfig(String globalSettingsConfigId, FilePath globalSettingsFile) throws AbortException {
Config c = Config.getByIdOrNull(globalSettingsConfigId);
if (c != null) {
GlobalMavenSettingsConfig config;
if (c instanceof GlobalMavenSettingsConfig) {
config = (GlobalMavenSettingsConfig) c;
} else {
config = new GlobalMavenSettingsConfig(c.id, c.name, c.comment, c.content, MavenSettingsConfig.isReplaceAllDefault, null);
}

final Boolean isReplaceAll = config.getIsReplaceAll();
console.println("Using global settings config with name " + config.name);
console.println("Replacing all maven server entries not found in credentials list is " + isReplaceAll);
if (StringUtils.isNotBlank(config.content)) {
try {
String fileContent = config.content;
Config c = ConfigFiles.getByIdOrNull(build, globalSettingsConfigId);
if (c == null) {
throw new AbortException("Could not find the Maven global settings.xml config file id:" + globalSettingsFile + ". Make sure it exists on Managed Files");
}
if (StringUtils.isBlank(c.content)) {
throw new AbortException("Could not create Maven global settings.xml config file id:" + globalSettingsFile + ". Content of the file is empty");
}

GlobalMavenSettingsConfig config;
if (c instanceof GlobalMavenSettingsConfig) {
config = (GlobalMavenSettingsConfig) c;
} else {
config = new GlobalMavenSettingsConfig(c.id, c.name, c.comment, c.content, MavenSettingsConfig.isReplaceAllDefault, null);
}

final List<ServerCredentialMapping> serverCredentialMappings = config.getServerCredentialMappings();
final Map<String, StandardUsernameCredentials> resolvedCredentials = CredentialsHelper.resolveCredentials(build, serverCredentialMappings);
final Boolean isReplaceAll = config.getIsReplaceAll();
console.println("Using global settings config with name " + config.name);
console.println("Replacing all maven server entries not found in credentials list is " + isReplaceAll);
try {
String fileContent = config.content;

if (!resolvedCredentials.isEmpty()) {
List<String> tempFiles = new ArrayList<String>();
fileContent = CredentialsHelper.fillAuthentication(fileContent, isReplaceAll, resolvedCredentials, tempBinDir, tempFiles);
}
final List<ServerCredentialMapping> serverCredentialMappings = config.getServerCredentialMappings();
final Map<String, StandardUsernameCredentials> resolvedCredentials = CredentialsHelper.resolveCredentials(build, serverCredentialMappings);

globalSettingsFile.write(fileContent, getComputer().getDefaultCharset().name());
LOGGER.log(Level.FINE, "Created global config file {0}", new Object[] { globalSettingsFile });
} catch (Exception e) {
throw new IllegalStateException("the globalSettings.xml could not be supplied for the current build: " + e.getMessage(), e);
}
} else {
throw new AbortException("Could not create Global Maven settings.xml config file id:" + globalSettingsConfigId + ". Content of the file is empty");
if (!resolvedCredentials.isEmpty()) {
List<String> tempFiles = new ArrayList<String>();
fileContent = CredentialsHelper.fillAuthentication(fileContent, isReplaceAll, resolvedCredentials, tempBinDir, tempFiles);
}
} else {
throw new AbortException("Could not find the Global Maven settings.xml config file id:" + globalSettingsConfigId + ". Make sure it exists on Managed Files");

globalSettingsFile.write(fileContent, getComputer().getDefaultCharset().name());
LOGGER.log(Level.FINE, "Created global config file {0}", new Object[]{globalSettingsFile});
} catch (Exception e) {
throw new IllegalStateException("the globalSettings.xml could not be supplied for the current build: " + e.getMessage(), e);
}
}

Expand Down

0 comments on commit 75e5701

Please sign in to comment.