Skip to content

Commit

Permalink
bugfix: NoClassDefFoundError: org/apache/commons/lang3/StringUtils (J…
Browse files Browse the repository at this point in the history
…ENKINS-71123) (#621)
  • Loading branch information
bguerin authored Apr 24, 2023
1 parent f8bef91 commit 6c4d0ce
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.interceptor.RequirePOST;

import static org.apache.commons.lang3.StringUtils.isBlank;

import java.io.IOException;

/**
Expand All @@ -20,7 +18,7 @@ public class NonProductionGradeDatabaseWarningAdministrativeMonitor extends Admi
@Override
public boolean isActivated() {
String jdbcUrl = GlobalPipelineMavenConfig.get().getJdbcUrl();
if (!isBlank(jdbcUrl)) {
if (jdbcUrl != null && !jdbcUrl.trim().isEmpty()) {
return jdbcUrl.startsWith("jdbc:h2:");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.jenkinsci.plugins.pipeline.maven.dao;

import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* This decorator handles the reporting of generated artifacts with custom types which do not match the artifact extension.
Expand All @@ -27,6 +27,8 @@ public class CustomTypePipelineMavenPluginDaoDecorator extends AbstractPipelineM
"javadoc"
);

private final Logger LOGGER = Logger.getLogger(getClass().getName());

public CustomTypePipelineMavenPluginDaoDecorator(@Nonnull PipelineMavenPluginDao delegate) {
super(delegate);
}
Expand All @@ -36,6 +38,7 @@ public void recordGeneratedArtifact(@Nonnull String jobFullName, int buildNumber
super.recordGeneratedArtifact(jobFullName, buildNumber, groupId, artifactId, version, type, baseVersion, repositoryUrl, skipDownstreamTriggers, extension, classifier);

if (shouldReportAgainWithExtensionAsType(type, extension)) {
LOGGER.log(Level.FINE, "Recording generated artifact " + groupId + ":" + artifactId + ":" + version + " as " + extension + " (in addition to " + type + ")");
super.recordGeneratedArtifact(jobFullName, buildNumber, groupId, artifactId, version, extension, baseVersion, repositoryUrl, skipDownstreamTriggers, extension, classifier);
}
}
Expand All @@ -45,7 +48,7 @@ private boolean shouldReportAgainWithExtensionAsType(String type, String extensi
return false;
}

return !StringUtils.equals(type, extension);
return type != null && !type.equals(extension);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package org.jenkinsci.plugins.pipeline.maven;

import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.InboundAgentRule;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.RealJenkinsRule;

import hudson.FilePath;
import hudson.model.Result;
import hudson.model.Slave;
import hudson.tasks.Maven;
import jenkins.model.Jenkins;
import jenkins.mvn.DefaultGlobalSettingsProvider;
import jenkins.mvn.DefaultSettingsProvider;
import jenkins.mvn.GlobalMavenConfig;
import jenkins.plugins.git.GitSampleRepoRule;
import jenkins.scm.impl.mock.GitSampleRepoRuleUtils;

public class WithMavenStepNoOptionalsTest {

@ClassRule
public static InboundAgentRule agentRule = new InboundAgentRule();

@Rule
public GitSampleRepoRule gitRepoRule = new GitSampleRepoRule();

@Rule
public RealJenkinsRule jenkinsRule = new RealJenkinsRule()
.omitPlugins(
"commons-lang3-api", "mysql-api", "postgresql-api", "maven-plugin", "flaky-test-handler",
"htmlpublisher", "jacoco", "jgiven", "junit", "junit-attachments", "matrix-project",
"maven-invoker-plugin", "pipeline-build-step", "findbugs", "tasks");

@Test
public void maven_build_jar_project_on_master_succeeds() throws Throwable {
loadMavenJarProjectInGitRepo(gitRepoRule);

jenkinsRule.then(WithMavenStepNoOptionalsTest::setup, new Build(gitRepoRule.toString()));
}

private static class Build implements RealJenkinsRule.Step {
private final String repoUrl;
Build(String repoUrl) {
this.repoUrl = repoUrl;
}
@Override
public void run(JenkinsRule r) throws Throwable {
String pipelineScript = "node('mock') {\n" +
" git($/" + repoUrl + "/$)\n" +
" withMaven() {\n" +
" sh 'mvn verify -Dmaven.test.failure.ignore=true'\n" +
" }\n" +
"}";

WorkflowJob pipeline = r.createProject(WorkflowJob.class, "build-on-master");
pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
WorkflowRun build = r.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));
r.assertLogContains("BUILD SUCCESS", build);
}
}

private static void setup(final JenkinsRule r) throws Throwable {
Slave agent = agentRule.createAgent(r, "mock");
r.waitOnline(agent);

String mavenVersion = "3.6.3";
FilePath buildDirectory = agent.getRootPath(); // No need of MasterToSlaveCallable because agent is a dumb, thus sharing file system with controller
FilePath mvnHome = buildDirectory.child("apache-maven-" + mavenVersion);
FilePath mvn = buildDirectory.createTempFile("maven", "zip");
mvn.copyFrom(new URL("https://dlcdn.apache.org/maven/maven-3/" + mavenVersion + "/binaries/apache-maven-" + mavenVersion + "-bin.tar.gz"));
mvn.untar(buildDirectory, FilePath.TarCompression.GZIP);
Maven.MavenInstallation mavenInstallation = new Maven.MavenInstallation("default", mvnHome.getRemote(), JenkinsRule.NO_PROPERTIES);
Jenkins.get().getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation);

GlobalMavenConfig globalMavenConfig = r.get(GlobalMavenConfig.class);
globalMavenConfig.setGlobalSettingsProvider(new DefaultGlobalSettingsProvider());
globalMavenConfig.setSettingsProvider(new DefaultSettingsProvider());

List<MavenPublisher> options = new ArrayList<>();
PipelineGraphPublisher graphPublisher = new PipelineGraphPublisher();
graphPublisher.setLifecycleThreshold("package");
options.add(graphPublisher);
GlobalPipelineMavenConfig pipelineConfig = r.get(GlobalPipelineMavenConfig.class);
pipelineConfig.setPublisherOptions(options);
}

private void loadMavenJarProjectInGitRepo(GitSampleRepoRule gitRepo) throws Exception {
gitRepo.init();
Path mavenProjectRoot = Paths
.get(WithMavenStepOnMasterTest.class.getResource("/org/jenkinsci/plugins/pipeline/maven/test/test_maven_projects/maven_jar_project/").toURI());
if (!Files.exists(mavenProjectRoot)) {
throw new IllegalStateException("Folder '" + mavenProjectRoot + "' not found");
}
GitSampleRepoRuleUtils.addFilesAndCommit(mavenProjectRoot, gitRepo);
}

}

0 comments on commit 6c4d0ce

Please sign in to comment.