remoting/server/hudson/src/main/java/org/netbeans/modules/jackpot30/hudson/InstallIndexingTool.java
author Jan Lahoda <jlahoda@netbeans.org>
Sun, 08 Jan 2017 20:11:20 +0100
changeset 1035 97d4ae8fcb13
parent 597 4524a9f87990
permissions -rw-r--r--
Fixing license headers for various files
jlahoda@583
     1
/*
jlahoda@583
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
jlahoda@583
     3
 *
jlahoda@583
     4
 * Copyright 2011 Sun Microsystems, Inc. All rights reserved.
jlahoda@583
     5
 *
jlahoda@583
     6
 * The contents of this file are subject to the terms of either the GNU
jlahoda@583
     7
 * General Public License Version 2 only ("GPL") or the Common
jlahoda@583
     8
 * Development and Distribution License("CDDL") (collectively, the
jlahoda@583
     9
 * "License"). You may not use this file except in compliance with the
jlahoda@583
    10
 * License. You can obtain a copy of the License at
jlahoda@583
    11
 * http://www.netbeans.org/cddl-gplv2.html
jlahoda@583
    12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
jlahoda@583
    13
 * specific language governing permissions and limitations under the
jlahoda@583
    14
 * License.  When distributing the software, include this License Header
jlahoda@583
    15
 * Notice in each file and include the License file at
jlahoda@583
    16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
jlahoda@583
    17
 * particular file as subject to the "Classpath" exception as provided
jlahoda@583
    18
 * by Sun in the GPL Version 2 section of the License file that
jlahoda@583
    19
 * accompanied this code. If applicable, add the following below the
jlahoda@583
    20
 * License Header, with the fields enclosed by brackets [] replaced by
jlahoda@583
    21
 * your own identifying information:
jlahoda@583
    22
 * "Portions Copyrighted [year] [name of copyright owner]"
jlahoda@583
    23
 *
jlahoda@583
    24
 * If you wish your version of this file to be governed by only the CDDL
jlahoda@583
    25
 * or only the GPL Version 2, indicate your decision by adding
jlahoda@583
    26
 * "[Contributor] elects to include this software in this distribution
jlahoda@583
    27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
jlahoda@583
    28
 * single choice of license, a recipient has the option to distribute
jlahoda@583
    29
 * your version of this file under either the CDDL, the GPL Version 2 or
jlahoda@583
    30
 * to extend the choice of license to its licensees as provided above.
jlahoda@583
    31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
jlahoda@583
    32
 * Version 2 license, then the option applies only if the new code is
jlahoda@583
    33
 * made subject to such option by the copyright holder.
jlahoda@583
    34
 *
jlahoda@583
    35
 * Contributor(s):
jlahoda@583
    36
 *
jlahoda@583
    37
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
jlahoda@583
    38
 */
jlahoda@583
    39
package org.netbeans.modules.jackpot30.hudson;
jlahoda@583
    40
jlahoda@583
    41
import hudson.Extension;
jlahoda@583
    42
import hudson.FilePath;
jlahoda@583
    43
import hudson.init.InitMilestone;
jlahoda@583
    44
import hudson.init.Initializer;
jlahoda@583
    45
import hudson.model.Hudson;
jlahoda@583
    46
import hudson.model.Node;
jlahoda@583
    47
import hudson.model.TaskListener;
jlahoda@583
    48
import hudson.tools.DownloadFromUrlInstaller;
jlahoda@583
    49
import hudson.tools.InstallSourceProperty;
jlahoda@583
    50
import hudson.tools.ToolInstallation;
jlahoda@583
    51
import hudson.tools.ToolProperty;
jlahoda@1035
    52
import java.io.ByteArrayInputStream;
jlahoda@583
    53
import java.io.IOException;
jlahoda@1035
    54
import java.io.InputStream;
jlahoda@583
    55
import java.util.Arrays;
jlahoda@583
    56
import org.kohsuke.stapler.DataBoundConstructor;
jlahoda@583
    57
jlahoda@583
    58
/**
jlahoda@583
    59
 *
jlahoda@583
    60
 * @author lahvac
jlahoda@583
    61
 */
jlahoda@583
    62
public class InstallIndexingTool extends DownloadFromUrlInstaller {
jlahoda@583
    63
jlahoda@583
    64
    @DataBoundConstructor
jlahoda@583
    65
    public InstallIndexingTool(String id) {
jlahoda@583
    66
        super(id);
jlahoda@583
    67
    }
jlahoda@583
    68
jlahoda@583
    69
    @Override
jlahoda@583
    70
    public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
jlahoda@583
    71
        return super.performInstallation(tool, node, log);
jlahoda@583
    72
    }
jlahoda@583
    73
jlahoda@583
    74
    @Extension
jlahoda@583
    75
    public static class DescriptorImpl extends DownloadFromUrlInstaller.DescriptorImpl<InstallIndexingTool> {
jlahoda@583
    76
jlahoda@583
    77
        @Override
jlahoda@583
    78
        public String getDisplayName() {
jlahoda@583
    79
            return "Install from web";
jlahoda@583
    80
        }
jlahoda@583
    81
jlahoda@583
    82
        @Override
jlahoda@583
    83
        public boolean isApplicable(Class<? extends ToolInstallation> toolType) {
jlahoda@583
    84
            return toolType == IndexingTool.class;
jlahoda@583
    85
        }
jlahoda@583
    86
jlahoda@583
    87
    }
jlahoda@583
    88
jlahoda@1035
    89
    private static final String INSTALLER_DESCRIPTION =
jlahoda@1035
    90
            "{\"list\": [{\"id\": \"main\", \"name\": \"main\", \"url\": \"http://deadlock.netbeans.org/hudson/job/jackpot30/lastSuccessfulBuild/artifact/remoting/build/indexing-backend.zip\"}]}";
jlahoda@1035
    91
jlahoda@583
    92
    //XXX:
jlahoda@583
    93
    @Initializer(after=InitMilestone.JOB_LOADED)
jlahoda@583
    94
    public static void prepareUpdates() throws IOException, InterruptedException {
jlahoda@583
    95
        FilePath update = new FilePath(new FilePath(Hudson.getInstance().getRootPath(), "updates"), "org.netbeans.modules.jackpot30.hudson.InstallIndexingTool");
jlahoda@583
    96
jlahoda@1035
    97
        InputStream in = new ByteArrayInputStream(INSTALLER_DESCRIPTION.getBytes());
jlahoda@1035
    98
jlahoda@1035
    99
        try {
jlahoda@1035
   100
            update.copyFrom(in);
jlahoda@1035
   101
        } finally {
jlahoda@1035
   102
            in.close();
jlahoda@1035
   103
        }
jlahoda@583
   104
jlahoda@583
   105
        //preinstall main tool if it does not exist:
jlahoda@583
   106
        IndexingTool[] tools = Hudson.getInstance().getDescriptorByType(IndexingTool.DescriptorImpl.class).getInstallations();
jlahoda@583
   107
jlahoda@583
   108
        if (tools.length == 0) {
jlahoda@583
   109
            ToolProperty<ToolInstallation> install = new InstallSourceProperty(Arrays.asList(new InstallIndexingTool("main")));
jlahoda@586
   110
            Hudson.getInstance().getDescriptorByType(IndexingTool.DescriptorImpl.class).setInstallations(new IndexingTool(IndexingTool.DEFAULT_INDEXING_NAME, "", Arrays.asList(install)));
jlahoda@583
   111
        }
jlahoda@583
   112
    }
jlahoda@583
   113
jlahoda@583
   114
}