[MPMD-304] - maven-pmd-plugin should be toolchains-aware · apache/maven-pmd-plugin@f39c001 (original) (raw)

``

1

`+

/*

`

``

2

`+

`

``

3

`+

`

``

4

`+

`

``

5

`+

`

``

6

`+

`

``

7

`+

`

``

8

`+

`

``

9

`+

`

``

10

`+

`

``

11

`+

`

``

12

`+

`

``

13

`+

`

``

14

`+

`

``

15

`+

`

``

16

`+

`

``

17

`+

`

``

18

`+

*/

`

``

19

+

``

20

`+

File testToolchains = new File( basedir, 'toolchains.xml' )

`

``

21

+

``

22

`+

File userToolchains = new File( System.getProperty( 'user.home' ), '.m2/toolchains.xml' )

`

``

23

`+

if ( userToolchains.exists() )

`

``

24

`+

{

`

``

25

`+

System.out.println( "INFO: Copying userToolchains.absolutePathto{userToolchains.absolutePath} to userToolchains.absolutePathto{testToolchains.absolutePath}" )

`

``

26

`+

testToolchains.text = userToolchains.text

`

``

27

`+

}

`

``

28

`+

else

`

``

29

`+

{

`

``

30

`+

System.out.println( "WARNING: File ${userToolchains.absolutePath} not found" )

`

``

31

`+

if ( System.getProperty( 'os.name' ).startsWith( 'Windows' ) )

`

``

32

`+

{

`

``

33

`+

String jdk11Windows = 'f:\jenkins\tools\java\latest11'

`

``

34

`+

File windowsToolchains = new File( basedir, 'toolchains.windows.xml' )

`

``

35

`+

System.out.println( "INFO: Creating testToolchains.absolutePathwithjdk:11:oracle={testToolchains.absolutePath} with jdk:11:oracle=testToolchains.absolutePathwithjdk:11:oracle={jdk11Windows}" )

`

``

36

+

``

37

`+

String placeholder = '@jdk.home@'

`

``

38

`+

String replacement = jdk11Windows

`

``

39

`+

// extra escaping of backslashes in the path for Windows

`

``

40

`+

replacement = replacement.replaceAll("\\", "\\\\")

`

``

41

`+

testToolchains.text = windowsToolchains.text.replaceAll( placeholder, replacement )

`

``

42

`+

System.out.println( "Replaced '${placeholder}' with '${replacement}' in '${testToolchains.absolutePath}'." )

`

``

43

`+

}

`

``

44

`+

}

`

``

45

+

``

46

`+

if ( testToolchains.exists() )

`

``

47

`+

{

`

``

48

`+

def toolchains = new XmlParser().parseText( testToolchains.text )

`

``

49

`+

def result = toolchains.children().find { toolchain ->

`

``

50

`+

toolchain.type.text() == 'jdk' &&

`

``

51

`+

toolchain.provides.version.text() == '11' &&

`

``

52

`+

toolchain.provides.vendor.text() == 'oracle'

`

``

53

`+

}

`

``

54

`+

if ( !result )

`

``

55

`+

{

`

``

56

`+

System.out.println( "WARNING: No jdk toolchain for 11:oracle found" )

`

``

57

`+

return false

`

``

58

`+

}

`

``

59

+

``

60

`+

System.out.println( "INFO: Found toolchain: ${result}" )

`

``

61

`+

return true

`

``

62

`+

}

`

``

63

+

``

64

`+

System.out.println( "WARNING: Skipping integration test due to missing toolchain" )

`

``

65

`+

return false

`