├── .github ├── dependabot.yml ├── release-drafter.yml └── workflows │ └── release-drafter.yml ├── .gitignore ├── CHANGELOG.md ├── Jenkinsfile ├── LICENSE ├── README.md ├── pom.xml └── src ├── main └── java │ └── hudson │ └── maven │ ├── MavenEmbedder.java │ ├── MavenEmbedderCallable.java │ ├── MavenEmbedderException.java │ ├── MavenEmbedderUtils.java │ ├── MavenInformation.java │ ├── MavenRequest.java │ └── ReactorReader.java └── test ├── java └── hudson │ └── maven │ ├── TestMavenEmbedderSimpleProject.java │ ├── TestMavenEmbedderSimpleProjectWithParent.java │ ├── TestMavenEmbedderUtils.java │ ├── TestMavenModules.java │ └── TestMavenProjectBuildWrong.java ├── maven-2.2.1 ├── LICENSE.txt ├── NOTICE.txt └── lib │ └── maven-2.2.1-uber.jar ├── projects-tests ├── eclipse-plugin-with-parent │ ├── child │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── mycompany │ │ │ │ └── app │ │ │ │ └── App.java │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── mycompany │ │ │ └── app │ │ │ └── AppTest.java │ └── parent │ │ └── pom.xml ├── eclipse-plugin │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── mycompany │ │ │ └── app │ │ │ └── App.java │ │ └── test │ │ └── java │ │ └── com │ │ └── mycompany │ │ └── app │ │ └── AppTest.java ├── incorrect-inheritence-testcase │ ├── pom.xml │ └── subdir │ │ └── mod1 │ │ └── pom.xml ├── one-module-with-parent │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── mycompany │ │ │ └── app │ │ │ └── App.java │ │ └── test │ │ └── java │ │ └── com │ │ └── mycompany │ │ └── app │ │ └── AppTest.java ├── one-module │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── mycompany │ │ │ └── app │ │ │ └── App.java │ │ └── test │ │ └── java │ │ └── com │ │ └── mycompany │ │ └── app │ │ └── AppTest.java ├── several-modules-in-directory │ ├── module.xml │ └── pom.xml └── test-pom-8395.xml └── resources └── log4j2-test.xml /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "maven" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | - package-ecosystem: "github-actions" 8 | directory: "/" 9 | schedule: 10 | interval: "weekly" 11 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | _extends: .github 2 | tag-template: lib-jenkins-maven-embedder-$NEXT_MINOR_VERSION 3 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | update_release_draft: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: release-drafter/release-drafter@v6.0.0 11 | env: 12 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### JetBrains template 2 | .idea/ 3 | *.iml 4 | *.iws 5 | 6 | ## Plugin-specific files: 7 | 8 | # IntelliJ 9 | /out/ 10 | 11 | # mpeltonen/sbt-idea plugin 12 | .idea_modules/ 13 | 14 | # JIRA plugin 15 | atlassian-ide-plugin.xml 16 | 17 | # Crashlytics plugin (for Android Studio and IntelliJ) 18 | com_crashlytics_export_strings.xml 19 | crashlytics.properties 20 | crashlytics-build.properties 21 | fabric.properties 22 | 23 | ### Maven template 24 | target/ 25 | pom.xml.tag 26 | pom.xml.versionsBackup 27 | pom.xml.next 28 | dependency-reduced-pom.xml 29 | buildNumber.properties 30 | .mvn/timing.properties 31 | pom.xml.releaseBackup 32 | release.properties 33 | 34 | # Exclude maven wrapper 35 | !/.mvn/wrapper/maven-wrapper.jar 36 | 37 | ### Java template 38 | *.class 39 | 40 | # Log file 41 | *.log 42 | 43 | # BlueJ files 44 | *.ctxt 45 | 46 | # Mobile Tools for Java (J2ME) 47 | .mtj.tmp/ 48 | 49 | # Package Files # 50 | *.jar 51 | *.war 52 | *.ear 53 | *.zip 54 | *.tar.gz 55 | *.rar 56 | 57 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 58 | hs_err_pid* 59 | 60 | ### Eclipse template 61 | 62 | .metadata 63 | bin/ 64 | tmp/ 65 | *.tmp 66 | *.bak 67 | *.swp 68 | *~.nib 69 | local.properties 70 | .settings/ 71 | .loadpath 72 | .recommenders 73 | 74 | # Eclipse Core 75 | 76 | # External tool builders 77 | .externalToolBuilders/ 78 | 79 | # Locally stored "Eclipse launch configurations" 80 | *.launch 81 | 82 | # PyDev specific (Python IDE for Eclipse) 83 | *.pydevproject 84 | 85 | # CDT-specific (C/C++ Development Tooling) 86 | .cproject 87 | 88 | # JDT-specific (Eclipse Java Development Tools) 89 | 90 | # Java annotation processor (APT) 91 | .factorypath 92 | 93 | # PDT-specific (PHP Development Tools) 94 | .buildpath 95 | 96 | # sbteclipse plugin 97 | .target 98 | 99 | # Tern plugin 100 | .tern-project 101 | 102 | # TeXlipse plugin 103 | .texlipse 104 | 105 | # STS (Spring Tool Suite) 106 | .springBeans 107 | 108 | # Code Recommenders 109 | .recommenders/ 110 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Changelog 2 | === 3 | 4 | ### 3.15 5 | 6 | Release date: Apr 8, 2020 7 | 8 | * update plexus-cipher to 1.8 9 | * fix build to get it working with Java11 10 | 11 | ### 3.14 12 | 13 | Release date: Jun 12, 2019 14 | 15 | * [JENKINS-54530](https://issues.jenkins-ci.org/browse/JENKINS-54530) Upgrade maven embedder from 3.1.0 to at least 3.5.4 16 | 17 | ### 3.12.1 18 | 19 | Release date: Jul 06, 2017 20 | 21 | * [JENKINS-40621](https://issues.jenkins-ci.org/browse/JENKINS-40621) - 22 | Prevent leaked file descriptors when invoking `MavenEmbedderUtils#getMavenVersion()` 23 | ([PR #5](https://github.com/jenkinsci/lib-jenkins-maven-embedder/pull/5)) 24 | * [JENKINS-42549](https://issues.jenkins-ci.org/browse/JENKINS-42549) - 25 | Prevent file access errors in `JARUrlConnection` due to the parallel reading of JAR resources in `MavenEmbedderUtils#getMavenVersion()` 26 | (regression in 3.12) 27 | 28 | 29 | ### 3.12 30 | 31 | Release date: Feb 16, 2017 32 | 33 | :exclamation: The release introduced the [JENKINS-42549](https://issues.jenkins-ci.org/browse/JENKINS-42549) regression. 34 | It is recommended to use newer versions. 35 | 36 | * Update from sisu-guice `3.1.3` to guice `4.0` 37 | * Update plexus-classworlds from `2.4.2` to `2.5.1` 38 | * Update Sonatype Aether `0.9.0.M2` to Eclipse Aether `1.1.0` 39 | * Update Apache Wagon `2.4` to `2.12` 40 | * Update org.eclipse.sisu:org.eclipse.sisu.plexus `0.0.0.M2a` to `0.3.3` 41 | 42 | ### 3.11 43 | 44 | Release date: Jul 23, 2013 45 | 46 | * Inherit distribution management from the Jenkins Parent POM 47 | 48 | ### Previous versions 49 | 50 | No Changelog, see the commit history 51 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | // Builds a module using https://github.com/jenkins-infra/pipeline-library 2 | buildPlugin(useContainerAgent: true, configurations: [ 3 | [ platform: "linux", jdk: "11" ], 4 | [ platform: "windows", jdk: "11" ], 5 | [ platform: "linux", jdk: "17" ] 6 | ]) 7 | 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2001-2017 The Apache Software Foundation. 2 | 3 | Licensed to the Apache Software Foundation (ASF) under one 4 | or more contributor license agreements. See the NOTICE file 5 | distributed with this work for additional information 6 | regarding copyright ownership. The ASF licenses this file 7 | to you under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the 9 | License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, 14 | software distributed under the License is distributed on an 15 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | KIND, either express or implied. See the License for the 17 | specific language governing permissions and limitations 18 | under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Jenkins Maven Embedder Library 2 | === 3 | 4 | Library for Jenkins plugins and other components, which allows embedding Maven into their logic. 5 | 6 | ### Changelog 7 | 8 | See the [CHANGELOG](CHANGELOG.md) page. 9 | 10 | ### License 11 | 12 | [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 13 | 14 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | 23 | org.jenkins-ci 24 | jenkins 25 | 1.113 26 | 27 | 4.0.0 28 | org.jenkins-ci.lib 29 | lib-jenkins-maven-embedder 30 | Jenkins Maven Embedder 31 | Library for Jenkins plugins and other components, which allows embedding Maven into their logic 32 | 3.16-SNAPSHOT 33 | 34 | 35 | 36 | Apache 2 37 | http://www.apache.org/licenses/LICENSE-2.0.txt 38 | repo 39 | 40 | 41 | 42 | 43 | scm:git:git://github.com/jenkinsci/lib-jenkins-maven-embedder.git 44 | scm:git:ssh://git@github.com/jenkinsci/lib-jenkins-maven-embedder.git 45 | https://github.com/jenkinsci/lib-jenkins-maven-embedder 46 | HEAD 47 | 48 | 49 | 50 | 1.9.19 51 | 3.9.6 52 | 3.5.3 53 | UTF-8 54 | 1.7.36 55 | 2.18.0 56 | 11 57 | 58 | High 59 | 60 | 61 | 62 | 63 | org.codehaus.plexus 64 | plexus-classworlds 65 | 2.7.0 66 | 67 | 68 | org.apache.maven 69 | maven-core 70 | ${mavenVersion} 71 | 72 | 73 | org.apache.maven 74 | maven-artifact 75 | ${mavenVersion} 76 | 77 | 78 | org.apache.maven 79 | maven-compat 80 | ${mavenVersion} 81 | 82 | 83 | org.apache.maven 84 | maven-embedder 85 | ${mavenVersion} 86 | 87 | 88 | org.sonatype.plexus 89 | plexus-cipher 90 | 91 | 92 | 93 | 94 | org.codehaus.plexus 95 | plexus-cipher 96 | 2.0 97 | 98 | 99 | 100 | org.eclipse.sisu 101 | org.eclipse.sisu.plexus 102 | 0.9.0.M2 103 | 104 | 105 | org.sonatype.sisu 106 | sisu-guice 107 | 108 | 109 | 110 | 111 | 112 | com.google.inject 113 | guice 114 | 5.0.1 115 | provided 116 | 117 | 118 | 119 | org.apache.maven.resolver 120 | maven-resolver-transport-wagon 121 | ${resolverVersion} 122 | 123 | 124 | org.codehaus.plexus 125 | plexus-container-default 126 | 127 | 128 | 129 | 130 | org.apache.maven.resolver 131 | maven-resolver-api 132 | ${resolverVersion} 133 | 134 | 135 | org.apache.maven.resolver 136 | maven-resolver-impl 137 | ${resolverVersion} 138 | 139 | 140 | org.apache.maven.resolver 141 | maven-resolver-spi 142 | ${resolverVersion} 143 | 144 | 145 | org.apache.maven.resolver 146 | maven-resolver-util 147 | ${resolverVersion} 148 | 149 | 150 | org.apache.maven.resolver 151 | maven-resolver-connector-basic 152 | ${resolverVersion} 153 | 154 | 155 | 156 | org.apache.ant 157 | ant 158 | 1.10.11 159 | 160 | 161 | 162 | com.github.spotbugs 163 | spotbugs-annotations 164 | compile 165 | 166 | 167 | 168 | 169 | org.apache.maven.wagon 170 | wagon-provider-api 171 | ${wagonVersion} 172 | 173 | 174 | org.apache.maven.wagon 175 | wagon-file 176 | ${wagonVersion} 177 | test 178 | 179 | 180 | org.apache.maven.wagon 181 | wagon-http 182 | ${wagonVersion} 183 | test 184 | 185 | 186 | commons-logging 187 | commons-logging 188 | 189 | 190 | 191 | 192 | commons-io 193 | commons-io 194 | 2.7 195 | 196 | 197 | org.slf4j 198 | slf4j-api 199 | ${slf4jVersion} 200 | test 201 | 202 | 203 | org.slf4j 204 | jcl-over-slf4j 205 | ${slf4jVersion} 206 | test 207 | 208 | 209 | org.apache.logging.log4j 210 | log4j-core 211 | ${log4j.version} 212 | test 213 | 214 | 215 | org.apache.logging.log4j 216 | log4j-slf4j-impl 217 | ${log4j.version} 218 | test 219 | 220 | 221 | 222 | junit 223 | junit 224 | 4.13.2 225 | test 226 | 227 | 228 | org.jenkins-ci 229 | test-annotations 230 | 1.2 231 | test 232 | 233 | 234 | com.google.code.findbugs 235 | jsr305 236 | 3.0.2 237 | provided 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | org.apache.maven.plugins 247 | maven-release-plugin 248 | 2.5.3 249 | 250 | deploy 251 | false 252 | -Pjenkins-release 253 | 254 | 255 | 256 | org.apache.maven.plugins 257 | maven-dependency-plugin 258 | 3.1.2 259 | 260 | 261 | org.apache.maven.plugins 262 | maven-enforcer-plugin 263 | 264 | 265 | 266 | 267 | com.google.inject:guice 268 | com.google.guava:guava 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | org.apache.maven.plugins 279 | maven-surefire-plugin 280 | 281 | false 282 | 283 | ${maven.home} 284 | ${maven.version} 285 | ${settings.localRepository} 286 | 287 | 288 | 289 | 290 | org.apache.maven.plugins 291 | maven-enforcer-plugin 292 | 293 | 294 | 295 | enforce 296 | 297 | validate 298 | ensure-no-plexus-librairies 299 | 300 | 301 | 302 | 303 | org.codehaus.plexus:plexus-container-default 304 | org.sonatype.sisu:sisu-guice 305 | org.sonatype.plexus:plexus-cipher 306 | 307 | 308 | ensure-no-plexus-container doesn't work anymore with maven 3 librairies. you have to add some exclusions. 309 | 310 | 311 | 312 | 313 | com.google.inject:guice 314 | 315 | 316 | 317 | true 318 | 319 | 320 | 321 | 322 | 323 | org.apache.maven.plugins 324 | maven-jar-plugin 325 | 326 | 327 | 328 | true 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | m.g.o-public 339 | https://repo.jenkins-ci.org/public/ 340 | 341 | true 342 | 343 | 344 | false 345 | 346 | 347 | 348 | 349 | 350 | 351 | m.g.o-public 352 | https://repo.jenkins-ci.org/public/ 353 | 354 | true 355 | 356 | 357 | false 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | jenkins-release 366 | 367 | 368 | 369 | org.apache.maven.plugins 370 | maven-source-plugin 371 | 372 | 373 | attach-sources 374 | 375 | jar 376 | 377 | 378 | 379 | 380 | 381 | org.apache.maven.plugins 382 | maven-javadoc-plugin 383 | 384 | 385 | attach-javadocs 386 | 387 | jar 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | -------------------------------------------------------------------------------- /src/main/java/hudson/maven/MavenEmbedder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2005 The Apache Software Foundation. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package hudson.maven; 17 | 18 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 19 | import org.apache.maven.DefaultMaven; 20 | import org.apache.maven.Maven; 21 | import org.apache.maven.artifact.Artifact; 22 | import org.apache.maven.artifact.InvalidRepositoryException; 23 | import org.apache.maven.artifact.manager.WagonManager; 24 | import org.apache.maven.artifact.repository.ArtifactRepository; 25 | import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; 26 | import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; 27 | import org.apache.maven.artifact.resolver.ArtifactNotFoundException; 28 | import org.apache.maven.artifact.resolver.ArtifactResolutionException; 29 | import org.apache.maven.cli.configuration.SettingsXmlConfigurationProcessor; 30 | import org.apache.maven.execution.DefaultMavenExecutionRequest; 31 | import org.apache.maven.execution.DefaultMavenExecutionResult; 32 | import org.apache.maven.execution.MavenExecutionRequest; 33 | import org.apache.maven.execution.MavenExecutionRequestPopulationException; 34 | import org.apache.maven.execution.MavenExecutionRequestPopulator; 35 | import org.apache.maven.execution.MavenExecutionResult; 36 | import org.apache.maven.execution.MavenSession; 37 | import org.apache.maven.model.Model; 38 | import org.apache.maven.model.Profile; 39 | import org.apache.maven.model.io.xpp3.MavenXpp3Reader; 40 | import org.apache.maven.model.io.xpp3.MavenXpp3Writer; 41 | import org.apache.maven.plugin.LegacySupport; 42 | import org.apache.maven.plugin.MojoExecutionException; 43 | import org.apache.maven.project.MavenProject; 44 | import org.apache.maven.project.ProjectBuilder; 45 | import org.apache.maven.project.ProjectBuildingException; 46 | import org.apache.maven.project.ProjectBuildingRequest; 47 | import org.apache.maven.project.ProjectBuildingResult; 48 | import org.apache.maven.repository.RepositorySystem; 49 | import org.apache.maven.settings.Mirror; 50 | import org.apache.maven.settings.Proxy; 51 | import org.apache.maven.settings.Server; 52 | import org.apache.maven.settings.Settings; 53 | import org.apache.maven.settings.SettingsConfigurationException; 54 | import org.apache.maven.settings.building.DefaultSettingsBuildingRequest; 55 | import org.apache.maven.settings.building.SettingsBuilder; 56 | import org.apache.maven.settings.building.SettingsBuildingException; 57 | import org.apache.maven.settings.building.SettingsBuildingRequest; 58 | import org.codehaus.plexus.PlexusContainer; 59 | import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; 60 | import org.codehaus.plexus.component.repository.exception.ComponentLookupException; 61 | import org.codehaus.plexus.logging.Logger; 62 | import org.codehaus.plexus.util.DirectoryScanner; 63 | import org.codehaus.plexus.util.Os; 64 | import org.codehaus.plexus.util.xml.pull.XmlPullParserException; 65 | import org.eclipse.aether.RepositorySystemSession; 66 | 67 | import java.io.File; 68 | import java.io.FileNotFoundException; 69 | import java.io.FileReader; 70 | import java.io.IOException; 71 | import java.io.Writer; 72 | import java.util.ArrayList; 73 | import java.util.Arrays; 74 | import java.util.Collections; 75 | import java.util.HashMap; 76 | import java.util.List; 77 | import java.util.Locale; 78 | import java.util.Map; 79 | import java.util.Map.Entry; 80 | import java.util.Properties; 81 | 82 | 83 | /** 84 | * Class intended to be used by clients who wish to embed Maven into their applications 85 | * 86 | * @author Jason van Zyl 87 | * @author Olivier Lamy 88 | */ 89 | public class MavenEmbedder 90 | { 91 | public static final String userHome = System.getProperty( "user.home" ); 92 | 93 | private MavenXpp3Reader modelReader; 94 | 95 | private MavenXpp3Writer modelWriter; 96 | 97 | private final File mavenHome; 98 | 99 | private final PlexusContainer plexusContainer; 100 | 101 | private final MavenRequest mavenRequest; 102 | 103 | private final MavenExecutionRequest mavenExecutionRequest; 104 | private final MavenSession mavenSession; 105 | 106 | public MavenEmbedder( File mavenHome, MavenRequest mavenRequest ) throws MavenEmbedderException { 107 | this(mavenHome,mavenRequest,MavenEmbedderUtils.buildPlexusContainer(mavenHome, mavenRequest)); 108 | } 109 | 110 | public MavenEmbedder( ClassLoader mavenClassLoader, ClassLoader parent, MavenRequest mavenRequest ) throws MavenEmbedderException { 111 | this(null,mavenRequest,MavenEmbedderUtils.buildPlexusContainer(mavenClassLoader, parent, mavenRequest)); 112 | } 113 | 114 | private MavenEmbedder( File mavenHome, MavenRequest mavenRequest, PlexusContainer plexusContainer ) 115 | throws MavenEmbedderException 116 | { 117 | this.mavenHome = mavenHome; 118 | this.mavenRequest = mavenRequest; 119 | this.plexusContainer = plexusContainer; 120 | 121 | try { 122 | this.mavenExecutionRequest = this.buildMavenExecutionRequest(mavenRequest); 123 | 124 | RepositorySystemSession rss = ((DefaultMaven) lookup(Maven.class)).newRepositorySession(mavenExecutionRequest); 125 | 126 | mavenSession = new MavenSession( plexusContainer, rss, mavenExecutionRequest, new DefaultMavenExecutionResult() ); 127 | 128 | lookup(LegacySupport.class).setSession(mavenSession); 129 | } catch (MavenEmbedderException | ComponentLookupException e) { 130 | throw new MavenEmbedderException(e.getMessage(), e); 131 | } 132 | } 133 | 134 | 135 | public MavenEmbedder( ClassLoader mavenClassLoader, MavenRequest mavenRequest ) throws MavenEmbedderException { 136 | this(mavenClassLoader, null, mavenRequest); 137 | } 138 | 139 | 140 | public PlexusContainer getPlexusContainer() { 141 | return plexusContainer; 142 | } 143 | 144 | protected MavenExecutionRequest buildMavenExecutionRequest(MavenRequest mavenRequest) 145 | throws MavenEmbedderException, ComponentLookupException { 146 | MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest(); 147 | 148 | if ( mavenRequest.getGlobalSettingsFile() != null ) { 149 | mavenExecutionRequest.setGlobalSettingsFile( new File( mavenRequest.getGlobalSettingsFile() ) ); 150 | } 151 | 152 | if ( mavenExecutionRequest.getUserSettingsFile() != null ) { 153 | mavenExecutionRequest.setUserSettingsFile( new File( mavenRequest.getUserSettingsFile() ) ); 154 | } 155 | 156 | try { 157 | lookup( MavenExecutionRequestPopulator.class ).populateFromSettings( mavenExecutionRequest, 158 | getSettings() ); 159 | 160 | lookup( MavenExecutionRequestPopulator.class ).populateDefaults( mavenExecutionRequest ); 161 | } catch ( MavenExecutionRequestPopulationException e ) { 162 | throw new MavenEmbedderException( e.getMessage(), e ); 163 | } 164 | 165 | ArtifactRepository localRepository = getLocalRepository(); 166 | mavenExecutionRequest.setLocalRepository( localRepository ); 167 | mavenExecutionRequest.setLocalRepositoryPath( localRepository.getBasedir() ); 168 | mavenExecutionRequest.setOffline( mavenRequest.isOffline() ); 169 | 170 | mavenExecutionRequest.setUpdateSnapshots( mavenRequest.isUpdateSnapshots() ); 171 | 172 | // TODO check null and create a console one ? 173 | mavenExecutionRequest.setTransferListener( mavenRequest.getTransferListener() ); 174 | 175 | mavenExecutionRequest.setCacheNotFound( mavenRequest.isCacheNotFound() ); 176 | mavenExecutionRequest.setCacheTransferError( true ); 177 | 178 | mavenExecutionRequest.setUserProperties( mavenRequest.getUserProperties() ); 179 | mavenExecutionRequest.getSystemProperties().putAll( System.getProperties() ); 180 | if ( mavenRequest.getSystemProperties() != null ) { 181 | mavenExecutionRequest.getSystemProperties().putAll( mavenRequest.getSystemProperties() ); 182 | } 183 | mavenExecutionRequest.getSystemProperties().putAll( getEnvVars() ); 184 | 185 | if ( this.mavenHome != null ) { 186 | mavenExecutionRequest.getSystemProperties().put( "maven.home", this.mavenHome.getAbsolutePath() ); 187 | } 188 | 189 | if (mavenRequest.getProfiles() != null && !mavenRequest.getProfiles().isEmpty()) { 190 | for (String id : mavenRequest.getProfiles()) { 191 | Profile p = new Profile(); 192 | p.setId( id ); 193 | p.setSource( "cli" ); 194 | mavenExecutionRequest.addProfile( p ); 195 | mavenExecutionRequest.addActiveProfile( id ); 196 | } 197 | } 198 | 199 | 200 | mavenExecutionRequest.setLoggingLevel( mavenRequest.getLoggingLevel() ); 201 | 202 | lookup( Logger.class ).setThreshold( mavenRequest.getLoggingLevel() ); 203 | 204 | mavenExecutionRequest.setExecutionListener( mavenRequest.getExecutionListener() ) 205 | .setInteractiveMode( mavenRequest.isInteractive() ) 206 | .setGlobalChecksumPolicy( mavenRequest.getGlobalChecksumPolicy() ) 207 | .setGoals( mavenRequest.getGoals() ); 208 | 209 | if ( mavenRequest.getPom() != null ) { 210 | mavenExecutionRequest.setPom( new File( mavenRequest.getPom() ) ); 211 | } 212 | 213 | if (mavenRequest.getWorkspaceReader() != null) { 214 | mavenExecutionRequest.setWorkspaceReader( mavenRequest.getWorkspaceReader() ); 215 | } 216 | 217 | // FIXME inactive profiles 218 | 219 | //this.mavenExecutionRequest.set 220 | 221 | return mavenExecutionRequest; 222 | 223 | } 224 | 225 | 226 | 227 | private Properties getEnvVars( ) { 228 | Properties envVars = new Properties(); 229 | boolean caseSensitive = !Os.isFamily( Os.FAMILY_WINDOWS ); 230 | for ( Map.Entry entry : System.getenv().entrySet() ) 231 | { 232 | String key = "env." + ( caseSensitive ? entry.getKey() : entry.getKey().toUpperCase( Locale.ENGLISH ) ); 233 | envVars.setProperty( key, entry.getValue() ); 234 | } 235 | return envVars; 236 | } 237 | 238 | public Settings getSettings() 239 | throws MavenEmbedderException, ComponentLookupException { 240 | 241 | SettingsBuildingRequest settingsBuildingRequest = new DefaultSettingsBuildingRequest(); 242 | if ( this.mavenRequest.getGlobalSettingsFile() != null ) { 243 | settingsBuildingRequest.setGlobalSettingsFile( new File( this.mavenRequest.getGlobalSettingsFile() ) ); 244 | } else { 245 | settingsBuildingRequest.setGlobalSettingsFile( SettingsXmlConfigurationProcessor.DEFAULT_GLOBAL_SETTINGS_FILE ); 246 | } 247 | if ( this.mavenRequest.getUserSettingsFile() != null ) { 248 | settingsBuildingRequest.setUserSettingsFile( new File( this.mavenRequest.getUserSettingsFile() ) ); 249 | } else { 250 | settingsBuildingRequest.setUserSettingsFile( SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE ); 251 | } 252 | 253 | settingsBuildingRequest.setUserProperties( this.mavenRequest.getUserProperties() ); 254 | settingsBuildingRequest.getSystemProperties().putAll( System.getProperties() ); 255 | settingsBuildingRequest.getSystemProperties().putAll( this.mavenRequest.getSystemProperties() ); 256 | settingsBuildingRequest.getSystemProperties().putAll( getEnvVars() ); 257 | 258 | try { 259 | return lookup( SettingsBuilder.class ).build( settingsBuildingRequest ).getEffectiveSettings(); 260 | } catch ( SettingsBuildingException e ) { 261 | throw new MavenEmbedderException( e.getMessage(), e ); 262 | } 263 | } 264 | 265 | public ArtifactRepository getLocalRepository() throws ComponentLookupException { 266 | try { 267 | String localRepositoryPath = getLocalRepositoryPath(); 268 | if ( localRepositoryPath != null ) { 269 | return lookup( RepositorySystem.class ).createLocalRepository( new File( localRepositoryPath ) ); 270 | } 271 | return lookup( RepositorySystem.class ).createLocalRepository( RepositorySystem.defaultUserLocalRepository ); 272 | } catch ( InvalidRepositoryException e ) { 273 | // never happened 274 | throw new IllegalStateException( e ); 275 | } 276 | } 277 | 278 | public String getLocalRepositoryPath() { 279 | String path = null; 280 | 281 | try { 282 | Settings settings = getSettings(); 283 | path = settings.getLocalRepository(); 284 | } catch ( MavenEmbedderException | ComponentLookupException e ) { 285 | // ignore 286 | } 287 | 288 | if ( this.mavenRequest.getLocalRepositoryPath() != null ) { 289 | path = this.mavenRequest.getLocalRepositoryPath(); 290 | } 291 | 292 | if ( path == null ) { 293 | path = RepositorySystem.defaultUserLocalRepository.getAbsolutePath(); 294 | } 295 | return path; 296 | } 297 | 298 | // ---------------------------------------------------------------------- 299 | // Model 300 | // ---------------------------------------------------------------------- 301 | 302 | /** 303 | * @deprecated not sure if use but definitely doesn't work 304 | */ 305 | @SuppressFBWarnings({"UWF_UNWRITTEN_FIELD","NP_UNWRITTEN_FIELD","DM_DEFAULT_ENCODING","OBL_UNSATISFIED_OBLIGATION"}) 306 | public Model readModel( File model ) 307 | throws XmlPullParserException, FileNotFoundException, IOException { 308 | return modelReader.read( new FileReader( model ) ); 309 | } 310 | 311 | /** 312 | * @deprecated not sure if use but definitely doesn't work 313 | */ 314 | @SuppressFBWarnings({"UWF_UNWRITTEN_FIELD","NP_UNWRITTEN_FIELD"}) 315 | public void writeModel( Writer writer, Model model ) 316 | throws IOException 317 | { 318 | modelWriter.write( writer, model ); 319 | } 320 | 321 | // ---------------------------------------------------------------------- 322 | // Project 323 | // ---------------------------------------------------------------------- 324 | 325 | public MavenProject readProject( File mavenProject ) 326 | throws ProjectBuildingException, MavenEmbedderException { 327 | 328 | List projects = readProjects( mavenProject, false ); 329 | return projects == null || projects.isEmpty() ? null : projects.get( 0 ); 330 | 331 | } 332 | 333 | public List readProjects( File mavenProject, boolean recursive ) 334 | throws ProjectBuildingException, MavenEmbedderException { 335 | ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); 336 | try { 337 | List results = buildProjects( mavenProject, recursive ); 338 | List projects = new ArrayList<>(results.size()); 339 | for (ProjectBuildingResult result : results) { 340 | projects.add( result.getProject() ); 341 | } 342 | return projects; 343 | } finally { 344 | Thread.currentThread().setContextClassLoader( originalCl ); 345 | } 346 | 347 | } 348 | 349 | public List buildProjects( File mavenProject, boolean recursive ) 350 | throws ProjectBuildingException, MavenEmbedderException { 351 | ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); 352 | try { 353 | Thread.currentThread().setContextClassLoader( this.plexusContainer.getContainerRealm() ); 354 | ProjectBuilder projectBuilder = lookup( ProjectBuilder.class ); 355 | ProjectBuildingRequest projectBuildingRequest = this.mavenExecutionRequest.getProjectBuildingRequest(); 356 | 357 | projectBuildingRequest.setValidationLevel( this.mavenRequest.getValidationLevel() ); 358 | 359 | RepositorySystemSession repositorySystemSession = buildRepositorySystemSession(); 360 | 361 | projectBuildingRequest.setRepositorySession( repositorySystemSession ); 362 | 363 | projectBuildingRequest.setProcessPlugins( this.mavenRequest.isProcessPlugins() ); 364 | 365 | projectBuildingRequest.setResolveDependencies( this.mavenRequest.isResolveDependencies() ); 366 | 367 | return projectBuilder.build( Collections.singletonList( mavenProject), recursive, projectBuildingRequest ); 368 | 369 | } catch(ComponentLookupException e) { 370 | throw new MavenEmbedderException(e.getMessage(), e); 371 | } finally { 372 | Thread.currentThread().setContextClassLoader( originalCl ); 373 | } 374 | 375 | } 376 | 377 | private RepositorySystemSession buildRepositorySystemSession() throws ComponentLookupException { 378 | DefaultMaven defaultMaven = (DefaultMaven) plexusContainer.lookup( Maven.class ); 379 | return defaultMaven.newRepositorySession( mavenExecutionRequest ); 380 | } 381 | 382 | public List collectProjects( File basedir, String[] includes, String[] excludes ) 383 | throws MojoExecutionException, MavenEmbedderException { 384 | List projects = new ArrayList<>(); 385 | 386 | List poms = getPomFiles( basedir, includes, excludes ); 387 | 388 | for ( File pom : poms ) { 389 | try { 390 | MavenProject p = readProject( pom ); 391 | 392 | projects.add( p ); 393 | 394 | } catch ( ProjectBuildingException e ) { 395 | throw new MojoExecutionException( "Error loading " + pom, e ); 396 | } 397 | } 398 | 399 | return projects; 400 | } 401 | 402 | // ---------------------------------------------------------------------- 403 | // Artifacts 404 | // ---------------------------------------------------------------------- 405 | 406 | public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ) 407 | throws MavenEmbedderException 408 | { 409 | try { 410 | RepositorySystem repositorySystem = lookup( RepositorySystem.class ); 411 | return repositorySystem.createArtifact( groupId, artifactId, version, scope, type ); 412 | } catch ( ComponentLookupException e ) { 413 | throw new MavenEmbedderException(e.getMessage(), e); 414 | } 415 | 416 | } 417 | 418 | public Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, String classifier ) 419 | throws MavenEmbedderException 420 | { 421 | try { 422 | RepositorySystem repositorySystem = lookup( RepositorySystem.class ); 423 | return repositorySystem.createArtifactWithClassifier( groupId, artifactId, version, type, classifier ); 424 | } catch ( ComponentLookupException e ) { 425 | throw new MavenEmbedderException(e.getMessage(), e); 426 | } 427 | } 428 | 429 | public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) 430 | throws ArtifactResolutionException, ArtifactNotFoundException { 431 | // FIXME ? 432 | } 433 | 434 | // ---------------------------------------------------------------------- 435 | // Execution of phases/goals 436 | // ---------------------------------------------------------------------- 437 | 438 | public MavenExecutionResult execute( MavenRequest mavenRequest ) 439 | throws MavenEmbedderException { 440 | ClassLoader original = Thread.currentThread().getContextClassLoader(); 441 | try { 442 | Maven maven = lookup( Maven.class ); 443 | Thread.currentThread().setContextClassLoader( this.plexusContainer.getContainerRealm() ); 444 | return maven.execute( buildMavenExecutionRequest( mavenRequest ) ); 445 | } 446 | catch ( MavenEmbedderException | ComponentLookupException e ) 447 | { 448 | throw new MavenEmbedderException(e.getMessage(),e); 449 | } 450 | finally { 451 | Thread.currentThread().setContextClassLoader( original ); 452 | } 453 | } 454 | // ---------------------------------------------------------------------- 455 | // Local Repository 456 | // ---------------------------------------------------------------------- 457 | 458 | public static final String DEFAULT_LOCAL_REPO_ID = "local"; 459 | 460 | public static final String DEFAULT_LAYOUT_ID = "default"; 461 | 462 | public ArtifactRepository createLocalRepository( File localRepository ) 463 | throws ComponentLookupException { 464 | return createLocalRepository( localRepository.getAbsolutePath(), DEFAULT_LOCAL_REPO_ID ); 465 | } 466 | 467 | public ArtifactRepository createLocalRepository( Settings settings ) 468 | throws ComponentLookupException { 469 | return createLocalRepository( settings.getLocalRepository(), DEFAULT_LOCAL_REPO_ID ); 470 | } 471 | 472 | public ArtifactRepository createLocalRepository( String url, String repositoryId ) 473 | throws ComponentLookupException { 474 | if ( !url.startsWith( "file:" ) ) { 475 | url = "file://" + url; 476 | } 477 | 478 | return createRepository( url, repositoryId ); 479 | } 480 | 481 | public ArtifactRepository createRepository( String url, String repositoryId ) 482 | throws ComponentLookupException { 483 | // snapshots vs releases 484 | // offline = to turning the update policy off 485 | 486 | //TODO: we'll need to allow finer grained creation of repositories but this will do for now 487 | 488 | String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS; 489 | 490 | String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN; 491 | 492 | ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag ); 493 | 494 | ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag ); 495 | 496 | RepositorySystem repositorySystem = lookup( RepositorySystem.class ); 497 | 498 | ArtifactRepositoryLayout repositoryLayout = lookup( ArtifactRepositoryLayout.class, "default" ); 499 | 500 | return repositorySystem.createArtifactRepository( repositoryId, url, repositoryLayout, snapshotsPolicy, releasesPolicy ); 501 | 502 | } 503 | 504 | // ---------------------------------------------------------------------- 505 | // Internal utility code 506 | // ---------------------------------------------------------------------- 507 | 508 | 509 | private List getPomFiles( File basedir, String[] includes, String[] excludes ) { 510 | DirectoryScanner scanner = new DirectoryScanner(); 511 | 512 | scanner.setBasedir( basedir ); 513 | 514 | scanner.setIncludes( includes ); 515 | 516 | scanner.setExcludes( excludes ); 517 | 518 | scanner.scan(); 519 | 520 | List poms = new ArrayList<>(); 521 | 522 | for ( int i = 0; i < scanner.getIncludedFiles().length; i++ ) { 523 | poms.add( new File( basedir, scanner.getIncludedFiles()[i] ) ); 524 | } 525 | 526 | return poms; 527 | } 528 | 529 | 530 | /** 531 | * {@link WagonManager} can't configure itself from {@link Settings}, so we need to baby-sit them. 532 | * So much for dependency injection. 533 | */ 534 | private void resolveParameters(WagonManager wagonManager, Settings settings) 535 | throws ComponentLookupException, ComponentLifecycleException, SettingsConfigurationException { 536 | 537 | // TODO todo or not todo ? 538 | 539 | Proxy proxy = settings.getActiveProxy(); 540 | 541 | if (proxy != null) { 542 | if (proxy.getHost() == null) { 543 | throw new SettingsConfigurationException("Proxy in settings.xml has no host"); 544 | } 545 | 546 | //wagonManager.addProxy(proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(), 547 | // proxy.getPassword(), proxy.getNonProxyHosts()); 548 | } 549 | 550 | for (Server server : settings.getServers()) { 551 | //wagonManager.addAuthenticationInfo(server.getId(), server.getUsername(), server.getPassword(), 552 | // server.getPrivateKey(), server.getPassphrase()); 553 | 554 | //wagonManager.addPermissionInfo(server.getId(), server.getFilePermissions(), 555 | // server.getDirectoryPermissions()); 556 | 557 | if (server.getConfiguration() != null) { 558 | //wagonManager.addConfiguration(server.getId(), (Xpp3Dom) server.getConfiguration()); 559 | } 560 | } 561 | 562 | for (Mirror mirror : settings.getMirrors()) { 563 | //wagonManager.addMirror(mirror.getId(), mirror.getMirrorOf(), mirror.getUrl()); 564 | } 565 | } 566 | 567 | public T lookup( Class clazz ) throws ComponentLookupException { 568 | return plexusContainer.lookup( clazz ); 569 | } 570 | 571 | public T lookup( Class clazz, String hint ) throws ComponentLookupException { 572 | return plexusContainer.lookup( clazz, hint ); 573 | } 574 | 575 | public Object lookup( String role, String hint ) throws ComponentLookupException { 576 | return plexusContainer.lookup( role, hint ); 577 | } 578 | 579 | public Object lookup( String role ) throws ComponentLookupException { 580 | return plexusContainer.lookup( role ); 581 | } 582 | 583 | private Map propertiesToMap(Properties properties) { 584 | if ( properties == null || properties.isEmpty() ) { 585 | return new HashMap<>( 0 ); 586 | } 587 | Map result = new HashMap<>( properties.size() ); 588 | for ( Entry entry : properties.entrySet() ) { 589 | result.put( (String) entry.getKey(), (String) entry.getValue() ); 590 | } 591 | return result; 592 | } 593 | 594 | public MavenRequest getMavenRequest() 595 | { 596 | return mavenRequest; 597 | } 598 | } 599 | -------------------------------------------------------------------------------- /src/main/java/hudson/maven/MavenEmbedderCallable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Oleg Nenashev. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package hudson.maven; 17 | 18 | /** 19 | * Callable interface for the Maven Embedder logic. 20 | * 21 | * Used primarily for testing purposes. 22 | * @author Oleg Nenashev 23 | */ 24 | /*package*/ interface MavenEmbedderCallable { 25 | 26 | void call() throws MavenEmbedderException; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/hudson/maven/MavenEmbedderException.java: -------------------------------------------------------------------------------- 1 | package hudson.maven; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | /** 23 | * @author olamy 24 | * 25 | */ 26 | public class MavenEmbedderException 27 | extends Exception 28 | { 29 | 30 | /** 31 | * 32 | */ 33 | public MavenEmbedderException() { 34 | // no op 35 | } 36 | 37 | /** 38 | * @param message 39 | */ 40 | public MavenEmbedderException( String message ) { 41 | super( message ); 42 | } 43 | 44 | /** 45 | * @param cause 46 | */ 47 | public MavenEmbedderException( Throwable cause ) { 48 | super( cause ); 49 | } 50 | 51 | /** 52 | * @param message 53 | * @param cause 54 | */ 55 | public MavenEmbedderException( String message, Throwable cause ) { 56 | super( message, cause ); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/hudson/maven/MavenEmbedderUtils.java: -------------------------------------------------------------------------------- 1 | package hudson.maven; 2 | 3 | /* 4 | * Olivier Lamy 5 | * Licensed to the Apache Software Foundation (ASF) under one 6 | * or more contributor license agreements. See the NOTICE file 7 | * distributed with this work for additional information 8 | * regarding copyright ownership. The ASF licenses this file 9 | * to you under the Apache License, Version 2.0 (the 10 | * "License"); you may not use this file except in compliance 11 | * with the License. You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, 16 | * software distributed under the License is distributed on an 17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 | * KIND, either express or implied. See the License for the 19 | * specific language governing permissions and limitations 20 | * under the License. 21 | */ 22 | 23 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 24 | import org.apache.maven.artifact.versioning.ComparableVersion; 25 | import org.apache.tools.ant.AntClassLoader; 26 | import org.codehaus.plexus.ContainerConfiguration; 27 | import org.codehaus.plexus.DefaultContainerConfiguration; 28 | import org.codehaus.plexus.DefaultPlexusContainer; 29 | import org.codehaus.plexus.PlexusContainer; 30 | import org.codehaus.plexus.PlexusContainerException; 31 | import org.codehaus.plexus.classworlds.ClassWorld; 32 | import org.codehaus.plexus.classworlds.realm.ClassRealm; 33 | 34 | import javax.annotation.CheckForNull; 35 | import javax.annotation.Nonnull; 36 | import java.io.File; 37 | import java.io.IOException; 38 | import java.io.InputStream; 39 | import java.net.MalformedURLException; 40 | import java.net.URL; 41 | import java.net.URLConnection; 42 | import java.util.Enumeration; 43 | import java.util.Properties; 44 | 45 | 46 | /** 47 | * @author Olivier Lamy 48 | * 49 | */ 50 | public class MavenEmbedderUtils 51 | { 52 | 53 | private static final String POM_PROPERTIES_PATH = "META-INF/maven/org.apache.maven/maven-core/pom.properties"; 54 | 55 | private MavenEmbedderUtils() { 56 | // no op only to prevent construction 57 | } 58 | 59 | /** 60 | * 61 | * build a {@link ClassRealm} with all jars in mavenHome/lib/*.jar 62 | * 63 | * 64 | * the {@link ClassRealm} is ChildFirst with the current classLoader as parent. 65 | * 66 | * @param mavenHome cannot be null 67 | * @param world can be null 68 | * @return 69 | */ 70 | @SuppressFBWarnings("DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED") 71 | public static ClassRealm buildClassRealm(File mavenHome, ClassWorld world, ClassLoader parentClassLoader ) 72 | throws MavenEmbedderException { 73 | 74 | if ( mavenHome == null ) { 75 | throw new IllegalArgumentException( "mavenHome cannot be null" ); 76 | } 77 | if ( !mavenHome.exists() ) { 78 | throw new IllegalArgumentException( "mavenHome '" + mavenHome.getPath() + "' doesn't seem to exist on this node (or you don't have sufficient rights to access it)" ); 79 | } 80 | 81 | // list all jar under mavenHome/lib 82 | 83 | File libDirectory = new File( mavenHome, "lib" ); 84 | if ( !libDirectory.exists() ) { 85 | throw new IllegalArgumentException( mavenHome.getPath() + " doesn't have a 'lib' subdirectory - thus cannot be a valid maven installation!" ); 86 | } 87 | 88 | File[] jarFiles = libDirectory.listFiles( ( dir, name ) -> name.endsWith( ".jar" )); 89 | 90 | 91 | AntClassLoader antClassLoader = new AntClassLoader( Thread.currentThread().getContextClassLoader(), false ); 92 | 93 | if(jarFiles!=null) { 94 | for ( File jarFile : jarFiles ) { 95 | antClassLoader.addPathComponent( jarFile ); 96 | } 97 | } 98 | if (world == null) { 99 | world = new ClassWorld(); 100 | } 101 | 102 | ClassRealm classRealm = new ClassRealm( world, "plexus.core", parentClassLoader == null ? antClassLoader : parentClassLoader ); 103 | 104 | if(jarFiles!=null) { 105 | for ( File jarFile : jarFiles ) { 106 | try { 107 | classRealm.addURL( jarFile.toURI().toURL() ); 108 | } catch ( MalformedURLException e ) { 109 | throw new MavenEmbedderException( e.getMessage(), e ); 110 | } 111 | } 112 | } 113 | return classRealm; 114 | } 115 | 116 | public static PlexusContainer buildPlexusContainer(File mavenHome, MavenRequest mavenRequest) throws MavenEmbedderException { 117 | ClassWorld world = new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader()); 118 | 119 | ClassRealm classRealm = MavenEmbedderUtils.buildClassRealm( mavenHome, world, Thread.currentThread().getContextClassLoader() ); 120 | 121 | DefaultContainerConfiguration conf = new DefaultContainerConfiguration(); 122 | 123 | conf.setContainerConfigurationURL( mavenRequest.getOverridingComponentsXml() ) 124 | .setRealm( classRealm ) 125 | .setClassWorld( world ) 126 | .setClassPathScanning( mavenRequest.getContainerClassPathScanning() ) 127 | .setComponentVisibility( mavenRequest.getContainerComponentVisibility() ); 128 | 129 | return buildPlexusContainer(mavenRequest,conf); 130 | } 131 | 132 | /** 133 | * used by PomParser in Jenkins 134 | * @param mavenClassLoader 135 | * @param parent 136 | * @param mavenRequest 137 | * @return 138 | * @throws MavenEmbedderException 139 | */ 140 | @SuppressFBWarnings("DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED") 141 | public static PlexusContainer buildPlexusContainer(ClassLoader mavenClassLoader, ClassLoader parent, MavenRequest mavenRequest) throws MavenEmbedderException { 142 | DefaultContainerConfiguration conf = new DefaultContainerConfiguration(); 143 | 144 | conf.setAutoWiring( mavenRequest.isContainerAutoWiring() ) 145 | .setClassPathScanning( mavenRequest.getContainerClassPathScanning() ) 146 | .setComponentVisibility( mavenRequest.getContainerComponentVisibility() ) 147 | .setContainerConfigurationURL( mavenRequest.getOverridingComponentsXml() ); 148 | 149 | ClassWorld classWorld = new ClassWorld(); 150 | 151 | ClassRealm classRealm = new ClassRealm( classWorld, "maven", mavenClassLoader ); 152 | classRealm.setParentRealm( new ClassRealm( classWorld, "maven-parent", 153 | parent == null ? Thread.currentThread().getContextClassLoader() 154 | : parent ) ); 155 | conf.setRealm( classRealm ); 156 | 157 | conf.setClassWorld( classWorld ); 158 | 159 | return buildPlexusContainer(mavenRequest,conf); 160 | } 161 | 162 | private static PlexusContainer buildPlexusContainer(MavenRequest mavenRequest,ContainerConfiguration containerConfiguration ) 163 | throws MavenEmbedderException { 164 | try 165 | { 166 | DefaultPlexusContainer plexusContainer = new DefaultPlexusContainer( containerConfiguration ); 167 | if (mavenRequest.getMavenLoggerManager() != null) { 168 | plexusContainer.setLoggerManager( mavenRequest.getMavenLoggerManager() ); 169 | } 170 | if (mavenRequest.getLoggingLevel() > 0) { 171 | plexusContainer.getLoggerManager().setThreshold( mavenRequest.getLoggingLevel() ); 172 | } 173 | return plexusContainer; 174 | } catch ( PlexusContainerException e ) { 175 | throw new MavenEmbedderException( e.getMessage(), e ); 176 | } 177 | } 178 | 179 | /** 180 | * @param mavenHome Maven Home directory 181 | * @return the maven version 182 | * @throws MavenEmbedderException Operation failure 183 | */ 184 | public static MavenInformation getMavenVersion(@Nonnull File mavenHome) throws MavenEmbedderException { 185 | return getMavenVersion(mavenHome, null); 186 | } 187 | 188 | /*package*/ static MavenInformation getMavenVersion(@Nonnull File mavenHome, 189 | @CheckForNull MavenEmbedderCallable preopertiesPreloadHook) throws MavenEmbedderException { 190 | 191 | MavenInformation information = null; 192 | ClassLoader original = null; 193 | //ClassRealm realm = null; 194 | try (ClassRealm realm = buildClassRealm( mavenHome, null, null )) { 195 | //realm = buildClassRealm( mavenHome, null, null ); 196 | if (debug) { 197 | debugMavenVersion(realm); 198 | } 199 | original = Thread.currentThread().getContextClassLoader(); 200 | 201 | Thread.currentThread().setContextClassLoader( realm ); 202 | // TODO is this really intending to use findResource rather than getResource? Cf. https://github.com/sonatype/plexus-classworlds/pull/8 203 | URL resource = realm.findResource( POM_PROPERTIES_PATH ); 204 | if (resource == null) { 205 | throw new MavenEmbedderException("Couldn't find maven version information in '" + mavenHome.getPath() 206 | + "'. Are you sure that this is a valid maven home?"); 207 | } 208 | URLConnection uc = resource.openConnection(); 209 | uc.setUseCaches(false); 210 | try(InputStream istream = uc.getInputStream()) { 211 | if (preopertiesPreloadHook != null) { 212 | preopertiesPreloadHook.call(); 213 | } 214 | Properties properties = new Properties(); 215 | properties.load( istream ); 216 | information = new MavenInformation( properties.getProperty( "version" ) , resource.toExternalForm() ); 217 | } 218 | } catch ( IOException e ) { 219 | throw new MavenEmbedderException( e.getMessage(), e ); 220 | } finally { 221 | Thread.currentThread().setContextClassLoader( original ); 222 | } 223 | 224 | return information; 225 | } 226 | 227 | public static boolean isAtLeastMavenVersion(File mavenHome, String version) throws MavenEmbedderException { 228 | ComparableVersion found = new ComparableVersion( getMavenVersion( mavenHome ).getVersion() ); 229 | ComparableVersion testedOne = new ComparableVersion( version ); 230 | return found.compareTo( testedOne ) >= 0; 231 | } 232 | 233 | private static void debugMavenVersion(ClassRealm realm ) { 234 | try { 235 | // TODO as above, consider getResources 236 | @SuppressWarnings("unchecked") 237 | Enumeration urls = realm.findResources( POM_PROPERTIES_PATH ); 238 | System.out.println("urls for " + POM_PROPERTIES_PATH ); 239 | while(urls.hasMoreElements()) { 240 | System.out.println("url " + urls.nextElement().toExternalForm()); 241 | } 242 | } catch (IOException e) { 243 | System.out.println("Ignore IOException during searching " + POM_PROPERTIES_PATH + ":" + e.getMessage()); 244 | } 245 | } 246 | 247 | public static final boolean debug = Boolean.getBoolean( "hudson.maven.MavenEmbedderUtils.debug" ); 248 | 249 | } 250 | -------------------------------------------------------------------------------- /src/main/java/hudson/maven/MavenInformation.java: -------------------------------------------------------------------------------- 1 | package hudson.maven; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.io.Serializable; 23 | 24 | 25 | /** 26 | * 27 | * @author Olivier Lamy 28 | * @since 3.0 29 | * 30 | */ 31 | public class MavenInformation implements Serializable { 32 | 33 | private static final long serialVersionUID = 8477909321273479507L; 34 | 35 | private final String version; 36 | 37 | private final String versionResourcePath; 38 | 39 | 40 | public MavenInformation( String version, String versionResourcePath ) { 41 | this.version = version; 42 | this.versionResourcePath = versionResourcePath; 43 | } 44 | 45 | 46 | public String getVersion() { 47 | return version; 48 | } 49 | 50 | 51 | public String getVersionResourcePath() { 52 | return versionResourcePath; 53 | } 54 | 55 | 56 | @Override 57 | public String toString() 58 | { 59 | final StringBuilder sb = new StringBuilder( "MavenInformation{" ); 60 | sb.append( "version='" ).append( version ).append( '\'' ); 61 | sb.append( ", versionResourcePath='" ).append( versionResourcePath ).append( '\'' ); 62 | sb.append( '}' ); 63 | return sb.toString(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/hudson/maven/MavenRequest.java: -------------------------------------------------------------------------------- 1 | package hudson.maven; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.net.URL; 23 | import java.util.List; 24 | import java.util.Properties; 25 | 26 | import org.apache.maven.execution.ExecutionListener; 27 | import org.apache.maven.execution.MavenExecutionRequest; 28 | import org.apache.maven.model.building.ModelBuildingRequest; 29 | import org.codehaus.plexus.PlexusConstants; 30 | import org.codehaus.plexus.logging.LoggerManager; 31 | import org.eclipse.aether.repository.WorkspaceReader; 32 | import org.eclipse.aether.transfer.TransferListener; 33 | 34 | /** 35 | * @author olamy 36 | * 37 | */ 38 | public class MavenRequest 39 | { 40 | 41 | private String globalSettingsFile; 42 | 43 | private String userSettingsFile; 44 | 45 | private String localRepositoryPath; 46 | 47 | private boolean offline; 48 | 49 | private TransferListener transferListener; 50 | 51 | private String baseDirectory; 52 | 53 | private List goals; 54 | 55 | private Properties systemProperties; 56 | 57 | private Properties userProperties; 58 | 59 | private String failureBehavior; 60 | 61 | private List selectedProjects; 62 | 63 | private String resumeFromProject; 64 | 65 | private String makeBehavior; 66 | 67 | private String threadCount; 68 | 69 | private boolean recursive; 70 | 71 | private String pom; 72 | 73 | private boolean showErrors; 74 | 75 | /** 76 | * @see org.apache.maven.execution.MavenExecutionRequest 77 | */ 78 | private int loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_INFO; 79 | 80 | private boolean updateSnapshots; 81 | 82 | private boolean noSnapshotUpdates; 83 | 84 | private String globalChecksumPolicy; 85 | 86 | private boolean interactive; 87 | 88 | private boolean cacheTransferError = true; 89 | 90 | private boolean cacheNotFound = true; 91 | 92 | private List profiles; 93 | 94 | private ExecutionListener executionListener; 95 | 96 | private WorkspaceReader workspaceReader; 97 | 98 | private LoggerManager mavenLoggerManager; 99 | 100 | /** 101 | * plexus configuration override 102 | */ 103 | private URL overridingComponentsXml; 104 | 105 | /** 106 | * will processPlugins during project reading 107 | * @since 3.2 108 | */ 109 | private boolean processPlugins; 110 | 111 | /** 112 | * will resolve dependencies during project reading 113 | * @since 3.2 114 | */ 115 | private boolean resolveDependencies; 116 | 117 | /** 118 | * level of validation when reading pom (ie model building request) 119 | * default {@link ModelBuildingRequest#VALIDATION_LEVEL_MAVEN_2_0} etc... 120 | * @since 3.2 121 | */ 122 | private int validationLevel = ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0; 123 | 124 | /** 125 | * @since 3.3 126 | */ 127 | private boolean containerAutoWiring = false; 128 | 129 | /** 130 | * @since 3.3 131 | */ 132 | private String containerComponentVisibility = PlexusConstants.REALM_VISIBILITY; 133 | 134 | /** 135 | * @since 3.3 136 | */ 137 | private String containerClassPathScanning = PlexusConstants.SCANNING_INDEX; 138 | 139 | public MavenRequest() { 140 | // no op 141 | } 142 | 143 | public String getGlobalSettingsFile() { 144 | return globalSettingsFile; 145 | } 146 | 147 | public MavenRequest setGlobalSettingsFile( String globalSettingsFile ) { 148 | this.globalSettingsFile = globalSettingsFile; 149 | return this; 150 | } 151 | 152 | public String getUserSettingsFile() { 153 | return userSettingsFile; 154 | } 155 | 156 | public MavenRequest setUserSettingsFile( String userSettingsFile ) { 157 | this.userSettingsFile = userSettingsFile; 158 | return this; 159 | } 160 | 161 | public String getLocalRepositoryPath() { 162 | return localRepositoryPath; 163 | } 164 | 165 | public MavenRequest setLocalRepositoryPath( String localRepositoryPath ) { 166 | this.localRepositoryPath = localRepositoryPath; 167 | return this; 168 | } 169 | 170 | public boolean isOffline() { 171 | return offline; 172 | } 173 | 174 | public MavenRequest setOffline( boolean offline ) { 175 | this.offline = offline; 176 | return this; 177 | } 178 | 179 | public TransferListener getTransferListener() { 180 | return transferListener; 181 | } 182 | 183 | public MavenRequest setTransferListener( TransferListener transferListener ) { 184 | this.transferListener = transferListener; 185 | return this; 186 | } 187 | 188 | public String getBaseDirectory() { 189 | return baseDirectory; 190 | } 191 | 192 | public MavenRequest setBaseDirectory( String baseDirectory ) { 193 | this.baseDirectory = baseDirectory; 194 | return this; 195 | } 196 | 197 | public List getGoals() { 198 | return goals; 199 | } 200 | 201 | public MavenRequest setGoals( List goals ) { 202 | this.goals = goals; 203 | return this; 204 | } 205 | 206 | public Properties getSystemProperties() { 207 | if (this.systemProperties == null) { 208 | this.systemProperties = new Properties(); 209 | this.systemProperties.putAll( System.getProperties() ); 210 | } 211 | return systemProperties; 212 | } 213 | 214 | public MavenRequest setSystemProperties( Properties systemProperties ) { 215 | this.systemProperties = systemProperties; 216 | return this; 217 | } 218 | 219 | public Properties getUserProperties() { 220 | if (this.userProperties == null) { 221 | this.userProperties = new Properties(); 222 | } 223 | return userProperties; 224 | } 225 | 226 | public MavenRequest setUserProperties( Properties userProperties ) { 227 | this.userProperties = userProperties; 228 | return this; 229 | } 230 | 231 | public String getFailureBehavior() { 232 | return failureBehavior; 233 | } 234 | 235 | public MavenRequest setFailureBehavior( String failureBehavior ) { 236 | this.failureBehavior = failureBehavior; 237 | return this; 238 | } 239 | 240 | public List getSelectedProjects() { 241 | return selectedProjects; 242 | } 243 | 244 | public MavenRequest setSelectedProjects( List selectedProjects ) { 245 | this.selectedProjects = selectedProjects; 246 | return this; 247 | } 248 | 249 | public String getResumeFromProject() { 250 | return resumeFromProject; 251 | } 252 | 253 | public MavenRequest setResumeFromProject( String resumeFromProject ) { 254 | this.resumeFromProject = resumeFromProject; 255 | return this; 256 | } 257 | 258 | public String getMakeBehavior() { 259 | return makeBehavior; 260 | } 261 | 262 | public MavenRequest setMakeBehavior( String makeBehavior ) { 263 | this.makeBehavior = makeBehavior; 264 | return this; 265 | } 266 | 267 | public String getThreadCount() { 268 | return threadCount; 269 | } 270 | 271 | public MavenRequest setThreadCount( String threadCount ) { 272 | this.threadCount = threadCount; 273 | return this; 274 | } 275 | 276 | public boolean isRecursive() { 277 | return recursive; 278 | } 279 | 280 | public MavenRequest setRecursive( boolean recursive ) { 281 | this.recursive = recursive; 282 | return this; 283 | } 284 | 285 | public String getPom() { 286 | return pom; 287 | } 288 | 289 | public MavenRequest setPom( String pom ) { 290 | this.pom = pom; 291 | return this; 292 | } 293 | 294 | public boolean isShowErrors() { 295 | return showErrors; 296 | } 297 | 298 | public MavenRequest setShowErrors( boolean showErrors ) { 299 | this.showErrors = showErrors; 300 | return this; 301 | } 302 | 303 | public int getLoggingLevel() { 304 | return loggingLevel; 305 | } 306 | 307 | public MavenRequest setLoggingLevel( int loggingLevel ) { 308 | this.loggingLevel = loggingLevel; 309 | return this; 310 | } 311 | 312 | public boolean isUpdateSnapshots() { 313 | return updateSnapshots; 314 | } 315 | 316 | public MavenRequest setUpdateSnapshots( boolean updateSnapshots ) { 317 | this.updateSnapshots = updateSnapshots; 318 | return this; 319 | } 320 | 321 | public boolean isNoSnapshotUpdates() { 322 | return noSnapshotUpdates; 323 | } 324 | 325 | public MavenRequest setNoSnapshotUpdates( boolean noSnapshotUpdates ) { 326 | this.noSnapshotUpdates = noSnapshotUpdates; 327 | return this; 328 | } 329 | 330 | public String getGlobalChecksumPolicy() { 331 | return globalChecksumPolicy; 332 | } 333 | 334 | public MavenRequest setGlobalChecksumPolicy( String globalChecksumPolicy ) { 335 | this.globalChecksumPolicy = globalChecksumPolicy; 336 | return this; 337 | } 338 | 339 | public boolean isInteractive() { 340 | return interactive; 341 | } 342 | 343 | public MavenRequest setInteractive( boolean interactive ) { 344 | this.interactive = interactive; 345 | return this; 346 | } 347 | 348 | public boolean isCacheTransferError() { 349 | return cacheTransferError; 350 | } 351 | 352 | public MavenRequest setCacheTransferError( boolean cacheTransferError ) { 353 | this.cacheTransferError = cacheTransferError; 354 | return this; 355 | } 356 | 357 | public boolean isCacheNotFound() { 358 | return cacheNotFound; 359 | } 360 | 361 | public MavenRequest setCacheNotFound( boolean cacheNotFound ) { 362 | this.cacheNotFound = cacheNotFound; 363 | return this; 364 | } 365 | 366 | public List getProfiles() { 367 | return profiles; 368 | } 369 | 370 | public MavenRequest setProfiles( List profiles ) { 371 | this.profiles = profiles; 372 | return this; 373 | } 374 | 375 | public ExecutionListener getExecutionListener() { 376 | return executionListener; 377 | } 378 | 379 | public MavenRequest setExecutionListener( ExecutionListener executionListener ) { 380 | this.executionListener = executionListener; 381 | return this; 382 | } 383 | 384 | public WorkspaceReader getWorkspaceReader() { 385 | return workspaceReader; 386 | } 387 | 388 | public MavenRequest setWorkspaceReader( WorkspaceReader workspaceReader ) { 389 | this.workspaceReader = workspaceReader; 390 | return this; 391 | } 392 | 393 | public LoggerManager getMavenLoggerManager() { 394 | return mavenLoggerManager; 395 | } 396 | 397 | public MavenRequest setMavenLoggerManager( LoggerManager mavenLoggerManager ) { 398 | this.mavenLoggerManager = mavenLoggerManager; 399 | return this; 400 | } 401 | 402 | public URL getOverridingComponentsXml() { 403 | return overridingComponentsXml; 404 | } 405 | 406 | public MavenRequest setOverridingComponentsXml( URL overridingComponentsXml ) { 407 | this.overridingComponentsXml = overridingComponentsXml; 408 | return this; 409 | } 410 | 411 | public boolean isProcessPlugins() { 412 | return processPlugins; 413 | } 414 | 415 | public MavenRequest setProcessPlugins( boolean processPlugins ) { 416 | this.processPlugins = processPlugins; 417 | return this; 418 | } 419 | 420 | public boolean isResolveDependencies() { 421 | return resolveDependencies; 422 | } 423 | 424 | public MavenRequest setResolveDependencies( boolean resolveDependencies ) { 425 | this.resolveDependencies = resolveDependencies; 426 | return this; 427 | } 428 | 429 | public int getValidationLevel() 430 | { 431 | return validationLevel; 432 | } 433 | 434 | public MavenRequest setValidationLevel( int validationLevel ) 435 | { 436 | this.validationLevel = validationLevel; 437 | return this; 438 | } 439 | 440 | public boolean isContainerAutoWiring() 441 | { 442 | return containerAutoWiring; 443 | } 444 | 445 | public void setContainerAutoWiring( boolean containerAutoWiring ) 446 | { 447 | this.containerAutoWiring = containerAutoWiring; 448 | } 449 | 450 | public String getContainerComponentVisibility() 451 | { 452 | return containerComponentVisibility; 453 | } 454 | 455 | public void setContainerComponentVisibility( String containerComponentVisibility ) 456 | { 457 | this.containerComponentVisibility = containerComponentVisibility; 458 | } 459 | 460 | public String getContainerClassPathScanning() 461 | { 462 | return containerClassPathScanning; 463 | } 464 | 465 | public void setContainerClassPathScanning( String containerClassPathScanning ) 466 | { 467 | this.containerClassPathScanning = containerClassPathScanning; 468 | } 469 | 470 | } 471 | -------------------------------------------------------------------------------- /src/main/java/hudson/maven/ReactorReader.java: -------------------------------------------------------------------------------- 1 | package hudson.maven; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.io.File; 23 | import java.util.ArrayList; 24 | import java.util.Collection; 25 | import java.util.Collections; 26 | import java.util.HashMap; 27 | import java.util.HashSet; 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | import org.apache.maven.artifact.ArtifactUtils; 32 | import org.apache.maven.project.MavenProject; 33 | import org.eclipse.aether.artifact.Artifact; 34 | import org.eclipse.aether.repository.WorkspaceReader; 35 | import org.eclipse.aether.repository.WorkspaceRepository; 36 | 37 | /** 38 | * NOTE : this class is not designed for external use so it can change without any prior notice 39 | * class coming from ASF sources 40 | * http://svn.apache.org/repos/asf/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/ReactorReader.java 41 | * FIXME simplify more !! 42 | * @author Olivier Lamy 43 | * @since 1.1 44 | */ 45 | public class ReactorReader 46 | implements WorkspaceReader 47 | { 48 | private Map projectsByGAV; 49 | 50 | private Map> projectsByGA; 51 | 52 | private WorkspaceRepository repository; 53 | 54 | private File workspaceRoot; 55 | 56 | public ReactorReader( Map reactorProjects, File workspaceRoot ) 57 | { 58 | projectsByGAV = reactorProjects; 59 | this.workspaceRoot = workspaceRoot; 60 | projectsByGA = new HashMap<>( reactorProjects.size() * 2 ); 61 | for ( MavenProject project : reactorProjects.values() ) 62 | { 63 | String key = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ); 64 | 65 | List projects = projectsByGA.computeIfAbsent( key, k -> new ArrayList<>( 1 ) ); 66 | 67 | projects.add( project ); 68 | } 69 | 70 | repository = new WorkspaceRepository( "reactor", new HashSet<>( projectsByGAV.keySet() ) ); 71 | } 72 | 73 | private File find( MavenProject project, Artifact artifact ) 74 | { 75 | if ( "pom".equals( artifact.getExtension() ) ) 76 | { 77 | return project.getFile(); 78 | } 79 | 80 | org.apache.maven.artifact.Artifact matchingArtifact = findMatchingArtifact( project, artifact ); 81 | if ( matchingArtifact != null ) 82 | { 83 | return matchingArtifact.getFile(); 84 | } 85 | return null; 86 | } 87 | 88 | /** 89 | * Tries to resolve the specified artifact from the artifacts of the given project. 90 | * 91 | * @param project The project to try to resolve the artifact from, must not be null. 92 | * @param requestedArtifact The artifact to resolve, must not be null. 93 | * @return The matching artifact from the project or null if not found. 94 | */ 95 | private org.apache.maven.artifact.Artifact findMatchingArtifact( MavenProject project, Artifact requestedArtifact ) 96 | { 97 | String requestedRepositoryConflictId = getConflictId( requestedArtifact ); 98 | 99 | org.apache.maven.artifact.Artifact mainArtifact = project.getArtifact(); 100 | if ( requestedRepositoryConflictId.equals( getConflictId( mainArtifact ) ) ) 101 | { 102 | mainArtifact.setFile( new File( workspaceRoot, project.getArtifactId() ) ); 103 | return mainArtifact; 104 | } 105 | 106 | Collection attachedArtifacts = project.getAttachedArtifacts(); 107 | if ( attachedArtifacts != null && !attachedArtifacts.isEmpty() ) 108 | { 109 | for ( org.apache.maven.artifact.Artifact attachedArtifact : attachedArtifacts ) 110 | { 111 | if ( requestedRepositoryConflictId.equals( getConflictId( attachedArtifact ) ) ) 112 | { 113 | attachedArtifact.setFile( new File( workspaceRoot, project.getArtifactId() ) ); 114 | return attachedArtifact; 115 | } 116 | } 117 | } 118 | 119 | return null; 120 | } 121 | 122 | /** 123 | * Gets the repository conflict id of the specified artifact. Unlike the dependency conflict id, the repository 124 | * conflict id uses the artifact file extension instead of the artifact type. Hence, the repository conflict id more 125 | * closely reflects the identity of artifacts as perceived by a repository. 126 | * 127 | * @param artifact The artifact, must not be null. 128 | * @return The repository conflict id, never null. 129 | */ 130 | private String getConflictId( org.apache.maven.artifact.Artifact artifact ) 131 | { 132 | StringBuilder buffer = new StringBuilder( 128 ); 133 | buffer.append( artifact.getGroupId() ); 134 | buffer.append( ':' ).append( artifact.getArtifactId() ); 135 | if ( artifact.getArtifactHandler() != null ) 136 | { 137 | buffer.append( ':' ).append( artifact.getArtifactHandler().getExtension() ); 138 | } 139 | else 140 | { 141 | buffer.append( ':' ).append( artifact.getType() ); 142 | } 143 | if ( artifact.hasClassifier() ) 144 | { 145 | buffer.append( ':' ).append( artifact.getClassifier() ); 146 | } 147 | return buffer.toString(); 148 | } 149 | 150 | private String getConflictId( Artifact artifact ) 151 | { 152 | StringBuilder buffer = new StringBuilder( 128 ); 153 | buffer.append( artifact.getGroupId() ); 154 | buffer.append( ':' ).append( artifact.getArtifactId() ); 155 | buffer.append( ':' ).append( artifact.getExtension() ); 156 | if ( artifact.getClassifier().length() > 0 ) 157 | { 158 | buffer.append( ':' ).append( artifact.getClassifier() ); 159 | } 160 | return buffer.toString(); 161 | } 162 | 163 | public File findArtifact( Artifact artifact ) 164 | { 165 | String projectKey = artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getVersion(); 166 | 167 | MavenProject project = projectsByGAV.get( projectKey ); 168 | 169 | if ( project != null ) 170 | { 171 | return find( project, artifact ); 172 | } 173 | 174 | return null; 175 | } 176 | 177 | public List findVersions( Artifact artifact ) 178 | { 179 | String key = artifact.getGroupId() + ':' + artifact.getArtifactId(); 180 | 181 | List projects = projectsByGA.get( key ); 182 | if ( projects == null || projects.isEmpty() ) 183 | { 184 | return Collections.emptyList(); 185 | } 186 | 187 | List versions = new ArrayList<>(); 188 | 189 | for ( MavenProject project : projects ) 190 | { 191 | if ( find( project, artifact ) != null ) 192 | { 193 | versions.add( project.getVersion() ); 194 | } 195 | } 196 | 197 | return Collections.unmodifiableList( versions ); 198 | } 199 | 200 | public void addProject(MavenProject mavenProject) { 201 | String key = mavenProject.getGroupId() + ':' + mavenProject.getArtifactId(); 202 | this.projectsByGA.put( key, Collections.singletonList( mavenProject ) ); 203 | 204 | String projectKey = mavenProject.getGroupId() + ':' + mavenProject.getArtifactId() + ':' + mavenProject.getVersion(); 205 | 206 | this.projectsByGAV.put( projectKey, mavenProject ); 207 | } 208 | 209 | public WorkspaceRepository getRepository() 210 | { 211 | return repository; 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /src/test/java/hudson/maven/TestMavenEmbedderSimpleProject.java: -------------------------------------------------------------------------------- 1 | package hudson.maven; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.io.File; 23 | import java.util.ArrayList; 24 | import java.util.Arrays; 25 | import java.util.List; 26 | 27 | 28 | import org.apache.maven.execution.AbstractExecutionListener; 29 | import org.apache.maven.execution.ExecutionEvent; 30 | import org.apache.maven.execution.MavenExecutionResult; 31 | import org.apache.maven.model.building.ModelBuildingRequest; 32 | import org.apache.maven.project.MavenProject; 33 | import org.apache.maven.project.ProjectBuildingException; 34 | import org.junit.Assert; 35 | import org.junit.Test; 36 | 37 | import static org.junit.Assert.assertEquals; 38 | import static org.junit.Assert.assertTrue; 39 | 40 | /** 41 | * @author olamy 42 | * 43 | */ 44 | public class TestMavenEmbedderSimpleProject { 45 | 46 | @Test 47 | public void testSimpleProjectRead() throws Exception { 48 | MavenRequest mavenRequest = new MavenRequest(); 49 | mavenRequest.setPom( new File( "src/test/projects-tests/one-module/pom.xml" ).getAbsolutePath() ); 50 | 51 | mavenRequest.setLocalRepositoryPath( System.getProperty( "localRepository" , "./target/repo-maven" ) ); 52 | 53 | mavenRequest.setBaseDirectory( new File( "src/test/projects-tests/scm-git-test-one-module" ).getAbsolutePath() ); 54 | MavenEmbedder mavenEmbedder = new MavenEmbedder( Thread.currentThread().getContextClassLoader(), mavenRequest ); 55 | //new MavenEmbedder( new File( System.getProperty( "maven.home" ) ), mavenRequest ); 56 | 57 | MavenProject project = mavenEmbedder.readProject( new File( "src/test/projects-tests/one-module/pom.xml" ) ); 58 | assertEquals( "my-app", project.getArtifactId()); 59 | } 60 | 61 | @Test 62 | public void testSimpleProjectBuild() throws Exception { 63 | MavenRequest mavenRequest = new MavenRequest(); 64 | mavenRequest.setUserSettingsFile( new File(System.getProperty( "user.home"), ".m2/settings.xml" ).getAbsolutePath() ); 65 | mavenRequest.setLocalRepositoryPath( System.getProperty( "localRepository" , "./target/repo-maven" ) ); 66 | mavenRequest.setPom( new File( "src/test/projects-tests/one-module/pom.xml" ).getAbsolutePath() ); 67 | mavenRequest.setGoals( Arrays.asList( "clean", "test" ) ); 68 | mavenRequest.getUserProperties().put( "failIfNoTests", "false" ); 69 | 70 | final List executedMojos = new ArrayList<>(); 71 | 72 | AbstractExecutionListener listener = new AbstractExecutionListener() 73 | { 74 | public void mojoStarted( ExecutionEvent event ) 75 | { 76 | executedMojos.add( event.getMojoExecution().getArtifactId() ); 77 | } 78 | 79 | }; 80 | 81 | mavenRequest.setExecutionListener( listener ); 82 | 83 | //mavenRequest.setBaseDirectory( new File( "src/test/projects-tests/scm-git-test-one-module" ).getAbsolutePath() ); 84 | MavenEmbedder mavenEmbedder = new MavenEmbedder( new File( System.getProperty( "maven.home" ) ), mavenRequest ); 85 | 86 | MavenExecutionResult result = mavenEmbedder.execute( mavenRequest ); 87 | 88 | System.out.println( result.getExceptions().toString() ); 89 | 90 | assertTrue(result.getExceptions().isEmpty()); 91 | 92 | assertTrue(executedMojos.contains( "maven-clean-plugin" )); 93 | assertTrue(executedMojos.contains( "maven-surefire-plugin" )); 94 | 95 | } 96 | 97 | @Test 98 | public void testEclipsePluginProjectRead() throws Exception { 99 | MavenRequest mavenRequest = new MavenRequest(); 100 | mavenRequest.setPom( new File( "src/test/projects-tests/eclipse-plugin/pom.xml" ).getAbsolutePath() ); 101 | 102 | mavenRequest.setLocalRepositoryPath( System.getProperty( "localRepository" , "./target/repo-maven" ) ); 103 | 104 | mavenRequest.setBaseDirectory( new File( "src/test/projects-tests/scm-git-test-one-module" ).getAbsolutePath() ); 105 | MavenEmbedder mavenEmbedder = new MavenEmbedder( Thread.currentThread().getContextClassLoader(), mavenRequest ); 106 | //new MavenEmbedder( new File( System.getProperty( "maven.home" ) ), mavenRequest ); 107 | 108 | MavenProject project = mavenEmbedder.readProject( new File( "src/test/projects-tests/eclipse-plugin/pom.xml" ) ); 109 | assertEquals("my-app", project.getArtifactId()); 110 | assertEquals("eclipse-plugin", project.getPackaging()); 111 | } 112 | 113 | @Test 114 | public void testEclipsePluginProjectReadMultiModule() throws Exception { 115 | MavenRequest mavenRequest = new MavenRequest(); 116 | mavenRequest.setPom( new File( "src/test/projects-tests/eclipse-plugin-with-parent/parent/pom.xml" ).getAbsolutePath() ); 117 | 118 | mavenRequest.setLocalRepositoryPath( System.getProperty( "localRepository" , "./target/repo-maven" ) ); 119 | 120 | mavenRequest.setBaseDirectory( new File( "src/test/projects-tests/eclipse-plugin-with-parent/parent/" ).getAbsolutePath() ); 121 | MavenEmbedder mavenEmbedder = new MavenEmbedder( Thread.currentThread().getContextClassLoader(), mavenRequest ); 122 | //new MavenEmbedder( new File( System.getProperty( "maven.home" ) ), mavenRequest ); 123 | 124 | List projects = mavenEmbedder.readProjects( new File( "src/test/projects-tests/eclipse-plugin-with-parent/parent/pom.xml" ), true ); 125 | assertEquals( "not 2 projects", 2, projects.size() ); 126 | } 127 | 128 | @Test 129 | public void testWrongScopeWithMaven2() throws Exception { 130 | MavenRequest mavenRequest = new MavenRequest(); 131 | mavenRequest.setPom( new File( "src/test/projects-tests/test-pom-8395.xml" ).getAbsolutePath() ); 132 | 133 | mavenRequest.setLocalRepositoryPath( System.getProperty( "localRepository" , "./target/repo-maven" ) ); 134 | 135 | mavenRequest.setBaseDirectory( new File( "src/test/projects-tests/" ).getAbsolutePath() ); 136 | MavenEmbedder mavenEmbedder = new MavenEmbedder( Thread.currentThread().getContextClassLoader(), mavenRequest ); 137 | //new MavenEmbedder( new File( System.getProperty( "maven.home" ) ), mavenRequest ); 138 | 139 | mavenEmbedder.readProjects( new File( "src/test/projects-tests/test-pom-8395.xml" ), true ); 140 | 141 | } 142 | 143 | @Test(expected = ProjectBuildingException.class) 144 | public void testWrongScopeWithMaven3() throws Exception { 145 | MavenRequest mavenRequest = new MavenRequest(); 146 | mavenRequest.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 ); 147 | mavenRequest.setPom( new File( "src/test/projects-tests/test-pom-8395.xml" ).getAbsolutePath() ); 148 | 149 | mavenRequest.setLocalRepositoryPath( System.getProperty( "localRepository" , "./target/repo-maven" ) ); 150 | 151 | mavenRequest.setBaseDirectory( new File( "src/test/projects-tests/" ).getAbsolutePath() ); 152 | MavenEmbedder mavenEmbedder = new MavenEmbedder( Thread.currentThread().getContextClassLoader(), mavenRequest ); 153 | //new MavenEmbedder( new File( System.getProperty( "maven.home" ) ), mavenRequest ); 154 | mavenEmbedder.readProjects( new File( "src/test/projects-tests/test-pom-8395.xml" ), true ); 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /src/test/java/hudson/maven/TestMavenEmbedderSimpleProjectWithParent.java: -------------------------------------------------------------------------------- 1 | package hudson.maven; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.apache.maven.project.MavenProject; 23 | import org.codehaus.plexus.util.FileUtils; 24 | import org.junit.Assert; 25 | import org.junit.Test; 26 | 27 | import java.io.File; 28 | 29 | /** 30 | * @author olamy 31 | */ 32 | public class TestMavenEmbedderSimpleProjectWithParent 33 | { 34 | 35 | @Test 36 | public void testSimpleProjectRead() 37 | throws Exception 38 | { 39 | MavenRequest mavenRequest = new MavenRequest(); 40 | mavenRequest.setLoggingLevel( 1 ); 41 | 42 | mavenRequest.setPom( new File( "src/test/projects-tests/one-module-with-parent/pom.xml" ).getAbsolutePath() ); 43 | 44 | String localRepoPath = System.getProperty( "localRepository", "./target/repo-maven" ); 45 | 46 | System.out.println( " use localRepo path " + localRepoPath ); 47 | 48 | File dir = new File( localRepoPath + "/org/sonatype/oss/oss-parent/5/" ); 49 | 50 | if ( dir.exists() ) 51 | { 52 | FileUtils.deleteDirectory( dir ); 53 | } 54 | 55 | mavenRequest.setLocalRepositoryPath( localRepoPath ); 56 | 57 | mavenRequest.setBaseDirectory( 58 | new File( "src/test/projects-tests/scm-git-test-one-module" ).getAbsolutePath() ); 59 | MavenEmbedder mavenEmbedder = new MavenEmbedder( Thread.currentThread().getContextClassLoader(), mavenRequest ); 60 | 61 | MavenProject project = 62 | mavenEmbedder.readProject( new File( "src/test/projects-tests/one-module-with-parent/pom.xml" ) ); 63 | Assert.assertEquals( "my-app", project.getArtifactId() ); 64 | Assert.assertNotNull( project.getParent() ); 65 | Assert.assertEquals( "org.jenkins-ci", project.getParent().getGroupId() ); 66 | Assert.assertEquals( "jenkins", project.getParent().getArtifactId() ); 67 | Assert.assertEquals( "1.37", project.getParent().getVersion() ); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/hudson/maven/TestMavenEmbedderUtils.java: -------------------------------------------------------------------------------- 1 | package hudson.maven; 2 | 3 | import org.apache.maven.artifact.versioning.ComparableVersion; 4 | import org.junit.Test; 5 | import org.jvnet.hudson.test.Issue; 6 | 7 | import java.io.File; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | /** 12 | * @author Olivier Lamy 13 | * 14 | */ 15 | public class TestMavenEmbedderUtils { 16 | 17 | @Test 18 | public void testMavenVersion() throws Exception { 19 | MavenInformation mavenInformation = MavenEmbedderUtils.getMavenVersion( new File( System.getProperty( "maven.home" ) )); 20 | 21 | String version = mavenInformation.getVersion(); 22 | assertNotNull( mavenInformation.getVersionResourcePath() ); 23 | System.out.println("maven version " + version ); 24 | 25 | assertNotNull( version ); 26 | ComparableVersion current = new ComparableVersion( version ); 27 | 28 | ComparableVersion old = new ComparableVersion( "2.2.1" ); 29 | 30 | assertTrue( current.compareTo( old ) > 0 ); 31 | 32 | assertTrue( current.compareTo( new ComparableVersion( "3.0" ) ) >= 0 ); 33 | } 34 | 35 | @Test 36 | public void testMavenVersion2_2_1() throws Exception { 37 | MavenInformation mavenInformation = MavenEmbedderUtils.getMavenVersion( new File( "src/test/maven-2.2.1" ) ); 38 | assertNotNull( mavenInformation.getVersionResourcePath() ); 39 | 40 | assertEquals("2.2.1", mavenInformation.getVersion()); 41 | } 42 | 43 | @Test(expected = MavenEmbedderException.class) 44 | public void testGetMavenVersionFromInvalidLocation() throws Exception { 45 | MavenEmbedderUtils.getMavenVersion( new File(System.getProperty("java.home"))); 46 | } 47 | 48 | @Test 49 | public void testisAtLeastMavenVersion() throws Exception { 50 | assertTrue( MavenEmbedderUtils.isAtLeastMavenVersion( new File( System.getProperty( "maven.home" ) ), "3.0" ) ); 51 | assertFalse( MavenEmbedderUtils.isAtLeastMavenVersion( new File( "src/test/maven-2.2.1" ), "3.0" ) ); 52 | } 53 | 54 | @Test 55 | @Issue("JENKINS-42549") 56 | public void testIfFailsInTheCaseOfRaceConditions() throws Exception { 57 | final File mvnHome = new File( System.getProperty( "maven.home" )); 58 | final MavenEmbedderCallable nestedLoad = () -> { 59 | // Here we invoke the nested call in order to emulate the race condition 60 | // between multiple threads. 61 | MavenEmbedderUtils.getMavenVersion(mvnHome); 62 | }; 63 | 64 | MavenEmbedderUtils.getMavenVersion(mvnHome, nestedLoad); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/hudson/maven/TestMavenModules.java: -------------------------------------------------------------------------------- 1 | package hudson.maven; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.io.File; 23 | import java.util.HashMap; 24 | import java.util.List; 25 | 26 | import junit.framework.TestCase; 27 | 28 | import org.apache.maven.model.building.ModelBuildingRequest; 29 | import org.apache.maven.project.MavenProject; 30 | 31 | /** 32 | * @author olamy 33 | * 34 | */ 35 | public class TestMavenModules extends TestCase { 36 | 37 | public void testModuleWithAPomInTheSameDirWithMaven2() throws Exception { 38 | MavenRequest mavenRequest = new MavenRequest(); 39 | mavenRequest.setPom( new File( "src/test/projects-tests/several-modules-in-directory/pom.xml" ).getAbsolutePath() ); 40 | 41 | mavenRequest.setLocalRepositoryPath( System.getProperty( "localRepository" , "./target/repo-maven" ) ); 42 | 43 | ReactorReader reactorReader = 44 | new ReactorReader( new HashMap<>(), new File (mavenRequest.getPom() ).getParentFile() ); 45 | 46 | mavenRequest.setWorkspaceReader( reactorReader ); 47 | 48 | mavenRequest.setBaseDirectory( new File( "src/test/projects-tests/" ).getAbsolutePath() ); 49 | MavenEmbedder mavenEmbedder = new MavenEmbedder( Thread.currentThread().getContextClassLoader(), mavenRequest ); 50 | 51 | MavenProject root = mavenEmbedder.readProject(new File("src/test/projects-tests/several-modules-in-directory/pom.xml")); 52 | 53 | reactorReader.addProject( root ); 54 | 55 | assertNotNull( root ); 56 | System.out.println("modules " + root.getModules()); 57 | for (String module : root.getModules()) { 58 | File moduleFile = new File(root.getBasedir(), module); 59 | if (!moduleFile.isFile()) 60 | { 61 | MavenProject mavenProject = mavenEmbedder.readProject( new File( root.getBasedir(), module + "/pom.xml" )); 62 | reactorReader.addProject( mavenProject ); 63 | assertNotNull( mavenProject ); 64 | } 65 | else 66 | { 67 | MavenProject mavenProject = mavenEmbedder.readProject( moduleFile ); 68 | reactorReader.addProject( mavenProject ); 69 | assertNotNull( mavenProject ); 70 | } 71 | } 72 | 73 | } 74 | 75 | 76 | public void testModuleWithAPomInTheSameDirWithMaven3() throws Exception { 77 | MavenRequest mavenRequest = new MavenRequest(); 78 | mavenRequest.setPom( new File( "src/test/projects-tests/several-modules-in-directory/pom.xml" ).getAbsolutePath() ); 79 | mavenRequest.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 ); 80 | mavenRequest.setLocalRepositoryPath( System.getProperty( "localRepository" , "./target/repo-maven" ) ); 81 | 82 | ReactorReader reactorReader = 83 | new ReactorReader( new HashMap<>(), new File (mavenRequest.getPom() ).getParentFile() ); 84 | 85 | mavenRequest.setWorkspaceReader( reactorReader ); 86 | 87 | mavenRequest.setBaseDirectory( new File( "src/test/projects-tests/" ).getAbsolutePath() ); 88 | MavenEmbedder mavenEmbedder = new MavenEmbedder( Thread.currentThread().getContextClassLoader(), mavenRequest ); 89 | 90 | List projects = mavenEmbedder.readProjects(new File("src/test/projects-tests/several-modules-in-directory/pom.xml"),true); 91 | 92 | assertEquals( 2, projects.size() ); 93 | 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/test/java/hudson/maven/TestMavenProjectBuildWrong.java: -------------------------------------------------------------------------------- 1 | package hudson.maven; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import java.io.File; 23 | import java.util.HashMap; 24 | 25 | import org.apache.maven.model.building.ModelBuildingRequest; 26 | import org.apache.maven.project.MavenProject; 27 | import org.apache.maven.project.ProjectBuildingException; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.assertNotNull; 31 | 32 | /** 33 | * @author olamy 34 | * 35 | */ 36 | public class TestMavenProjectBuildWrong { 37 | 38 | @Test 39 | public void testWrongInheritenceWithMaven2() throws Exception { 40 | MavenRequest mavenRequest = new MavenRequest(); 41 | mavenRequest.setPom( new File( "src/test/projects-tests/incorrect-inheritence-testcase/pom.xml" ).getAbsolutePath() ); 42 | 43 | mavenRequest.setLocalRepositoryPath( System.getProperty( "localRepository" , "./target/repo-maven" ) ); 44 | 45 | ReactorReader reactorReader = 46 | new ReactorReader( new HashMap<>(), new File (mavenRequest.getPom() ).getParentFile() ); 47 | 48 | mavenRequest.setWorkspaceReader( reactorReader ); 49 | 50 | mavenRequest.setBaseDirectory( new File( "src/test/projects-tests/" ).getAbsolutePath() ); 51 | MavenEmbedder mavenEmbedder = new MavenEmbedder( Thread.currentThread().getContextClassLoader(), mavenRequest ); 52 | 53 | MavenProject root = mavenEmbedder.readProject( new File( "src/test/projects-tests/incorrect-inheritence-testcase/pom.xml" )); 54 | 55 | reactorReader.addProject( root ); 56 | 57 | assertNotNull( root ); 58 | System.out.println("modules " + root.getModules()); 59 | for (String module : root.getModules()) { 60 | MavenProject mavenProject = mavenEmbedder.readProject( new File( root.getBasedir(), module + "/pom.xml" )); 61 | reactorReader.addProject( mavenProject ); 62 | assertNotNull( mavenProject ); 63 | } 64 | 65 | } 66 | 67 | @Test(expected = ProjectBuildingException.class) 68 | public void testWrongInheritenceWithMaven3() throws Exception { 69 | MavenRequest mavenRequest = new MavenRequest(); 70 | mavenRequest.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 ); 71 | mavenRequest.setPom( new File( "src/test/projects-tests/incorrect-inheritence-testcase/pom.xml" ).getAbsolutePath() ); 72 | 73 | mavenRequest.setLocalRepositoryPath( System.getProperty( "localRepository" , "./target/repo-maven" ) ); 74 | 75 | mavenRequest.setBaseDirectory( new File( "src/test/projects-tests/" ).getAbsolutePath() ); 76 | MavenEmbedder mavenEmbedder = new MavenEmbedder( Thread.currentThread().getContextClassLoader(), mavenRequest ); 77 | //new MavenEmbedder( new File( System.getProperty( "maven.home" ) ), mavenRequest ); 78 | mavenEmbedder.readProjects( new File( "src/test/projects-tests/incorrect-inheritence-testcase/pom.xml" ), true ); 79 | 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/test/maven-2.2.1/LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | License for JSch 180 | 181 | ------------------------------------------------------------------------------ 182 | Copyright (c) 2002,2003,2004,2005,2006,2007,2008 Atsuhiko Yamanaka, JCraft,Inc. 183 | All rights reserved. 184 | 185 | Redistribution and use in source and binary forms, with or without 186 | modification, are permitted provided that the following conditions are met: 187 | 188 | 1. Redistributions of source code must retain the above copyright notice, 189 | this list of conditions and the following disclaimer. 190 | 191 | 2. Redistributions in binary form must reproduce the above copyright 192 | notice, this list of conditions and the following disclaimer in 193 | the documentation and/or other materials provided with the distribution. 194 | 195 | 3. The names of the authors may not be used to endorse or promote products 196 | derived from this software without specific prior written permission. 197 | 198 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 199 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 200 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 201 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 202 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 203 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 204 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 205 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 206 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 207 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 208 | 209 | License for SLF4J 210 | 211 | Copyright (c) 2004-2008 QOS.ch 212 | All rights reserved. 213 | 214 | Permission is hereby granted, free of charge, to any person obtaining 215 | a copy of this software and associated documentation files (the 216 | "Software"), to deal in the Software without restriction, including 217 | without limitation the rights to use, copy, modify, merge, publish, 218 | distribute, sublicense, and/or sell copies of the Software, and to 219 | permit persons to whom the Software is furnished to do so, subject to 220 | the following conditions: 221 | 222 | The above copyright notice and this permission notice shall be 223 | included in all copies or substantial portions of the Software. 224 | 225 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 226 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 227 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 228 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 229 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 230 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 231 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 232 | 233 | 234 | -------------------------------------------------------------------------------- /src/test/maven-2.2.1/NOTICE.txt: -------------------------------------------------------------------------------- 1 | ========================================================================= 2 | == NOTICE file corresponding to the section 4 d of == 3 | == the Apache License, Version 2.0, == 4 | == in this case for the Apache Maven distribution. == 5 | ========================================================================= 6 | 7 | This product includes software developed by 8 | The Apache Software Foundation (http://www.apache.org/). 9 | 10 | This product includes software (Plexus and Classworlds) developed by 11 | The Codehaus Foundation (http://www.codehaus.org/). 12 | 13 | This product includes software (JSCH) developed by 14 | JCraft Inc. (http://www.jcraft.com/jsch/). 15 | 16 | This product includes software (JTidy) developed at 17 | SourceForge (http://sourceforge.net/projects/jtidy). 18 | 19 | This product includes software (NekoHTML) developed at 20 | SourceForge (http://sourceforge.net/projects/nekohtml). 21 | -------------------------------------------------------------------------------- /src/test/maven-2.2.1/lib/maven-2.2.1-uber.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/lib-jenkins-maven-embedder/41a5f93b76c810dc590fdfb4d581fc672d2d494c/src/test/maven-2.2.1/lib/maven-2.2.1-uber.jar -------------------------------------------------------------------------------- /src/test/projects-tests/eclipse-plugin-with-parent/child/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.mycompany.app 5 | my-app 6 | 1.0-SNAPSHOT 7 | ../parent/ 8 | 9 | com.mycompany.app 10 | my-app-plugin 11 | Maven Quick Start Archetype 12 | eclipse-plugin 13 | 14 | 15 | junit 16 | junit 17 | 4.13.1 18 | test 19 | 20 | 21 | 22 | 23 | 24 | local.repo 25 | file repository to svn 26 | file://${user.home}/mavenrepo 27 | 28 | 29 | local.repo 30 | file repository to svn 31 | file://${user.home}/mavenreposnapshot 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/test/projects-tests/eclipse-plugin-with-parent/child/src/main/java/com/mycompany/app/App.java: -------------------------------------------------------------------------------- 1 | package com.mycompany.app; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World!" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/projects-tests/eclipse-plugin-with-parent/child/src/test/java/com/mycompany/app/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.mycompany.app; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/projects-tests/eclipse-plugin-with-parent/parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.mycompany.app 4 | my-app 5 | 1.0-SNAPSHOT 6 | Maven Quick Start Archetype 7 | pom 8 | 9 | 10 | junit 11 | junit 12 | 4.13.1 13 | test 14 | 15 | 16 | 17 | ../child 18 | 19 | 20 | 21 | 22 | org.sonatype.tycho 23 | tycho-maven-plugin 24 | 0.10.0 25 | true 26 | 27 | 28 | 29 | 30 | 31 | 32 | local.repo 33 | file repository to svn 34 | file://${user.home}/mavenrepo 35 | 36 | 37 | local.repo 38 | file repository to svn 39 | file://${user.home}/mavenreposnapshot 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/test/projects-tests/eclipse-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.mycompany.app 4 | my-app 5 | 2.5-SNAPSHOT 6 | Maven Quick Start Archetype 7 | eclipse-plugin 8 | 9 | 10 | junit 11 | junit 12 | 3.8.2 13 | test 14 | 15 | 16 | 17 | 18 | 19 | org.sonatype.tycho 20 | tycho-maven-plugin 21 | 0.10.0 22 | true 23 | 24 | 25 | 26 | 27 | 28 | 29 | local.repo 30 | file repository to svn 31 | file://${user.home}/mavenrepo 32 | 33 | 34 | local.repo 35 | file repository to svn 36 | file://${user.home}/mavenreposnapshot 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/test/projects-tests/eclipse-plugin/src/main/java/com/mycompany/app/App.java: -------------------------------------------------------------------------------- 1 | package com.mycompany.app; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World!" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/projects-tests/eclipse-plugin/src/test/java/com/mycompany/app/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.mycompany.app; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/projects-tests/incorrect-inheritence-testcase/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | org.hudson-ci.testcase 5 | wrong-inheritence-parent 6 | 1.0-SNAPSHOT 7 | pom 8 | 9 | subdir/mod1 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/test/projects-tests/incorrect-inheritence-testcase/subdir/mod1/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hudson-ci.testcase 6 | wrong-inheritence-parent 7 | 1.0-SNAPSHOT 8 | 9 | wrong-inheritence-module 10 | jar 11 | 12 | -------------------------------------------------------------------------------- /src/test/projects-tests/one-module-with-parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | org.jenkins-ci 6 | jenkins 7 | 1.37 8 | 9 | 10 | 4.0.0 11 | com.mycompany.app 12 | my-app 13 | 2.5-SNAPSHOT 14 | Maven Quick Start Archetype 15 | 16 | 17 | http://maven.apache.org 18 | scm:git:git://github.com/olamy/scm-git-test-one-module.git 19 | scm:git:git@github.com:olamy/scm-git-test-one-module.git 20 | 21 | 22 | 23 | junit 24 | junit 25 | 4.13.1 26 | test 27 | 28 | 29 | 30 | 31 | 32 | org.apache.maven.plugins 33 | maven-release-plugin 34 | 2.1 35 | 36 | deploy 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | local.repo 45 | file repository to svn 46 | file://${user.home}/mavenrepo 47 | 48 | 49 | local.repo 50 | file repository to svn 51 | file://${user.home}/mavenreposnapshot 52 | 53 | 54 | 55 | 56 | 57 | 58 | m.g.o-public 59 | https://repo.jenkins-ci.org/public/ 60 | 61 | true 62 | 63 | 64 | false 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/test/projects-tests/one-module-with-parent/src/main/java/com/mycompany/app/App.java: -------------------------------------------------------------------------------- 1 | package com.mycompany.app; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World!" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/projects-tests/one-module-with-parent/src/test/java/com/mycompany/app/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.mycompany.app; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/projects-tests/one-module/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.mycompany.app 4 | my-app 5 | 2.5-SNAPSHOT 6 | Maven Quick Start Archetype 7 | 8 | 9 | http://maven.apache.org 10 | scm:git:git://github.com/olamy/scm-git-test-one-module.git 11 | scm:git:git@github.com:olamy/scm-git-test-one-module.git 12 | 13 | 14 | 15 | junit 16 | junit 17 | 4.13.1 18 | test 19 | 20 | 21 | 22 | 23 | 24 | org.apache.maven.plugins 25 | maven-compiler-plugin 26 | 3.8.1 27 | 28 | 1.8 29 | 1.8 30 | 31 | 32 | 33 | org.apache.maven.plugins 34 | maven-surefire-plugin 35 | 2.9 36 | 37 | 38 | org.apache.maven.plugins 39 | maven-release-plugin 40 | 2.1 41 | 42 | deploy 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | local.repo 51 | file repository to svn 52 | file://${user.home}/mavenrepo 53 | 54 | 55 | local.repo 56 | file repository to svn 57 | file://${user.home}/mavenreposnapshot 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/test/projects-tests/one-module/src/main/java/com/mycompany/app/App.java: -------------------------------------------------------------------------------- 1 | package com.mycompany.app; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World!" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/projects-tests/one-module/src/test/java/com/mycompany/app/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.mycompany.app; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/projects-tests/several-modules-in-directory/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.mycompany.app 4 | module 5 | 1.0-SNAPSHOT 6 | jar 7 | Parent in module.xml 8 | 9 | -------------------------------------------------------------------------------- /src/test/projects-tests/several-modules-in-directory/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.mycompany.app 4 | reactor 5 | 1.0-SNAPSHOT 6 | Parent 7 | pom 8 | 9 | module.xml 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/test/projects-tests/test-pom-8395.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | org.hudson-ci.testcase 5 | testcase-wrong-plugin-dep-scope 6 | 1.0-SNAPSHOT 7 | jar 8 | 9 | 10 | 11 | org.apache.maven.plugins 12 | maven-antrun-plugin 13 | 1.6 14 | 15 | 16 | ant 17 | ant-nodeps 18 | 1.8.2 19 | test 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/test/resources/log4j2-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | --------------------------------------------------------------------------------
61 | * build a {@link ClassRealm} with all jars in mavenHome/lib/*.jar 62 | *
64 | * the {@link ClassRealm} is ChildFirst with the current classLoader as parent. 65 | *
null