Skip to content

Commit f459e51

Browse files
committed
Merge branch 'JENKINS-66898' of github.com:mawinter69/pipeline-groovy-lib-plugin into JENKINS-66898
2 parents 197b051 + 773332a commit f459e51

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@
6363
</pluginRepositories>
6464
<properties>
6565
<changelist>999999-SNAPSHOT</changelist>
66-
<jenkins.version>2.303.1</jenkins.version>
66+
<jenkins.version>2.289.1</jenkins.version>
6767
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
6868
</properties>
6969
<dependencyManagement>
7070
<dependencies>
7171
<dependency>
7272
<groupId>io.jenkins.tools.bom</groupId>
73-
<artifactId>bom-2.303.x</artifactId>
73+
<artifactId>bom-2.289.x</artifactId>
7474
<version>1008.vb9e22885c9cf</version>
7575
<scope>import</scope>
7676
<type>pom</type>

src/main/java/org/jenkinsci/plugins/workflow/libs/LibraryAdder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.util.logging.Logger;
5151
import edu.umd.cs.findbugs.annotations.CheckForNull;
5252
import edu.umd.cs.findbugs.annotations.NonNull;
53+
import java.util.regex.Pattern;
5354
import org.apache.commons.io.IOUtils;
5455
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
5556
import org.jenkinsci.plugins.workflow.cps.GlobalVariable;
@@ -377,7 +378,7 @@ private static String readResource(FilePath file, @CheckForNull String encoding)
377378
continue;
378379
}
379380
for (FilePath groovy : root.list("**/*.groovy")) {
380-
String clazz = groovy.getRemote().replaceFirst("^\\Q" + root.getRemote() + "\\E[/\\\\](.+)[.]groovy", "$1").replace('/', '.').replace('\\', '.');
381+
String clazz = className(groovy.getRemote(), root.getRemote());
381382
scripts.put(clazz, groovy.readToString()); // TODO no idea what encoding the Groovy compiler uses
382383
}
383384
}
@@ -390,6 +391,10 @@ private static String readResource(FilePath file, @CheckForNull String encoding)
390391
return scripts;
391392
}
392393

394+
static String className(String groovy, String root) {
395+
return groovy.replaceFirst("^" + Pattern.quote(root) + "[/\\\\](.+)[.]groovy", "$1").replace('/', '.').replace('\\', '.');
396+
}
397+
393398
}
394399

395400
@Extension public static class Copier extends FlowCopier.ByRun {

src/test/java/org/jenkinsci/plugins/workflow/libs/LibraryAdderTest.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@
3131
import hudson.model.queue.QueueTaskFuture;
3232
import hudson.plugins.git.BranchSpec;
3333
import hudson.plugins.git.GitSCM;
34-
import hudson.plugins.git.SubmoduleConfig;
3534
import hudson.plugins.git.UserRemoteConfig;
36-
import hudson.plugins.git.extensions.GitSCMExtension;
37-
import hudson.slaves.WorkspaceList;
38-
import hudson.scm.SubversionSCM;
3935
import hudson.scm.ChangeLogSet;
40-
36+
import hudson.scm.SubversionSCM;
37+
import hudson.slaves.WorkspaceList;
4138
import java.time.ZonedDateTime;
4239
import java.util.Collection;
4340
import java.util.Collections;
@@ -48,25 +45,28 @@
4845
import jenkins.plugins.git.GitSampleRepoRule;
4946
import jenkins.scm.impl.subversion.SubversionSCMSource;
5047
import jenkins.scm.impl.subversion.SubversionSampleRepoRule;
48+
import static org.hamcrest.MatcherAssert.assertThat;
49+
import static org.hamcrest.Matchers.is;
50+
import static org.hamcrest.Matchers.nullValue;
5151
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
5252
import org.jenkinsci.plugins.workflow.cps.GlobalVariable;
5353
import org.jenkinsci.plugins.workflow.cps.global.GrapeTest;
5454
import org.jenkinsci.plugins.workflow.cps.global.UserDefinedGlobalVariable;
5555
import org.jenkinsci.plugins.workflow.cps.replay.ReplayAction;
5656
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
5757
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
58-
import static org.junit.Assert.*;
58+
import static org.junit.Assert.assertEquals;
59+
import static org.junit.Assert.assertNotNull;
5960
import org.junit.ClassRule;
60-
import org.junit.Test;
6161
import org.junit.Rule;
62+
import org.junit.Test;
6263
import org.jvnet.hudson.test.BuildWatcher;
6364
import org.jvnet.hudson.test.Issue;
6465
import org.jvnet.hudson.test.JenkinsRule;
6566
import org.jvnet.hudson.test.TestExtension;
67+
import org.jvnet.hudson.test.WithoutJenkins;
6668
import org.jvnet.hudson.test.recipes.LocalData;
6769

68-
import static org.hamcrest.Matchers.nullValue;
69-
7070
public class LibraryAdderTest {
7171

7272
@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@@ -106,7 +106,7 @@ public class LibraryAdderTest {
106106
new SCMRetriever(
107107
new GitSCM(Collections.singletonList(new UserRemoteConfig(sampleRepo.fileUrl(), null, null, null)),
108108
Collections.singletonList(new BranchSpec("${library.stuff.version}")),
109-
false, Collections.<SubmoduleConfig>emptyList(), null, null, Collections.<GitSCMExtension>emptyList())));
109+
null, null, Collections.emptyList())));
110110
stuff.setDefaultVersion("master");
111111
stuff.setImplicit(true);
112112
GlobalLibraries.get().setLibraries(Collections.singletonList(stuff));
@@ -512,4 +512,13 @@ public void parallelBuildsDontInterfereWithExpiredCache() throws Throwable {
512512
r.assertLogContains("is due for a refresh after", r1);
513513
r.assertLogContains("Library library@master is cached. Copying from home.", r2);
514514
}
515+
516+
@Issue("JENKINS-68544")
517+
@WithoutJenkins
518+
@Test public void className() {
519+
assertThat(LibraryAdder.LoadedLibraries.className("/path/to/lib/src/some/pkg/Type.groovy", "/path/to/lib/src"), is("some.pkg.Type"));
520+
assertThat(LibraryAdder.LoadedLibraries.className("C:\\path\\to\\lib\\src\\some\\pkg\\Type.groovy", "C:\\path\\to\\lib\\src"), is("some.pkg.Type"));
521+
assertThat(LibraryAdder.LoadedLibraries.className("C:\\path\\to\\Extra\\lib\\src\\some\\pkg\\Type.groovy", "C:\\path\\to\\Extra\\lib\\src"), is("some.pkg.Type"));
522+
}
523+
515524
}

0 commit comments

Comments
 (0)