Search in sources :

Example 11 with PluginWrapper

use of hudson.PluginWrapper in project blueocean-plugin by jenkinsci.

the class BlueI18nTest method test_200_response_locale_fallback.

@Test
public void test_200_response_locale_fallback() {
    PluginWrapper plugin = BlueI18n.getPlugin("blueocean-dashboard");
    if (plugin == null) {
        // Skip. See waitForPluginLoaded() above.
        return;
    }
    String dashboardVersion = plugin.getVersion();
    // Make sure we fallback to the base resource bundle def if an unknown locale is requested.
    // Of course, we will need to modify this test if translations for the test languages are added.
    get("/blue/rest/i18n/blueocean-dashboard/" + dashboardVersion + "/jenkins.plugins.blueocean.dashboard.Messages/en", HttpServletResponse.SC_OK, Map.class);
    get("/blue/rest/i18n/blueocean-dashboard/" + dashboardVersion + "/jenkins.plugins.blueocean.dashboard.Messages/en_US", HttpServletResponse.SC_OK, Map.class);
    get("/blue/rest/i18n/blueocean-dashboard/" + dashboardVersion + "/jenkins.plugins.blueocean.dashboard.Messages/jp", HttpServletResponse.SC_OK, Map.class);
}
Also used : PluginWrapper(hudson.PluginWrapper) Test(org.junit.Test) BaseTest(io.jenkins.blueocean.service.embedded.BaseTest)

Example 12 with PluginWrapper

use of hudson.PluginWrapper in project hudson-2.x by hudson.

the class UsageStatistics method getStatData.

/**
     * Gets the encrypted usage stat data to be sent to the Hudson server.
     */
public String getStatData() throws IOException {
    Hudson h = Hudson.getInstance();
    JSONObject o = new JSONObject();
    o.put("stat", 1);
    o.put("install", Util.getDigestOf(h.getSecretKey()));
    o.put("version", Hudson.VERSION);
    List<JSONObject> nodes = new ArrayList<JSONObject>();
    for (Computer c : h.getComputers()) {
        JSONObject n = new JSONObject();
        if (c.getNode() == h) {
            n.put("master", true);
            n.put("jvm-vendor", System.getProperty("java.vm.vendor"));
            n.put("jvm-version", System.getProperty("java.version"));
        }
        n.put("executors", c.getNumExecutors());
        DescriptorImpl descriptor = h.getDescriptorByType(DescriptorImpl.class);
        n.put("os", descriptor.get(c));
        nodes.add(n);
    }
    o.put("nodes", nodes);
    List<JSONObject> plugins = new ArrayList<JSONObject>();
    for (PluginWrapper pw : h.getPluginManager().getPlugins()) {
        if (!pw.isActive()) {
            // treat disabled plugins as if they are uninstalled
            continue;
        }
        JSONObject p = new JSONObject();
        p.put("name", pw.getShortName());
        p.put("version", pw.getVersion());
        plugins.add(p);
    }
    o.put("plugins", plugins);
    JSONObject jobs = new JSONObject();
    List<TopLevelItem> items = h.getItems();
    for (TopLevelItemDescriptor d : Items.all()) {
        int cnt = 0;
        for (TopLevelItem item : items) {
            if (item.getDescriptor() == d) {
                cnt++;
            }
        }
        jobs.put(d.getJsonSafeClassName(), cnt);
    }
    o.put("jobs", jobs);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // json -> UTF-8 encode -> gzip -> encrypt -> base64 -> string
        OutputStreamWriter w = new OutputStreamWriter(new GZIPOutputStream(new CombinedCipherOutputStream(baos, getCipher(), "AES")), "UTF-8");
        o.write(w);
        w.close();
        return new String(Base64.encode(baos.toByteArray()));
    } catch (GeneralSecurityException e) {
        // impossible
        throw new Error(e);
    }
}
Also used : DescriptorImpl(hudson.node_monitors.ArchitectureMonitor.DescriptorImpl) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) JSONObject(net.sf.json.JSONObject) GZIPOutputStream(java.util.zip.GZIPOutputStream) PluginWrapper(hudson.PluginWrapper) OutputStreamWriter(java.io.OutputStreamWriter)

Example 13 with PluginWrapper

use of hudson.PluginWrapper in project hudson-2.x by hudson.

the class PluginWrapperFactory method create.

public PluginWrapper create(final File file) throws Exception {
    checkNotNull(file);
    log.trace("Creating plugin wrapper for: {}", file);
    PluginWrapper plugin = delegate.createPluginWrapper(file);
    // Attach the plugin to the class-loader
    PluginClassLoader cl = (PluginClassLoader) plugin.classLoader;
    cl.setPlugin(plugin);
    return plugin;
}
Also used : PluginWrapper(hudson.PluginWrapper)

Example 14 with PluginWrapper

use of hudson.PluginWrapper in project hudson-2.x by hudson.

the class SmoothiePluginStrategy method createPluginWrapper.

/**
     * Load the plugins wrapper and inject it with the {@link SmoothieContainer}.
     */
public PluginWrapper createPluginWrapper(final File archive) throws IOException {
    checkNotNull(archive);
    PluginWrapper plugin;
    try {
        plugin = pluginFactory.create(archive);
    } catch (Exception e) {
        throw new IOException2(e);
    }
    if (log.isDebugEnabled()) {
        logPluginDetails(plugin);
    }
    return plugin;
}
Also used : PluginWrapper(hudson.PluginWrapper) IOException(java.io.IOException) IOException2(hudson.util.IOException2)

Example 15 with PluginWrapper

use of hudson.PluginWrapper in project blueocean-plugin by jenkinsci.

the class BlueI18nTest method test_browser_cacheable.

@Test
public void test_browser_cacheable() {
    PluginWrapper plugin = BlueI18n.getPlugin("git");
    if (plugin == null) {
        // Skip. See waitForPluginLoaded() above.
        return;
    }
    String version = plugin.getVersion();
    Assume.assumeTrue("Test is only valid if git plugin is a suitable probe", version.matches("\"[\\\\d/.]{3,}\""));
    BlueI18n.BundleParams bundleParams = BlueI18n.getBundleParameters(String.format("git/%s/pluginx.bundle", version));
    // Should be cacheable because the installed version matches the requested version + the
    // version is a release version (not a SNAPSHOT version).
    Assert.assertTrue(bundleParams.isBrowserCacheable());
}
Also used : PluginWrapper(hudson.PluginWrapper) Test(org.junit.Test) BaseTest(io.jenkins.blueocean.service.embedded.BaseTest)

Aggregations

PluginWrapper (hudson.PluginWrapper)19 BaseTest (io.jenkins.blueocean.service.embedded.BaseTest)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 File (java.io.File)3 JSONObject (net.sf.json.JSONObject)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CheckForNull (javax.annotation.CheckForNull)2 Jenkins (jenkins.model.Jenkins)2 PluginManager (hudson.PluginManager)1 Initializer (hudson.init.Initializer)1 Node (hudson.model.Node)1 DescriptorImpl (hudson.node_monitors.ArchitectureMonitor.DescriptorImpl)1 IOException2 (hudson.util.IOException2)1 BlueExtensionClassContainer (io.jenkins.blueocean.rest.model.BlueExtensionClassContainer)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1