From 8e98a0dfdbcf7da78e3dd4a865dbc51fb838292a Mon Sep 17 00:00:00 2001 From: Maxim Lukyanenko Date: Wed, 11 May 2022 21:26:23 +0300 Subject: [PATCH] v2022-06 compatibility --- .vscode/settings.json | 5 + io.takari.m2e.jenkins.feature/feature.xml | 1 + .../.settings/org.eclipse.jdt.core.prefs | 37 ++- .../META-INF/MANIFEST.MF | 8 +- .../m2e/jenkins/internal/JenkinsBuilder.java | 2 +- .../JenkinsLocalizerProjectConfigurator.java | 2 +- .../internal/JenkinsProjectConfigurator.java | 2 +- .../JenkinsLaunchConfigurationDelegate.java | 41 +++- .../internal/launch/LaunchShortcutAction.java | 2 +- .../jenkins/internal/ui/JenkinsMainTab.java | 2 +- .../jenkins/{ => plugin}/IJenkinsPlugin.java | 2 +- .../{ => plugin}/JenkinsPluginArtifact.java | 2 +- .../{ => plugin}/JenkinsPluginProject.java | 2 +- .../PluginDependenciesCalculator.java | 2 +- .../{ => plugin}/PluginDependency.java | 2 +- .../jenkins/{ => plugin}/PluginUpdates.java | 2 +- pom.xml | 78 ++++-- .../.settings/org.eclipse.jdt.core.prefs | 9 +- runtime/io.takari.m2e.jenkins.runtime/pom.xml | 8 +- .../.settings/org.eclipse.jdt.core.prefs | 9 +- runtime/launcher/pom.xml | 33 ++- .../io/takari/m2e/jenkins/launcher/Main.java | 117 ++++++++- .../launcher/log/PackagingDataCalculator.java | 2 +- .../java/io/takari/reflect/Reflection.java | 8 + runtime/pom.xml | 222 +++++++++++------- 25 files changed, 448 insertions(+), 152 deletions(-) create mode 100644 .vscode/settings.json rename io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/{ => plugin}/IJenkinsPlugin.java (89%) rename io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/{ => plugin}/JenkinsPluginArtifact.java (93%) rename io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/{ => plugin}/JenkinsPluginProject.java (97%) rename io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/{ => plugin}/PluginDependenciesCalculator.java (99%) rename io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/{ => plugin}/PluginDependency.java (91%) rename io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/{ => plugin}/PluginUpdates.java (92%) create mode 100644 runtime/launcher/src/main/java/io/takari/reflect/Reflection.java diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..acbde89 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic", + "java.configuration.maven.userSettings": "~/.m2/settings-plugins.xml", + "maven.view": "hierarchical" +} \ No newline at end of file diff --git a/io.takari.m2e.jenkins.feature/feature.xml b/io.takari.m2e.jenkins.feature/feature.xml index 964a5ab..e7b9fb8 100644 --- a/io.takari.m2e.jenkins.feature/feature.xml +++ b/io.takari.m2e.jenkins.feature/feature.xml @@ -14,6 +14,7 @@ + getRuntimeClasspath() { if (CLASSPATH == null) { LinkedHashSet allentries = new LinkedHashSet(); - Bundle runtimeBundle = Bundles.findDependencyBundle(JenkinsPlugin.getInstance().getBundle(), - RUNTIME_BUNDLE_SYMBOLICNAME); + Bundle runtimeBundle = findDependencyBundle(JenkinsPlugin.getInstance().getBundle(), + RUNTIME_BUNDLE_SYMBOLICNAME, new HashSet<>()); allentries.addAll(Bundles.getClasspathEntries(runtimeBundle)); CLASSPATH = new ArrayList<>(allentries); } return CLASSPATH; } + private static Bundle findDependencyBundle(Bundle bundle, String dependencyName, Set visited) { + BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); + if (bundleWiring == null) { + return null; + } + ArrayList dependencies = new ArrayList(); + dependencies.addAll(bundleWiring.getRequiredWires(BundleNamespace.BUNDLE_NAMESPACE)); + dependencies.addAll(bundleWiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE)); + for (BundleWire wire : dependencies) { + Bundle requiredBundle = wire.getProviderWiring().getBundle(); + if (requiredBundle != null && visited.add(requiredBundle)) { + if (dependencyName.equals(requiredBundle.getSymbolicName())) { + return requiredBundle; + } + Bundle required = findDependencyBundle(requiredBundle, dependencyName, visited); + if (required != null) { + return required; + } + } + } + return null; + } + private Descriptor createDescriptor(JenkinsLaunchConfig config, IProgressMonitor monitor) throws CoreException { // locate all used plugins' hpl files, those should have been generated by // test-hpl mojo diff --git a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/internal/launch/LaunchShortcutAction.java b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/internal/launch/LaunchShortcutAction.java index f6a7122..2c6f126 100644 --- a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/internal/launch/LaunchShortcutAction.java +++ b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/internal/launch/LaunchShortcutAction.java @@ -22,8 +22,8 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IEditorPart; -import io.takari.m2e.jenkins.JenkinsPluginProject; import io.takari.m2e.jenkins.internal.JenkinsPlugin; +import io.takari.m2e.jenkins.plugin.JenkinsPluginProject; public class LaunchShortcutAction implements ILaunchShortcut { diff --git a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/internal/ui/JenkinsMainTab.java b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/internal/ui/JenkinsMainTab.java index 4cb0c14..207c771 100644 --- a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/internal/ui/JenkinsMainTab.java +++ b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/internal/ui/JenkinsMainTab.java @@ -41,7 +41,6 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.ui.dialogs.ContainerSelectionDialog; -import io.takari.m2e.jenkins.JenkinsPluginProject; import io.takari.m2e.jenkins.internal.JenkinsPlugin; import io.takari.m2e.jenkins.internal.launch.JenkinsLaunchConfig; import io.takari.m2e.jenkins.internal.launch.LaunchingUtils; @@ -49,6 +48,7 @@ import io.takari.m2e.jenkins.internal.ui.databinding.IntegerValidator; import io.takari.m2e.jenkins.internal.ui.databinding.SetSelectionObservable; import io.takari.m2e.jenkins.internal.ui.databinding.StringToIntegerConverter; +import io.takari.m2e.jenkins.plugin.JenkinsPluginProject; public class JenkinsMainTab extends JavaLaunchTab { diff --git a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/IJenkinsPlugin.java b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/IJenkinsPlugin.java similarity index 89% rename from io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/IJenkinsPlugin.java rename to io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/IJenkinsPlugin.java index ee97925..596bfed 100644 --- a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/IJenkinsPlugin.java +++ b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/IJenkinsPlugin.java @@ -1,4 +1,4 @@ -package io.takari.m2e.jenkins; +package io.takari.m2e.jenkins.plugin; import java.io.File; import java.util.List; diff --git a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/JenkinsPluginArtifact.java b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/JenkinsPluginArtifact.java similarity index 93% rename from io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/JenkinsPluginArtifact.java rename to io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/JenkinsPluginArtifact.java index 84e04b2..eca0ecb 100644 --- a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/JenkinsPluginArtifact.java +++ b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/JenkinsPluginArtifact.java @@ -1,4 +1,4 @@ -package io.takari.m2e.jenkins; +package io.takari.m2e.jenkins.plugin; import java.io.File; import java.util.Collections; diff --git a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/JenkinsPluginProject.java b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/JenkinsPluginProject.java similarity index 97% rename from io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/JenkinsPluginProject.java rename to io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/JenkinsPluginProject.java index 1714696..4430401 100644 --- a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/JenkinsPluginProject.java +++ b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/JenkinsPluginProject.java @@ -1,4 +1,4 @@ -package io.takari.m2e.jenkins; +package io.takari.m2e.jenkins.plugin; import java.io.File; import java.io.FileOutputStream; diff --git a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/PluginDependenciesCalculator.java b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/PluginDependenciesCalculator.java similarity index 99% rename from io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/PluginDependenciesCalculator.java rename to io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/PluginDependenciesCalculator.java index 347250a..080c019 100644 --- a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/PluginDependenciesCalculator.java +++ b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/PluginDependenciesCalculator.java @@ -1,4 +1,4 @@ -package io.takari.m2e.jenkins; +package io.takari.m2e.jenkins.plugin; import java.io.File; import java.io.IOException; diff --git a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/PluginDependency.java b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/PluginDependency.java similarity index 91% rename from io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/PluginDependency.java rename to io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/PluginDependency.java index dd9bfec..99b571e 100644 --- a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/PluginDependency.java +++ b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/PluginDependency.java @@ -1,4 +1,4 @@ -package io.takari.m2e.jenkins; +package io.takari.m2e.jenkins.plugin; public class PluginDependency { private IJenkinsPlugin plugin; diff --git a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/PluginUpdates.java b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/PluginUpdates.java similarity index 92% rename from io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/PluginUpdates.java rename to io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/PluginUpdates.java index 740a6b0..32f09f8 100644 --- a/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/PluginUpdates.java +++ b/io.takari.m2e.jenkins.plugin/src/main/java/io/takari/m2e/jenkins/plugin/PluginUpdates.java @@ -1,4 +1,4 @@ -package io.takari.m2e.jenkins; +package io.takari.m2e.jenkins.plugin; import io.takari.m2e.jenkins.runtime.PluginUpdateCenter; diff --git a/pom.xml b/pom.xml index 907e539..c78b07d 100644 --- a/pom.xml +++ b/pom.xml @@ -14,12 +14,14 @@ pom + UTF-8 + UTF-8 jenkins-dev Jenkins Plugin Development Environment - http://download.eclipse.org/releases/photon - https://repo1.maven.org/maven2/.m2e/connectors/m2e/1.10.0/N/LATEST/ - 3.0.1 + https://download.eclipse.org/releases/2022-06/ + https://download.eclipse.org/technology/m2e/releases/1.20.1/ + 2.7.3 @@ -43,7 +45,7 @@ m2e-takari p2 - http://takari.github.io/m2e-jenkins/repo/ + https://takari.github.io/io.takari.m2e.lifecycle/repo/ @@ -72,16 +74,6 @@ - - - - - org.apache.felix - maven-bundle-plugin - ${maven-bundle-plugin.version} - - - @@ -97,6 +89,64 @@ runtime + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.eclipse.tycho + target-platform-configuration + [2.7.3,) + + target-platform + + + + + + + + + + org.eclipse.tycho + tycho-ds-plugin + [2.7.3,) + + declarative-services + + + + + + + + + + org.eclipse.tycho + tycho-compiler-plugin + [2.7.3,) + + validate-classpath + + + + + + + + + + + + + diff --git a/runtime/io.takari.m2e.jenkins.runtime/.settings/org.eclipse.jdt.core.prefs b/runtime/io.takari.m2e.jenkins.runtime/.settings/org.eclipse.jdt.core.prefs index 25a6db9..9227441 100644 --- a/runtime/io.takari.m2e.jenkins.runtime/.settings/org.eclipse.jdt.core.prefs +++ b/runtime/io.takari.m2e.jenkins.runtime/.settings/org.eclipse.jdt.core.prefs @@ -1,17 +1,20 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=9 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.compliance=9 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=disabled org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=9 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 diff --git a/runtime/io.takari.m2e.jenkins.runtime/pom.xml b/runtime/io.takari.m2e.jenkins.runtime/pom.xml index a328d6a..45c182f 100644 --- a/runtime/io.takari.m2e.jenkins.runtime/pom.xml +++ b/runtime/io.takari.m2e.jenkins.runtime/pom.xml @@ -27,17 +27,17 @@ net.java.sezpoz sezpoz - 1.9 + 1.13 com.fasterxml.jackson.core jackson-core - 2.7.3 + 2.13.2 com.fasterxml.jackson.core jackson-databind - 2.7.3 + 2.13.2.2 org.apache.maven @@ -59,6 +59,7 @@ maven-bundle-plugin + ${osgi.execution.runtime} *;scope=compile|runtime @@ -87,6 +88,7 @@ org.eclipse.tycho tycho-p2-plugin + ${tychoVersion} diff --git a/runtime/launcher/.settings/org.eclipse.jdt.core.prefs b/runtime/launcher/.settings/org.eclipse.jdt.core.prefs index 25a6db9..9227441 100644 --- a/runtime/launcher/.settings/org.eclipse.jdt.core.prefs +++ b/runtime/launcher/.settings/org.eclipse.jdt.core.prefs @@ -1,17 +1,20 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=9 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.compliance=9 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=disabled org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=9 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 diff --git a/runtime/launcher/pom.xml b/runtime/launcher/pom.xml index 2f42b3b..cf39bae 100644 --- a/runtime/launcher/pom.xml +++ b/runtime/launcher/pom.xml @@ -13,7 +13,8 @@ jar - 9.2.15.v20160210 + + 9.4.46.v20220331 @@ -30,10 +31,31 @@ + + com.sun.xml.bind + jaxb-core + 2.3.0.1 + + + javax.xml.bind + jaxb-api + 2.3.1 + + + com.sun.xml.bind + jaxb-impl + 2.3.1 + + + org.javassist + javassist + 3.25.0-GA + + commons-io commons-io - 2.4 + 2.11.0 org.eclipse.jetty @@ -116,7 +138,7 @@ ch.qos.logback logback-classic - 1.1.3 + 1.2.11 org.slf4j @@ -134,6 +156,11 @@ 1.7.12 + + com.sun.activation + javax.activation + 1.2.0 + diff --git a/runtime/launcher/src/main/java/io/takari/m2e/jenkins/launcher/Main.java b/runtime/launcher/src/main/java/io/takari/m2e/jenkins/launcher/Main.java index 93f055c..20226e3 100644 --- a/runtime/launcher/src/main/java/io/takari/m2e/jenkins/launcher/Main.java +++ b/runtime/launcher/src/main/java/io/takari/m2e/jenkins/launcher/Main.java @@ -1,11 +1,19 @@ package io.takari.m2e.jenkins.launcher; +import static java.util.Objects.isNull; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Field; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Properties; import java.util.UUID; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -33,6 +41,7 @@ import io.takari.m2e.jenkins.launcher.desc.Descriptor; import io.takari.m2e.jenkins.launcher.desc.PluginDesc; import io.takari.m2e.jenkins.launcher.log.JettyLogWrapper; +import sun.misc.Unsafe; public class Main { @@ -58,6 +67,8 @@ public static void main(String[] args) throws Exception { return; } + dumpAppRuntime(args); + String descLocation = args[0]; Descriptor desc = Descriptor.read(new File(descLocation)); @@ -150,14 +161,83 @@ public static void main(String[] args) throws Exception { setSystemPropertyIfEmpty("stapler.resourcePath", res.toString()); } - runServer(desc, tmpDir); + runServer(desc, tmpDir, workDir); + } + + private static void dumpAppRuntime(String[] args) { + log.info("launcher.jar {}", args == null ? "" : String.join(" ", args)); + + log.info("Java home: {}", System.getProperty("java.home")); + log.info("Java version: {} - {}", System.getProperty("java.runtime.name"), System.getProperty("java.version")); + + try { + ModuleLayer.boot().modules().stream().map(m -> m.getClassLoader()).collect(Collectors.toSet()).stream() + .forEach(c -> dumpModules(c)); + + dumpJarsUrls(ClassLoader.getPlatformClassLoader()); + dumpJarsUrls(ClassLoader.getSystemClassLoader()); + + } catch (Throwable t) { + log.error("Dump of runtime failed", t); + throw new IllegalStateException(t); + } + } + + + private static void dumpJarsUrls(ClassLoader cl) { + URL[] urls = getUrls(cl); + String res = urls == null ? "" + : Arrays.asList(urls).stream().map(m -> m.toExternalForm()).collect(Collectors.joining(", ")); + log.info("Classloader urls: {}\n{}", toName(cl), res); + } + + @SuppressWarnings({ "unchecked" }) + public static URL[] getUrls(ClassLoader classLoader) { + if (classLoader instanceof URLClassLoader) { + return ((URLClassLoader) classLoader).getURLs(); + } + + // jdk9 + if (classLoader.getClass().getName().startsWith("jdk.internal.loader.ClassLoaders$")) { + try { + Field field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + Unsafe unsafe = (Unsafe) field.get(null); + + // jdk.internal.loader.ClassLoaders.AppClassLoader.ucp + Field ucpField = classLoader.getClass().getDeclaredField("ucp"); + long ucpFieldOffset = unsafe.objectFieldOffset(ucpField); + Object ucpObject = unsafe.getObject(classLoader, ucpFieldOffset); + + // jdk.internal.loader.URLClassPath.path + Field pathField = ucpField.getType().getDeclaredField("path"); + long pathFieldOffset = unsafe.objectFieldOffset(pathField); + ArrayList path = (ArrayList) unsafe.getObject(ucpObject, pathFieldOffset); + + return path.toArray(new URL[path.size()]); + } catch (NoSuchFieldException unimportant) { + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + return null; + } + + private static void dumpModules(ClassLoader classLoader) { + log.info("Classloader: {}\n{}", toName(classLoader), ModuleLayer.boot().modules().stream() + .filter(m -> classLoader == m.getClassLoader()).map(m -> m.getName()).collect(Collectors.joining(", "))); + } + + private static String toName(ClassLoader classloder) { + return isNull(classloder) ? "bootstrap" : classloder.getName(); } private static void writeVersion(File file, String version) throws IOException { FileUtils.write(file, version); } - private static void runServer(Descriptor desc, File tmpDir) throws Exception { + private static void runServer(Descriptor desc, File tmpDir, File workDir) throws Exception { Resource.setDefaultUseCaches(false); Server server = new Server(); @@ -200,12 +280,13 @@ private static void runServer(Descriptor desc, File tmpDir) throws Exception { WebAppContext webapp = new WebAppContext(); webapp.setContextPath(desc.getContext()); contexts.addHandler(webapp); - configureWebApplication(webapp, desc, tmpDir); + configureWebApplication(webapp, desc, tmpDir, workDir); server.start(); server.join(); } - private static void configureWebApplication(WebAppContext webapp, Descriptor desc, File tmpDir) throws Exception { + private static void configureWebApplication(WebAppContext webapp, Descriptor desc, + File tmpDir, File workDir) throws Exception { File webAppFile = new File(desc.getJenkinsWar()); webapp.setWar(webAppFile.getCanonicalPath()); @@ -218,8 +299,10 @@ private static void configureWebApplication(WebAppContext webapp, Descriptor des } // cf. https://wiki.jenkins-ci.org/display/JENKINS/Jetty + String realmConfig = provideDefaultRealmConfig(workDir); HashLoginService hashLoginService = (new HashLoginService("Jenkins Realm")); - hashLoginService.setConfig("work/etc/realm.properties"); + hashLoginService.setConfig(realmConfig); + webapp.getSecurityHandler().setLoginService(hashLoginService); webapp.setAttribute("org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern", ".*/classes/.*"); @@ -227,7 +310,7 @@ private static void configureWebApplication(WebAppContext webapp, Descriptor des // different port, // use different session cookie names. Otherwise they can mix up. See // http://stackoverflow.com/questions/1612177/are-http-cookies-port-specific - webapp.getSessionHandler().getSessionManager().getSessionCookieConfig() + webapp.getSessionHandler().getSessionCookieConfig() .setName("JSESSIONID." + UUID.randomUUID().toString().replace("-", "").substring(0, 8)); try { @@ -235,13 +318,33 @@ private static void configureWebApplication(WebAppContext webapp, Descriptor des // target/classes // via classloader magic WebAppClassLoader wacl = new WebAppClassLoader( - new JettyAndServletApiOnlyClassLoader(null, Main.class.getClassLoader()), webapp); + new JettyAndServletApiOnlyClassLoader(ClassLoader.getPlatformClassLoader(), + ClassLoader.getSystemClassLoader()), + webapp); webapp.setClassLoader(wacl); } catch (IOException e) { throw new Error(e); } } + private static String provideDefaultRealmConfig(File workDir) throws IOException { + String jenkinsEtc = "work/etc/"; + String realmConfig = jenkinsEtc + "realm.properties"; + + File fileRealmConfig = new File(workDir, realmConfig); + if (!fileRealmConfig.exists()) { + File dirJenkinsEtc = new File(workDir, jenkinsEtc); + if (!dirJenkinsEtc.exists()) { + dirJenkinsEtc.mkdirs(); + log.info("Work dir created: {}", workDir); + } + fileRealmConfig.createNewFile(); + log.info("New empty realm config created: {}", fileRealmConfig); + } + + return realmConfig; + } + private static final String VERSION_PATH = "META-INF/maven/org.jenkins-ci.main/jenkins-war/pom.properties"; private static final String VERSION_PROP = "version"; diff --git a/runtime/launcher/src/main/java/io/takari/m2e/jenkins/launcher/log/PackagingDataCalculator.java b/runtime/launcher/src/main/java/io/takari/m2e/jenkins/launcher/log/PackagingDataCalculator.java index 66a3c27..b99a14e 100644 --- a/runtime/launcher/src/main/java/io/takari/m2e/jenkins/launcher/log/PackagingDataCalculator.java +++ b/runtime/launcher/src/main/java/io/takari/m2e/jenkins/launcher/log/PackagingDataCalculator.java @@ -11,7 +11,7 @@ import ch.qos.logback.classic.spi.ClassPackagingData; import ch.qos.logback.classic.spi.IThrowableProxy; import ch.qos.logback.classic.spi.StackTraceElementProxy; -import sun.reflect.Reflection; +import io.takari.reflect.Reflection; @SuppressWarnings({ "rawtypes", "restriction" }) public class PackagingDataCalculator { diff --git a/runtime/launcher/src/main/java/io/takari/reflect/Reflection.java b/runtime/launcher/src/main/java/io/takari/reflect/Reflection.java new file mode 100644 index 0000000..9d59f21 --- /dev/null +++ b/runtime/launcher/src/main/java/io/takari/reflect/Reflection.java @@ -0,0 +1,8 @@ +package io.takari.reflect; + +public class Reflection { + public static Class getCallerClass(int n){ + StackTraceElement[] elements = new Throwable().getStackTrace(); + return elements[n].getClass() ; + } +} \ No newline at end of file diff --git a/runtime/pom.xml b/runtime/pom.xml index 0a609ec..a2fcd10 100644 --- a/runtime/pom.xml +++ b/runtime/pom.xml @@ -1,92 +1,132 @@ - - - 4.0.0 - - io.takari.m2e.jenkins - runtime - 0.2.0-SNAPSHOT - pom - - - yyyyMMdd-HHmm - ${maven.build.timestamp} - 3.0.1 - - - - launcher - io.takari.m2e.jenkins.runtime - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - - - - org.apache.felix - maven-bundle-plugin - ${maven-bundle-plugin.version} - true - - - true - <_failok>true - <_nouses>true - <_nodefaultversion>true - <_snapshot>${osgi-version-qualifier} - - ${project.artifactId};singleton:=true - lazy - JavaSE-1.7,JavaSE-1.8 - %Bundle-Name - %Bundle-Vendor - {maven-dependencies} - dir - - - false - - - - - - - - - - m2e - - - m2e.version - - - - qualifier - - - - - - org.apache.felix - maven-bundle-plugin - - - META-INF - - - - - - - + + + 4.0.0 + + io.takari.m2e.jenkins + runtime + 0.2.0-SNAPSHOT + pom + + + UTF-8 + UTF-8 + yyyyMMdd-HHmm + ${maven.build.timestamp} + 5.1.6 + JavaSE-9 + 9 + 9 + 2.7.3 + 2.0.7 + + + + launcher + io.takari.m2e.jenkins.runtime + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + ${maven.compiler.source} + ${maven.compiler.target} + + + + org.apache.felix + maven-bundle-plugin + ${maven-bundle-plugin.version} + true + + + true + <_failok>true + <_nouses>true + <_nodefaultversion>true + <_snapshot>${osgi-version-qualifier} + + ${project.artifactId};singleton:=true + lazy + JavaSE-1.8 + %Bundle-Name + %Bundle-Vendor + {maven-dependencies} + dir + + + false + + + + + + + + + + m2e + + + m2e.version + + + + qualifier + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.felix + maven-bundle-plugin + [5.1.6,) + + manifest + bundle + + + + + true + + + true + + + + + + + + + + org.apache.felix + maven-bundle-plugin + ${maven-bundle-plugin.version} + + + META-INF + false + + + + + + + + \ No newline at end of file