Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace custom Plugin management code by Plugin Installation Manager #324

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@
<groupId>org.jenkins-ci</groupId>
<artifactId>version-number</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugin-management</groupId>
<artifactId>plugin-management-library</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package io.jenkins.jenkinsfile.runner.bootstrap;

import hudson.util.VersionNumber;
import io.jenkins.tools.pluginmanager.impl.Plugin;
import io.jenkins.tools.pluginmanager.impl.PluginManager;
import io.jenkins.tools.pluginmanager.util.PluginListParser;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.kohsuke.args4j.CmdLineException;
Expand All @@ -20,6 +24,7 @@
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

Expand Down Expand Up @@ -189,18 +194,18 @@ public void postConstruct(CmdLineParser parser) throws IOException {
File plugins_txt = this.pluginsDir;
// This is a plugin list file
this.pluginsDir = Files.createTempDirectory("plugins").toFile();
for (String line : FileUtils.readLines(plugins_txt, UTF_8)) {
String shortname = line;
String version = "latest";

int i = line.indexOf(':');
if (i != -1) {
shortname = line.substring(0,i);
version = line.substring(i+1);
}

installPlugin(shortname, version);
List<Plugin> plugins = new PluginListParser().parsePluginTxtFile(plugins_txt);
if (plugins == null || plugins.isEmpty()) {
// TODO: proper error propagation?
System.err.println("Failed to read plugins from " + plugins_txt);
System.exit(-1);
}

PluginManager pluginManager = Util.initPluginManager(
pluginsDir,
configBuilder -> configBuilder.withPlugins(plugins));
pluginManager.installedPlugins();
}

if (this.runWorkspace != null){
Expand Down Expand Up @@ -279,20 +284,6 @@ private File getJenkinsWar() throws IOException {
return war;
}

private void installPlugin(String shortname, String version) throws IOException {

final File install = new File(pluginsDir, shortname + ".jpi");
File plugin = new File(cache, String.format("plugins/%s/%s-%s.hpi", shortname, shortname, version));
if (!plugin.exists() || ("latest".equals(version) && plugin.lastModified() < CACHE_EXPIRE) ) {
plugin.getParentFile().mkdirs();
final URL url = new URL(getMirrorURL(String.format("http://updates.jenkins.io/download/plugins/%s/%s/%s.hpi", shortname, version, shortname)));
System.out.printf("Downloading jenkins plugin %s (%s)...\n", shortname, version);
FileUtils.copyURLToFile(url, plugin);
}

Files.createSymbolicLink(install.toPath(), plugin.toPath());
}

private String getMirrorURL(String url) {
if (this.mirror == null || "".equals(this.mirror.trim())) {
return url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import edu.umd.cs.findbugs.annotations.NonNull;
import io.jenkins.tools.pluginmanager.config.Config;
import io.jenkins.tools.pluginmanager.impl.PluginManager;


public class Util {

Expand Down Expand Up @@ -46,4 +50,28 @@ public static File explodeWar(String jarPath) throws IOException {
}
return destDir;
}

public interface PluginManagerConfigurator {
void configure(Config.Builder configBuilder);
}

@NonNull
public static PluginManager initPluginManager(File pluginsDir, PluginManagerConfigurator configurator) {
Config.Builder configBuilder = Config.builder()
//.withJenkinsWar(jenkinsWar.getAbsolutePath())
.withPluginDir(pluginsDir)
.withShowAvailableUpdates(true)
.withIsVerbose(true)
.withDoDownload(false);
configurator.configure(configBuilder);
Config config = configBuilder.build();

PluginManager pluginManager = new PluginManager(config);
//pluginManager.setCm(new CacheManager(cacheDir.toPath(), true));
//pluginManager.setJenkinsVersion(new VersionNumber("2.222.1"));
//pluginManager.setLatestUcJson(latestUcJson);
//pluginManager.setLatestUcPlugins(latestUcJson.getJSONObject("plugins"));
//pluginManager.setPluginInfoJson(pluginManager.getJson(pluginVersionsFile.toURI().toURL(), "plugin-versions"));
return pluginManager;
}
}
4 changes: 2 additions & 2 deletions packaging/docker/unix/debian-jdk8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ RUN mkdir /app && unzip /jenkinsfile-runner/vanilla-package/target/war/jenkins.w
FROM openjdk:8-jdk
ENV JENKINS_UC https://updates.jenkins.io
ENV CASC_JENKINS_CONFIG /usr/share/jenkins/ref/casc
ENV JENKINS_PM_VERSION 0.1-alpha-10
ENV JENKINS_PM_URL https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/plugin-management-parent-pom-$JENKINS_PM_VERSION/jenkins-plugin-manager-$JENKINS_PM_VERSION.jar
ENV JENKINS_PM_VERSION 1.1.2
ENV JENKINS_PM_URL https://repo.jenkins-ci.org/releases/io/jenkins/plugin-management/plugin-management-cli/${PLUGIN_MANAGER_TOOL_VERSION}/plugin-management-cli-${JENKINS_PM_VERSION}.jar -O tmp/jenkins-plugin-manager-${JENKINS_PM_VERSION}.jar
USER root
RUN mkdir -p /app /usr/share/jenkins/ref/plugins /usr/share/jenkins/ref/casc /app/bin \
&& echo "jenkins: {}" >/usr/share/jenkins/ref/casc/jenkins.yaml \
Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ THE SOFTWARE.
<jetty.version>9.4.30.v20200611</jetty.version>
<!--TODO: Reenable once all the issues are fixed (JENKINS-57353)-->
<findbugs.failOnError>false</findbugs.failOnError>
<!-- https://github.com/jenkinsci/plugin-installation-manager-tool -->
<plugin.installation.manager.version>1.1.2</plugin.installation.manager.version>
</properties>

<dependencyManagement>
Expand All @@ -89,6 +91,12 @@ THE SOFTWARE.
<artifactId>support-log-formatter</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>io.jenkins.plugin-management</groupId>
<artifactId>plugin-management-library</artifactId>
<version>1.1.2</version>
</dependency>

<!-- TODO(oleg-nenashev): Remove after 2.238: https://github.com/jenkinsci/jenkins/pull/4702 -->
<dependency>
<groupId>commons-collections</groupId>
Expand Down