提交 c9688c34 编写于 作者: O Olivier Lamy

change package import due to moove of config provider classes to a separate repo

上级 21a1dafb
/*
The MIT License
Copyright (c) 2011, Dominik Bartholdi
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 jenkins.configprovider;
import hudson.BulkChange;
import hudson.XmlFile;
import hudson.model.Saveable;
import hudson.model.listeners.SaveableListener;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import jenkins.configprovider.model.Config;
import jenkins.configprovider.model.ConfigDescription;
import jenkins.model.Jenkins;
public abstract class AbstractConfigProvider extends ConfigProvider implements Saveable {
protected final String ID_PREFIX = this.getClass().getSimpleName() + ".";
protected Map<String, Config> configs = new HashMap<String, Config>();
public AbstractConfigProvider() {
load();
}
@Override
public Collection<Config> getAllConfigs() {
return Collections.unmodifiableCollection(configs.values());
}
@Override
public Config getConfigById(String configId) {
return configs.get(configId);
}
@Override
public abstract ConfigDescription getConfigDescription();
@Override
public String getProviderId() {
return ID_PREFIX;
}
@Override
public boolean isResponsibleFor(String configId) {
return configId != null && configId.startsWith(ID_PREFIX);
}
@Override
public Config newConfig() {
String id = this.getProviderId() + System.currentTimeMillis();
return new Config(id, null, null, null);
}
@Override
public void remove(String configId) {
configs.remove(configId);
this.save();
}
@Override
public void save(Config config) {
configs.put(config.id, config);
this.save();
}
/**
* @see hudson.model.Saveable#save()
*/
public void save() {
if (BulkChange.contains(this))
return;
try {
getConfigXml().write(this);
SaveableListener.fireOnChange(this, getConfigXml());
} catch (IOException e) {
e.printStackTrace();
}
}
protected void load() {
XmlFile xml = getConfigXml();
if (xml.exists()) {
try {
xml.unmarshal(this);
} catch (IOException e) {
e.printStackTrace();
}
}
}
protected XmlFile getConfigXml() {
return new XmlFile(Jenkins.XSTREAM, new File(Jenkins.getInstance().getRootDir(), this.getXmlFileName()));
}
protected abstract String getXmlFileName();
}
/*
The MIT License
Copyright (c) 2011, Dominik Bartholdi
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 jenkins.configprovider;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import java.util.Collection;
import jenkins.configprovider.model.Config;
import jenkins.configprovider.model.ConfigDescription;
import jenkins.configprovider.model.ContentType;
import jenkins.model.Jenkins;
/**
* A ConfigProvider is able to manage different configuration files (see:
* {@link Config})
*
* @author domi
*
*/
public abstract class ConfigProvider implements ExtensionPoint {
/**
* All registered {@link ConfigProvider}s.
*/
public static ExtensionList<ConfigProvider> all() {
return Jenkins.getInstance().getExtensionList(ConfigProvider.class);
}
/**
* returns all the configs of this provider
*
* @return collection of Configs
*/
public abstract Collection<Config> getAllConfigs();
/**
* The description of the config this provider is able to provide instances
* of
*
* @return the description
*/
public abstract ConfigDescription getConfigDescription();
/**
* The content type of the configs this provider manages. e.g. can be used
* to display the content in the UI (editor).
*
* @return the type. <code>null</code> if no specific formating should be
* supported.
*/
public abstract ContentType getContentType();
/**
* Returns the config item identified by this id.
*
* @param configId
* the id
* @return the config with the given id
*/
public abstract Config getConfigById(String configId);
/**
* Whether this provider is responsible for a Config with the given Id.
*
* @param configId
* the id to check
* @return <code>true</code> if the provider takes responsibility
*/
public abstract boolean isResponsibleFor(String configId);
/**
* save the content of the given config.
*
* @param config
* the config to be saved
*/
public abstract void save(Config config);
/**
* Removes/deletes the config with the given Id
*
* @param configId
* the id
*/
public abstract void remove(String configId);
/**
* An ID uniquely identifying this provider, the id of each {@link Config}
* must start with this ID separated by a '.'!
*
* @return the unique id for this provider.
*/
public abstract String getProviderId();
/**
* Returns a new {@link Config} object with a unique id, starting with the
* id of this provider - separated by '.'. e.g. "MyCustomProvider.123456".
* This object is also used initialize the user interface.
*
* @return the new config object, ready for editing.
*/
public abstract Config newConfig();
}
/*
The MIT License
Copyright (c) 2011, Dominik Bartholdi
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 jenkins.configprovider.model;
import jenkins.configprovider.ConfigProvider;
import org.kohsuke.stapler.DataBoundConstructor;
import java.io.Serializable;
/**
* Represents a configuration file. A Config object is always managed by one
* specific {@link ConfigProvider}
*
* @author domi
*
*/
public class Config implements Serializable {
/**
* a unique id along all providers!
*/
public final String id;
public final String name;
public final String comment;
public final String content;
@DataBoundConstructor
public Config(String id, String name, String comment, String content) {
this.id = id == null ? String.valueOf(System.currentTimeMillis()) : id;
this.name = name;
this.comment = comment;
this.content = content;
}
@Override
public String toString() {
return "[Config: id=" + id + ", name=" + name + "]";
}
}
/*
The MIT License
Copyright (c) 2011, Dominik Bartholdi
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 jenkins.configprovider.model;
import jenkins.configprovider.ConfigProvider;
/**
* Describes the {@link Config} a {@link ConfigProvider} is able to handle. This
* information can be used for display in the UI.
*
* @author domi
*
*/
public class ConfigDescription {
private final String name;
private final String description;
public ConfigDescription(String name, String description) {
this.name = name;
this.description = description;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
}
/*
The MIT License
Copyright (c) 2011, Dominik Bartholdi
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 jenkins.configprovider.model;
/**
* Describes the content of a {@link Config} in a more technical way. In fact it
* provides information to determine how the content should be rendered in a
* editor (e.g. CodeMirror).
*
* @author domi
*
*/
public interface ContentType {
/**
* The CodeMirror mode as defined in Stapler (
* <code>org.kohsuke.stapler.codemirror.mode.*</code>). <br>
* Currently Supported:
* <ul>
* <li>clike</li>
* <li>css</li>
* <li>diff</li>
* <li>haskell</li>
* <li>htmlmixed</li>
* <li>javascript</li>
* <li>lua</li>
* <li>php</li>
* <li>plsql</li>
* <li>python</li>
* <li>rst</li>
* <li>smaltalk</li>
* <li>stex</li>
* <li>xml</li>
* </ul>
* e.g. used in
* <code>&lt;textarea name="config.content" codemirror-mode="${contentType.cmMode}" ... /&gt;</code>
*
* @return the CodeMirror mode
*/
public String getCmMode();
/**
* Actually the 'mode' attribute for the CodeMirror editor. As in:
* <code>&lt;textarea name="config.content" codemirror-config="mode:'${contentType.mime}',lineNumbers: true" ... /&gt;</code>
*
* @return the mime.
*/
public String getMime();
public enum DefinedType implements ContentType {
XML("xml", "application/xml"), HTML("htmlmixed", "text/html"), GROOVY(
"clike", "text/x-groovy");
public final String cmMode;
public final String mime;
private DefinedType(String cmMode, String mime) {
this.cmMode = cmMode;
this.mime = mime;
}
public String getCmMode() {
return cmMode;
}
public String getMime() {
return mime;
}
}
}
......@@ -119,7 +119,13 @@ THE SOFTWARE.
<groupId>org.jenkins-ci.main.maven</groupId>
<artifactId>maven3-interceptor</artifactId>
<version>${mavenInterceptorsVersion}</version>
</dependency>
</dependency>
<dependency>
<groupId>org.jenkins-ci.lib</groupId>
<artifactId>config-provider-model</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
......
......@@ -42,8 +42,6 @@ import hudson.model.Descriptor;
import hudson.model.Descriptor.FormException;
import hudson.model.Executor;
import hudson.model.TaskListener;
import jenkins.configprovider.ConfigProvider;
import jenkins.configprovider.model.Config;
import jenkins.model.Jenkins;
import hudson.model.Item;
import hudson.model.ItemGroup;
......@@ -92,6 +90,8 @@ 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;
......
......@@ -47,8 +47,6 @@ import hudson.model.Computer;
import hudson.model.Environment;
import hudson.model.Executor;
import hudson.model.Fingerprint;
import jenkins.configprovider.ConfigProvider;
import jenkins.configprovider.model.Config;
import jenkins.model.Jenkins;
import hudson.model.ParameterDefinition;
import hudson.model.ParametersAction;
......@@ -101,6 +99,8 @@ import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.plexus.util.PathTool;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册