提交 fff55f85 编写于 作者: I imod

refactor interaction with config-file-provider plugin to make dependency optional

上级 9cc6e16d
......@@ -37,6 +37,7 @@ import hudson.Util;
import hudson.maven.local_repo.DefaultLocalRepositoryLocator;
import hudson.maven.local_repo.LocalRepositoryLocator;
import hudson.maven.local_repo.PerJobLocalRepositoryLocator;
import hudson.maven.settings.SettingConfig;
import hudson.maven.settings.SettingsProviderUtils;
import hudson.model.AbstractProject;
import hudson.model.Action;
......@@ -96,8 +97,6 @@ import net.sf.json.JSONObject;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.QueryParameter;
......@@ -117,7 +116,6 @@ import org.kohsuke.stapler.export.Exported;
*/
public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenModuleSetBuild> implements TopLevelItem, ItemGroup<MavenModule>, SCMedItem, Saveable, BuildableItemWithBuildWrappers {
/**
* All {@link MavenModule}s, keyed by their {@link MavenModule#getModuleName()} module name}s.
*/
......@@ -944,34 +942,16 @@ public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenMod
* @since 1.426
* @return
*/
public List<Config> getAllMavenSettingsConfigs() {
List<Config> mavenSettingsConfigs = new ArrayList<Config>();
ExtensionList<ConfigProvider> configProviders = ConfigProvider.all();
if (configProviders != null && configProviders.size() > 0) {
for (ConfigProvider configProvider : configProviders) {
if (SettingsProviderUtils.isMavenSettingsProvider( configProvider )){
mavenSettingsConfigs.addAll( configProvider.getAllConfigs() );
}
}
}
return mavenSettingsConfigs;
public List<SettingConfig> getAllMavenSettingsConfigs() {
return SettingsProviderUtils.getAllMavenSettingsConfigs();
}
/**
* @since 1.426
* @return
*/
public List<Config> getAllGlobalMavenSettingsConfigs() {
List<Config> globalMavenSettingsConfigs = new ArrayList<Config>();
ExtensionList<ConfigProvider> configProviders = ConfigProvider.all();
if (configProviders != null && configProviders.size() > 0) {
for (ConfigProvider configProvider : configProviders) {
if (SettingsProviderUtils.isGlobalMavenSettingsProvider( configProvider )){
globalMavenSettingsConfigs.addAll( configProvider.getAllConfigs() );
}
}
}
return globalMavenSettingsConfigs;
public List<SettingConfig> getAllGlobalMavenSettingsConfigs() {
return SettingsProviderUtils.getAllGlobalMavenSettingsConfigs();
}
/**
......
......@@ -34,8 +34,7 @@ import hudson.maven.MavenBuild.ProxyImpl2;
import hudson.maven.reporters.MavenAggregatedArtifactRecord;
import hudson.maven.reporters.MavenFingerprinter;
import hudson.maven.reporters.MavenMailer;
import hudson.maven.settings.GlobalMavenSettingsProvider;
import hudson.maven.settings.MavenSettingsProvider;
import hudson.maven.settings.SettingConfig;
import hudson.maven.settings.SettingsProviderUtils;
import hudson.model.AbstractProject;
import hudson.model.Action;
......@@ -92,7 +91,6 @@ import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.plexus.util.PathTool;
import org.jenkinsci.lib.configprovider.model.Config;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
......@@ -624,7 +622,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
String settingsConfigId = project.getSettingConfigId();
if (StringUtils.isNotBlank(settingsConfigId)) {
Config settingsConfig = SettingsProviderUtils.findConfig( settingsConfigId, MavenSettingsProvider.class, org.jenkinsci.lib.configprovider.maven.MavenSettingsProvider.class );
SettingConfig settingsConfig = SettingsProviderUtils.findSettings(settingsConfigId);
if (settingsConfig == null) {
logger.println(" your Apache Maven build is setup to use a config with id " + settingsConfigId
+ " but cannot find the config");
......@@ -639,7 +637,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
String globalSettingsConfigId = project.getGlobalSettingConfigId();
if (StringUtils.isNotBlank(globalSettingsConfigId)) {
Config settingsConfig = SettingsProviderUtils.findConfig( globalSettingsConfigId, GlobalMavenSettingsProvider.class, org.jenkinsci.lib.configprovider.maven.GlobalMavenSettingsProvider.class );
SettingConfig settingsConfig = SettingsProviderUtils.findSettings(globalSettingsConfigId);
if (settingsConfig == null) {
logger.println(" your Apache Maven build is setup to use a global settings config with id " + globalSettingsConfigId
+ " but cannot find the config");
......
......@@ -29,8 +29,7 @@ import hudson.Launcher;
import hudson.Util;
import hudson.maven.reporters.MavenAbstractArtifactRecord;
import hudson.maven.reporters.MavenArtifactRecord;
import hudson.maven.settings.GlobalMavenSettingsProvider;
import hudson.maven.settings.MavenSettingsProvider;
import hudson.maven.settings.SettingConfig;
import hudson.maven.settings.SettingsProviderUtils;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
......@@ -54,6 +53,9 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.Artifact;
......@@ -67,13 +69,9 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.cli.BatchModeMavenTransferListener;
import org.apache.maven.repository.Proxy;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.jenkinsci.lib.configprovider.model.Config;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
/**
* {@link Publisher} for {@link MavenModuleSetBuild} to deploy artifacts
* after a build is fully succeeded.
......@@ -233,8 +231,7 @@ public class RedeployPublisher extends Recorder {
String altSettingsPath = null;
if (!StringUtils.isBlank(settingsConfigId)) {
Config config = SettingsProviderUtils.findConfig( settingsConfigId,
MavenSettingsProvider.class, org.jenkinsci.lib.configprovider.maven.MavenSettingsProvider.class );
SettingConfig config = SettingsProviderUtils.findSettings(settingsConfigId);
if (config == null) {
listener.getLogger().println(
" your Apache Maven build is setup to use a config with id " + settingsConfigId
......@@ -254,7 +251,7 @@ public class RedeployPublisher extends Recorder {
String globalSettingsConfigId = mavenModuleSet.getGlobalSettingConfigId();
if (!StringUtils.isBlank(globalSettingsConfigId)) {
Config config = SettingsProviderUtils.findConfig( globalSettingsConfigId, GlobalMavenSettingsProvider.class, org.jenkinsci.lib.configprovider.maven.GlobalMavenSettingsProvider.class );
SettingConfig config = SettingsProviderUtils.findSettings(globalSettingsConfigId);
if (config == null) {
listener.getLogger().println(
" your Apache Maven build is setup to use a global settings config with id "
......
/*
* Copyright 20011 Olivier Lamy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hudson.maven.settings;
/**
* @author Olivier Lamy
* @since 1.426
*/
public interface GlobalMavenSettingsProvider {
// no op only a marker interface
}
/*
The MIT License
Copyright (c) 2011, Dominik Bartholdi, Olivier Lamy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package hudson.maven.settings;
/**
* @since 1.426
*/
public interface MavenSettingsProvider
{
// no op only a marker interface
}
......@@ -15,15 +15,13 @@
*/
package hudson.maven.settings;
import hudson.ExtensionList;
import hudson.FilePath;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
/**
* @author Olivier Lamy
......@@ -32,89 +30,54 @@ import org.jenkinsci.lib.configprovider.model.Config;
*/
public class SettingsProviderUtils {
/**
* utility method to retrieve Config of type (MavenSettingsProvider etc..)
*
* @param settingsConfigId
* @param type
* @return Config
*/
public static Config findConfig(String settingsConfigId, Class<?>... types) {
ExtensionList<ConfigProvider> configProviders = ConfigProvider.all();
if (configProviders != null && configProviders.size() > 0) {
for (ConfigProvider configProvider : configProviders) {
for (Class<?> type : types) {
if (type.isAssignableFrom(configProvider.getClass())) {
if (configProvider.isResponsibleFor(settingsConfigId)) {
return configProvider.getConfigById(settingsConfigId);
}
}
private static ConfigProviderFacade configProvider = new ConfigProviderDelegate();
}
}
}
return null;
}
private SettingsProviderUtils() {
}
/**
*
* @param config
* @param workspace
*/
public static FilePath copyConfigContentToFilePath(Config config, FilePath workspace) throws IOException, InterruptedException {
return workspace.createTextTempFile("config", ".tmp", config.content, false);
}
/**
* @since 1.426
* @return
*/
public static List<SettingConfig> getAllMavenSettingsConfigs() {
return configProvider.getAllMavenSettingsConfigs();
}
/**
*
* @return a temp file which must be deleted after use
*/
public static File copyConfigContentToFile(Config config) throws IOException {
/**
* @since 1.426
* @return
*/
public static List<SettingConfig> getAllGlobalMavenSettingsConfigs() {
return configProvider.getAllGlobalMavenSettingsConfigs();
}
File tmpContentFile = File.createTempFile("config", "tmp");
FileUtils.writeStringToFile(tmpContentFile, config.content);
return tmpContentFile;
}
/**
* utility method to retrieve Config of type (MavenSettingsProvider etc..)
*
* @param settingsConfigId
* @param type
* @return SettingConfig
*/
public static SettingConfig findSettings(String settingsConfigId) {
return configProvider.findConfig(settingsConfigId);
}
/**
* tells whether a config file provider serves global settings configs
*
* @param configProvider
* the provider to check
* @return <code>true</code> if it implements one of the supported
* interfaces
*/
public static boolean isGlobalMavenSettingsProvider(ConfigProvider configProvider) {
// first prio to old implementation
if (configProvider instanceof GlobalMavenSettingsProvider) {
return true;
}
// second prio to new impl, only if the plugin is installed
if (org.jenkinsci.lib.configprovider.maven.GlobalMavenSettingsProvider.class.isAssignableFrom(configProvider.getClass())) {
return true;
}
return false;
}
/**
*
* @param config
* @param workspace
*/
public static FilePath copyConfigContentToFilePath(SettingConfig config, FilePath workspace) throws IOException, InterruptedException {
return workspace.createTextTempFile("config", ".tmp", config.content, false);
}
/**
* tells whether a config file provider serves settings configs
*
* @param configProvider
* the provider to check
* @return <code>true</code> if it implements one of the supported
* interfaces
*/
public static boolean isMavenSettingsProvider(ConfigProvider configProvider) {
// first prio to old implementation
if (configProvider instanceof MavenSettingsProvider) {
return true;
}
// second prio to new impl, only if the plugin is installed
if (org.jenkinsci.lib.configprovider.maven.MavenSettingsProvider.class.isAssignableFrom(configProvider.getClass())) {
return true;
}
return false;
}
/**
* @return a temp file which must be deleted after use
*/
public static File copyConfigContentToFile(SettingConfig config) throws IOException {
File tmpContentFile = File.createTempFile("config", "tmp");
FileUtils.writeStringToFile(tmpContentFile, config.content);
return tmpContentFile;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册