Skip to content

Commit

Permalink
JENKINS-39916 update config-file-provider plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
imod committed Nov 21, 2016
1 parent a1bd50a commit 2d95836
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -92,7 +92,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>config-file-provider</artifactId>
<version>2.11</version>
<version>2.14.2-beta</version>
</dependency>
</dependencies>
</project>
Expand Up @@ -24,14 +24,17 @@

package org.jenkinsci.plugins.pipeline.maven;

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.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
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 @@ -195,27 +198,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 @@ -517,7 +518,16 @@ 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);

Config c = null;
Executor executor = Executor.currentExecutor();
if (executor != null) {
Queue.Executable currentExecutable = executor.getCurrentExecutable();
if (currentExecutable != null) {
c = ConfigFiles.getByIdOrNull((Run<?, ?>) currentExecutable, settingsConfigId);
}
}

if (c != null) {
MavenSettingsConfig config;
if (c instanceof MavenSettingsConfig) {
Expand Down Expand Up @@ -564,7 +574,16 @@ 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);

Config c = null;
Executor executor = Executor.currentExecutor();
if (executor != null) {
Queue.Executable currentExecutable = executor.getCurrentExecutable();
if (currentExecutable != null) {
c = ConfigFiles.getByIdOrNull((Run<?, ?>) currentExecutable, globalSettingsConfigId);
}
}

if (c != null) {
GlobalMavenSettingsConfig config;
if (c instanceof GlobalMavenSettingsConfig) {
Expand Down

0 comments on commit 2d95836

Please sign in to comment.