Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright (C) 2010 JFrog Ltd.
   * 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
  * 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 org.jfrog.hudson;
 import java.util.List;

Yossi Shaul
 public class ArtifactoryBuilder extends Builder {
     public boolean perform(AbstractBuild buildLauncher launcherBuildListener listener) {
         // this is where you 'build' the project
         List<ArtifactoryServerservers = getDescriptor().getArtifactoryServers();
         if (servers.isEmpty()) {
             listener.getLogger().println("No Artifactory server configured");
         } else {
             listener.getLogger().println(servers.size() + " Artifactory servers configured");
         return true;
     // override for better type safety.
     // if your plugin doesn't really define any property on Descriptor,
     // you don't have to do this.
     public DescriptorImpl getDescriptor() {
         return (DescriptorImplsuper.getDescriptor();

Descriptor for ArtifactoryBuilder. Used as a singleton. The class is marked as public so that it can be accessed from views.

See views/hudson/plugins/artifactory/ArtifactoryBuilder/*.jelly for the actual HTML fragment for the configuration screen.

     // this marker indicates Hudson that this is an implementation of an extension point.
     public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
         private List<ArtifactoryServerartifactoryServers;
         public DescriptorImpl() {

Performs on-the-fly validation of the form field 'name'.

value This parameter receives the value that the user has typed.
Indicates the outcome of the validation. This is sent to the browser.
         public FormValidation doCheckName(@QueryParameter String valuethrows IOExceptionServletException {
             if (value.length() == 0) {
                 return FormValidation.error("Please set a name");
             if (value.length() < 4) {
                 return FormValidation.warning("Isn't the name too short?");
             return FormValidation.ok();

Most chances this validation won't work, since there no proper way to explicitly request either deployer or resolver credentials from the global config form, so we can't check if we should use resolver or deployer credentials when testing the connection to the server
        public FormValidation doCheckUrl(@QueryParameter final String value,
                @QueryParameter final String username,
                @QueryParameter final String passwordthrows ServletException {
            if (StringUtils.isBlank(value)) {
                return FormValidation.error("Please set a valid Artifactory URL");
            ArtifactoryBuildInfoClient client;
            if (StringUtils.isNotBlank(username)) {
                client = new ArtifactoryBuildInfoClient(valueusernamepasswordnew NullLog());
            } else {
                client = new ArtifactoryBuildInfoClient(valuenew NullLog());
            ArtifactoryVersion version;
            try {
                version = client.verifyCompatibleArtifactoryVersion();
            } catch (UnsupportedOperationException uoe) {
                return FormValidation.warning(uoe.getMessage());
            } catch (Exception e) {
                return FormValidation.error(e.getMessage());
            return FormValidation.ok("Found Artifactory " + version.toString());
        public boolean isApplicable(Class<? extends AbstractProjectaClass) {
            // indicates that this builder can be used with all kinds of project types
            return aClass == MavenModuleSet.class;

This human readable name is used in the configuration screen.
        public String getDisplayName() {
            return "Artifactory Plugin";
        public boolean configure(StaplerRequest reqJSONObject othrows FormException {
            Object servers = o.get("artifactoryServer");    // an array or single object
            if (!JSONNull.getInstance().equals(servers)) {
                 = req.bindJSONToList(ArtifactoryServer.classservers);
            } else {
                 = null;
            return super.configure(reqo);
        public List<ArtifactoryServergetArtifactoryServers() {
            return ;
        // Required by external plugins.
        public void setArtifactoryServers(List<ArtifactoryServerartifactoryServers) {
            this. = artifactoryServers;
New to GrepCode? Check out our FAQ X