diff --git a/core/src/main/java/jenkins/configprovider/AbstractConfigProvider.java b/core/src/main/java/jenkins/configprovider/AbstractConfigProvider.java deleted file mode 100644 index eaf6454bd0..0000000000 --- a/core/src/main/java/jenkins/configprovider/AbstractConfigProvider.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - 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 configs = new HashMap(); - - public AbstractConfigProvider() { - load(); - } - - @Override - public Collection 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(); - -} diff --git a/core/src/main/java/jenkins/configprovider/ConfigProvider.java b/core/src/main/java/jenkins/configprovider/ConfigProvider.java deleted file mode 100644 index cff9bd019c..0000000000 --- a/core/src/main/java/jenkins/configprovider/ConfigProvider.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - 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 all() { - return Jenkins.getInstance().getExtensionList(ConfigProvider.class); - } - - /** - * returns all the configs of this provider - * - * @return collection of Configs - */ - public abstract Collection 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. null 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 true 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(); - -} diff --git a/core/src/main/java/jenkins/configprovider/model/Config.java b/core/src/main/java/jenkins/configprovider/model/Config.java deleted file mode 100644 index 541012cfe1..0000000000 --- a/core/src/main/java/jenkins/configprovider/model/Config.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - 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 + "]"; - } -} diff --git a/core/src/main/java/jenkins/configprovider/model/ConfigDescription.java b/core/src/main/java/jenkins/configprovider/model/ConfigDescription.java deleted file mode 100644 index 7ceaeefa1e..0000000000 --- a/core/src/main/java/jenkins/configprovider/model/ConfigDescription.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - 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; - } - -} diff --git a/core/src/main/java/jenkins/configprovider/model/ContentType.java b/core/src/main/java/jenkins/configprovider/model/ContentType.java deleted file mode 100644 index 83a9e6f834..0000000000 --- a/core/src/main/java/jenkins/configprovider/model/ContentType.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - 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 ( - * org.kohsuke.stapler.codemirror.mode.*).
- * Currently Supported: - *
    - *
  • clike
  • - *
  • css
  • - *
  • diff
  • - *
  • haskell
  • - *
  • htmlmixed
  • - *
  • javascript
  • - *
  • lua
  • - *
  • php
  • - *
  • plsql
  • - *
  • python
  • - *
  • rst
  • - *
  • smaltalk
  • - *
  • stex
  • - *
  • xml
  • - *
- * e.g. used in - * <textarea name="config.content" codemirror-mode="${contentType.cmMode}" ... /> - * - * @return the CodeMirror mode - */ - public String getCmMode(); - - /** - * Actually the 'mode' attribute for the CodeMirror editor. As in: - * <textarea name="config.content" codemirror-config="mode:'${contentType.mime}',lineNumbers: true" ... /> - * - * @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; - } - } - -} diff --git a/maven-plugin/pom.xml b/maven-plugin/pom.xml index 8e1724eb38..d22b251dde 100644 --- a/maven-plugin/pom.xml +++ b/maven-plugin/pom.xml @@ -119,7 +119,13 @@ THE SOFTWARE. org.jenkins-ci.main.maven maven3-interceptor ${mavenInterceptorsVersion} - + + + + org.jenkins-ci.lib + config-provider-model + 1.0-SNAPSHOT + org.apache.ant diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java index 29e266cb96..497ea6e356 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java @@ -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; diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java b/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java index 6e180b8ab3..7e724e05c9 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java @@ -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;